Codulle - L'explorateur de code sources
Informations fichier
Nom du fichier : geshi.phpTaille du fichier : 86 Ko (2649 lignes)
Language : PHP
span style="color: #808080; font-style: italic;">/** * GeSHi - Generic Syntax Highlighter * * The GeSHi class for Generic Syntax Highlighting. Please refer to the documentation * at http://qbnz.com/highlighter/documentation.php for more information about how to * use this class. * * For changes, release notes, TODOs etc, see the relevant files in the docs/ directory * * This file is part of GeSHi. * * GeSHi is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * GeSHi is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GeSHi; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * @package core * @author Nigel McNie <nigel@geshi.org> * @copyright Copyright © 2004, 2005, Nigel McNie * @license http://gnu.org/copyleft/gpl.html GNU GPL * @version $Id: geshi.php,v 1.23 2005/11/19 02:23:37 oracleshinoda Exp $ * */ // // GeSHi Constants // You should use these constant names in your programs instead of // their values - you never know when a value may change in a future // version // /** The version of this GeSHi file */'GESHI_VERSION', '1.0.7.5'); /** For the future (though this may never be realised) */'GESHI_OUTPUT_HTML', 0); /** Set the correct directory separator */'GESHI_DIR_SEPARATOR', ('WIN''/' : '\\'); // Define the root directory for the GeSHi code tree 'GESHI_ROOT')) { /** The root directory for GeSHi */'GESHI_ROOT'/** The language file directory for GeSHi @access private */'GESHI_LANG_ROOT''geshi'// Line numbers - use with enable_line_numbers() /** Use no line numbers when building the result */'GESHI_NO_LINE_NUMBERS', 0); /** Use normal line numbers when building the result */'GESHI_NORMAL_LINE_NUMBERS', 1); /** Use fancy line numbers when building the result */'GESHI_FANCY_LINE_NUMBERS', 2); // Container HTML type /** Use nothing to surround the source */'GESHI_HEADER_NONE', 0); /** Use a "div" to surround the source */'GESHI_HEADER_DIV', 1); /** Use a "pre" to surround the source */'GESHI_HEADER_PRE', 2); // Capatalisation constants /** Lowercase keywords found */'GESHI_CAPS_NO_CHANGE', 0); /** Uppercase keywords found */'GESHI_CAPS_UPPER', 1); /** Leave keywords found as the case that they are */'GESHI_CAPS_LOWER', 2); // Link style constants /** Links in the source in the :link state */'GESHI_LINK', 0); /** Links in the source in the :hover state */'GESHI_HOVER', 1); /** Links in the source in the :active state */'GESHI_ACTIVE', 2); /** Links in the source in the :visited state */'GESHI_VISITED', 3); // Important string starter/finisher // Note that if you change these, they should be as-is: i.e., don't // write them as if they had been run through htmlentities() /** The starter for important parts of the source */'GESHI_START_IMPORTANT', '<BEGIN GeSHi>'); /** The ender for important parts of the source */'GESHI_END_IMPORTANT', '<END GeSHi>'); /**#@+ * @access private */ // When strict mode applies for a language /** Strict mode never applies (this is the most common) */'GESHI_NEVER', 0); /** Strict mode *might* apply, and can be enabled or disabled by {@link GeSHi::enable_strict_mode()} */'GESHI_MAYBE', 1); /** Strict mode always applies */'GESHI_ALWAYS', 2); // Advanced regexp handling constants, used in language files /** The key of the regex array defining what to search for */'GESHI_SEARCH', 0); /** The key of the regex array defining what bracket group in a matched search to use as a replacement */'GESHI_REPLACE', 1); /** The key of the regex array defining any modifiers to the regular expression */'GESHI_MODIFIERS', 2); /** The key of the regex array defining what bracket group in a matched search to put before the replacement */'GESHI_BEFORE', 3); /** The key of the regex array defining what bracket group in a matched search to put after the replacement */'GESHI_AFTER', 4); /** Used in language files to mark comments */'GESHI_COMMENTS', 0); // Error detection - use these to analyse faults /** No sourcecode to highlight was specified */'GESHI_ERROR_NO_INPUT', 1); /** The language specified does not exist */'GESHI_ERROR_NO_SUCH_LANG', 2); /** GeSHi could not open a file for reading (generally a language file) */'GESHI_ERROR_FILE_NOT_READABLE', 3); /** The header type passed to {@link GeSHi::set_header_type()} was invalid */'GESHI_ERROR_INVALID_HEADER_TYPE', 4); /** The line number type passed to {@link GeSHi::enable_line_numbers()} was invalid */'GESHI_ERROR_INVALID_LINE_NUMBER_TYPE', 5); /**#@-*/ /** * The GeSHi Class. * * Please refer to the documentation for GeSHi 1.0.X that is available * at http://qbnz.com/highlighter/documentation.php for more information * about how to use this class. * * @package core * @author Nigel McNie <nigel@geshi.org> * @copyright Copyright © 2004, 2005 Nigel McNie *//**#@+ * @access private */ /** * The source code to highlight * @var string */''; /** * The language to use when highlighting * @var string */''; /** * The data for the language used * @var array *//** * The path to the language files * @var string *//** * The error message associated with an error * @var string * @todo check err reporting works *//** * Possible error messages * @var array */'No source code inputted''GeSHi could not find the language {LANGUAGE} (using path {PATH})''The file specified for load_from_file was not readable''The header type specified is invalid''The line number type specified is invalid' ); /** * Whether highlighting is strict or not * @var boolean *//** * Whether to use CSS classes in output * @var boolean *//** * The type of header to use. Can be one of the following * values: * * <ul> * <li><b>GESHI_HEADER_PRE</b>: Source is outputted in * a <pre> HTML element.</li> * <li><b>GESHI_HEADER_DIV</b>: Source is outputted in * a <div> HTML element.</li> * </ul> * * @var int *//** * Array of permissions for which lexics should be highlighted * @var array */'KEYWORDS''COMMENTS''MULTI''REGEXPS''ESCAPE_CHAR''BRACKETS''SYMBOLS''STRINGS''NUMBERS''METHODS''SCRIPT'/** * The time it took to parse the code * @var double *//** * The content of the header block * @var string */''; /** * The content of the footer block * @var string */''; /** * The style of the header block * @var string */''; /** * The style of the footer block * @var string */''; /** * The styles for hyperlinks in the code * @var array *//** * Whether important blocks should be recognised or not * @var boolean * @deprecated * @todo REMOVE THIS FUNCTIONALITY! *//** * Styles for important parts of the code * @var string * @deprecated * @todo As above - rethink the whole idea of important blocks as it is buggy and * will be hard to implement in 1.2 */'font-weight: bold; color: red;'; // Styles for important parts of the code /** * Whether CSS IDs should be added to the code * @var boolean *//** * Lines that should be highlighted extra * @var array *//** * Styles of extra-highlighted lines * @var string */'color: #cc0; background-color: #ffc;'; /** * Number at which line numbers should start at * @var int * @todo Warning documentation about XHTML compliance *//** * The overall style for this code block * @var string */''; /** * The style for the actual code * @var string */'font-family: \'Courier New\', Courier, monospace; font-weight: normal;'; /** * The overall class for this code block * @var string */''; /** * The overall ID for this code block * @var string */''; /** * Line number styles * @var string */'font-family: \'Courier New\', Courier, monospace; color: black; font-weight: normal; font-style: normal;'; /** * Line number styles for fancy lines * @var string */'font-weight: bold;'; /** * Flag for how line nubmers are displayed * @var boolean *//** * The "nth" value for fancy line highlighting * @var int *//** * The size of tab stops * @var int *//** * Default target for keyword links * @var string */''; /** * The encoding to use for entity encoding * @var string */'ISO-8859-1'; /** * Unused (planned for future) * @var int *//**#@-*/ /** * Creates a new GeSHi object, with source and language * * @param string The source code to highlight * @param string The language to highlight the source with * @param string The path to the language file directory. <b>This * is deprecated!</b> I've backported the auto path * detection from the 1.1.X dev branch, so now it * should be automatically set correctly. If you have * renamed the language directory however, you will * still need to set the path using this parameter or * {@link GeSHi::set_language_path()} * @since 1.0.0 */''/** * Returns an error message associated with the last GeSHi operation, * or false if no error has occured * * @return string|false An error message if there has been an error, else false * @since 1.0.0 */'{LANGUAGE}' => $this->language, '{PATH}'"<br /><strong>GeSHi Error:</strong> $msg (code $this->error)<br />"/** * Gets a human-readable language name (thanks to Simon Patterson * for the idea :)) * * @return string The name for the current language * @since 1.0.2 */'LANG_NAME'] . ' (Unknown Language)''LANG_NAME']; } /** * Sets the source code for this object * * @param string The source code to highlight * @since 1.0.0 */''/** * Sets the language for this object * * @param string The name of the language to use * @since 1.0.0 */'#[^a-zA-Z0-9\-_]#', '''.php'// Load the language for parsing /** * Sets the path to the directory containing the language files. Note * that this path is relative to the directory of the script that included * geshi.php, NOT geshi.php itself. * * @param string The path to the language directory * @since 1.0.0 * @deprecated The path to the language files should now be automatically * detected, so this method should no longer be needed. The * 1.1.X branch handles manual setting of the path differently * so this method will disappear in 1.2.0. */'/''/'; } } /** * Sets the type of header to be used. * * If GESHI_HEADER_DIV is used, the code is surrounded in a "div".This * means more source code but more control over tab width and line-wrapping. * GESHI_HEADER_PRE means that a "pre" is used - less source, but less * control. Default is GESHI_HEADER_PRE. * * From 1.0.7.2, you can use GESHI_HEADER_NONE to specify that no header code * should be outputted. * * @param int The type of header to be used * @since 1.0.0 *//** * Sets the styles for the code that will be outputted * when this object is parsed. The style should be a * string of valid stylesheet declarations * * @param string The overall style for the outputted code block * @param boolean Whether to merge the styles with the current styles or not * @since 1.0.0 *//** * Sets the overall classname for this block of code. This * class can then be used in a stylesheet to style this object's * output * * @param string The class name to use for this block of code * @since 1.0.0 *//** * Sets the overall id for this block of code. This id can then * be used in a stylesheet to style this object's output * * @param string The ID to use for this block of code * @since 1.0.0 *//** * Sets whether CSS classes should be used to highlight the source. Default * is off, calling this method with no arguments will turn it on * * @param boolean Whether to turn classes on or not * @since 1.0.0 *//** * Sets the style for the actual code. This should be a string * containing valid stylesheet declarations. If $preserve_defaults is * true, then styles are merged with the default styles, with the * user defined styles having priority * * Note: Use this method to override any style changes you made to * the line numbers if you are using line numbers, else the line of * code will have the same style as the line number! Consult the * GeSHi documentation for more information about this. * * @param string The style to use for actual code * @param boolean Whether to merge the current styles with the new styles *//** * Sets the styles for the line numbers. * * @param string The style for the line numbers that are "normal" * @param string|boolean If a string, this is the style of the line * numbers that are "fancy", otherwise if boolean then this * defines whether the normal styles should be merged with the * new normal styles or not * @param boolean If set, is the flag for whether to merge the "fancy" * styles with the current styles or not * @since 1.0.2 */''''/** * Sets whether line numbers should be displayed. * * Valid values for the first parameter are: * * <ul> * <li><b>GESHI_NO_LINE_NUMBERS</b>: Line numbers will not be displayed</li> * <li><b>GESHI_NORMAL_LINE_NUMBERS</b>: Line numbers will be displayed</li> * <li><b>GESHI_FANCY_LINE_NUMBERS</b>: Fancy line numbers will be displayed</li> * </ul> * * For fancy line numbers, the second parameter is used to signal which lines * are to be fancy. For example, if the value of this parameter is 5 then every * 5th line will be fancy. * * @param int How line numbers should be displayed * @param int Defines which lines are fancy * @since 1.0.0 *//** * Sets the style for a keyword group. If $preserve_defaults is * true, then styles are merged with the default styles, with the * user defined styles having priority * * @param int The key of the keyword group to change the styles of * @param string The style to make the keywords * @param boolean Whether to merge the new styles with the old or just * to overwrite them * @since 1.0.0 */'STYLES']['KEYWORDS''STYLES']['KEYWORDS'/** * Turns highlighting on/off for a keyword group * * @param int The key of the keyword group to turn on or off * @param boolean Whether to turn highlighting for that group on or off * @since 1.0.0 */'KEYWORDS'/** * Sets the styles for comment groups. If $preserve_defaults is * true, then styles are merged with the default styles, with the * user defined styles having priority * * @param int The key of the comment group to change the styles of * @param string The style to make the comments * @param boolean Whether to merge the new styles with the old or just * to overwrite them * @since 1.0.0 */'STYLES']['COMMENTS''STYLES']['COMMENTS'/** * Turns highlighting on/off for comment groups * * @param int The key of the comment group to turn on or off * @param boolean Whether to turn highlighting for that group on or off * @since 1.0.0 */'COMMENTS'/** * Sets the styles for escaped characters. If $preserve_defaults is * true, then styles are merged with the default styles, with the * user defined styles having priority * * @param string The style to make the escape characters * @param boolean Whether to merge the new styles with the old or just * to overwrite them * @since 1.0.0 */'STYLES']['ESCAPE_CHAR''STYLES']['ESCAPE_CHAR'][0] .= $style; } } /** * Turns highlighting on/off for escaped characters * * @param boolean Whether to turn highlighting for escape characters on or off * @since 1.0.0 */'ESCAPE_CHAR'/** * Sets the styles for brackets. If $preserve_defaults is * true, then styles are merged with the default styles, with the * user defined styles having priority * * This method is DEPRECATED: use set_symbols_style instead. * This method will be removed in 1.2.X * * @param string The style to make the brackets * @param boolean Whether to merge the new styles with the old or just * to overwrite them * @since 1.0.0 * @deprecated In favour of set_symbols_style */'STYLES']['BRACKETS''STYLES']['BRACKETS'][0] .= $style; } } /** * Turns highlighting on/off for brackets * * This method is DEPRECATED: use set_symbols_highlighting instead. * This method will be remove in 1.2.X * * @param boolean Whether to turn highlighting for brackets on or off * @since 1.0.0 * @deprecated In favour of set_symbols_highlighting */'BRACKETS'/** * Sets the styles for symbols. If $preserve_defaults is * true, then styles are merged with the default styles, with the * user defined styles having priority * * @param string The style to make the symbols * @param boolean Whether to merge the new styles with the old or just * to overwrite them * @since 1.0.1 */'STYLES']['SYMBOLS''STYLES']['SYMBOLS'][0] .= $style; } // For backward compatibility /** * Turns highlighting on/off for symbols * * @param boolean Whether to turn highlighting for symbols on or off * @since 1.0.0 */'SYMBOLS'// For backward compatibility /** * Sets the styles for strings. If $preserve_defaults is * true, then styles are merged with the default styles, with the * user defined styles having priority * * @param string The style to make the escape characters * @param boolean Whether to merge the new styles with the old or just * to overwrite them * @since 1.0.0 */'STYLES']['STRINGS''STYLES']['STRINGS'][0] .= $style; } } /** * Turns highlighting on/off for strings * * @param boolean Whether to turn highlighting for strings on or off * @since 1.0.0 */'STRINGS'/** * Sets the styles for numbers. If $preserve_defaults is * true, then styles are merged with the default styles, with the * user defined styles having priority * * @param string The style to make the numbers * @param boolean Whether to merge the new styles with the old or just * to overwrite them * @since 1.0.0 */'STYLES']['NUMBERS''STYLES']['NUMBERS'][0] .= $style; } } /** * Turns highlighting on/off for numbers * * @param boolean Whether to turn highlighting for numbers on or off * @since 1.0.0 */'NUMBERS'/** * Sets the styles for methods. $key is a number that references the * appropriate "object splitter" - see the language file for the language * you are highlighting to get this number. If $preserve_defaults is * true, then styles are merged with the default styles, with the * user defined styles having priority * * @param int The key of the object splitter to change the styles of * @param string The style to make the methods * @param boolean Whether to merge the new styles with the old or just * to overwrite them * @since 1.0.0 */'STYLES']['METHODS''STYLES']['METHODS'/** * Turns highlighting on/off for methods * * @param boolean Whether to turn highlighting for methods on or off * @since 1.0.0 */'METHODS'/** * Sets the styles for regexps. If $preserve_defaults is * true, then styles are merged with the default styles, with the * user defined styles having priority * * @param string The style to make the regular expression matches * @param boolean Whether to merge the new styles with the old or just * to overwrite them * @since 1.0.0 */'STYLES']['REGEXPS''STYLES']['REGEXPS'/** * Turns highlighting on/off for regexps * * @param int The key of the regular expression group to turn on or off * @param boolean Whether to turn highlighting for the regular expression group on or off * @since 1.0.0 */'REGEXPS'/** * Sets whether a set of keywords are checked for in a case sensitive manner * * @param int The key of the keyword group to change the case sensitivity of * @param boolean Whether to check in a case sensitive manner or not * @since 1.0.0 */'CASE_SENSITIVE'/** * Sets the case that keywords should use when found. Use the constants: * * <ul> * <li><b>GESHI_CAPS_NO_CHANGE</b>: leave keywords as-is</li> * <li><b>GESHI_CAPS_UPPER</b>: convert all keywords to uppercase where found</li> * <li><b>GESHI_CAPS_LOWER</b>: convert all keywords to lowercase where found</li> * </ul> * * @param int A constant specifying what to do with matched keywords * @since 1.0.1 * @todo Error check the passed value */'CASE_KEYWORDS'/** * Sets how many spaces a tab is substituted for * * Widths below zero are ignored * * @param int The tab width * @since 1.0.0 *//** * Enables/disables strict highlighting. Default is off, calling this * method without parameters will turn it on. See documentation * for more details on strict mode and where to use it. * * @param boolean Whether to enable strict mode or not * @since 1.0.0 */'STRICT_MODE_APPLIES'/** * Disables all highlighting * * @since 1.0.0 * @todo Rewrite with an array traversal */// Context blocks /** * Enables all highlighting * * @since 1.0.0 * @todo Rewrite with array traversal */// Context blocks /** * Given a file extension, this method returns either a valid geshi language * name, or the empty string if it couldn't be found * * @param string The extension to get a language name for * @param array A lookup array to use instead of the default * @since 1.0.5 * @todo Re-think about how this method works (maybe make it private and/or make it * a extension->lang lookup?) * @todo static? */'actionscript''as'), 'ada''a', 'ada', 'adb', 'ads'), 'apache''conf'), 'asm''ash', 'asm'), 'asp''asp'), 'bash''sh'), 'c''c'), 'c_mac''c'), 'caddcl''cadlisp''cpp''cpp'), 'csharp''css''css'), 'delphi''dpk', 'dpr'), 'html4strict''html', 'htm'), 'java''java'), 'javascript''js'), 'lisp''lisp'), 'lua''lua'), 'mpasm''nsis''objc''oobas''oracle8''pascal''pas'), 'perl''pl', 'pm'), 'php''php', 'php5', 'phtml', 'phps'), 'python''py'), 'qbasic''bi'), 'smarty''vb''bas'), 'vbnet''visualfoxpro''xml''xml'''; } /** * Given a file name, this method loads its contents in, and attempts * to set the language automatically. An optional lookup table can be * passed for looking up the language name. If not specified a default * table is used * * The language table is in the form * <pre>array( * 'lang_name' => array('extension', 'extension', ...), * 'lang_name' ... * );</pre> * * @todo Complete rethink of this and above method * @since 1.0.5 */'''.'/** * Adds a keyword to a keyword group for highlighting * * @param int The key of the keyword group to add the keyword to * @param string The word to add to the keyword group * @since 1.0.0 */'KEYWORDS'/** * Removes a keyword from a keyword group * * @param int The key of the keyword group to remove the keyword from * @param string The word to remove from the keyword group * @since 1.0.0 */'KEYWORDS''KEYWORDS'/** * Creates a new keyword group * * @param int The key of the keyword group to create * @param string The styles for the keyword group * @param boolean Whether the keyword group is case sensitive ornot * @param array The words to use for the keyword group * @since 1.0.0 */'KEYWORDS''KEYWORDS''CASE_SENSITIVE''STYLES']['KEYWORDS'/** * Removes a keyword group * * @param int The key of the keyword group to remove * @since 1.0.0 */'KEYWORDS''KEYWORDS''CASE_SENSITIVE''STYLES']['KEYWORDS'/** * Sets the content of the header block * * @param string The content of the header block * @since 1.0.2 *//** * Sets the content of the footer block * * @param string The content of the footer block * @since 1.0.2 *//** * Sets the style for the header content * * @param string The style for the header content * @since 1.0.2 *//** * Sets the style for the footer content * * @param string The style for the footer content * @since 1.0.2 *//** * Sets the base URL to be used for keywords * * @param int The key of the keyword group to set the URL for * @param string The URL to set for the group. If {FNAME} is in * the url somewhere, it is replaced by the keyword * that the URL is being made for * @since 1.0.2 */'URLS'][$group] = $url; } /** * Sets styles for links in code * * @param int A constant that specifies what state the style is being * set for - e.g. :hover or :visited * @param string The styles to use for that state * @since 1.0.2 *//** * Sets the target for links in code * * @param string The target for links in the code, e.g. _blank * @since 1.0.3 */''' target="' . $target . '" '; } } /** * Sets styles for important parts of the code * * @param string The styles to use on important parts of the code * @since 1.0.2 *//** * Sets whether context-important blocks are highlighted * * @todo REMOVE THIS SHIZ FROM GESHI! * @deprecated *//** * Whether CSS IDs should be added to each line * * @param boolean If true, IDs will be added to each line. * @since 1.0.2 *//** * Specifies which lines to highlight extra * * @param mixed An array of line numbers to highlight, or just a line * number on its own. * @since 1.0.2 * @todo Some data replication here that could be cut down on *//** * Sets the style for extra-highlighted lines * * @param string The style for extra-highlighted lines * @since 1.0.2 *//** * Sets what number line numbers should start at. Should * be a positive integer, and will be converted to one. * * <b>Warning:</b> Using this method will add the "start" * attribute to the <ol> that is used for line numbering. * This is <b>not</b> valid XHTML strict, so if that's what you * care about then don't use this method. Firefox is getting * support for the CSS method of doing this in 1.1 and Opera * has support for the CSS method, but (of course) IE doesn't * so it's not worth doing it the CSS way yet. * * @param int The number to start line numbers at * @since 1.0.2 *//** * Sets the encoding used for htmlspecialchars(), for international * support. * * @param string The encoding to use for the source * @since 1.0.3 *//** * Returns the code in $this->source, highlighted and surrounded by the * nessecary HTML. * * This should only be called ONCE, cos it's SLOW! If you want to highlight * the same source multiple times, you're better off doing a whole lot of * str_replaces to replace the <span>s * * @since 1.0.0 */// Start the timer // Firstly, if there is an error, we won't highlight // Stop Timing // Add spaces for regular expression matching and line numbers $code = ' ' . $this->source . ' '; // Replace all newlines to a common form. "\r\n", "\n""\r", "\n", $code); // Initialise various stuff ''// Turn highlighting on if strict mode doesn't apply to this language ''; // Whether to highlight inside a block of code ''; $result = ''; // "Important" selections are handled like multiline comments // @todo GET RID OF THIS SHIZ 'COMMENT_MULTI'// Break the source into bits. Each bit will be a portion of the code // within script delimiters - for example, HTML between < and > '''SCRIPT_DELIMITERS'// Get the next little bit for this opening string // If it matches... // We start a new block with the highlightable // code in it // No point going around again... 'SCRIPT_DELIMITERS'// Found the closing tag // We check code from our current position BACKWARDS. This is so // the ending string for highlighting can be included in the block ''; // Add the string to the rest of the string for this part ''; $char = ''''// Not strict mode - simply dump the source into // the array at index 1 (the first highlightable block) '', 1 => $code ) ); } // Now we go through each part. We know that even-indexed parts are // code that shouldn't be highlighted, and odd-indexed parts should // be highlighted // If this block should be highlighted... // Find the class key for this block of code 'SCRIPT_DELIMITERS''STYLES']['SCRIPT''''SCRIPT']) { // Add a span element around the source to // highlight the overall source block 'STYLES']['SCRIPT''') { $attributes = ' style="''STYLES']['SCRIPT''"'' class="sc''"'; } $result .= "<span$attributes>"'HIGHLIGHT_STRICT_BLOCK'// Now, highlight the code in this block. This code // is really the engine of GeSHi (along with the method // parse_non_string_part). // Get the next char // Is this char the newline and line numbers being used? "\n") { // If so, is there a string open? If there is, we should end it before // the newline and begin it again (so when <li>s are put in the source // remains XHTML compliant) // note to self: This opens up possibility of config files specifying // that languages can/cannot have multiline strings??? ' style="''STYLES']['STRINGS'][0] . '"'' class="st0"'; } $char = '</span>' . $char . "<span$attributes>"// A match of a string delimiter 'ESCAPE_CHAR''STRINGS''</span>''''QUOTEMARKS''''STRINGS']) { // The start of a new string ' style="''STYLES']['STRINGS'][0] . '"'' class="st0"'; } $char = "<span$attributes>"'''ESCAPE_CHAR''')) { // An escape character 'ESCAPE_CHAR'' style="''STYLES']['ESCAPE_CHAR'][0] . '"'' class="es0"'; } $char = "<span$attributes>""\n") { // escaping a newline, what's the point in putting the span around // the newline? It only causes hassles when inserting line numbers $char .= '</span>''ESCAPE_CHAR']) { $char .= '</span>''ESCAPE_CHAR']) { $char .= '</span>''') { // Is this a multiline comment? 'COMMENT_MULTI'//@todo If remove important do remove here 'COMMENTS']['MULTI'' style="''STYLES']['COMMENTS']['MULTI'] . '"'' class="coMULTI"'"<span$attributes>"' style="''"'' class="imp"'; } // We don't include the start of the comment if it's an // "important" part "<span$attributes>"// Short-cut through all the multiline code 'COMMENTS']['MULTI'// strreplace to put close span and open span around multiline newlines "\n", "</span>\n<span$attributes>"'COMMENTS']['MULTI''</span>'// parse the rest ''// If we haven't matched a multiline comment, try single-line comments 'COMMENT_SINGLE''CASE_SENSITIVE''COMMENTS'' style="''STYLES']['COMMENTS''"'' class="co''"'"<span$attributes>""\n"'COMMENTS'"</span>"; } // Take into account that the comment might be the last in the source "\n"// parse the rest '''') { // Otherwise, convert it to HTML form 'utf-8') { //only escape <128 (we don't want to break multibyte chars) //encode everthing // Where are we adding this char? ''// Parse the last bit ''// Close the <span> that surrounds the block 'STYLES']['SCRIPT''''SCRIPT']) { $result .= '</span>'// Else not a block to highlight // Parse the last stuff (redundant?) // Lop off the very first and last spaces // Are we still in a string? '</span>'; } // We're finished: stop timing /** * Swaps out spaces and tabs for HTML indentation. Not needed if * the code is in a pre block... * * @param string The source to indent * @return string The source with HTML indenting applied * @since 1.0.0 * @access private *//// Replace tabs with the correct number of spaces "\t""\n""\t"//echo 'checking line ' . $key . '<br />'; ''; //echo '<pre>line: ' . htmlspecialchars($line) . '</pre>'; // Simple engine to work out whether we're in a tag. // If we are we modify $pos. This is so we ignore HTML // in the line and only workout the tab replacement // via the actual content of the string // This test could be improved to include strings in the // html so that < or > would be allowed in user's styles // (e.g. quotes: '<' '>'; or similar) '>''>''<''<''&' == $char) { //echo "matched & in line... "; //$substr_5 = substr($line, 5, 1); ';'//echo "found entity at $posi\n"; '&'"\t" == $char) { $str = ''; // OPTIMISE - move $strs out. Make an array: // $tabs = array( // 1 => ' ', // 2 => ' ', // 3 => ' ' etc etc // to use instead of building a string every time ' ', 1 => ' '); //echo "building (pos=$pos i=$i) (" . ($i - $pos) . ") " . ($tab_width - (($i - $pos) % $tab_width)) . " spaces\n"; //$pos--; //$pos -= $tab_width-1; "\t", $i + 1)) { //$lines[$key] = $result_line; //echo 'got here'; //++$pos; "\n", $lines); } // Other whitespace ' ', ' '' ', ' '"\n ", "\n "/** * Changes the case of a keyword for those languages where a change is asked for * * @param string The keyword to change the case of * @return string The keyword with its case changed * @since 1.0.0 * @access private */'CASE_KEYWORDS''CASE_KEYWORDS'/** * Adds a url to a keyword where needed. * * @param string The keyword to add the URL HTML to * @param int What group the keyword is from * @param boolean Whether to get the HTML for the start or end * @return The HTML for either the start or end of the HTML <a> tag * @since 1.0.2 * @access private * @todo Get rid of ender */'URLS''URLS'][$group] != '''</') { // There is a base group for this keyword 'BEGIN') { // HTML workaround... not good form (tm) but should work for 1.0.X '<''>''''CASE_SENSITIVE''<|UR1|"''{FNAME}', '.''<DOT>''URLS'][$group] ) . '">'''; // HTML fix. Again, dirty hackage... 'html4strict' && '>''</a>'; } } } /** * Takes a string that has no strings or comments in it, and highlights * stuff like keywords, numbers and methods. * * @param string The string to parse for keyword, numbers etc. * @since 1.0.0 * @access private * @todo BUGGY! Why? Why not build string and return? */' '// These vars will disappear in the future $func = '$this->change_case'; $func2 = '$this->add_url_to_keyword'; // // Regular expressions // 'REGEXPS''REGEXPS'"#""#{$regexp[GESHI_MODIFIERS]}", "{$regexp[GESHI_BEFORE]}<|!REG3XP$key!>{$regexp[GESHI_REPLACE]}|>{$regexp[GESHI_AFTER]}""#("")#", "<|!REG3XP$key!>\\1|>"// // Highlight numbers. This regexp sucks... anyone with a regexp that WORKS // here wins a cookie if they send it to me. At the moment there's two doing // almost exactly the same thing, except the second one prevents a number // being highlighted twice (eg <span...><span...>5</span></span>) // Put /NUM!/ in for the styles, which gets replaced at the end. // 'NUMBERS''#[0-9]#''#([^a-zA-Z0-9\#])([0-9]+)([^a-zA-Z0-9])#', "\\1<|/NUM!/>\\2|>\\3"'#([^a-zA-Z0-9\#>])([0-9]+)([^a-zA-Z0-9])#', "\\1<|/NUM!/>\\2|>\\3"// Highlight keywords // if there is a couple of alpha symbols there *might* be a keyword '#[a-zA-Z]{2,}#''KEYWORDS''KEYWORDS'// // This replacement checks the word is on it's own (except if brackets etc // are next to it), then highlights it. We don't put the color=" for the span // in just yet - otherwise languages with the keywords "color" or "or" have // a fit. // ' '; // Might make a more unique string for putting the number in soon // Basically, we don't put the styles in yet because then the styles themselves will // get highlighted if the language has a CSS keyword in it (like CSS, for example ;)) $styles = "/$k/"'CASE_SENSITIVE'"#([^a-zA-Z0-9\$_\|\#;>])($keyword)([^a-zA-Z0-9_<\|%\-&])#e", "'\\1' . $func2('\\2', '$k', 'BEGIN') . '<|$styles>' . $func('\\2') . '|>' . $func2('\\2', '$k', 'END') . '\\3'"// Change the case of the word. "#([^a-zA-Z0-9\$_\|\#;>])($keyword)([^a-zA-Z0-9_<\|%\-&])#ie", "'\\1' . $func2('\\2', '$k', 'BEGIN') . '<|$styles>' . $func('\\2') . '|>' . $func2('\\2', '$k', 'END') . '\\3'"// // Now that's all done, replace /[number]/ with the correct styles // 'KEYWORDS'' style="''STYLES']['KEYWORDS'][$k] . '"'' class="kw' . $k . '"'"/$k/"// Put number styles in 'NUMBERS']) { $attributes = ' style="''STYLES']['NUMBERS'][0] . '"'' class="nu0"''/NUM!/'// // Highlight methods and fields in objects // 'METHODS''OOLANG''OBJECT_SPLITTERS'' style="''STYLES']['METHODS''"'' class="me''"'"#("'OBJECT_SPLITTERS'"[\s]*)([a-zA-Z\*\(][a-zA-Z0-9_\*]*)#", "\\1<|$attributes>\\2|>"// // Highlight brackets. Yes, I've tried adding a semi-colon to this list. // You try it, and see what happens ;) // TODO: Fix lexic permissions not converting entities if shouldn't // be highlighting regardless // 'BRACKETS''[', ']', '(', ')', '{', '}''<| style="''STYLES']['BRACKETS'][0] . '">[|>', '<| style="''STYLES']['BRACKETS'][0] . '">]|>', '<| style="''STYLES']['BRACKETS'][0] . '">(|>', '<| style="''STYLES']['BRACKETS'][0] . '">)|>', '<| style="''STYLES']['BRACKETS'][0] . '">{|>', '<| style="''STYLES']['BRACKETS'][0] . '">}|>''<| class="br0">[|>', '<| class="br0">]|>', '<| class="br0">(|>', '<| class="br0">)|>', '<| class="br0">{|>', '<| class="br0">}|>'// // Add class/style for regexps // 'REGEXPS''REGEXPS'' style="''STYLES']['REGEXPS''"'' class="re''"'"!REG3XP$key!", "$attributes"// Replace <DOT> with . for urls '<DOT>', '.'// Replace <|UR1| with <a href= for urls also '<|UR1|', '<a'' href=''<|UR1|', '<a'' style="''" href=''<|UR1|', '<a'' href='// // NOW we add the span thingy ;) // '<|', '<span''|>', '</span>'/** * Sets the time taken to parse the code * * @param microtime The time when parsing started * @param microtime The time when parsing ended * @since 1.0.2 * @access private */' '' '/** * Gets the time taken to parse the code * * @return double The time taken to parse the code * @since 1.0.2 *//** * Gets language information and stores it for later use * * @access private * @todo Needs to load keys for lexic permissions for keywords, regexps etc */// Perhaps some checking might be added here later to check that // $language data is a valid thing but maybe not // Set strict mode if should be set 'STRICT_MODE_APPLIES'// Set permissions for all lexics to true // so they'll be highlighted by default 'KEYWORDS''KEYWORDS''COMMENT_SINGLE''COMMENTS''REGEXPS''REGEXPS'// Set default class for CSS /** * Takes the parsed code and various options, and creates the HTML * surrounding it to make it look nice. * * @param string The code already parsed * @return string The code nicely finalised * @since 1.0.0 * @access private */// Remove end parts of important declarations // This is BUGGY!! My fault for bad code: fix coming in 1.2 // @todo Remove this crap ''// Add HTML whitespace stuff if we're using the <div> header // If we're using line numbers, we insert <li>s and appropriate // markup to style them (otherwise we don't need to do anything) // If we're using the <pre> header, we shouldn't add newlines because // the <pre> will line-break them (and the <li>s already do this for us) "\n" : ''; // Get code into lines "\n"// Set vars to defaults for following loop ''; $i = 0; // Foreach line... ' '; // If this is a "special line"... // Set the attributes to style the line ' class="li2"'' class="de2"'' style="''"'; // This style "covers up" the special styles set for special lines // so that styles applied to special lines don't apply to the actual // code on that line ' style="''"'; } // Span or div? $start = "<div$def_attr>"'</div>'' class="li1"'' class="de1"'' style="''"'' style="''"'; } $start = "<div$def_attr>"'</div>'; } ++$i; // Are we supposed to use ids? If so, add them " id=\"{$this->overall_id}-{$i}\""" class=\"ln-xtra\""" style=\"{$this->highlight_extra_lines_style}\""; } // Add in the line surrounded by appropriate list HTML "<li$attr>$start$line$end</li>$ls"// No line numbers, but still need to handle highlighting lines extra. // Have to use divs so the full width of the code is highlighted "\n"''// Make lines have at least one space in them if they're empty $line = ($line) ? $line : ' ''<div class="ln-xtra">'"<div style=\"{$this->highlight_extra_lines_style}\">""</div>\n""\n"; } } } // purge some unnecessary stuff '#<span[^>]+>(\s*)</span>#', '\\1''#<div[^>]+>(\s*)</div>#', '\\1'// enforce line numbers when using pre '<li></li>', '<li> </li>'/** * Creates the header for the code block (with correct attributes) * * @return string The header for the code block * @since 1.0.0 * @access private */// Get attributes needed ''' start="''"'; } // Get the header HTML "$header<ol$ol_attributes>"// Work out what to return and do it "<pre$attributes>$header<ol$ol_attributes>""<div$attributes>$header<ol$ol_attributes>""<pre$attributes>$header""<div$attributes>$header"; } } } /** * Returns the header content, formatted for output * * @return string The header content, formatted for output * @since 1.0.2 * @access private */"\n", ''' class="head"'" style=\"{$this->header_content_style}\"""<div$attr>$header</div>"; } } /** * Returns the footer for the code block. * * @return string The footer for the code block * @since 1.0.0 * @access private */'</ol>'"</ol>$footer_content</div>""$footer_content</div>""</ol>$footer_content</pre>""$footer_content</pre>"; } } /** * Returns the footer content, formatted for output * * @return string The footer content, formatted for output * @since 1.0.2 * @access private */"\n", ''' class="foot"'" style=\"{$this->footer_content_style}\"""<div$attr>$footer</div>"; } } /** * Replaces certain keywords in the header and footer with * certain configuration values * * @param string The header or footer content to do replacement on * @return string The header or footer with replaced keywords * @since 1.0.2 * @access private */'<TIME>''<LANGUAGE>''<VERSION>'/** * Gets the CSS attributes for this code * * @return The CSS attributes for this code * @since 1.0.0 * @access private * @todo Document behaviour change - class is outputted regardless of whether we're using classes or not. * Same with style */'''') { $attributes .= " class=\"{$this->overall_class}\""'') { $attributes .= " id=\"{$this->overall_id}\""'') { $attributes .= ' style="''"'/** * Returns a stylesheet for the highlighted code. If $economy mode * is true, we only return the stylesheet declarations that matter for * this code block instead of the whole thing * * @param boolean Whether to use economy mode or not * @return string A stylesheet built on the data for the current language * @since 1.0.0 */// If there's an error, chances are that the language file // won't have populated the language data file, so we can't // risk getting a stylesheet... ''; } // First, work out what the selector should be. If there's an ID, // that should be used, the same for a class. Otherwise, a selector // of '' means that these styles will be applied anywhere '') ? "#{$this->overall_id} " : ''; $selector = ($selector == '''') ? ".{$this->overall_class} " : $selector; // Header of the stylesheet "/**\n * GeSHi Dynamically Generated Stylesheet\n * --------------------------------------\n * Dynamically generated stylesheet for {$this->language}\n * CSS class: {$this->overall_class}, CSS id: {$this->overall_id}\n * GeSHi (c) Nigel McNie 2004 (http://qbnz.com/highlighter)\n */\n"'/* GeSHi (c) Nigel McNie 2004 (http://qbnz.com/highlighter) */' . "\n"; } // Set the <ol> to have no effect at all if there are line numbers // (<ol>s have margins that should be destroyed so all layout is // controlled by the set_overall_style method, which works on the // <pre> or <div> container). Additionally, set default styles for lines //$stylesheet .= "$selector, {$selector}ol, {$selector}ol li {margin: 0;}\n"; $stylesheet .= "$selector.de1, $selector.de2 {{$this->code_style}}\n"; } // Add overall styles '') { $stylesheet .= "$selector {{$this->overall_style}}\n"; } // Add styles for links '') { $stylesheet .= "{$selector}a:link {{$style}}\n"'') { $stylesheet .= "{$selector}a:hover {{$style}}\n"'') { $stylesheet .= "{$selector}a:active {{$style}}\n"'') { $stylesheet .= "{$selector}a:visited {{$style}}\n"; } } // Header and footer '') { $stylesheet .= "$selector.head {{$this->header_content_style}}\n"'') { $stylesheet .= "$selector.foot {{$this->footer_content_style}}\n"; } // Styles for important stuff '') { $stylesheet .= "$selector.imp {{$this->important_styles}}\n"; } // Styles for lines being highlighted extra "$selector.ln-xtra {{$this->highlight_extra_lines_style}}\n"; } // Simple line number styles '')) { $stylesheet .= "{$selector}li {{$this->line_style1}}\n"; } // If there is a style set for fancy line numbers, echo it out '')) { $stylesheet .= "{$selector}li.li2 {{$this->line_style2}}\n"'STYLES']['KEYWORDS''KEYWORDS'][$group] || $styles == ''))) { $stylesheet .= "$selector.kw$group {{$styles}}\n"'STYLES']['COMMENTS''''COMMENTS'][$group])) { $stylesheet .= "$selector.co$group {{$styles}}\n"'STYLES']['ESCAPE_CHAR''''ESCAPE_CHAR'])) { $stylesheet .= "$selector.es$group {{$styles}}\n"'STYLES']['SYMBOLS''''BRACKETS'])) { $stylesheet .= "$selector.br$group {{$styles}}\n"'STYLES']['STRINGS''''STRINGS'])) { $stylesheet .= "$selector.st$group {{$styles}}\n"'STYLES']['NUMBERS''''NUMBERS'])) { $stylesheet .= "$selector.nu$group {{$styles}}\n"'STYLES']['METHODS''''METHODS'])) { $stylesheet .= "$selector.me$group {{$styles}}\n"'STYLES']['SCRIPT''')) { $stylesheet .= "$selector.sc$group {{$styles}}\n"'STYLES']['REGEXPS''''REGEXPS'][$group])) { $stylesheet .= "$selector.re$group {{$styles}}\n"// End Class GeSHi 'geshi_highlight')) { /** * Easy way to highlight stuff. Behaves just like highlight_string * * @param string The code to highlight * @param string The language to highlight the code in * @param string The path to the language files. You can leave this blank if you need * as from version 1.0.7 the path should be automatically detected * @param boolean Whether to return the result or to echo * @return string The code highlighted (if $return is true) * @since 1.0.2 */'<code>''</code>''<code>''</code>'