function bb_syntax_highlight($match) { global $bb_syntax_matches; $i = intval($match[1]); $match = $bb_syntax_matches[$i]; $language = strtolower(trim($match[1])); $line = trim($match[2]); $escaped = trim($match[3]); $code = bb_syntax_code_trim($match[4]); //if ($escaped == "true") $code = htmlspecialchars_decode($code); $code = htmlspecialchars_decode($code); //$code = str_replace("<", "<", $code); //$code = str_replace(">", ">", $code); $geshi = new GeSHi($code, $language); $geshi->enable_keyword_links(false); do_action_ref_array('bb_syntax_init_geshi', array(&$geshi)); $output = "\n<div class=\"bb_syntax\">"; if ($line) { $output .= "<table><tr><td class=\"line_numbers\">"; $output .= bb_syntax_line_numbers($code, $line); $output .= "</td><td class=\"code\">"; $output .= $geshi->parse_code(); $output .= "</td></tr></table>"; } else { $output .= "<div class=\"code\">"; $output .= $geshi->parse_code(); $output .= "</div>"; } $output .= "</div>\n"; return $output; }
public function getSyntaxHighlightedContent($content, $type) { //$content = ; //return array('<pre>' . $content . '</pre>', 'none'); //error_log("content len=" . strlen($content)); // サイズがでかすぎたら syntax highlight ナシ if (strlen($content) > 1 << 15) { error_log($content); return array('<pre>' . htmlspecialchars($content, ENT_QUOTES) . '</pre>', 'none'); } if ($type == '__pastit_type_none__') { $type = 'none'; // auto detect $first_line = explode(PHP_EOL, $content); $first_line = $first_line[0]; if (preg_match('@#!.+bin/(\\w+)@', $first_line, $m)) { $type = $m[1]; } if (preg_match('@#!.+bin/env\\s+(\\w+)@', $first_line, $m)) { $type = $m[1]; } if (preg_match('@\\+\\+\\+@', $content) && preg_match('@\\-\\-\\-@', $content)) { $type = 'diff'; } } require_once 'geshi/geshi.php'; $geshi = new GeSHi($content, $type); $geshi->set_overall_style('font-family: menlo, monaco, \'courier new\', mono-space;'); $content = $geshi->parse_code(); //return '<pre class=" superpre">' . PHP_EOL . $body . '</pre>'; return array($content, $type); }
protected function formatCodeBlocks($source){ return preg_replace_callback('/<code>([\s\S]*?)<\/code>/', function($matches){ $geshi = new GeSHi($matches[1], 'javascript'); $geshi->enable_classes(); return $geshi->parse_code(); }, $source); }
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 code($source, $language) { $code = new GeSHi($source, $language); $parse = $code->parse_code(); $resultat = '<div>' . '<br/>' . $parse . '</div>'; return $resultat; }
function _doGeshi($shebangMatch) { $language = $shebangMatch['lang']; $line = (int) ($shebangMatch['linenumber'] > 1 ? $shebangMatch['linenumber'] : 0); $codeblock = $shebangMatch['code']; $highlighter = new GeSHi($this->outdent(trim($codeblock)), $language); $highlighted = $highlighter->parse_code(); if ($line) { preg_match('!^(\\s*<pre[^>]+>)(.*)(</pre>)!s', $highlighted, $m); $ret = '<ol'; if ($line) { $ret .= ' start="' . $line . '"'; } $ret .= '>'; $ret .= preg_replace('/.+(\\n|$)/', '<li>$0</li>', $m[2]); $ret .= '</ol>'; $ret = $m[1] . $ret . $m[3]; } else { $ret = $highlighted; } if ($shebangMatch['params']) { $ret = $this->_processGeshiParams($ret, $shebangMatch['params']); } return "\n\n" . $this->hashBlock($ret) . "\n\n"; }
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 _codeBlockHighlighter($codeblock, &$clear) { $split = preg_split('/[\\r\\n]/', $codeblock, 2, PREG_SPLIT_NO_EMPTY); if (count($split) == 2 && preg_match('/^\\s*((\\\\){0,2}\\[([a-zA-Z0-9\\-_]+)\\]\\s*)/', $split[0], $matches)) { if ($matches[2] == '\\') { $codeblock = substr($codeblock, 1); return $codeblock; } $strlen = strlen($matches[0]); $parser = strtolower($matches[3]); $codeblock = $split[1]; if ($strlen > 0) { if ($parser == 'console') { $codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES); $codeblock = preg_replace_callback('/^\\n+/', array($this, '_doFencedCodeBlocks_newlines'), $codeblock); $codeblock = "<pre class=\"console\"><code>{$codeblock}</code></pre>"; } else { $codeblock = preg_replace('/\\n+$/', '', $codeblock); $geshi = new GeSHi($codeblock, $parser); $geshi->set_overall_style(''); $codeblock = $geshi->parse_code(); } $clear = false; } } return $codeblock; }
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 JHP_Geshi_replacer(&$matches) { // print_r($matches); //// die(); jimport('geshi.geshi'); jimport('domit.xml_saxy_shared'); $args = SAXY_Parser_Base::parseAttributes($matches[1]); // print_r($args); $text = $matches[2]; $lang = JArrayHelper::getValue($args, 'lang', 'phpz'); $lines = JArrayHelper::getValue($args, 'lines', 'true'); $html_entities_match = array("|\\<br \\/\\>|", "#<#", "#>#", "|'|", '#"#', '# #'); $html_entities_replace = array("\n", '<', '>', "'", '"', ' '); $text = preg_replace($html_entities_match, $html_entities_replace, $text); $text = str_replace('<', '<', $text); $text = str_replace('>', '>', $text); $text = str_replace("\t", ' ', $text); $geshi = new GeSHi($text, $lang); if ($lines == 'true') { $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS); } $text = $geshi->parse_code(); $text = '???' . $text . '???'; return $text; }
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; }
/** * Replaces the matched tags an image * @param array An array of matches (see preg_match_all) * @return string */ function plgContentGeshi_replacer(&$matches) { $params =& $GLOBALS['_MAMBOT_GESHI_PARAMS']; jimport('geshi.geshi'); jimport('domit.xml_saxy_shared'); $args = SAXY_Parser_Base::parseAttributes($matches[1]); $text = $matches[2]; $lang = JArrayHelper::getValue($args, 'lang', 'php'); $lines = JArrayHelper::getValue($args, 'lines', 'false'); $html_entities_match = array("|\\<br \\/\\>|", "#<#", "#>#", "|'|", '#"#', '# #'); $html_entities_replace = array("\n", '<', '>', "'", '"', ' '); $text = preg_replace($html_entities_match, $html_entities_replace, $text); $text = str_replace('<', '<', $text); $text = str_replace('>', '>', $text); /* // Replace 2 spaces with " " so non-tabbed code indents without making huge long lines. $text = str_replace(" ", " ", $text); // now Replace 2 spaces with " " to catch odd #s of spaces. $text = str_replace(" ", " ", $text); */ // Replace tabs with " " so tabbed code indents sorta right without making huge long lines. //$text = str_replace("\t", " ", $text); $text = str_replace("\t", ' ', $text); $geshi = new GeSHi($text, $lang); if ($lines == 'true') { $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); } $text = $geshi->parse_code(); return $text; }
function wp_syntax_highlight($match) { global $wp_syntax_matches; $i = intval($match[1]); $match = $wp_syntax_matches[$i]; $language = strtolower(trim($match[1])); $line = trim($match[2]); $code = wp_syntax_code_trim($match[3]); $geshi = new GeSHi($code, $language); $geshi->enable_keyword_links(false); do_action_ref_array('wp_syntax_init_geshi', array(&$geshi)); $output = "\n<div class=\"wp_syntax\">"; if ($line) { $output .= "<table><tr><td class=\"line_numbers\">"; $output .= wp_syntax_line_numbers($code, $line); $output .= "</td><td class=\"code\">"; $output .= $geshi->parse_code(); $output .= "</td></tr></table>"; } else { $output .= "<div class=\"code\">"; $output .= $geshi->parse_code(); $output .= "</div>"; } return $output .= "</div>\n"; return $output; }
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; }
/** * 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 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>'; } }
/** * * 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"; }
/** * Format the content of this snippet with GeSHi and return the output. * @return string Formatted code output */ function getFormattedOutput() { require_once dirname(__DIR__) . '/thirdparty/geshi/geshi.php'; $g = new GeSHi($this->Code, $this->Language); $g->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS); return $g->parse_code(); }
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; }
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 syntaxHighlight($matches) { $geshi = new GeSHi($matches[3], empty($matches[2]) ? "txt" : $matches[2]); $geshi->enable_classes(); $geshi->set_overall_style(""); // empty style return $geshi->parse_code(); }
/** * @param string $sContent * @param string $sLanguage * @return string */ public function parseGeshi($sContent, $sLanguage, $bUseClasses = false) { $oGeshi = new \GeSHi($sContent, $sLanguage); if ($bUseClasses) { $oGeshi->enable_classes(); } return $oGeshi->parse_code(); }
public static function codeShortcode($options, $content) { include_once __DIR__ . '/vendor/geshi-1.0.8.15/geshi.php'; $name = empty($options[0]) ? 'text' : $options[0]; $geshi = new GeSHi(trim($content), $name); #$geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS); return sprintf('<div class="highlight highlight-%s">%s</div>', $name, $geshi->parse_code()); }
/** * Highlight code with style * * @param string $value Full source text * * @return string */ public function highlightCode($value) { $text = preg_replace_callback(self::$pattern, function ($data) { $geshi = new \GeSHi($data[2], $data[1]); return $geshi->parse_code(); }, $value); return $text; }
public function getFormatedCode(){ $content=$this->content(); $content=str_replace(array("<", ">", '&', ''', '"','<', '>'), array("<", ">",'&','\'','"','<','>'), htmlspecialchars_decode($content, ENT_NOQUOTES)); $geshi = new GeSHi($content, $this->codeLanguage); $value= $geshi->parse_code(); return ($value); }
/** * Compiles the node to PHP. * * @param \Twig_Compiler A Twig_Compiler instance */ public function compile(\Twig_Compiler $compiler) { $source = trim($this->getNode('body')->getAttribute('data')); $name = $this->getAttribute('name'); $geshi = new \GeSHi($source, $name); #$geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS); $parsedCode = sprintf('<div class="highlight highlight-%s">%s</div>', $name, $geshi->parse_code()); $compiler->addDebugInfo($this)->write('echo ')->string($parsedCode)->raw(";\n"); }
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 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(); }