Lines Matching +full:insert +full:- +full:user -(+path:inc +path:lang) -(+path:lib +path:plugins +path:lang) -(+path:lib +path:tpl +path:dokuwiki +path:lang)

3  * GeSHi - Generic Syntax Highlighter
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 * @copyright (C) 2004 - 2007 Nigel McNie, (C) 2007 - 2014 Benny Baumann
38 // their values - you never know when a value may change in a future
60 // Line numbers - use with enable_line_numbers()
111 // Note that if you change these, they should be as-is: i.e., don't
125 disabled by {@link GeSHi->enable_strict_mode()} */
153 @see GeSHi->optimize_regexp_list()
159 @see GeSHi->optimize_regexp_list()
167 define('GESHI_NUMBER_INT_CSTYLE', 2); //Default C-Style \d+[lL]?
175 define('GESHI_NUMBER_OCT_PREFIX', 256); //0[0-7]+
177 define('GESHI_NUMBER_OCT_PREFIX_0O', 512); //0[0-7]+
179 define('GESHI_NUMBER_OCT_PREFIX_AT', 1024); //@[0-7]+
181 define('GESHI_NUMBER_OCT_SUFFIX', 2048); //[0-7]+[oO]
183 define('GESHI_NUMBER_HEX_PREFIX', 4096); //0x[0-9a-fA-F]+
185 define('GESHI_NUMBER_HEX_PREFIX_DOLLAR', 8192); //$[0-9a-fA-F]+
187 define('GESHI_NUMBER_HEX_SUFFIX', 16384); //[0-9][0-9a-fA-F]*h
188 /** Number format to highlight floating-point numbers without support for scientific notation */
190 /** Number format to highlight floating-point numbers without support for scientific notation */
192 /** Number format to highlight floating-point numbers with support for scientific notation (E) and optional leading zero */
194 /** Number format to highlight floating-point numbers with support for scientific notation (E) and required leading digit */
198 // Error detection - use these to analyse faults
207 /** The header type passed to {@link GeSHi->set_header_type()} was invalid */
209 /** The line number type passed to {@link GeSHi->enable_line_numbers()} was invalid */
211 /**#@-*/
224 * @copyright (C) 2004 - 2007 Nigel McNie, (C) 2007 - 2014 Benny Baumann
286 * - GESHI_HEADER_PRE: Source is outputted in a "pre" HTML element.
287 * - GESHI_HEADER_DIV: Source is outputted in a "div" HTML element.
288 * - GESHI_HEADER_NONE: No header is outputted.
366 * @todo As above - rethink the whole idea of important blocks as it is buggy and
369 protected $important_styles = 'font-weight: bold; color: red;'; // Styles for important parts of the code
390 * Styles of extra-highlighted lines
393 protected $highlight_extra_lines_style = 'background-color: #ffc;';
413 protected $overall_style = 'font-family:monospace;';
419 protected $code_style = 'font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;';
437 protected $line_style1 = 'font-weight: normal; vertical-align:top;';
443 protected $line_style2 = 'font-weight: bold; vertical-align:top;';
449 protected $table_linenumber_style = 'width:1px;text-align:right;margin:0;padding:0 2px;vertical-align:top;';
477 * Should we use language-defined tab stop widths?
490 * NOTE: Used with Escape Char Sequences to fix UTF-8 handling (cf. SF#2037598)
493 protected $encoding = 'utf-8';
557 * {@link GeSHi->set_language_path()}
562 $this->set_source($source);
565 $this->set_language($language);
567 $this->set_language_path($path);
589 if ($this->error) {
592 '{LANGUAGE}' => $this->language,
593 '{PATH}' => $this->language_path
598 $this->error_messages[$this->error]);
600 return "<br /><strong>GeSHi Error:</strong> $msg (code {$this->error})<br />";
606 * Gets a human-readable language name (thanks to Simon Patterson
613 if (GESHI_ERROR_NO_SUCH_LANG == $this->error) {
614 return $this->language_data['LANG_NAME'] . ' (Unknown Language)';
616 return $this->language_data['LANG_NAME'];
626 $this->source = $source;
627 $this->highlight_extra_lines = array();
637 $language = preg_replace('#[^a-zA-Z0-9\-_]#', '', $language);
646 * @note since 1.0.8 this function won't reset language-settings by default anymore!
654 $this->error = false;
655 $this->strict_mode = GESHI_NEVER;
658 $this->loaded_language = false;
662 $language = $this->strip_language_name($language);
665 $file_name = $this->language_path . $language . '.php';
666 if ($file_name == $this->loaded_language) {
671 $this->language = $language;
675 $this->error = GESHI_ERROR_NO_SUCH_LANG;
680 $this->load_language($file_name);
699 if(!preg_match('#^[a-zA-Z]:#', $path) || false !== strpos($path, ':', 2)) {
706 if(preg_match('#[^/a-zA-Z0-9_\.\-\\\s:]#', $path)) {
719 $this->language_path = ('/' == $path[strlen($path) - 1]) ? $path : $path . '/';
720 $this->set_language($this->language); // otherwise set_language_path has no effect
735 $dir = dir($this->language_path);
738 while (false !== ($entry = $dir->read()))
740 $full_path = $this->language_path.$entry;
758 if (false !== ($fullname = $this->get_language_fullname($langname)))
770 $dir->close();
783 $language = preg_replace('#[^a-zA-Z0-9\-_]#', '', $language);
787 // get fullpath-filename for a langname
788 $fullpath = $this->language_path.$language.'.php';
792 $this->error = sprintf('Geshi::get_lang_fullname() Unknown Language: %s', $language);
798 $this->error = sprintf('Geshi::get_lang_fullname(%s): Regex can not detect language', $language);
810 * means more source code but more control over tab width and line-wrapping.
811 * GESHI_HEADER_PRE means that a "pre" is used - less source, but less
824 $this->error = GESHI_ERROR_INVALID_HEADER_TYPE;
829 $this->header_type = $type;
843 $this->overall_style = $style;
845 $this->overall_style .= $style;
858 $this->overall_class = $class;
869 $this->overall_id = $id;
880 $this->use_classes = ($flag) ? true : false;
887 * user defined styles having priority
900 $this->code_style = $style;
902 $this->code_style .= $style;
927 $this->line_style1 = $style1;
928 $this->line_style2 = $style2;
930 $this->line_style1 .= $style1;
931 $this->line_style2 .= $style2;
940 * - GESHI_NO_LINE_NUMBERS: Line numbers will not be displayed
941 * - GESHI_NORMAL_LINE_NUMBERS: Line numbers will be displayed
942 * - GESHI_FANCY_LINE_NUMBERS: Fancy line numbers will be displayed
955 $this->error = GESHI_ERROR_INVALID_LINE_NUMBER_TYPE;
957 $this->line_numbers = $flag;
958 $this->line_nth_row = $nth_row;
971 $this->allow_multiline_span = (bool) $flag;
975 * Get current setting for multiline spans, see GeSHi->enable_multiline_span().
981 return $this->allow_multiline_span;
987 * user defined styles having priority
998 foreach($this->language_data['STYLES']['KEYWORDS'] as $_key => $_value) {
1000 $this->language_data['STYLES']['KEYWORDS'][$_key] = $style;
1002 $this->language_data['STYLES']['KEYWORDS'][$_key] .= $style;
1007 $this->language_data['STYLES']['KEYWORDS'][$key] = $style;
1009 $this->language_data['STYLES']['KEYWORDS'][$key] .= $style;
1014 if (!isset($this->lexic_permissions['KEYWORDS'][$key])) {
1015 $this->lexic_permissions['KEYWORDS'][$key] = true;
1027 $this->lexic_permissions['KEYWORDS'][$key] = ($flag) ? true : false;
1033 * user defined styles having priority
1043 foreach($this->language_data['STYLES']['COMMENTS'] as $_key => $_value) {
1045 $this->language_data['STYLES']['COMMENTS'][$_key] = $style;
1047 $this->language_data['STYLES']['COMMENTS'][$_key] .= $style;
1052 $this->language_data['STYLES']['COMMENTS'][$key] = $style;
1054 $this->language_data['STYLES']['COMMENTS'][$key] .= $style;
1067 $this->lexic_permissions['COMMENTS'][$key] = ($flag) ? true : false;
1073 * user defined styles having priority
1083 $this->language_data['STYLES']['ESCAPE_CHAR'][$group] = $style;
1085 $this->language_data['STYLES']['ESCAPE_CHAR'][$group] .= $style;
1096 $this->lexic_permissions['ESCAPE_CHAR'] = ($flag) ? true : false;
1102 * user defined styles having priority
1115 $this->language_data['STYLES']['BRACKETS'][0] = $style;
1117 $this->language_data['STYLES']['BRACKETS'][0] .= $style;
1132 $this->lexic_permissions['BRACKETS'] = ($flag) ? true : false;
1138 * user defined styles having priority
1149 $this->language_data['STYLES']['SYMBOLS'][$group] = $style;
1151 $this->language_data['STYLES']['SYMBOLS'][$group] .= $style;
1156 $this->set_brackets_style ($style, $preserve_defaults);
1168 $this->lexic_permissions['SYMBOLS'] = ($flag) ? true : false;
1171 $this->set_brackets_highlighting ($flag);
1177 * user defined styles having priority
1187 $this->language_data['STYLES']['STRINGS'][$group] = $style;
1189 $this->language_data['STYLES']['STRINGS'][$group] .= $style;
1200 $this->lexic_permissions['STRINGS'] = ($flag) ? true : false;
1206 * user defined styles having priority
1217 $this->language_data['STYLES']['SCRIPT'][$group] = $style;
1219 $this->language_data['STYLES']['SCRIPT'][$group] .= $style;
1226 * user defined styles having priority
1236 $this->language_data['STYLES']['NUMBERS'][$group] = $style;
1238 $this->language_data['STYLES']['NUMBERS'][$group] .= $style;
1249 $this->lexic_permissions['NUMBERS'] = ($flag) ? true : false;
1254 * appropriate "object splitter" - see the language file for the language
1257 * user defined styles having priority
1267 $this->language_data['STYLES']['METHODS'][$key] = $style;
1269 $this->language_data['STYLES']['METHODS'][$key] .= $style;
1280 $this->lexic_permissions['METHODS'] = ($flag) ? true : false;
1286 * user defined styles having priority
1297 $this->language_data['STYLES']['REGEXPS'][$key] = $style;
1299 $this->language_data['STYLES']['REGEXPS'][$key] .= $style;
1311 $this->lexic_permissions['REGEXPS'][$key] = ($flag) ? true : false;
1322 $this->language_data['CASE_SENSITIVE'][$key] = ($case) ? true : false;
1328 * - GESHI_CAPS_NO_CHANGE: leave keywords as-is
1329 * - GESHI_CAPS_UPPER: convert all keywords to uppercase where found
1330 * - GESHI_CAPS_LOWER: convert all keywords to lowercase where found
1338 $this->language_data['CASE_KEYWORDS'] = $case;
1351 $this->tab_width = intval($width);
1354 if ($this->tab_width < 1) {
1356 $this->tab_width = 8;
1361 * Sets whether or not to use tab-stop width specifed by language
1363 * @param boolean $use Whether to use language-specific tab-stop widths
1367 $this->use_language_tab_width = (bool) $use;
1371 * Returns the tab width to use, based on the current language and user
1378 if (!$this->use_language_tab_width ||
1379 !isset($this->language_data['TAB_WIDTH'])) {
1380 return $this->tab_width;
1382 return $this->language_data['TAB_WIDTH'];
1395 if (GESHI_MAYBE == $this->language_data['STRICT_MODE_APPLIES']) {
1396 $this->strict_mode = ($mode) ? GESHI_ALWAYS : GESHI_NEVER;
1408 $this->enable_highlighting(false);
1423 foreach ($this->lexic_permissions as $key => $value) {
1426 $this->lexic_permissions[$key][$k] = $flag;
1429 $this->lexic_permissions[$key] = $flag;
1434 $this->enable_important_blocks = $flag;
1444 * @todo Re-think about how this method works (maybe make it private and/or make it
1445 * a extension->lang lookup?)
1557 $this->set_source(file_get_contents($file_name));
1558 $this->set_language(self::get_language_name_from_extension(substr(strrchr($file_name, '.'), 1), $lookup));
1560 $this->error = GESHI_ERROR_FILE_NOT_READABLE;
1572 if (!is_array($this->language_data['KEYWORDS'][$key])) {
1573 $this->language_data['KEYWORDS'][$key] = array();
1575 if (!in_array($word, $this->language_data['KEYWORDS'][$key])) {
1576 $this->language_data['KEYWORDS'][$key][] = $word;
1579 if ($this->parse_cache_built) {
1580 $subkey = count($this->language_data['CACHED_KEYWORD_LISTS'][$key]) - 1;
1581 $this->language_data['CACHED_KEYWORD_LISTS'][$key][$subkey] .= '|' . preg_quote($word, '/');
1592 * Note: if you set this to false and @see GeSHi->parse_code() was already called once,
1593 * for the current language, you have to manually call @see GeSHi->optimize_keyword_group()
1600 $key_to_remove = array_search($word, $this->language_data['KEYWORDS'][$key]);
1602 unset($this->language_data['KEYWORDS'][$key][$key_to_remove]);
1605 if ($recompile && $this->parse_cache_built) {
1606 $this->optimize_keyword_group($key);
1629 $this->language_data['KEYWORDS'][$key] = $words;
1630 $this->lexic_permissions['KEYWORDS'][$key] = true;
1631 $this->language_data['CASE_SENSITIVE'][$key] = $case_sensitive;
1632 $this->language_data['STYLES']['KEYWORDS'][$key] = $styles;
1635 if ($this->parse_cache_built) {
1636 $this->optimize_keyword_group($key);
1649 unset($this->language_data['KEYWORDS'][$key]);
1650 unset($this->lexic_permissions['KEYWORDS'][$key]);
1651 unset($this->language_data['CASE_SENSITIVE'][$key]);
1652 unset($this->language_data['STYLES']['KEYWORDS'][$key]);
1655 unset($this->language_data['CACHED_KEYWORD_LISTS'][$key]);
1665 $this->language_data['CACHED_KEYWORD_LISTS'][$key] =
1666 $this->optimize_regexp_list($this->language_data['KEYWORDS'][$key]);
1668 if(isset($this->language_data['PARSER_CONTROL'])) {
1669 if(isset($this->language_data['PARSER_CONTROL']['KEYWORDS'])) {
1670 if(isset($this->language_data['PARSER_CONTROL']['KEYWORDS']['SPACE_AS_WHITESPACE'])) {
1671 $space_as_whitespace = $this->language_data['PARSER_CONTROL']['KEYWORDS']['SPACE_AS_WHITESPACE'];
1673 if(isset($this->language_data['PARSER_CONTROL']['KEYWORDS'][$key]['SPACE_AS_WHITESPACE'])) {
1674 if(isset($this->language_data['PARSER_CONTROL']['KEYWORDS'][$key]['SPACE_AS_WHITESPACE'])) {
1675 $space_as_whitespace = $this->language_data['PARSER_CONTROL']['KEYWORDS'][$key]['SPACE_AS_WHITESPACE'];
1681 foreach($this->language_data['CACHED_KEYWORD_LISTS'][$key] as $rxk => $rxv) {
1682 $this->language_data['CACHED_KEYWORD_LISTS'][$key][$rxk] =
1695 $this->header_content = $content;
1705 $this->footer_content = $content;
1715 $this->header_content_style = $style;
1725 $this->footer_content_style = $style;
1736 $this->force_code_block = (bool)$flag;
1749 $this->language_data['URLS'][$group] = $url;
1756 * set for - e.g. :hover or :visited
1761 $this->link_styles[$type] = $styles;
1772 $this->link_target = '';
1774 $this->link_target = ' target="' . $target . '"';
1785 $this->important_styles = $styles;
1789 * Sets whether context-important blocks are highlighted
1797 $this->enable_important_blocks = ( $flag ) ? true : false;
1807 $this->add_ids = ($flag) ? true : false;
1828 $this->highlight_lines_extra($line, $style);
1833 $this->highlight_extra_lines[$lines] = $lines;
1837 unset($this->highlight_extra_lines_styles[$lines]);
1839 unset($this->highlight_extra_lines[$lines]);
1840 unset($this->highlight_extra_lines_styles[$lines]);
1842 $this->highlight_extra_lines_styles[$lines] = $style;
1848 * Sets the style for extra-highlighted lines
1850 * @param string $styles The style for extra-highlighted lines
1854 $this->highlight_extra_lines_style = $styles;
1858 * Sets the line-ending
1860 * @param string $line_ending The new line-ending
1864 $this->line_ending = (string)$line_ending;
1883 $this->line_numbers_start = abs(intval($number));
1900 $this->encoding = strtolower($encoding);
1911 $this->keyword_links = (bool) $enable;
1924 if($this->lexic_permissions['NUMBERS']) {
1926 if(!isset($this->language_data['NUMBERS'])) {
1927 $this->language_data['NUMBERS'] = 0;
1930 if(is_array($this->language_data['NUMBERS'])) {
1931 $this->language_data['NUMBERS_CACHE'] = $this->language_data['NUMBERS'];
1933 $this->language_data['NUMBERS_CACHE'] = array();
1934 if(!$this->language_data['NUMBERS']) {
1935 $this->language_data['NUMBERS'] =
1940 for($i = 0, $j = $this->language_data['NUMBERS']; $j > 0; ++$i, $j>>=1) {
1942 if(isset($this->language_data['STYLES']['NUMBERS'][1<<$i])) {
1943 $this->language_data['STYLES']['NUMBERS'][$i] =
1944 $this->language_data['STYLES']['NUMBERS'][1<<$i];
1945 unset($this->language_data['STYLES']['NUMBERS'][1<<$i]);
1952 if(isset($this->language_data['STYLES']['NUMBERS'][$i])) {
1953 $this->language_data['NUMBERS_CACHE'][$i] = 1 << $i;
1955 if(!isset($this->language_data['NUMBERS_CACHE'][0])) {
1956 $this->language_data['NUMBERS_CACHE'][0] = 0;
1958 $this->language_data['NUMBERS_CACHE'][0] |= 1 << $i;
1974 if (empty($this->language_data)) {
1983 if ($this->lexic_permissions['SYMBOLS'] && !empty($this->language_data['SYMBOLS'])) {
1984 $this->language_data['MULTIPLE_SYMBOL_GROUPS'] = count($this->language_data['STYLES']['SYMBOLS']) > 1;
1986 $this->language_data['SYMBOL_DATA'] = array();
1989 foreach ($this->language_data['SYMBOLS'] as $key => $symbols) {
1992 $sym = $this->hsc($sym);
1993 if (!isset($this->language_data['SYMBOL_DATA'][$sym])) {
1994 $this->language_data['SYMBOL_DATA'][$sym] = $key;
1998 if ($sym == '-') {
2000 $symbol_preg_single[] = '\-';
2008 $symbols = $this->hsc($symbols);
2009 if (!isset($this->language_data['SYMBOL_DATA'][$symbols])) {
2010 $this->language_data['SYMBOL_DATA'][$symbols] = 0;
2013 } elseif ($symbols == '-') {
2015 $symbol_preg_single[] = '\-';
2036 $this->language_data['SYMBOL_SEARCH'] = implode("|", $symbol_preg);
2041 $this->language_data['CACHED_KEYWORD_LISTS'] = array();
2042 foreach (array_keys($this->language_data['KEYWORDS']) as $key) {
2043 if (!isset($this->lexic_permissions['KEYWORDS'][$key]) ||
2044 $this->lexic_permissions['KEYWORDS'][$key]) {
2045 $this->optimize_keyword_group($key);
2050 if ($this->lexic_permissions['BRACKETS']) {
2051 $this->language_data['CACHE_BRACKET_MATCH'] = array('[', ']', '(', ')', '{', '}');
2052 if (!$this->use_classes && isset($this->language_data['STYLES']['BRACKETS'][0])) {
2053 $this->language_data['CACHE_BRACKET_REPLACE'] = array(
2054 '<| style="' . $this->language_data['STYLES']['BRACKETS'][0] . '">&#91;|>',
2055 '<| style="' . $this->language_data['STYLES']['BRACKETS'][0] . '">&#93;|>',
2056 '<| style="' . $this->language_data['STYLES']['BRACKETS'][0] . '">&#40;|>',
2057 '<| style="' . $this->language_data['STYLES']['BRACKETS'][0] . '">&#41;|>',
2058 '<| style="' . $this->language_data['STYLES']['BRACKETS'][0] . '">&#123;|>',
2059 '<| style="' . $this->language_data['STYLES']['BRACKETS'][0] . '">&#125;|>',
2063 $this->language_data['CACHE_BRACKET_REPLACE'] = array(
2075 if($this->lexic_permissions['NUMBERS']) {
2078 if(!isset($this->language_data['NUMBERS_CACHE'])) {
2079 $this->build_style_cache();
2083 //All this formats are matched case-insensitively!
2086 '(?:(?<![0-9a-z_\.%$@])|(?<=\.\.))(?<![\d\.]e[+\-])([1-9]\d*?|0)(?![0-9a-z]|\.(?:[eE][+\-]?)?\d)',
2088 '(?<![0-9a-z_\.%])(?<![\d\.]e[+\-])([1-9]\d*?|0)l(?![0-9a-z]|\.(?:[eE][+\-]?)?\d)',
2090 '(?<![0-9a-z_\.])(?<![\d\.]e[+\-])[01]+?[bB](?![0-9a-z]|\.(?:[eE][+\-]?)?\d)',
2092 '(?<![0-9a-z_\.%])(?<![\d\.]e[+\-])%[01]+?(?![0-9a-z]|\.(?:[eE][+\-]?)?\d)',
2094 '(?<![0-9a-z_\.%])(?<![\d\.]e[+\-])0b[01]+?(?![0-9a-z]|\.(?:[eE][+\-]?)?\d)',
2096 '(?<![0-9a-z_\.])(?<![\d\.]e[+\-])0[0-7]+?(?![0-9a-z]|\.(?:[eE][+\-]?)?\d)',
2098 '(?<![0-9a-z_\.%])(?<![\d\.]e[+\-])0o[0-7]+?(?![0-9a-z]|\.(?:[eE][+\-]?)?\d)',
2100 '(?<![0-9a-z_\.%])(?<![\d\.]e[+\-])\@[0-7]+?(?![0-9a-z]|\.(?:[eE][+\-]?)?\d)',
2102 '(?<![0-9a-z_\.])(?<![\d\.]e[+\-])[0-7]+?o(?![0-9a-z]|\.(?:[eE][+\-]?)?\d)',
2104 '(?<![0-9a-z_\.])(?<![\d\.]e[+\-])0x[0-9a-fA-F]+?(?![0-9a-z]|\.(?:[eE][+\-]?)?\d)',
2106 '(?<![0-9a-z_\.])(?<![\d\.]e[+\-])\$[0-9a-fA-F]+?(?![0-9a-z]|\.(?:[eE][+\-]?)?\d)',
2108 '(?<![0-9a-z_\.])(?<![\d\.]e[+\-])\d[0-9a-fA-F]*?[hH](?![0-9a-z]|\.(?:[eE][+\-]?)?\d)',
2110 '(?<![0-9a-z_\.])(?<![\d\.]e[+\-])\d+?\.\d+?(?![0-9a-z]|\.(?:[eE][+\-]?)?\d)',
2112 '(?<![0-9a-z_\.])(?<![\d\.]e[+\-])(?:\d+?(?:\.\d*?)?|\.\d+?)f(?![0-9a-z]|\.(?:[eE][+\-]?)?\d)',
2114 '(?<![0-9a-z_\.])(?<![\d\.]e[+\-])\.\d+?(?:e[+\-]?\d+?)?(?![0-9a-z]|\.(?:[eE][+\-]?)?\d)',
2116 '(?<![0-9a-z_\.])(?<![\d\.]e[+\-])(?:\d+?(?:\.\d*?)?|\.\d+?)(?:e[+\-]?\d+?)?(?![0-9a-z]|\.(?:[eE][+\-]?)?\d)'
2121 $this->language_data['NUMBERS_RXCACHE'] = array();
2122 foreach($this->language_data['NUMBERS_CACHE'] as $key => $rxdata) {
2137 $this->language_data['NUMBERS_RXCACHE'][$key] =
2141 if(!isset($this->language_data['PARSER_CONTROL']['NUMBERS']['PRECHECK_RX'])) {
2142 $this->language_data['PARSER_CONTROL']['NUMBERS']['PRECHECK_RX'] = '#\d#';
2146 $this->parse_cache_built = true;
2150 * Returns the code in $this->source, highlighted and surrounded by the
2164 $code = str_replace("\r\n", "\n", $this->source);
2168 if (empty($this->language_data)) {
2169 $this->error = GESHI_ERROR_NO_SUCH_LANG;
2173 if ($this->error) {
2175 $result = $this->hsc($this->source);
2182 $this->set_time($start_time, $start_time);
2183 $this->finalise($result);
2188 if (!$this->parse_cache_built) {
2189 $this->build_parse_cache();
2200 if ($this->enable_important_blocks) {
2201 $this->language_data['COMMENT_MULTI'][GESHI_START_IMPORTANT] = GESHI_END_IMPORTANT;
2204 if ($this->strict_mode) {
2206 // within script delimiters - for example, HTML between < and >
2212 $delim_copy = $this->language_data['SCRIPT_DELIMITERS'];
2222 'next_match' => -1,
2257 * - Group 1 is the opener
2258 * - Group 2 is the closer
2293 // non-highlightable text
2295 1 => substr($code, $i, $next_match_pos - $i)
2307 //Only combine for non-rx script blocks
2322 // merge adjacent but make sure we don't merge things like <tag><!-- comment -->
2346 $parts[$k][1] = substr($code, $next_match_pos, $i - $next_match_pos);
2353 if ($num_parts == 1 && $this->strict_mode == GESHI_MAYBE) {
2370 // Not strict mode - simply dump the source into
2389 $hq = isset($this->language_data['HARDQUOTE']) ? $this->language_data['HARDQUOTE'][0] : false;
2394 $check_linenumbers = $this->line_numbers != GESHI_NO_LINE_NUMBERS ||
2395 !empty($this->highlight_extra_lines) || !$this->allow_multiline_span;
2398 $escaped_escape_char = $this->hsc($this->language_data['ESCAPE_CHAR']);
2400 // this is used for single-line comments
2404 if (isset($this->language_data['PARSER_CONTROL'])) {
2405 if (isset($this->language_data['PARSER_CONTROL']['COMMENTS'])) {
2406 if (isset($this->language_data['PARSER_CONTROL']['COMMENTS']['DISALLOWED_BEFORE'])) {
2407 $sc_disallowed_before = $this->language_data['PARSER_CONTROL']['COMMENTS']['DISALLOWED_BEFORE'];
2409 if (isset($this->language_data['PARSER_CONTROL']['COMMENTS']['DISALLOWED_AFTER'])) {
2410 $sc_disallowed_after = $this->language_data['PARSER_CONTROL']['COMMENTS']['DISALLOWED_AFTER'];
2417 if ($this->lexic_permissions['STRINGS']) {
2418 foreach ($this->language_data['QUOTEMARKS'] as $quotemark) {
2431 // Now we go through each part. We know that even-indexed parts are
2432 // code that shouldn't be highlighted, and odd-indexed parts should
2440 $endresult .= $this->hsc($parts[$key][1]);
2449 if ($this->strict_mode && !is_null($parts[$key][0])) {
2452 $highlight_part = $this->language_data['HIGHLIGHT_STRICT_BLOCK'][$script_key];
2453 if ($this->language_data['STYLES']['SCRIPT'][$script_key] != '' &&
2454 $this->lexic_permissions['SCRIPT']) {
2457 if (!$this->use_classes &&
2458 $this->language_data['STYLES']['SCRIPT'][$script_key] != '') {
2459 $attributes = ' style="' . $this->language_data['STYLES']['SCRIPT'][$script_key] . '"';
2475 $next_comment_regexp_pos = -1;
2476 $next_comment_multi_pos = -1;
2477 $next_comment_single_pos = -1;
2485 $next_escape_regexp_pos = -1;
2494 if (isset($this->language_data['COMMENT_REGEXP']) && $next_comment_regexp_pos < $i) {
2496 foreach ($this->language_data['COMMENT_REGEXP'] as $comment_key => $regexp) {
2561 $string_key = array_search($char, $this->language_data['QUOTEMARKS']);
2562 if (!isset($this->language_data['STYLES']['STRINGS'][$string_key]) ||
2563 !isset($this->language_data['STYLES']['ESCAPE_CHAR'][$string_key])) {
2568 $result .= $this->parse_non_string_part($stuff_to_parse);
2571 if (!$this->use_classes) {
2572 $string_attributes = ' style="' . $this->language_data['STYLES']['STRINGS'][$string_key] . '"';
2582 if(empty($this->language_data['ESCAPE_REGEXP'])) {
2593 if($this->lexic_permissions['ESCAPE_CHAR']) {
2595 if (isset($this->language_data['ESCAPE_REGEXP']) && $next_escape_regexp_pos < $start) {
2597 foreach ($this->language_data['ESCAPE_REGEXP'] as $escape_key => $regexp) {
2632 if('' != $this->language_data['ESCAPE_CHAR']) {
2633 $simple_escape = strpos($part, $this->language_data['ESCAPE_CHAR'], $start);
2652 $string .= $this->hsc(substr($part, $start, $es_pos - $start));
2655 if (!$this->use_classes) {
2656 $escape_char_attributes = ' style="' . $this->language_data['STYLES']['ESCAPE_CHAR'][0] . '"';
2663 GeSHi::hsc($this->language_data['ESCAPE_CHAR']);
2672 //This is an non-ASCII char (UTF8 or single byte)
2675 $es_char_m = mb_substr(substr($part, $es_pos+1, 16), 0, 1, $this->encoding);
2677 } elseif ('utf-8' == $this->encoding) {
2678 if(preg_match("/[\xC2-\xDF][\x80-\xBF]".
2679 "|\xE0[\xA0-\xBF][\x80-\xBF]".
2680 "|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}".
2681 "|\xED[\x80-\x9F][\x80-\xBF]".
2682 "|\xF0[\x90-\xBF][\x80-\xBF]{2}".
2683 "|[\xF1-\xF3][\x80-\xBF]{3}".
2684 "|\xF4[\x80-\x8F][\x80-\xBF]{2}/s",
2690 $string .= $this->hsc($es_char_m) . '</span>';
2692 $es_char_m = $this->hsc($es_char);
2696 $string .= $this->hsc($es_char) . '</span>';
2703 $string .= $this->hsc(substr($part, $start, $es_pos - $start));
2711 if (!$this->use_classes) {
2712 $escape_char_attributes = ' style="' . $this->language_data['STYLES']['ESCAPE_CHAR'][$escape_key] . '"';
2719 $this->hsc($escape_str) . '</span>';
2724 $string .= $this->hsc(substr($part, $start, $close_pos - $start + $char_len)) . '</span>';
2741 $i = $start - 1;
2743 } elseif ($this->lexic_permissions['STRINGS'] && $hq && $hq[0] == $char &&
2746 if (!$this->use_classes) {
2747 $string_attributes = ' style="' . $this->language_data['STYLES']['STRINGS']['HARD'] . '"';
2748 $escape_char_attributes = ' style="' . $this->language_data['STYLES']['ESCAPE_CHAR']['HARD'] . '"';
2754 $result .= $this->parse_non_string_part($stuff_to_parse);
2762 while ($close_pos = strpos($part, $this->language_data['HARDQUOTE'][1], $start)) {
2764 if ($this->lexic_permissions['ESCAPE_CHAR'] && $part[$close_pos - 1] == $this->language_data['HARDCHAR'] &&
2767 foreach ($this->language_data['HARDESCAPE'] as $hardescape) {
2768 if (substr($part, $close_pos - 1, strlen($hardescape)) == $hardescape) {
2770 $escape_char_pos = $close_pos - 1;
2772 && $part[$escape_char_pos - 1] == $this->language_data['HARDCHAR']) {
2773 --$escape_char_pos;
2775 if (($close_pos - $escape_char_pos) & 1) {
2794 $string = substr($part, $i, $close_pos - $i + 1);
2799 if ($this->lexic_permissions['ESCAPE_CHAR'] && $this->language_data['ESCAPE_CHAR']) {
2802 while ($es_pos = strpos($string, $this->language_data['ESCAPE_CHAR'], $start)) {
2804 $new_string .= $this->hsc(substr($string, $start, $es_pos - $start));
2806 foreach ($this->language_data['HARDESCAPE'] as $hardescape) {
2810 $this->hsc($hardescape) . '</span>';
2819 && $string[$es_pos + $c] == $this->language_data['ESCAPE_CHAR']
2820 && $string[$es_pos + $c + 1] == $this->language_data['ESCAPE_CHAR']) {
2834 $string = $new_string . $this->hsc(substr($string, $start));
2836 $string = $this->hsc($string);
2856 $test_str = $this->hsc(substr($part, $i, $comment['length']));
2859 if ($this->lexic_permissions['COMMENTS']['MULTI']) {
2860 if (!$this->use_classes) {
2861 $attributes = ' style="' . $this->language_data['STYLES']['COMMENTS'][$comment['key']] . '"';
2868 // Short-cut through all the multiline code
2878 $i += $comment['length'] - 1;
2881 $result .= $this->parse_non_string_part($stuff_to_parse);
2885 // If we haven't matched a regexp comment, try multi-line comments
2888 if (!empty($this->language_data['COMMENT_MULTI']) && $next_comment_multi_pos < $i) {
2890 foreach ($this->language_data['COMMENT_MULTI'] as $open => $close) {
2918 $close = $this->language_data['COMMENT_MULTI'][$open];
2924 if ($this->lexic_permissions['COMMENTS']['MULTI'] ||
2927 if (!$this->use_classes) {
2928 $attributes = ' style="' . $this->language_data['STYLES']['COMMENTS']['MULTI'] . '"';
2932 $test_str = "<span$attributes>" . $this->hsc($open);
2934 if (!$this->use_classes) {
2935 $attributes = ' style="' . $this->important_styles . '"';
2945 $test_str = $this->hsc($open);
2954 // Short-cut through all the multiline code
2955 $rest_of_comment = $this->hsc(substr($part, $i + $open_strlen, $close_pos - $i - $open_strlen + $close_strlen));
2956 if (($this->lexic_permissions['COMMENTS']['MULTI'] ||
2969 if ($this->lexic_permissions['COMMENTS']['MULTI'] ||
2974 $i = $close_pos + $close_strlen - 1;
2977 $result .= $this->parse_non_string_part($stuff_to_parse);
2982 // If we haven't matched a multiline comment, try single-line comments
2985 if (!empty($this->language_data['COMMENT_SINGLE']) && $next_comment_single_pos < $i) {
2987 foreach ($this->language_data['COMMENT_SINGLE'] as $comment_key => $comment_mark) {
3000 ($this->language_data['CASE_SENSITIVE'][GESHI_COMMENTS] &&
3003 (!$this->language_data['CASE_SENSITIVE'][GESHI_COMMENTS] &&
3021 $comment_mark = $this->language_data['COMMENT_SINGLE'][$comment_key];
3027 (false === strpos($sc_disallowed_before, $part[$i-1]))) &&
3033 if ($this->lexic_permissions['COMMENTS'][$comment_key]) {
3034 if (!$this->use_classes) {
3035 $attributes = ' style="' . $this->language_data['STYLES']['COMMENTS'][$comment_key] . '"';
3039 $test_str = "<span$attributes>" . $this->hsc($this->change_case($comment_mark));
3041 $test_str = $this->hsc($comment_mark);
3051 $test_str .= $this->hsc(substr($part, $i + $com_len, $close_pos - $i - $com_len));
3052 if ($this->lexic_permissions['COMMENTS'][$comment_key]) {
3064 $result .= $this->parse_non_string_part($stuff_to_parse);
3081 $result .= $this->parse_non_string_part($stuff_to_parse);
3084 $result .= $this->hsc($part);
3102 // $result .= $this->parse_non_string_part($stuff_to_parse);
3105 // $result = substr($result, 1, -1);
3108 $this->set_time($start_time, microtime());
3110 $this->finalise($endresult);
3126 $tab_width = $this->get_real_tab_width();
3147 // html so that < or > would be allowed in user's styles
3163 $pos -= $posi+2;
3168 // OPTIMISE - move $strs out. Make an array:
3174 $tab_end_width = $tab_width - ($pos % $tab_width); //Moved out of the look as it doesn't change within the loop
3197 unset($lines);//We don't need the lines separated beyond this --- free them!
3204 if ($this->line_numbers == GESHI_NO_LINE_NUMBERS && $this->header_type != GESHI_HEADER_PRE_TABLE) {
3205 if ($this->line_ending === null) {
3208 $result = str_replace("\n", $this->line_ending, $result);
3221 switch ($this->language_data['CASE_KEYWORDS']) {
3241 $k = $this->_kw_replace_group;
3248 if ($this->keyword_links) {
3251 if (isset($this->language_data['URLS'][$k]) &&
3252 $this->language_data['URLS'][$k] != '') {
3256 //$keyword = ( $this->language_data['CASE_SENSITIVE'][$group] ) ? $keyword : strtolower($keyword);
3258 if (!$this->language_data['CASE_SENSITIVE'][$k] &&
3259 strpos($this->language_data['URLS'][$k], '{FNAME}') !== false) {
3260 foreach ($this->language_data['KEYWORDS'][$k] as $word) {
3278 str_replace('+', '%20', urlencode($this->hsc($word))),
3279 str_replace('+', '%20', urlencode($this->hsc(strtolower($word)))),
3280 str_replace('+', '%20', urlencode($this->hsc(strtoupper($word)))),
3281 str_replace('+', '%20', urlencode($this->hsc(ucfirst($word)))),
3283 $this->language_data['URLS'][$k]
3289 return $before . '<|/'. $k .'/>' . $this->change_case($keyword) . '|>' . $after;
3293 * handles regular expressions highlighting-definitions with callback functions
3303 return ' style="' . call_user_func($this->language_data['STYLES']['REGEXPS'][$this->_rx_key], $matches[1]) . '"'. $matches[1] . '|>';
3316 $before = $this->_hmr_before;
3317 $after = $this->_hmr_after;
3318 if ($this->_hmr_replace) {
3319 $replace = $this->_hmr_replace;
3333 . '<|!REG3XP' . $this->_hmr_key .'!>'
3334 . str_replace("\n", "|>\n<|!REG3XP" . $this->_hmr_key . '!>', $replace)
3349 $stuff_to_parse = ' ' . $this->hsc($stuff_to_parse);
3352 $disallowed_before = "(?<![a-zA-Z0-9\$_\|\#|^&";
3353 $disallowed_after = "(?![a-zA-Z0-9_\|%\\-&;";
3354 if ($this->lexic_permissions['STRINGS']) {
3355 $quotemarks = preg_quote(implode($this->language_data['QUOTEMARKS']), '/');
3363 if (isset($this->language_data['PARSER_CONTROL'])) {
3364 if (isset($this->language_data['PARSER_CONTROL']['KEYWORDS'])) {
3365 $x = 0; // check wether per-keyword-group parser_control is enabled
3366 if (isset($this->language_data['PARSER_CONTROL']['KEYWORDS']['DISALLOWED_BEFORE'])) {
3367 $disallowed_before = $this->language_data['PARSER_CONTROL']['KEYWORDS']['DISALLOWED_BEFORE'];
3370 if (isset($this->language_data['PARSER_CONTROL']['KEYWORDS']['DISALLOWED_AFTER'])) {
3371 $disallowed_after = $this->language_data['PARSER_CONTROL']['KEYWORDS']['DISALLOWED_AFTER'];
3374 $parser_control_pergroup = (count($this->language_data['PARSER_CONTROL']['KEYWORDS']) - $x) > 0;
3378 foreach (array_keys($this->language_data['KEYWORDS']) as $k) {
3379 if (!isset($this->lexic_permissions['KEYWORDS'][$k]) ||
3380 $this->lexic_permissions['KEYWORDS'][$k]) {
3382 $case_sensitive = $this->language_data['CASE_SENSITIVE'][$k];
3385 // NEW in 1.0.8 - per-keyword-group parser control
3388 if ($parser_control_pergroup && isset($this->language_data['PARSER_CONTROL']['KEYWORDS'][$k])) {
3389 if (isset($this->language_data['PARSER_CONTROL']['KEYWORDS'][$k]['DISALLOWED_BEFORE'])) {
3391 $this->language_data['PARSER_CONTROL']['KEYWORDS'][$k]['DISALLOWED_BEFORE'];
3394 if (isset($this->language_data['PARSER_CONTROL']['KEYWORDS'][$k]['DISALLOWED_AFTER'])) {
3396 $this->language_data['PARSER_CONTROL']['KEYWORDS'][$k]['DISALLOWED_AFTER'];
3400 $this->_kw_replace_group = $k;
3404 for ($set = 0, $set_length = count($this->language_data['CACHED_KEYWORD_LISTS'][$k]); $set < $set_length; ++$set) {
3405 $keywordset =& $this->language_data['CACHED_KEYWORD_LISTS'][$k][$set];
3419 foreach ($this->language_data['REGEXPS'] as $key => $regexp) {
3420 if ($this->lexic_permissions['REGEXPS'][$key]) {
3422 if ($this->line_numbers != GESHI_NO_LINE_NUMBERS) {
3424 $this->_hmr_replace = $regexp[GESHI_REPLACE];
3425 $this->_hmr_before = $regexp[GESHI_BEFORE];
3426 $this->_hmr_key = $key;
3427 $this->_hmr_after = $regexp[GESHI_AFTER];
3432 $this->_hmr_replace = false;
3433 $this->_hmr_before = '';
3434 $this->_hmr_after = '';
3442 if ($this->line_numbers != GESHI_NO_LINE_NUMBERS) {
3444 $this->_hmr_key = $key;
3447 $this->_hmr_key = '';
3458 if ($this->lexic_permissions['NUMBERS'] && preg_match($this->language_data['PARSER_CONTROL']['NUMBERS']['PRECHECK_RX'], $stuff_to_parse )) {
3462 foreach($this->language_data['NUMBERS_RXCACHE'] as $id => $regexp) {
3471 foreach (array_keys($this->language_data['KEYWORDS']) as $k) {
3472 if (!$this->use_classes) {
3474 (isset($this->language_data['STYLES']['KEYWORDS'][$k]) ?
3475 $this->language_data['STYLES']['KEYWORDS'][$k] : "") . '"';
3484 foreach($this->language_data['NUMBERS_RXCACHE'] as $id => $regexp) {
3489 if (!$this->use_classes) {
3490 $attributes = ' style="' . $this->language_data['STYLES']['NUMBERS'][$id] . '"';
3502 if ($this->lexic_permissions['METHODS'] && $this->language_data['OOLANG']) {
3505 $oolang_after = "[a-zA-Z][a-zA-Z0-9_]*";
3506 if (isset($this->language_data['PARSER_CONTROL'])) {
3507 if (isset($this->language_data['PARSER_CONTROL']['OOLANG'])) {
3508 if (isset($this->language_data['PARSER_CONTROL']['OOLANG']['MATCH_BEFORE'])) {
3509 $oolang_before = $this->language_data['PARSER_CONTROL']['OOLANG']['MATCH_BEFORE'];
3511 if (isset($this->language_data['PARSER_CONTROL']['OOLANG']['MATCH_AFTER'])) {
3512 $oolang_after = $this->language_data['PARSER_CONTROL']['OOLANG']['MATCH_AFTER'];
3514 if (isset($this->language_data['PARSER_CONTROL']['OOLANG']['MATCH_SPACES'])) {
3515 $oolang_spaces = $this->language_data['PARSER_CONTROL']['OOLANG']['MATCH_SPACES'];
3520 foreach ($this->language_data['OBJECT_SPLITTERS'] as $key => $splitter) {
3522 if (!$this->use_classes) {
3523 $attributes = ' style="' . $this->language_data['STYLES']['METHODS'][$key] . '"';
3527 $stuff_to_parse = preg_replace("/($oolang_before)(" . preg_quote($this->language_data['OBJECT_SPLITTERS'][$key], '/') . ")($oolang_spaces)($oolang_after)/", "\\1\\2\\3<|$attributes>\\4|>", $stuff_to_parse);
3533 // Highlight brackets. Yes, I've tried adding a semi-colon to this list.
3538 if ($this->lexic_permissions['BRACKETS']) {
3539 $stuff_to_parse = str_replace( $this->language_data['CACHE_BRACKET_MATCH'],
3540 $this->language_data['CACHE_BRACKET_REPLACE'], $stuff_to_parse );
3545 if ($this->lexic_permissions['SYMBOLS'] && !empty($this->language_data['SYMBOLS'])) {
3547 $n_symbols = preg_match_all("/<\|(?:<DOT>|[^>])+>(?:(?!\|>).*?)\|>|<\/a>|(?:" . $this->language_data['SYMBOL_SEARCH'] . ")+(?![^<]+?>)/", $stuff_to_parse, $pot_symbols, PREG_OFFSET_CAPTURE | PREG_SET_ORDER);
3569 if ($this->language_data['MULTIPLE_SYMBOL_GROUPS']) {
3570 $old_sym = -1;
3572 preg_match_all("/" . $this->language_data['SYMBOL_SEARCH'] . "/", $symbol_match, $sym_match_syms, PREG_PATTERN_ORDER);
3575 if (isset($this->language_data['SYMBOL_DATA'][$sym_ms])
3576 && ($this->language_data['SYMBOL_DATA'][$sym_ms] != $old_sym)) {
3577 if (-1 != $old_sym) {
3580 $old_sym = $this->language_data['SYMBOL_DATA'][$sym_ms];
3581 if (!$this->use_classes) {
3582 $symbol_hl .= '<| style="' . $this->language_data['STYLES']['SYMBOLS'][$old_sym] . '">';
3591 //Close remaining tags and insert the replacement at the right position ...
3593 if (-1 != $old_sym) {
3597 if (!$this->use_classes) {
3598 $symbol_hl = '<| style="' . $this->language_data['STYLES']['SYMBOLS'][0] . '">';
3609 $global_offset += strlen($symbol_hl) - $symbol_length;
3615 foreach (array_keys($this->language_data['REGEXPS']) as $key) {
3616 if ($this->lexic_permissions['REGEXPS'][$key]) {
3617 if (is_callable($this->language_data['STYLES']['REGEXPS'][$key])) {
3618 $this->_rx_key = $key;
3623 if (!$this->use_classes) {
3624 $attributes = ' style="' . $this->language_data['STYLES']['REGEXPS'][$key] . '"';
3626 if (is_array($this->language_data['REGEXPS'][$key]) &&
3627 array_key_exists(GESHI_CLASS, $this->language_data['REGEXPS'][$key])) {
3629 $this->language_data['REGEXPS'][$key][GESHI_CLASS] . '"';
3642 if (isset($this->link_styles[GESHI_LINK])) {
3643 if ($this->use_classes) {
3644 $stuff_to_parse = str_replace('<|UR1|', '<a' . $this->link_target . ' href=', $stuff_to_parse);
3646 $stuff_to_parse = str_replace('<|UR1|', '<a' . $this->link_target . ' style="' . $this->link_styles[GESHI_LINK] . '" href=', $stuff_to_parse);
3649 $stuff_to_parse = str_replace('<|UR1|', '<a' . $this->link_target . ' href=', $stuff_to_parse);
3671 $this->time = $end[0] + $end[1] - $start[0] - $start[1];
3681 return $this->time;
3698 trigger_error('Argument #' . ($i+1) . ' is not an array - trying to merge array with scalar! Returning false!', E_USER_WARNING);
3710 // if $ret[$key] is not an array you try to merge an scalar value with an array - the result is not defined (incompatible arrays)
3712 $ret[$key] = $this->merge_arrays($ret[$key], $value);
3730 if ($file_name == $this->loaded_language) {
3736 $this->loaded_language = $file_name;
3737 $this->parse_cache_built = false;
3738 $this->enable_highlighting();
3746 $this->language_data = $language_data;
3749 $this->strict_mode = $this->language_data['STRICT_MODE_APPLIES'];
3753 foreach (array_keys($this->language_data['KEYWORDS']) as $key) {
3754 if (!empty($this->language_data['KEYWORDS'][$key])) {
3755 $this->lexic_permissions['KEYWORDS'][$key] = true;
3757 $this->lexic_permissions['KEYWORDS'][$key] = false;
3761 foreach (array_keys($this->language_data['COMMENT_SINGLE']) as $key) {
3762 $this->lexic_permissions['COMMENTS'][$key] = true;
3764 foreach (array_keys($this->language_data['REGEXPS']) as $key) {
3765 $this->lexic_permissions['REGEXPS'][$key] = true;
3771 // even if $this->language_data['PARSER_CONTROL'] is undefined this won't trigger a notice
3772 if (!empty($this->language_data['PARSER_CONTROL']['ENABLE_FLAGS'])) {
3773 foreach ($this->language_data['PARSER_CONTROL']['ENABLE_FLAGS'] as $flag => $value) {
3777 $this->enable_highlighting($perm);
3780 if (!isset($this->lexic_permissions[$flag])) {
3784 if (is_array($this->lexic_permissions[$flag])) {
3785 foreach ($this->lexic_permissions[$flag] as $key => $val) {
3786 $this->lexic_permissions[$flag][$key] = $perm;
3789 $this->lexic_permissions[$flag] = $perm;
3792 unset($this->language_data['PARSER_CONTROL']['ENABLE_FLAGS']);
3797 if(!isset($this->language_data['HARDCHAR'])) {
3798 $this->language_data['HARDCHAR'] = $this->language_data['ESCAPE_CHAR'];
3802 $style_filename = substr($file_name, 0, -4) . '.style.php';
3814 $this->language_data['STYLES'] =
3815 $this->merge_arrays($this->language_data['STYLES'], $style_data);
3831 if ($this->enable_important_blocks &&
3832 (strpos($parsed_code, $this->hsc(GESHI_START_IMPORTANT)) === false)) {
3833 $parsed_code = str_replace($this->hsc(GESHI_END_IMPORTANT), '', $parsed_code);
3837 if ($this->header_type != GESHI_HEADER_PRE && $this->header_type != GESHI_HEADER_PRE_VALID) {
3838 $this->indent($parsed_code);
3847 if ($this->add_ids && !$this->overall_id) {
3848 $this->overall_id = 'geshi-' . substr(md5(microtime()), 0, 4);
3854 $parsed_code = $this->header();
3856 // If we're using line numbers, we insert <li>s and appropriate
3858 if ($this->line_numbers != GESHI_NO_LINE_NUMBERS && $this->header_type != GESHI_HEADER_PRE_TABLE) {
3860 // the <pre> will line-break them (and the <li>s already do this for us)
3861 $ls = ($this->header_type != GESHI_HEADER_PRE && $this->header_type != GESHI_HEADER_PRE_VALID) ? "\n" : '';
3875 if ($this->line_numbers == GESHI_FANCY_LINE_NUMBERS &&
3876 $i % $this->line_nth_row == ($this->line_nth_row - 1)) {
3878 if ($this->use_classes) {
3883 //$attr = ' style="' . $this->line_style2 . '"';
3884 $attrs['style'][] = $this->line_style2;
3888 $def_attr = ' style="' . $this->code_style . '"';
3891 if ($this->use_classes) {
3896 //$attr = ' style="' . $this->line_style1 . '"';
3897 $attrs['style'][] = $this->line_style1;
3898 $def_attr = ' style="' . $this->code_style . '"';
3902 //Check which type of tag to insert for this line
3903 if ($this->header_type == GESHI_HEADER_PRE_VALID) {
3915 if ($this->add_ids) {
3916 $attrs['id'][] = "$this->overall_id-$i";
3920 if (in_array($i, $this->highlight_extra_lines)) {
3921 if ($this->use_classes) {
3922 if (isset($this->highlight_extra_lines_styles[$i])) {
3925 $attrs['class'][] = "ln-xtra";
3928 array_push($attrs['style'], $this->get_line_style($i));
3938 $parsed_code .= "<li$attr_string>$start{$code[$i-1]}$end</li>$ls";
3939 unset($code[$i - 1]);
3943 if ($this->use_classes) {
3946 $attributes = ' style="'. $this->code_style .'"';
3948 if ($this->header_type == GESHI_HEADER_PRE_VALID) {
3950 } elseif ($this->header_type == GESHI_HEADER_PRE_TABLE) {
3951 if ($this->line_numbers != GESHI_NO_LINE_NUMBERS) {
3952 if ($this->use_classes) {
3955 $attrs = ' style="'. $this->table_linenumber_style .'"';
3966 if ($this->line_numbers == GESHI_FANCY_LINE_NUMBERS &&
3967 $i % $this->line_nth_row == ($this->line_nth_row - 1)) {
3969 if ($this->use_classes) {
3975 $parsed_code .= '<span style="display:block;' . $this->line_style2 . '">'
3976 .'<span style="' . $this->code_style .'">';
3981 if (in_array($i + 1, $this->highlight_extra_lines)) {
3982 if ($this->use_classes) {
3983 if (isset($this->highlight_extra_lines_styles[$i])) {
3986 $parsed_code .= "<span class=\"xtra ln-xtra\">";
3989 $parsed_code .= "<span style=\"display:block;" . $this->get_line_style($i) . "\">";
3993 $parsed_code .= $this->line_numbers_start + $i;
4014 if ($this->line_numbers == GESHI_FANCY_LINE_NUMBERS &&
4015 $i % $this->line_nth_row == ($this->line_nth_row - 1)) {
4017 if ($this->use_classes) {
4023 $parsed_code .= '<span style="display:block;' . $this->line_style2 . '">'
4024 .'<span style="' . $this->code_style .'">';
4029 if (in_array($i + 1, $this->highlight_extra_lines)) {
4030 if ($this->use_classes) {
4031 if (isset($this->highlight_extra_lines_styles[$i])) {
4034 $parsed_code .= "<span class=\"xtra ln-xtra\">";
4037 $parsed_code .= "<span style=\"display:block;" . $this->get_line_style($i) . "\">";
4054 if ($this->header_type == GESHI_HEADER_PRE_VALID || $this->header_type == GESHI_HEADER_PRE_TABLE) {
4057 if ($this->header_type == GESHI_HEADER_PRE_TABLE && $this->line_numbers != GESHI_NO_LINE_NUMBERS) {
4062 $parsed_code .= $this->footer();
4074 * @todo Document behaviour change - class is outputted regardless of whether
4077 $attributes = ' class="' . $this->_genCSSName($this->language);
4078 if ($this->overall_class != '') {
4079 $attributes .= " ".$this->_genCSSName($this->overall_class);
4083 if ($this->overall_id != '') {
4084 $attributes .= " id=\"{$this->overall_id}\"";
4086 if ($this->overall_style != '' && !$this->use_classes) {
4087 $attributes .= ' style="' . $this->overall_style . '"';
4092 if ($this->line_numbers_start != 1) {
4093 $ol_attributes .= ' start="' . $this->line_numbers_start . '"';
4097 $header = $this->header_content;
4099 if ($this->header_type == GESHI_HEADER_PRE || $this->header_type == GESHI_HEADER_PRE_VALID) {
4102 $header = $this->replace_keywords($header);
4104 if ($this->use_classes) {
4107 $attr = " style=\"{$this->header_content_style}\"";
4109 if ($this->header_type == GESHI_HEADER_PRE_TABLE && $this->line_numbers != GESHI_NO_LINE_NUMBERS) {
4116 if (GESHI_HEADER_NONE == $this->header_type) {
4117 if ($this->line_numbers != GESHI_NO_LINE_NUMBERS) {
4120 return $header . ($this->force_code_block ? '<div>' : '');
4124 if ($this->line_numbers != GESHI_NO_LINE_NUMBERS) {
4125 if ($this->header_type == GESHI_HEADER_PRE) {
4127 } elseif ($this->header_type == GESHI_HEADER_DIV ||
4128 $this->header_type == GESHI_HEADER_PRE_VALID) {
4130 } elseif ($this->header_type == GESHI_HEADER_PRE_TABLE) {
4134 if ($this->header_type == GESHI_HEADER_PRE) {
4136 ($this->force_code_block ? '<div>' : '');
4139 ($this->force_code_block ? '<div>' : '');
4151 $footer = $this->footer_content;
4153 if ($this->header_type == GESHI_HEADER_PRE) {
4156 $footer = $this->replace_keywords($footer);
4158 if ($this->use_classes) {
4161 $attr = " style=\"{$this->footer_content_style}\"";
4163 if ($this->header_type == GESHI_HEADER_PRE_TABLE && $this->line_numbers != GESHI_NO_LINE_NUMBERS) {
4170 if (GESHI_HEADER_NONE == $this->header_type) {
4171 return ($this->line_numbers != GESHI_NO_LINE_NUMBERS) ? '</ol>' . $footer : $footer;
4174 if ($this->header_type == GESHI_HEADER_DIV || $this->header_type == GESHI_HEADER_PRE_VALID) {
4175 if ($this->line_numbers != GESHI_NO_LINE_NUMBERS) {
4178 return ($this->force_code_block ? '</div>' : '') .
4181 elseif ($this->header_type == GESHI_HEADER_PRE_TABLE) {
4182 if ($this->line_numbers != GESHI_NO_LINE_NUMBERS) {
4185 return ($this->force_code_block ? '</div>' : '') .
4189 if ($this->line_numbers != GESHI_NO_LINE_NUMBERS) {
4192 return ($this->force_code_block ? '</div>' : '') .
4210 $replacements[] = $replacements[] = number_format($time = $this->get_time(), 3);
4214 $replacements[] = $replacements[] = $this->language_data['LANG_NAME'];
4225 $speed = strlen($this->source) / $time;
4238 * Secure replacement for PHP built-in function htmlspecialchars().
4250 * I suspect PHP's htmlspecialchars() is working at the byte-value level and
4254 * byte-value level that goes some way towards explaining why the
4256 * htmlentities() which certainly is working at byte-value level.)
4259 * therefore be "immune" to character set differences - so no charset
4283 * - ENT_COMPAT: escapes &, <, > and double quote (default)
4284 * - ENT_NOQUOTES: escapes only &, < and >
4285 * - ENT_QUOTES: escapes &, <, >, double and single quotes
4301 //This is required as ; would produce undesirable side-effects if it
4345 if ($this->error) {
4351 if(!isset($this->language_data['NUMBERS_CACHE'])) {
4352 $this->build_style_cache();
4358 if ($this->overall_id) {
4359 $selector = '#' . $this->_genCSSName($this->overall_id);
4361 $selector = '.' . $this->_genCSSName($this->language);
4362 if ($this->overall_class) {
4363 $selector .= '.' . $this->_genCSSName($this->overall_class);
4372 " * --------------------------------------\n".
4373 " * Dynamically generated stylesheet for {$this->language}\n".
4374 " * CSS class: {$this->overall_class}, CSS id: {$this->overall_id}\n".
4375 " * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2014 Benny Baumann\n" .
4377 " * --------------------------------------\n".
4381 " * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2014 Benny Baumann\n" .
4390 if (!$economy_mode || $this->line_numbers != GESHI_NO_LINE_NUMBERS) {
4392 $stylesheet .= "$selector.de1, $selector.de2 {{$this->code_style}}\n";
4397 if ($this->overall_style != '') {
4398 $stylesheet .= "$selector {{$this->overall_style}}\n";
4405 foreach ($this->link_styles as $key => $style) {
4426 if ($this->header_content_style != '') {
4427 $stylesheet .= "$selector.head {{$this->header_content_style}}\n";
4429 if ($this->footer_content_style != '') {
4430 $stylesheet .= "$selector.foot {{$this->footer_content_style}}\n";
4435 if ($this->important_styles != '') {
4436 $stylesheet .= "$selector.imp {{$this->important_styles}}\n";
4440 if ((!$economy_mode || $this->line_numbers != GESHI_NO_LINE_NUMBERS) && $this->line_style1 != '') {
4441 $stylesheet .= "{$selector}li, {$selector}.li1 {{$this->line_style1}}\n";
4443 if ((!$economy_mode || $this->line_numbers != GESHI_NO_LINE_NUMBERS) && $this->table_linenumber_style != '') {
4444 $stylesheet .= "{$selector}.ln {{$this->table_linenumber_style}}\n";
4447 if ((!$economy_mode || $this->line_numbers == GESHI_FANCY_LINE_NUMBERS) && $this->line_style2 != '') {
4448 $stylesheet .= "{$selector}.li2 {{$this->line_style2}}\n";
4452 foreach ($this->language_data['STYLES']['KEYWORDS'] as $group => $styles) {
4454 (isset($this->lexic_permissions['KEYWORDS'][$group]) &&
4455 $this->lexic_permissions['KEYWORDS'][$group]))) {
4459 foreach ($this->language_data['STYLES']['COMMENTS'] as $group => $styles) {
4461 (isset($this->lexic_permissions['COMMENTS'][$group]) &&
4462 $this->lexic_permissions['COMMENTS'][$group]) ||
4463 (!empty($this->language_data['COMMENT_REGEXP']) &&
4464 !empty($this->language_data['COMMENT_REGEXP'][$group])))) {
4468 foreach ($this->language_data['STYLES']['ESCAPE_CHAR'] as $group => $styles) {
4469 if ($styles != '' && (!$economy_mode || $this->lexic_permissions['ESCAPE_CHAR'])) {
4477 foreach ($this->language_data['STYLES']['BRACKETS'] as $group => $styles) {
4478 if ($styles != '' && (!$economy_mode || $this->lexic_permissions['BRACKETS'])) {
4482 foreach ($this->language_data['STYLES']['SYMBOLS'] as $group => $styles) {
4483 if ($styles != '' && (!$economy_mode || $this->lexic_permissions['SYMBOLS'])) {
4487 foreach ($this->language_data['STYLES']['STRINGS'] as $group => $styles) {
4488 if ($styles != '' && (!$economy_mode || $this->lexic_permissions['STRINGS'])) {
4496 foreach ($this->language_data['STYLES']['NUMBERS'] as $group => $styles) {
4497 if ($styles != '' && (!$economy_mode || $this->lexic_permissions['NUMBERS'])) {
4501 foreach ($this->language_data['STYLES']['METHODS'] as $group => $styles) {
4502 if ($styles != '' && (!$economy_mode || $this->lexic_permissions['METHODS'])) {
4507 foreach ($this->language_data['STYLES']['SCRIPT'] as $group => $styles) {
4512 foreach ($this->language_data['STYLES']['REGEXPS'] as $group => $styles) {
4514 (isset($this->lexic_permissions['REGEXPS'][$group]) &&
4515 $this->lexic_permissions['REGEXPS'][$group]))) {
4516 if (is_array($this->language_data['REGEXPS'][$group]) &&
4517 array_key_exists(GESHI_CLASS, $this->language_data['REGEXPS'][$group])) {
4519 $stylesheet .= $this->language_data['REGEXPS'][$group][GESHI_CLASS];
4527 if (!$economy_mode || (count($this->highlight_extra_lines)!=count($this->highlight_extra_lines_styles))) {
4528 $stylesheet .= "{$selector}.ln-xtra, {$selector}li.ln-xtra, {$selector}div.ln-xtra {{$this->highlight_extra_lines_style}}\n";
4531 foreach ($this->highlight_extra_lines_styles as $lineid => $linestyle) {
4546 if (isset($this->highlight_extra_lines_styles[$line])) {
4547 $style = $this->highlight_extra_lines_styles[$line];
4549 $style = $this->highlight_extra_lines_style;
4570 $regex_chars = array('.', '\\', '+', '-', '*', '?', '[', '^', ']', '$',
4585 $regexp_list[++$list_key] = $this->_optimize_regexp_list_tokens_to_string($tokens);
4642 $new_entry = $this->_optimize_regexp_list_tokens_to_string($tokens);
4667 $new_entry = $this->_optimize_regexp_list_tokens_to_string($tokens);
4684 * you should not call this function directly, @see $this->optimize_regexp_list().
4699 $list .= '(?:' . $this->_optimize_regexp_list_tokens_to_string($sub_tokens, true) . ')';
4726 return substr($list, 0, -1);
4745 $geshi->set_header_type(GESHI_HEADER_NONE);
4748 return '<code>' . $geshi->parse_code() . '</code>';
4751 echo '<code>' . $geshi->parse_code() . '</code>';
4753 if ($geshi->error()) {