本文整理汇总了PHP中GeSHi::enable_line_numbers方法的典型用法代码示例。如果您正苦于以下问题:PHP GeSHi::enable_line_numbers方法的具体用法?PHP GeSHi::enable_line_numbers怎么用?PHP GeSHi::enable_line_numbers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GeSHi
的用法示例。
在下文中一共展示了GeSHi::enable_line_numbers方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parse
/**
* @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>';
}
}
示例2: import
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;
}
示例3: getFormattedOutput
/**
* 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();
}
示例4: renderTagCode
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>';
}
}
示例5: JHP_Geshi_replacer
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;
}
示例6: highlight
/**
* 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();
}
示例7: print_highlighted
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;
}
示例8: plgContentGeshi_replacer
/**
* 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;
}
示例9: 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();
}
}
示例10: 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";
}
示例11: getTemplateVars
public function getTemplateVars(Kwf_Component_Renderer_Abstract $renderer)
{
$ret = parent::getTemplateVars($renderer);
$row = $this->getRow();
if ($row->language) {
$geshi = new GeSHi($row->code, $row->language);
if ($row->line_numbers) {
$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
} else {
$geshi->enable_line_numbers(GESHI_NO_LINE_NUMBERS);
}
$ret['html'] = $geshi->parse_code();
} else {
$ret['html'] = '<code>' . htmlspecialchars($row->code) . '</code>';
}
return $ret;
}
示例12: handle_shortcode
/**
* @param string $arguments array with the type
* @param array $code string of the code to parse
* @param \ShortcodeParser $parser Parser root user.
* @param string $shortcode
* @param array $extra
*
* @return String of parsed code.
*/
public static function handle_shortcode($arguments, $code, $parser, $shortcode, $extra = array())
{
if (!isset($arguments['type'])) {
/** Assuming most code is PHP. Feel free to update. Should this be a configurable? */
$arguments['type'] = 'php';
}
$geshi = new \GeSHi(html_entity_decode(str_replace('<br>', "\n", $code)), $arguments['type']);
$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
return $geshi->parse_code();
}
示例13: render_code
function render_code(&$renderer, $code, $lang)
{
// code
$renderer->doc .= "<div class=\"code_block_code\">";
$geshi = new GeSHi($code, $lang);
$geshi->set_header_type(GESHI_HEADER_DIV);
$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
$renderer->doc .= $geshi->parse_code();
$renderer->doc .= "</div>";
}
示例14: GeSHi
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();
}
示例15: setNum
/**
* Нумерация строк
*
* @return Code
*/
protected function setNum()
{
if (isset($this->attributes['num'])) {
$this->geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS);
if ('' !== $this->attributes['num']) {
$num = (int) $this->attributes['num'];
$this->geshi->start_line_numbers_at($num);
}
}
return $this;
}