plugins/geshi/base.php
author Dan
Fri, 29 May 2009 19:30:59 -0400
changeset 2 9e3258dfae15
parent 0 441963e5b07a
child 3 f3e2bbbd2155
permissions -rwxr-xr-x
Updated GeSHi. w00t.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
     1
<?php
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
     2
/**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
     3
 * GeSHi - Generic Syntax Highlighter
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
     4
 *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
     5
 * The GeSHi class for Generic Syntax Highlighting. Please refer to the
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
     6
 * documentation at http://qbnz.com/highlighter/documentation.php for more
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
     7
 * information about how to use this class.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
     8
 *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
     9
 * For changes, release notes, TODOs etc, see the relevant files in the docs/
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    10
 * directory.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    11
 *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    12
 *   This file is part of GeSHi.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    13
 *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    14
 *  GeSHi is free software; you can redistribute it and/or modify
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    15
 *  it under the terms of the GNU General Public License as published by
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    16
 *  the Free Software Foundation; either version 2 of the License, or
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    17
 *  (at your option) any later version.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    18
 *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    19
 *  GeSHi is distributed in the hope that it will be useful,
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    20
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    21
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    22
 *  GNU General Public License for more details.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    23
 *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    24
 *  You should have received a copy of the GNU General Public License
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    25
 *  along with GeSHi; if not, write to the Free Software
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    26
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    27
 *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    28
 * @package    geshi
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    29
 * @subpackage core
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
    30
 * @author     Nigel McNie <nigel@geshi.org>, Benny Baumann <BenBE@omorphia.de>
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
    31
 * @copyright  (C) 2004 - 2007 Nigel McNie, (C) 2007 - 2008 Benny Baumann
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    32
 * @license    http://gnu.org/copyleft/gpl.html GNU GPL
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    33
 *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    34
 */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    35
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    36
//
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    37
// GeSHi Constants
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    38
// You should use these constant names in your programs instead of
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    39
// their values - you never know when a value may change in a future
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    40
// version
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    41
//
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    42
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    43
/** The version of this GeSHi file */
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
    44
define('GESHI_VERSION', '1.0.8.2');
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    45
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    46
// Define the root directory for the GeSHi code tree
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    47
if (!defined('GESHI_ROOT')) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    48
    /** The root directory for GeSHi */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    49
    define('GESHI_ROOT', dirname(__FILE__) . DIRECTORY_SEPARATOR);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    50
}
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    51
/** The language file directory for GeSHi
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    52
    @access private */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    53
define('GESHI_LANG_ROOT', GESHI_ROOT . 'geshi' . DIRECTORY_SEPARATOR);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    54
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
    55
// Define if GeSHi should be paranoid about security
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
    56
if (!defined('GESHI_SECURITY_PARANOID')) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
    57
    /** Tells GeSHi to be paranoid about security settings */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
    58
    define('GESHI_SECURITY_PARANOID', false);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
    59
}
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    60
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    61
// Line numbers - use with enable_line_numbers()
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    62
/** Use no line numbers when building the result */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    63
define('GESHI_NO_LINE_NUMBERS', 0);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    64
/** Use normal line numbers when building the result */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    65
define('GESHI_NORMAL_LINE_NUMBERS', 1);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    66
/** Use fancy line numbers when building the result */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    67
define('GESHI_FANCY_LINE_NUMBERS', 2);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    68
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    69
// Container HTML type
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    70
/** Use nothing to surround the source */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    71
define('GESHI_HEADER_NONE', 0);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    72
/** Use a "div" to surround the source */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    73
define('GESHI_HEADER_DIV', 1);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    74
/** Use a "pre" to surround the source */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    75
define('GESHI_HEADER_PRE', 2);
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
    76
/** Use a pre to wrap lines when line numbers are enabled or to wrap the whole code. */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
    77
define('GESHI_HEADER_PRE_VALID', 3);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
    78
/**
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
    79
 * Use a "table" to surround the source:
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
    80
 *
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
    81
 *  <table>
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
    82
 *    <thead><tr><td colspan="2">$header</td></tr></thead>
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
    83
 *    <tbody><tr><td><pre>$linenumbers</pre></td><td><pre>$code></pre></td></tr></tbody>
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
    84
 *    <tfooter><tr><td colspan="2">$footer</td></tr></tfoot>
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
    85
 *  </table>
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
    86
 *
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
    87
 * this is essentially only a workaround for Firefox, see sf#1651996 or take a look at
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
    88
 * https://bugzilla.mozilla.org/show_bug.cgi?id=365805
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
    89
 * @note when linenumbers are disabled this is essentially the same as GESHI_HEADER_PRE
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
    90
 */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
    91
define('GESHI_HEADER_PRE_TABLE', 4);
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    92
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    93
// Capatalisation constants
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    94
/** Lowercase keywords found */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    95
define('GESHI_CAPS_NO_CHANGE', 0);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    96
/** Uppercase keywords found */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    97
define('GESHI_CAPS_UPPER', 1);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    98
/** Leave keywords found as the case that they are */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    99
define('GESHI_CAPS_LOWER', 2);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   100
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   101
// Link style constants
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   102
/** Links in the source in the :link state */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   103
define('GESHI_LINK', 0);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   104
/** Links in the source in the :hover state */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   105
define('GESHI_HOVER', 1);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   106
/** Links in the source in the :active state */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   107
define('GESHI_ACTIVE', 2);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   108
/** Links in the source in the :visited state */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   109
define('GESHI_VISITED', 3);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   110
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   111
// Important string starter/finisher
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   112
// Note that if you change these, they should be as-is: i.e., don't
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   113
// write them as if they had been run through htmlentities()
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   114
/** The starter for important parts of the source */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   115
define('GESHI_START_IMPORTANT', '<BEGIN GeSHi>');
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   116
/** The ender for important parts of the source */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   117
define('GESHI_END_IMPORTANT', '<END GeSHi>');
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   118
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   119
/**#@+
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   120
 *  @access private
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   121
 */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   122
// When strict mode applies for a language
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   123
/** Strict mode never applies (this is the most common) */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   124
define('GESHI_NEVER', 0);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   125
/** Strict mode *might* apply, and can be enabled or
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   126
    disabled by {@link GeSHi->enable_strict_mode()} */
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   127
define('GESHI_MAYBE', 1);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   128
/** Strict mode always applies */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   129
define('GESHI_ALWAYS', 2);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   130
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   131
// Advanced regexp handling constants, used in language files
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   132
/** The key of the regex array defining what to search for */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   133
define('GESHI_SEARCH', 0);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   134
/** The key of the regex array defining what bracket group in a
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   135
    matched search to use as a replacement */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   136
define('GESHI_REPLACE', 1);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   137
/** The key of the regex array defining any modifiers to the regular expression */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   138
define('GESHI_MODIFIERS', 2);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   139
/** The key of the regex array defining what bracket group in a
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   140
    matched search to put before the replacement */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   141
define('GESHI_BEFORE', 3);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   142
/** The key of the regex array defining what bracket group in a
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   143
    matched search to put after the replacement */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   144
define('GESHI_AFTER', 4);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   145
/** The key of the regex array defining a custom keyword to use
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   146
    for this regexp's html tag class */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   147
define('GESHI_CLASS', 5);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   148
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   149
/** Used in language files to mark comments */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   150
define('GESHI_COMMENTS', 0);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   151
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   152
/** Used to work around missing PHP features **/
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   153
define('GESHI_PHP_PRE_433', !(version_compare(PHP_VERSION, '4.3.3') === 1));
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   154
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   155
/** make sure we can call stripos **/
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   156
if (!function_exists('stripos')) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   157
    // the offset param of preg_match is not supported below PHP 4.3.3
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   158
    if (GESHI_PHP_PRE_433) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   159
        /**
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   160
         * @ignore
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   161
         */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   162
        function stripos($haystack, $needle, $offset = null) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   163
            if (!is_null($offset)) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   164
                $haystack = substr($haystack, $offset);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   165
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   166
            if (preg_match('/'. preg_quote($needle, '/') . '/', $haystack, $match, PREG_OFFSET_CAPTURE)) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   167
                return $match[0][1];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   168
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   169
            return false;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   170
        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   171
    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   172
    else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   173
        /**
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   174
         * @ignore
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   175
         */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   176
        function stripos($haystack, $needle, $offset = null) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   177
            if (preg_match('/'. preg_quote($needle, '/') . '/', $haystack, $match, PREG_OFFSET_CAPTURE, $offset)) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   178
                return $match[0][1];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   179
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   180
            return false;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   181
        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   182
    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   183
}
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   184
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   185
/** some old PHP / PCRE subpatterns only support up to xxx subpatterns in
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   186
    regular expressions. Set this to false if your PCRE lib is up to date
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   187
    @see GeSHi->optimize_regexp_list()
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   188
    **/
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   189
define('GESHI_MAX_PCRE_SUBPATTERNS', 500);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   190
/** it's also important not to generate too long regular expressions
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   191
    be generous here... but keep in mind, that when reaching this limit we
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   192
    still have to close open patterns. 12k should do just fine on a 16k limit.
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   193
    @see GeSHi->optimize_regexp_list()
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   194
    **/
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   195
define('GESHI_MAX_PCRE_LENGTH', 12288);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   196
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   197
//Number format specification
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   198
/** Basic number format for integers */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   199
define('GESHI_NUMBER_INT_BASIC', 1);        //Default integers \d+
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   200
/** Enhanced number format for integers like seen in C */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   201
define('GESHI_NUMBER_INT_CSTYLE', 2);       //Default C-Style \d+[lL]?
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   202
/** Number format to highlight binary numbers with a suffix "b" */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   203
define('GESHI_NUMBER_BIN_SUFFIX', 16);           //[01]+[bB]
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   204
/** Number format to highlight binary numbers with a prefix % */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   205
define('GESHI_NUMBER_BIN_PREFIX_PERCENT', 32);   //%[01]+
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   206
/** Number format to highlight binary numbers with a prefix 0b (C) */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   207
define('GESHI_NUMBER_BIN_PREFIX_0B', 64);        //0b[01]+
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   208
/** Number format to highlight octal numbers with a leading zero */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   209
define('GESHI_NUMBER_OCT_PREFIX', 256);           //0[0-7]+
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   210
/** Number format to highlight octal numbers with a suffix of o */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   211
define('GESHI_NUMBER_OCT_SUFFIX', 512);           //[0-7]+[oO]
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   212
/** Number format to highlight hex numbers with a prefix 0x */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   213
define('GESHI_NUMBER_HEX_PREFIX', 4096);           //0x[0-9a-fA-F]+
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   214
/** Number format to highlight hex numbers with a suffix of h */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   215
define('GESHI_NUMBER_HEX_SUFFIX', 8192);           //[0-9][0-9a-fA-F]*h
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   216
/** Number format to highlight floating-point numbers without support for scientific notation */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   217
define('GESHI_NUMBER_FLT_NONSCI', 65536);          //\d+\.\d+
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   218
/** Number format to highlight floating-point numbers without support for scientific notation */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   219
define('GESHI_NUMBER_FLT_NONSCI_F', 131072);       //\d+(\.\d+)?f
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   220
/** Number format to highlight floating-point numbers with support for scientific notation (E) and optional leading zero */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   221
define('GESHI_NUMBER_FLT_SCI_SHORT', 262144);      //\.\d+e\d+
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   222
/** Number format to highlight floating-point numbers with support for scientific notation (E) and required leading digit */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   223
define('GESHI_NUMBER_FLT_SCI_ZERO', 524288);       //\d+(\.\d+)?e\d+
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   224
//Custom formats are passed by RX array
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   225
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   226
// Error detection - use these to analyse faults
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   227
/** No sourcecode to highlight was specified
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   228
 * @deprecated
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   229
 */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   230
define('GESHI_ERROR_NO_INPUT', 1);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   231
/** The language specified does not exist */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   232
define('GESHI_ERROR_NO_SUCH_LANG', 2);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   233
/** GeSHi could not open a file for reading (generally a language file) */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   234
define('GESHI_ERROR_FILE_NOT_READABLE', 3);
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   235
/** The header type passed to {@link GeSHi->set_header_type()} was invalid */
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   236
define('GESHI_ERROR_INVALID_HEADER_TYPE', 4);
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   237
/** The line number type passed to {@link GeSHi->enable_line_numbers()} was invalid */
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   238
define('GESHI_ERROR_INVALID_LINE_NUMBER_TYPE', 5);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   239
/**#@-*/
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   240
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   241
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   242
/**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   243
 * The GeSHi Class.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   244
 *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   245
 * Please refer to the documentation for GeSHi 1.0.X that is available
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   246
 * at http://qbnz.com/highlighter/documentation.php for more information
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   247
 * about how to use this class.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   248
 *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   249
 * @package   geshi
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   250
 * @author    Nigel McNie <nigel@geshi.org>, Benny Baumann <BenBE@omorphia.de>
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   251
 * @copyright (C) 2004 - 2007 Nigel McNie, (C) 2007 - 2008 Benny Baumann
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   252
 */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   253
