diff options
author | Andreas Gohr <andi@splitbrain.org> | 2008-03-26 22:17:55 +0100 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2008-03-26 22:17:55 +0100 |
commit | d09ae2055575141a00e67faeadb9bcb3d8285f3f (patch) | |
tree | 5f8f372f379b77f8f36805468d4e60fdb8ebc1b5 /inc/geshi.php | |
parent | 3d1f9ec3674462e63f4195dd834603148a7c7b42 (diff) | |
download | rpg-d09ae2055575141a00e67faeadb9bcb3d8285f3f.tar.gz rpg-d09ae2055575141a00e67faeadb9bcb3d8285f3f.tar.bz2 |
GeSHi update to 1.0.7.21
darcs-hash:20080326211755-7ad00-98c89cb8da99fab17b88222d33a312a020527cdb.gz
Diffstat (limited to 'inc/geshi.php')
-rw-r--r-- | inc/geshi.php | 379 |
1 files changed, 282 insertions, 97 deletions
diff --git a/inc/geshi.php b/inc/geshi.php index 832b62efe..362acd9c6 100644 --- a/inc/geshi.php +++ b/inc/geshi.php @@ -27,8 +27,8 @@ * * @package geshi * @subpackage core - * @author Nigel McNie <nigel@geshi.org> - * @copyright (C) 2004 - 2007 Nigel McNie + * @author Nigel McNie <nigel@geshi.org>, Benny Baumann <BenBE@omorphia.de> + * @copyright (C) 2004 - 2007 Nigel McNie, (C) 2007 - 2008 Benny Baumann * @license http://gnu.org/copyleft/gpl.html GNU GPL * */ @@ -41,7 +41,7 @@ // /** The version of this GeSHi file */ -define('GESHI_VERSION', '1.0.7.20'); +define('GESHI_VERSION', '1.0.7.21'); // Define the root directory for the GeSHi code tree if (!defined('GESHI_ROOT')) { @@ -152,8 +152,8 @@ define('GESHI_ERROR_INVALID_LINE_NUMBER_TYPE', 5); * about how to use this class. * * @package geshi - * @author Nigel McNie <nigel@geshi.org> - * @copyright (C) 2004 - 2007 Nigel McNie + * @author Nigel McNie <nigel@geshi.org>, Benny Baumann <BenBE@omorphia.de> + * @copyright (C) 2004 - 2007 Nigel McNie, (C) 2007 - 2008 Benny Baumann */ class GeSHi { /**#@+ @@ -235,7 +235,7 @@ class GeSHi { 'REGEXPS' => array(), 'ESCAPE_CHAR' => true, 'BRACKETS' => true, - 'SYMBOLS' => true, + 'SYMBOLS' => false, 'STRINGS' => true, 'NUMBERS' => true, 'METHODS' => true, @@ -315,6 +315,12 @@ class GeSHi { var $highlight_extra_lines = array(); /** + * Styles of lines that should be highlighted extra + * @var array + */ + var $highlight_extra_lines_styles = array(); + + /** * Styles of extra-highlighted lines * @var string */ @@ -614,6 +620,7 @@ class GeSHi { * * @param string The style to use for actual code * @param boolean Whether to merge the current styles with the new styles + * @since 1.0.2 */ function set_code_style($style, $preserve_defaults = false) { if (!$preserve_defaults) { @@ -813,17 +820,20 @@ class GeSHi { * @param string The style to make the symbols * @param boolean Whether to merge the new styles with the old or just * to overwrite them + * @param int Tells the group of symbols for which style should be set. * @since 1.0.1 */ - function set_symbols_style($style, $preserve_defaults = false) { + function set_symbols_style($style, $preserve_defaults = false, $group = 0) { if (!$preserve_defaults) { - $this->language_data['STYLES']['SYMBOLS'][0] = $style; + $this->language_data['STYLES']['SYMBOLS'][$group] = $style; } else { - $this->language_data['STYLES']['SYMBOLS'][0] .= $style; + $this->language_data['STYLES']['SYMBOLS'][$group] .= $style; } // For backward compatibility - $this->set_brackets_style ($style, $preserve_defaults); + if(0 == $group) { + $this->set_brackets_style ($style, $preserve_defaults); + } } /** @@ -978,10 +988,12 @@ class GeSHi { * * @param int A constant specifying what to do with matched keywords * @since 1.0.1 - * @todo Error check the passed value */ function set_case_keywords($case) { - $this->language_data['CASE_KEYWORDS'] = $case; + if(in_array($case, array( + GESHI_CAPS_NO_CHANGE, GESHI_CAPS_UPPER, GESHI_CAPS_LOWER))) { + $this->language_data['CASE_KEYWORDS'] = $case; + } } /** @@ -1005,6 +1017,7 @@ class GeSHi { * Sets whether or not to use tab-stop width specifed by language * * @param boolean Whether to use language-specific tab-stop widths + * @since 1.0.7.20 */ function set_use_language_tab_width($use) { $this->use_language_tab_width = (bool) $use; @@ -1015,6 +1028,7 @@ class GeSHi { * preference * * @return int Tab width + * @since 1.0.7.20 */ function get_real_tab_width() { if (!$this->use_language_tab_width || !isset($this->language_data['TAB_WIDTH'])) { @@ -1042,42 +1056,37 @@ class GeSHi { * Disables all highlighting * * @since 1.0.0 - * @todo Rewrite with an array traversal + * @todo Rewrite with array traversal + * @deprecated In favour of enable_highlighting */ function disable_highlighting() { - foreach ($this->lexic_permissions as $key => $value) { - if (is_array($value)) { - foreach ($value as $k => $v) { - $this->lexic_permissions[$key][$k] = false; - } - } - else { - $this->lexic_permissions[$key] = false; - } - } - // Context blocks - $this->enable_important_blocks = false; + $this->enable_highlighting(false); } /** * Enables all highlighting * + * The optional flag parameter was added in version 1.0.7.21 and can be used + * to enable (true) or disable (false) all highlighting. + * * @since 1.0.0 + * @param boolean A flag specifying whether to enable or disable all highlighting * @todo Rewrite with array traversal */ - function enable_highlighting() { + function enable_highlighting($flag = true) { + $flag = $flag ? true : false; foreach ($this->lexic_permissions as $key => $value) { if (is_array($value)) { foreach ($value as $k => $v) { - $this->lexic_permissions[$key][$k] = true; + $this->lexic_permissions[$key][$k] = $flag; } } else { - $this->lexic_permissions[$key] = true; + $this->lexic_permissions[$key] = $flag; } } // Context blocks - $this->enable_important_blocks = true; + $this->enable_important_blocks = $flag; } /** @@ -1085,14 +1094,14 @@ class GeSHi { * 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 + * @param array A lookup array to use instead of the default one * @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? */ function get_language_name_from_extension( $extension, $lookup = array() ) { - if ( !$lookup ) { + if ( !is_array($lookup) || !count($lookup)) { $lookup = array( 'actionscript' => array('as'), 'ada' => array('a', 'ada', 'adb', 'ads'), @@ -1108,7 +1117,8 @@ class GeSHi { 'cpp' => array('cpp', 'h', 'hpp'), 'csharp' => array(), 'css' => array('css'), - 'delphi' => array('dpk', 'dpr'), + 'delphi' => array('dpk', 'dpr', 'pp', 'pas'), + 'dos' => array('bat', 'cmd'), 'html4strict' => array('html', 'htm'), 'java' => array('java'), 'javascript' => array('js'), @@ -1119,7 +1129,7 @@ class GeSHi { 'objc' => array(), 'oobas' => array(), 'oracle8' => array(), - 'pascal' => array('pas'), + 'pascal' => array(), 'perl' => array('pl', 'pm'), 'php' => array('php', 'php5', 'phtml', 'phps'), 'python' => array('py'), @@ -1155,6 +1165,8 @@ class GeSHi { * 'lang_name' ... * );</pre> * + * @param string The filename to load the source from + * @param array A lookup array to use instead of the default one * @todo Complete rethink of this and above method * @since 1.0.5 */ @@ -1325,8 +1337,10 @@ class GeSHi { /** * Sets whether context-important blocks are highlighted * + * @param boolean Tells whether to enable or disable highlighting of important blocks * @todo REMOVE THIS SHIZ FROM GESHI! * @deprecated + * @since 1.0.2 */ function enable_important_blocks($flag) { $this->enable_important_blocks = ( $flag ) ? true : false; @@ -1345,19 +1359,27 @@ class GeSHi { /** * Specifies which lines to highlight extra * + * The extra style parameter was added in 1.0.7.21. + * * @param mixed An array of line numbers to highlight, or just a line * number on its own. + * @param string A string specifying the style to use for this line * @since 1.0.2 * @todo Some data replication here that could be cut down on */ - function highlight_lines_extra($lines) { + function highlight_lines_extra($lines, $style = null) { if (is_array($lines)) { foreach ($lines as $line) { - $this->highlight_extra_lines[intval($line)] = intval($line); + $this->highlight_lines_extra(line, $style); } } else { $this->highlight_extra_lines[intval($lines)] = intval($lines); + if ($style != null) { + $this->highlight_extra_lines_styles[intval($lines)] = $style; + } else { + unset($this->highlight_extra_lines_styles[intval($lines)]); + } } } @@ -1375,6 +1397,7 @@ class GeSHi { * Sets the line-ending * * @param string The new line-ending + * @since 1.0.2 */ function set_line_ending($line_ending) { $this->line_ending = (string)$line_ending; @@ -1421,6 +1444,7 @@ class GeSHi { * Turns linking of keywords on or off. * * @param boolean If true, links will be added to keywords + * @since 1.0.2 */ function enable_keyword_links($enable = true) { $this->keyword_links = ($enable) ? true : false; @@ -1707,7 +1731,7 @@ class GeSHi { $com_len = strlen($open); $test_str = substr( $part, $i, $com_len ); $test_str_match = $test_str; - if ($open == $test_str) { + if (strtolower($open) == strtolower($test_str)) { $COMMENT_MATCHED = true; //@todo If remove important do remove here if ($this->lexic_permissions['COMMENTS']['MULTI'] || @@ -1756,7 +1780,7 @@ class GeSHi { count($this->highlight_extra_lines) > 0)) { // strreplace to put close span and open span around multiline newlines $test_str .= str_replace( - "\n", "</span>\n<span$attributes>", + "\n", "</span>\n<span$attributes>", str_replace("\n ", "\n ", $rest_of_comment) ); } @@ -1789,6 +1813,25 @@ class GeSHi { else { $match = (strtolower($comment_mark) == strtolower($test_str)); } + //This check will find special variables like $# in bash or compiler directives of Delphi beginning {$ + if($match) { + $disallowed_before = ""; + $disallowed_after = ""; + + if(isset($this->language_data['PARSER_CONTROL'])) { + if (isset($this->language_data['PARSER_CONTROL']['COMMENTS'])) { + if (isset($this->language_data['PARSER_CONTROL']['COMMENTS']['DISALLOWED_BEFORE'])) { + $disallowed_before = $this->language_data['PARSER_CONTROL']['COMMENTS']['DISALLOWED_BEFORE']; + } + if (isset($this->language_data['PARSER_CONTROL']['COMMENTS']['DISALLOWED_AFTER'])) { + $disallowed_after = $this->language_data['PARSER_CONTROL']['COMMENTS']['DISALLOWED_AFTER']; + } + } + } + + $match = $match && (!strlen($disallowed_before) || ((false === strpos($disallowed_before, substr($part, $i-1, 1))) && (0!=$i))); + $match = $match && (!strlen($disallowed_after) || ((false === strpos($disallowed_after, substr($part, $i+1, 1))) && (strlen($part)-1>$i))); + } if ($match) { $COMMENT_MATCHED = true; if ($this->lexic_permissions['COMMENTS'][$comment_key]) { @@ -1980,7 +2023,7 @@ class GeSHi { } // Other whitespace // BenBE: Fix to reduce the number of replacements to be done - $result = str_replace("\n ", "\n ", $result); + $result = preg_replace('/^ /m', ' ', $result); $result = str_replace(' ', ' ', $result); if ($this->line_numbers == GESHI_NO_LINE_NUMBERS) { @@ -2049,8 +2092,9 @@ class GeSHi { return '<|UR1|"' . str_replace( - array('{FNAME}', '.'), - array(GeSHi::hsc($word), '<DOT>'), + array('{FNAME}', '{FNAMEL}', '{FNAMEU}', '.'), + array(GeSHi::hsc($word), GeSHi::hsc(strtolower($word)), + GeSHi::hsc(strtoupper($word)), '<DOT>'), $this->language_data['URLS'][$group] ) . '">'; } @@ -2130,23 +2174,26 @@ class GeSHi { // 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/"; - if ($this->language_data['CASE_SENSITIVE'][$k]) { - $stuff_to_parse = preg_replace( - "/([^a-zA-Z0-9\$_\|\#;>|^])($keyword)(?=[^a-zA-Z0-9_<\|%\-&])/e", - "'\\1' . $func2('\\2', '$k', 'BEGIN') . '<|$styles>' . $func('\\2') . '|>' . $func2('\\2', '$k', 'END')", - $stuff_to_parse - ); - } - else { - // Change the case of the word. - // hackage again... must... release... 1.2... - if ('smarty' == $this->language) { $hackage = '\/'; } else { $hackage = ''; } - $stuff_to_parse = preg_replace( - "/([^a-zA-Z0-9\$_\|\#;>$hackage|^])($keyword)(?=[^a-zA-Z0-9_<\|%\-&])/ie", - "'\\1' . $func2('\\2', '$k', 'BEGIN') . '<|$styles>' . $func('\\2') . '|>' . $func2('\\2', '$k', 'END')", - $stuff_to_parse - ); + $modifiers = ($this->language_data['CASE_SENSITIVE'][$k]) ? "e" : "ie"; + + $disallowed_before = "a-zA-Z0-9\$_\|\#;>|^"; + $disallowed_after = "a-zA-Z0-9_<\|%\\-&"; + if(isset($this->language_data['PARSER_CONTROL'])) { + if (isset($this->language_data['PARSER_CONTROL']['KEYWORDS'])) { + if (isset($this->language_data['PARSER_CONTROL']['KEYWORDS']['DISALLOWED_BEFORE'])) { + $disallowed_before = $this->language_data['PARSER_CONTROL']['KEYWORDS']['DISALLOWED_BEFORE']; + } + if (isset($this->language_data['PARSER_CONTROL']['KEYWORDS']['DISALLOWED_AFTER'])) { + $disallowed_after = $this->language_data['PARSER_CONTROL']['KEYWORDS']['DISALLOWED_AFTER']; + } + } } + $stuff_to_parse = preg_replace( + "/([^$disallowed_before])($keyword)(?=[^$disallowed_after])/$modifiers", + "'\\1' . $func2('\\2', '$k', 'BEGIN') . '<|$styles>' . $func('\\2') . '|>' . $func2('\\2', '$k', 'END')", + $stuff_to_parse + ); + $stuff_to_parse = substr($stuff_to_parse, 0, strlen($stuff_to_parse) - 1); } } @@ -2224,25 +2271,113 @@ class GeSHi { $stuff_to_parse = str_replace( $code_entities_match, $code_entities_replace, $stuff_to_parse ); } + //FIX for symbol highlighting ... + if($this->lexic_permissions['SYMBOLS']) { + //As this is a costy operation, we avoid doing it for multiple groups ... + //Instead we perform it for all symbols at once. + // + //For this to work, we need to reorganize the data arrays. + $symbol_data = $symbol_preg = array(); + foreach($this->language_data['SYMBOLS'] as $key => $symbols) { + if(is_array($symbols)) { + foreach($symbols as $sym) { + if(!isset($symbol_data[$sym])) { + $symbol_data[GeSHi::hsc($sym)] = $key; + $symbol_preg[] = preg_quote(GeSHi::hsc($sym), '/'); + } + } + } else { + if(!isset($symbol_data[$symbols])) { + $symbol_data[GeSHi::hsc($symbols)] = 0; + $symbol_preg[] = preg_quote(GESHI::hsc($symbols), '/'); + } + } + } + //Now we have an array with each possible symbol as the key and the style as the actual data. + //This way we can set the correct style just the moment we highlight ... + // + //Now we need to rewrite our array to get a search string that + $sym_search = implode("|", $symbol_preg); + //Get all matches and throw away those witin a block that is already highlighted... (i.e. matched by a regexp) + preg_match_all("/(?:" . $sym_search . ")+/", $stuff_to_parse, $matches_in_stuff, PREG_OFFSET_CAPTURE | PREG_SET_ORDER); + //Match anything that is a highlighted block ... + preg_match_all("/<\|(?:<DOT>|[^>])+>(?:(?!\|>).*?)\|>|<\/a>/", $stuff_to_parse, $highlighted_in_stuff, PREG_OFFSET_CAPTURE); + foreach($matches_in_stuff as $stuff_match_id => $stuff_match_data) { + foreach($highlighted_in_stuff[0] as $highlight_id => $highlight_data) { + //Do a range check of the found highlight identifier and the OOP match ... + if(($highlight_data[1] <= $stuff_match_data[0][1]) && + ($highlight_data[1] + strlen($highlight_data[0]) >= $stuff_match_data[0][1] + strlen($stuff_match_data[0][0]))) + { + //We found a match that was already highlighted ... + unset($matches_in_stuff[$stuff_match_id]); + break; + } + } + } + //Rebuild the matches array to be ordered by offset ... + $symbol_offsets = array(); + foreach($matches_in_stuff as $stuff_match_data) { + $symbol_offsets[$stuff_match_data[0][1]] = $stuff_match_data[0][0]; + } + krsort($symbol_offsets); + //Perform the actual replacements ... + foreach($symbol_offsets as $symbol_offset => $symbol_match) { + $symbol_hl = ""; + $old_sym = -1; + //Split the current stuff to replace into its atomic symbols ... + preg_match_all("/$sym_search/", $symbol_match, $sym_match_syms, PREG_PATTERN_ORDER); + foreach($sym_match_syms[0] as $sym_ms) { + //Check if consequtive symbols belong to the same group to save output ... + if (isset($symbol_data[$sym_ms]) && ($symbol_data[$sym_ms] != $old_sym)) { + if(-1 != $old_sym) { + $symbol_hl .= "|>"; + } + $old_sym = $symbol_data[$sym_ms]; + if (!$this->use_classes) { + $symbol_hl .= '<| style="' . $this->language_data['STYLES']['SYMBOLS'][$old_sym] . '">'; + } + else { + $symbol_hl .= '<| class="sy' . $old_sym . '">'; + } + } + $symbol_hl .= $sym_ms; + } + //Close remaining tags and insert the replacement at the right position ... + //Take caution if symbol_hl is empty to avoid doubled closing spans. + if (-1 != $old_sym) { + $symbol_hl .= "|>"; + } + $stuff_to_parse = substr($stuff_to_parse, 0, $symbol_offset) . $symbol_hl . substr($stuff_to_parse, $symbol_offset + strlen($symbol_match)); + } + } + //FIX for symbol highlighting ... + // // Add class/style for regexps // foreach ($this->language_data['REGEXPS'] as $key => $regexp) { if ($this->lexic_permissions['REGEXPS'][$key]) { - if (!$this->use_classes) { - $attributes = ' style="' . $this->language_data['STYLES']['REGEXPS'][$key] . '"'; + if (is_callable($this->language_data['STYLES']['REGEXPS'][$key])) { + $func = $this->language_data['STYLES']['REGEXPS'][$key]; + $stuff_to_parse = preg_replace("/!REG3XP$key!(.*)\|>/eU", + "' style=\"' . call_user_func(\"$func\", '\\1') . '\"\\1|>'", $stuff_to_parse); } else { - if(is_array($this->language_data['REGEXPS'][$key]) && - array_key_exists(GESHI_CLASS, $this->language_data['REGEXPS'][$key])) { - $attributes = ' class="' - . $this->language_data['REGEXPS'][$key][GESHI_CLASS] . '"'; + if (!$this->use_classes) { + $attributes = ' style="' . $this->language_data['STYLES']['REGEXPS'][$key] . '"'; } - else { - $attributes = ' class="re' . $key . '"'; + else { + if (is_array($this->language_data['REGEXPS'][$key]) && + array_key_exists(GESHI_CLASS, $this->language_data['REGEXPS'][$key])) { + $attributes = ' class="' . + $this->language_data['REGEXPS'][$key][GESHI_CLASS] . '"'; + } + else { + $attributes = ' class="re' . $key . '"'; + } } + $stuff_to_parse = str_replace("!REG3XP$key!", "$attributes", $stuff_to_parse); } - $stuff_to_parse = str_replace("!REG3XP$key!", "$attributes", $stuff_to_parse); } } @@ -2298,6 +2433,8 @@ class GeSHi { /** * Gets language information and stores it for later use * + * @param string The filename of the language file you want to load + * @since 1.0.0 * @access private * @todo Needs to load keys for lexic permissions for keywords, regexps etc */ @@ -2371,10 +2508,12 @@ class GeSHi { // Set vars to defaults for following loop $parsed_code = ''; $i = 0; - $attrs = array(); // Foreach line... foreach ($code as $line) { + //Reset the attributes for a new line ... + $attrs = array(); + // Make lines have at least one space in them if they're empty // BenBE: Checking emptiness using trim instead of relying on blanks if ('' == trim($line)) { @@ -2421,21 +2560,24 @@ class GeSHi { if ($this->add_ids) { $attrs['id'][] = "$this->overall_id-$i"; } - if ($this->use_classes && in_array($i, $this->highlight_extra_lines)) { - $attrs['class'][] = 'ln-xtra'; - } - if (!$this->use_classes && in_array($i, $this->highlight_extra_lines)) { - $attrs['style'][] = $this->highlight_extra_lines_style; + if (in_array($i, $this->highlight_extra_lines)) { + if ($this->use_classes) { + if(array_key_exists($i, $this->highlight_extra_lines_styles)) { + $attrs['class'][] = "lx$i"; + } else { + $attrs['class'][] = "ln-xtra"; + } + } else { + array_push($attrs['style'], $this->get_line_style($i)); + } } // Add in the line surrounded by appropriate list HTML - $attr_string = ' '; + $attr_string = ''; foreach ($attrs as $key => $attr) { - $attr_string .= $key . '="' . implode(' ', $attr) . '" '; + $attr_string .= ' ' . $key . '="' . implode(' ', $attr) . '"'; } - $attr_string = substr($attr_string, 0, -1); $parsed_code .= "<li$attr_string>$start$line$end</li>$ls"; - $attrs = array(); } } else { @@ -2452,15 +2594,17 @@ class GeSHi { } if (in_array(++$i, $this->highlight_extra_lines)) { if ($this->use_classes) { - $parsed_code .= '<div class="ln-xtra">'; - } - else { - $parsed_code .= "<div style=\"{$this->highlight_extra_lines_style}\">"; + if (array_key_exists($i, $this->highlight_extra_lines_styles)) { + $parsed_code .= "<div class=\"lx$i\">"; + } else { + $parsed_code .= "<div class=\"ln-xtra\">"; + } + } else { + $parsed_code .= "<div style=\"" . $this->get_line_style($i) . "\">"; } // Remove \n because it stuffs up <pre> header $parsed_code .= $line . "</div>"; - } - else { + } else { $parsed_code .= $line . "\n"; } } @@ -2699,13 +2843,14 @@ class GeSHi { * @copyright Copyright 2007, {@link http://wikkawiki.org/CreditsPage * Wikka Development Team} * - * @access public + * @access private * @param string $string string to be converted * @param integer $quote_style * - ENT_COMPAT: escapes &, <, > and double quote (default) * - ENT_NOQUOTES: escapes only &, < and > * - ENT_QUOTES: escapes &, <, >, double and single quotes * @return string converted string + * @since 1.0.7.18 */ function hsc($string, $quote_style=ENT_COMPAT) { // init @@ -2753,9 +2898,20 @@ class GeSHi { // Header of the stylesheet if (!$economy_mode) { - $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) 2004 - 2007 Nigel McNie (http://qbnz.com/highlighter)\n */\n"; + $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) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann\n" . + " * (http://qbnz.com/highlighter/ and http://geshi.org/)\n". + " * --------------------------------------\n". + " */\n"; } else { - $stylesheet = '/* GeSHi (C) 2004 - 2007 Nigel McNie (http://qbnz.com/highlighter) */' . "\n"; + $stylesheet = "/**\n". + " * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann\n" . + " * (http://qbnz.com/highlighter/ and http://geshi.org/)\n". + " */\n"; } // Set the <ol> to have no effect at all if there are line numbers @@ -2801,29 +2957,26 @@ class GeSHi { $stylesheet .= "$selector.imp {{$this->important_styles}}\n"; } - // Styles for lines being highlighted extra - if (!$economy_mode || count($this->highlight_extra_lines)) { - $stylesheet .= "$selector.ln-xtra {{$this->highlight_extra_lines_style}}\n"; - } - // Simple line number styles if (!$economy_mode || ($this->line_numbers != GESHI_NO_LINE_NUMBERS && $this->line_style1 != '')) { - $stylesheet .= "{$selector}li {{$this->line_style1}}\n"; + $stylesheet .= "{$selector}li, {$selector}li.li1 {{$this->line_style1}}\n"; } - // If there is a style set for fancy line numbers, echo it out if (!$economy_mode || ($this->line_numbers == GESHI_FANCY_LINE_NUMBERS && $this->line_style2 != '')) { $stylesheet .= "{$selector}li.li2 {{$this->line_style2}}\n"; } foreach ($this->language_data['STYLES']['KEYWORDS'] as $group => $styles) { - if (!$economy_mode || !($economy_mode && (!$this->lexic_permissions['KEYWORDS'][$group] || $styles == ''))) { + if (!$economy_mode || ($economy_mode && $styles != '') && + (isset($this->lexic_permissions['KEYWORDS'][$group]) && + $this->lexic_permissions['KEYWORDS'][$group])) { $stylesheet .= "$selector.kw$group {{$styles}}\n"; } } foreach ($this->language_data['STYLES']['COMMENTS'] as $group => $styles) { - if (!$economy_mode || !($economy_mode && $styles == '') && - !($economy_mode && !$this->lexic_permissions['COMMENTS'][$group])) { + if (!$economy_mode || ($economy_mode && $styles != '') && + (isset($this->lexic_permissions['COMMENTS'][$group]) && + $this->lexic_permissions['COMMENTS'][$group])) { $stylesheet .= "$selector.co$group {{$styles}}\n"; } } @@ -2833,12 +2986,18 @@ class GeSHi { $stylesheet .= "$selector.es$group {{$styles}}\n"; } } - foreach ($this->language_data['STYLES']['SYMBOLS'] as $group => $styles) { + foreach ($this->language_data['STYLES']['BRACKETS'] as $group => $styles) { if (!$economy_mode || !($economy_mode && $styles == '') && !($economy_mode && !$this->lexic_permissions['BRACKETS'])) { $stylesheet .= "$selector.br$group {{$styles}}\n"; } } + foreach ($this->language_data['STYLES']['SYMBOLS'] as $group => $styles) { + if (!$economy_mode || !($economy_mode && $styles == '') && !($economy_mode && + !$this->lexic_permissions['SYMBOLS'])) { + $stylesheet .= "$selector.sy$group {{$styles}}\n"; + } + } foreach ($this->language_data['STYLES']['STRINGS'] as $group => $styles) { if (!$economy_mode || !($economy_mode && $styles == '') && !($economy_mode && !$this->lexic_permissions['STRINGS'])) { @@ -2863,8 +3022,9 @@ class GeSHi { } } foreach ($this->language_data['STYLES']['REGEXPS'] as $group => $styles) { - if (!$economy_mode || !($economy_mode && $styles == '') && !($economy_mode && - !$this->lexic_permissions['REGEXPS'][$group])) { + if (!$economy_mode || ($economy_mode && $styles != '') && + (isset($this->lexic_permissions['REGEXPS'][$group]) && + $this->lexic_permissions['REGEXPS'][$group])) { if (is_array($this->language_data['REGEXPS'][$group]) && array_key_exists(GESHI_CLASS, $this->language_data['REGEXPS'][$group])) { @@ -2877,10 +3037,35 @@ class GeSHi { } } } + // Styles for lines being highlighted extra + if (!$economy_mode || (count($this->highlight_extra_lines)!=count($this->highlight_extra_lines_styles))) { + $stylesheet .= "{$selector}.ln-xtra, {$selector}li.ln-xtra, {$selector}div.ln-xtra {{$this->highlight_extra_lines_style}}\n"; + } + foreach ($this->highlight_extra_lines_styles as $lineid => $linestyle) { + $stylesheet .= "{$selector}.lx$lineid, {$selector}li.lx$lineid, {$selector}div.lx$lineid {{$linestyle}}\n"; + } return $stylesheet; } + /** + * Get's the style that is used for the specified line + * + * @param int The line number information is requested for + * @access private + * @since 1.0.7.21 + */ + function get_line_style($line) { + //$style = null; + $style = null; + if (array_key_exists($line, $this->highlight_extra_lines_styles)) { + $style = $this->highlight_extra_lines_styles[$line]; + } else { // if no "extra" style assigned + $style = $this->highlight_extra_lines_style; + } + + return $style; + } } // End Class GeSHi |