예제 #1
0
 private function code($string)
 {
     $code = array('4cs', '6502acme', '6502kickass', '6502tasm', '68000devpac', 'abap', 'actionscript', 'actionscript3', 'ada', 'algol68', 'apache', 'applescript', 'apt_sources', 'arm', 'asm', 'asp', 'asymptote', 'autoconf', 'autohotkey', 'autoit', 'avisynth', 'awk', 'bascomavr', 'bash', 'basic4gl', 'bf', 'bibtex', 'blitzbasic', 'bnf', 'boo', 'c', 'caddcl', 'cadlisp', 'cfdg', 'cfm', 'chaiscript', 'cil', 'clojure', 'cmake', 'cobol', 'coffeescript', 'cpp-qt', 'cpp', 'csharp', 'css', 'cuesheet', 'c_loadrunner', 'c_mac', 'd', 'dcl', 'dcpu16', 'dcs', 'delphi', 'diff', 'div', 'dos', 'dot', 'e', 'ecmascript', 'eiffel', 'email', 'epc', 'erlang', 'euphoria', 'f1', 'falcon', 'fo', 'fortran', 'freebasic', 'freeswitch', 'fsharp', 'gambas', 'gdb', 'genero', 'genie', 'gettext', 'glsl', 'gml', 'gnuplot', 'go', 'groovy', 'gwbasic', 'haskell', 'haxe', 'hicest', 'hq9plus', 'html4strict', 'html5', 'icon', 'idl', 'ini', 'inno', 'intercal', 'io', 'j', 'java', 'java5', 'javascript', 'jquery', 'kixtart', 'klonec', 'klonecpp', 'latex', 'lb', 'ldif', 'lisp', 'llvm', 'locobasic', 'logtalk', 'lolcode', 'lotusformulas', 'lotusscript', 'lscript', 'lsl2', 'lua', 'm68k', 'magiksf', 'make', 'mapbasic', 'matlab', 'mirc', 'mmix', 'modula2', 'modula3', 'mpasm', 'mxml', 'mysql', 'nagios', 'netrexx', 'newlisp', 'nsis', 'oberon2', 'objc', 'objeck', 'ocaml-brief', 'ocaml', 'octave', 'oobas', 'oorexx', 'oracle11', 'oracle8', 'oxygene', 'oz', 'parasail', 'parigp', 'pascal', 'pcre', 'per', 'perl', 'perl6', 'pf', 'php-brief', 'php', 'pic16', 'pike', 'pixelbender', 'pli', 'plsql', 'postgresql', 'povray', 'powerbuilder', 'powershell', 'proftpd', 'progress', 'prolog', 'properties', 'providex', 'purebasic', 'pycon', 'pys60', 'python', 'q', 'qbasic', 'rails', 'rebol', 'reg', 'rexx', 'robots', 'rpmspec', 'rsplus', 'ruby', 'sas', 'scala', 'scheme', 'scilab', 'sdlbasic', 'smalltalk', 'smarty', 'spark', 'sparql', 'sql', 'stonescript', 'systemverilog', 'tcl', 'teraterm', 'text', 'thinbasic', 'tsql', 'typoscript', 'unicon', 'upc', 'urbi', 'uscript', 'vala', 'vb', 'vbnet', 'vedit', 'verilog', 'vhdl', 'vim', 'visualfoxpro', 'visualprolog', 'whitespace', 'whois', 'winbatch', 'xbasic', 'xml', 'xorg_conf', 'xpp', 'yaml', 'z80', 'zxbasic');
     /*
      * Loop throught each available programming languages
      */
     foreach ($code as $highlight) {
         // using regex is worth to save some lines :)
         preg_match_all('/\\[' . $highlight . '\\].*?\\[\\/' . $highlight . '\\]/s', $string, $out);
         if (!empty($out[0])) {
             foreach ($out[0] as $multi) {
                 $no_tag = preg_replace('/\\[\\/?.*\\]/', '', $multi);
                 $geshi = new GeSHi($no_tag, $highlight);
                 $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS);
                 $geshi->set_overall_style('background: #414141;width:100%;');
                 $geshi->set_header_type(GESHI_HEADER_PRE_VALID);
                 $geshi->set_case_keywords(GESHI_CAPS_LOWER);
                 $geshi->set_symbols_style('color: white;', false, 1);
                 $geshi->set_symbols_style('color: #B3F9FF;', false, 2);
                 $geshi->set_methods_style(1, 'color: white;');
                 $geshi->set_strings_style('color: yellow;', false, 'HARD');
                 $geshi->set_strings_style('color: yellow;', false);
                 $geshi->set_numbers_style('color: #FF80E5;');
                 $geshi->set_escape_characters_style('color: #FF80E5;');
                 $geshi->set_regexps_style(1, 'color: white;');
                 $geshi->set_regexps_style(0, 'color: white;');
                 $geshi->set_keyword_group_style(1, 'color: #FF8B8B;', true);
                 $geshi->set_keyword_group_style(2, 'color: #B3F9FF;', true);
                 $geshi->set_keyword_group_style(3, 'color: #B3F9FF;', true);
                 $geshi->set_keyword_group_style(4, 'color: #B3F9FF;', true);
                 $geshi->set_keyword_group_style(5, 'color: #B3F9FF;', true);
                 $geshi->set_keyword_group_style(6, 'color: #B3F9FF;', true);
                 $string = str_replace($multi, $geshi->parse_code(), $string);
             }
         }
     }
     return $string;
 }
예제 #2
0
}
set_time_limit(5 * 60);
// can run long, but not more than 5 minutes
ini_set("error_reporting", E_ALL);
// kill the E_STRICT warnings in GeSHi under PHP 5
require dirname(__FILE__) . '/geshi/geshi.php';
$geshi = new GeSHi('', 'php', dirname(__FILE__) . '/geshi/geshi');
$geshi->set_tab_width(4);
$geshi->set_overall_class('phpcode');
$geshi->set_overall_style('font-size: 85%', true);
$geshi->set_symbols_highlighting(false);
$geshi->set_strings_style('color: green', true);
$geshi->set_keyword_group_style(1, 'color: #d09010; font-weight: bold', true);
$geshi->set_numbers_style('color: #aa0000; font-weight: bold', true);
$geshi->set_methods_style('color: black; font-style: italic', true);
$geshi->set_regexps_style(0, 'color: #004090', true);
// use this to get updated stylesheet info if changed via abovementioned API
// file_put_contents('style.css', $geshi->get_stylesheet());
function callback_html_number_entities_decode($matches)
{
    return chr($matches[1]);
}
function callback_highlight_php($matches)
{
    $with_tags = trim(html_entity_decode($matches[1]));
    global $geshi;
    $geshi->set_language('php');
    $geshi->set_overall_class('phpcode');
    // because last line changes it
    $geshi->enable_classes();
    $geshi->set_source($with_tags);