function load() { if ($this->exists() == true) { $this->import(); $this->lng = $this->data['language']; $this->source = $this->data['source']; } else { if (!class_exists('GeSHi')) { include_once 'classes/class.geshi.php'; } global $lang; $language = $this->hasLanguage() ? $this->lng : 'text'; $geshi = new GeSHi($this->source, $language, 'classes/geshi'); $geshi->set_encoding($lang->charset()); $geshi->enable_classes(false); $geshi->set_header_type(GESHI_HEADER_DIV); $geshi->enable_keyword_links(true); $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 5); if (!$this->hasLanguage()) { $geshi->enable_highlighting(false); $geshi->set_numbers_highlighting(false); $geshi->set_brackets_highlighting(false); $language = ''; } else { $language = $geshi->get_language_name(); } $this->data = array('language' => $language, 'parsed' => $geshi->parse_code(), 'source' => $this->source); $this->export(); } }
/** * @desc Highlights the code. It uses the geshi HTML syntax highlighter and then it highlights the specific template syntax. * @param int $line_number GESHI_NO_LINE_NUMBERS => no line numbers, GESHI_NORMAL_LINE_NUMBERS line numbers. * @param bool $inline_code true if it's a sigle line code, otherwise false. */ public function parse($line_number = GESHI_NO_LINE_NUMBERS, $inline_code = false) { //The template language of PHPBoost contains HTML. We first ask to highlight the html code. require_once PATH_TO_ROOT . '/kernel/lib/php/geshi/geshi.php'; $geshi = new GeSHi($this->content, 'html'); if ($line_number) { $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); } //GeSHi must not put any div or pre tag before and after the content if ($inline_code) { $geshi->set_header_type(GESHI_HEADER_NONE); } $this->content = $geshi->parse_code(); //Now we highlight the specific syntax of PHPBoost templates //Conditionnal block $this->content = preg_replace('`# IF ( NOT)? ((?:\\w+\\.)*)(\\w+) #`i', '<span style="' . self::TPL_SHARP_STYLE . '">#</span> <span style="' . self::TPL_KEYWORD_STYLE . '">IF$1</span> <span style="' . self::TPL_NESTED_VARIABLE_STYLE . '">$2</span><span style="' . self::TPL_VARIABLE_STYLE . '">$3</span> <span style="' . self::TPL_SHARP_STYLE . '">#</span>', $this->content); $this->content = preg_replace('`# ELSEIF ( NOT)? ((?:\\w+\\.)*)(\\w+) #`i', '<span style="' . self::TPL_SHARP_STYLE . '">#</span> <span style="' . self::TPL_KEYWORD_STYLE . '">ELSEIF$1</span> <span style="' . self::TPL_NESTED_VARIABLE_STYLE . '">$2</span><span style="' . self::TPL_VARIABLE_STYLE . '">$3</span> <span style="' . self::TPL_SHARP_STYLE . '">#</span>', $this->content); $this->content = str_replace('# ELSE #', '<span style="' . self::TPL_SHARP_STYLE . '">#</span> <span style="' . self::TPL_KEYWORD_STYLE . '">ELSE</span> <span style="' . self::TPL_SHARP_STYLE . '">#</span>', $this->content); $this->content = str_replace('# ENDIF #', '<span style="' . self::TPL_SHARP_STYLE . '">#</span> <span style="' . self::TPL_KEYWORD_STYLE . '">ENDIF</span> <span style="' . self::TPL_SHARP_STYLE . '">#</span>', $this->content); //Loops $this->content = preg_replace('`# START ((?:\\w+\\.)*)(\\w+) #`i', '<span style="' . self::TPL_SHARP_STYLE . '">#</span> <span style="' . self::TPL_KEYWORD_STYLE . '">START</span> <span style="' . self::TPL_NESTED_VARIABLE_STYLE . '">$1</span><span style="' . self::TPL_VARIABLE_STYLE . '">$2</span> <span style="' . self::TPL_SHARP_STYLE . '">#</span>', $this->content); $this->content = preg_replace('`# END ((?:\\w+\\.)*)(\\w+) #`i', '<span style="' . self::TPL_SHARP_STYLE . '">#</span> <span style="' . self::TPL_KEYWORD_STYLE . '">END</span> <span style="' . self::TPL_NESTED_VARIABLE_STYLE . '">$1</span><span style="' . self::TPL_VARIABLE_STYLE . '">$2</span> <span style="' . self::TPL_SHARP_STYLE . '">#</span>', $this->content); //Inclusions $this->content = preg_replace('`# INCLUDE ((?:\\w+\\.)*)([\\w]+) #`', '<span style="' . self::TPL_SHARP_STYLE . '">#</span> <span style="' . self::TPL_KEYWORD_STYLE . '">INCLUDE </span> <span style="' . self::TPL_NESTED_VARIABLE_STYLE . '">$1</span><span style="' . self::TPL_VARIABLE_STYLE . '">$2</span> <span style="' . self::TPL_SHARP_STYLE . '">#</span>', $this->content); //Simple variable $this->content = preg_replace('`{([\\w]+)}`i', '<span style="' . self::TPL_BRACES_STYLE . '">{</span><span style="' . self::TPL_VARIABLE_STYLE . '">$1</span><span style="' . self::TPL_BRACES_STYLE . '">}</span>', $this->content); //Loop variable $this->content = preg_replace('`{((?:[\\w]+\\.)+)([\\w]+)}`i', '<span style="' . self::TPL_BRACES_STYLE . '">{</span><span style="' . self::TPL_NESTED_VARIABLE_STYLE . '">$1</span><span style="' . self::TPL_VARIABLE_STYLE . '">$2</span><span style="' . self::TPL_BRACES_STYLE . '">}</span>', $this->content); if ($inline_code) { $this->content = '<pre style="display:inline; font-color:courier new;">' . $this->content . '</pre>'; } }
function _highlight_code($contents, $language, $line_number, $inline_code) { $contents = htmlspecialchars_decode($contents); if (strtolower($language) == 'bbcode') { import('content/parser/bbcode_highlighter'); $bbcode_highlighter = new BBCodeHighlighter(); $bbcode_highlighter->set_content($contents, PARSER_DO_NOT_STRIP_SLASHES); $bbcode_highlighter->parse($inline_code); $contents = $bbcode_highlighter->get_content(DO_NOT_ADD_SLASHES); } elseif (strtolower($language) == 'tpl' || strtolower($language) == 'template') { import('content/parser/template_highlighter'); require_once PATH_TO_ROOT . '/kernel/framework/content/geshi/geshi.php'; $template_highlighter = new TemplateHighlighter(); $template_highlighter->set_content($contents, PARSER_DO_NOT_STRIP_SLASHES); $template_highlighter->parse($line_number ? GESHI_NORMAL_LINE_NUMBERS : GESHI_NO_LINE_NUMBERS, $inline_code); $contents = $template_highlighter->get_content(DO_NOT_ADD_SLASHES); } elseif ($language != '') { require_once PATH_TO_ROOT . '/kernel/framework/content/geshi/geshi.php'; $Geshi = new GeSHi($contents, $language); if ($line_number) { $Geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); } if ($inline_code) { $Geshi->set_header_type(GESHI_HEADER_NONE); } $contents = '<pre style="display:inline;">' . $Geshi->parse_code() . '</pre>'; } else { $highlight = highlight_string($contents, true); $font_replace = str_replace(array('<font ', '</font>'), array('<span ', '</span>'), $highlight); $contents = preg_replace('`color="(.*?)"`', 'style="color:$1"', $font_replace); } return $contents; }
/** * Highlight a given piece of source code. * Works for xhtml only. Falls back to original highlighter for * other formats. * * @param string $text Text to highlight * @param string $role Source code role to use (php, xml, html, ...) * @param string $format Output format (pdf, xhtml, troff, ...) * * @return string Highlighted code */ public function highlight($text, $role, $format) { $geshi = new \GeSHi($text, $role); $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); $geshi->set_header_type(GESHI_HEADER_DIV); return $geshi->parse_code(); }
function jabFormatCode($code) { @(include_once "geshi-1.0.8.6/geshi/geshi.php"); if (function_exists('geshi_highlight')) { // Strip off language specifier $language = null; if (preg_match("/^{{(.*)}}\n+/", $code, $matches)) { $language = $matches[1]; $code = preg_replace("/^{{(.*)}}\n+/", "", $code); } global $jab; if ($language == null && isset($jab['syntax_language'])) { $language = $jab['syntax_language']; } if ($language !== null) { $geshi = new GeSHi($code, $language, null); $geshi->set_header_type(GESHI_HEADER_NONE); $geshi->line_ending = "\n"; $geshi->set_comments_style(1, 'color: #008200;'); $geshi->set_comments_style('MULTI', 'color: #008200;'); $geshi->set_strings_style('color: #848200'); $geshi->set_numbers_style(''); return "<pre><code>" . $geshi->parse_code() . "</code></pre>"; } } return "<pre><code>" . htmlspecialchars($code, ENT_NOQUOTES) . "</code></pre>"; }
public function codeReplace($text) { // check if geshi available $geshiPath = dirname(__FILE__) . '/../vendor/geshi/geshi.php'; if (!file_exists($geshiPath)) { return $text; } $regexp = '@<code class="(\\w+)">(.+?)<\\/code>@s'; // replace codes if (preg_match_all($regexp, $text, $found)) { require_once $geshiPath; for ($index = 0; $index < count($found) - 1; $index++) { if (!isset($found[1][$index])) { continue; } $language = $found[1][$index]; $code = trim($found[2][$index]); $geshi = new GeSHi($code, $language); $geshi->set_header_type(GESHI_HEADER_NONE); $geshi->enable_classes(); $geshi->set_tab_width(2); $geshi->enable_keyword_links(false); if (in_array($language, array('php', 'css', 'shell', 'ruby', 'python', 'bash', 'sql')) && String::numberOfLines($code) > 5) { //$geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 2); } // replace image place holders $text = str_replace($code, $geshi->parse_code(), $text); } } return $text; }
function print_highlighted($lang) { //The GeSHI syntax highlighter is included. include_once 'geshi/geshi.php'; //The string returned is stored in a variable. $filename = get_id($_SERVER['REQUEST_URI']); //If file does not exist then it redirects the user to the home page. $file = fopen("data/{$filename}", "r") or header("Location: /"); $source = ''; while (!feof($file)) { $source = $source . fgets($file); } //The object created is passed two arguments for syntax highlighting. $geshi = new GeSHi($source, $lang); $geshi->set_overall_style('background-color: #f2f2f2; margin: 0px 35px; border: 1px dotted;', true); //$geshi->set_header_type(GESHI_HEADER_PRE_VALID); $geshi->set_header_type(GESHI_HEADER_DIV); //The flag below shows the line numbers. See GeSHI docs for more options. $flag = GESHI_FANCY_LINE_NUMBERS; $geshi->enable_line_numbers($flag); $geshi->set_line_style(' padding: 0px 15px;'); //The <pre> tags are included for maintaining the indentation. // echo "<pre>"; echo $geshi->parse_code(); // echo "</pre></div>"; return 0; }
public function renderTagCode(array $tag, array $rendererStates) { if (strtolower(strval($tag['option'])) == 'html') { $tag['option'] = 'html5'; } if (!$tag['option']) { $tag['option'] = 'text'; } $content = $this->stringifyTree($tag['children']); $content = XenForo_Helper_String::censorString($content); $geshi = new GeSHi($content, $tag['option']); if (XenForo_Application::get('options')->get('dpSyntaxHighlighterShowLines')) { $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS); } $geshi->set_link_target('_blank" rel="nofollow'); $geshi->set_header_type(GESHI_HEADER_NONE); $geshi->set_tab_width(4); $content = $geshi->parse_code(); if ($this->_view) { $template = $this->_view->createTemplateObject('dp_bb_code_tag_code', array('content' => $content, 'language' => $geshi->get_language_name())); return $template->render(); } else { return '<div style="margin: 1em auto" title="Code">' . $content . '</div>'; } }
function DoGeshi($code) { $geshi = new GeSHi(trim($code), "html4strict", null); $geshi->set_header_type(GESHI_HEADER_NONE); $geshi->enable_classes(); return "<span class=\"geshi\">" . str_replace("\n", "", $geshi->parse_code()) . "</span>"; }
function smarty_block_code($params, $content, Smarty_Internal_Template $template, $open) { if ($open) { return ''; } else { $language = isset($params['language']) ? (string) $params['language'] : null; $classes = array(); if ($language) { $classes[] = $language; } if (!empty($params['class'])) { $classes[] = $params['class']; } $content = trim($content, "\n\r"); $content = rtrim($content); $rows = preg_split("#[\n\r]#", $content); preg_match('#^\\s+#', reset($rows), $matches); if ($matches) { $whitespace = $matches[0]; foreach ($rows as &$row) { $row = preg_replace('#^' . $whitespace . '#', '', $row); } } $content = implode(PHP_EOL, $rows); $content = trim($content, "\n\r"); $geshi = new GeSHi($content, $language); $geshi->keyword_links = false; $geshi->set_tab_width(4); $geshi->set_header_type(GESHI_HEADER_NONE); return '<code class="' . implode(' ', $classes) . '">' . $geshi->parse_code() . '</code>'; } }
function source_highlighter($code) { $source = str_replace(array(">", "<", """, "&"), array(">", "<", "\"", "&"), $code[1]); if (false !== stristr($code[0], "[php]")) { $lang2geshi = "php"; } elseif (false !== stristr($code[0], "[sql]")) { $lang2geshi = "sql"; } elseif (false !== stristr($code[0], "[html]")) { $lang2geshi = "html4strict"; } else { $lang2geshi = "txt"; } $geshi = new GeSHi($source, $lang2geshi); $geshi->set_header_type(GESHI_HEADER_PRE_VALID); $geshi->set_overall_style('font: normal normal 100% monospace; color: #000066;', false); $geshi->set_line_style('color: #003030;', 'font-weight: bold; color: #006060;', true); $geshi->set_code_style('color: #000020;font-family:monospace; font-size:12px;line-height:6px;', true); //$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); $geshi->enable_classes(false); $geshi->set_link_styles(GESHI_LINK, 'color: #000060;'); $geshi->set_link_styles(GESHI_HOVER, 'background-color: #f0f000;'); $return = "<div class=\"codetop\">CODE</div><div class=\"codemain\">\n"; $return .= $geshi->parse_code(); $return .= "\n</div>\n"; return $return; }
/** * * Renders a token into text matching the requested format. * * @access public * * @param array $options The "options" portion of the token (second * element). * * @return string The text rendered from the token options. * */ function token($options) { $text = $options['text']; $attr = $options['attr']; $type = strtolower($attr['type']); $css = $this->formatConf(' class="%s"', 'css'); $css_code = $this->formatConf(' class="%s"', 'css_code'); $css_php = $this->formatConf(' class="%s"', 'css_php'); $css_html = $this->formatConf(' class="%s"', 'css_html'); $geshi_class = path::file("plugins") . "geshi/geshi.php"; if ($type != "" && file_exists(path::file("plugins") . "geshi/geshi.php") && is_readable(path::file("plugins") . "geshi/geshi.php")) { require_once path::file("plugins") . "geshi/geshi.php"; $geshi = new GeSHi(trim($text), $type, path::file("plugins") . "geshi/geshi/"); $geshi->set_encoding("utf-8"); $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS, 1); $geshi->set_header_type(GESHI_HEADER_DIV); $geshi->enable_classes(); $geshi->set_overall_class('geshi_code'); $text = $geshi->parse_code(); $style = $geshi->get_stylesheet(); global $page_handler; $style = "<style type='text/css'>\n{$style}\n</style>"; $page_handler->add_header_data($style); } else { //generic code example: //convert tabs to four spaces, //convert entities. $text = trim(htmlentities($text)); $text = str_replace("\t", " ", $text); $text = str_replace(" ", " ", $text); $text = "<code{$css_code}>{$text}</code>"; } return "\n{$text}\n\n"; }
function render_code(&$renderer, $code, $lang) { // code $renderer->doc .= "<div class=\"code_block_code\">"; $geshi = new GeSHi($code, $lang); $geshi->set_header_type(GESHI_HEADER_DIV); $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); $renderer->doc .= $geshi->parse_code(); $renderer->doc .= "</div>"; }
function markdown_code_highlighter($code, $language, $rss = false) { $code = stripslashes(trim(htmlspecialchars_decode($code, ENT_NOQUOTES))); $geshi = new GeSHi($code, $language); if ($rss == false) { $geshi->set_header_type(GESHI_HEADER_NONE); $geshi->enable_classes(); } return '<pre class="lang-' . $language . '"><code>' . $geshi->parse_code() . '</code></pre>'; }
function htmlify($filename) { ob_start(); include $filename; $html = ob_get_contents(); ob_end_clean(); $geshi = new GeSHi(trim($html), 'html5'); $geshi->set_header_type(GESHI_HEADER_PRE); $geshi->enable_keyword_links(false); echo $geshi->parse_code(); }
function handle_geshi($content, $language) { $g = new GeSHi($content, $language); $g->enable_classes(); $g->set_header_type(GESHI_HEADER_DIV); $g->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 5); #$g->set_overall_style('color:black'); $g->set_overall_id('source'); $g->set_code_style('color:black;', "'Courier New', Courier, monospace"); $g->set_line_style('color:#838383;', '', true); return $g->parse_code(); }
function highlight($code, $lang) { if ($lang == 'php-html') { return smartHighlight($code); } $geshi = new GeSHi($code, $lang); $geshi->set_header_type(GESHI_HEADER_NONE); $geshi->enable_classes(); $geshi->enable_keyword_links(false); $code = $geshi->parse_code(); return '<span class="' . $lang . '">' . $code . '</span>'; }
public function code(&$buff) { $geshi = new GeSHi($buff, $this->lang_alias($this->lang)); $geshi->set_header_type(GESHI_HEADER_PRE); $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS); $geshi->code_style = $geshi->line_style1 = ''; $geshi->keyword_links = false; $error = $geshi->error(); if ($error) { debug($error); } return '<span class="code">' . ($error ? nl2br(htmlspecialchars($buff)) : $geshi->parse_code()) . '</span>'; }
/** * Send output to browser. */ function toHTML($code_text, $parm) { global $e107cache; $class = e107::getBB()->getClass('code'); $pref = e107::getPref(); $tp = e107::getParser(); if ($pref['smiley_activate']) { if (!is_object($tp->e_emote)) { $tp->e_emote = new e_emoteFilter(); } $code_text = $tp->e_emote->filterEmotesRev($code_text); } $search = array(E_NL, '\', '$', '<'); $replace = array("\r\n", "\\", '$', '<'); $code_text = str_replace($search, $replace, $code_text); if (isset($pref['useGeshi']) && $pref['useGeshi'] && file_exists(e_PLUGIN . "geshi/geshi.php")) { $code_md5 = md5($code_text); if (!($CodeCache = $e107cache->retrieve('GeshiParsed_' . $code_md5))) { require_once e_PLUGIN . "geshi/geshi.php"; if ($parm) { $geshi = new GeSHi($code_text, $parm, e_PLUGIN . "geshi/geshi/"); } else { $geshi = new GeSHi($code_text, $pref['defaultLanGeshi'] ? $pref['defaultLanGeshi'] : 'php', e_PLUGIN . "geshi/geshi/"); } $geshi->line_style1 = "font-family: 'Courier New', Courier, monospace; font-weight: normal; font-style: normal;"; $geshi->set_encoding('utf-8'); $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); $geshi->set_header_type(GESHI_HEADER_DIV); $CodeCache = $geshi->parse_code(); $e107cache->set('GeshiParsed_' . $code_md5, $CodeCache); } $ret = "<code class='code_highlight code-box {$class}' style='unicode-bidi: embed; direction: ltr'>" . str_replace("&", "&", $CodeCache) . "</code>"; } else { $code_text = html_entity_decode($code_text, ENT_QUOTES, 'utf-8'); $code_text = trim($code_text); $code_text = htmlspecialchars($code_text, ENT_QUOTES, 'utf-8'); $srch = array('{', '}'); $repl = array('{', '}'); $code_text = str_replace($srch, $repl, $code_text); // avoid code getting parsed as templates or shortcodes. if ($parm == 'inline') { return "<code style='unicode-bidi: embed; direction: ltr'>" . $code_text . "</code>"; } // $highlighted_text = highlight_string($code_text, TRUE); // highlighted_text = str_replace(array("<code>","</code>"),"",$highlighted_text); $divClass = $parm ? $parm : 'code_highlight'; $ret = "<pre class='prettyprint linenums " . $tp->toAttribute($divClass) . " code-box {$class}' style='unicode-bidi: embed; direction: ltr'>" . $code_text . "</pre>"; } $ret = str_replace("[", "[", $ret); return $ret; }
function highlight_syntax($code, $langid) { $value = get_record('problemstatement_programming_language', 'id', $langid); if ($value) { $syntax = $value->geshi; } else { $syntax = ''; } /* switch ($langid) { case '0': $syntax='cpp'; break; case '1': $syntax='delphi'; break; case '2': $syntax='java'; break; case '3': $syntax='python'; break; case '4': $syntax='csharp'; break; }*/ $geshi = new GeSHi($code, $syntax); $geshi->set_header_type(GESHI_HEADER_DIV); // $geshi->enable_classes(true); $geshi->set_overall_style('font-family: monospace;'); $linenumbers = 1; if ($linenumbers) { $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 5); $geshi->set_line_style('color:#222;', 'color:#888;'); $geshi->set_overall_style('font-size: 14px;font-family: monospace;', true); } $urls = FALSE; $indentsize = FALSE; $inline = FALSE; if (!$urls) { for ($i = 0; $i < 5; $i++) { $geshi->set_url_for_keyword_group($i, ''); } } if ($indentsize) { $geshi->set_tab_width($indentsize); } $parsed = $geshi->parse_code(); if ($inline) { $parsed = preg_replace('/^<div/', '<span', $parsed); $parsed = preg_replace('/<\\/div>$/', '</span>', $parsed); } //return $geshi->parse_code().$syntax; $lang = get_record('problemstatement_programming_language', 'id', $langid); if (!$lang) { $lang = ''; } $comment = get_string("programwritten", "problemstatement") . $lang->language_name; //get_string("lang_".$langid, "problemstatement"); return $parsed . $comment; }
public static function output($text, $syntax = 'none') { if ($syntax == 'none') { return '<pre>' . $text . '</pre>'; } else { // Since we may be coming from another syntax highlighter, // we'll try downcasing the syntax name and hope we get lucky. $syntax = strtolower($syntax); $geshi = new GeSHi($text, $syntax); } $geshi->set_header_type(GESHI_HEADER_PRE_TABLE); $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS); return $geshi->parse_code(); }
function bbcodeCodeHighlight($contents, $arg) { include_once "geshi.php"; if (!$arg) { return '<div class="codeblock">' . htmlentities($contents) . '</div>'; } else { $language = $arg; $geshi = new GeSHi(trim($contents), $language, null); $geshi->set_header_type(GESHI_HEADER_NONE); $geshi->enable_classes(); $geshi->enable_keyword_links(false); $code = str_replace("\n", "", $geshi->parse_code()); $code = decodeCrapEntities($code); return "<div class=\"codeblock geshi\">{$code}</div>"; } }
private function highlight(&$text, $lang = 'php', $lines = false) { $geshi = new GeSHi(trim($text, "\r\n"), $lang); $geshi->enable_classes(); $geshi->set_header_type(GESHI_HEADER_PRE); $geshi->set_overall_class("code"); $geshi->set_encoding("utf-8"); // [[mw:user:Brianegge]] suggestion $geshi->set_overall_style('background: #EEEEEE; border: padding: 0.2em'); if ($lines == true or $lines == 1 or $lines == '1') { $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS); } else { $geshi->enable_line_numbers(GESHI_NO_LINE_NUMBERS); } return "<style>" . $geshi->get_stylesheet() . "</style>" . $geshi->parse_code(); }
function wp_syntax_highlight_mpdf($match) { global $wp_syntax_matches; $i = intval($match[1]); $match = $wp_syntax_matches[$i]; $language = strtolower(trim($match[1])); $line = trim($match[2]); $escaped = trim($match[3]); $code = wp_syntax_code_trim($match[4]); $code = htmlspecialchars_decode($code); $geshi = new GeSHi($code, $language); $geshi->enable_keyword_links(false); $geshi->set_header_type(GESHI_HEADER_DIV); $geshi->set_tab_width(4); do_action_ref_array('wp_syntax_init_geshi', array(&$geshi)); $output = "\n<div class=\"wp_syntax\">"; //Beim Printen immer Line numbern anmachen $line = get_option('mpdf_geshi_linenumbers'); if ($line) { $lineMode = explode("\n", $code); $output .= '<table>'; for ($i = 0; $i < count($lineMode); $i++) { $geshi->set_source($lineMode[$i]); if ($i % 2) { $output .= '<tr style="background-color: #f5f5f5;">'; } else { $output .= '<tr>'; } $output .= '<td class="line_numbers" style="vertical-align: top;">'; if (($i + 1) % 5) { $output .= $i + 1; } else { $output .= '<b>' . ($i + 1) . '</b>'; } $output .= '</td><td class="code">'; $output .= $geshi->parse_code(); $output .= '</td></tr>'; } $output .= '</table>'; } else { $output .= "<div class=\"code\">"; $output .= $geshi->parse_code(); $output .= "</div>"; } return $output .= "</div>\n"; return $output; }
function highlight_sql_query($sql) { require_once 'classes/class.geshi.php'; $path = 'classes/geshi'; $language = 'mysql'; if (!file_exists($path . '/' . $language . '.php')) { $language = 'sql'; if (!file_exists($path . '/' . $language . '.php')) { return null; } } $geshi = new GeSHi($sql, $language, $path); $geshi->enable_classes(false); $geshi->set_header_type(GESHI_HEADER_DIV); $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 5); return $geshi->parse_code(); }
/** * filter * * @param string $text * @return string */ public function filter($text) { return preg_replace_callback(self::$regex, function ($matches) { if (isset($matches[1]) && isset($matches[2])) { //we have a #lang attribute in our <code /> $language = trim($matches[1], "#\n"); $code = html_entity_decode(trim($matches[2], "\n")); $geshi = new \GeSHi($code, $language); $geshi->set_header_type(GESHI_HEADER_PRE_VALID); $geshi->set_overall_class('highlighted'); $geshi->enable_classes(); return $geshi->parse_code(); } return $matches[0]; //for some reason this went wrong }, $text); }
function bbcode_highlite($s, $language = false) { $s = base64_decode($s); if (!$language) { return '<code>' . htmlspecialchars($s, ENT_COMPAT, 'UTF-8') . '</code>'; } $geshi = new GeSHi($s, $language); $geshi->enable_classes(true); $geshi->set_header_type(GESHI_HEADER_DIV); $geshi->enable_keyword_links(false); $geshi->set_tab_width(4); $output = $geshi->parse_code(); if ($geshi->error()) { return false; } head('stylesheet', 'geshi/' . $language, 'screen'); return '<div class="geshi">' . $output . '</div>'; }
function source_highlighter($source, $lang2geshi) { require_once 'geshi/geshi.php'; $source = str_replace(array("'", ">", "<", """, "&"), array("'", ">", "<", "\"", "&"), $source); $lang2geshi = $lang2geshi == 'html' ? 'html4strict' : $lang2geshi; $geshi = new GeSHi($source, $lang2geshi); $geshi->set_header_type(GESHI_HEADER_PRE_VALID); $geshi->set_overall_style('font: normal normal 100% monospace; color: #000066;', false); $geshi->set_line_style('color: #003030;', 'font-weight: bold; color: #006060;', true); $geshi->set_code_style('color: #000020;font-family:monospace; font-size:12px;line-height:13px;', true); $geshi->enable_classes(false); $geshi->set_link_styles(GESHI_LINK, 'color: #000060;'); $geshi->set_link_styles(GESHI_HOVER, 'background-color: #f0f000;'); $return = "<div class=\"codetop\">Code</div><div class=\"codemain\">\n"; $return .= $geshi->parse_code(); $return .= "\n</div>\n"; return $return; }
/** * Highlights the passed source code as css * * @param $source */ function textsanitizer_geshi_css_highlight($source) { if (!@(include_once ICMS_LIBRARIES_PATH . '/geshi/geshi.php')) { return false; } $source = icms_core_DataFilter::undoHtmlSpecialChars($source); // Create the new GeSHi object, passing relevant stuff $geshi = new GeSHi($source, 'css'); // Enclose the code in a <div> $geshi->set_header_type(GESHI_HEADER_NONE); // Sets the proper encoding charset other than "ISO-8859-1" $geshi->set_encoding(_CHARSET); $geshi->set_link_target("_blank"); // Parse the code $code = $geshi->parse_code(); $code = "<div class=\"icmsCodeCss\"><code>" . $code . "</code></div>"; return $code; }
function task_modifier_scan_text($string) { $CI =& get_instance(); $CI->config->load('geshi'); $highlight_map = $CI->config->item('geshi_highlighting_map'); $html = str_get_html($string, true, true, DEFAULT_TARGET_CHARSET, false); foreach ($html->find('pre br') as $br) { $br->outertext = "\n"; } foreach ($html->find('pre.highlight') as $highlighted_code) { $lang = $highlighted_code->lang; if (isset($highlight_map[$lang])) { $content = str_replace(' ', ' ', htmlspecialchars_decode(strip_tags($highlighted_code->innertext), ENT_HTML5 | ENT_QUOTES)); $geshi = new GeSHi($content, $highlight_map[$lang]); $geshi->set_header_type(GESHI_HEADER_PRE_VALID); $geshi->enable_line_numbers(GESHI_NO_LINE_NUMBERS); $highlighted_code->innertext = $geshi->parse_code(); $highlighted_code->lang = null; } else { $highlighted_code->lang = null; $highlighted_code->class = null; } } ob_start(); echo $html; return ob_get_clean(); }