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 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; }
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(); } }
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; }
static function generic_render_code($source, $lang, $line_numbers = false) { require_once self::$geshi_file; $geshi = new GeSHi($source, $lang); if ($line_numbers) { $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); } $geshi->enable_keyword_links(false); return $geshi->parse_code(); }
public function register(Application $app) { $app['geshi'] = function () use($app) { $geshi = new \GeSHi(); $geshi->enable_classes(); // this must be the first method (see Geshi doc) $geshi->set_encoding($app['app.charset']); $geshi->enable_line_numbers(GESHI_NO_LINE_NUMBERS); $geshi->enable_keyword_links(false); return $geshi; }; }
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>'; }
/** * Ссылки на документацию * * @return Code */ protected function setLinks() { if (isset($this->attributes['links'])) { if ('1' === $this->attributes['links'] || 'true' === $this->attributes['links']) { $this->geshi->enable_keyword_links(true); } else { $this->geshi->enable_keyword_links(false); } } else { $this->geshi->enable_keyword_links($this->getKeywordLinks()); } return $this; }
protected function callGeshi($text, $language) { if ($language == 'html') { $language = 'html4strict'; } $text = html_entity_decode($text); $geshi = new GeSHi($text, $language); $geshi->enable_classes(); // disable links on PHP functions, HTML tags, ... $geshi->enable_keyword_links(false); $ret = @$geshi->parse_code(); //fix extra space at bottom return str_replace(" </pre>", "</pre>", $ret); }
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>"; } }
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 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]); $escaped = trim($match[3]); $code = wp_syntax_code_trim($match[5]); if ($escaped == "true") { $code = htmlspecialchars_decode($code); } $geshi = new GeSHi($code, $language); $geshi->enable_keyword_links(false); do_action_ref_array('wp_syntax_init_geshi', array(&$geshi)); //START LINE HIGHLIGHT SUPPORT $highlight = array(); if (!empty($match[4])) { $highlight = strpos($match[4], ',') == false ? array($match[4]) : explode(',', $match[4]); $h_lines = array(); for ($i = 0; $i < sizeof($highlight); $i++) { $h_range = explode('-', $highlight[$i]); if (sizeof($h_range) == 2) { $h_lines = array_merge($h_lines, range($h_range[0], $h_range[1])); } else { array_push($h_lines, $highlight[$i]); } } $geshi->highlight_lines_extra($h_lines); } //END LINE HIGHLIGHT SUPPORT $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 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); $geshi->enable_keyword_links(false); return $geshi->parse_code(); }
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 bbcodeCodeHighlight($dom, $contents, $arg) { // in <pre> style $contents = preg_replace('/^\\n|\\n$/', "", $contents); include_once "geshi.php"; if (!$arg) { $div = $dom->createElement('div'); $div->setAttribute('class', 'codeblock'); $div->appendChild($dom->createTextNode($contents)); return $div; } else { $language = $arg; $geshi = new GeSHi($contents, $language); $geshi->set_header_type(GESHI_HEADER_NONE); $geshi->enable_classes(); $geshi->enable_keyword_links(false); $code = str_replace("\n", "", $geshi->parse_code()); return markupToMarkup($dom, "<div class=\"codeblock geshi\">{$code}</div>"); } }
function onParseContentBlock($page, $name, $text, $shortcut) { $output = NULL; if (!empty($name) && !$shortcut) { list($language, $lineNumber, $class, $id) = $this->getHighlightInfo($name); if (!empty($language)) { $geshi = new GeSHi(trim($text), $language); $geshi->set_language_path($this->yellow->config->get("pluginDir") . "/highlight/"); $geshi->set_header_type(GESHI_HEADER_PRE_TABLE); $geshi->set_overall_class($class); $geshi->set_overall_id($id); $geshi->enable_line_numbers($lineNumber ? GESHI_NORMAL_LINE_NUMBERS : GESHI_NO_LINE_NUMBERS); $geshi->start_line_numbers_at($lineNumber); $geshi->enable_classes(true); $geshi->enable_keyword_links(false); $output = $geshi->parse_code(); $output = preg_replace("#<pre(.*?)>(.+?)</pre>#s", "<pre\$1><code>\$2</code></pre>", $output); } } return $output; }
function pretty_file($file, $language, $startline = 0, $endline = 0, $number = false) { if (!$file) { return false; } $s = read_file($file, $startline, $endline); if (!$s) { return false; } if (!$language) { return $s; } $output = false; switch ($language) { case 'plain': $s = preg_replace("/\\]\\=\\>\n(\\s+)/m", "] => ", $s); $s = htmlentities($s, ENT_COMPAT, 'UTF-8'); $output = '<pre class="plain">' . PHP_EOL . $s . '</pre>' . PHP_EOL; break; default: $geshi = new GeSHi($s, $language); $geshi->enable_classes(true); $geshi->set_header_type(GESHI_HEADER_DIV); if ($number) { $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); $geshi->start_line_numbers_at($startline > 0 ? $startline : 1); } $geshi->enable_keyword_links(false); $geshi->set_tab_width(4); // echo '<pre>' . PHP_EOL .$geshi->get_stylesheet( ). '</pre>' . PHP_EOL; $output = $geshi->parse_code(); if ($geshi->error()) { return false; } } return $output; }
function render_example($src) { $geshi = new GeSHi(join('', file($src)), "php"); $geshi->enable_keyword_links(false); print "<div class='example'>"; print "<div class='example_code_title'>Code</div>"; print "<div class='example_code'>" . $geshi->parse_code() . "</div>"; print "<div class='example_output_title'>Output</div>"; print "<div class='example_output'>"; include $src; print "</div>"; print "</div>"; }
/** * Process a <code> tag */ private function syntax_highlight($match) { $code = $this->trim($match[2]); // process the match as somewhat XML $element = new SimpleXMLElement("<code{$match[1]}></code>"); $attributes = $element->attributes(); // Make sure Syntax isn't turned off if (isset($attributes['syntax']) && mb_strtolower($attributes['syntax']) == 'off') { return $match[0]; } // Get language $lang = isset($attributes['syntax']['lang']) ? $attributes['syntax']['lang'] : false; if (!$lang) { $lang = Options::get('syntax__default_lang'); } $lang = preg_replace('#[^a-zA-Z0-9\\-_]#', '', $lang); // should we do line highlighting $line = isset($attributes['syntax']['lines']) ? $attributes['syntax']['lines'] : isset($attributes['syntax']['line']) ? $attributes['syntax']['line'] : false; if (!$line) { $line = Options::get('syntax__line_numbers') ? 'on' : 'off'; } // Turn off error reporting $er = error_reporting(); error_reporting(0); // We need to include this here... // YOU CAN REMOVE THIS IF YOU HAVE GeSHi in your user/classes if (!class_exists('GeSHi')) { require_once dirname(__FILE__) . '/geshi.php'; } // Start GeSHi $geshi = new GeSHi($code, $lang); // we enable classes and use a stylehseet, // saves output time $geshi->enable_classes(true); $geshi->enable_keyword_links(false); $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS, 5); //$geshi->enable_line_numbers( GESHI_FANCY_LINE_NUMBERS, 5 ); // remove PRE default style $geshi->set_overall_style('', false); $parsed = $geshi->parse_code(); error_reporting($er); // create output $output = ""; $count = count(explode("\n", $code)); if ($line == 'on' && $count > 1) { $output .= "<table><tr><td class=\"line_numbers\"><pre>"; $this->line_numbers($code, $output, $count, Options::get('syntax__start_on_one')); $output .= "</pre></td><td class=\"code\">{$parsed}</td></tr></table>"; } else { $output .= $parsed; } return "<div class=\"syntax_highlight\">{$output}</div>"; }
function wp_codebox_highlight_geshi ($match) { global $codeid, $post; $codeid ++; //get option from DB $cb_plain_txt = get_option("cb_plain_txt"); $cb_line = get_option("cb_line"); $cb_colla = get_option("cb_colla"); $cb_wrap_over = get_option("cb_wrap_over"); $cb_highlight = get_option("cb_highlight"); $cb_strict = get_option("cb_strict"); $cb_caps = get_option("cb_caps"); $cb_tab_width = intval(get_option("cb_tab_width")); $cb_keywords_link = get_option("cb_keywords_link"); if ($match[1]) { $language = strtolower(trim($match[1])); } else { $language = "text"; } $line = trim($match[4]); $file = trim($match[2]); $colla = trim($match[3]); $code = wp_codebox_code_trim($match[5]); $is_windowsie = wp_codebox_is_windowsie(); $geshi = new GeSHi($code, $language); $geshi->enable_keyword_links($cb_keywords_link); $geshi->set_case_keywords($cb_caps); $geshi->set_tab_width($cb_tab_width); $geshi->enable_strict_mode($cb_strict); do_action_ref_array('wp_codebox_init_geshi', array(&$geshi)); $output = "\n"; if (! ($cb_plain_txt)) { $output .= "<div class=\"wp_codebox_msgheader"; if (($cb_colla && (! ($colla == "+"))) || ($colla == "-")) { $output .= " wp_codebox_hide"; } $output .= "\">"; $output .= "<span class=\"right\">"; $output .= "<sup><a href=\"http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples\" target=\"_blank\" title=\"WP-CodeBox HowTo?\"><span style=\"color: #99cc00\">?</span></a></sup>"; if ($is_windowsie) { $output .= "<a href=\"javascript:;\" onclick=\"copycode('p" . $post->ID . "code" . $codeid . "');\">" . __('[Copy to clipboard]', 'wp-codebox') . "</a>"; } /* $output .= "<a href=\"javascript:;\" onclick=\"toggle_collapse('p".$post->ID.$codeid."');\">[<span id=\"p".$post->ID.$codeid."_symbol\">"; if (($cb_colla && (!($colla == "+"))) || ($colla == "-")){$output .= "+";} else {$output.= "-";} $output .= "</span>]</a>"; */ $output .= "</span>"; if ($file) { $output .= "<span class=\"left2\">" . __('Download', 'wp-codebox') . ' <a href="' . get_bloginfo('wpurl') . '/wp-content/plugins/wp-codebox/wp-codebox.php?p=' . $post->ID . '&download=' . wp_specialchars($file) . '">' . wp_specialchars($file) . '</a>'; } else { $output .= "<span class=\"left\">" . "<a href=\"javascript:;\" onclick=\"javascript:showCodeTxt('p" . $post->ID . "code" . $codeid . "'); return false;\">" . __('View Code', 'wp-codebox') . "</a> " . strtoupper($language); } $output .= "</span><div class=\"codebox_clear\"></div></div>"; } $output .= "<div class=\"wp_codebox\">"; $output .= "<table>"; $output .= "<tr "; $output .= "id=\"p" . $post->ID . $codeid . "\">"; if ($cb_line && (! ($line))) $line = "1"; if (($line) && (! ($line == "n"))) { $output .= "<td class=\"line_numbers\">"; $output .= wp_codebox_line_numbers($code, $line); $output .= "</td>"; } $output .= "<td class=\"code\" id=\"p" . $post->ID . "code" . $codeid . "\">"; $output .= $geshi->parse_code(); $output .= "</td></tr></table></div>\n"; return $output; }
static function texyBlockHandler($invocation, $blocktype, $content, $lang, $modifier) { if ($blocktype !== 'block/code') { return $invocation->proceed(); } $texy = $invocation->getTexy(); if ($lang == 'html') { $lang = 'html4strict'; } elseif ($lang == 'yaml') { $lang = 'python'; } $content = Texy::outdent($content); $geshi = new GeSHi($content, $lang); // GeSHi could not find the language if ($geshi->error) { return $invocation->proceed(); } // do syntax-highlighting $geshi->set_encoding('UTF-8'); $geshi->set_header_type(GESHI_HEADER_PRE); $geshi->enable_classes(); $geshi->enable_keyword_links(false); $geshi->set_overall_style(''); $geshi->set_overall_class('code'); // save generated stylesheet $content = $geshi->parse_code(); // check buggy GESHI, it sometimes produce not UTF-8 valid code :-(( $content = iconv('UTF-8', 'UTF-8//IGNORE', $content); // protect output is in HTML $content = $texy->protect($content, Texy::CONTENT_BLOCK); $el = TexyHtml::el(); $el->setText($content); return $el; }
/** * Initialise a GeSHi object to format some code, performing * common setup for all our uses of it * * @param string $text * @param string $lang * @return GeSHi */ private static function prepare($text, $lang) { self::initialise(); $geshi = new GeSHi($text, $lang); if ($geshi->error() == GESHI_ERROR_NO_SUCH_LANG) { return null; } $geshi->set_encoding('UTF-8'); $geshi->enable_classes(); $geshi->set_overall_class("source-{$lang}"); $geshi->enable_keyword_links(false); return $geshi; }
/** * Initialise a GeSHi object to format some code, performing * common setup for all our uses of it * * @param string $text * @param string $lang * @return GeSHi */ public static function prepare($text, $lang) { global $wgSyntaxHighlightKeywordLinks; self::initialise(); $geshi = new GeSHi($text, $lang); if ($geshi->error() == GESHI_ERROR_NO_SUCH_LANG) { return null; } $geshi->set_encoding('UTF-8'); $geshi->enable_classes(); $geshi->set_overall_class("source-{$lang}"); $geshi->enable_keyword_links($wgSyntaxHighlightKeywordLinks); // If the source code is over 100 kB, disable higlighting of symbols. // If over 200 kB, disable highlighting of strings too. $bytes = strlen($text); if ($bytes > 102400) { $geshi->set_symbols_highlighting(false); if ($bytes > 204800) { $geshi->set_strings_highlighting(false); } } /** * GeSHi comes by default with a font-family set to monospace, which * causes the font-size to be smaller than one would expect. * We append a CSS hack to the default GeSHi styles: specifying 'monospace' * twice "resets" the browser font-size specified for monospace. * * The hack is documented in MediaWiki core under * docs/uidesign/monospace.html and in bug 33496. */ // Preserve default since we don't want to override the other style // properties set by geshi (padding, font-size, vertical-align etc.) $geshi->set_code_style('font-family: monospace, monospace;', true); // No need to preserve default (which is just "font-family: monospace;") // outputting both is unnecessary $geshi->set_overall_style('font-family: monospace, monospace;', false); return $geshi; }
/** * @param string $type * @param string $text * @param string $language */ function _highlight($type, $text, $language = null) { $style_name = $this->styleset->getStyleName('source code'); if ($type == "file") { $style_name = $this->styleset->getStyleName('source file'); } if (is_null($language)) { $this->_preformatted($text, $style_name); return; } // from inc/parserutils.php:p_xhtml_cached_geshi() $geshi = new GeSHi($text, $language, DOKU_INC . 'inc/geshi'); $geshi->set_encoding('utf-8'); // $geshi->enable_classes(); DO NOT WANT ! $geshi->set_header_type(GESHI_HEADER_PRE); $geshi->enable_keyword_links(false); // remove GeSHi's wrapper element (we'll replace it with our own later) // we need to use a GeSHi wrapper to avoid <BR> throughout the highlighted text $highlighted_code = trim(preg_replace('!^<pre[^>]*>|</pre>$!', '', $geshi->parse_code()), "\n\r"); // remove useless leading and trailing whitespace-newlines $highlighted_code = preg_replace('/^ \\n/', '', $highlighted_code); $highlighted_code = preg_replace('/\\n $/', '', $highlighted_code); // replace styles $highlighted_code = str_replace("</span>", "</text:span>", $highlighted_code); $highlighted_code = preg_replace_callback('/<span style="([^"]+)">/', array($this, '_convert_css_styles'), $highlighted_code); // cleanup leftover span tags $highlighted_code = preg_replace('/<span[^>]*>/', "<text:span>", $highlighted_code); $highlighted_code = str_replace(" ", " ", $highlighted_code); $this->_preformatted($highlighted_code, $style_name, false); }
/** * Initialise a GeSHi object to format some code, performing * common setup for all our uses of it * * @note Used only until MW 1.20 * * @param string $text * @param string $lang * @return GeSHi */ public static function prepare( $text, $lang ) { global $wgSyntaxHighlightKeywordLinks; self::initialise(); $geshi = new GeSHi( $text, $lang ); if( $geshi->error() == GESHI_ERROR_NO_SUCH_LANG ) { return null; } $geshi->set_encoding( 'UTF-8' ); $geshi->enable_classes(); $geshi->set_overall_class( "source-$lang" ); $geshi->enable_keyword_links( $wgSyntaxHighlightKeywordLinks ); // If the source code is over 100 kB, disable higlighting of symbols. // If over 200 kB, disable highlighting of strings too. $bytes = strlen( $text ); if ( $bytes > 102400 ) { $geshi->set_symbols_highlighting( false ); if ( $bytes > 204800 ) { $geshi->set_strings_highlighting( false ); } } return $geshi; }
/** * Initialise a GeSHi object to format some code, performing * common setup for all our uses of it * * @param string $text * @param string $lang * @return GeSHi */ public static function prepare($text, $lang) { global $wgTitle, $wgOut; self::initialise(); $geshi = new GeSHi($text, $lang); if ($geshi->error() == GESHI_ERROR_NO_SUCH_LANG) { return null; } $geshi->set_encoding('UTF-8'); $geshi->enable_classes(); $geshi->set_overall_class("source-{$lang}"); $geshi->enable_keyword_links(false); // Wikia change start if ($wgTitle instanceof Title && EditPageLayoutHelper::isCodeSyntaxHighlightingEnabled($wgTitle)) { $theme = 'solarized-light'; if (SassUtil::isThemeDark()) { $theme = 'solarized-dark'; } $geshi->set_language_path(GESHI_ROOT . $theme . DIRECTORY_SEPARATOR); $geshi->set_overall_id('theme-' . $theme); $wgOut->addStyle(AssetsManager::getInstance()->getSassCommonURL('extensions/SyntaxHighlight_GeSHi/styles/solarized.scss')); } // Wikia change end return $geshi; }
<?php error_reporting(1); header('Content-Type:text/plain; charset=utf-8'); if (!empty($_POST['UGC']) && !empty($_POST['UGL'])) { include_once dirname(__FILE__) . '/geshi.php'; if (get_magic_quotes_gpc()) { $_POST['UGC'] = stripslashes($_POST['UGC']); } $_POST['UGC'] = stripslashes($_POST['UGC']); $_POST['UGL'] = strtolower($_POST['UGL']); $GeSHi = new GeSHi($_POST['UGC'], $_POST['UGL']); //$GeSHi->enable_classes(); $GeSHi->set_header_type(GESHI_HEADER_NONE); $GeSHi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); $GeSHi->enable_keyword_links(false); $GeSHi->set_overall_style(''); $GeSHi->set_tab_width(4); echo $GeSHi->parse_code(); }
protected static function getGeshi($text, $language) { if ('html' == $language) { $language = 'html4strict'; } $geshi = new GeSHi($text, $language); $geshi->enable_classes(); // disable links on PHP functions, HTML tags, ... $geshi->enable_keyword_links(false); return @$geshi->parse_code(); }
/** * @param KunenaBBCode $bbcode * @param $action * @param $name * @param $default * @param $params * @param $content * @return bool|string */ function DoCode($bbcode, $action, $name, $default, $params, $content) { if ($action == BBCODE_CHECK) { return true; } $type = isset($params["type"]) ? $params["type"] : "php"; if ($type == 'js') { $type = 'javascript'; } elseif ($type == 'html') { $type = 'html4strict'; } $highlight = KunenaFactory::getConfig()->highlightcode && empty($bbcode->parent->forceMinimal); if ($highlight && !class_exists('GeSHi')) { $paths = array(JPATH_ROOT . '/plugins/content/geshiall/geshi/geshi.php', JPATH_ROOT . '/plugins/content/geshi/geshi/geshi.php'); foreach ($paths as $path) { if (!class_exists('GeSHi') && file_exists($path)) { require_once $path; } } } if ($highlight && class_exists('GeSHi')) { $geshi = new GeSHi($bbcode->UnHTMLEncode($content), $type); $geshi->enable_keyword_links(false); $code = $geshi->parse_code(); } else { $type = preg_replace('/[^A-Z0-9_\\.-]/i', '', $type); $code = '<pre xml:' . $type . '>' . $content . '</pre>'; } return '<div class="highlight">' . $code . '</div>'; }
/** * Easy way to highlight stuff. Behaves just like highlight_string * * @param string The code to highlight * @param string The language to highlight the code in * @param string The path to the language files. You can leave this blank if you need * as from version 1.0.7 the path should be automatically detected * @param boolean Whether to return the result or to echo * @return string The code highlighted (if $return is true) * @since 1.0.2 */ function geshi_highlight($string, $language, $path = null, $return = false) { $geshi = new GeSHi($string, $language, $path); $geshi->set_header_type(GESHI_HEADER_PRE_VALID); $geshi->enable_classes(); $geshi->enable_keyword_links(false); $geshi->highlight_lines_extra(array(8, 9, 10, 11, 13, 14, 15, 16, 18, 19, 24, 32, 80)); if ($return) { return '<code>' . $geshi->parse_code() . '</code>'; } echo '<code>' . $geshi->parse_code() . '</code>'; if ($geshi->error()) { return false; } return true; }