本文整理汇总了PHP中GeSHi::set_overall_class方法的典型用法代码示例。如果您正苦于以下问题:PHP GeSHi::set_overall_class方法的具体用法?PHP GeSHi::set_overall_class怎么用?PHP GeSHi::set_overall_class使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GeSHi
的用法示例。
在下文中一共展示了GeSHi::set_overall_class方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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";
}
示例2: unset
function code_callback($matches)
{
$index = (int) $matches[1];
$lang = $this->saved_code[$index]['lang'];
$code = $this->saved_code[$index]['code'];
// for prevent memory leaks
unset($this->saved_code[$index]);
// translate some language names so that simpler names can be used
${$lang} = strtr($lang, array('html' => 'html4strict', 'php' => 'php-brief'));
// if we get HTML for example, it's already encoded
$geshi = new GeSHi(htmlspecialchars_decode(trim($code, " \t\n\r\v�"), ENT_QUOTES), $lang);
$geshi->enable_classes();
$geshi->set_overall_class('code');
return $geshi->parse_code();
}
示例3: 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();
}
示例4: filter
/**
* 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);
}
示例5: codeHighlight
public function codeHighlight($source, $lang)
{
Zend_Loader::loadFile("geshi.php", array(config::getFilename("geshi/"), "/usr/share/php-geshi"), true);
if ($lang == "cpp") {
$lang = "C++";
}
if ($lang == "gcj") {
$lang = "Java";
}
if (!class_exists("GeSHi")) {
return "<!-- GeSHi disabled --> <pre>" . htmlspecialchars($source) . "</pre>";
}
$geshi = new GeSHi($source, $lang);
$geshi->set_header_type(GESHI_HEADER_PRE_TABLE);
$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
$geshi->set_overall_class("geshi");
$code = $geshi->parse_code();
return $code;
}
示例6: highlight
function highlight($code, $lang, $path)
{
if (empty($lang)) {
$lang = 'c';
}
$geshi = new GeSHi($code, $lang);
$geshi->enable_classes();
$geshi->set_overall_class('highlight');
$geshi->set_header_type(GESHI_HEADER_NONE);
/* Now this feature works, maybe activate it? */
/* $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 1); */
$result = $geshi->parse_code();
/* This thing fixes styles when line numbers are disabled */
$result = '<div class="highlight ' . $lang . '">' . $result . '</div>';
if ($geshi->error()) {
$result = $code;
}
return $result;
}
示例7: onParseContentBlock
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;
}
示例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
*/
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;
}
示例9: getLiveInfo
$geshi->set_tab_width(2);
//$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
//$geshi->set_line_style('background: #fcfcfc;', true);
Yii::app()->clientScript->registerCss('highlightcode2', $geshi->get_stylesheet());
echo $geshi->parse_code();
?>
<p> </p>
<p>Now we modify our function:<br>
</p>
<?php
$source = "\nvar counter = 0;\nvar reset_comment = false;\nvar comment_id = 0;\nvar subject_id = 0;\n\nfunction getLiveInfo(){\n\t\$.getJSON('http://samesub.com/api/v1/live/getall?callback=?',\n\t\t{subject_id:subject_id, coment_id:comment_id},\n\t\tfunction(data) {\n\t\t\t//If everything is ok(response_code == 200), let's print some LIVE information\n\t\t\tif(data.response_code == 200){\n\t\t\t\tcounter = data.time_remaining;\n\t\t\t\tif(data.new_sub != 0 || data.new_comment != 0 ){\n\t\t\t\t\tif(data.new_sub != 0) {\n\t\t\t\t\t\t//Every time there is a nuew sub, comments must be cleared\n\t\t\t\t\t\treset_comment=true;\n\t\t\t\t\t\tcomment_id = 0;\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t//Display subject\n\t\t\t\t\t\tsubject_id = data.subject_id;\n\t\t\t\t\t\t\$('#title').html(data.title);\n\t\t\t\t\t\t\$('#time_remaining').html(data.time_remaining + ' seconds.');\n\t\t\t\t\t}\n\t\t\t\t\tif(data.new_comment != 0){\n\t\t\t\t\t\tcomment_id = data.comment_id;\n\t\t\t\t\t\tshow_comments(data.comments);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\t//Otherwise alert data.response_message\t\t\t\t\n\t\t\t\talert(data.response_message);\n\t\t\t}\n\t\t}\n\t);\n\tvar aa = setTimeout('getLiveInfo()',8000);\n}\n\nfunction show_comments(comments){\n\tif(reset_comment == true) {\n\t\t\$('#comments_box').html('');//Clear all previous comments\n\t}\n\tfor(var i in comments) {\n\t\t\$('#comments_box').prepend(comments[i]['comment_text']+ '<br />');\n\t}\n}\n\nvar myInterval = setInterval(\n\tfunction(){\n\t\tcounter = counter - 1;\n\t\t\$('#time_remaining').html(counter + ' seconds.');\n\t}\n,1000);\n";
$language = 'Javascript';
$geshi = new GeSHi($source, $language);
$geshi->enable_classes();
$geshi->set_overall_class('myjs_no_lines');
$geshi->set_header_type(GESHI_HEADER_DIV);
$geshi->set_overall_style("padding:1px 15px 1px 15px;border:1px solid #999999;background: #fcfcfc;font: normal normal 1em/1.2em monospace;");
$geshi->set_tab_width(2);
//$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
//$geshi->set_line_style('background: #fcfcfc;', true);
Yii::app()->clientScript->registerCss('highlightcode2', $geshi->get_stylesheet());
echo $geshi->parse_code();
?>
<p> </p>
<p>As you can see there are several changes: </p>
<ol>
<li>We have declared few global variables.</li>
<li>We have splitted our function in three main parts: the <b>getLiveInfo</b>
function itself, the <b>show_comments</b> function, and the interval
function.</li>
示例10: code
/**
* Callback for code text
*
* Uses GeSHi to highlight language syntax
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function code($text, $language = NULL)
{
global $conf;
if (is_null($language)) {
$this->preformatted($text);
} else {
//strip leading blank line
$text = preg_replace('/^\\s*?\\n/', '', $text);
// Handle with Geshi here
require_once DOKU_INC . 'inc/geshi.php';
$geshi = new GeSHi($text, strtolower($language), DOKU_INC . 'inc/geshi');
$geshi->set_encoding('utf-8');
$geshi->enable_classes();
$geshi->set_header_type(GESHI_HEADER_PRE);
$geshi->set_overall_class("code {$language}");
$geshi->set_link_target($conf['target']['extern']);
$text = $geshi->parse_code();
$this->doc .= $text;
}
}
示例11: 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();
}
示例12: 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 $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;
}
示例13: getCacheName
/**
* Wrapper for GeSHi Code Highlighter, provides caching of its output
* Modified to calculate cache from URL so we don't have to re-download time and again
*
* @author Christopher Smith <chris@jalakai.co.uk>
* @author Esther Brunner <wikidesign@gmail.com>
*/
function _cached_geshi($url, $refresh)
{
global $conf;
$cache = getCacheName($url, '.code');
$mtime = @filemtime($cache);
// 0 if it doesn't exist
if ($mtime != 0 && !$_REQUEST['purge'] && $mtime > time() - $refresh && $mtime > filemtime(DOKU_INC . 'inc/geshi.php')) {
$hi_code = io_readFile($cache, false);
if ($conf['allowdebug']) {
$hi_code .= "\n<!-- cachefile {$cache} used -->\n";
}
} else {
require_once DOKU_INC . 'inc/geshi.php';
// get the source code language first
$search = array('/^htm/', '/^js$/');
$replace = array('html4strict', 'javascript');
$lang = preg_replace($search, $replace, substr(strrchr($url, '.'), 1));
// download external file
$http = new DokuHTTPClient();
$http->timeout = 25;
//max. 25 sec
$code = $http->get($url);
$geshi = new GeSHi($code, strtolower($lang), DOKU_INC . 'inc/geshi');
$geshi->set_encoding('utf-8');
$geshi->enable_classes();
$geshi->set_header_type(GESHI_HEADER_PRE);
$geshi->set_overall_class("code {$language}");
$geshi->set_link_target($conf['target']['extern']);
$hi_code = $geshi->parse_code();
io_saveFile($cache, $hi_code);
if ($conf['allowdebug']) {
$hi_code .= "\n<!-- no cachefile used, but created -->\n";
}
}
return $hi_code;
}
示例14: dirname
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Jakub Vrana <vrana@php.net> |
+----------------------------------------------------------------------+
*/
if ($_SERVER["argc"] < 3) {
exit("Purpose: Syntax highlight PHP examples in XSLT generated manual.\r\n" . 'Usage: highlight.php [ "xml" | "php" ] [ filename.ext | dir | wildcard ] ...' . "\r\n");
}
set_time_limit(5 * 60);
// can run long, but not more than 5 minutes
ini_set("error_reporting", E_ALL);
// kill the E_STRICT warnings in GeSHi under PHP 5
require dirname(__FILE__) . '/geshi/geshi.php';
$geshi = new GeSHi('', 'php', dirname(__FILE__) . '/geshi/geshi');
$geshi->set_tab_width(4);
$geshi->set_overall_class('phpcode');
$geshi->set_overall_style('font-size: 85%', true);
$geshi->set_symbols_highlighting(false);
$geshi->set_strings_style('color: green', true);
$geshi->set_keyword_group_style(1, 'color: #d09010; font-weight: bold', true);
$geshi->set_numbers_style('color: #aa0000; font-weight: bold', true);
$geshi->set_methods_style('color: black; font-style: italic', true);
$geshi->set_regexps_style(0, 'color: #004090', true);
// use this to get updated stylesheet info if changed via abovementioned API
// file_put_contents('style.css', $geshi->get_stylesheet());
function callback_html_number_entities_decode($matches)
{
return chr($matches[1]);
}
function callback_highlight_php($matches)
{
示例15: 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;
}