本文整理汇总了PHP中GeSHi::enable_classes方法的典型用法代码示例。如果您正苦于以下问题:PHP GeSHi::enable_classes方法的具体用法?PHP GeSHi::enable_classes怎么用?PHP GeSHi::enable_classes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GeSHi
的用法示例。
在下文中一共展示了GeSHi::enable_classes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: main
/**
* The main method of the Plugin
*
* @param string $content: The PlugIn content
* @param array $conf: The PlugIn configuration
* @return The content that is displayed on the website
*/
function main($content, $config)
{
// get content
$this->pi_initPIflexForm();
$config['content.']['lang'] = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'cLang', 'sVIEW');
$config['content.']['code'] = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'cCode', 'sVIEW');
$config['content.']['highlight'] = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'cHighlight', 'sOPTIONS');
$config['content.']['startnumber'] = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'cStartnumber', 'sOPTIONS');
// init geshi library
$this->geshi = new GeSHi($config['content.']['code'], $config['content.']['lang']);
// defaults
$this->geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
// set highlighted lines
if ($config['content.']['highlight'] !== '') {
$this->geshi->highlight_lines_extra(split(',', $config['content.']['highlight']));
}
// set startnumber
if (isset($config['content.']['startnumber'])) {
$this->geshi->start_line_numbers_at($config['content.']['startnumber']);
}
// style
if (isset($config['default.'])) {
$this->_styleSubjects($config['default.']);
}
if (isset($config[$config['content.']['lang'] . '.'])) {
$this->_styleSubjects($config[$config['content.']['lang'] . '.']);
}
// external stylesheets
if (isset($config['global.']['external']) && $config['global.']['external'] == 0) {
// do not use external style sheets
} else {
// mtness.net modification: I love stylesheets!
$this->geshi->enable_classes();
// Echo out the stylesheet for this code block And continue echoing the page
$this->geshiCSS = '<style type="text/css"><!--' . $this->geshi->get_stylesheet() . '--></style>';
// additional headerdata to include the styles
$GLOBALS['TSFE']->additionalHeaderData['dev_null_geshi:' . $config['content.']['lang']] = $this->geshiCSS;
}
// xhtml compliance
if (isset($config['global.']['xhtmlcompliant']) && $config['global.']['xhtmlcompliant'] == 1) {
$this->geshi->set_xhtml_compliance(true);
}
// check for errors
if ($this->geshi->error() !== false) {
// log an error, this happens if the language file is missing or non-readable. Other input
// specific errors can also occour, eg. if a non-existing container type is set for the engine.
$GLOBALS['BE_USER']->simplelog($this->geshi->error(), $extKey = 'dev_null_geshi', 1);
}
// render
return $this->pi_wrapInBaseClass($this->geshi->parse_code());
}
示例2: formatCodeBlocks
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);
}
示例3: codeReplace
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;
}
示例4: source_highlighter
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;
}
示例5: 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();
}
}
示例6: 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";
}
示例7: DoGeshi
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>";
}
示例8: syntaxHighlight
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();
}
示例9: parseGeshi
/**
* @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();
}
示例10: markdown_code_highlighter
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>';
}
示例11: highlight
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>';
}
示例12: 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;
};
}
示例13: handle_geshi
function handle_geshi($content, $language)
{
$g = new GeSHi($content, $language);
$g->enable_classes();
$g->set_header_type(GESHI_HEADER_DIV);
$g->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 5);
#$g->set_overall_style('color:black');
$g->set_overall_id('source');
$g->set_code_style('color:black;', "'Courier New', Courier, monospace");
$g->set_line_style('color:#838383;', '', true);
return $g->parse_code();
}
示例14: callGeshi
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);
}
示例15: 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();
}