本文整理汇总了PHP中GeSHi::set_code_style方法的典型用法代码示例。如果您正苦于以下问题:PHP GeSHi::set_code_style方法的具体用法?PHP GeSHi::set_code_style怎么用?PHP GeSHi::set_code_style使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GeSHi
的用法示例。
在下文中一共展示了GeSHi::set_code_style方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: 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();
}
示例3: source_highlighter
function source_highlighter($source, $lang2geshi)
{
require_once 'geshi/geshi.php';
$source = str_replace(array("'", ">", "<", """, "&"), array("'", ">", "<", "\"", "&"), $source);
$lang2geshi = $lang2geshi == 'html' ? 'html4strict' : $lang2geshi;
$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:13px;', true);
$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;
}
示例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: exit
exit("Access outside acceptable path.");
}
// Check file exists
if (!file_exists($path)) {
exit("File not found ({$path}).");
}
// Prepare GeSHi instance
$geshi = new GeSHi();
$geshi->set_language('text');
$geshi->load_from_file($path);
$geshi->set_header_type(GESHI_HEADER_PRE);
$geshi->enable_classes();
$geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 10);
$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;');
$geshi->set_header_content('Source code viewer - ' . $path . ' - ' . $geshi->get_language_name());
$geshi->set_header_content_style('font-family: Verdana, Arial, sans-serif; color: #808080; font-size: 70%; font-weight: bold; background-color: #f0f0ff; border-bottom: 1px solid #d0d0d0; padding: 2px;');
$geshi->set_footer_content('Parsed in <TIME> seconds, using GeSHi <VERSION>');
$geshi->set_footer_content_style('font-family: Verdana, Arial, sans-serif; color: #808080; font-size: 70%; font-weight: bold; background-color: #f0f0ff; border-top: 1px solid #d0d0d0; padding: 2px;');
?>
<!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
示例6: 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);
}
示例7: 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;
}
示例8: 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 );
}
示例9:
$geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 5);
// Set the style for the PRE around the code. The line numbers are contained within this box (not
// XHTML compliant btw, but if you are liberally minded about these things then you'll appreciate
// the reduced source output).
$geshi->set_overall_style('font: normal normal 90% monospace; color: #000066; border: 1px solid #d0d0d0; background-color: #f0f0f0;', false);
// Set the style for line numbers. In order to get style for line numbers working, the <li> element
// is being styled. This means that the code on the line will also be styled, and most of the time
// you don't want this. So the set_code_style reverts styles for the line (by using a <div> on the line).
// So the source output looks like this:
//
// <pre style="[set_overall_style styles]"><ol>
// <li style="[set_line_style styles]"><div style="[set_code_style styles]>...</div></li>
// ...
// </ol></pre>
$geshi->set_line_style('color: #003030;', 'font-weight: bold; color: #006060;', true);
$geshi->set_code_style('color: #000020;', true);
// Styles for hyperlinks in the code. GESHI_LINK for default styles, GESHI_HOVER for hover style etc...
// note that classes must be enabled for this to work.
$geshi->set_link_styles(GESHI_LINK, 'color: #000060;');
$geshi->set_link_styles(GESHI_HOVER, 'background-color: #f0f000;');
// Use the header/footer functionality. This puts a div with content within the PRE element, so it is
// affected by the styles set by set_overall_style. So if the PRE has a border then the header/footer will
// appear inside it.
$geshi->set_header_content('<SPEED> <TIME> GeSHi © 2004-2007, Nigel McNie, 2007-2008 Benny Baumann. View source of example.php for example of using GeSHi');
$geshi->set_header_content_style('font-family: sans-serif; color: #808080; font-size: 70%; font-weight: bold; background-color: #f0f0ff; border-bottom: 1px solid #d0d0d0; padding: 2px;');
// You can use <TIME> and <VERSION> as placeholders
$geshi->set_footer_content('Parsed in <TIME> seconds at <SPEED>, using GeSHi <VERSION>');
$geshi->set_footer_content_style('font-family: sans-serif; color: #808080; font-size: 70%; font-weight: bold; background-color: #f0f0ff; border-top: 1px solid #d0d0d0; padding: 2px;');
} else {
// make sure we don't preselect any language
$_POST['language'] = null;
示例10: switch
/**
* Style language
*
* @param array $subjects
*/
function _styleSubjects($subjects)
{
// set overall style
if (isset($subjects['view'])) {
$this->geshi->set_overall_style($subjects['view'], $this->_invertOverwrite($subjects['view.']['overwrite']));
}
if (isset($subjects['view.']['container'])) {
switch ($subjects['view.']['container']) {
case 'none':
case 'NONE':
case 'None':
$this->geshi->set_header_type(GESHI_HEADER_NONE);
break;
case 'div':
case 'Div':
case 'DIV':
$this->geshi->set_header_type(GESHI_HEADER_DIV);
break;
case 'pre':
case 'Pre':
case 'PRE':
default:
$this->geshi->set_header_type(GESHI_HEADER_PRE);
break;
}
}
if (isset($subjects['view.']['tabwidth'])) {
$this->geshi->set_tab_width(intval($subjects['view.']['tabwidth']));
}
// configure linenumbers
if (isset($subjects['linenumbers'])) {
$this->geshi->set_line_style($subjects['linenumbers'], isset($subjects['linenumbers.']['fancy']) ? $subjects['linenumbers.']['fancy'] : '', $this->_invertOverwrite($subjects['linenumbers.']['overwrite']));
}
// enable / disable linenumbers
if (isset($subjects['linenumbers.']['enable'])) {
$this->geshi->enable_line_numbers($subjects['linenumbers.']['enable']);
}
// configure code style
if (isset($subjects['code'])) {
$this->geshi->set_code_style($subjects['code'], $this->_invertOverwrite($subjects['code.']['overwrite']));
}
// configure escape
if (isset($subjects['escape'])) {
$this->geshi->set_escape_characters_style($subjects['escape'], $this->_invertOverwrite($subjects['escape.']['overwrite']));
}
// configure symbols
if (isset($subjects['symbols'])) {
$this->geshi->set_symbols_style($subjects['symbols'], $this->_invertOverwrite($subjects['symbols.']['overwrite']));
}
// configure strings
if (isset($subjects['strings'])) {
$this->geshi->set_strings_style($subjects['strings'], $this->_invertOverwrite($subjects['strings.']['overwrite']));
}
// configure numbers
if (isset($subjects['numbers'])) {
$this->geshi->set_numbers_style($subjects['numbers'], $this->_invertOverwrite($subjects['numbers.']['overwrite']));
}
// configure comment style
if (isset($subjects['comments.'])) {
foreach ($subjects['comments.'] as $key => $value) {
if (strstr($key, '.') == false) {
$this->geshi->set_comments_style($key, $value, $this->_invertOverwrite($subjects['comments.'][$key . '.']['overwrite']));
}
}
}
// configure keywords style
if (isset($subjects['keywords.'])) {
foreach ($subjects['keywords.'] as $key => $value) {
if (strstr($key, '.') == false) {
$this->geshi->set_keyword_group_style($key, $value, $this->_invertOverwrite($subjects['keywords.'][$key . '.']['overwrite']));
}
}
}
// enable / disable keyword links
if (isset($subjects['keyword.']['links.']['enable'])) {
$this->geshi->enable_keyword_links($subjects['keyword.']['links.']['enable']);
}
// configure keyword link styles
if (isset($subjects['keyword.']['links'])) {
$this->geshi->set_link_styles(GESHI_LINK, $subjects['keyword.']['links']);
}
if (isset($subjects['keyword.']['links.']['hover'])) {
$this->geshi->set_link_styles(GESHI_HOVER, $subjects['keyword.']['links.']['hover']);
}
if (isset($subjects['keyword.']['links.']['active'])) {
$this->geshi->set_link_styles(GESHI_ACTIVE, $subjects['keyword.']['links.']['active']);
}
if (isset($subjects['keyword.']['links.']['visited'])) {
$this->geshi->set_link_styles(GESHI_VISITED, $subjects['keyword.']['links.']['visited']);
}
// configure keyword link target
if (isset($subjects['keyword.']['links.']['target'])) {
$this->geshi->set_link_target($subjects['keyword.']['links.']['target']);
}
// configure method styles
//.........这里部分代码省略.........
示例11: 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);
}
示例12: 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);
}