本文整理汇总了PHP中GeSHi::get_stylesheet方法的典型用法代码示例。如果您正苦于以下问题:PHP GeSHi::get_stylesheet方法的具体用法?PHP GeSHi::get_stylesheet怎么用?PHP GeSHi::get_stylesheet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GeSHi
的用法示例。
在下文中一共展示了GeSHi::get_stylesheet方法的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: 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: onExtra
function onExtra($name)
{
$output = NULL;
if ($name == "header") {
if (!$this->yellow->config->get("highlightStylesheetDefault")) {
$locationStylesheet = $this->yellow->config->get("serverBase") . $this->yellow->config->get("pluginLocation") . "highlight.css";
$fileNameStylesheet = $this->yellow->config->get("pluginDir") . "highlight.css";
if (is_file($fileNameStylesheet)) {
$output = "<link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"{$locationStylesheet}\" />\n";
}
} else {
$geshi = new GeSHi();
$geshi->set_language_path($this->yellow->config->get("pluginDir") . "/highlight/");
foreach ($geshi->get_supported_languages() as $language) {
if ($language == "geshi") {
continue;
}
$geshi->set_language($language);
$output .= $geshi->get_stylesheet(false);
}
$output = "<style type=\"text/css\">\n{$output}</style>";
}
}
return $output;
}
示例4: 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;
}
示例5: buildHeadItem
/**
* Prepare a CSS snippet suitable for use as a ParserOutput/OutputPage
* head item
*
* @param GeSHi $geshi
* @return string
*/
public static function buildHeadItem($geshi)
{
global $wgUseSiteCss, $wgSquidMaxage;
// begin Wikia change
// VOLDEV-85
// backporting core fix to monobook font size
/**
* 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);
// end Wikia change
$lang = $geshi->language;
$css = array();
$css[] = '<style type="text/css">/*<![CDATA[*/';
$css[] = ".source-{$lang} {line-height: normal;}";
$css[] = ".source-{$lang} li, .source-{$lang} pre {";
$css[] = "\tline-height: normal; border: 0px none white;";
$css[] = "}";
$css[] = $geshi->get_stylesheet(false);
$css[] = '/*]]>*/';
$css[] = '</style>';
return implode("\n", $css);
}
示例6: getCSS
/**
* Get the complete CSS code necessary to display styles for given GeSHi instance.
*
* @param GeSHi $geshi
* @return string
*/
public static function getCSS($geshi)
{
$lang = $geshi->language;
$css = array();
$css[] = ".source-{$lang} {line-height: normal;}";
$css[] = ".source-{$lang} li, .source-{$lang} pre {";
$css[] = "\tline-height: normal; border: 0px none white;";
$css[] = "}";
$css[] = $geshi->get_stylesheet(false);
return implode("\n", $css);
}
示例7: buildHeadItem
/**
* Prepare a CSS snippet suitable for use as a ParserOutput/OutputPage
* head item
*
* @param GeSHi $geshi
* @return string
*/
public static function buildHeadItem( $geshi ) {
/**
* Geshi comes by default with a font-family set to monospace which
* ends ultimately ends up causing the font-size to be smaller than
* one would expect (causing bug 26204).
* We append to the default geshi style a CSS hack which is to specify
* monospace twice which "reset" the browser font-size specified for monospace.
*
* The hack is documented in MediaWiki core under
* docs/uidesign/monospace.html and in bug 33496.
*/
$geshi->set_code_style( 'font-family: monospace, monospace;',
/** preserve defaults */ true );
$lang = $geshi->language;
$css = array();
$css[] = '<style type="text/css">/*<![CDATA[*/';
$css[] = ".source-$lang {line-height: normal;}";
$css[] = ".source-$lang li, .source-$lang pre {";
$css[] = "\tline-height: normal; border: 0px none white;";
$css[] = "}";
$css[] = $geshi->get_stylesheet( false );
$css[] = '/*]]>*/';
$css[] = '</style>';
return implode( "\n", $css );
}
示例8: syntaxhighlighting
/**
* Highlights the content parts marked as source code using the GeSHi
* class.
* @author Björn Detert <b.detert@mittwald.de>
* @version 20. 9. 2006
* @param string $content The text to be parsed
* @param object $parent The calling object (regulary of type tx_mmforum_pi1), so this
* object inherits all configuration and language options from the
* calling object.
* @param array $conf The calling plugin's configuration vars
* @return string The parsed string
*/
function syntaxhighlighting($content, $parent, $conf)
{
/* Path to Geshi Syntax-Highlighting files. */
$path = GeneralUtility::getFileAbsFileName('EXT:mm_forum/res/geshi/geshi/', $onlyRelative = 1, $relToTYPO3_mainDir = 0);
$conf['postparser.']['tsrefUrl'] ? define('GESHI_TS_REF', $conf['postparser.']['tsrefUrl']) : define('GESHI_TS_REF', 'www.typo3.net');
$res = $this->databaseHandle->exec_SELECTquery('lang_title,lang_pattern,lang_code', 'tx_mmforum_syntaxhl', 'deleted=0');
while ($data = $this->databaseHandle->sql_fetch_assoc($res)) {
preg_match_all($data['lang_pattern'], $content, $source_arr);
while (list($key, $value) = each($source_arr[1])) {
$value = trim($this->decode_entities($value));
if ($data['lang_title'] == 'php') {
if (!preg_match("/<\\?/", trim(substr($value, 0, 6)))) {
$value = "<?\n" . $value . "\n?>";
}
}
$geshi = new GeSHi($value, $data['lang_code'], $path);
$geshi->set_header_type(GESHI_HEADER_PRE);
#$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
$geshi->set_line_style('background: ' . $conf['postparser.']['sh_linestyle_bg'] . ';', 'background: ' . $conf['postparser.']['sh_linestyle_bg2'] . ';', true);
$geshi->set_overall_style('margin:0px;', true);
$geshi->enable_classes();
$style = '<style type="text/css"><!--';
$style .= $geshi->get_stylesheet();
$style .= '--></style>';
$geshi->enable_strict_mode('FALSE');
$replace = $geshi->parse_code();
$time = $geshi->get_time();
$CodeHead = '<div class="tx-mmforum-pi1-codeheader">' . strtoupper($data['lang_title']) . '</div>';
// $code_header , check this out?? I get confused ^^
$replace = '###DONT_PARSE_AGAIN_START###' . $CodeHead . '<div class="tx-mmforum-pi1-codeblock">' . $style . $replace . '</div>###DONT_PARSE_AGAIN_ENDE###';
$content = str_replace($source_arr[0][$key], $replace, $content);
}
}
return $content;
}
示例9: dirname
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @package geshi
* @subpackage contrib
* @author revulo <revulon@gmail.com>
* @copyright 2008 revulo
* @license http://gnu.org/copyleft/gpl.html GNU GPL
*
*/
require dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'geshi.php';
$geshi = new GeSHi();
$languages = array();
if ($handle = opendir($geshi->language_path)) {
while (($file = readdir($handle)) !== false) {
$pos = strpos($file, '.');
if ($pos > 0 && substr($file, $pos) == '.php') {
$languages[] = substr($file, 0, $pos);
}
}
closedir($handle);
}
sort($languages);
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="geshi.css"');
echo "/**\n" . " * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann\n" . " * (http://qbnz.com/highlighter/ and http://geshi.org/)\n" . " */\n";
foreach ($languages as $language) {
$geshi->set_language($language);
// note: the false argument is required for stylesheet generators, see API documentation
$css = $geshi->get_stylesheet(false);
echo preg_replace('/^\\/\\*\\*.*?\\*\\//s', '', $css);
}
示例10: LoadData
/**
* Loads data for this template
*/
protected function LoadData()
{
$head = $this->GetProject()->GetHeadCommit();
$this->tpl->assign('head', $head);
$commit = $this->GetProject()->GetCommit($this->params['hashbase']);
$this->tpl->assign('commit', $commit);
if (!isset($this->params['hash']) && isset($this->params['file'])) {
$this->params['hash'] = $commit->GetTree()->PathToHash($this->params['file']);
if (empty($this->params['hash'])) {
throw new GitPHP_FileNotFoundException($this->params['file']);
}
}
$blob = $this->GetProject()->GetObjectManager()->GetBlob($this->params['hash']);
if ($this->params['file']) {
$blob->SetPath($this->params['file']);
}
$blob->SetCommit($commit);
$this->tpl->assign('blob', $blob);
$blame = new GitPHP_FileBlame($this->GetProject(), $commit, $this->params['file'], $this->exe);
$this->tpl->assign('blame', $blame->GetBlame());
if (isset($this->params['output']) && $this->params['output'] == 'js') {
return;
}
$this->tpl->assign('tree', $commit->GetTree());
if ($this->config->GetValue('geshi')) {
include_once GITPHP_GESHIDIR . "geshi.php";
if (class_exists('GeSHi')) {
$geshi = new GeSHi("", 'php');
if ($geshi) {
$lang = GitPHP_Util::GeshiFilenameToLanguage($blob->GetName());
if (empty($lang)) {
$lang = $geshi->get_language_name_from_extension(substr(strrchr($blob->GetName(), '.'), 1));
}
if (!empty($lang)) {
$geshi->enable_classes();
$geshi->enable_strict_mode(GESHI_MAYBE);
$geshi->set_source($blob->GetData());
$geshi->set_language($lang);
$geshi->set_header_type(GESHI_HEADER_PRE_TABLE);
$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
$output = $geshi->parse_code();
$bodystart = strpos($output, '<td');
$bodyend = strrpos($output, '</tr>');
if ($bodystart !== false && $bodyend !== false) {
$geshihead = substr($output, 0, $bodystart);
$geshifoot = substr($output, $bodyend);
$geshibody = substr($output, $bodystart, $bodyend - $bodystart);
$this->tpl->assign('geshihead', $geshihead);
$this->tpl->assign('geshibody', $geshibody);
$this->tpl->assign('geshifoot', $geshifoot);
$this->tpl->assign('geshicss', $geshi->get_stylesheet());
$this->tpl->assign('geshi', true);
}
}
}
}
}
}
示例11:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Source code viewer - <?php
echo $path;
?>
- <?php
$geshi->get_language_name();
?>
</title>
<style type="text/css">
<!--
<?php
// Output the stylesheet. Note it doesn't output the <style> tag
echo $geshi->get_stylesheet();
?>
html {
background-color: #f0f0f0;
}
body {
font-family: Verdana, Arial, sans-serif;
margin: 10px;
border: 2px solid #e0e0e0;
background-color: #fcfcfc;
padding: 5px;
}
h2 {
margin: .1em 0 .2em .5em;
border-bottom: 1px solid #b0b0b0;
color: #b0b0b0;
示例12: Copyright
<?php
/*
This file is part of the Pastebin package.
Copyright (c) 2003-2008, Stephen Olesen
All rights reserved.
More information is available at http://pastebin.ca/
*/
### Generate CSS for all the GeSHi languages
$langs = array('actionscript', 'ada', 'apache', 'asm', 'asp', 'asterisk-conf', 'asterisk-exten', 'bash', 'c', 'c_mac', 'caddcl', 'cadlisp', 'cpp', 'csharp', 'css', 'delphi', 'html4strict', 'java', 'javascript', 'lisp', 'lua', 'mpasm', 'nsis', 'objc', 'oobas', 'oracle8', 'pascal', 'perl', 'php-brief', 'php', 'python', 'qbasic', 'smarty', 'sql', 'vb', 'vbnet', 'visualfoxpro', 'xml');
require_once "geshi.php";
foreach ($langs as $v) {
$g = new GeSHi("...", $v);
$g->enable_classes();
$g->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 5);
$g->set_header_type(GESHI_HEADER_DIV);
#$g->set_overall_id('source');
#$g->set_overall_class($v);
$g->set_code_style('color:black;', "'Courier New', Courier, monospace");
$g->set_line_style('color:#838383;', '', true);
$fd = fopen("css/lang/{$v}.css", "w");
fwrite($fd, $g->get_stylesheet(false));
fclose($fd);
}
示例13: getPost
/**
* Get formatted post, ready for inserting into a page
* Returns an array of useful information
*/
function getPost($pid)
{
$post = $this->db->getPost($pid, $this->conf['subdomain']);
if ($post) {
//show a quick reference url, poster and parents
$post['posttitle'] = "Posted by {$post['poster']} on {$post['postdate']}";
if ($post['parent_pid'] != '0') {
$parent_pid = $post['parent_pid'];
$parent = $this->db->getPost($parent_pid, $this->conf['subdomain']);
if ($parent) {
$post['parent_poster'] = trim($parent['poster']);
if (strlen($post['parent_poster']) == 0) {
$post['parent_poster'] = 'Anonymous';
}
$post['parent_url'] = $this->getPostUrl($parent_pid);
$post['parent_postdate'] = $parent['postdate'];
$post['parent_diffurl'] = $this->conf['this_script'] . "?diff={$pid}";
}
}
//any amendments - note that a db class might have already
//filled this if efficient, othewise we grab it on demand
if (!isset($post['followups'])) {
$post['followups'] = $this->db->getFollowupPosts($pid);
}
foreach ($post['followups'] as $idx => $followup) {
$post['followups'][$idx]['followup_url'] = $this->getPostUrl($followup['pid']);
}
$post['downloadurl'] = $this->conf['this_script'] . "?dl={$pid}";
$post['deleteurl'] = $this->conf['this_script'] . "?erase={$pid}";
//store the code for later editing
$post['editcode'] = $post['code'];
//preprocess
$highlight = array();
$prefix_size = strlen($this->conf['highlight_prefix']);
if ($prefix_size) {
$lines = explode("\n", $post['editcode']);
$post['editcode'] = "";
foreach ($lines as $idx => $line) {
if (substr($line, 0, $prefix_size) == $this->conf['highlight_prefix']) {
$highlight[] = $idx + 1;
$line = substr($line, $prefix_size);
}
$post['editcode'] .= $line . "\n";
}
$post['editcode'] = rtrim($post['editcode']);
}
//get formatted version of code
if (strlen($post['codefmt']) == 0) {
$geshi = new GeSHi($post['editcode'], $post['format']);
$geshi->set_encoding($this->conf['htmlentity_encoding']);
$geshi->enable_classes();
$geshi->set_header_type(GESHI_HEADER_DIV);
$geshi->set_line_style('background: #ffffff;', 'background: #f8f8f8;');
//$geshi->set_comments_style(1, 'color: #008800;',true);
//$geshi->set_comments_style('multi', 'color: #008800;',true);
//$geshi->set_strings_style('color:#008888',true);
//$geshi->set_keyword_group_style(1, 'color:#000088',true);
//$geshi->set_keyword_group_style(2, 'color:#000088;font-weight: normal;',true);
//$geshi->set_keyword_group_style(3, 'color:black;font-weight: normal;',true);
//$geshi->set_keyword_group_style(4, 'color:#000088',true);
//$geshi->set_symbols_style('color:#ff0000');
if (count($highlight)) {
$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
$geshi->highlight_lines_extra($highlight);
$geshi->set_highlight_lines_extra_style('color:black;background:#FFFF88;');
} else {
$geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 2);
}
$post['codefmt'] = $geshi->parse_code();
$post['codecss'] = $geshi->get_stylesheet();
//save it!
$this->db->saveFormatting($pid, $post['codefmt'], $post['codecss']);
}
$post['pid'] = $pid;
} else {
$post['codefmt'] = "<b>Unknown post id, it may have been deleted</b><br />";
}
return $post;
}
示例14: finalizeSQLSyntax
/**
* Put the last options to the sql: highlight, backticks....
*
* @param string $sql
* @param boolean $deactivateForeignKeys
* @param boolean $backticks
* @param boolean $highlight
* @param boolean $lineNumbers
*
* @return string
*/
private function finalizeSQLSyntax($sql, $deactivateForeignKeys, $backticks, $highlight, $lineNumbers)
{
$sql = implode(';' . PHP_EOL, $sql) . ';' . PHP_EOL;
// Set line numbers, backticks....
// Manage latest options
if ($deactivateForeignKeys) {
$sql = 'SET FOREIGN_KEY_CHECKS = 0;' . PHP_EOL . PHP_EOL . $sql;
$sql .= PHP_EOL . 'SET FOREIGN_KEY_CHECKS = 1;';
}
// At the end
if (!$backticks) {
$sql = str_replace('`', '', $sql);
}
// Highlight Syntax ?
$css = '';
if ($highlight || $lineNumbers) {
$geshi = new \GeSHi($sql, 'mysql');
$geshi->enable_classes();
$geshi->enable_keyword_links(false);
if ($lineNumbers) {
$geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS);
}
if ($highlight) {
$css = $geshi->get_stylesheet();
}
$sql = $geshi->parse_code();
} else {
$sql = "<pre>{$sql}</pre>";
}
return ['sql' => $sql, 'css' => $css];
}
示例15: wp_geshi_highlight_and_generate_css
function wp_geshi_highlight_and_generate_css()
{
global $wp_geshi_codesnipmatch_arrays;
global $wp_geshi_css_code;
global $wp_geshi_highlighted_matches;
global $wp_geshi_requested_css_files;
global $wp_geshi_used_languages;
// It is time to initialize the highlighting machinery.
// Check for `class_exists('GeSHi')` for preventing
// `Cannot redeclare class GeSHi` errors. Another plugin may already have
// included its own version of GeSHi.
// TODO: in this case, include GeSHi of WP-GeSHi-Highlight anyway, via
// namespacing or class renaming.
if (!class_exists('GeSHi')) {
include_once "geshi/geshi.php";
}
$wp_geshi_css_code = "";
foreach ($wp_geshi_codesnipmatch_arrays as $match_index => $match) {
// Process match details. The array structure is explained in
// a comment to function `wp_geshi_filter_replace_code()`.
$language = strtolower(trim($match[1]));
$line = trim($match[2]);
$escaped = trim($match[3]);
$cssfile = trim($match[4]);
$code = wp_geshi_code_trim($match[5]);
if ($escaped == "true") {
$code = htmlspecialchars_decode($code);
}
// (C) Ryan McGeary
// Set up GeSHi.
$geshi = new GeSHi($code, $language);
// Output CSS code / do *not* create inline styles.
$geshi->enable_classes();
// Disable keyword links.
$geshi->enable_keyword_links(false);
if ($line) {
$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
$geshi->start_line_numbers_at($line);
}
// Set the output type. Reference:
// http://qbnz.com/highlighter/geshi-doc.html#the-code-container
$geshi->set_header_type(GESHI_HEADER_PRE_VALID);
// By default, geshi sets font size to 1em and line height to 1.2em.
// That does not fit many modern CSS architectures. Make this
// relative and, most importantly, customizable.
$geshi->set_code_style('');
// If the current language has not been processed in a previous
// iteration:
// - create CSS code for this language
// - append this to the `$wp_geshi_css_code string`.
// $geshi->get_stylesheet(false) disables the economy mode, i.e.
// this will return the full CSS code for the given language.
// This allows for reusing the same CSS code for multiple code
// blocks of the same language.
if (!in_array($language, $wp_geshi_used_languages)) {
$wp_geshi_used_languages[] = $language;
$wp_geshi_css_code .= $geshi->get_stylesheet(false);
}
$output = "";
// cssfile "none" means no wrapping divs at all.
if ($cssfile != "none") {
if (empty($cssfile)) {
// For this code snippet the default css file is required.
$cssfile = "wp-geshi-highlight";
}
// Append "the css file" to the array.
$wp_geshi_requested_css_files[] = $cssfile;
$output .= "\n\n" . '<div class="' . $cssfile . '-wrap5">' . '<div class="' . $cssfile . '-wrap4">' . '<div class="' . $cssfile . '-wrap3">' . '<div class="' . $cssfile . '-wrap2">' . '<div class="' . $cssfile . '-wrap">' . '<div class="' . $cssfile . '">';
}
// Create highlighted HTML code.
$output .= $geshi->parse_code();
if ($cssfile != "none") {
$output .= '</div></div></div></div></div></div>' . "\n\n";
}
// Store highlighted HTML code for later usage.
$wp_geshi_highlighted_matches[$match_index] = $output;
}
// At this point, all code snippets are parsed. Highlighted code is stored.
// CSS code has been generated. Delete what is not required anymore.
unset($wp_geshi_codesnipmatch_arrays);
}