本文整理汇总了PHP中GeSHi::set_encoding方法的典型用法代码示例。如果您正苦于以下问题:PHP GeSHi::set_encoding方法的具体用法?PHP GeSHi::set_encoding怎么用?PHP GeSHi::set_encoding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GeSHi
的用法示例。
在下文中一共展示了GeSHi::set_encoding方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load
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();
}
}
示例2: token
/**
*
* 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";
}
示例3: register
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;
};
}
示例4: toHTML
/**
* 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;
}
示例5: textsanitizer_geshi_css_highlight
/**
* 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;
}
示例6: GeSHi
function ch_highlight_code($matches)
{
global $ch_options;
// undo nl and p formatting
$plancode = $matches[2];
$plancode = $this->entodec($plancode);
$geshi = new GeSHi($plancode, strtolower($matches[1]));
$geshi->set_encoding('utf-8');
$geshi->set_header_type(GESHI_HEADER_DIV);
$geshi->enable_classes(true);
$language = $geshi->get_language_name();
if ($language == 'PHP') {
$geshi->add_keyword(2, 'protected');
$geshi->add_keyword(2, 'private');
$geshi->add_keyword(2, 'abstract');
$geshi->add_keyword(2, 'static');
$geshi->add_keyword(2, 'final');
$geshi->add_keyword(2, 'implements');
} elseif ($language == 'Bash') {
$geshi->add_keyword(2, 'convert');
$geshi->add_keyword(2, 'git');
} elseif ($language == 'Vim Script') {
$geshi->add_keyword(1, 'endfunction');
}
if (ch_go('ch_b_linenumber')) {
$geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS);
}
$geshi->enable_strict_mode(ch_go('ch_b_strict_mode'));
$geshi->set_tab_width(ch_go('ch_in_tab_width'));
$geshi->set_overall_class('dean_ch');
$overall_style = '';
if (!ch_go("ch_b_wrap_text")) {
$overall_style .= 'white-space: nowrap;';
} else {
$overall_style .= 'white-space: wrap;';
}
if ($overall_style != '') {
$geshi->set_overall_style($overall_style, false);
}
return $geshi->parse_code();
}
示例7: blockHandler
/**
* User handler for code block
*
* @param TexyHandlerInvocation handler invocation
* @param string block type
* @param string text to highlight
* @param string language
* @param TexyModifier modifier
* @return TexyHtml
*/
function blockHandler($invocation, $blocktype, $content, $lang, $modifier)
{
if ($blocktype !== 'block/code') {
return $invocation->proceed();
}
$texy = $invocation->getTexy();
global $geshiPath;
if ($lang == 'html') {
$lang = 'html4strict';
}
$content = Texy::outdent($content);
$geshi = new GeSHi($content, $lang, $geshiPath . 'geshi/');
// 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->set_overall_style('color: #000066; border: 1px solid #d0d0d0; background-color: #f0f0f0;', true);
$geshi->set_line_style('font: normal normal 95% \'Courier New\', Courier, monospace; color: #003030;', 'font-weight: bold; color: #006060;', true);
$geshi->set_code_style('color: #000020;', 'color: #000020;');
$geshi->set_link_styles(GESHI_LINK, 'color: #000060;');
$geshi->set_link_styles(GESHI_HOVER, 'background-color: #f0f000;');
// save generated stylesheet
$texy->styleSheet .= $geshi->get_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;
}
示例8: prepare
/**
* 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;
}
示例9: highlight
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();
}
示例10: dirname
//.........这里部分代码省略.........
} else {
$error = TRUE;
}
} else {
// use GeSHi 1.0
include_once dirname(__FILE__) . '/geshi-1.0/geshi.php';
// highlight code according to type setting, default to php
$geshi = new GeSHi($not_geshified, $match['type'] !== NULL ? $match['type'] : $this->settings['default_type']);
$str_error = $geshi->error();
if (empty($str_error)) {
// enable line numbers
$number_style = !empty($match['line']) ? $match['line'] : $this->settings['default_line'];
switch (strtolower(preg_replace('/\\d+/', '', $number_style))) {
case 'normal':
$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
break;
case 'fancy':
$geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, (int) preg_replace('/[^\\d]*/', '', $number_style));
break;
case 'none':
$geshi->enable_line_numbers(GESHI_NO_LINE_NUMBERS);
break;
}
// set first line number
if ($match['start']) {
$geshi->start_line_numbers_at($match['start']);
}
// set strict mode
if ($match['strict']) {
$geshi->enable_strict_mode(TRUE);
}
// enable or disable keyword links
$geshi->enable_keyword_links((bool) ($match['keyword_links'] !== NULL) ? $match['keyword_links'] : $this->settings['keyword_links']);
// set overall class name
if ($match['overall_class'] != NULL) {
$geshi->set_overall_class($match['overall_class']);
}
// set overall id
if ($match['overall_id'] != NULL) {
$geshi->set_overall_id($match['overall_id']);
}
// set header type
switch ($this->settings['geshi_header_type']) {
case 'div':
$geshi->set_header_type(GESHI_HEADER_DIV);
break;
case 'pre':
$geshi->set_header_type(GESHI_HEADER_PRE);
break;
case 'pre-valid':
$geshi->set_header_type(GESHI_HEADER_PRE_VALID);
break;
case 'pre-table':
$geshi->set_header_type(GESHI_HEADER_PRE_TABLE);
break;
case 'none':
$geshi->set_header_type(GESHI_HEADER_NONE);
break;
}
// set encoding (for legacy reasons afaik)
$geshi->set_encoding($this->settings['geshi_encoding']);
// parse the source code
$geshified = $geshi->parse_code();
} else {
$error = TRUE;
}
}
if (!file_exists($cache_dir . $md5) && is_writable($cache_dir) || file_exists($cache_dir . $md5) && is_writable($cache_dir . $md5)) {
if (!$error) {
// we can write to the cache file
if (is_callable('file_put_contents')) {
file_put_contents($cache_dir . $md5, $geshified);
@chmod($cache_dir . $md5, 0777);
} else {
// when will you guys finally drop PHP4 support?
$f = fopen($cache_dir . $md5, 'w');
fwrite($f, $geshified);
fclose($f);
@chmod($cache_dir . $md5, 0777);
}
}
} else {
// We could ignore that, but for performance reasons better warn the user.
print '<b>Warning</b>: Your <i>' . $this->name . '</i> cache directory <b>' . $cache_dir . '</b> is not writable! This will cause severe performance problems, so I suggest you chmod that dir.';
}
}
// save replacement to cache and mark location with an identifier for later replacement
if (!isset($_SESSION['cache']['ext.geshify'])) {
$_SESSION['cache']['ext.geshify'] = array();
}
if (!$error) {
$_SESSION['cache']['ext.geshify'][$md5] = $geshified;
$str = substr($str, 0, $code_pos) . $md5 . substr($str, $code_end_pos + $rllen);
}
}
// unset used variables, so we don't get messed up
unset($code_pos, $code_end_pos, $md5, $geshified, $not_geshified, $geshi, $match, $ident, $error);
}
return $str;
}
示例11: eval
}
$sourcecode = $codeObj->get();
$sourcecode['source'] = html_entity_decode($sourcecode['source'], ENT_QUOTES);
($code = $plugins->load('popup_hlcode_start')) ? eval($code) : null;
if ($_GET['temp'] == 1) {
viscacha_header('Content-Type: text/plain');
viscacha_header('Content-Length: ' . strlen($sourcecode['source']));
viscacha_header('Content-Disposition: attachment; filename="' . date('d-m-Y_H-i') . '.txt"');
echo $sourcecode['source'];
$slog->updatelogged();
$db->close();
exit;
} else {
require_once 'classes/class.geshi.php';
$geshi = new GeSHi($sourcecode['source'], strtolower($sourcecode['language']), 'classes/geshi');
$geshi->set_encoding($lang->phrase('charset'));
// Use classes for colouring
$geshi->enable_classes();
// Output in a div instead in a pre-element
$geshi->set_header_type(GESHI_HEADER_DIV);
// Linenumbers on - each 5th element is bold
$geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 5);
$lang_name = $geshi->get_language_name();
// Print Stylesheet
$htmlhead .= '<style type="text/css"><!-- ' . $geshi->get_stylesheet() . ' --></style>';
echo $tpl->parse("popup/header");
($code = $plugins->load('popup_hlcode_initialized')) ? eval($code) : null;
$sourcecode['hl'] = $geshi->parse_code();
echo $tpl->parse("popup/hlcode");
($code = $plugins->load('popup_hlcode_end')) ? eval($code) : null;
}
示例12: prepare
/**
* 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;
}
示例13: execAction
function execAction($dir, $item)
{
// show file contents
global $action;
if (@eregi($GLOBALS["images_ext"], $item)) {
$html = '<img src="' . make_link('get_image', $dir, rawurlencode($item)) . '" alt="' . $GLOBALS["messages"]["actview"] . ": " . $item . '" /><br /><br />';
} elseif (@eregi($GLOBALS["editable_ext"], $item)) {
$geshiFile = _EXT_PATH . '/libraries/geshi/geshi.php';
ext_RaiseMemoryLimit('32M');
// GeSHi 1.0.7 is very memory-intensive
include_once $geshiFile;
// Create the GeSHi object that renders our source beautiful
$geshi = new GeSHi('', '', dirname($geshiFile) . '/geshi');
$file = get_abs_item($dir, $item);
$pathinfo = pathinfo($file);
if (ext_isFTPMode()) {
$file = ext_ftp_make_local_copy($file);
}
if (is_callable(array($geshi, 'load_from_file'))) {
$geshi->load_from_file($file);
} else {
$geshi->set_source(file_get_contents($file));
}
if (is_callable(array($geshi, 'get_language_name_from_extension'))) {
$lang = $geshi->get_language_name_from_extension($pathinfo['extension']);
} else {
$pathinfo = pathinfo($item);
$lang = $pathinfo['extension'];
}
$geshi->set_language($lang);
$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
$langs = $GLOBALS["language"];
if ($langs == "japanese") {
$enc_list = array("ASCII", "ISO-2022-JP", "UTF-8", "EUCJP-WIN", "SJIS-WIN");
$_e0 = strtoupper(mb_detect_encoding($geshi->source, $enc_list, true));
if ($_e0 == "SJIS-WIN") {
$_encoding = "Shift_JIS";
} elseif ($_e0 == "EUCJP-WIN") {
$_e0 = "EUC-JP";
} elseif ($_e0 == "ASCII") {
$_e0 = "UTF-8";
} else {
$_encoding = $_e0;
}
$geshi->set_encoding($_encoding);
}
$html = $geshi->parse_code();
if ($langs == "japanese") {
if (empty($lang) || strtoupper(mb_detect_encoding($html, $enc_list)) != "UTF-8") {
$html = mb_convert_encoding($html, "UTF-8", $_e0);
}
}
if (ext_isFTPMode()) {
unlink($file);
}
$html .= '<hr /><div style="line-height:25px;vertical-align:middle;text-align:center;" class="small">Rendering Time: <strong>' . $geshi->get_time() . ' Sec.</strong></div>';
} else {
$html = '
<iframe src="' . make_link('download', $dir, $item, null, null, null, '&action2=view') . '" id="iframe1" width="100%" height="100%" frameborder="0"></iframe>';
}
$html = str_replace(array("\r", "\n"), array('\\r', '\\n'), addslashes($html));
?>
{
"dialogtitle": "<?php
echo $GLOBALS['messages']['actview'] . ": " . $item;
?>
",
"height": 500,
"autoScroll": true,
"html": "<?php
echo $html;
?>
"
}
<?php
}
示例14: __construct
//.........这里部分代码省略.........
// twig path for default content templates
// (easybook built-in templates for contents; e.g. `license.md.twig`)
$this['twig.path.contents'] = $this->share(function ($app) {
$paths = array();
$theme = ucfirst($app->edition('theme'));
$format = Toolkit::camelize($app->edition('format'), true);
// TODO: fix the following hack
if ('Epub' == $format) {
$format = 'Epub2';
}
// default content templates for the edition/book theme
// <easybook>/app/Resources/Themes/<theme>/<edition-type>/Contents/<template-name>.twig
$dir = sprintf('%s/%s/%s/Contents', $app['app.dir.themes'], $theme, $format);
if (file_exists($dir)) {
$paths[] = $dir;
}
// default content templates for every edition and every book
// <easybook>/app/Resources/Themes/Base/<edition-type>/Contents/<template-name>.twig
$dir = sprintf('%s/Base/%s/Contents', $app['app.dir.themes'], $format);
if (file_exists($dir)) {
$paths[] = $dir;
}
return $paths;
});
$this['twig.loader'] = function () use($app) {
return new \Twig_Loader_Filesystem($app['twig.path']);
};
$this['twig'] = function () use($app) {
$twig = new \Twig_Environment($app['twig.loader'], $app['twig.options']);
$twig->addExtension(new TwigCssExtension());
$twig->addGlobal('app', $app);
if (null != $app->get('book')) {
$twig->addGlobal('book', $app->get('book'));
$publishingEdition = $app->get('publishing.edition');
$editions = $app->book('editions');
$twig->addGlobal('edition', $editions[$publishingEdition]);
}
return $twig;
};
// -- princeXML -------------------------------------------------------
$this['prince.default_paths'] = array('/usr/local/bin/prince', '/usr/bin/prince', 'C:\\Program Files\\Prince\\engine\\bin\\prince.exe');
$this['prince'] = $app->share(function () use($app) {
// look for the executable file of PrinceXML
$princePath = null;
foreach ($app['prince.default_paths'] as $path) {
if (file_exists($path)) {
$princePath = $path;
break;
}
}
if (null == $princePath) {
echo sprintf(" In order to generate PDF files, PrinceXML library must be installed. \n\n" . " We couldn't find PrinceXML executable in any of the following directories: \n" . " -> %s \n\n" . " If you haven't installed it yet, you can download a fully-functional demo at: \n" . " %s \n\n" . " If you have installed in a custom directory, please type its full absolute path:\n > ", implode($app['prince.default_paths'], "\n -> "), 'http://www.princexml.com/download');
$input = trim(fgets(STDIN));
if (file_exists($input)) {
$princePath = $input;
echo "\n";
} else {
throw new \Exception(sprintf("We couldn't find the PrinceXML executable in the given directory (%s)", $input));
}
}
$prince = new Prince($princePath);
$prince->setHtml(true);
return $prince;
});
// -- slugger ---------------------------------------------------------
$this['slugger'] = $app->share(function () use($app) {
return new Slugger($app);
});
// -- code syntax highlighter -----------------------------------------
$this['geshi'] = function () use($app) {
require_once __DIR__ . '/../../../vendor/geshi/geshi/geshi.php';
$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;
};
// -- labels ---------------------------------------------------------
$this['labels'] = $app->share(function () use($app) {
$labels = Yaml::parse($app['app.dir.translations'] . '/labels.' . $app->book('language') . '.yml');
// books can define their own labels files
if (null != ($customLabelsFile = $app->getCustomLabelsFile())) {
$customLabels = Yaml::parse($customLabelsFile);
return Toolkit::array_deep_merge($labels, $customLabels);
}
return $labels;
});
// -- titles ----------------------------------------------------------
$this['titles'] = $app->share(function () use($app) {
$titles = Yaml::parse($app['app.dir.translations'] . '/titles.' . $app->book('language') . '.yml');
// books can define their own titles files
if (null != ($customTitlesFile = $app->getCustomTitlesFile())) {
$customTitles = Yaml::parse($customTitlesFile);
return Toolkit::array_deep_merge($titles, $customTitles);
}
return $titles;
});
}
示例15: prepare
/**
* 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;
}