diff options
author | Andreas Gohr <gohr@cosmocode.de> | 2010-01-11 13:19:46 +0100 |
---|---|---|
committer | Andreas Gohr <gohr@cosmocode.de> | 2010-01-11 13:19:46 +0100 |
commit | 29df5bf1c20e236ae1b30eefe7ccbedf1cde39d4 (patch) | |
tree | 6b66ecb7139e5f2898cbee7d24671ad85ba58ad8 /inc/geshi.php | |
parent | c471e6a6aee9997e62ce58c3e49dd8ecad28b92a (diff) | |
download | rpg-29df5bf1c20e236ae1b30eefe7ccbedf1cde39d4.tar.gz rpg-29df5bf1c20e236ae1b30eefe7ccbedf1cde39d4.tar.bz2 |
Upgraded GeSHi to 1.0.8.6
Diffstat (limited to 'inc/geshi.php')
-rw-r--r-- | inc/geshi.php | 87 |
1 files changed, 49 insertions, 38 deletions
diff --git a/inc/geshi.php b/inc/geshi.php index abe69a2bd..14acf15a6 100644 --- a/inc/geshi.php +++ b/inc/geshi.php @@ -41,7 +41,7 @@ // /** The version of this GeSHi file */ -define('GESHI_VERSION', '1.0.8.4'); +define('GESHI_VERSION', '1.0.8.6'); // Define the root directory for the GeSHi code tree if (!defined('GESHI_ROOT')) { @@ -207,8 +207,10 @@ define('GESHI_NUMBER_BIN_PREFIX_PERCENT', 32); //%[01]+ define('GESHI_NUMBER_BIN_PREFIX_0B', 64); //0b[01]+ /** Number format to highlight octal numbers with a leading zero */ define('GESHI_NUMBER_OCT_PREFIX', 256); //0[0-7]+ +/** Number format to highlight octal numbers with a prefix 0o (logtalk) */ +define('GESHI_NUMBER_OCT_PREFIX_0O', 512); //0[0-7]+ /** Number format to highlight octal numbers with a suffix of o */ -define('GESHI_NUMBER_OCT_SUFFIX', 512); //[0-7]+[oO] +define('GESHI_NUMBER_OCT_SUFFIX', 1024); //[0-7]+[oO] /** Number format to highlight hex numbers with a prefix 0x */ define('GESHI_NUMBER_HEX_PREFIX', 4096); //0x[0-9a-fA-F]+ /** Number format to highlight hex numbers with a suffix of h */ @@ -1084,13 +1086,14 @@ class GeSHi { * @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 + * @param int Tells the group of strings for which style should be set. * @since 1.0.0 */ - function set_strings_style($style, $preserve_defaults = false) { + function set_strings_style($style, $preserve_defaults = false, $group = 0) { if (!$preserve_defaults) { - $this->language_data['STYLES']['STRINGS'][0] = $style; + $this->language_data['STYLES']['STRINGS'][$group] = $style; } else { - $this->language_data['STYLES']['STRINGS'][0] .= $style; + $this->language_data['STYLES']['STRINGS'][$group] .= $style; } } @@ -1132,13 +1135,14 @@ class GeSHi { * @param string The style to make the numbers * @param boolean Whether to merge the new styles with the old or just * to overwrite them + * @param int Tells the group of numbers for which style should be set. * @since 1.0.0 */ - function set_numbers_style($style, $preserve_defaults = false) { + function set_numbers_style($style, $preserve_defaults = false, $group = 0) { if (!$preserve_defaults) { - $this->language_data['STYLES']['NUMBERS'][0] = $style; + $this->language_data['STYLES']['NUMBERS'][$group] = $style; } else { - $this->language_data['STYLES']['NUMBERS'][0] .= $style; + $this->language_data['STYLES']['NUMBERS'][$group] .= $style; } } @@ -1370,6 +1374,7 @@ class GeSHi { 'delphi' => array('dpk', 'dpr', 'pp', 'pas'), 'diff' => array('diff', 'patch'), 'dos' => array('bat', 'cmd'), + 'gdb' => array('kcrash', 'crash', 'bt'), 'gettext' => array('po', 'pot'), 'gml' => array('gml'), 'gnuplot' => array('plt'), @@ -1966,31 +1971,33 @@ class GeSHi { //All this formats are matched case-insensitively! static $numbers_format = array( GESHI_NUMBER_INT_BASIC => - '(?<![0-9a-z_\.%])(?<![\d\.]e[+\-])([1-9]\d*?|0)(?![0-9a-z]|\.(?!(?m:$)))', + '(?<![0-9a-z_\.%])(?<![\d\.]e[+\-])([1-9]\d*?|0)(?![0-9a-z]|\.(?:[eE][+\-]?)?\d)', GESHI_NUMBER_INT_CSTYLE => - '(?<![0-9a-z_\.%])(?<![\d\.]e[+\-])([1-9]\d*?|0)l(?![0-9a-z\.])', + '(?<![0-9a-z_\.%])(?<![\d\.]e[+\-])([1-9]\d*?|0)l(?![0-9a-z]|\.(?:[eE][+\-]?)?\d)', GESHI_NUMBER_BIN_SUFFIX => - '(?<![0-9a-z_\.])(?<![\d\.]e[+\-])[01]+?b(?![0-9a-z\.])', + '(?<![0-9a-z_\.])(?<![\d\.]e[+\-])[01]+?[bB](?![0-9a-z]|\.(?:[eE][+\-]?)?\d)', GESHI_NUMBER_BIN_PREFIX_PERCENT => - '(?<![0-9a-z_\.%])(?<![\d\.]e[+\-])%[01]+?(?![0-9a-z\.])', + '(?<![0-9a-z_\.%])(?<![\d\.]e[+\-])%[01]+?(?![0-9a-z]|\.(?:[eE][+\-]?)?\d)', GESHI_NUMBER_BIN_PREFIX_0B => - '(?<![0-9a-z_\.%])(?<![\d\.]e[+\-])0b[01]+?(?![0-9a-z\.])', + '(?<![0-9a-z_\.%])(?<![\d\.]e[+\-])0b[01]+?(?![0-9a-z]|\.(?:[eE][+\-]?)?\d)', GESHI_NUMBER_OCT_PREFIX => - '(?<![0-9a-z_\.])(?<![\d\.]e[+\-])0[0-7]+?(?![0-9a-z\.])', + '(?<![0-9a-z_\.])(?<![\d\.]e[+\-])0[0-7]+?(?![0-9a-z]|\.(?:[eE][+\-]?)?\d)', + GESHI_NUMBER_OCT_PREFIX_0O => + '(?<![0-9a-z_\.%])(?<![\d\.]e[+\-])0o[0-7]+?(?![0-9a-z]|\.(?:[eE][+\-]?)?\d)', GESHI_NUMBER_OCT_SUFFIX => - '(?<![0-9a-z_\.])(?<![\d\.]e[+\-])[0-7]+?o(?![0-9a-z\.])', + '(?<![0-9a-z_\.])(?<![\d\.]e[+\-])[0-7]+?o(?![0-9a-z]|\.(?:[eE][+\-]?)?\d)', GESHI_NUMBER_HEX_PREFIX => - '(?<![0-9a-z_\.])(?<![\d\.]e[+\-])0x[0-9a-f]+?(?![0-9a-z\.])', + '(?<![0-9a-z_\.])(?<![\d\.]e[+\-])0x[0-9a-fA-F]+?(?![0-9a-z]|\.(?:[eE][+\-]?)?\d)', GESHI_NUMBER_HEX_SUFFIX => - '(?<![0-9a-z_\.])(?<![\d\.]e[+\-])\d[0-9a-f]*?h(?![0-9a-z\.])', + '(?<![0-9a-z_\.])(?<![\d\.]e[+\-])\d[0-9a-fA-F]*?[hH](?![0-9a-z]|\.(?:[eE][+\-]?)?\d)', GESHI_NUMBER_FLT_NONSCI => - '(?<![0-9a-z_\.])(?<![\d\.]e[+\-])\d+?\.\d+?(?![0-9a-z\.])', + '(?<![0-9a-z_\.])(?<![\d\.]e[+\-])\d+?\.\d+?(?![0-9a-z]|\.(?:[eE][+\-]?)?\d)', GESHI_NUMBER_FLT_NONSCI_F => - '(?<![0-9a-z_\.])(?<![\d\.]e[+\-])(?:\d+?(?:\.\d*?)?|\.\d+?)f(?![0-9a-z\.])', + '(?<![0-9a-z_\.])(?<![\d\.]e[+\-])(?:\d+?(?:\.\d*?)?|\.\d+?)f(?![0-9a-z]|\.(?:[eE][+\-]?)?\d)', GESHI_NUMBER_FLT_SCI_SHORT => - '(?<![0-9a-z_\.])(?<![\d\.]e[+\-])\.\d+?(?:e[+\-]?\d+?)?(?![0-9a-z\.])', + '(?<![0-9a-z_\.])(?<![\d\.]e[+\-])\.\d+?(?:e[+\-]?\d+?)?(?![0-9a-z]|\.(?:[eE][+\-]?)?\d)', GESHI_NUMBER_FLT_SCI_ZERO => - '(?<![0-9a-z_\.])(?<![\d\.]e[+\-])(?:\d+?(?:\.\d*?)?|\.\d+?)(?:e[+\-]?\d+?)?(?![0-9a-z\.])' + '(?<![0-9a-z_\.])(?<![\d\.]e[+\-])(?:\d+?(?:\.\d*?)?|\.\d+?)(?:e[+\-]?\d+?)?(?![0-9a-z]|\.(?:[eE][+\-]?)?\d)' ); //At this step we have an associative array with flag groups for a @@ -2012,7 +2019,7 @@ class GeSHi { } $this->language_data['NUMBERS_RXCACHE'][$key] = - "/(?<!<\|\/)(?<!<\|!REG3XP)(?<!<\|\/NUM!)(?<!\d\/>)($regexp)(?!\|>)(?![^\"\|\>\<]+<)/i"; + "/(?<!<\|\/)(?<!<\|!REG3XP)(?<!<\|\/NUM!)(?<!\d\/>)($regexp)(?!(?:<DOT>|[^\<])+>)(?![^<]*>)(?!\|>)(?!\/>)/i"; // } } @@ -2033,6 +2040,10 @@ class GeSHi { // Start the timer $start_time = microtime(); + // Replace all newlines to a common form. + $code = str_replace("\r\n", "\n", $this->source); + $code = str_replace("\r", "\n", $code); + // Firstly, if there is an error, we won't highlight if ($this->error) { //Escape the source for output @@ -2053,13 +2064,6 @@ class GeSHi { $this->build_parse_cache(); } - // Replace all newlines to a common form. - $code = str_replace("\r\n", "\n", $this->source); - $code = str_replace("\r", "\n", $code); - - // Add spaces for regular expression matching and line numbers -// $code = "\n" . $code . "\n"; - // Initialise various stuff $length = strlen($code); $COMMENT_MATCHED = false; @@ -3087,7 +3091,7 @@ class GeSHi { $result = preg_replace('/^ /m', ' ', $result); $result = str_replace(' ', ' ', $result); - if ($this->line_numbers == GESHI_NO_LINE_NUMBERS) { + if ($this->line_numbers == GESHI_NO_LINE_NUMBERS && $this->header_type != GESHI_HEADER_PRE_TABLE) { if ($this->line_ending === null) { $result = nl2br($result); } else { @@ -3430,7 +3434,7 @@ class GeSHi { //FIX for symbol highlighting ... if ($this->lexic_permissions['SYMBOLS'] && !empty($this->language_data['SYMBOLS'])) { //Get all matches and throw away those witin a block that is already highlighted... (i.e. matched by a regexp) - $n_symbols = preg_match_all("/<\|(?:<DOT>|[^>])+>(?:(?!\|>).*?)\|>|<\/a>|(?:" . $this->language_data['SYMBOL_SEARCH'] . ")+/", $stuff_to_parse, $pot_symbols, PREG_OFFSET_CAPTURE | PREG_SET_ORDER); + $n_symbols = preg_match_all("/<\|(?:<DOT>|[^>])+>(?:(?!\|>).*?)\|>|<\/a>|(?:" . $this->language_data['SYMBOL_SEARCH'] . ")+(?![^<]+?>)/", $stuff_to_parse, $pot_symbols, PREG_OFFSET_CAPTURE | PREG_SET_ORDER); $global_offset = 0; for ($s_id = 0; $s_id < $n_symbols; ++$s_id) { $symbol_match = $pot_symbols[$s_id][0][0]; @@ -3969,16 +3973,16 @@ class GeSHi { * @todo Document behaviour change - class is outputted regardless of whether * we're using classes or not. Same with style */ - $attributes = ' class="' . $this->language; + $attributes = ' class="' . $this->_genCSSName($this->language); if ($this->overall_class != '') { - $attributes .= " ".$this->overall_class; + $attributes .= " ".$this->_genCSSName($this->overall_class); } $attributes .= '"'; if ($this->overall_id != '') { $attributes .= " id=\"{$this->overall_id}\""; } - if ($this->overall_style != '') { + if ($this->overall_style != '' && !$this->use_classes) { $attributes .= ' style="' . $this->overall_style . '"'; } @@ -4215,6 +4219,10 @@ class GeSHi { return strtr($string, $aTransSpecchar); } + function _genCSSName($name){ + return (is_numeric($name[0]) ? '_' : '') . $name; + } + /** * Returns a stylesheet for the highlighted code. If $economy mode * is true, we only return the stylesheet declarations that matter for @@ -4242,11 +4250,11 @@ class GeSHi { // that should be used, the same for a class. Otherwise, a selector // of '' means that these styles will be applied anywhere if ($this->overall_id) { - $selector = '#' . $this->overall_id; + $selector = '#' . $this->_genCSSName($this->overall_id); } else { - $selector = '.' . $this->language; + $selector = '.' . $this->_genCSSName($this->language); if ($this->overall_class) { - $selector .= '.' . $this->overall_class; + $selector .= '.' . $this->_genCSSName($this->overall_class); } } $selector .= ' '; @@ -4555,7 +4563,10 @@ class GeSHi { // make sure the last tokens get converted as well $new_entry = $this->_optimize_regexp_list_tokens_to_string($tokens); if (GESHI_MAX_PCRE_SUBPATTERNS && $num_subpatterns + substr_count($new_entry, '(?:') > GESHI_MAX_PCRE_SUBPATTERNS) { - $regexp_list[++$list_key] = $new_entry; + if ( !empty($regexp_list[$list_key]) ) { + ++$list_key; + } + $regexp_list[$list_key] = $new_entry; } else { if (!empty($regexp_list[$list_key])) { $new_entry = '|' . $new_entry; |