class GeSHi {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   254
    /**#@+
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   255
     * @access private
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   256
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   257
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   258
     * The source code to highlight
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   259
     * @var string
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   260
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   261
    var $source = '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   262
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   263
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   264
     * The language to use when highlighting
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   265
     * @var string
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   266
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   267
    var $language = '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   268
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   269
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   270
     * The data for the language used
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   271
     * @var array
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   272
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   273
    var $language_data = array();
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   274
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   275
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   276
     * The path to the language files
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   277
     * @var string
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   278
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   279
    var $language_path = GESHI_LANG_ROOT;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   280
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   281
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   282
     * The error message associated with an error
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   283
     * @var string
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   284
     * @todo check err reporting works
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   285
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   286
    var $error = false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   287
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   288
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   289
     * Possible error messages
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   290
     * @var array
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   291
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   292
    var $error_messages = array(
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   293
        GESHI_ERROR_NO_SUCH_LANG => 'GeSHi could not find the language {LANGUAGE} (using path {PATH})',
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   294
        GESHI_ERROR_FILE_NOT_READABLE => 'The file specified for load_from_file was not readable',
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   295
        GESHI_ERROR_INVALID_HEADER_TYPE => 'The header type specified is invalid',
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   296
        GESHI_ERROR_INVALID_LINE_NUMBER_TYPE => 'The line number type specified is invalid'
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   297
    );
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   298
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   299
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   300
     * Whether highlighting is strict or not
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   301
     * @var boolean
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   302
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   303
    var $strict_mode = false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   304
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   305
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   306
     * Whether to use CSS classes in output
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   307
     * @var boolean
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   308
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   309
    var $use_classes = false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   310
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   311
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   312
     * The type of header to use. Can be one of the following
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   313
     * values:
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   314
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   315
     * - GESHI_HEADER_PRE: Source is outputted in a "pre" HTML element.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   316
     * - GESHI_HEADER_DIV: Source is outputted in a "div" HTML element.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   317
     * - GESHI_HEADER_NONE: No header is outputted.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   318
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   319
     * @var int
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   320
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   321
    var $header_type = GESHI_HEADER_PRE;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   322
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   323
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   324
     * Array of permissions for which lexics should be highlighted
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   325
     * @var array
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   326
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   327
    var $lexic_permissions = array(
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   328
        'KEYWORDS' =>    array(),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   329
        'COMMENTS' =>    array('MULTI' => true),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   330
        'REGEXPS' =>     array(),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   331
        'ESCAPE_CHAR' => true,
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   332
        'BRACKETS' =>    true,
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   333
        'SYMBOLS' =>     false,
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   334
        'STRINGS' =>     true,
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   335
        'NUMBERS' =>     true,
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   336
        'METHODS' =>     true,
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   337
        'SCRIPT' =>      true
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   338
    );
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   339
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   340
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   341
     * The time it took to parse the code
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   342
     * @var double
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   343
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   344
    var $time = 0;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   345
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   346
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   347
     * The content of the header block
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   348
     * @var string
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   349
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   350
    var $header_content = '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   351
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   352
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   353
     * The content of the footer block
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   354
     * @var string
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   355
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   356
    var $footer_content = '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   357
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   358
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   359
     * The style of the header block
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   360
     * @var string
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   361
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   362
    var $header_content_style = '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   363
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   364
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   365
     * The style of the footer block
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   366
     * @var string
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   367
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   368
    var $footer_content_style = '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   369
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   370
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   371
     * Tells if a block around the highlighted source should be forced
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   372
     * if not using line numbering
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   373
     * @var boolean
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   374
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   375
    var $force_code_block = false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   376
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   377
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   378
     * The styles for hyperlinks in the code
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   379
     * @var array
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   380
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   381
    var $link_styles = array();
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   382
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   383
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   384
     * Whether important blocks should be recognised or not
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   385
     * @var boolean
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   386
     * @deprecated
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   387
     * @todo REMOVE THIS FUNCTIONALITY!
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   388
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   389
    var $enable_important_blocks = false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   390
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   391
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   392
     * Styles for important parts of the code
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   393
     * @var string
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   394
     * @deprecated
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   395
     * @todo As above - rethink the whole idea of important blocks as it is buggy and
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   396
     * will be hard to implement in 1.2
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   397
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   398
    var $important_styles = 'font-weight: bold; color: red;'; // Styles for important parts of the code
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   399
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   400
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   401
     * Whether CSS IDs should be added to the code
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   402
     * @var boolean
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   403
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   404
    var $add_ids = false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   405
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   406
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   407
     * Lines that should be highlighted extra
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   408
     * @var array
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   409
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   410
    var $highlight_extra_lines = array();
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   411
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   412
    /**
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   413
     * Styles of lines that should be highlighted extra
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   414
     * @var array
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   415
     */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   416
    var $highlight_extra_lines_styles = array();
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   417
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   418
    /**
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   419
     * Styles of extra-highlighted lines
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   420
     * @var string
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   421
     */
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   422
    var $highlight_extra_lines_style = 'background-color: #ffc;';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   423
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   424
    /**
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   425
     * The line ending
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   426
     * If null, nl2br() will be used on the result string.
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   427
     * Otherwise, all instances of \n will be replaced with $line_ending
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   428
     * @var string
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   429
     */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   430
    var $line_ending = null;
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   431
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   432
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   433
     * Number at which line numbers should start at
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   434
     * @var int
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   435
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   436
    var $line_numbers_start = 1;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   437
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   438
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   439
     * The overall style for this code block
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   440
     * @var string
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   441
     */
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   442
    var $overall_style = 'font-family:monospace;';
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   443
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   444
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   445
     *  The style for the actual code
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   446
     * @var string
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   447
     */
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   448
    var $code_style = 'font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;';
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   449
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   450
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   451
     * The overall class for this code block
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   452
     * @var string
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   453
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   454
    var $overall_class = '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   455
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   456
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   457
     * The overall ID for this code block
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   458
     * @var string
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   459
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   460
    var $overall_id = '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   461
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   462
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   463
     * Line number styles
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   464
     * @var string
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   465
     */
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   466
    var $line_style1 = 'font-weight: normal; vertical-align:top;';
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   467
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   468
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   469
     * Line number styles for fancy lines
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   470
     * @var string
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   471
     */
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   472
    var $line_style2 = 'font-weight: bold; vertical-align:top;';
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   473
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   474
    /**
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   475
     * Style for line numbers when GESHI_HEADER_PRE_TABLE is chosen
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   476
     * @var string
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   477
     */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   478
    var $table_linenumber_style = 'width:1px;text-align:right;margin:0;padding:0 2px;vertical-align:top;';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   479
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   480
    /**
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   481
     * Flag for how line numbers are displayed
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   482
     * @var boolean
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   483
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   484
    var $line_numbers = GESHI_NO_LINE_NUMBERS;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   485
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   486
    /**
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   487
     * Flag to decide if multi line spans are allowed. Set it to false to make sure
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   488
     * each tag is closed before and reopened after each linefeed.
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   489
     * @var boolean
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   490
     */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   491
    var $allow_multiline_span = true;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   492
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   493
    /**
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   494
     * The "nth" value for fancy line highlighting
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   495
     * @var int
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   496
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   497
    var $line_nth_row = 0;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   498
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   499
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   500
     * The size of tab stops
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   501
     * @var int
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   502
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   503
    var $tab_width = 8;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   504
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   505
    /**
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   506
     * Should we use language-defined tab stop widths?
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   507
     * @var int
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   508
     */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   509
    var $use_language_tab_width = false;
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   510
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   511
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   512
     * Default target for keyword links
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   513
     * @var string
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   514
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   515
    var $link_target = '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   516
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   517
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   518
     * The encoding to use for entity encoding
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   519
     * NOTE: Used with Escape Char Sequences to fix UTF-8 handling (cf. SF#2037598)
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   520
     * @var string
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   521
     */
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   522
    var $encoding = 'utf-8';
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   523
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   524
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   525
     * Should keywords be linked?
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   526
     * @var boolean
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   527
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   528
    var $keyword_links = true;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   529
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   530
    /**
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   531
     * Currently loaded language file
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   532
     * @var string
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   533
     * @since 1.0.7.22
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   534
     */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   535
    var $loaded_language = '';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   536
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   537
    /**
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   538
     * Wether the caches needed for parsing are built or not
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   539
     *
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   540
     * @var bool
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   541
     * @since 1.0.8
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   542
     */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   543
    var $parse_cache_built = false;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   544
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   545
    /**
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   546
     * Work around for Suhosin Patch with disabled /e modifier
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   547
     *
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   548
     * Note from suhosins author in config file:
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   549
     * <blockquote>
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   550
     *   The /e modifier inside <code>preg_replace()</code> allows code execution.
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   551
     *   Often it is the cause for remote code execution exploits. It is wise to
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   552
     *   deactivate this feature and test where in the application it is used.
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   553
     *   The developer using the /e modifier should be made aware that he should
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   554
     *   use <code>preg_replace_callback()</code> instead
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   555
     * </blockquote>
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   556
     *
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   557
     * @var array
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   558
     * @since 1.0.8
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   559
     */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   560
    var $_kw_replace_group = 0;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   561
    var $_rx_key = 0;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   562
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   563
    /**
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   564
     * some "callback parameters" for handle_multiline_regexps
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   565
     *
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   566
     * @since 1.0.8
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   567
     * @access private
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   568
     * @var string
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   569
     */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   570
    var $_hmr_before = '';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   571
    var $_hmr_replace = '';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   572
    var $_hmr_after = '';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   573
    var $_hmr_key = 0;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   574
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   575
    /**#@-*/
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   576
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   577
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   578
     * Creates a new GeSHi object, with source and language
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   579
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   580
     * @param string The source code to highlight
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   581
     * @param string The language to highlight the source with
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   582
     * @param string The path to the language file directory. <b>This
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   583
     *               is deprecated!</b> I've backported the auto path
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   584
     *               detection from the 1.1.X dev branch, so now it
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   585
     *               should be automatically set correctly. If you have
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   586
     *               renamed the language directory however, you will
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   587
     *               still need to set the path using this parameter or
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   588
     *               {@link GeSHi->set_language_path()}
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   589
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   590
     */
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   591
    function GeSHi($source = '', $language = '', $path = '') {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   592
        if (!empty($source)) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   593
            $this->set_source($source);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   594
        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   595
        if (!empty($language)) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   596
            $this->set_language($language);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   597
        }
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   598
        $this->set_language_path($path);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   599
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   600
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   601
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   602
     * Returns an error message associated with the last GeSHi operation,
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   603
     * or false if no error has occured
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   604
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   605
     * @return string|false An error message if there has been an error, else false
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   606
     * @since  1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   607
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   608
    function error() {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   609
        if ($this->error) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   610
            //Put some template variables for debugging here ...
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   611
            $debug_tpl_vars = array(
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   612
                '{LANGUAGE}' => $this->language,
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   613
                '{PATH}' => $this->language_path
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   614
            );
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   615
            $msg = str_replace(
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   616
                array_keys($debug_tpl_vars),
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   617
                array_values($debug_tpl_vars),
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   618
                $this->error_messages[$this->error]);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   619
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   620
            return "<br /><strong>GeSHi Error:</strong> $msg (code {$this->error})<br />";
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   621
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   622
        return false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   623
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   624
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   625
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   626
     * Gets a human-readable language name (thanks to Simon Patterson
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   627
     * for the idea :))
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   628
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   629
     * @return string The name for the current language
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   630
     * @since  1.0.2
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   631
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   632
    function get_language_name() {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   633
        if (GESHI_ERROR_NO_SUCH_LANG == $this->error) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   634
            return $this->language_data['LANG_NAME'] . ' (Unknown Language)';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   635
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   636
        return $this->language_data['LANG_NAME'];
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   637
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   638
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   639
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   640
     * Sets the source code for this object
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   641
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   642
     * @param string The source code to highlight
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   643
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   644
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   645
    function set_source($source) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   646
        $this->source = $source;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   647
        $this->highlight_extra_lines = array();
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   648
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   649
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   650
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   651
     * Sets the language for this object
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   652
     *
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   653
     * @note since 1.0.8 this function won't reset language-settings by default anymore!
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   654
     *       if you need this set $force_reset = true
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   655
     *
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   656
     * @param string The name of the language to use
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   657
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   658
     */
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   659
    function set_language($language, $force_reset = false) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   660
        if ($force_reset) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   661
            $this->loaded_language = false;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   662
        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   663
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   664
        //Clean up the language name to prevent malicious code injection
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   665
        $language = preg_replace('#[^a-zA-Z0-9\-_]#', '', $language);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   666
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   667
        $language = strtolower($language);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   668
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   669
        //Retreive the full filename
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   670
        $file_name = $this->language_path . $language . '.php';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   671
        if ($file_name == $this->loaded_language) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   672
            // this language is already loaded!
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   673
            return;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   674
        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   675
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   676
        $this->language = $language;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   677
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   678
        $this->error = false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   679
        $this->strict_mode = GESHI_NEVER;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   680
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   681
        //Check if we can read the desired file
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   682
        if (!is_readable($file_name)) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   683
            $this->error = GESHI_ERROR_NO_SUCH_LANG;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   684
            return;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   685
        }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   686
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   687
        // Load the language for parsing
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   688
        $this->load_language($file_name);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   689
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   690
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   691
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   692
     * Sets the path to the directory containing the language files. Note
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   693
     * that this path is relative to the directory of the script that included
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   694
     * geshi.php, NOT geshi.php itself.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   695
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   696
     * @param string The path to the language directory
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   697
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   698
     * @deprecated The path to the language files should now be automatically
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   699
     *             detected, so this method should no longer be needed. The
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   700
     *             1.1.X branch handles manual setting of the path differently
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   701
     *             so this method will disappear in 1.2.0.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   702
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   703
    function set_language_path($path) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   704
        if(strpos($path,':')) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   705
            //Security Fix to prevent external directories using fopen wrappers.
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   706
            if(DIRECTORY_SEPARATOR == "\\") {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   707
                if(!preg_match('#^[a-zA-Z]:#', $path) || false !== strpos($path, ':', 2)) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   708
                    return;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   709
                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   710
            } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   711
                return;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   712
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   713
        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   714
        if(preg_match('#[^/a-zA-Z0-9_\.\-\\\s:]#', $path)) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   715
            //Security Fix to prevent external directories using fopen wrappers.
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   716
            return;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   717
        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   718
        if(GESHI_SECURITY_PARANOID && false !== strpos($path, '/.')) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   719
            //Security Fix to prevent external directories using fopen wrappers.
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   720
            return;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   721
        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   722
        if(GESHI_SECURITY_PARANOID && false !== strpos($path, '..')) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   723
            //Security Fix to prevent external directories using fopen wrappers.
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   724
            return;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   725
        }
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   726
        if ($path) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   727
            $this->language_path = ('/' == $path[strlen($path) - 1]) ? $path : $path . '/';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   728
            $this->set_language($this->language); // otherwise set_language_path has no effect
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   729
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   730
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   731
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   732
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   733
     * Sets the type of header to be used.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   734
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   735
     * If GESHI_HEADER_DIV is used, the code is surrounded in a "div".This
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   736
     * means more source code but more control over tab width and line-wrapping.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   737
     * GESHI_HEADER_PRE means that a "pre" is used - less source, but less
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   738
     * control. Default is GESHI_HEADER_PRE.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   739
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   740
     * From 1.0.7.2, you can use GESHI_HEADER_NONE to specify that no header code
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   741
     * should be outputted.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   742
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   743
     * @param int The type of header to be used
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   744
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   745
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   746
    function set_header_type($type) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   747
        //Check if we got a valid header type
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   748
        if (!in_array($type, array(GESHI_HEADER_NONE, GESHI_HEADER_DIV,
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   749
            GESHI_HEADER_PRE, GESHI_HEADER_PRE_VALID, GESHI_HEADER_PRE_TABLE))) {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   750
            $this->error = GESHI_ERROR_INVALID_HEADER_TYPE;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   751
            return;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   752
        }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   753
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   754
        //Set that new header type
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   755
        $this->header_type = $type;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   756
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   757
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   758
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   759
     * Sets the styles for the code that will be outputted
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   760
     * when this object is parsed. The style should be a
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   761
     * string of valid stylesheet declarations
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   762
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   763
     * @param string  The overall style for the outputted code block
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   764
     * @param boolean Whether to merge the styles with the current styles or not
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   765
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   766
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   767
    function set_overall_style($style, $preserve_defaults = false) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   768
        if (!$preserve_defaults) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   769
            $this->overall_style = $style;
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   770
        } else {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   771
            $this->overall_style .= $style;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   772
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   773
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   774
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   775
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   776
     * Sets the overall classname for this block of code. This
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   777
     * class can then be used in a stylesheet to style this object's
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   778
     * output
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   779
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   780
     * @param string The class name to use for this block of code
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   781
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   782
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   783
    function set_overall_class($class) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   784
        $this->overall_class = $class;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   785
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   786
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   787
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   788
     * Sets the overall id for this block of code. This id can then
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   789
     * be used in a stylesheet to style this object's output
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   790
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   791
     * @param string The ID to use for this block of code
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   792
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   793
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   794
    function set_overall_id($id) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   795
        $this->overall_id = $id;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   796
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   797
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   798
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   799
     * Sets whether CSS classes should be used to highlight the source. Default
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   800
     * is off, calling this method with no arguments will turn it on
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   801
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   802
     * @param boolean Whether to turn classes on or not
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   803
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   804
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   805
    function enable_classes($flag = true) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   806
        $this->use_classes = ($flag) ? true : false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   807
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   808
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   809
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   810
     * Sets the style for the actual code. This should be a string
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   811
     * containing valid stylesheet declarations. If $preserve_defaults is
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   812
     * true, then styles are merged with the default styles, with the
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   813
     * user defined styles having priority
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   814
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   815
     * Note: Use this method to override any style changes you made to
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   816
     * the line numbers if you are using line numbers, else the line of
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   817
     * code will have the same style as the line number! Consult the
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   818
     * GeSHi documentation for more information about this.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   819
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   820
     * @param string  The style to use for actual code
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   821
     * @param boolean Whether to merge the current styles with the new styles
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   822
     * @since 1.0.2
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   823
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   824
    function set_code_style($style, $preserve_defaults = false) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   825
        if (!$preserve_defaults) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   826
            $this->code_style = $style;
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   827
        } else {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   828
            $this->code_style .= $style;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   829
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   830
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   831
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   832
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   833
     * Sets the styles for the line numbers.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   834
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   835
     * @param string The style for the line numbers that are "normal"
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   836
     * @param string|boolean If a string, this is the style of the line
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   837
     *        numbers that are "fancy", otherwise if boolean then this
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   838
     *        defines whether the normal styles should be merged with the
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   839
     *        new normal styles or not
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   840
     * @param boolean If set, is the flag for whether to merge the "fancy"
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   841
     *        styles with the current styles or not
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   842
     * @since 1.0.2
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   843
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   844
    function set_line_style($style1, $style2 = '', $preserve_defaults = false) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   845
        //Check if we got 2 or three parameters
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   846
        if (is_bool($style2)) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   847
            $preserve_defaults = $style2;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   848
            $style2 = '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   849
        }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   850
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   851
        //Actually set the new styles
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   852
        if (!$preserve_defaults) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   853
            $this->line_style1 = $style1;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   854
            $this->line_style2 = $style2;
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   855
        } else {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   856
            $this->line_style1 .= $style1;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   857
            $this->line_style2 .= $style2;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   858
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   859
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   860
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   861
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   862
     * Sets whether line numbers should be displayed.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   863
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   864
     * Valid values for the first parameter are:
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   865
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   866
     *  - GESHI_NO_LINE_NUMBERS: Line numbers will not be displayed
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   867
     *  - GESHI_NORMAL_LINE_NUMBERS: Line numbers will be displayed
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   868
     *  - GESHI_FANCY_LINE_NUMBERS: Fancy line numbers will be displayed
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   869
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   870
     * For fancy line numbers, the second parameter is used to signal which lines
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   871
     * are to be fancy. For example, if the value of this parameter is 5 then every
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   872
     * 5th line will be fancy.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   873
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   874
     * @param int How line numbers should be displayed
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   875
     * @param int Defines which lines are fancy
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   876
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   877
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   878
    function enable_line_numbers($flag, $nth_row = 5) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   879
        if (GESHI_NO_LINE_NUMBERS != $flag && GESHI_NORMAL_LINE_NUMBERS != $flag
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   880
            && GESHI_FANCY_LINE_NUMBERS != $flag) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   881
            $this->error = GESHI_ERROR_INVALID_LINE_NUMBER_TYPE;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   882
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   883
        $this->line_numbers = $flag;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   884
        $this->line_nth_row = $nth_row;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   885
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   886
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   887
    /**
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   888
     * Sets wether spans and other HTML markup generated by GeSHi can
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   889
     * span over multiple lines or not. Defaults to true to reduce overhead.
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   890
     * Set it to false if you want to manipulate the output or manually display
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   891
     * the code in an ordered list.
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   892
     *
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   893
     * @param boolean Wether multiline spans are allowed or not
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   894
     * @since 1.0.7.22
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   895
     */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   896
    function enable_multiline_span($flag) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   897
        $this->allow_multiline_span = (bool) $flag;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   898
    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   899
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   900
    /**
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   901
     * Get current setting for multiline spans, see GeSHi->enable_multiline_span().
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   902
     *
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   903
     * @see enable_multiline_span
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   904
     * @return bool
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   905
     */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   906
    function get_multiline_span() {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   907
        return $this->allow_multiline_span;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   908
    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   909
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   910
    /**
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   911
     * Sets the style for a keyword group. If $preserve_defaults is
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   912
     * true, then styles are merged with the default styles, with the
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   913
     * user defined styles having priority
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   914
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   915
     * @param int     The key of the keyword group to change the styles of
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   916
     * @param string  The style to make the keywords
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   917
     * @param boolean Whether to merge the new styles with the old or just
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   918
     *                to overwrite them
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   919
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   920
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   921
    function set_keyword_group_style($key, $style, $preserve_defaults = false) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   922
        //Set the style for this keyword group
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   923
        if (!$preserve_defaults) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   924
            $this->language_data['STYLES']['KEYWORDS'][$key] = $style;
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   925
        } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   926
            $this->language_data['STYLES']['KEYWORDS'][$key] .= $style;
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   927
        }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   928
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   929
        //Update the lexic permissions
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   930
        if (!isset($this->lexic_permissions['KEYWORDS'][$key])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   931
            $this->lexic_permissions['KEYWORDS'][$key] = true;
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   932
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   933
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   934
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   935
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   936
     * Turns highlighting on/off for a keyword group
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   937
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   938
     * @param int     The key of the keyword group to turn on or off
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   939
     * @param boolean Whether to turn highlighting for that group on or off
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   940
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   941
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   942
    function set_keyword_group_highlighting($key, $flag = true) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   943
        $this->lexic_permissions['KEYWORDS'][$key] = ($flag) ? true : false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   944
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   945
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   946
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   947
     * Sets the styles for comment groups.  If $preserve_defaults is
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   948
     * true, then styles are merged with the default styles, with the
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   949
     * user defined styles having priority
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   950
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   951
     * @param int     The key of the comment group to change the styles of
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   952
     * @param string  The style to make the comments
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   953
     * @param boolean Whether to merge the new styles with the old or just
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   954
     *                to overwrite them
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   955
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   956
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   957
    function set_comments_style($key, $style, $preserve_defaults = false) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   958
        if (!$preserve_defaults) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   959
            $this->language_data['STYLES']['COMMENTS'][$key] = $style;
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   960
        } else {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   961
            $this->language_data['STYLES']['COMMENTS'][$key] .= $style;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   962
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   963
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   964
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   965
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   966
     * Turns highlighting on/off for comment groups
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   967
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   968
     * @param int     The key of the comment group to turn on or off
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   969
     * @param boolean Whether to turn highlighting for that group on or off
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   970
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   971
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   972
    function set_comments_highlighting($key, $flag = true) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   973
        $this->lexic_permissions['COMMENTS'][$key] = ($flag) ? true : false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   974
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   975
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   976
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   977
     * Sets the styles for escaped characters. If $preserve_defaults is
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   978
     * true, then styles are merged with the default styles, with the
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   979
     * user defined styles having priority
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   980
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   981
     * @param string  The style to make the escape characters
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   982
     * @param boolean Whether to merge the new styles with the old or just
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   983
     *                to overwrite them
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   984
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   985
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   986
    function set_escape_characters_style($style, $preserve_defaults = false) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   987
        if (!$preserve_defaults) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   988
            $this->language_data['STYLES']['ESCAPE_CHAR'][0] = $style;
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
   989
        } else {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   990
            $this->language_data['STYLES']['ESCAPE_CHAR'][0] .= $style;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   991
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   992
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   993
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   994
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   995
     * Turns highlighting on/off for escaped characters
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   996
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   997
     * @param boolean Whether to turn highlighting for escape characters on or off
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   998
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   999
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1000
    function set_escape_characters_highlighting($flag = true) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1001
        $this->lexic_permissions['ESCAPE_CHAR'] = ($flag) ? true : false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1002
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1003
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1004
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1005
     * Sets the styles for brackets. If $preserve_defaults is
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1006
     * true, then styles are merged with the default styles, with the
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1007
     * user defined styles having priority
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1008
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1009
     * This method is DEPRECATED: use set_symbols_style instead.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1010
     * This method will be removed in 1.2.X
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1011
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1012
     * @param string  The style to make the brackets
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1013
     * @param boolean Whether to merge the new styles with the old or just
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1014
     *                to overwrite them
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1015
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1016
     * @deprecated In favour of set_symbols_style
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1017
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1018
    function set_brackets_style($style, $preserve_defaults = false) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1019
        if (!$preserve_defaults) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1020
            $this->language_data['STYLES']['BRACKETS'][0] = $style;
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1021
        } else {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1022
            $this->language_data['STYLES']['BRACKETS'][0] .= $style;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1023
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1024
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1025
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1026
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1027
     * Turns highlighting on/off for brackets
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1028
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1029
     * This method is DEPRECATED: use set_symbols_highlighting instead.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1030
     * This method will be remove in 1.2.X
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1031
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1032
     * @param boolean Whether to turn highlighting for brackets on or off
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1033
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1034
     * @deprecated In favour of set_symbols_highlighting
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1035
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1036
    function set_brackets_highlighting($flag) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1037
        $this->lexic_permissions['BRACKETS'] = ($flag) ? true : false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1038
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1039
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1040
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1041
     * Sets the styles for symbols. If $preserve_defaults is
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1042
     * true, then styles are merged with the default styles, with the
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1043
     * user defined styles having priority
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1044
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1045
     * @param string  The style to make the symbols
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1046
     * @param boolean Whether to merge the new styles with the old or just
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1047
     *                to overwrite them
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1048
     * @param int     Tells the group of symbols for which style should be set.
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1049
     * @since 1.0.1
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1050
     */
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1051
    function set_symbols_style($style, $preserve_defaults = false, $group = 0) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1052
        // Update the style of symbols
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1053
        if (!$preserve_defaults) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1054
            $this->language_data['STYLES']['SYMBOLS'][$group] = $style;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1055
        } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1056
            $this->language_data['STYLES']['SYMBOLS'][$group] .= $style;
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1057
        }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1058
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1059
        // For backward compatibility
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1060
        if (0 == $group) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1061
            $this->set_brackets_style ($style, $preserve_defaults);
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1062
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1063
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1064
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1065
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1066
     * Turns highlighting on/off for symbols
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1067
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1068
     * @param boolean Whether to turn highlighting for symbols on or off
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1069
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1070
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1071
    function set_symbols_highlighting($flag) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1072
        // Update lexic permissions for this symbol group
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1073
        $this->lexic_permissions['SYMBOLS'] = ($flag) ? true : false;
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1074
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1075
        // For backward compatibility
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1076
        $this->set_brackets_highlighting ($flag);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1077
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1078
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1079
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1080
     * Sets the styles for strings. If $preserve_defaults is
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1081
     * true, then styles are merged with the default styles, with the
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1082
     * user defined styles having priority
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1083
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1084
     * @param string  The style to make the escape characters
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1085
     * @param boolean Whether to merge the new styles with the old or just
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1086
     *                to overwrite them
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1087
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1088
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1089
    function set_strings_style($style, $preserve_defaults = false) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1090
        if (!$preserve_defaults) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1091
            $this->language_data['STYLES']['STRINGS'][0] = $style;
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1092
        } else {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1093
            $this->language_data['STYLES']['STRINGS'][0] .= $style;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1094
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1095
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1096
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1097
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1098
     * Turns highlighting on/off for strings
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1099
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1100
     * @param boolean Whether to turn highlighting for strings on or off
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1101
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1102
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1103
    function set_strings_highlighting($flag) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1104
        $this->lexic_permissions['STRINGS'] = ($flag) ? true : false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1105
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1106
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1107
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1108
     * Sets the styles for numbers. If $preserve_defaults is
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1109
     * true, then styles are merged with the default styles, with the
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1110
     * user defined styles having priority
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1111
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1112
     * @param string  The style to make the numbers
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1113
     * @param boolean Whether to merge the new styles with the old or just
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1114
     *                to overwrite them
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1115
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1116
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1117
    function set_numbers_style($style, $preserve_defaults = false) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1118
        if (!$preserve_defaults) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1119
            $this->language_data['STYLES']['NUMBERS'][0] = $style;
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1120
        } else {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1121
            $this->language_data['STYLES']['NUMBERS'][0] .= $style;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1122
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1123
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1124
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1125
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1126
     * Turns highlighting on/off for numbers
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1127
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1128
     * @param boolean Whether to turn highlighting for numbers on or off
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1129
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1130
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1131
    function set_numbers_highlighting($flag) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1132
        $this->lexic_permissions['NUMBERS'] = ($flag) ? true : false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1133
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1134
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1135
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1136
     * Sets the styles for methods. $key is a number that references the
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1137
     * appropriate "object splitter" - see the language file for the language
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1138
     * you are highlighting to get this number. If $preserve_defaults is
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1139
     * true, then styles are merged with the default styles, with the
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1140
     * user defined styles having priority
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1141
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1142
     * @param int     The key of the object splitter to change the styles of
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1143
     * @param string  The style to make the methods
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1144
     * @param boolean Whether to merge the new styles with the old or just
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1145
     *                to overwrite them
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1146
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1147
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1148
    function set_methods_style($key, $style, $preserve_defaults = false) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1149
        if (!$preserve_defaults) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1150
            $this->language_data['STYLES']['METHODS'][$key] = $style;
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1151
        } else {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1152
            $this->language_data['STYLES']['METHODS'][$key] .= $style;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1153
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1154
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1155
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1156
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1157
     * Turns highlighting on/off for methods
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1158
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1159
     * @param boolean Whether to turn highlighting for methods on or off
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1160
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1161
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1162
    function set_methods_highlighting($flag) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1163
        $this->lexic_permissions['METHODS'] = ($flag) ? true : false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1164
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1165
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1166
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1167
     * Sets the styles for regexps. If $preserve_defaults is
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1168
     * true, then styles are merged with the default styles, with the
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1169
     * user defined styles having priority
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1170
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1171
     * @param string  The style to make the regular expression matches
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1172
     * @param boolean Whether to merge the new styles with the old or just
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1173
     *                to overwrite them
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1174
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1175
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1176
    function set_regexps_style($key, $style, $preserve_defaults = false) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1177
        if (!$preserve_defaults) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1178
            $this->language_data['STYLES']['REGEXPS'][$key] = $style;
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1179
        } else {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1180
            $this->language_data['STYLES']['REGEXPS'][$key] .= $style;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1181
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1182
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1183
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1184
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1185
     * Turns highlighting on/off for regexps
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1186
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1187
     * @param int     The key of the regular expression group to turn on or off
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1188
     * @param boolean Whether to turn highlighting for the regular expression group on or off
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1189
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1190
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1191
    function set_regexps_highlighting($key, $flag) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1192
        $this->lexic_permissions['REGEXPS'][$key] = ($flag) ? true : false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1193
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1194
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1195
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1196
     * Sets whether a set of keywords are checked for in a case sensitive manner
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1197
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1198
     * @param int The key of the keyword group to change the case sensitivity of
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1199
     * @param boolean Whether to check in a case sensitive manner or not
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1200
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1201
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1202
    function set_case_sensitivity($key, $case) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1203
        $this->language_data['CASE_SENSITIVE'][$key] = ($case) ? true : false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1204
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1205
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1206
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1207
     * Sets the case that keywords should use when found. Use the constants:
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1208
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1209
     *  - GESHI_CAPS_NO_CHANGE: leave keywords as-is
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1210
     *  - GESHI_CAPS_UPPER: convert all keywords to uppercase where found
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1211
     *  - GESHI_CAPS_LOWER: convert all keywords to lowercase where found
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1212
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1213
     * @param int A constant specifying what to do with matched keywords
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1214
     * @since 1.0.1
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1215
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1216
    function set_case_keywords($case) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1217
        if (in_array($case, array(
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1218
            GESHI_CAPS_NO_CHANGE, GESHI_CAPS_UPPER, GESHI_CAPS_LOWER))) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1219
            $this->language_data['CASE_KEYWORDS'] = $case;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1220
        }
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1221
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1222
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1223
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1224
     * Sets how many spaces a tab is substituted for
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1225
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1226
     * Widths below zero are ignored
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1227
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1228
     * @param int The tab width
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1229
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1230
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1231
    function set_tab_width($width) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1232
        $this->tab_width = intval($width);
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1233
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1234
        //Check if it fit's the constraints:
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1235
        if ($this->tab_width < 1) {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1236
            //Return it to the default
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1237
            $this->tab_width = 8;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1238
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1239
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1240
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1241
    /**
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1242
     * Sets whether or not to use tab-stop width specifed by language
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1243
     *
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1244
     * @param boolean Whether to use language-specific tab-stop widths
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1245
     * @since 1.0.7.20
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1246
     */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1247
    function set_use_language_tab_width($use) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1248
        $this->use_language_tab_width = (bool) $use;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1249
    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1250
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1251
    /**
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1252
     * Returns the tab width to use, based on the current language and user
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1253
     * preference
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1254
     *
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1255
     * @return int Tab width
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1256
     * @since 1.0.7.20
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1257
     */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1258
    function get_real_tab_width() {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1259
        if (!$this->use_language_tab_width ||
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1260
            !isset($this->language_data['TAB_WIDTH'])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1261
            return $this->tab_width;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1262
        } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1263
            return $this->language_data['TAB_WIDTH'];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1264
        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1265
    }
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1266
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1267
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1268
     * Enables/disables strict highlighting. Default is off, calling this
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1269
     * method without parameters will turn it on. See documentation
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1270
     * for more details on strict mode and where to use it.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1271
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1272
     * @param boolean Whether to enable strict mode or not
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1273
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1274
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1275
    function enable_strict_mode($mode = true) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1276
        if (GESHI_MAYBE == $this->language_data['STRICT_MODE_APPLIES']) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1277
            $this->strict_mode = ($mode) ? GESHI_ALWAYS : GESHI_NEVER;
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1278
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1279
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1280
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1281
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1282
     * Disables all highlighting
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1283
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1284
     * @since 1.0.0
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1285
     * @todo  Rewrite with array traversal
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1286
     * @deprecated In favour of enable_highlighting
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1287
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1288
    function disable_highlighting() {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1289
        $this->enable_highlighting(false);
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1290
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1291
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1292
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1293
     * Enables all highlighting
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1294
     *
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1295
     * The optional flag parameter was added in version 1.0.7.21 and can be used
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1296
     * to enable (true) or disable (false) all highlighting.
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1297
     *
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1298
     * @since 1.0.0
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1299
     * @param boolean A flag specifying whether to enable or disable all highlighting
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1300
     * @todo  Rewrite with array traversal
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1301
     */
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1302
    function enable_highlighting($flag = true) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1303
        $flag = $flag ? true : false;
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1304
        foreach ($this->lexic_permissions as $key => $value) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1305
            if (is_array($value)) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1306
                foreach ($value as $k => $v) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1307
                    $this->lexic_permissions[$key][$k] = $flag;
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1308
                }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1309
            } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1310
                $this->lexic_permissions[$key] = $flag;
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1311
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1312
        }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1313
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1314
        // Context blocks
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1315
        $this->enable_important_blocks = $flag;
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1316
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1317
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1318
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1319
     * Given a file extension, this method returns either a valid geshi language
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1320
     * name, or the empty string if it couldn't be found
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1321
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1322
     * @param string The extension to get a language name for
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1323
     * @param array  A lookup array to use instead of the default one
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1324
     * @since 1.0.5
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1325
     * @todo Re-think about how this method works (maybe make it private and/or make it
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1326
     *       a extension->lang lookup?)
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1327
     * @todo static?
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1328
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1329
    function get_language_name_from_extension( $extension, $lookup = array() ) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1330
        if ( !is_array($lookup) || empty($lookup)) {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1331
            $lookup = array(
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1332
                'actionscript' => array('as'),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1333
                'ada' => array('a', 'ada', 'adb', 'ads'),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1334
                'apache' => array('conf'),
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1335
                'asm' => array('ash', 'asm', 'inc'),
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1336
                'asp' => array('asp'),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1337
                'bash' => array('sh'),
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1338
                'bf' => array('bf'),
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1339
                'c' => array('c', 'h'),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1340
                'c_mac' => array('c', 'h'),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1341
                'caddcl' => array(),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1342
                'cadlisp' => array(),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1343
                'cdfg' => array('cdfg'),
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1344
                'cobol' => array('cbl'),
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1345
                'cpp' => array('cpp', 'hpp', 'C', 'H', 'CPP', 'HPP'),
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1346
                'csharp' => array('cs'),
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1347
                'css' => array('css'),
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1348
                'd' => array('d'),
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1349
                'delphi' => array('dpk', 'dpr', 'pp', 'pas'),
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1350
                'diff' => array('diff', 'patch'),
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1351
                'dos' => array('bat', 'cmd'),
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1352
                'gettext' => array('po', 'pot'),
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1353
                'gml' => array('gml'),
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1354
                'gnuplot' => array('plt'),
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1355
                'groovy' => array('groovy'),
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1356
                'haskell' => array('hs'),
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1357
                'html4strict' => array('html', 'htm'),
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1358
                'ini' => array('ini', 'desktop'),
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1359
                'java' => array('java'),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1360
                'javascript' => array('js'),
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1361
                'klonec' => array('kl1'),
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1362
                'klonecpp' => array('klx'),
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1363
                'latex' => array('tex'),
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1364
                'lisp' => array('lisp'),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1365
                'lua' => array('lua'),
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1366
                'matlab' => array('m'),
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1367
                'mpasm' => array(),
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1368
                'mysql' => array('sql'),
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1369
                'nsis' => array(),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1370
                'objc' => array(),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1371
                'oobas' => array(),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1372
                'oracle8' => array(),
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1373
                'oracle10' => array(),
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1374
                'pascal' => array('pas'),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1375
                'perl' => array('pl', 'pm'),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1376
                'php' => array('php', 'php5', 'phtml', 'phps'),
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1377
                'povray' => array('pov'),
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1378
                'providex' => array('pvc', 'pvx'),
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1379
                'prolog' => array('pl'),
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1380
                'python' => array('py'),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1381
                'qbasic' => array('bi'),
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1382
                'reg' => array('reg'),
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1383
                'ruby' => array('rb'),
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1384
                'sas' => array('sas'),
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1385
                'scala' => array('scala'),
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1386
                'scheme' => array('scm'),
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1387
                'scilab' => array('sci'),
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1388
                'smalltalk' => array('st'),
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1389
                'smarty' => array(),
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1390
                'tcl' => array('tcl'),
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1391
                'vb' => array('bas'),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1392
                'vbnet' => array(),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1393
                'visualfoxpro' => array(),
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1394
                'whitespace' => array('ws'),
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1395
                'xml' => array('xml', 'svg'),
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1396
                'z80' => array('z80', 'asm', 'inc')
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1397
            );
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1398
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1399
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1400
        foreach ($lookup as $lang => $extensions) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1401
            if (in_array($extension, $extensions)) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1402
                return $lang;
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1403
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1404
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1405
        return '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1406
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1407
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1408
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1409
     * Given a file name, this method loads its contents in, and attempts
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1410
     * to set the language automatically. An optional lookup table can be
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1411
     * passed for looking up the language name. If not specified a default
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1412
     * table is used
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1413
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1414
     * The language table is in the form
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1415
     * <pre>array(
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1416
     *   'lang_name' => array('extension', 'extension', ...),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1417
     *   'lang_name' ...
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1418
     * );</pre>
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1419
     *
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1420
     * @param string The filename to load the source from
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1421
     * @param array  A lookup array to use instead of the default one
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1422
     * @todo Complete rethink of this and above method
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1423
     * @since 1.0.5
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1424
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1425
    function load_from_file($file_name, $lookup = array()) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1426
        if (is_readable($file_name)) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1427
            $this->set_source(file_get_contents($file_name));
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1428
            $this->set_language($this->get_language_name_from_extension(substr(strrchr($file_name, '.'), 1), $lookup));
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1429
        } else {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1430
            $this->error = GESHI_ERROR_FILE_NOT_READABLE;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1431
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1432
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1433
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1434
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1435
     * Adds a keyword to a keyword group for highlighting
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1436
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1437
     * @param int    The key of the keyword group to add the keyword to
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1438
     * @param string The word to add to the keyword group
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1439
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1440
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1441
    function add_keyword($key, $word) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1442
        if (!in_array($word, $this->language_data['KEYWORDS'][$key])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1443
            $this->language_data['KEYWORDS'][$key][] = $word;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1444
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1445
            //NEW in 1.0.8 don't recompile the whole optimized regexp, simply append it
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1446
            if ($this->parse_cache_built) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1447
                $subkey = count($this->language_data['CACHED_KEYWORD_LISTS'][$key]) - 1;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1448
                $this->language_data['CACHED_KEYWORD_LISTS'][$key][$subkey] .= '|' . preg_quote($word, '/');
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1449
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1450
        }
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1451
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1452
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1453
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1454
     * Removes a keyword from a keyword group
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1455
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1456
     * @param int    The key of the keyword group to remove the keyword from
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1457
     * @param string The word to remove from the keyword group
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1458
     * @param bool   Wether to automatically recompile the optimized regexp list or not.
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1459
     *               Note: if you set this to false and @see GeSHi->parse_code() was already called once,
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1460
     *               for the current language, you have to manually call @see GeSHi->optimize_keyword_group()
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1461
     *               or the removed keyword will stay in cache and still be highlighted! On the other hand
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1462
     *               it might be too expensive to recompile the regexp list for every removal if you want to
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1463
     *               remove a lot of keywords.
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1464
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1465
     */
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1466
    function remove_keyword($key, $word, $recompile = true) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1467
        $key_to_remove = array_search($word, $this->language_data['KEYWORDS'][$key]);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1468
        if ($key_to_remove !== false) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1469
            unset($this->language_data['KEYWORDS'][$key][$key_to_remove]);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1470
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1471
            //NEW in 1.0.8, optionally recompile keyword group
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1472
            if ($recompile && $this->parse_cache_built) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1473
                $this->optimize_keyword_group($key);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1474
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1475
        }
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1476
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1477
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1478
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1479
     * Creates a new keyword group
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1480
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1481
     * @param int    The key of the keyword group to create
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1482
     * @param string The styles for the keyword group
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1483
     * @param boolean Whether the keyword group is case sensitive ornot
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1484
     * @param array  The words to use for the keyword group
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1485
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1486
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1487
    function add_keyword_group($key, $styles, $case_sensitive = true, $words = array()) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1488
        $words = (array) $words;
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1489
        if  (empty($words)) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1490
            // empty word lists mess up highlighting
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1491
            return false;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1492
        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1493
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1494
        //Add the new keyword group internally
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1495
        $this->language_data['KEYWORDS'][$key] = $words;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1496
        $this->lexic_permissions['KEYWORDS'][$key] = true;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1497
        $this->language_data['CASE_SENSITIVE'][$key] = $case_sensitive;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1498
        $this->language_data['STYLES']['KEYWORDS'][$key] = $styles;
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1499
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1500
        //NEW in 1.0.8, cache keyword regexp
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1501
        if ($this->parse_cache_built) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1502
            $this->optimize_keyword_group($key);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1503
        }
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1504
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1505
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1506
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1507
     * Removes a keyword group
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1508
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1509
     * @param int    The key of the keyword group to remove
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1510
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1511
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1512
    function remove_keyword_group ($key) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1513
        //Remove the keyword group internally
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1514
        unset($this->language_data['KEYWORDS'][$key]);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1515
        unset($this->lexic_permissions['KEYWORDS'][$key]);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1516
        unset($this->language_data['CASE_SENSITIVE'][$key]);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1517
        unset($this->language_data['STYLES']['KEYWORDS'][$key]);
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1518
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1519
        //NEW in 1.0.8
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1520
        unset($this->language_data['CACHED_KEYWORD_LISTS'][$key]);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1521
    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1522
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1523
    /**
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1524
     * compile optimized regexp list for keyword group
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1525
     *
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1526
     * @param int   The key of the keyword group to compile & optimize
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1527
     * @since 1.0.8
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1528
     */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1529
    function optimize_keyword_group($key) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1530
        $this->language_data['CACHED_KEYWORD_LISTS'][$key] =
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1531
            $this->optimize_regexp_list($this->language_data['KEYWORDS'][$key]);
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1532
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1533
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1534
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1535
     * Sets the content of the header block
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1536
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1537
     * @param string The content of the header block
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1538
     * @since 1.0.2
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1539
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1540
    function set_header_content($content) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1541
        $this->header_content = $content;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1542
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1543
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1544
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1545
     * Sets the content of the footer block
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1546
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1547
     * @param string The content of the footer block
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1548
     * @since 1.0.2
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1549
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1550
    function set_footer_content($content) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1551
        $this->footer_content = $content;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1552
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1553
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1554
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1555
     * Sets the style for the header content
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1556
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1557
     * @param string The style for the header content
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1558
     * @since 1.0.2
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1559
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1560
    function set_header_content_style($style) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1561
        $this->header_content_style = $style;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1562
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1563
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1564
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1565
     * Sets the style for the footer content
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1566
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1567
     * @param string The style for the footer content
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1568
     * @since 1.0.2
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1569
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1570
    function set_footer_content_style($style) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1571
        $this->footer_content_style = $style;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1572
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1573
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1574
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1575
     * Sets whether to force a surrounding block around
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1576
     * the highlighted code or not
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1577
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1578
     * @param boolean Tells whether to enable or disable this feature
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1579
     * @since 1.0.7.20
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1580
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1581
    function enable_inner_code_block($flag) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1582
        $this->force_code_block = (bool)$flag;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1583
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1584
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1585
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1586
     * Sets the base URL to be used for keywords
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1587
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1588
     * @param int The key of the keyword group to set the URL for
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1589
     * @param string The URL to set for the group. If {FNAME} is in
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1590
     *               the url somewhere, it is replaced by the keyword
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1591
     *               that the URL is being made for
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1592
     * @since 1.0.2
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1593
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1594
    function set_url_for_keyword_group($group, $url) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1595
        $this->language_data['URLS'][$group] = $url;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1596
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1597
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1598
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1599
     * Sets styles for links in code
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1600
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1601
     * @param int A constant that specifies what state the style is being
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1602
     *            set for - e.g. :hover or :visited
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1603
     * @param string The styles to use for that state
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1604
     * @since 1.0.2
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1605
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1606
    function set_link_styles($type, $styles) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1607
        $this->link_styles[$type] = $styles;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1608
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1609
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1610
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1611
     * Sets the target for links in code
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1612
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1613
     * @param string The target for links in the code, e.g. _blank
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1614
     * @since 1.0.3
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1615
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1616
    function set_link_target($target) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1617
        if (!$target) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1618
            $this->link_target = '';
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1619
        } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1620
            $this->link_target = ' target="' . $target . '"';
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1621
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1622
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1623
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1624
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1625
     * Sets styles for important parts of the code
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1626
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1627
     * @param string The styles to use on important parts of the code
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1628
     * @since 1.0.2
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1629
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1630
    function set_important_styles($styles) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1631
        $this->important_styles = $styles;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1632
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1633
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1634
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1635
     * Sets whether context-important blocks are highlighted
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1636
     *
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1637
     * @param boolean Tells whether to enable or disable highlighting of important blocks
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1638
     * @todo REMOVE THIS SHIZ FROM GESHI!
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1639
     * @deprecated
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1640
     * @since 1.0.2
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1641
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1642
    function enable_important_blocks($flag) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1643
        $this->enable_important_blocks = ( $flag ) ? true : false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1644
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1645
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1646
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1647
     * Whether CSS IDs should be added to each line
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1648
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1649
     * @param boolean If true, IDs will be added to each line.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1650
     * @since 1.0.2
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1651
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1652
    function enable_ids($flag = true) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1653
        $this->add_ids = ($flag) ? true : false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1654
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1655
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1656
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1657
     * Specifies which lines to highlight extra
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1658
     *
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1659
     * The extra style parameter was added in 1.0.7.21.
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1660
     *
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1661
     * @param mixed An array of line numbers to highlight, or just a line
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1662
     *              number on its own.
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1663
     * @param string A string specifying the style to use for this line.
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1664
     *              If null is specified, the default style is used.
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1665
     *              If false is specified, the line will be removed from
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1666
     *              special highlighting
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1667
     * @since 1.0.2
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1668
     * @todo  Some data replication here that could be cut down on
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1669
     */
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1670
    function highlight_lines_extra($lines, $style = null) {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1671
        if (is_array($lines)) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1672
            //Split up the job using single lines at a time
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1673
            foreach ($lines as $line) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1674
                $this->highlight_lines_extra($line, $style);
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1675
            }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1676
        } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1677
            //Mark the line as being highlighted specially
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1678
            $lines = intval($lines);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1679
            $this->highlight_extra_lines[$lines] = $lines;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1680
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1681
            //Decide on which style to use
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1682
            if ($style === null) { //Check if we should use default style
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1683
                unset($this->highlight_extra_lines_styles[$lines]);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1684
            } else if ($style === false) { //Check if to remove this line
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1685
                unset($this->highlight_extra_lines[$lines]);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1686
                unset($this->highlight_extra_lines_styles[$lines]);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1687
            } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1688
                $this->highlight_extra_lines_styles[$lines] = $style;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1689
            }
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1690
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1691
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1692
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1693
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1694
     * Sets the style for extra-highlighted lines
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1695
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1696
     * @param string The style for extra-highlighted lines
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1697
     * @since 1.0.2
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1698
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1699
    function set_highlight_lines_extra_style($styles) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1700
        $this->highlight_extra_lines_style = $styles;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1701
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1702
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1703
    /**
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1704
     * Sets the line-ending
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1705
     *
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1706
     * @param string The new line-ending
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1707
     * @since 1.0.2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1708
     */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1709
    function set_line_ending($line_ending) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1710
        $this->line_ending = (string)$line_ending;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1711
    }
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1712
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1713
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1714
     * Sets what number line numbers should start at. Should
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1715
     * be a positive integer, and will be converted to one.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1716
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1717
     * <b>Warning:</b> Using this method will add the "start"
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1718
     * attribute to the &lt;ol&gt; that is used for line numbering.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1719
     * This is <b>not</b> valid XHTML strict, so if that's what you
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1720
     * care about then don't use this method. Firefox is getting
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1721
     * support for the CSS method of doing this in 1.1 and Opera
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1722
     * has support for the CSS method, but (of course) IE doesn't
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1723
     * so it's not worth doing it the CSS way yet.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1724
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1725
     * @param int The number to start line numbers at
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1726
     * @since 1.0.2
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1727
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1728
    function start_line_numbers_at($number) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1729
        $this->line_numbers_start = abs(intval($number));
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1730
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1731
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1732
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1733
     * Sets the encoding used for htmlspecialchars(), for international
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1734
     * support.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1735
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1736
     * NOTE: This is not needed for now because htmlspecialchars() is not
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1737
     * being used (it has a security hole in PHP4 that has not been patched).
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1738
     * Maybe in a future version it may make a return for speed reasons, but
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1739
     * I doubt it.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1740
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1741
     * @param string The encoding to use for the source
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1742
     * @since 1.0.3
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1743
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1744
    function set_encoding($encoding) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1745
        if ($encoding) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1746
          $this->encoding = strtolower($encoding);
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1747
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1748
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1749
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1750
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1751
     * Turns linking of keywords on or off.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1752
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1753
     * @param boolean If true, links will be added to keywords
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1754
     * @since 1.0.2
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1755
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1756
    function enable_keyword_links($enable = true) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1757
        $this->keyword_links = (bool) $enable;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1758
    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1759
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1760
    /**
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1761
     * Setup caches needed for styling. This is automatically called in
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1762
     * parse_code() and get_stylesheet() when appropriate. This function helps
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1763
     * stylesheet generators as they rely on some style information being
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1764
     * preprocessed
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1765
     *
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1766
     * @since 1.0.8
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1767
     * @access private
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1768
     */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1769
    function build_style_cache() {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1770
        //Build the style cache needed to highlight numbers appropriate
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1771
        if($this->lexic_permissions['NUMBERS']) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1772
            //First check what way highlighting information for numbers are given
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1773
            if(!isset($this->language_data['NUMBERS'])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1774
                $this->language_data['NUMBERS'] = 0;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1775
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1776
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1777
            if(is_array($this->language_data['NUMBERS'])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1778
                $this->language_data['NUMBERS_CACHE'] = $this->language_data['NUMBERS'];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1779
            } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1780
                $this->language_data['NUMBERS_CACHE'] = array();
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1781
                if(!$this->language_data['NUMBERS']) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1782
                    $this->language_data['NUMBERS'] =
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1783
                        GESHI_NUMBER_INT_BASIC |
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1784
                        GESHI_NUMBER_FLT_NONSCI;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1785
                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1786
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1787
                for($i = 0, $j = $this->language_data['NUMBERS']; $j > 0; ++$i, $j>>=1) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1788
                    //Rearrange style indices if required ...
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1789
                    if(isset($this->language_data['STYLES']['NUMBERS'][1<<$i])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1790
                        $this->language_data['STYLES']['NUMBERS'][$i] =
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1791
                            $this->language_data['STYLES']['NUMBERS'][1<<$i];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1792
                        unset($this->language_data['STYLES']['NUMBERS'][1<<$i]);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1793
                    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1794
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1795
                    //Check if this bit is set for highlighting
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1796
                    if($j&1) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1797
                        //So this bit is set ...
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1798
                        //Check if it belongs to group 0 or the actual stylegroup
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1799
                        if(isset($this->language_data['STYLES']['NUMBERS'][$i])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1800
                            $this->language_data['NUMBERS_CACHE'][$i] = 1 << $i;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1801
                        } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1802
                            if(!isset($this->language_data['NUMBERS_CACHE'][0])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1803
                                $this->language_data['NUMBERS_CACHE'][0] = 0;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1804
                            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1805
                            $this->language_data['NUMBERS_CACHE'][0] |= 1 << $i;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1806
                        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1807
                    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1808
                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1809
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1810
        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1811
    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1812
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1813
    /**
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1814
     * Setup caches needed for parsing. This is automatically called in parse_code() when appropriate.
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1815
     * This function makes stylesheet generators much faster as they do not need these caches.
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1816
     *
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1817
     * @since 1.0.8
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1818
     * @access private
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1819
     */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1820
    function build_parse_cache() {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1821
        // cache symbol regexp
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1822
        //As this is a costy operation, we avoid doing it for multiple groups ...
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1823
        //Instead we perform it for all symbols at once.
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1824
        //
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1825
        //For this to work, we need to reorganize the data arrays.
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1826
        if ($this->lexic_permissions['SYMBOLS'] && !empty($this->language_data['SYMBOLS'])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1827
            $this->language_data['MULTIPLE_SYMBOL_GROUPS'] = count($this->language_data['STYLES']['SYMBOLS']) > 1;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1828
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1829
            $this->language_data['SYMBOL_DATA'] = array();
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1830
            $symbol_preg_multi = array(); // multi char symbols
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1831
            $symbol_preg_single = array(); // single char symbols
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1832
            foreach ($this->language_data['SYMBOLS'] as $key => $symbols) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1833
                if (is_array($symbols)) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1834
                    foreach ($symbols as $sym) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1835
                        $sym = $this->hsc($sym);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1836
                        if (!isset($this->language_data['SYMBOL_DATA'][$sym])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1837
                            $this->language_data['SYMBOL_DATA'][$sym] = $key;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1838
                            if (isset($sym[1])) { // multiple chars
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1839
                                $symbol_preg_multi[] = preg_quote($sym, '/');
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1840
                            } else { // single char
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1841
                                if ($sym == '-') {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1842
                                    // don't trigger range out of order error
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1843
                                    $symbol_preg_single[] = '\-';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1844
                                } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1845
                                    $symbol_preg_single[] = preg_quote($sym, '/');
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1846
                                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1847
                            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1848
                        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1849
                    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1850
                } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1851
                    $symbols = $this->hsc($symbols);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1852
                    if (!isset($this->language_data['SYMBOL_DATA'][$symbols])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1853
                        $this->language_data['SYMBOL_DATA'][$symbols] = 0;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1854
                        if (isset($symbols[1])) { // multiple chars
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1855
                            $symbol_preg_multi[] = preg_quote($symbols, '/');
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1856
                        } else if ($symbols == '-') {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1857
                            // don't trigger range out of order error
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1858
                            $symbol_preg_single[] = '\-';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1859
                        } else { // single char
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1860
                            $symbol_preg_single[] = preg_quote($symbols, '/');
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1861
                        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1862
                    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1863
                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1864
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1865
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1866
            //Now we have an array with each possible symbol as the key and the style as the actual data.
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1867
            //This way we can set the correct style just the moment we highlight ...
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1868
            //
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1869
            //Now we need to rewrite our array to get a search string that
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1870
            $symbol_preg = array();
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1871
            if (!empty($symbol_preg_multi)) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1872
                rsort($symbol_preg_multi);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1873
                $symbol_preg[] = implode('|', $symbol_preg_multi);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1874
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1875
            if (!empty($symbol_preg_single)) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1876
                rsort($symbol_preg_single);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1877
                $symbol_preg[] = '[' . implode('', $symbol_preg_single) . ']';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1878
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1879
            $this->language_data['SYMBOL_SEARCH'] = implode("|", $symbol_preg);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1880
        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1881
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1882
        // cache optimized regexp for keyword matching
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1883
        // remove old cache
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1884
        $this->language_data['CACHED_KEYWORD_LISTS'] = array();
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1885
        foreach (array_keys($this->language_data['KEYWORDS']) as $key) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1886
            if (!isset($this->lexic_permissions['KEYWORDS'][$key]) ||
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1887
                    $this->lexic_permissions['KEYWORDS'][$key]) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1888
                $this->optimize_keyword_group($key);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1889
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1890
        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1891
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1892
        // brackets
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1893
        if ($this->lexic_permissions['BRACKETS']) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1894
            $this->language_data['CACHE_BRACKET_MATCH'] = array('[', ']', '(', ')', '{', '}');
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1895
            if (!$this->use_classes && isset($this->language_data['STYLES']['BRACKETS'][0])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1896
                $this->language_data['CACHE_BRACKET_REPLACE'] = array(
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1897
                    '<| style="' . $this->language_data['STYLES']['BRACKETS'][0] . '">&#91;|>',
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1898
                    '<| style="' . $this->language_data['STYLES']['BRACKETS'][0] . '">&#93;|>',
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1899
                    '<| style="' . $this->language_data['STYLES']['BRACKETS'][0] . '">&#40;|>',
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1900
                    '<| style="' . $this->language_data['STYLES']['BRACKETS'][0] . '">&#41;|>',
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1901
                    '<| style="' . $this->language_data['STYLES']['BRACKETS'][0] . '">&#123;|>',
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1902
                    '<| style="' . $this->language_data['STYLES']['BRACKETS'][0] . '">&#125;|>',
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1903
                );
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1904
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1905
            else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1906
                $this->language_data['CACHE_BRACKET_REPLACE'] = array(
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1907
                    '<| class="br0">&#91;|>',
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1908
                    '<| class="br0">&#93;|>',
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1909
                    '<| class="br0">&#40;|>',
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1910
                    '<| class="br0">&#41;|>',
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1911
                    '<| class="br0">&#123;|>',
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1912
                    '<| class="br0">&#125;|>',
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1913
                );
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1914
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1915
        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1916
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1917
        //Build the parse cache needed to highlight numbers appropriate
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1918
        if($this->lexic_permissions['NUMBERS']) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1919
            //Check if the style rearrangements have been processed ...
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1920
            //This also does some preprocessing to check which style groups are useable ...
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1921
            if(!isset($this->language_data['NUMBERS_CACHE'])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1922
                $this->build_style_cache();
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1923
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1924
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1925
            //Number format specification
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1926
            //All this formats are matched case-insensitively!
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1927
            static $numbers_format = array(
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1928
                GESHI_NUMBER_INT_BASIC =>
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1929
                    '(?<![0-9a-z_\.%])(?<![\d\.]e[+\-])([1-9]\d*?|0)(?![0-9a-z\.])',
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1930
                GESHI_NUMBER_INT_CSTYLE =>
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1931
                    '(?<![0-9a-z_\.%])(?<![\d\.]e[+\-])([1-9]\d*?|0)l(?![0-9a-z\.])',
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1932
                GESHI_NUMBER_BIN_SUFFIX =>
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1933
                    '(?<![0-9a-z_\.])(?<![\d\.]e[+\-])[01]+?b(?![0-9a-z\.])',
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1934
                GESHI_NUMBER_BIN_PREFIX_PERCENT =>
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1935
                    '(?<![0-9a-z_\.%])(?<![\d\.]e[+\-])%[01]+?(?![0-9a-z\.])',
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1936
                GESHI_NUMBER_BIN_PREFIX_0B =>
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1937
                    '(?<![0-9a-z_\.%])(?<![\d\.]e[+\-])0b[01]+?(?![0-9a-z\.])',
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1938
                GESHI_NUMBER_OCT_PREFIX =>
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1939
                    '(?<![0-9a-z_\.])(?<![\d\.]e[+\-])0[0-7]+?(?![0-9a-z\.])',
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1940
                GESHI_NUMBER_OCT_SUFFIX =>
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1941
                    '(?<![0-9a-z_\.])(?<![\d\.]e[+\-])[0-7]+?o(?![0-9a-z\.])',
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1942
                GESHI_NUMBER_HEX_PREFIX =>
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1943
                    '(?<![0-9a-z_\.])(?<![\d\.]e[+\-])0x[0-9a-f]+?(?![0-9a-z\.])',
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1944
                GESHI_NUMBER_HEX_SUFFIX =>
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1945
                    '(?<![0-9a-z_\.])(?<![\d\.]e[+\-])\d[0-9a-f]*?h(?![0-9a-z\.])',
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1946
                GESHI_NUMBER_FLT_NONSCI =>
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1947
                    '(?<![0-9a-z_\.])(?<![\d\.]e[+\-])\d+?\.\d+?(?![0-9a-z\.])',
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1948
                GESHI_NUMBER_FLT_NONSCI_F =>
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1949
                    '(?<![0-9a-z_\.])(?<![\d\.]e[+\-])(?:\d+?(?:\.\d*?)?|\.\d+?)f(?![0-9a-z\.])',
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1950
                GESHI_NUMBER_FLT_SCI_SHORT =>
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1951
                    '(?<![0-9a-z_\.])(?<![\d\.]e[+\-])\.\d+?(?:e[+\-]?\d+?)?(?![0-9a-z\.])',
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1952
                GESHI_NUMBER_FLT_SCI_ZERO =>
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1953
                    '(?<![0-9a-z_\.])(?<![\d\.]e[+\-])(?:\d+?(?:\.\d*?)?|\.\d+?)(?:e[+\-]?\d+?)?(?![0-9a-z\.])'
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1954
                );
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1955
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1956
            //At this step we have an associative array with flag groups for a
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1957
            //specific style or an string denoting a regexp given its index.
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1958
            $this->language_data['NUMBERS_RXCACHE'] = array();
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1959
            foreach($this->language_data['NUMBERS_CACHE'] as $key => $rxdata) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1960
                if(is_string($rxdata)) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1961
                    $regexp = $rxdata;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1962
                } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1963
                    //This is a bitfield of number flags to highlight:
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1964
                    //Build an array, implode them together and make this the actual RX
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1965
                    $rxuse = array();
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1966
                    for($i = 1; $i <= $rxdata; $i<<=1) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1967
                        if($rxdata & $i) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1968
                            $rxuse[] = $numbers_format[$i];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1969
                        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1970
                    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1971
                    $regexp = implode("|", $rxuse);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1972
                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1973
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1974
                $this->language_data['NUMBERS_RXCACHE'][$key] =
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1975
                    "/(?<!<\|\/NUM!)(?<!\d\/>)($regexp)(?!\|>)/i";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1976
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1977
        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1978
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1979
        $this->parse_cache_built = true;
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1980
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1981
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1982
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1983
     * Returns the code in $this->source, highlighted and surrounded by the
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1984
     * nessecary HTML.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1985
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1986
     * This should only be called ONCE, cos it's SLOW! If you want to highlight
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1987
     * the same source multiple times, you're better off doing a whole lot of
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1988
     * str_replaces to replace the &lt;span&gt;s
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1989
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1990
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1991
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1992
    function parse_code () {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1993
        // Start the timer
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1994
        $start_time = microtime();
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1995
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1996
        // Firstly, if there is an error, we won't highlight
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1997
        if ($this->error) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1998
            //Escape the source for output
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  1999
            $result = $this->hsc($this->source);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2000
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2001
            //This fix is related to SF#1923020, but has to be applied regardless of
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2002
            //actually highlighting symbols.
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2003
            $result = str_replace(array('<SEMI>', '<PIPE>'), array(';', '|'), $result);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2004
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2005
            // Timing is irrelevant
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2006
            $this->set_time($start_time, $start_time);
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2007
            $this->finalise($result);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2008
            return $result;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2009
        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2010
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2011
        // make sure the parse cache is up2date
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2012
        if (!$this->parse_cache_built) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2013
            $this->build_parse_cache();
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2014
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2015
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2016
        // Replace all newlines to a common form.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2017
        $code = str_replace("\r\n", "\n", $this->source);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2018
        $code = str_replace("\r", "\n", $code);
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2019
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2020
        // Add spaces for regular expression matching and line numbers
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2021
//        $code = "\n" . $code . "\n";
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2022
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2023
        // Initialise various stuff
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2024
        $length           = strlen($code);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2025
        $COMMENT_MATCHED  = false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2026
        $stuff_to_parse   = '';
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2027
        $endresult        = '';
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2028
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2029
        // "Important" selections are handled like multiline comments
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2030
        // @todo GET RID OF THIS SHIZ
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2031
        if ($this->enable_important_blocks) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2032
            $this->language_data['COMMENT_MULTI'][GESHI_START_IMPORTANT] = GESHI_END_IMPORTANT;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2033
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2034
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2035
        if ($this->strict_mode) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2036
            // Break the source into bits. Each bit will be a portion of the code
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2037
            // within script delimiters - for example, HTML between < and >
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2038
            $k = 0;
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2039
            $parts = array();
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2040
            $matches = array();
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2041
            $next_match_pointer = null;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2042
            // we use a copy to unset delimiters on demand (when they are not found)
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2043
            $delim_copy = $this->language_data['SCRIPT_DELIMITERS'];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2044
            $i = 0;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2045
            while ($i < $length) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2046
                $next_match_pos = $length + 1; // never true
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2047
                foreach ($delim_copy as $dk => $delimiters) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2048
                    if(is_array($delimiters)) {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2049
                        foreach ($delimiters as $open => $close) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2050
                            // make sure the cache is setup properly
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2051
                            if (!isset($matches[$dk][$open])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2052
                                $matches[$dk][$open] = array(
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2053
                                    'next_match' => -1,
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2054
                                    'dk' => $dk,
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2055
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2056
                                    'open' => $open, // needed for grouping of adjacent code blocks (see below)
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2057
                                    'open_strlen' => strlen($open),
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2058
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2059
                                    'close' => $close,
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2060
                                    'close_strlen' => strlen($close),
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2061
                                );
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2062
                            }
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2063
                            // Get the next little bit for this opening string
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2064
                            if ($matches[$dk][$open]['next_match'] < $i) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2065
                                // only find the next pos if it was not already cached
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2066
                                $open_pos = strpos($code, $open, $i);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2067
                                if ($open_pos === false) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2068
                                    // no match for this delimiter ever
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2069
                                    unset($delim_copy[$dk][$open]);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2070
                                    continue;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2071
                                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2072
                                $matches[$dk][$open]['next_match'] = $open_pos;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2073
                            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2074
                            if ($matches[$dk][$open]['next_match'] < $next_match_pos) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2075
                                //So we got a new match, update the close_pos
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2076
                                $matches[$dk][$open]['close_pos'] =
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2077
                                    strpos($code, $close, $matches[$dk][$open]['next_match']+1);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2078
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2079
                                $next_match_pointer =& $matches[$dk][$open];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2080
                                $next_match_pos = $matches[$dk][$open]['next_match'];
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2081
                            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2082
                        }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2083
                    } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2084
                        //So we should match an RegExp as Strict Block ...
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2085
                        /**
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2086
                         * The value in $delimiters is expected to be an RegExp
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2087
                         * containing exactly 2 matching groups:
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2088
                         *  - Group 1 is the opener
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2089
                         *  - Group 2 is the closer
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2090
                         */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2091
                        if(!GESHI_PHP_PRE_433 && //Needs proper rewrite to work with PHP >=4.3.0; 4.3.3 is guaranteed to work.
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2092
                            preg_match($delimiters, $code, $matches_rx, PREG_OFFSET_CAPTURE, $i)) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2093
                            //We got a match ...
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2094
                            $matches[$dk] = array(
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2095
                                'next_match' => $matches_rx[1][1],
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2096
                                'dk' => $dk,
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2097
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2098
                                'close_strlen' => strlen($matches_rx[2][0]),
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2099
                                'close_pos' => $matches_rx[2][1],
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2100
                                );
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2101
                        } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2102
                            // no match for this delimiter ever
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2103
                            unset($delim_copy[$dk]);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2104
                            continue;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2105
                        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2106
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2107
                        if ($matches[$dk]['next_match'] <= $next_match_pos) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2108
                            $next_match_pointer =& $matches[$dk];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2109
                            $next_match_pos = $matches[$dk]['next_match'];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2110
                        }
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2111
                    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2112
                }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2113
                // non-highlightable text
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2114
                $parts[$k] = array(
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2115
                    1 => substr($code, $i, $next_match_pos - $i)
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2116
                );
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2117
                ++$k;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2118
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2119
                if ($next_match_pos > $length) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2120
                    // out of bounds means no next match was found
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2121
                    break;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2122
                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2123
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2124
                // highlightable code
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2125
                $parts[$k][0] = $next_match_pointer['dk'];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2126
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2127
                //Only combine for non-rx script blocks
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2128
                if(is_array($delim_copy[$next_match_pointer['dk']])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2129
                    // group adjacent script blocks, e.g. <foobar><asdf> should be one block, not three!
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2130
                    $i = $next_match_pos + $next_match_pointer['open_strlen'];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2131
                    while (true) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2132
                        $close_pos = strpos($code, $next_match_pointer['close'], $i);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2133
                        if ($close_pos == false) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2134
                            break;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2135
                        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2136
                        $i = $close_pos + $next_match_pointer['close_strlen'];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2137
                        if ($i == $length) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2138
                            break;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2139
                        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2140
                        if ($code[$i] == $next_match_pointer['open'][0] && ($next_match_pointer['open_strlen'] == 1 ||
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2141
                            substr($code, $i, $next_match_pointer['open_strlen']) == $next_match_pointer['open'])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2142
                            // merge adjacent but make sure we don't merge things like <tag><!-- comment -->
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2143
                            foreach ($matches as $submatches) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2144
                                foreach ($submatches as $match) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2145
                                    if ($match['next_match'] == $i) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2146
                                        // a different block already matches here!
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2147
                                        break 3;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2148
                                    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2149
                                }
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2150
                            }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2151
                        } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2152
                            break;
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2153
                        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2154
                    }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2155
                } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2156
                    $close_pos = $next_match_pointer['close_pos'] + $next_match_pointer['close_strlen'];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2157
                    $i = $close_pos;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2158
                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2159
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2160
                if ($close_pos === false) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2161
                    // no closing delimiter found!
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2162
                    $parts[$k][1] = substr($code, $next_match_pos);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2163
                    ++$k;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2164
                    break;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2165
                } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2166
                    $parts[$k][1] = substr($code, $next_match_pos, $i - $next_match_pos);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2167
                    ++$k;
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2168
                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2169
            }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2170
            unset($delim_copy, $next_match_pointer, $next_match_pos, $matches);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2171
            $num_parts = $k;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2172
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2173
            if ($num_parts == 1 && $this->strict_mode == GESHI_MAYBE) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2174
                // when we have only one part, we don't have anything to highlight at all.
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2175
                // if we have a "maybe" strict language, this should be handled as highlightable code
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2176
                $parts = array(
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2177
                    0 => array(
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2178
                        0 => '',
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2179
                        1 => ''
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2180
                    ),
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2181
                    1 => array(
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2182
                        0 => null,
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2183
                        1 => $parts[0][1]
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2184
                    )
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2185
                );
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2186
                $num_parts = 2;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2187
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2188
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2189
        } else {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2190
            // Not strict mode - simply dump the source into
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2191
            // the array at index 1 (the first highlightable block)
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2192
            $parts = array(
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2193
                0 => array(
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2194
                    0 => '',
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2195
                    1 => ''
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2196
                ),
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2197
                1 => array(
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2198
                    0 => null,
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2199
                    1 => $code
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2200
                )
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2201
            );
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2202
            $num_parts = 2;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2203
        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2204
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2205
        //Unset variables we won't need any longer
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2206
        unset($code);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2207
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2208
        //Preload some repeatedly used values regarding hardquotes ...
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2209
        $hq = isset($this->language_data['HARDQUOTE']) ? $this->language_data['HARDQUOTE'][0] : false;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2210
        $hq_strlen = strlen($hq);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2211
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2212
        //Preload if line numbers are to be generated afterwards
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2213
        //Added a check if line breaks should be forced even without line numbers, fixes SF#1727398
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2214
        $check_linenumbers = $this->line_numbers != GESHI_NO_LINE_NUMBERS ||
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2215
            !empty($this->highlight_extra_lines) || !$this->allow_multiline_span;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2216
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2217
        //preload the escape char for faster checking ...
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2218
        $escaped_escape_char = $this->hsc($this->language_data['ESCAPE_CHAR']);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2219
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2220
        // this is used for single-line comments
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2221
        $sc_disallowed_before = "";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2222
        $sc_disallowed_after = "";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2223
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2224
        if (isset($this->language_data['PARSER_CONTROL'])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2225
            if (isset($this->language_data['PARSER_CONTROL']['COMMENTS'])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2226
                if (isset($this->language_data['PARSER_CONTROL']['COMMENTS']['DISALLOWED_BEFORE'])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2227
                    $sc_disallowed_before = $this->language_data['PARSER_CONTROL']['COMMENTS']['DISALLOWED_BEFORE'];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2228
                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2229
                if (isset($this->language_data['PARSER_CONTROL']['COMMENTS']['DISALLOWED_AFTER'])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2230
                    $sc_disallowed_after = $this->language_data['PARSER_CONTROL']['COMMENTS']['DISALLOWED_AFTER'];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2231
                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2232
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2233
        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2234
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2235
        //Fix for SF#1932083: Multichar Quotemarks unsupported
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2236
        $is_string_starter = array();
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2237
        if ($this->lexic_permissions['STRINGS']) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2238
            foreach ($this->language_data['QUOTEMARKS'] as $quotemark) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2239
                if (!isset($is_string_starter[$quotemark[0]])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2240
                    $is_string_starter[$quotemark[0]] = (string)$quotemark;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2241
                } else if (is_string($is_string_starter[$quotemark[0]])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2242
                    $is_string_starter[$quotemark[0]] = array(
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2243
                        $is_string_starter[$quotemark[0]],
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2244
                        $quotemark);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2245
                } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2246
                    $is_string_starter[$quotemark[0]][] = $quotemark;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2247
                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2248
            }
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2249
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2250
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2251
        // Now we go through each part. We know that even-indexed parts are
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2252
        // code that shouldn't be highlighted, and odd-indexed parts should
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2253
        // be highlighted
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2254
        for ($key = 0; $key < $num_parts; ++$key) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2255
            $STRICTATTRS = '';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2256
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2257
            // If this block should be highlighted...
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2258
            if (!($key & 1)) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2259
                // Else not a block to highlight
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2260
                $endresult .= $this->hsc($parts[$key][1]);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2261
                unset($parts[$key]);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2262
                continue;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2263
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2264
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2265
            $result = '';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2266
            $part = $parts[$key][1];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2267
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2268
            $highlight_part = true;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2269
            if ($this->strict_mode && !is_null($parts[$key][0])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2270
                // get the class key for this block of code
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2271
                $script_key = $parts[$key][0];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2272
                $highlight_part = $this->language_data['HIGHLIGHT_STRICT_BLOCK'][$script_key];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2273
                if ($this->language_data['STYLES']['SCRIPT'][$script_key] != '' &&
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2274
                    $this->lexic_permissions['SCRIPT']) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2275
                    // Add a span element around the source to
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2276
                    // highlight the overall source block
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2277
                    if (!$this->use_classes &&
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2278
                        $this->language_data['STYLES']['SCRIPT'][$script_key] != '') {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2279
                        $attributes = ' style="' . $this->language_data['STYLES']['SCRIPT'][$script_key] . '"';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2280
                    } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2281
                        $attributes = ' class="sc' . $script_key . '"';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2282
                    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2283
                    $result .= "<span$attributes>";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2284
                    $STRICTATTRS = $attributes;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2285
                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2286
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2287
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2288
            if ($highlight_part) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2289
                // Now, highlight the code in this block. This code
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2290
                // is really the engine of GeSHi (along with the method
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2291
                // parse_non_string_part).
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2292
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2293
                // cache comment regexps incrementally
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2294
                $next_comment_regexp_key = '';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2295
                $next_comment_regexp_pos = -1;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2296
                $next_comment_multi_pos = -1;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2297
                $next_comment_single_pos = -1;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2298
                $comment_regexp_cache_per_key = array();
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2299
                $comment_multi_cache_per_key = array();
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2300
                $comment_single_cache_per_key = array();
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2301
                $next_open_comment_multi = '';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2302
                $next_comment_single_key = '';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2303
                $escape_regexp_cache_per_key = array();
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2304
                $next_escape_regexp_key = '';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2305
                $next_escape_regexp_pos = -1;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2306
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2307
                $length = strlen($part);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2308
                for ($i = 0; $i < $length; ++$i) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2309
                    // Get the next char
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2310
                    $char = $part[$i];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2311
                    $char_len = 1;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2312
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2313
                    // update regexp comment cache if needed
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2314
                    if (isset($this->language_data['COMMENT_REGEXP']) && $next_comment_regexp_pos < $i) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2315
                        $next_comment_regexp_pos = $length;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2316
                        foreach ($this->language_data['COMMENT_REGEXP'] as $comment_key => $regexp) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2317
                            $match_i = false;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2318
                            if (isset($comment_regexp_cache_per_key[$comment_key]) &&
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2319
                                ($comment_regexp_cache_per_key[$comment_key]['pos'] >= $i ||
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2320
                                 $comment_regexp_cache_per_key[$comment_key]['pos'] === false)) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2321
                                // we have already matched something
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2322
                                if ($comment_regexp_cache_per_key[$comment_key]['pos'] === false) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2323
                                    // this comment is never matched
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2324
                                    continue;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2325
                                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2326
                                $match_i = $comment_regexp_cache_per_key[$comment_key]['pos'];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2327
                            } else if (
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2328
                                //This is to allow use of the offset parameter in preg_match and stay as compatible with older PHP versions as possible
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2329
                                (GESHI_PHP_PRE_433 && preg_match($regexp, substr($part, $i), $match, PREG_OFFSET_CAPTURE)) ||
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2330
                                (!GESHI_PHP_PRE_433 && preg_match($regexp, $part, $match, PREG_OFFSET_CAPTURE, $i))
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2331
                                ) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2332
                                $match_i = $match[0][1];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2333
                                if (GESHI_PHP_PRE_433) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2334
                                    $match_i += $i;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2335
                                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2336
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2337
                                $comment_regexp_cache_per_key[$comment_key] = array(
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2338
                                    'key' => $comment_key,
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2339
                                    'length' => strlen($match[0][0]),
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2340
                                    'pos' => $match_i
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2341
                                );
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2342
                            } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2343
                                $comment_regexp_cache_per_key[$comment_key]['pos'] = false;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2344
                                continue;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2345
                            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2346
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2347
                            if ($match_i !== false && $match_i < $next_comment_regexp_pos) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2348
                                $next_comment_regexp_pos = $match_i;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2349
                                $next_comment_regexp_key = $comment_key;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2350
                                if ($match_i === $i) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2351
                                    break;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2352
                                }
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2353
                            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2354
                        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2355
                    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2356
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2357
                    $string_started = false;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2358
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2359
                    if (isset($is_string_starter[$char])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2360
                        // Possibly the start of a new string ...
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2361
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2362
                        //Check which starter it was ...
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2363
                        //Fix for SF#1932083: Multichar Quotemarks unsupported
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2364
                        if (is_array($is_string_starter[$char])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2365
                            $char_new = '';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2366
                            foreach ($is_string_starter[$char] as $testchar) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2367
                                if ($testchar === substr($part, $i, strlen($testchar)) &&
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2368
                                    strlen($testchar) > strlen($char_new)) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2369
                                    $char_new = $testchar;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2370
                                    $string_started = true;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2371
                                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2372
                            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2373
                            if ($string_started) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2374
                                $char = $char_new;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2375
                            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2376
                        } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2377
                            $testchar = $is_string_starter[$char];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2378
                            if ($testchar === substr($part, $i, strlen($testchar))) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2379
                                $char = $testchar;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2380
                                $string_started = true;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2381
                            }
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2382
                        }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2383
                        $char_len = strlen($char);
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2384
                    }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2385
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2386
                    if ($string_started && $i != $next_comment_regexp_pos) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2387
                        // Hand out the correct style information for this string
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2388
                        $string_key = array_search($char, $this->language_data['QUOTEMARKS']);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2389
                        if (!isset($this->language_data['STYLES']['STRINGS'][$string_key]) ||
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2390
                            !isset($this->language_data['STYLES']['ESCAPE_CHAR'][$string_key])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2391
                            $string_key = 0;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2392
                        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2393
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2394
                        // parse the stuff before this
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2395
                        $result .= $this->parse_non_string_part($stuff_to_parse);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2396
                        $stuff_to_parse = '';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2397
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2398
                        if (!$this->use_classes) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2399
                            $string_attributes = ' style="' . $this->language_data['STYLES']['STRINGS'][$string_key] . '"';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2400
                        } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2401
                            $string_attributes = ' class="st'.$string_key.'"';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2402
                        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2403
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2404
                        // now handle the string
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2405
                        $string = "<span$string_attributes>" . GeSHi::hsc($char);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2406
                        $start = $i + $char_len;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2407
                        $string_open = true;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2408
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2409
                        if(empty($this->language_data['ESCAPE_REGEXP'])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2410
                            $next_escape_regexp_pos = $length;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2411
                        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2412
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2413
                        do {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2414
                            //Get the regular ending pos ...
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2415
                            $close_pos = strpos($part, $char, $start);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2416
                            if(false === $close_pos) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2417
                                $close_pos = $length;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2418
                            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2419
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2420
                            if($this->lexic_permissions['ESCAPE_CHAR']) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2421
                                // update escape regexp cache if needed
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2422
                                if (isset($this->language_data['ESCAPE_REGEXP']) && $next_escape_regexp_pos < $start) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2423
                                    $next_escape_regexp_pos = $length;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2424
                                    foreach ($this->language_data['ESCAPE_REGEXP'] as $escape_key => $regexp) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2425
                                        $match_i = false;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2426
                                        if (isset($escape_regexp_cache_per_key[$escape_key]) &&
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2427
                                            ($escape_regexp_cache_per_key[$escape_key]['pos'] >= $start ||
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2428
                                             $escape_regexp_cache_per_key[$escape_key]['pos'] === false)) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2429
                                            // we have already matched something
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2430
                                            if ($escape_regexp_cache_per_key[$escape_key]['pos'] === false) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2431
                                                // this comment is never matched
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2432
                                                continue;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2433
                                            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2434
                                            $match_i = $escape_regexp_cache_per_key[$escape_key]['pos'];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2435
                                        } else if (
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2436
                                            //This is to allow use of the offset parameter in preg_match and stay as compatible with older PHP versions as possible
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2437
                                            (GESHI_PHP_PRE_433 && preg_match($regexp, substr($part, $start), $match, PREG_OFFSET_CAPTURE)) ||
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2438
                                            (!GESHI_PHP_PRE_433 && preg_match($regexp, $part, $match, PREG_OFFSET_CAPTURE, $start))
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2439
                                            ) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2440
                                            $match_i = $match[0][1];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2441
                                            if (GESHI_PHP_PRE_433) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2442
                                                $match_i += $start;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2443
                                            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2444
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2445
                                            $escape_regexp_cache_per_key[$escape_key] = array(
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2446
                                                'key' => $escape_key,
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2447
                                                'length' => strlen($match[0][0]),
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2448
                                                'pos' => $match_i
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2449
                                            );
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2450
                                        } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2451
                                            $escape_regexp_cache_per_key[$escape_key]['pos'] = false;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2452
                                            continue;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2453
                                        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2454
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2455
                                        if ($match_i !== false && $match_i < $next_escape_regexp_pos) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2456
                                            $next_escape_regexp_pos = $match_i;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2457
                                            $next_escape_regexp_key = $escape_key;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2458
                                            if ($match_i === $start) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2459
                                                break;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2460
                                            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2461
                                        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2462
                                    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2463
                                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2464
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2465
                                //Find the next simple escape position
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2466
                                if('' != $this->language_data['ESCAPE_CHAR']) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2467
                                    $simple_escape = strpos($part, $this->language_data['ESCAPE_CHAR'], $start);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2468
                                    if(false === $simple_escape) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2469
                                        $simple_escape = $length;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2470
                                    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2471
                                } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2472
                                    $simple_escape = $length;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2473
                                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2474
                            } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2475
                                $next_escape_regexp_pos = $length;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2476
                                $simple_escape = $length;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2477
                            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2478
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2479
                            if($simple_escape < $next_escape_regexp_pos &&
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2480
                                $simple_escape < $length &&
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2481
                                $simple_escape < $close_pos) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2482
                                //The nexxt escape sequence is a simple one ...
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2483
                                $es_pos = $simple_escape;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2484
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2485
                                //Add the stuff not in the string yet ...
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2486
                                $string .= $this->hsc(substr($part, $start, $es_pos - $start));
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2487
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2488
                                //Get the style for this escaped char ...
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2489
                                if (!$this->use_classes) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2490
                                    $escape_char_attributes = ' style="' . $this->language_data['STYLES']['ESCAPE_CHAR'][0] . '"';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2491
                                } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2492
                                    $escape_char_attributes = ' class="es0"';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2493
                                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2494
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2495
                                //Add the style for the escape char ...
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2496
                                $string .= "<span$escape_char_attributes>" .
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2497
                                    GeSHi::hsc($this->language_data['ESCAPE_CHAR']);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2498
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2499
                                //Get the byte AFTER the ESCAPE_CHAR we just found
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2500
                                $es_char = $part[$es_pos + 1];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2501
                                if ($es_char == "\n") {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2502
                                    // don't put a newline around newlines
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2503
                                    $string .= "</span>\n";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2504
                                    $start = $es_pos + 2;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2505
                                } else if (ord($es_char) >= 128) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2506
                                    //This is an non-ASCII char (UTF8 or single byte)
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2507
                                    //This code tries to work around SF#2037598 ...
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2508
                                    if(function_exists('mb_substr')) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2509
                                        $es_char_m = mb_substr(substr($part, $es_pos+1, 16), 0, 1, $this->encoding);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2510
                                        $string .= $es_char_m . '</span>';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2511
                                    } else if (!GESHI_PHP_PRE_433 && 'utf-8' == $this->encoding) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2512
                                        if(preg_match("/[\xC2-\xDF][\x80-\xBF]".
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2513
                                            "|\xE0[\xA0-\xBF][\x80-\xBF]".
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2514
                                            "|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}".
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2515
                                            "|\xED[\x80-\x9F][\x80-\xBF]".
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2516
                                            "|\xF0[\x90-\xBF][\x80-\xBF]{2}".
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2517
                                            "|[\xF1-\xF3][\x80-\xBF]{3}".
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2518
                                            "|\xF4[\x80-\x8F][\x80-\xBF]{2}/s",
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2519
                                            $part, $es_char_m, null, $es_pos + 1)) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2520
                                            $es_char_m = $es_char_m[0];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2521
                                        } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2522
                                            $es_char_m = $es_char;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2523
                                        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2524
                                        $string .= $this->hsc($es_char_m) . '</span>';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2525
                                    } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2526
                                        $es_char_m = $this->hsc($es_char);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2527
                                    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2528
                                    $start = $es_pos + strlen($es_char_m) + 1;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2529
                                } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2530
                                    $string .= $this->hsc($es_char) . '</span>';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2531
                                    $start = $es_pos + 2;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2532
                                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2533
                            } else if ($next_escape_regexp_pos < $length &&
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2534
                                $next_escape_regexp_pos < $close_pos) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2535
                                $es_pos = $next_escape_regexp_pos;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2536
                                //Add the stuff not in the string yet ...
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2537
                                $string .= $this->hsc(substr($part, $start, $es_pos - $start));
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2538
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2539
                                //Get the key and length of this match ...
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2540
                                $escape = $escape_regexp_cache_per_key[$next_escape_regexp_key];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2541
                                $escape_str = substr($part, $es_pos, $escape['length']);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2542
                                $escape_key = $escape['key'];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2543
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2544
                                //Get the style for this escaped char ...
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2545
                                if (!$this->use_classes) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2546
                                    $escape_char_attributes = ' style="' . $this->language_data['STYLES']['ESCAPE_CHAR'][$escape_key] . '"';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2547
                                } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2548
                                    $escape_char_attributes = ' class="es' . $escape_key . '"';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2549
                                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2550
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2551
                                //Add the style for the escape char ...
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2552
                                $string .= "<span$escape_char_attributes>" .
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2553
                                    $this->hsc($escape_str) . '</span>';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2554
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2555
                                $start = $es_pos + $escape['length'];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2556
                            } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2557
                                //Copy the remainder of the string ...
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2558
                                $string .= $this->hsc(substr($part, $start, $close_pos - $start + $char_len)) . '</span>';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2559
                                $start = $close_pos + $char_len;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2560
                                $string_open = false;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2561
                            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2562
                        } while($string_open);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2563
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2564
                        if ($check_linenumbers) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2565
                            // Are line numbers used? If, we should end the string before
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2566
                            // the newline and begin it again (so when <li>s are put in the source
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2567
                            // remains XHTML compliant)
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2568
                            // note to self: This opens up possibility of config files specifying
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2569
                            // that languages can/cannot have multiline strings???
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2570
                            $string = str_replace("\n", "</span>\n<span$string_attributes>", $string);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2571
                        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2572
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2573
                        $result .= $string;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2574
                        $string = '';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2575
                        $i = $start - 1;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2576
                        continue;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2577
                    } else if ($this->lexic_permissions['STRINGS'] && $hq && $hq[0] == $char &&
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2578
                        substr($part, $i, $hq_strlen) == $hq) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2579
                        // The start of a hard quoted string
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2580
                        if (!$this->use_classes) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2581
                            $string_attributes = ' style="' . $this->language_data['STYLES']['STRINGS']['HARD'] . '"';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2582
                            $escape_char_attributes = ' style="' . $this->language_data['STYLES']['ESCAPE_CHAR']['HARD'] . '"';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2583
                        } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2584
                            $string_attributes = ' class="st_h"';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2585
                            $escape_char_attributes = ' class="es_h"';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2586
                        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2587
                        // parse the stuff before this
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2588
                        $result .= $this->parse_non_string_part($stuff_to_parse);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2589
                        $stuff_to_parse = '';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2590
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2591
                        // now handle the string
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2592
                        $string = '';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2593
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2594
                        // look for closing quote
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2595
                        $start = $i + $hq_strlen;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2596
                        while ($close_pos = strpos($part, $this->language_data['HARDQUOTE'][1], $start)) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2597
                            $start = $close_pos + 1;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2598
                            if ($this->lexic_permissions['ESCAPE_CHAR'] && $part[$close_pos - 1] == $this->language_data['ESCAPE_CHAR']) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2599
                                // make sure this quote is not escaped
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2600
                                foreach ($this->language_data['HARDESCAPE'] as $hardescape) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2601
                                    if (substr($part, $close_pos - 1, strlen($hardescape)) == $hardescape) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2602
                                        // check wether this quote is escaped or if it is something like '\\'
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2603
                                        $escape_char_pos = $close_pos - 1;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2604
                                        while ($escape_char_pos > 0
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2605
                                                && $part[$escape_char_pos - 1] == $this->language_data['ESCAPE_CHAR']) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2606
                                            --$escape_char_pos;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2607
                                        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2608
                                        if (($close_pos - $escape_char_pos) & 1) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2609
                                            // uneven number of escape chars => this quote is escaped
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2610
                                            continue 2;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2611
                                        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2612
                                    }
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2613
                                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2614
                            }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2615
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2616
                            // found closing quote
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2617
                            break;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2618
                        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2619
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2620
                        //Found the closing delimiter?
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2621
                        if (!$close_pos) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2622
                            // span till the end of this $part when no closing delimiter is found
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2623
                            $close_pos = $length;
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2624
                        }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2625
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2626
                        //Get the actual string
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2627
                        $string = substr($part, $i, $close_pos - $i + 1);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2628
                        $i = $close_pos;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2629
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2630
                        // handle escape chars and encode html chars
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2631
                        // (special because when we have escape chars within our string they may not be escaped)
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2632
                        if ($this->lexic_permissions['ESCAPE_CHAR'] && $this->language_data['ESCAPE_CHAR']) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2633
                            $start = 0;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2634
                            $new_string = '';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2635
                            while ($es_pos = strpos($string, $this->language_data['ESCAPE_CHAR'], $start)) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2636
                                // hmtl escape stuff before
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2637
                                $new_string .= $this->hsc(substr($string, $start, $es_pos - $start));
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2638
                                // check if this is a hard escape
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2639
                                foreach ($this->language_data['HARDESCAPE'] as $hardescape) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2640
                                    if (substr($string, $es_pos, strlen($hardescape)) == $hardescape) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2641
                                        // indeed, this is a hardescape
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2642
                                        $new_string .= "<span$escape_char_attributes>" .
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2643
                                            $this->hsc($hardescape) . '</span>';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2644
                                        $start = $es_pos + strlen($hardescape);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2645
                                        continue 2;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2646
                                    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2647
                                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2648
                                // not a hard escape, but a normal escape
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2649
                                // they come in pairs of two
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2650
                                $c = 0;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2651
                                while (isset($string[$es_pos + $c]) && isset($string[$es_pos + $c + 1])
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2652
                                    && $string[$es_pos + $c] == $this->language_data['ESCAPE_CHAR']
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2653
                                    && $string[$es_pos + $c + 1] == $this->language_data['ESCAPE_CHAR']) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2654
                                    $c += 2;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2655
                                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2656
                                if ($c) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2657
                                    $new_string .= "<span$escape_char_attributes>" .
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2658
                                        str_repeat($escaped_escape_char, $c) .
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2659
                                        '</span>';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2660
                                    $start = $es_pos + $c;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2661
                                } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2662
                                    // this is just a single lonely escape char...
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2663
                                    $new_string .= $escaped_escape_char;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2664
                                    $start = $es_pos + 1;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2665
                                }
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2666
                            }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2667
                            $string = $new_string . $this->hsc(substr($string, $start));
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2668
                        } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2669
                            $string = $this->hsc($string);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2670
                        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2671
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2672
                        if ($check_linenumbers) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2673
                            // Are line numbers used? If, we should end the string before
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2674
                            // the newline and begin it again (so when <li>s are put in the source
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2675
                            // remains XHTML compliant)
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2676
                            // note to self: This opens up possibility of config files specifying
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2677
                            // that languages can/cannot have multiline strings???
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2678
                            $string = str_replace("\n", "</span>\n<span$string_attributes>", $string);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2679
                        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2680
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2681
                        $result .= "<span$string_attributes>" . $string . '</span>';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2682
                        $string = '';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2683
                        continue;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2684
                    } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2685
                        //Have a look for regexp comments
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2686
                        if ($i == $next_comment_regexp_pos) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2687
                            $COMMENT_MATCHED = true;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2688
                            $comment = $comment_regexp_cache_per_key[$next_comment_regexp_key];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2689
                            $test_str = $this->hsc(substr($part, $i, $comment['length']));
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2690
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2691
                            //@todo If remove important do remove here
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2692
                            if ($this->lexic_permissions['COMMENTS']['MULTI']) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2693
                                if (!$this->use_classes) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2694
                                    $attributes = ' style="' . $this->language_data['STYLES']['COMMENTS'][$comment['key']] . '"';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2695
                                } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2696
                                    $attributes = ' class="co' . $comment['key'] . '"';
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2697
                                }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2698
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2699
                                $test_str = "<span$attributes>" . $test_str . "</span>";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2700
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2701
                                // Short-cut through all the multiline code
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2702
                                if ($check_linenumbers) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2703
                                    // strreplace to put close span and open span around multiline newlines
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2704
                                    $test_str = str_replace(
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2705
                                        "\n", "</span>\n<span$attributes>",
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2706
                                        str_replace("\n ", "\n&nbsp;", $test_str)
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2707
                                    );
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2708
                                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2709
                            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2710
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2711
                            $i += $comment['length'] - 1;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2712
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2713
                            // parse the rest
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2714
                            $result .= $this->parse_non_string_part($stuff_to_parse);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2715
                            $stuff_to_parse = '';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2716
                        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2717
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2718
                        // If we haven't matched a regexp comment, try multi-line comments
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2719
                        if (!$COMMENT_MATCHED) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2720
                            // Is this a multiline comment?
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2721
                            if (!empty($this->language_data['COMMENT_MULTI']) && $next_comment_multi_pos < $i) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2722
                                $next_comment_multi_pos = $length;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2723
                                foreach ($this->language_data['COMMENT_MULTI'] as $open => $close) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2724
                                    $match_i = false;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2725
                                    if (isset($comment_multi_cache_per_key[$open]) &&
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2726
                                        ($comment_multi_cache_per_key[$open] >= $i ||
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2727
                                         $comment_multi_cache_per_key[$open] === false)) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2728
                                        // we have already matched something
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2729
                                        if ($comment_multi_cache_per_key[$open] === false) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2730
                                            // this comment is never matched
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2731
                                            continue;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2732
                                        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2733
                                        $match_i = $comment_multi_cache_per_key[$open];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2734
                                    } else if (($match_i = stripos($part, $open, $i)) !== false) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2735
                                        $comment_multi_cache_per_key[$open] = $match_i;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2736
                                    } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2737
                                        $comment_multi_cache_per_key[$open] = false;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2738
                                        continue;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2739
                                    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2740
                                    if ($match_i !== false && $match_i < $next_comment_multi_pos) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2741
                                        $next_comment_multi_pos = $match_i;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2742
                                        $next_open_comment_multi = $open;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2743
                                        if ($match_i === $i) {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2744
                                            break;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2745
                                        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2746
                                    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2747
                                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2748
                            }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2749
                            if ($i == $next_comment_multi_pos) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2750
                                $open = $next_open_comment_multi;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2751
                                $close = $this->language_data['COMMENT_MULTI'][$open];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2752
                                $open_strlen = strlen($open);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2753
                                $close_strlen = strlen($close);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2754
                                $COMMENT_MATCHED = true;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2755
                                $test_str_match = $open;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2756
                                //@todo If remove important do remove here
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2757
                                if ($this->lexic_permissions['COMMENTS']['MULTI'] ||
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2758
                                    $open == GESHI_START_IMPORTANT) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2759
                                    if ($open != GESHI_START_IMPORTANT) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2760
                                        if (!$this->use_classes) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2761
                                            $attributes = ' style="' . $this->language_data['STYLES']['COMMENTS']['MULTI'] . '"';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2762
                                        } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2763
                                            $attributes = ' class="coMULTI"';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2764
                                        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2765
                                        $test_str = "<span$attributes>" . $this->hsc($open);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2766
                                    } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2767
                                        if (!$this->use_classes) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2768
                                            $attributes = ' style="' . $this->important_styles . '"';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2769
                                        } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2770
                                            $attributes = ' class="imp"';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2771
                                        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2772
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2773
                                        // We don't include the start of the comment if it's an
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2774
                                        // "important" part
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2775
                                        $test_str = "<span$attributes>";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2776
                                    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2777
                                } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2778
                                    $test_str = $this->hsc($open);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2779
                                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2780
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2781
                                $close_pos = strpos( $part, $close, $i + $open_strlen );
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2782
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2783
                                if ($close_pos === false) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2784
                                    $close_pos = $length;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2785
                                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2786
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2787
                                // Short-cut through all the multiline code
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2788
                                $rest_of_comment = $this->hsc(substr($part, $i + $open_strlen, $close_pos - $i - $open_strlen + $close_strlen));
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2789
                                if (($this->lexic_permissions['COMMENTS']['MULTI'] ||
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2790
                                    $test_str_match == GESHI_START_IMPORTANT) &&
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2791
                                    $check_linenumbers) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2792
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2793
                                    // strreplace to put close span and open span around multiline newlines
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2794
                                    $test_str .= str_replace(
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2795
                                        "\n", "</span>\n<span$attributes>",
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2796
                                        str_replace("\n ", "\n&nbsp;", $rest_of_comment)
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2797
                                    );
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2798
                                } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2799
                                    $test_str .= $rest_of_comment;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2800
                                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2801
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2802
                                if ($this->lexic_permissions['COMMENTS']['MULTI'] ||
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2803
                                    $test_str_match == GESHI_START_IMPORTANT) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2804
                                    $test_str .= '</span>';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2805
                                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2806
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2807
                                $i = $close_pos + $close_strlen - 1;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2808
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2809
                                // parse the rest
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2810
                                $result .= $this->parse_non_string_part($stuff_to_parse);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2811
                                $stuff_to_parse = '';
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2812
                            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2813
                        }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2814
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2815
                        // If we haven't matched a multiline comment, try single-line comments
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2816
                        if (!$COMMENT_MATCHED) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2817
                            // cache potential single line comment occurances
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2818
                            if (!empty($this->language_data['COMMENT_SINGLE']) && $next_comment_single_pos < $i) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2819
                                $next_comment_single_pos = $length;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2820
                                foreach ($this->language_data['COMMENT_SINGLE'] as $comment_key => $comment_mark) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2821
                                    $match_i = false;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2822
                                    if (isset($comment_single_cache_per_key[$comment_key]) &&
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2823
                                        ($comment_single_cache_per_key[$comment_key] >= $i ||
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2824
                                         $comment_single_cache_per_key[$comment_key] === false)) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2825
                                        // we have already matched something
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2826
                                        if ($comment_single_cache_per_key[$comment_key] === false) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2827
                                            // this comment is never matched
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2828
                                            continue;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2829
                                        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2830
                                        $match_i = $comment_single_cache_per_key[$comment_key];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2831
                                    } else if (
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2832
                                        // case sensitive comments
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2833
                                        ($this->language_data['CASE_SENSITIVE'][GESHI_COMMENTS] &&
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2834
                                        ($match_i = stripos($part, $comment_mark, $i)) !== false) ||
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2835
                                        // non case sensitive
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2836
                                        (!$this->language_data['CASE_SENSITIVE'][GESHI_COMMENTS] &&
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2837
                                          (($match_i = strpos($part, $comment_mark, $i)) !== false))) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2838
                                        $comment_single_cache_per_key[$comment_key] = $match_i;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2839
                                    } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2840
                                        $comment_single_cache_per_key[$comment_key] = false;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2841
                                        continue;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2842
                                    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2843
                                    if ($match_i !== false && $match_i < $next_comment_single_pos) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2844
                                        $next_comment_single_pos = $match_i;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2845
                                        $next_comment_single_key = $comment_key;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2846
                                        if ($match_i === $i) {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2847
                                            break;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2848
                                        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2849
                                    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2850
                                }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2851
                            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2852
                            if ($next_comment_single_pos == $i) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2853
                                $comment_key = $next_comment_single_key;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2854
                                $comment_mark = $this->language_data['COMMENT_SINGLE'][$comment_key];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2855
                                $com_len = strlen($comment_mark);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2856
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2857
                                // This check will find special variables like $# in bash
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2858
                                // or compiler directives of Delphi beginning {$
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2859
                                if ((empty($sc_disallowed_before) || ($i == 0) ||
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2860
                                    (false === strpos($sc_disallowed_before, $part[$i-1]))) &&
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2861
                                    (empty($sc_disallowed_after) || ($length <= $i + $com_len) ||
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2862
                                    (false === strpos($sc_disallowed_after, $part[$i + $com_len]))))
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2863
                                {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2864
                                    // this is a valid comment
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2865
                                    $COMMENT_MATCHED = true;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2866
                                    if ($this->lexic_permissions['COMMENTS'][$comment_key]) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2867
                                        if (!$this->use_classes) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2868
                                            $attributes = ' style="' . $this->language_data['STYLES']['COMMENTS'][$comment_key] . '"';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2869
                                        } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2870
                                            $attributes = ' class="co' . $comment_key . '"';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2871
                                        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2872
                                        $test_str = "<span$attributes>" . $this->hsc($this->change_case($comment_mark));
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2873
                                    } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2874
                                        $test_str = $this->hsc($comment_mark);
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2875
                                    }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2876
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2877
                                    //Check if this comment is the last in the source
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2878
                                    $close_pos = strpos($part, "\n", $i);
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2879
                                    $oops = false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2880
                                    if ($close_pos === false) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2881
                                        $close_pos = $length;
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2882
                                        $oops = true;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2883
                                    }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2884
                                    $test_str .= $this->hsc(substr($part, $i + $com_len, $close_pos - $i - $com_len));
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2885
                                    if ($this->lexic_permissions['COMMENTS'][$comment_key]) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2886
                                        $test_str .= "</span>";
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2887
                                    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2888
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2889
                                    // Take into account that the comment might be the last in the source
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2890
                                    if (!$oops) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2891
                                      $test_str .= "\n";
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2892
                                    }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2893
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2894
                                    $i = $close_pos;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2895
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2896
                                    // parse the rest
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2897
                                    $result .= $this->parse_non_string_part($stuff_to_parse);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2898
                                    $stuff_to_parse = '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2899
                                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2900
                            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2901
                        }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2902
                    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2903
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2904
                    // Where are we adding this char?
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2905
                    if (!$COMMENT_MATCHED) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2906
                        $stuff_to_parse .= $char;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2907
                    } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2908
                        $result .= $test_str;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2909
                        unset($test_str);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2910
                        $COMMENT_MATCHED = false;
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2911
                    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2912
                }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2913
                // Parse the last bit
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2914
                $result .= $this->parse_non_string_part($stuff_to_parse);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2915
                $stuff_to_parse = '';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2916
            } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2917
                $result .= $this->hsc($part);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2918
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2919
            // Close the <span> that surrounds the block
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2920
            if ($STRICTATTRS != '') {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2921
                $result = str_replace("\n", "</span>\n<span$STRICTATTRS>", $result);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2922
                $result .= '</span>';
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2923
            }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2924
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2925
            $endresult .= $result;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2926
            unset($part, $parts[$key], $result);
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2927
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2928
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2929
        //This fix is related to SF#1923020, but has to be applied regardless of
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2930
        //actually highlighting symbols.
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2931
        /** NOTE: memorypeak #3 */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2932
        $endresult = str_replace(array('<SEMI>', '<PIPE>'), array(';', '|'), $endresult);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2933
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2934
//        // Parse the last stuff (redundant?)
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2935
//        $result .= $this->parse_non_string_part($stuff_to_parse);
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2936
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2937
        // Lop off the very first and last spaces
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2938
//        $result = substr($result, 1, -1);
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2939
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2940
        // We're finished: stop timing
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2941
        $this->set_time($start_time, microtime());
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2942
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2943
        $this->finalise($endresult);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2944
        return $endresult;
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2945
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2946
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2947
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2948
     * Swaps out spaces and tabs for HTML indentation. Not needed if
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2949
     * the code is in a pre block...
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2950
     *
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2951
     * @param  string The source to indent (reference!)
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2952
     * @since  1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2953
     * @access private
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2954
     */
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2955
    function indent(&$result) {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2956
        /// Replace tabs with the correct number of spaces
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2957
        if (false !== strpos($result, "\t")) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2958
            $lines = explode("\n", $result);
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2959
            $result = null;//Save memory while we process the lines individually
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2960
            $tab_width = $this->get_real_tab_width();
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2961
            $tab_string = '&nbsp;' . str_repeat(' ', $tab_width);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2962
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2963
            for ($key = 0, $n = count($lines); $key < $n; $key++) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2964
                $line = $lines[$key];
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2965
                if (false === strpos($line, "\t")) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2966
                    continue;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2967
                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2968
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2969
                $pos = 0;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2970
                $length = strlen($line);
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2971
                $lines[$key] = ''; // reduce memory
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2972
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2973
                $IN_TAG = false;
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2974
                for ($i = 0; $i < $length; ++$i) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2975
                    $char = $line[$i];
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2976
                    // Simple engine to work out whether we're in a tag.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2977
                    // If we are we modify $pos. This is so we ignore HTML
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2978
                    // in the line and only workout the tab replacement
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2979
                    // via the actual content of the string
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2980
                    // This test could be improved to include strings in the
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2981
                    // html so that < or > would be allowed in user's styles
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2982
                    // (e.g. quotes: '<' '>'; or similar)
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2983
                    if ($IN_TAG) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2984
                        if ('>' == $char) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2985
                            $IN_TAG = false;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2986
                        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2987
                        $lines[$key] .= $char;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2988
                    } else if ('<' == $char) {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2989
                        $IN_TAG = true;
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2990
                        $lines[$key] .= '<';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2991
                    } else if ('&' == $char) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2992
                        $substr = substr($line, $i + 3, 5);
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2993
                        $posi = strpos($substr, ';');
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2994
                        if (false === $posi) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2995
                            ++$pos;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2996
                        } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2997
                            $pos -= $posi+2;
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2998
                        }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  2999
                        $lines[$key] .= $char;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3000
                    } else if ("\t" == $char) {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3001
                        $str = '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3002
                        // OPTIMISE - move $strs out. Make an array:
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3003
                        // $tabs = array(
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3004
                        //  1 => '&nbsp;',
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3005
                        //  2 => '&nbsp; ',
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3006
                        //  3 => '&nbsp; &nbsp;' etc etc
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3007
                        // to use instead of building a string every time
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3008
                        $tab_end_width = $tab_width - ($pos % $tab_width); //Moved out of the look as it doesn't change within the loop
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3009
                        if (($pos & 1) || 1 == $tab_end_width) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3010
                            $str .= substr($tab_string, 6, $tab_end_width);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3011
                        } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3012
                            $str .= substr($tab_string, 0, $tab_end_width+5);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3013
                        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3014
                        $lines[$key] .= $str;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3015
                        $pos += $tab_end_width;
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3016
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3017
                        if (false === strpos($line, "\t", $i + 1)) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3018
                            $lines[$key] .= substr($line, $i + 1);
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3019
                            break;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3020
                        }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3021
                    } else if (0 == $pos && ' ' == $char) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3022
                        $lines[$key] .= '&nbsp;';
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3023
                        ++$pos;
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3024
                    } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3025
                        $lines[$key] .= $char;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3026
                        ++$pos;
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3027
                    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3028
                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3029
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3030
            $result = implode("\n", $lines);
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3031
            unset($lines);//We don't need the lines separated beyond this --- free them!
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3032
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3033
        // Other whitespace
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3034
        // BenBE: Fix to reduce the number of replacements to be done
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3035
        $result = preg_replace('/^ /m', '&nbsp;', $result);
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3036
        $result = str_replace('  ', ' &nbsp;', $result);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3037
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3038
        if ($this->line_numbers == GESHI_NO_LINE_NUMBERS) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3039
            if ($this->line_ending === null) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3040
                $result = nl2br($result);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3041
            } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3042
                $result = str_replace("\n", $this->line_ending, $result);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3043
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3044
        }
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3045
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3046
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3047
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3048
     * Changes the case of a keyword for those languages where a change is asked for
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3049
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3050
     * @param  string The keyword to change the case of
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3051
     * @return string The keyword with its case changed
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3052
     * @since  1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3053
     * @access private
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3054
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3055
    function change_case($instr) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3056
        switch ($this->language_data['CASE_KEYWORDS']) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3057
            case GESHI_CAPS_UPPER:
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3058
                return strtoupper($instr);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3059
            case GESHI_CAPS_LOWER:
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3060
                return strtolower($instr);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3061
            default:
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3062
                return $instr;
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3063
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3064
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3065
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3066
    /**
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3067
     * Handles replacements of keywords to include markup and links if requested
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3068
     *
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3069
     * @param  string The keyword to add the Markup to
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3070
     * @return The HTML for the match found
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3071
     * @since  1.0.8
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3072
     * @access private
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3073
     *
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3074
     * @todo   Get rid of ender in keyword links
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3075
     */
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3076
    function handle_keyword_replace($match) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3077
        $k = $this->_kw_replace_group;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3078
        $keyword = $match[0];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3079
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3080
        $before = '';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3081
        $after = '';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3082
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3083
        if ($this->keyword_links) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3084
            // Keyword links have been ebabled
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3085
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3086
            if (isset($this->language_data['URLS'][$k]) &&
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3087
                $this->language_data['URLS'][$k] != '') {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3088
                // There is a base group for this keyword
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3089
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3090
                // Old system: strtolower
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3091
                //$keyword = ( $this->language_data['CASE_SENSITIVE'][$group] ) ? $keyword : strtolower($keyword);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3092
                // New system: get keyword from language file to get correct case
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3093
                if (!$this->language_data['CASE_SENSITIVE'][$k] &&
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3094
                    strpos($this->language_data['URLS'][$k], '{FNAME}') !== false) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3095
                    foreach ($this->language_data['KEYWORDS'][$k] as $word) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3096
                        if (strcasecmp($word, $keyword) == 0) {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3097
                            break;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3098
                        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3099
                    }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3100
                } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3101
                    $word = $keyword;
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3102
                }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3103
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3104
                $before = '<|UR1|"' .
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3105
                    str_replace(
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3106
                        array(
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3107
                            '{FNAME}',
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3108
                            '{FNAMEL}',
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3109
                            '{FNAMEU}',
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3110
                            '.'),
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3111
                        array(
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3112
                            str_replace('+', '%20', urlencode($this->hsc($word))),
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3113
                            str_replace('+', '%20', urlencode($this->hsc(strtolower($word)))),
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3114
                            str_replace('+', '%20', urlencode($this->hsc(strtoupper($word)))),
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3115
                            '<DOT>'),
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3116
                        $this->language_data['URLS'][$k]
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3117
                    ) . '">';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3118
                $after = '</a>';
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3119
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3120
        }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3121
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3122
        return $before . '<|/'. $k .'/>' . $this->change_case($keyword) . '|>' . $after;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3123
    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3124
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3125
    /**
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3126
     * handles regular expressions highlighting-definitions with callback functions
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3127
     *
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3128
     * @note this is a callback, don't use it directly
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3129
     *
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3130
     * @param array the matches array
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3131
     * @return The highlighted string
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3132
     * @since 1.0.8
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3133
     * @access private
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3134
     */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3135
    function handle_regexps_callback($matches) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3136
        // before: "' style=\"' . call_user_func(\"$func\", '\\1') . '\"\\1|>'",
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3137
        return  ' style="' . call_user_func($this->language_data['STYLES']['REGEXPS'][$this->_rx_key], $matches[1]) . '"'. $matches[1] . '|>';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3138
    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3139
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3140
    /**
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3141
     * handles newlines in REGEXPS matches. Set the _hmr_* vars before calling this
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3142
     *
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3143
     * @note this is a callback, don't use it directly
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3144
     *
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3145
     * @param array the matches array
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3146
     * @return string
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3147
     * @since 1.0.8
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3148
     * @access private
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3149
     */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3150
    function handle_multiline_regexps($matches) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3151
        $before = $this->_hmr_before;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3152
        $after = $this->_hmr_after;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3153
        if ($this->_hmr_replace) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3154
            $replace = $this->_hmr_replace;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3155
            $search = array();
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3156
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3157
            foreach (array_keys($matches) as $k) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3158
                $search[] = '\\' . $k;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3159
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3160
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3161
            $before = str_replace($search, $matches, $before);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3162
            $after = str_replace($search, $matches, $after);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3163
            $replace = str_replace($search, $matches, $replace);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3164
        } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3165
            $replace = $matches[0];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3166
        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3167
        return $before
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3168
                    . '<|!REG3XP' . $this->_hmr_key .'!>'
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3169
                        . str_replace("\n", "|>\n<|!REG3XP" . $this->_hmr_key . '!>', $replace)
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3170
                    . '|>'
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3171
              . $after;
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3172
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3173
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3174
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3175
     * Takes a string that has no strings or comments in it, and highlights
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3176
     * stuff like keywords, numbers and methods.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3177
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3178
     * @param string The string to parse for keyword, numbers etc.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3179
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3180
     * @access private
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3181
     * @todo BUGGY! Why? Why not build string and return?
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3182
     */
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3183
    function parse_non_string_part($stuff_to_parse) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3184
        $stuff_to_parse = ' ' . $this->hsc($stuff_to_parse);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3185
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3186
        // Regular expressions
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3187
        foreach ($this->language_data['REGEXPS'] as $key => $regexp) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3188
            if ($this->lexic_permissions['REGEXPS'][$key]) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3189
                if (is_array($regexp)) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3190
                    if ($this->line_numbers != GESHI_NO_LINE_NUMBERS) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3191
                        // produce valid HTML when we match multiple lines
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3192
                        $this->_hmr_replace = $regexp[GESHI_REPLACE];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3193
                        $this->_hmr_before = $regexp[GESHI_BEFORE];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3194
                        $this->_hmr_key = $key;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3195
                        $this->_hmr_after = $regexp[GESHI_AFTER];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3196
                        $stuff_to_parse = preg_replace_callback(
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3197
                            "/" . $regexp[GESHI_SEARCH] . "/{$regexp[GESHI_MODIFIERS]}",
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3198
                            array($this, 'handle_multiline_regexps'),
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3199
                            $stuff_to_parse);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3200
                        $this->_hmr_replace = false;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3201
                        $this->_hmr_before = '';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3202
                        $this->_hmr_after = '';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3203
                    } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3204
                        $stuff_to_parse = preg_replace(
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3205
                            '/' . $regexp[GESHI_SEARCH] . '/' . $regexp[GESHI_MODIFIERS],
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3206
                            $regexp[GESHI_BEFORE] . '<|!REG3XP'. $key .'!>' . $regexp[GESHI_REPLACE] . '|>' . $regexp[GESHI_AFTER],
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3207
                            $stuff_to_parse);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3208
                    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3209
                } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3210
                    if ($this->line_numbers != GESHI_NO_LINE_NUMBERS) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3211
                        // produce valid HTML when we match multiple lines
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3212
                        $this->_hmr_key = $key;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3213
                        $stuff_to_parse = preg_replace_callback( "/(" . $regexp . ")/",
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3214
                                              array($this, 'handle_multiline_regexps'), $stuff_to_parse);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3215
                        $this->_hmr_key = '';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3216
                    } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3217
                        $stuff_to_parse = preg_replace( "/(" . $regexp . ")/", "<|!REG3XP$key!>\\1|>", $stuff_to_parse);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3218
                    }
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3219
                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3220
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3221
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3222
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3223
        // Highlight numbers. As of 1.0.8 we support diffent types of numbers
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3224
        $numbers_found = false;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3225
        if ($this->lexic_permissions['NUMBERS'] && preg_match('#\d#', $stuff_to_parse )) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3226
            $numbers_found = true;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3227
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3228
            //For each of the formats ...
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3229
            foreach($this->language_data['NUMBERS_RXCACHE'] as $id => $regexp) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3230
                //Check if it should be highlighted ...
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3231
                $stuff_to_parse = preg_replace($regexp, "<|/NUM!$id/>\\1|>", $stuff_to_parse);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3232
            }
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3233
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3234
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3235
        // Highlight keywords
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3236
        $disallowed_before = "(?<![a-zA-Z0-9\$_\|\#;>|^&";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3237
        $disallowed_after = "(?![a-zA-Z0-9_\|%\\-&;";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3238
        if ($this->lexic_permissions['STRINGS']) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3239
            $quotemarks = preg_quote(implode($this->language_data['QUOTEMARKS']), '/');
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3240
            $disallowed_before .= $quotemarks;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3241
            $disallowed_after .= $quotemarks;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3242
        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3243
        $disallowed_before .= "])";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3244
        $disallowed_after .= "])";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3245
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3246
        $parser_control_pergroup = false;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3247
        if (isset($this->language_data['PARSER_CONTROL'])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3248
            if (isset($this->language_data['PARSER_CONTROL']['KEYWORDS'])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3249
                $x = 0; // check wether per-keyword-group parser_control is enabled
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3250
                if (isset($this->language_data['PARSER_CONTROL']['KEYWORDS']['DISALLOWED_BEFORE'])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3251
                    $disallowed_before = $this->language_data['PARSER_CONTROL']['KEYWORDS']['DISALLOWED_BEFORE'];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3252
                    ++$x;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3253
                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3254
                if (isset($this->language_data['PARSER_CONTROL']['KEYWORDS']['DISALLOWED_AFTER'])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3255
                    $disallowed_after = $this->language_data['PARSER_CONTROL']['KEYWORDS']['DISALLOWED_AFTER'];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3256
                    ++$x;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3257
                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3258
                $parser_control_pergroup = (count($this->language_data['PARSER_CONTROL']['KEYWORDS']) - $x) > 0;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3259
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3260
        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3261
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3262
        // if this is changed, don't forget to change it below
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3263
//        if (!empty($disallowed_before)) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3264
//            $disallowed_before = "(?<![$disallowed_before])";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3265
//        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3266
//        if (!empty($disallowed_after)) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3267
//            $disallowed_after = "(?![$disallowed_after])";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3268
//        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3269
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3270
        foreach (array_keys($this->language_data['KEYWORDS']) as $k) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3271
            if (!isset($this->lexic_permissions['KEYWORDS'][$k]) ||
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3272
                $this->lexic_permissions['KEYWORDS'][$k]) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3273
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3274
                $case_sensitive = $this->language_data['CASE_SENSITIVE'][$k];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3275
                $modifiers = $case_sensitive ? '' : 'i';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3276
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3277
                // NEW in 1.0.8 - per-keyword-group parser control
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3278
                $disallowed_before_local = $disallowed_before;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3279
                $disallowed_after_local = $disallowed_after;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3280
                if ($parser_control_pergroup && isset($this->language_data['PARSER_CONTROL']['KEYWORDS'][$k])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3281
                    if (isset($this->language_data['PARSER_CONTROL']['KEYWORDS'][$k]['DISALLOWED_BEFORE'])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3282
                        $disallowed_before_local =
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3283
                            $this->language_data['PARSER_CONTROL']['KEYWORDS'][$k]['DISALLOWED_BEFORE'];
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3284
                    }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3285
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3286
                    if (isset($this->language_data['PARSER_CONTROL']['KEYWORDS'][$k]['DISALLOWED_AFTER'])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3287
                        $disallowed_after_local =
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3288
                            $this->language_data['PARSER_CONTROL']['KEYWORDS'][$k]['DISALLOWED_AFTER'];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3289
                    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3290
                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3291
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3292
                $this->_kw_replace_group = $k;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3293
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3294
                //NEW in 1.0.8, the cached regexp list
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3295
                // since we don't want PHP / PCRE to crash due to too large patterns we split them into smaller chunks
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3296
                for ($set = 0, $set_length = count($this->language_data['CACHED_KEYWORD_LISTS'][$k]); $set <  $set_length; ++$set) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3297
                    $keywordset =& $this->language_data['CACHED_KEYWORD_LISTS'][$k][$set];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3298
                    // Might make a more unique string for putting the number in soon
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3299
                    // Basically, we don't put the styles in yet because then the styles themselves will
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3300
                    // get highlighted if the language has a CSS keyword in it (like CSS, for example ;))
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3301
                    $stuff_to_parse = preg_replace_callback(
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3302
                        "/$disallowed_before_local({$keywordset})(?!\<DOT\>(?:htm|php))$disallowed_after_local/$modifiers",
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3303
                        array($this, 'handle_keyword_replace'),
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3304
                        $stuff_to_parse
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3305
                        );
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3306
                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3307
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3308
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3309
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3310
        //
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3311
        // Now that's all done, replace /[number]/ with the correct styles
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3312
        //
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3313
        foreach (array_keys($this->language_data['KEYWORDS']) as $k) {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3314
            if (!$this->use_classes) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3315
                $attributes = ' style="' .
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3316
                    (isset($this->language_data['STYLES']['KEYWORDS'][$k]) ?
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3317
                    $this->language_data['STYLES']['KEYWORDS'][$k] : "") . '"';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3318
            } else {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3319
                $attributes = ' class="kw' . $k . '"';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3320
            }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3321
            $stuff_to_parse = str_replace("<|/$k/>", "<|$attributes>", $stuff_to_parse);
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3322
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3323
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3324
        if ($numbers_found) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3325
            // Put number styles in
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3326
            foreach($this->language_data['NUMBERS_RXCACHE'] as $id => $regexp) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3327
//Commented out for now, as this needs some review ...
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3328
//                if ($numbers_permissions & $id) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3329
                    //Get the appropriate style ...
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3330
                        //Checking for unset styles is done by the style cache builder ...
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3331
                    if (!$this->use_classes) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3332
                        $attributes = ' style="' . $this->language_data['STYLES']['NUMBERS'][$id] . '"';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3333
                    } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3334
                        $attributes = ' class="nu'.$id.'"';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3335
                    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3336
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3337
                    //Set in the correct styles ...
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3338
                    $stuff_to_parse = str_replace("/NUM!$id/", $attributes, $stuff_to_parse);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3339
//                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3340
            }
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3341
        }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3342
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3343
        // Highlight methods and fields in objects
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3344
        if ($this->lexic_permissions['METHODS'] && $this->language_data['OOLANG']) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3345
            $oolang_spaces = "[\s]*";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3346
            $oolang_before = "";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3347
            $oolang_after = "[a-zA-Z][a-zA-Z0-9_]*";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3348
            if (isset($this->language_data['PARSER_CONTROL'])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3349
                if (isset($this->language_data['PARSER_CONTROL']['OOLANG'])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3350
                    if (isset($this->language_data['PARSER_CONTROL']['OOLANG']['MATCH_BEFORE'])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3351
                        $oolang_before = $this->language_data['PARSER_CONTROL']['OOLANG']['MATCH_BEFORE'];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3352
                    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3353
                    if (isset($this->language_data['PARSER_CONTROL']['OOLANG']['MATCH_AFTER'])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3354
                        $oolang_after = $this->language_data['PARSER_CONTROL']['OOLANG']['MATCH_AFTER'];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3355
                    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3356
                    if (isset($this->language_data['PARSER_CONTROL']['OOLANG']['MATCH_SPACES'])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3357
                        $oolang_spaces = $this->language_data['PARSER_CONTROL']['OOLANG']['MATCH_SPACES'];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3358
                    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3359
                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3360
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3361
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3362
            foreach ($this->language_data['OBJECT_SPLITTERS'] as $key => $splitter) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3363
                if (false !== strpos($stuff_to_parse, $splitter)) {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3364
                    if (!$this->use_classes) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3365
                        $attributes = ' style="' . $this->language_data['STYLES']['METHODS'][$key] . '"';
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3366
                    } else {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3367
                        $attributes = ' class="me' . $key . '"';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3368
                    }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3369
                    $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);
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3370
                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3371
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3372
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3373
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3374
        //
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3375
        // Highlight brackets. Yes, I've tried adding a semi-colon to this list.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3376
        // You try it, and see what happens ;)
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3377
        // TODO: Fix lexic permissions not converting entities if shouldn't
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3378
        // be highlighting regardless
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3379
        //
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3380
        if ($this->lexic_permissions['BRACKETS']) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3381
            $stuff_to_parse = str_replace( $this->language_data['CACHE_BRACKET_MATCH'],
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3382
                              $this->language_data['CACHE_BRACKET_REPLACE'], $stuff_to_parse );
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3383
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3384
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3385
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3386
        //FIX for symbol highlighting ...
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3387
        if ($this->lexic_permissions['SYMBOLS'] && !empty($this->language_data['SYMBOLS'])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3388
            //Get all matches and throw away those witin a block that is already highlighted... (i.e. matched by a regexp)
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3389
            $n_symbols = preg_match_all("/<\|(?:<DOT>|[^>])+>(?:(?!\|>).*?)\|>|<\/a>|(?:" . $this->language_data['SYMBOL_SEARCH'] . ")+/", $stuff_to_parse, $pot_symbols, PREG_OFFSET_CAPTURE | PREG_SET_ORDER);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3390
            $global_offset = 0;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3391
            for ($s_id = 0; $s_id < $n_symbols; ++$s_id) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3392
                $symbol_match = $pot_symbols[$s_id][0][0];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3393
                if (strpos($symbol_match, '<') !== false || strpos($symbol_match, '>') !== false) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3394
                    // already highlighted blocks _must_ include either < or >
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3395
                    // so if this conditional applies, we have to skip this match
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3396
                    // BenBE: UNLESS the block contains <SEMI> or <PIPE>
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3397
                    if(strpos($symbol_match, '<SEMI>') === false &&
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3398
                        strpos($symbol_match, '<PIPE>') === false) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3399
                        continue;
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3400
                    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3401
                }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3402
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3403
                // if we reach this point, we have a valid match which needs to be highlighted
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3404
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3405
                $symbol_length = strlen($symbol_match);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3406
                $symbol_offset = $pot_symbols[$s_id][0][1];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3407
                unset($pot_symbols[$s_id]);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3408
                $symbol_end = $symbol_length + $symbol_offset;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3409
                $symbol_hl = "";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3410
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3411
                // if we have multiple styles, we have to handle them properly
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3412
                if ($this->language_data['MULTIPLE_SYMBOL_GROUPS']) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3413
                    $old_sym = -1;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3414
                    // Split the current stuff to replace into its atomic symbols ...
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3415
                    preg_match_all("/" . $this->language_data['SYMBOL_SEARCH'] . "/", $symbol_match, $sym_match_syms, PREG_PATTERN_ORDER);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3416
                    foreach ($sym_match_syms[0] as $sym_ms) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3417
                        //Check if consequtive symbols belong to the same group to save output ...
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3418
                        if (isset($this->language_data['SYMBOL_DATA'][$sym_ms])
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3419
                            && ($this->language_data['SYMBOL_DATA'][$sym_ms] != $old_sym)) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3420
                            if (-1 != $old_sym) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3421
                                $symbol_hl .= "|>";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3422
                            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3423
                            $old_sym = $this->language_data['SYMBOL_DATA'][$sym_ms];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3424
                            if (!$this->use_classes) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3425
                                $symbol_hl .= '<| style="' . $this->language_data['STYLES']['SYMBOLS'][$old_sym] . '">';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3426
                            } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3427
                                $symbol_hl .= '<| class="sy' . $old_sym . '">';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3428
                            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3429
                        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3430
                        $symbol_hl .= $sym_ms;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3431
                    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3432
                    unset($sym_match_syms);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3433
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3434
                    //Close remaining tags and insert the replacement at the right position ...
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3435
                    //Take caution if symbol_hl is empty to avoid doubled closing spans.
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3436
                    if (-1 != $old_sym) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3437
                        $symbol_hl .= "|>";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3438
                    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3439
                } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3440
                    if (!$this->use_classes) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3441
                        $symbol_hl = '<| style="' . $this->language_data['STYLES']['SYMBOLS'][0] . '">';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3442
                    } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3443
                        $symbol_hl = '<| class="sy0">';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3444
                    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3445
                    $symbol_hl .= $symbol_match . '|>';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3446
                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3447
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3448
                $stuff_to_parse = substr_replace($stuff_to_parse, $symbol_hl, $symbol_offset + $global_offset, $symbol_length);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3449
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3450
                // since we replace old text with something of different size,
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3451
                // we'll have to keep track of the differences
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3452
                $global_offset += strlen($symbol_hl) - $symbol_length;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3453
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3454
        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3455
        //FIX for symbol highlighting ...
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3456
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3457
        // Add class/style for regexps
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3458
        foreach (array_keys($this->language_data['REGEXPS']) as $key) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3459
            if ($this->lexic_permissions['REGEXPS'][$key]) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3460
                if (is_callable($this->language_data['STYLES']['REGEXPS'][$key])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3461
                    $this->_rx_key = $key;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3462
                    $stuff_to_parse = preg_replace_callback("/!REG3XP$key!(.*)\|>/U",
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3463
                        array($this, 'handle_regexps_callback'),
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3464
                        $stuff_to_parse);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3465
                } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3466
                    if (!$this->use_classes) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3467
                        $attributes = ' style="' . $this->language_data['STYLES']['REGEXPS'][$key] . '"';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3468
                    } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3469
                        if (is_array($this->language_data['REGEXPS'][$key]) &&
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3470
                            array_key_exists(GESHI_CLASS, $this->language_data['REGEXPS'][$key])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3471
                            $attributes = ' class="' .
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3472
                                $this->language_data['REGEXPS'][$key][GESHI_CLASS] . '"';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3473
                        } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3474
                           $attributes = ' class="re' . $key . '"';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3475
                        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3476
                    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3477
                    $stuff_to_parse = str_replace("!REG3XP$key!", "$attributes", $stuff_to_parse);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3478
                }
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3479
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3480
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3481
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3482
        // Replace <DOT> with . for urls
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3483
        $stuff_to_parse = str_replace('<DOT>', '.', $stuff_to_parse);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3484
        // Replace <|UR1| with <a href= for urls also
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3485
        if (isset($this->link_styles[GESHI_LINK])) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3486
            if ($this->use_classes) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3487
                $stuff_to_parse = str_replace('<|UR1|', '<a' . $this->link_target . ' href=', $stuff_to_parse);
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3488
            } else {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3489
                $stuff_to_parse = str_replace('<|UR1|', '<a' . $this->link_target . ' style="' . $this->link_styles[GESHI_LINK] . '" href=', $stuff_to_parse);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3490
            }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3491
        } else {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3492
            $stuff_to_parse = str_replace('<|UR1|', '<a' . $this->link_target . ' href=', $stuff_to_parse);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3493
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3494
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3495
        //
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3496
        // NOW we add the span thingy ;)
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3497
        //
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3498
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3499
        $stuff_to_parse = str_replace('<|', '<span', $stuff_to_parse);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3500
        $stuff_to_parse = str_replace ( '|>', '</span>', $stuff_to_parse );
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3501
        return substr($stuff_to_parse, 1);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3502
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3503
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3504
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3505
     * Sets the time taken to parse the code
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3506
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3507
     * @param microtime The time when parsing started
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3508
     * @param microtime The time when parsing ended
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3509
     * @since 1.0.2
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3510
     * @access private
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3511
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3512
    function set_time($start_time, $end_time) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3513
        $start = explode(' ', $start_time);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3514
        $end = explode(' ', $end_time);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3515
        $this->time = $end[0] + $end[1] - $start[0] - $start[1];
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3516
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3517
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3518
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3519
     * Gets the time taken to parse the code
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3520
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3521
     * @return double The time taken to parse the code
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3522
     * @since  1.0.2
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3523
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3524
    function get_time() {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3525
        return $this->time;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3526
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3527
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3528
    /**
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3529
     * Merges arrays recursively, overwriting values of the first array with values of later arrays
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3530
     *
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3531
     * @since 1.0.8
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3532
     * @access private
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3533
     */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3534
    function merge_arrays() {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3535
        $arrays = func_get_args();
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3536
        $narrays = count($arrays);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3537
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3538
        // check arguments
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3539
        // comment out if more performance is necessary (in this case the foreach loop will trigger a warning if the argument is not an array)
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3540
        for ($i = 0; $i < $narrays; $i ++) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3541
            if (!is_array($arrays[$i])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3542
                // also array_merge_recursive returns nothing in this case
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3543
                trigger_error('Argument #' . ($i+1) . ' is not an array - trying to merge array with scalar! Returning false!', E_USER_WARNING);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3544
                return false;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3545
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3546
        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3547
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3548
        // the first array is in the output set in every case
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3549
        $ret = $arrays[0];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3550
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3551
        // merege $ret with the remaining arrays
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3552
        for ($i = 1; $i < $narrays; $i ++) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3553
            foreach ($arrays[$i] as $key => $value) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3554
                if (is_array($value) && isset($ret[$key])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3555
                    // if $ret[$key] is not an array you try to merge an scalar value with an array - the result is not defined (incompatible arrays)
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3556
                    // in this case the call will trigger an E_USER_WARNING and the $ret[$key] will be false.
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3557
                    $ret[$key] = $this->merge_arrays($ret[$key], $value);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3558
                } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3559
                    $ret[$key] = $value;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3560
                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3561
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3562
        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3563
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3564
        return $ret;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3565
    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3566
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3567
    /**
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3568
     * Gets language information and stores it for later use
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3569
     *
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3570
     * @param string The filename of the language file you want to load
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3571
     * @since 1.0.0
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3572
     * @access private
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3573
     * @todo Needs to load keys for lexic permissions for keywords, regexps etc
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3574
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3575
    function load_language($file_name) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3576
        if ($file_name == $this->loaded_language) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3577
            // this file is already loaded!
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3578
            return;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3579
        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3580
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3581
        //Prepare some stuff before actually loading the language file
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3582
        $this->loaded_language = $file_name;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3583
        $this->parse_cache_built = false;
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3584
        $this->enable_highlighting();
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3585
        $language_data = array();
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3586
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3587
        //Load the language file
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3588
        require $file_name;
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3589
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3590
        // Perhaps some checking might be added here later to check that
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3591
        // $language data is a valid thing but maybe not
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3592
        $this->language_data = $language_data;
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3593
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3594
        // Set strict mode if should be set
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3595
        $this->strict_mode = $this->language_data['STRICT_MODE_APPLIES'];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3596
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3597
        // Set permissions for all lexics to true
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3598
        // so they'll be highlighted by default
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3599
        foreach (array_keys($this->language_data['KEYWORDS']) as $key) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3600
            if (!empty($this->language_data['KEYWORDS'][$key])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3601
                $this->lexic_permissions['KEYWORDS'][$key] = true;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3602
            } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3603
                $this->lexic_permissions['KEYWORDS'][$key] = false;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3604
            }
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3605
        }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3606
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3607
        foreach (array_keys($this->language_data['COMMENT_SINGLE']) as $key) {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3608
            $this->lexic_permissions['COMMENTS'][$key] = true;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3609
        }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3610
        foreach (array_keys($this->language_data['REGEXPS']) as $key) {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3611
            $this->lexic_permissions['REGEXPS'][$key] = true;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3612
        }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3613
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3614
        // for BenBE and future code reviews:
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3615
        // we can use empty here since we only check for existance and emptiness of an array
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3616
        // if it is not an array at all but rather false or null this will work as intended as well
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3617
        // even if $this->language_data['PARSER_CONTROL'] is undefined this won't trigger a notice
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3618
        if (!empty($this->language_data['PARSER_CONTROL']['ENABLE_FLAGS'])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3619
            foreach ($this->language_data['PARSER_CONTROL']['ENABLE_FLAGS'] as $flag => $value) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3620
                // it's either true or false and maybe is true as well
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3621
                $perm = $value !== GESHI_NEVER;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3622
                if ($flag == 'ALL') {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3623
                    $this->enable_highlighting($perm);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3624
                    continue;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3625
                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3626
                if (!isset($this->lexic_permissions[$flag])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3627
                    // unknown lexic permission
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3628
                    continue;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3629
                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3630
                if (is_array($this->lexic_permissions[$flag])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3631
                    foreach ($this->lexic_permissions[$flag] as $key => $val) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3632
                        $this->lexic_permissions[$flag][$key] = $perm;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3633
                    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3634
                } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3635
                    $this->lexic_permissions[$flag] = $perm;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3636
                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3637
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3638
            unset($this->language_data['PARSER_CONTROL']['ENABLE_FLAGS']);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3639
        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3640
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3641
        //NEW in 1.0.8: Allow styles to be loaded from a separate file to override defaults
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3642
        $style_filename = substr($file_name, 0, -4) . '.style.php';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3643
        if (is_readable($style_filename)) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3644
            //Clear any style_data that could have been set before ...
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3645
            if (isset($style_data)) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3646
                unset($style_data);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3647
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3648
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3649
            //Read the Style Information from the style file
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3650
            include $style_filename;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3651
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3652
            //Apply the new styles to our current language styles
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3653
            if (isset($style_data) && is_array($style_data)) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3654
                $this->language_data['STYLES'] =
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3655
                    $this->merge_arrays($this->language_data['STYLES'], $style_data);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3656
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3657
        }
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3658
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3659
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3660
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3661
     * Takes the parsed code and various options, and creates the HTML
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3662
     * surrounding it to make it look nice.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3663
     *
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3664
     * @param  string The code already parsed (reference!)
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3665
     * @since  1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3666
     * @access private
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3667
     */
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3668
    function finalise(&$parsed_code) {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3669
        // Remove end parts of important declarations
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3670
        // This is BUGGY!! My fault for bad code: fix coming in 1.2
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3671
        // @todo Remove this crap
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3672
        if ($this->enable_important_blocks &&
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3673
            (strpos($parsed_code, $this->hsc(GESHI_START_IMPORTANT)) === false)) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3674
            $parsed_code = str_replace($this->hsc(GESHI_END_IMPORTANT), '', $parsed_code);
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3675
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3676
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3677
        // Add HTML whitespace stuff if we're using the <div> header
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3678
        if ($this->header_type != GESHI_HEADER_PRE && $this->header_type != GESHI_HEADER_PRE_VALID) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3679
            $this->indent($parsed_code);
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3680
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3681
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3682
        // purge some unnecessary stuff
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3683
        /** NOTE: memorypeak #1 */
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3684
        $parsed_code = preg_replace('#<span[^>]+>(\s*)</span>#', '\\1', $parsed_code);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3685
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3686
        // If we are using IDs for line numbers, there needs to be an overall
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3687
        // ID set to prevent collisions.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3688
        if ($this->add_ids && !$this->overall_id) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3689
            $this->overall_id = 'geshi-' . substr(md5(microtime()), 0, 4);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3690
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3691
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3692
        // Get code into lines
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3693
        /** NOTE: memorypeak #2 */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3694
        $code = explode("\n", $parsed_code);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3695
        $parsed_code = $this->header();
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3696
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3697
        // If we're using line numbers, we insert <li>s and appropriate
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3698
        // markup to style them (otherwise we don't need to do anything)
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3699
        if ($this->line_numbers != GESHI_NO_LINE_NUMBERS && $this->header_type != GESHI_HEADER_PRE_TABLE) {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3700
            // If we're using the <pre> header, we shouldn't add newlines because
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3701
            // the <pre> will line-break them (and the <li>s already do this for us)
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3702
            $ls = ($this->header_type != GESHI_HEADER_PRE && $this->header_type != GESHI_HEADER_PRE_VALID) ? "\n" : '';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3703
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3704
            // Set vars to defaults for following loop
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3705
            $i = 0;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3706
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3707
            // Foreach line...
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3708
            for ($i = 0, $n = count($code); $i < $n;) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3709
                //Reset the attributes for a new line ...
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3710
                $attrs = array();
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3711
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3712
                // Make lines have at least one space in them if they're empty
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3713
                // BenBE: Checking emptiness using trim instead of relying on blanks
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3714
                if ('' == trim($code[$i])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3715
                    $code[$i] = '&nbsp;';
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3716
                }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3717
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3718
                // If this is a "special line"...
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3719
                if ($this->line_numbers == GESHI_FANCY_LINE_NUMBERS &&
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3720
                    $i % $this->line_nth_row == ($this->line_nth_row - 1)) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3721
                    // Set the attributes to style the line
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3722
                    if ($this->use_classes) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3723
                        //$attr = ' class="li2"';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3724
                        $attrs['class'][] = 'li2';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3725
                        $def_attr = ' class="de2"';
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3726
                    } else {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3727
                        //$attr = ' style="' . $this->line_style2 . '"';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3728
                        $attrs['style'][] = $this->line_style2;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3729
                        // This style "covers up" the special styles set for special lines
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3730
                        // so that styles applied to special lines don't apply to the actual
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3731
                        // code on that line
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3732
                        $def_attr = ' style="' . $this->code_style . '"';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3733
                    }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3734
                } else {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3735
                    if ($this->use_classes) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3736
                        //$attr = ' class="li1"';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3737
                        $attrs['class'][] = 'li1';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3738
                        $def_attr = ' class="de1"';
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3739
                    } else {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3740
                        //$attr = ' style="' . $this->line_style1 . '"';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3741
                        $attrs['style'][] = $this->line_style1;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3742
                        $def_attr = ' style="' . $this->code_style . '"';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3743
                    }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3744
                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3745
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3746
                //Check which type of tag to insert for this line
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3747
                if ($this->header_type == GESHI_HEADER_PRE_VALID) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3748
                    $start = "<pre$def_attr>";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3749
                    $end = '</pre>';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3750
                } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3751
                    // Span or div?
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3752
                    $start = "<div$def_attr>";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3753
                    $end = '</div>';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3754
                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3755
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3756
                ++$i;
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3757
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3758
                // Are we supposed to use ids? If so, add them
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3759
                if ($this->add_ids) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3760
                    $attrs['id'][] = "$this->overall_id-$i";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3761
                }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3762
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3763
                //Is this some line with extra styles???
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3764
                if (in_array($i, $this->highlight_extra_lines)) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3765
                    if ($this->use_classes) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3766
                        if (isset($this->highlight_extra_lines_styles[$i])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3767
                            $attrs['class'][] = "lx$i";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3768
                        } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3769
                            $attrs['class'][] = "ln-xtra";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3770
                        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3771
                    } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3772
                        array_push($attrs['style'], $this->get_line_style($i));
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3773
                    }
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3774
                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3775
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3776
                // Add in the line surrounded by appropriate list HTML
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3777
                $attr_string = '';
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3778
                foreach ($attrs as $key => $attr) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3779
                    $attr_string .= ' ' . $key . '="' . implode(' ', $attr) . '"';
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3780
                }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3781
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3782
                $parsed_code .= "<li$attr_string>$start{$code[$i-1]}$end</li>$ls";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3783
                unset($code[$i - 1]);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3784
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3785
        } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3786
            $n = count($code);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3787
            if ($this->use_classes) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3788
                $attributes = ' class="de1"';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3789
            } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3790
                $attributes = ' style="'. $this->code_style .'"';
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3791
            }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3792
            if ($this->header_type == GESHI_HEADER_PRE_VALID) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3793
                $parsed_code .= '<pre'. $attributes .'>';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3794
            } elseif ($this->header_type == GESHI_HEADER_PRE_TABLE) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3795
                if ($this->line_numbers != GESHI_NO_LINE_NUMBERS) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3796
                    if ($this->use_classes) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3797
                        $attrs = ' class="ln"';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3798
                    } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3799
                        $attrs = ' style="'. $this->table_linenumber_style .'"';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3800
                    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3801
                    $parsed_code .= '<td'.$attrs.'><pre'.$attributes.'>';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3802
                    // get linenumbers
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3803
                    // we don't merge it with the for below, since it should be better for
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3804
                    // memory consumption this way
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3805
                    // @todo: but... actually it would still be somewhat nice to merge the two loops
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3806
                    //        the mem peaks are at different positions
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3807
                    for ($i = 0; $i < $n; ++$i) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3808
                        $close = 0;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3809
                        // fancy lines
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3810
                        if ($this->line_numbers == GESHI_FANCY_LINE_NUMBERS &&
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3811
                            $i % $this->line_nth_row == ($this->line_nth_row - 1)) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3812
                            // Set the attributes to style the line
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3813
                            if ($this->use_classes) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3814
                                $parsed_code .= '<span class="xtra li2"><span class="de2">';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3815
                            } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3816
                                // This style "covers up" the special styles set for special lines
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3817
                                // so that styles applied to special lines don't apply to the actual
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3818
                                // code on that line
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3819
                                $parsed_code .= '<span style="display:block;' . $this->line_style2 . '">'
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3820
                                                  .'<span style="' . $this->code_style .'">';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3821
                            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3822
                            $close += 2;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3823
                        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3824
                        //Is this some line with extra styles???
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3825
                        if (in_array($i + 1, $this->highlight_extra_lines)) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3826
                            if ($this->use_classes) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3827
                                if (isset($this->highlight_extra_lines_styles[$i])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3828
                                    $parsed_code .= "<span class=\"xtra lx$i\">";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3829
                                } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3830
                                    $parsed_code .= "<span class=\"xtra ln-xtra\">";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3831
                                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3832
                            } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3833
                                $parsed_code .= "<span style=\"display:block;" . $this->get_line_style($i) . "\">";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3834
                            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3835
                            ++$close;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3836
                        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3837
                        $parsed_code .= $this->line_numbers_start + $i;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3838
                        if ($close) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3839
                            $parsed_code .= str_repeat('</span>', $close);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3840
                        } else if ($i != $n) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3841
                            $parsed_code .= "\n";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3842
                        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3843
                    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3844
                    $parsed_code .= '</pre></td><td'.$attributes.'>';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3845
                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3846
                $parsed_code .= '<pre'. $attributes .'>';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3847
            }
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3848
            // No line numbers, but still need to handle highlighting lines extra.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3849
            // Have to use divs so the full width of the code is highlighted
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3850
            $close = 0;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3851
            for ($i = 0; $i < $n; ++$i) {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3852
                // Make lines have at least one space in them if they're empty
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3853
                // BenBE: Checking emptiness using trim instead of relying on blanks
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3854
                if ('' == trim($code[$i])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3855
                    $code[$i] = '&nbsp;';
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3856
                }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3857
                // fancy lines
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3858
                if ($this->line_numbers == GESHI_FANCY_LINE_NUMBERS &&
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3859
                    $i % $this->line_nth_row == ($this->line_nth_row - 1)) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3860
                    // Set the attributes to style the line
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3861
                    if ($this->use_classes) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3862
                        $parsed_code .= '<span class="xtra li2"><span class="de2">';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3863
                    } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3864
                        // This style "covers up" the special styles set for special lines
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3865
                        // so that styles applied to special lines don't apply to the actual
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3866
                        // code on that line
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3867
                        $parsed_code .= '<span style="display:block;' . $this->line_style2 . '">'
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3868
                                          .'<span style="' . $this->code_style .'">';
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3869
                    }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3870
                    $close += 2;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3871
                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3872
                //Is this some line with extra styles???
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3873
                if (in_array($i + 1, $this->highlight_extra_lines)) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3874
                    if ($this->use_classes) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3875
                        if (isset($this->highlight_extra_lines_styles[$i])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3876
                            $parsed_code .= "<span class=\"xtra lx$i\">";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3877
                        } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3878
                            $parsed_code .= "<span class=\"xtra ln-xtra\">";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3879
                        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3880
                    } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3881
                        $parsed_code .= "<span style=\"display:block;" . $this->get_line_style($i) . "\">";
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3882
                    }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3883
                    ++$close;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3884
                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3885
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3886
                $parsed_code .= $code[$i];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3887
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3888
                if ($close) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3889
                  $parsed_code .= str_repeat('</span>', $close);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3890
                  $close = 0;
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3891
                }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3892
                elseif ($i + 1 < $n) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3893
                    $parsed_code .= "\n";
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3894
                }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3895
                unset($code[$i]);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3896
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3897
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3898
            if ($this->header_type == GESHI_HEADER_PRE_VALID || $this->header_type == GESHI_HEADER_PRE_TABLE) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3899
                $parsed_code .= '</pre>';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3900
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3901
            if ($this->header_type == GESHI_HEADER_PRE_TABLE && $this->line_numbers != GESHI_NO_LINE_NUMBERS) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3902
                $parsed_code .= '</td>';
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3903
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3904
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3905
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3906
        $parsed_code .= $this->footer();
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3907
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3908
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3909
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3910
     * Creates the header for the code block (with correct attributes)
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3911
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3912
     * @return string The header for the code block
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3913
     * @since  1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3914
     * @access private
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3915
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3916
    function header() {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3917
        // Get attributes needed
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3918
        /**
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3919
         * @todo   Document behaviour change - class is outputted regardless of whether
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3920
         *         we're using classes or not. Same with style
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3921
         */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3922
        $attributes = ' class="' . $this->language;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3923
        if ($this->overall_class != '') {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3924
            $attributes .= " ".$this->overall_class;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3925
        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3926
        $attributes .= '"';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3927
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3928
        if ($this->overall_id != '') {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3929
            $attributes .= " id=\"{$this->overall_id}\"";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3930
        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3931
        if ($this->overall_style != '') {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3932
            $attributes .= ' style="' . $this->overall_style . '"';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3933
        }
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3934
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3935
        $ol_attributes = '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3936
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3937
        if ($this->line_numbers_start != 1) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3938
            $ol_attributes .= ' start="' . $this->line_numbers_start . '"';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3939
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3940
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3941
        // Get the header HTML
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3942
        $header = $this->header_content;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3943
        if ($header) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3944
            if ($this->header_type == GESHI_HEADER_PRE || $this->header_type == GESHI_HEADER_PRE_VALID) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3945
                $header = str_replace("\n", '', $header);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3946
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3947
            $header = $this->replace_keywords($header);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3948
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3949
            if ($this->use_classes) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3950
                $attr = ' class="head"';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3951
            } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3952
                $attr = " style=\"{$this->header_content_style}\"";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3953
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3954
            if ($this->header_type == GESHI_HEADER_PRE_TABLE && $this->line_numbers != GESHI_NO_LINE_NUMBERS) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3955
                $header = "<thead><tr><td colspan=\"2\" $attr>$header</td></tr></thead>";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3956
            } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3957
                $header = "<div$attr>$header</div>";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3958
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3959
        }
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3960
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3961
        if (GESHI_HEADER_NONE == $this->header_type) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3962
            if ($this->line_numbers != GESHI_NO_LINE_NUMBERS) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3963
                return "$header<ol$attributes$ol_attributes>";
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3964
            }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3965
            return $header . ($this->force_code_block ? '<div>' : '');
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3966
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3967
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3968
        // Work out what to return and do it
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3969
        if ($this->line_numbers != GESHI_NO_LINE_NUMBERS) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3970
            if ($this->header_type == GESHI_HEADER_PRE) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3971
                return "<pre$attributes>$header<ol$ol_attributes>";
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3972
            } else if ($this->header_type == GESHI_HEADER_DIV ||
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3973
                $this->header_type == GESHI_HEADER_PRE_VALID) {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3974
                return "<div$attributes>$header<ol$ol_attributes>";
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3975
            } else if ($this->header_type == GESHI_HEADER_PRE_TABLE) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3976
                return "<table$attributes>$header<tbody><tr class=\"li1\">";
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3977
            }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3978
        } else {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3979
            if ($this->header_type == GESHI_HEADER_PRE) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3980
                return "<pre$attributes>$header"  .
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3981
                    ($this->force_code_block ? '<div>' : '');
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  3982
            } else {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3983
                return "<div$attributes>$header" .
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3984
                    ($this->force_code_block ? '<div>' : '');
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3985
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3986
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3987
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3988
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3989
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3990
     * Returns the footer for the code block.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3991
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3992
     * @return string The footer for the code block
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3993
     * @since  1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3994
     * @access private
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3995
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3996
    function footer() {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3997
        $footer = $this->footer_content;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3998
        if ($footer) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  3999
            if ($this->header_type == GESHI_HEADER_PRE) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4000
                $footer = str_replace("\n", '', $footer);;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4001
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4002
            $footer = $this->replace_keywords($footer);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4003
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4004
            if ($this->use_classes) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4005
                $attr = ' class="foot"';
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4006
            } else {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4007
                $attr = " style=\"{$this->footer_content_style}\"";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4008
            }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4009
            if ($this->header_type == GESHI_HEADER_PRE_TABLE && $this->linenumbers != GESHI_NO_LINE_NUMBERS) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4010
                $footer = "<tfoot><tr><td colspan=\"2\">$footer</td></tr></tfoot>";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4011
            } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4012
                $footer = "<div$attr>$footer</div>";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4013
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4014
        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4015
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4016
        if (GESHI_HEADER_NONE == $this->header_type) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4017
            return ($this->line_numbers != GESHI_NO_LINE_NUMBERS) ? '</ol>' . $footer : $footer;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4018
        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4019
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4020
        if ($this->header_type == GESHI_HEADER_DIV || $this->header_type == GESHI_HEADER_PRE_VALID) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4021
            if ($this->line_numbers != GESHI_NO_LINE_NUMBERS) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4022
                return "</ol>$footer</div>";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4023
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4024
            return ($this->force_code_block ? '</div>' : '') .
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4025
                "$footer</div>";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4026
        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4027
        elseif ($this->header_type == GESHI_HEADER_PRE_TABLE) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4028
            if ($this->line_numbers != GESHI_NO_LINE_NUMBERS) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4029
                return "</tr></tbody>$footer</table>";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4030
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4031
            return ($this->force_code_block ? '</div>' : '') .
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4032
                "$footer</div>";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4033
        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4034
        else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4035
            if ($this->line_numbers != GESHI_NO_LINE_NUMBERS) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4036
                return "</ol>$footer</pre>";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4037
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4038
            return ($this->force_code_block ? '</div>' : '') .
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4039
                "$footer</pre>";
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4040
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4041
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4042
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4043
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4044
     * Replaces certain keywords in the header and footer with
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4045
     * certain configuration values
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4046
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4047
     * @param  string The header or footer content to do replacement on
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4048
     * @return string The header or footer with replaced keywords
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4049
     * @since  1.0.2
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4050
     * @access private
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4051
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4052
    function replace_keywords($instr) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4053
        $keywords = $replacements = array();
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4054
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4055
        $keywords[] = '<TIME>';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4056
        $keywords[] = '{TIME}';
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4057
        $replacements[] = $replacements[] = number_format($time = $this->get_time(), 3);
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4058
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4059
        $keywords[] = '<LANGUAGE>';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4060
        $keywords[] = '{LANGUAGE}';
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4061
        $replacements[] = $replacements[] = $this->language_data['LANG_NAME'];
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4062
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4063
        $keywords[] = '<VERSION>';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4064
        $keywords[] = '{VERSION}';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4065
        $replacements[] = $replacements[] = GESHI_VERSION;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4066
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4067
        $keywords[] = '<SPEED>';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4068
        $keywords[] = '{SPEED}';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4069
        if ($time <= 0) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4070
            $speed = 'N/A';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4071
        } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4072
            $speed = strlen($this->source) / $time;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4073
            if ($speed >= 1024) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4074
                $speed = sprintf("%.2f KB/s", $speed / 1024.0);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4075
            } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4076
                $speed = sprintf("%.0f B/s", $speed);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4077
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4078
        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4079
        $replacements[] = $replacements[] = $speed;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4080
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4081
        return str_replace($keywords, $replacements, $instr);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4082
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4083
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4084
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4085
     * Secure replacement for PHP built-in function htmlspecialchars().
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4086
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4087
     * See ticket #427 (http://wush.net/trac/wikka/ticket/427) for the rationale
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4088
     * for this replacement function.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4089
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4090
     * The INTERFACE for this function is almost the same as that for
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4091
     * htmlspecialchars(), with the same default for quote style; however, there
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4092
     * is no 'charset' parameter. The reason for this is as follows:
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4093
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4094
     * The PHP docs say:
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4095
     *      "The third argument charset defines character set used in conversion."
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4096
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4097
     * I suspect PHP's htmlspecialchars() is working at the byte-value level and
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4098
     * thus _needs_ to know (or asssume) a character set because the special
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4099
     * characters to be replaced could exist at different code points in
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4100
     * different character sets. (If indeed htmlspecialchars() works at
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4101
     * byte-value level that goes some  way towards explaining why the
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4102
     * vulnerability would exist in this function, too, and not only in
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4103
     * htmlentities() which certainly is working at byte-value level.)
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4104
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4105
     * This replacement function however works at character level and should
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4106
     * therefore be "immune" to character set differences - so no charset
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4107
     * parameter is needed or provided. If a third parameter is passed, it will
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4108
     * be silently ignored.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4109
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4110
     * In the OUTPUT there is a minor difference in that we use '&#39;' instead
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4111
     * of PHP's '&#039;' for a single quote: this provides compatibility with
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4112
     *      get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES)
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4113
     * (see comment by mikiwoz at yahoo dot co dot uk on
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4114
     * http://php.net/htmlspecialchars); it also matches the entity definition
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4115
     * for XML 1.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4116
     * (http://www.w3.org/TR/xhtml1/dtds.html#a_dtd_Special_characters).
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4117
     * Like PHP we use a numeric character reference instead of '&apos;' for the
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4118
     * single quote. For the other special characters we use the named entity
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4119
     * references, as PHP is doing.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4120
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4121
     * @author      {@link http://wikkawiki.org/JavaWoman Marjolein Katsma}
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4122
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4123
     * @license     http://www.gnu.org/copyleft/lgpl.html
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4124
     *              GNU Lesser General Public License
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4125
     * @copyright   Copyright 2007, {@link http://wikkawiki.org/CreditsPage
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4126
     *              Wikka Development Team}
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4127
     *
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4128
     * @access      private
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4129
     * @param       string  $string string to be converted
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4130
     * @param       integer $quote_style
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4131
     *                      - ENT_COMPAT:   escapes &, <, > and double quote (default)
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4132
     *                      - ENT_NOQUOTES: escapes only &, < and >
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4133
     *                      - ENT_QUOTES:   escapes &, <, >, double and single quotes
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4134
     * @return      string  converted string
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4135
     * @since       1.0.7.18
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4136
     */
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4137
    function hsc($string, $quote_style = ENT_COMPAT) {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4138
        // init
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4139
        static $aTransSpecchar = array(
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4140
            '&' => '&amp;',
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4141
            '"' => '&quot;',
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4142
            '<' => '&lt;',
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4143
            '>' => '&gt;',
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4144
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4145
            //This fix is related to SF#1923020, but has to be applied
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4146
            //regardless of actually highlighting symbols.
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4147
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4148
            //Circumvent a bug with symbol highlighting
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4149
            //This is required as ; would produce undesirable side-effects if it
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4150
            //was not to be processed as an entity.
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4151
            ';' => '<SEMI>', // Force ; to be processed as entity
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4152
            '|' => '<PIPE>' // Force | to be processed as entity
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4153
            );                      // ENT_COMPAT set
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4154
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4155
        switch ($quote_style) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4156
            case ENT_NOQUOTES: // don't convert double quotes
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4157
                unset($aTransSpecchar['"']);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4158
                break;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4159
            case ENT_QUOTES: // convert single quotes as well
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4160
                $aTransSpecchar["'"] = '&#39;'; // (apos) htmlspecialchars() uses '&#039;'
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4161
                break;
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4162
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4163
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4164
        // return translated string
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4165
        return strtr($string, $aTransSpecchar);
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4166
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4167
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4168
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4169
     * Returns a stylesheet for the highlighted code. If $economy mode
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4170
     * is true, we only return the stylesheet declarations that matter for
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4171
     * this code block instead of the whole thing
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4172
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4173
     * @param  boolean Whether to use economy mode or not
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4174
     * @return string A stylesheet built on the data for the current language
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4175
     * @since  1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4176
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4177
    function get_stylesheet($economy_mode = true) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4178
        // If there's an error, chances are that the language file
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4179
        // won't have populated the language data file, so we can't
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4180
        // risk getting a stylesheet...
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4181
        if ($this->error) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4182
            return '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4183
        }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4184
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4185
        //Check if the style rearrangements have been processed ...
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4186
        //This also does some preprocessing to check which style groups are useable ...
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4187
        if(!isset($this->language_data['NUMBERS_CACHE'])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4188
            $this->build_style_cache();
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4189
        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4190
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4191
        // First, work out what the selector should be. If there's an ID,
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4192
        // that should be used, the same for a class. Otherwise, a selector
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4193
        // of '' means that these styles will be applied anywhere
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4194
        if ($this->overall_id) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4195
            $selector = '#' . $this->overall_id;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4196
        } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4197
            $selector = '.' . $this->language;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4198
            if ($this->overall_class) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4199
                $selector .= '.' . $this->overall_class;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4200
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4201
        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4202
        $selector .= ' ';
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4203
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4204
        // Header of the stylesheet
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4205
        if (!$economy_mode) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4206
            $stylesheet = "/**\n".
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4207
                " * GeSHi Dynamically Generated Stylesheet\n".
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4208
                " * --------------------------------------\n".
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4209
                " * Dynamically generated stylesheet for {$this->language}\n".
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4210
                " * CSS class: {$this->overall_class}, CSS id: {$this->overall_id}\n".
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4211
                " * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann\n" .
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4212
                " * (http://qbnz.com/highlighter/ and http://geshi.org/)\n".
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4213
                " * --------------------------------------\n".
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4214
                " */\n";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4215
        } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4216
            $stylesheet = "/**\n".
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4217
                " * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann\n" .
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4218
                " * (http://qbnz.com/highlighter/ and http://geshi.org/)\n".
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4219
                " */\n";
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4220
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4221
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4222
        // Set the <ol> to have no effect at all if there are line numbers
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4223
        // (<ol>s have margins that should be destroyed so all layout is
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4224
        // controlled by the set_overall_style method, which works on the
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4225
        // <pre> or <div> container). Additionally, set default styles for lines
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4226
        if (!$economy_mode || $this->line_numbers != GESHI_NO_LINE_NUMBERS) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4227
            //$stylesheet .= "$selector, {$selector}ol, {$selector}ol li {margin: 0;}\n";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4228
            $stylesheet .= "$selector.de1, $selector.de2 {{$this->code_style}}\n";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4229
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4230
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4231
        // Add overall styles
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4232
        // note: neglect economy_mode, empty styles are meaningless
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4233
        if ($this->overall_style != '') {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4234
            $stylesheet .= "$selector {{$this->overall_style}}\n";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4235
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4236
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4237
        // Add styles for links
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4238
        // note: economy mode does not make _any_ sense here
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4239
        //       either the style is empty and thus no selector is needed
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4240
        //       or the appropriate key is given.
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4241
        foreach ($this->link_styles as $key => $style) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4242
            if ($style != '') {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4243
                switch ($key) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4244
                    case GESHI_LINK:
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4245
                        $stylesheet .= "{$selector}a:link {{$style}}\n";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4246
                        break;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4247
                    case GESHI_HOVER:
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4248
                        $stylesheet .= "{$selector}a:hover {{$style}}\n";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4249
                        break;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4250
                    case GESHI_ACTIVE:
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4251
                        $stylesheet .= "{$selector}a:active {{$style}}\n";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4252
                        break;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4253
                    case GESHI_VISITED:
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4254
                        $stylesheet .= "{$selector}a:visited {{$style}}\n";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4255
                        break;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4256
                }
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4257
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4258
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4259
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4260
        // Header and footer
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4261
        // note: neglect economy_mode, empty styles are meaningless
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4262
        if ($this->header_content_style != '') {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4263
            $stylesheet .= "$selector.head {{$this->header_content_style}}\n";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4264
        }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4265
        if ($this->footer_content_style != '') {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4266
            $stylesheet .= "$selector.foot {{$this->footer_content_style}}\n";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4267
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4268
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4269
        // Styles for important stuff
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4270
        // note: neglect economy_mode, empty styles are meaningless
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4271
        if ($this->important_styles != '') {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4272
            $stylesheet .= "$selector.imp {{$this->important_styles}}\n";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4273
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4274
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4275
        // Simple line number styles
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4276
        if ((!$economy_mode || $this->line_numbers != GESHI_NO_LINE_NUMBERS) && $this->line_style1 != '') {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4277
            $stylesheet .= "{$selector}li, {$selector}.li1 {{$this->line_style1}}\n";
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4278
        }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4279
        if ((!$economy_mode || $this->line_numbers != GESHI_NO_LINE_NUMBERS) && $this->table_linenumber_style != '') {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4280
            $stylesheet .= "{$selector}.ln {{$this->table_linenumber_style}}\n";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4281
        }
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4282
        // If there is a style set for fancy line numbers, echo it out
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4283
        if ((!$economy_mode || $this->line_numbers == GESHI_FANCY_LINE_NUMBERS) && $this->line_style2 != '') {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4284
            $stylesheet .= "{$selector}.li2 {{$this->line_style2}}\n";
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4285
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4286
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4287
        // note: empty styles are meaningless
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4288
        foreach ($this->language_data['STYLES']['KEYWORDS'] as $group => $styles) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4289
            if ($styles != '' && (!$economy_mode ||
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4290
                (isset($this->lexic_permissions['KEYWORDS'][$group]) &&
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4291
                $this->lexic_permissions['KEYWORDS'][$group]))) {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4292
                $stylesheet .= "$selector.kw$group {{$styles}}\n";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4293
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4294
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4295
        foreach ($this->language_data['STYLES']['COMMENTS'] as $group => $styles) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4296
            if ($styles != '' && (!$economy_mode ||
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4297
                (isset($this->lexic_permissions['COMMENTS'][$group]) &&
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4298
                $this->lexic_permissions['COMMENTS'][$group]) ||
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4299
                (!empty($this->language_data['COMMENT_REGEXP']) &&
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4300
                !empty($this->language_data['COMMENT_REGEXP'][$group])))) {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4301
                $stylesheet .= "$selector.co$group {{$styles}}\n";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4302
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4303
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4304
        foreach ($this->language_data['STYLES']['ESCAPE_CHAR'] as $group => $styles) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4305
            if ($styles != '' && (!$economy_mode || $this->lexic_permissions['ESCAPE_CHAR'])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4306
                // NEW: since 1.0.8 we have to handle hardescapes
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4307
                if ($group === 'HARD') {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4308
                    $group = '_h';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4309
                }
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4310
                $stylesheet .= "$selector.es$group {{$styles}}\n";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4311
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4312
        }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4313
        foreach ($this->language_data['STYLES']['BRACKETS'] as $group => $styles) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4314
            if ($styles != '' && (!$economy_mode || $this->lexic_permissions['BRACKETS'])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4315
                $stylesheet .= "$selector.br$group {{$styles}}\n";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4316
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4317
        }
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4318
        foreach ($this->language_data['STYLES']['SYMBOLS'] as $group => $styles) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4319
            if ($styles != '' && (!$economy_mode || $this->lexic_permissions['SYMBOLS'])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4320
                $stylesheet .= "$selector.sy$group {{$styles}}\n";
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4321
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4322
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4323
        foreach ($this->language_data['STYLES']['STRINGS'] as $group => $styles) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4324
            if ($styles != '' && (!$economy_mode || $this->lexic_permissions['STRINGS'])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4325
                // NEW: since 1.0.8 we have to handle hardquotes
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4326
                if ($group === 'HARD') {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4327
                    $group = '_h';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4328
                }
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4329
                $stylesheet .= "$selector.st$group {{$styles}}\n";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4330
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4331
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4332
        foreach ($this->language_data['STYLES']['NUMBERS'] as $group => $styles) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4333
            if ($styles != '' && (!$economy_mode || $this->lexic_permissions['NUMBERS'])) {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4334
                $stylesheet .= "$selector.nu$group {{$styles}}\n";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4335
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4336
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4337
        foreach ($this->language_data['STYLES']['METHODS'] as $group => $styles) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4338
            if ($styles != '' && (!$economy_mode || $this->lexic_permissions['METHODS'])) {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4339
                $stylesheet .= "$selector.me$group {{$styles}}\n";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4340
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4341
        }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4342
        // note: neglect economy_mode, empty styles are meaningless
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4343
        foreach ($this->language_data['STYLES']['SCRIPT'] as $group => $styles) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4344
            if ($styles != '') {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4345
                $stylesheet .= "$selector.sc$group {{$styles}}\n";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4346
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4347
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4348
        foreach ($this->language_data['STYLES']['REGEXPS'] as $group => $styles) {
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4349
            if ($styles != '' && (!$economy_mode ||
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4350
                (isset($this->lexic_permissions['REGEXPS'][$group]) &&
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4351
                $this->lexic_permissions['REGEXPS'][$group]))) {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4352
                if (is_array($this->language_data['REGEXPS'][$group]) &&
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4353
                    array_key_exists(GESHI_CLASS, $this->language_data['REGEXPS'][$group])) {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4354
                    $stylesheet .= "$selector.";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4355
                    $stylesheet .= $this->language_data['REGEXPS'][$group][GESHI_CLASS];
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4356
                    $stylesheet .= " {{$styles}}\n";
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4357
                } else {
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4358
                    $stylesheet .= "$selector.re$group {{$styles}}\n";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4359
                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4360
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4361
        }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4362
        // Styles for lines being highlighted extra
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4363
        if (!$economy_mode || (count($this->highlight_extra_lines)!=count($this->highlight_extra_lines_styles))) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4364
            $stylesheet .= "{$selector}.ln-xtra, {$selector}li.ln-xtra, {$selector}div.ln-xtra {{$this->highlight_extra_lines_style}}\n";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4365
        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4366
        $stylesheet .= "{$selector}span.xtra { display:block; }\n";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4367
        foreach ($this->highlight_extra_lines_styles as $lineid => $linestyle) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4368
            $stylesheet .= "{$selector}.lx$lineid, {$selector}li.lx$lineid, {$selector}div.lx$lineid {{$linestyle}}\n";
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4369
        }
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4370
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4371
        return $stylesheet;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4372
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4373
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4374
    /**
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4375
     * Get's the style that is used for the specified line
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4376
     *
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4377
     * @param int The line number information is requested for
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4378
     * @access private
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4379
     * @since 1.0.7.21
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4380
     */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4381
    function get_line_style($line) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4382
        //$style = null;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4383
        $style = null;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4384
        if (isset($this->highlight_extra_lines_styles[$line])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4385
            $style = $this->highlight_extra_lines_styles[$line];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4386
        } else { // if no "extra" style assigned
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4387
            $style = $this->highlight_extra_lines_style;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4388
        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4389
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4390
        return $style;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4391
    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4392
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4393
    /**
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4394
    * this functions creates an optimized regular expression list
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4395
    * of an array of strings.
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4396
    *
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4397
    * Example:
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4398
    * <code>$list = array('faa', 'foo', 'foobar');
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4399
    *          => string 'f(aa|oo(bar)?)'</code>
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4400
    *
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4401
    * @param $list array of (unquoted) strings
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4402
    * @param $regexp_delimiter your regular expression delimiter, @see preg_quote()
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4403
    * @return string for regular expression
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4404
    * @author Milian Wolff <mail@milianw.de>
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4405
    * @since 1.0.8
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4406
    * @access private
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4407
    */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4408
    function optimize_regexp_list($list, $regexp_delimiter = '/') {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4409
        $regex_chars = array('.', '\\', '+', '*', '?', '[', '^', ']', '$',
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4410
            '(', ')', '{', '}', '=', '!', '<', '>', '|', ':', $regexp_delimiter);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4411
        sort($list);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4412
        $regexp_list = array('');
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4413
        $num_subpatterns = 0;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4414
        $list_key = 0;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4415
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4416
        // the tokens which we will use to generate the regexp list
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4417
        $tokens = array();
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4418
        $prev_keys = array();
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4419
        // go through all entries of the list and generate the token list
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4420
        $cur_len = 0;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4421
        for ($i = 0, $i_max = count($list); $i < $i_max; ++$i) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4422
            if ($cur_len > GESHI_MAX_PCRE_LENGTH) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4423
                // seems like the length of this pcre is growing exorbitantly
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4424
                $regexp_list[++$list_key] = $this->_optimize_regexp_list_tokens_to_string($tokens);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4425
                $num_subpatterns = substr_count($regexp_list[$list_key], '(?:');
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4426
                $tokens = array();
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4427
                $cur_len = 0;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4428
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4429
            $level = 0;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4430
            $entry = preg_quote((string) $list[$i], $regexp_delimiter);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4431
            $pointer = &$tokens;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4432
            // properly assign the new entry to the correct position in the token array
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4433
            // possibly generate smaller common denominator keys
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4434
            while (true) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4435
                // get the common denominator
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4436
                if (isset($prev_keys[$level])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4437
                    if ($prev_keys[$level] == $entry) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4438
                        // this is a duplicate entry, skip it
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4439
                        continue 2;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4440
                    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4441
                    $char = 0;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4442
                    while (isset($entry[$char]) && isset($prev_keys[$level][$char])
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4443
                            && $entry[$char] == $prev_keys[$level][$char]) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4444
                        ++$char;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4445
                    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4446
                    if ($char > 0) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4447
                        // this entry has at least some chars in common with the current key
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4448
                        if ($char == strlen($prev_keys[$level])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4449
                            // current key is totally matched, i.e. this entry has just some bits appended
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4450
                            $pointer = &$pointer[$prev_keys[$level]];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4451
                        } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4452
                            // only part of the keys match
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4453
                            $new_key_part1 = substr($prev_keys[$level], 0, $char);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4454
                            $new_key_part2 = substr($prev_keys[$level], $char);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4455
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4456
                            if (in_array($new_key_part1[0], $regex_chars)
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4457
                                || in_array($new_key_part2[0], $regex_chars)) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4458
                                // this is bad, a regex char as first character
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4459
                                $pointer[$entry] = array('' => true);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4460
                                array_splice($prev_keys, $level, count($prev_keys), $entry);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4461
                                $cur_len += strlen($entry);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4462
                                continue;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4463
                            } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4464
                                // relocate previous tokens
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4465
                                $pointer[$new_key_part1] = array($new_key_part2 => $pointer[$prev_keys[$level]]);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4466
                                unset($pointer[$prev_keys[$level]]);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4467
                                $pointer = &$pointer[$new_key_part1];
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4468
                                // recreate key index
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4469
                                array_splice($prev_keys, $level, count($prev_keys), array($new_key_part1, $new_key_part2));
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4470
                                $cur_len += strlen($new_key_part2);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4471
                            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4472
                        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4473
                        ++$level;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4474
                        $entry = substr($entry, $char);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4475
                        continue;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4476
                    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4477
                    // else: fall trough, i.e. no common denominator was found
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4478
                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4479
                if ($level == 0 && !empty($tokens)) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4480
                    // we can dump current tokens into the string and throw them away afterwards
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4481
                    $new_entry = $this->_optimize_regexp_list_tokens_to_string($tokens);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4482
                    $new_subpatterns = substr_count($new_entry, '(?:');
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4483
                    if (GESHI_MAX_PCRE_SUBPATTERNS && $num_subpatterns + $new_subpatterns > GESHI_MAX_PCRE_SUBPATTERNS) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4484
                        $regexp_list[++$list_key] = $new_entry;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4485
                        $num_subpatterns = $new_subpatterns;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4486
                    } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4487
                        if (!empty($regexp_list[$list_key])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4488
                            $new_entry = '|' . $new_entry;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4489
                        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4490
                        $regexp_list[$list_key] .= $new_entry;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4491
                        $num_subpatterns += $new_subpatterns;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4492
                    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4493
                    $tokens = array();
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4494
                    $cur_len = 0;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4495
                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4496
                // no further common denominator found
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4497
                $pointer[$entry] = array('' => true);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4498
                array_splice($prev_keys, $level, count($prev_keys), $entry);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4499
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4500
                $cur_len += strlen($entry);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4501
                break;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4502
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4503
            unset($list[$i]);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4504
        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4505
        // make sure the last tokens get converted as well
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4506
        $new_entry = $this->_optimize_regexp_list_tokens_to_string($tokens);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4507
        if (GESHI_MAX_PCRE_SUBPATTERNS && $num_subpatterns + substr_count($new_entry, '(?:') > GESHI_MAX_PCRE_SUBPATTERNS) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4508
            $regexp_list[++$list_key] = $new_entry;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4509
        } else {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4510
            if (!empty($regexp_list[$list_key])) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4511
                $new_entry = '|' . $new_entry;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4512
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4513
            $regexp_list[$list_key] .= $new_entry;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4514
        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4515
        return $regexp_list;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4516
    }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4517
    /**
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4518
    * this function creates the appropriate regexp string of an token array
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4519
    * you should not call this function directly, @see $this->optimize_regexp_list().
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4520
    *
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4521
    * @param &$tokens array of tokens
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4522
    * @param $recursed bool to know wether we recursed or not
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4523
    * @return string
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4524
    * @author Milian Wolff <mail@milianw.de>
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4525
    * @since 1.0.8
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4526
    * @access private
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4527
    */
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4528
    function _optimize_regexp_list_tokens_to_string(&$tokens, $recursed = false) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4529
        $list = '';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4530
        foreach ($tokens as $token => $sub_tokens) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4531
            $list .= $token;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4532
            $close_entry = isset($sub_tokens['']);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4533
            unset($sub_tokens['']);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4534
            if (!empty($sub_tokens)) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4535
                $list .= '(?:' . $this->_optimize_regexp_list_tokens_to_string($sub_tokens, true) . ')';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4536
                if ($close_entry) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4537
                    // make sub_tokens optional
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4538
                    $list .= '?';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4539
                }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4540
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4541
            $list .= '|';
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4542
        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4543
        if (!$recursed) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4544
            // do some optimizations
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4545
            // common trailing strings
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4546
            // BUGGY!
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4547
            //$list = preg_replace_callback('#(?<=^|\:|\|)\w+?(\w+)(?:\|.+\1)+(?=\|)#', create_function(
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4548
            //    '$matches', 'return "(?:" . preg_replace("#" . preg_quote($matches[1], "#") . "(?=\||$)#", "", $matches[0]) . ")" . $matches[1];'), $list);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4549
            // (?:p)? => p?
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4550
            $list = preg_replace('#\(\?\:(.)\)\?#', '\1?', $list);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4551
            // (?:a|b|c|d|...)? => [abcd...]?
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4552
            // TODO: a|bb|c => [ac]|bb
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4553
            static $callback_2;
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4554
            if (!isset($callback_2)) {
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4555
                $callback_2 = create_function('$matches', 'return "[" . str_replace("|", "", $matches[1]) . "]";');
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4556
            }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4557
            $list = preg_replace_callback('#\(\?\:((?:.\|)+.)\)#', $callback_2, $list);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4558
        }
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4559
        // return $list without trailing pipe
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4560
        return substr($list, 0, -1);
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4561
    }
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4562
} // End Class GeSHi
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4563
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4564
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4565
if (!function_exists('geshi_highlight')) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4566
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4567
     * Easy way to highlight stuff. Behaves just like highlight_string
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4568
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4569
     * @param string The code to highlight
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4570
     * @param string The language to highlight the code in
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4571
     * @param string The path to the language files. You can leave this blank if you need
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4572
     *               as from version 1.0.7 the path should be automatically detected
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4573
     * @param boolean Whether to return the result or to echo
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4574
     * @return string The code highlighted (if $return is true)
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4575
     * @since 1.0.2
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4576
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4577
    function geshi_highlight($string, $language, $path = null, $return = false) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4578
        $geshi = new GeSHi($string, $language, $path);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4579
        $geshi->set_header_type(GESHI_HEADER_NONE);
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4580
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4581
        if ($return) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4582
            return '<code>' . $geshi->parse_code() . '</code>';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4583
        }
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4584
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4585
        echo '<code>' . $geshi->parse_code() . '</code>';
2
9e3258dfae15 Updated GeSHi. w00t.
Dan
parents: 0
diff changeset
  4586
0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4587
        if ($geshi->error()) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4588
            return false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4589
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4590
        return true;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4591
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4592
}
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4593
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  4594
?>