plugins/geshi/base.php
author Dan
Sun, 10 Feb 2008 18:10:52 -0500
changeset 0 441963e5b07a
child 2 9e3258dfae15
permissions -rw-r--r--
Initial population - based on GeSHi 1.0.7.20
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
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    30
 * @author     Nigel McNie <nigel@geshi.org>
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    31
 * @copyright  (C) 2004 - 2007 Nigel McNie
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 */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    44
define('GESHI_VERSION', '1.0.7.20');
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
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    55
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    56
// Line numbers - use with enable_line_numbers()
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    57
/** Use no line numbers when building the result */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    58
define('GESHI_NO_LINE_NUMBERS', 0);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    59
/** Use normal line numbers when building the result */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    60
define('GESHI_NORMAL_LINE_NUMBERS', 1);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    61
/** Use fancy line numbers when building the result */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    62
define('GESHI_FANCY_LINE_NUMBERS', 2);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    63
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    64
// Container HTML type
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    65
/** Use nothing to surround the source */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    66
define('GESHI_HEADER_NONE', 0);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    67
/** Use a "div" to surround the source */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    68
define('GESHI_HEADER_DIV', 1);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    69
/** Use a "pre" to surround the source */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    70
define('GESHI_HEADER_PRE', 2);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    71
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    72
// Capatalisation constants
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    73
/** Lowercase keywords found */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    74
define('GESHI_CAPS_NO_CHANGE', 0);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    75
/** Uppercase keywords found */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    76
define('GESHI_CAPS_UPPER', 1);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    77
/** Leave keywords found as the case that they are */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    78
define('GESHI_CAPS_LOWER', 2);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    79
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    80
// Link style constants
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    81
/** Links in the source in the :link state */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    82
define('GESHI_LINK', 0);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    83
/** Links in the source in the :hover state */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    84
define('GESHI_HOVER', 1);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    85
/** Links in the source in the :active state */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    86
define('GESHI_ACTIVE', 2);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    87
/** Links in the source in the :visited state */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    88
define('GESHI_VISITED', 3);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    89
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    90
// Important string starter/finisher
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    91
// 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
    92
// write them as if they had been run through htmlentities()
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    93
/** The starter for important parts of the source */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    94
define('GESHI_START_IMPORTANT', '<BEGIN GeSHi>');
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    95
/** The ender for important parts of the source */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    96
define('GESHI_END_IMPORTANT', '<END GeSHi>');
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    97
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    98
/**#@+
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
    99
 *  @access private
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
// When strict mode applies for a language
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   102
/** Strict mode never applies (this is the most common) */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   103
define('GESHI_NEVER', 0);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   104
/** Strict mode *might* apply, and can be enabled or
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   105
    disabled by {@link GeSHi::enable_strict_mode()} */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   106
define('GESHI_MAYBE', 1);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   107
/** Strict mode always applies */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   108
define('GESHI_ALWAYS', 2);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   109
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   110
// Advanced regexp handling constants, used in language files
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   111
/** 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
   112
define('GESHI_SEARCH', 0);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   113
/** 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
   114
    matched search to use as a replacement */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   115
define('GESHI_REPLACE', 1);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   116
/** 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
   117
define('GESHI_MODIFIERS', 2);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   118
/** 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
   119
    matched search to put before the replacement */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   120
define('GESHI_BEFORE', 3);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   121
/** 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
   122
    matched search to put after the replacement */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   123
define('GESHI_AFTER', 4);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   124
/** 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
   125
    for this regexp's html tag class */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   126
define('GESHI_CLASS', 5);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   127
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   128
/** Used in language files to mark comments */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   129
define('GESHI_COMMENTS', 0);
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
// Error detection - use these to analyse faults
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   132
/** No sourcecode to highlight was specified
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   133
 * @deprecated
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   134
 */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   135
define('GESHI_ERROR_NO_INPUT', 1);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   136
/** The language specified does not exist */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   137
define('GESHI_ERROR_NO_SUCH_LANG', 2);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   138
/** 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
   139
define('GESHI_ERROR_FILE_NOT_READABLE', 3);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   140
/** The header type passed to {@link GeSHi::set_header_type()} was invalid */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   141
define('GESHI_ERROR_INVALID_HEADER_TYPE', 4);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   142
/** The line number type passed to {@link GeSHi::enable_line_numbers()} was invalid */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   143
define('GESHI_ERROR_INVALID_LINE_NUMBER_TYPE', 5);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   144
/**#@-*/
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   145
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   146
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   147
/**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   148
 * The GeSHi Class.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   149
 *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   150
 * 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
   151
 * at http://qbnz.com/highlighter/documentation.php for more information
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   152
 * about how to use this class.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   153
 *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   154
 * @package   geshi
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   155
 * @author    Nigel McNie <nigel@geshi.org>
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   156
 * @copyright (C) 2004 - 2007 Nigel McNie
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   157
 */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   158
class GeSHi {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   159
    /**#@+
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   160
     * @access private
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   161
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   162
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   163
     * The source code to highlight
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   164
     * @var string
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   165
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   166
    var $source = '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   167
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   168
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   169
     * The language to use when highlighting
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   170
     * @var string
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   171
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   172
    var $language = '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   173
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   174
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   175
     * The data for the language used
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   176
     * @var array
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   177
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   178
    var $language_data = array();
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   179
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   180
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   181
     * The path to the language files
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   182
     * @var string
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   183
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   184
    var $language_path = GESHI_LANG_ROOT;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   185
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   186
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   187
     * The error message associated with an error
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   188
     * @var string
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   189
     * @todo check err reporting works
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   190
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   191
    var $error = false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   192
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   193
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   194
     * Possible error messages
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   195
     * @var array
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   196
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   197
    var $error_messages = array(
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   198
        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
   199
        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
   200
        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
   201
        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
   202
    );
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   203
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   204
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   205
     * Whether highlighting is strict or not
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   206
     * @var boolean
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   207
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   208
    var $strict_mode = false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   209
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   210
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   211
     * Whether to use CSS classes in output
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   212
     * @var boolean
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   213
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   214
    var $use_classes = false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   215
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   216
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   217
     * 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
   218
     * values:
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   219
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   220
     * - 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
   221
     * - 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
   222
     * - GESHI_HEADER_NONE: No header is outputted.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   223
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   224
     * @var int
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   225
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   226
    var $header_type = GESHI_HEADER_PRE;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   227
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   228
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   229
     * Array of permissions for which lexics should be highlighted
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   230
     * @var array
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   231
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   232
    var $lexic_permissions = array(
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   233
        'KEYWORDS' =>    array(),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   234
        'COMMENTS' =>    array('MULTI' => true),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   235
        'REGEXPS' =>     array(),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   236
        'ESCAPE_CHAR' => true,
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   237
        'BRACKETS' =>    true,
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   238
        'SYMBOLS' =>     true,
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   239
        'STRINGS' =>     true,
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   240
        'NUMBERS' =>     true,
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   241
        'METHODS' =>     true,
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   242
        'SCRIPT' =>      true
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   243
    );
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
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   246
     * The time it took to parse the code
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   247
     * @var double
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
    var $time = 0;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   250
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   251
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   252
     * The content of the header block
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   253
     * @var string
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
    var $header_content = '';
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 content of the footer block
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 $footer_content = '';
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 style of the header block
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 $header_content_style = '';
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 style of the footer block
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   271
     * @var string
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 $footer_content_style = '';
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
     * 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
   277
     * if not using line numbering
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   278
     * @var boolean
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   279
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   280
    var $force_code_block = false;
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
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   283
     * The styles for hyperlinks in the code
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   284
     * @var array
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 $link_styles = array();
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
     * Whether important blocks should be recognised or not
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   290
     * @var boolean
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   291
     * @deprecated
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   292
     * @todo REMOVE THIS FUNCTIONALITY!
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   293
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   294
    var $enable_important_blocks = false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   295
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   296
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   297
     * Styles for important parts of the code
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   298
     * @var string
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   299
     * @deprecated
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   300
     * @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
   301
     * will be hard to implement in 1.2
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 $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
   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 CSS IDs should be added to the code
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 $add_ids = 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
     * Lines that should be highlighted extra
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   313
     * @var array
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
    var $highlight_extra_lines = array();
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   316
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   317
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   318
     * Styles of extra-highlighted lines
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   319
     * @var string
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 $highlight_extra_lines_style = 'color: #cc0; background-color: #ffc;';
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
	 * The line ending
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   325
	 * If null, nl2br() will be used on the result string.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   326
	 * Otherwise, all instances of \n will be replaced with $line_ending
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   327
	 * @var string
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   328
	 */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   329
	var $line_ending = null;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   330
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   331
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   332
     * Number at which line numbers should start at
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   333
     * @var int
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   334
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   335
    var $line_numbers_start = 1;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   336
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   337
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   338
     * The overall style for this code block
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   339
     * @var string
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
    var $overall_style = '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   342
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
     *  The style for the actual code
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   345
     * @var string
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
    var $code_style = 'font-family: \'Courier New\', Courier, monospace; font-weight: normal;';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   348
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
     * The overall class for this code block
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   351
     * @var string
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
    var $overall_class = '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   354
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
     * The overall ID for this code block
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   357
     * @var string
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
    var $overall_id = '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   360
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
     * Line number styles
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   363
     * @var string
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
    var $line_style1 = 'font-family: \'Courier New\', Courier, monospace; color: black; font-weight: normal; font-style: normal;';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   366
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
     * Line number styles for fancy lines
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   369
     * @var string
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
    var $line_style2 = 'font-weight: bold;';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   372
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   373
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   374
     * Flag for how line nubmers are displayed
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   375
     * @var boolean
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
    var $line_numbers = GESHI_NO_LINE_NUMBERS;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   378
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   379
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   380
     * The "nth" value for fancy line highlighting
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   381
     * @var int
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
    var $line_nth_row = 0;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   384
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   385
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   386
     * The size of tab stops
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   387
     * @var int
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 $tab_width = 8;
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
	 * Should we use language-defined tab stop widths?
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   393
	 * @var int
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   394
	 */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   395
	var $use_language_tab_width = false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   396
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
     * Default target for keyword links
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   399
     * @var string
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
    var $link_target = '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   402
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
     * The encoding to use for entity encoding
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   405
     * NOTE: no longer used
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   406
     * @var string
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   407
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   408
    var $encoding = 'ISO-8859-1';
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
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   411
     * Should keywords be linked?
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   412
     * @var boolean
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   413
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   414
    var $keyword_links = true;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   415
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   416
    /**#@-*/
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   417
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   418
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   419
     * Creates a new GeSHi object, with source and language
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   420
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   421
     * @param string The source code to highlight
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   422
     * @param string The language to highlight the source with
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   423
     * @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
   424
     *               is deprecated!</b> I've backported the auto path
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   425
     *               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
   426
     *               should be automatically set correctly. If you have
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   427
     *               renamed the language directory however, you will
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   428
     *               still need to set the path using this parameter or
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   429
     *               {@link GeSHi::set_language_path()}
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   430
     * @since 1.0.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
    function GeSHi($source, $language, $path = '') {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   433
        $this->set_source($source);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   434
        $this->set_language_path($path);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   435
        $this->set_language($language);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   436
    }
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
     * Returns an error message associated with the last GeSHi operation,
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   440
     * or false if no error has occured
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   441
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   442
     * @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
   443
     * @since  1.0.0
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
    function error() {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   446
        if ($this->error) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   447
            $msg = $this->error_messages[$this->error];
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   448
            $debug_tpl_vars = array(
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   449
                '{LANGUAGE}' => $this->language,
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   450
                '{PATH}' => $this->language_path
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   451
            );
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   452
            foreach ($debug_tpl_vars as $tpl => $var) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   453
                $msg = str_replace($tpl, $var, $msg);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   454
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   455
            return "<br /><strong>GeSHi Error:</strong> $msg (code $this->error)<br />";
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
        return false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   458
    }
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
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   461
     * Gets a human-readable language name (thanks to Simon Patterson
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   462
     * for the idea :))
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   463
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   464
     * @return string The name for the current language
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   465
     * @since  1.0.2
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   466
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   467
    function get_language_name() {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   468
        if (GESHI_ERROR_NO_SUCH_LANG == $this->error) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   469
            return $this->language_data['LANG_NAME'] . ' (Unknown Language)';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   470
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   471
        return $this->language_data['LANG_NAME'];
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   472
    }
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
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   475
     * Sets the source code for this object
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   476
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   477
     * @param string The source code to highlight
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   478
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   479
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   480
    function set_source($source) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   481
        $this->source = $source;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   482
        $this->highlight_extra_lines = array();
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
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
     * Sets the language for this object
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   487
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   488
     * @param string The name of the language to use
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   489
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   490
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   491
    function set_language($language) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   492
        $this->error = false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   493
        $this->strict_mode = GESHI_NEVER;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   494
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   495
        $language = preg_replace('#[^a-zA-Z0-9\-_]#', '', $language);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   496
        $this->language = strtolower($language);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   497
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   498
        $file_name = $this->language_path . $this->language . '.php';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   499
        if (!is_readable($file_name)) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   500
            $this->error = GESHI_ERROR_NO_SUCH_LANG;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   501
            return;
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
        // Load the language for parsing
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   504
        $this->load_language($file_name);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   505
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   506
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   507
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   508
     * 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
   509
     * 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
   510
     * geshi.php, NOT geshi.php itself.
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
     * @param string The path to the language directory
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   513
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   514
     * @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
   515
     *             detected, so this method should no longer be needed. The
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   516
     *             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
   517
     *             so this method will disappear in 1.2.0.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   518
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   519
    function set_language_path($path) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   520
        if ($path) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   521
            $this->language_path = ('/' == substr($path, strlen($path) - 1, 1)) ? $path : $path . '/';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   522
            $this->set_language($this->language);        // otherwise set_language_path has no effect
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
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   526
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   527
     * Sets the type of header to be used.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   528
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   529
     * 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
   530
     * 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
   531
     * 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
   532
     * control. Default is GESHI_HEADER_PRE.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   533
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   534
     * 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
   535
     * should be outputted.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   536
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   537
     * @param int The type of header to be used
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   538
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   539
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   540
    function set_header_type($type) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   541
        if (GESHI_HEADER_DIV != $type && GESHI_HEADER_PRE != $type && GESHI_HEADER_NONE != $type) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   542
            $this->error = GESHI_ERROR_INVALID_HEADER_TYPE;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   543
            return;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   544
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   545
        $this->header_type = $type;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   546
        // Set a default overall style if the header is a <div>
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   547
        if (GESHI_HEADER_DIV == $type && !$this->overall_style) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   548
            $this->overall_style = 'font-family: monospace;';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   549
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   550
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   551
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   552
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   553
     * Sets the styles for the code that will be outputted
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   554
     * when this object is parsed. The style should be a
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   555
     * string of valid stylesheet declarations
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   556
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   557
     * @param string  The overall style for the outputted code block
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   558
     * @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
   559
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   560
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   561
    function set_overall_style($style, $preserve_defaults = false) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   562
        if (!$preserve_defaults) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   563
            $this->overall_style = $style;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   564
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   565
        else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   566
            $this->overall_style .= $style;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   567
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   568
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   569
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   570
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   571
     * Sets the overall classname for this block of code. This
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   572
     * 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
   573
     * output
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   574
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   575
     * @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
   576
     * @since 1.0.0
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
    function set_overall_class($class) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   579
        $this->overall_class = $class;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   580
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   581
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   582
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   583
     * 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
   584
     * 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
   585
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   586
     * @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
   587
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   588
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   589
    function set_overall_id($id) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   590
        $this->overall_id = $id;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   591
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   592
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   593
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   594
     * 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
   595
     * 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
   596
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   597
     * @param boolean Whether to turn classes on or not
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   598
     * @since 1.0.0
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
    function enable_classes($flag = true) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   601
        $this->use_classes = ($flag) ? true : false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   602
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   603
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
     * 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
   606
     * containing valid stylesheet declarations. If $preserve_defaults is
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   607
     * 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
   608
     * user defined styles having priority
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   609
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   610
     * 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
   611
     * 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
   612
     * 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
   613
     * GeSHi documentation for more information about this.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   614
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   615
     * @param string  The style to use for actual code
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   616
     * @param boolean Whether to merge the current styles with the new styles
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   617
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   618
    function set_code_style($style, $preserve_defaults = false) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   619
        if (!$preserve_defaults) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   620
            $this->code_style = $style;
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
        else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   623
            $this->code_style .= $style;
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
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   627
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   628
     * Sets the styles for the line numbers.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   629
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   630
     * @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
   631
     * @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
   632
     *        numbers that are "fancy", otherwise if boolean then this
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   633
     *        defines whether the normal styles should be merged with the
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   634
     *        new normal styles or not
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   635
     * @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
   636
     *        styles with the current styles or not
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   637
     * @since 1.0.2
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
    function set_line_style($style1, $style2 = '', $preserve_defaults = false) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   640
        if (is_bool($style2)) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   641
            $preserve_defaults = $style2;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   642
            $style2 = '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   643
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   644
        if (!$preserve_defaults) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   645
            $this->line_style1 = $style1;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   646
            $this->line_style2 = $style2;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   647
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   648
        else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   649
            $this->line_style1 .= $style1;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   650
            $this->line_style2 .= $style2;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   651
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   652
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   653
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   654
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   655
     * Sets whether line numbers should be displayed.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   656
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   657
     * Valid values for the first parameter are:
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   658
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   659
     *  - GESHI_NO_LINE_NUMBERS: Line numbers will not be displayed
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   660
     *  - GESHI_NORMAL_LINE_NUMBERS: Line numbers will be displayed
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   661
     *  - GESHI_FANCY_LINE_NUMBERS: Fancy line numbers will be displayed
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   662
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   663
     * 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
   664
     * 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
   665
     * 5th line will be fancy.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   666
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   667
     * @param int How line numbers should be displayed
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   668
     * @param int Defines which lines are fancy
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   669
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   670
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   671
    function enable_line_numbers($flag, $nth_row = 5) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   672
        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
   673
            && GESHI_FANCY_LINE_NUMBERS != $flag) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   674
            $this->error = GESHI_ERROR_INVALID_LINE_NUMBER_TYPE;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   675
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   676
        $this->line_numbers = $flag;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   677
        $this->line_nth_row = $nth_row;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   678
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   679
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   680
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   681
     * 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
   682
     * 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
   683
     * user defined styles having priority
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   684
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   685
     * @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
   686
     * @param string  The style to make the keywords
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   687
     * @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
   688
     *                to overwrite them
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   689
     * @since 1.0.0
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
    function set_keyword_group_style($key, $style, $preserve_defaults = false) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   692
        if (!$preserve_defaults) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   693
            $this->language_data['STYLES']['KEYWORDS'][$key] = $style;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   694
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   695
        else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   696
            $this->language_data['STYLES']['KEYWORDS'][$key] .= $style;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   697
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   698
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   699
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   700
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   701
     * Turns highlighting on/off for a keyword group
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
     * @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
   704
     * @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
   705
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   706
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   707
    function set_keyword_group_highlighting($key, $flag = true) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   708
        $this->lexic_permissions['KEYWORDS'][$key] = ($flag) ? true : false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   709
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   710
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   711
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   712
     * Sets the styles for comment groups.  If $preserve_defaults is
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   713
     * 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
   714
     * user defined styles having priority
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   715
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   716
     * @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
   717
     * @param string  The style to make the comments
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   718
     * @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
   719
     *                to overwrite them
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   720
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   721
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   722
    function set_comments_style($key, $style, $preserve_defaults = false) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   723
        if (!$preserve_defaults) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   724
            $this->language_data['STYLES']['COMMENTS'][$key] = $style;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   725
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   726
        else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   727
            $this->language_data['STYLES']['COMMENTS'][$key] .= $style;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   728
        }
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
     * Turns highlighting on/off for comment groups
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   733
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   734
     * @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
   735
     * @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
   736
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   737
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   738
    function set_comments_highlighting($key, $flag = true) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   739
        $this->lexic_permissions['COMMENTS'][$key] = ($flag) ? true : false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   740
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   741
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
     * Sets the styles for escaped characters. If $preserve_defaults is
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   744
     * 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
   745
     * user defined styles having priority
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   746
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   747
     * @param string  The style to make the escape characters
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   748
     * @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
   749
     *                to overwrite them
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   750
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   751
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   752
    function set_escape_characters_style($style, $preserve_defaults = false) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   753
        if (!$preserve_defaults) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   754
            $this->language_data['STYLES']['ESCAPE_CHAR'][0] = $style;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   755
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   756
        else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   757
            $this->language_data['STYLES']['ESCAPE_CHAR'][0] .= $style;
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
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   760
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   761
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   762
     * Turns highlighting on/off for escaped characters
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   763
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   764
     * @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
   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_escape_characters_highlighting($flag = true) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   768
        $this->lexic_permissions['ESCAPE_CHAR'] = ($flag) ? true : false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   769
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   770
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   771
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   772
     * Sets the styles for brackets. If $preserve_defaults is
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   773
     * 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
   774
     * user defined styles having priority
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
     * This method is DEPRECATED: use set_symbols_style instead.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   777
     * This method will be removed in 1.2.X
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   778
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   779
     * @param string  The style to make the brackets
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   780
     * @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
   781
     *                to overwrite them
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   782
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   783
     * @deprecated In favour of set_symbols_style
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   784
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   785
    function set_brackets_style($style, $preserve_defaults = false) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   786
        if (!$preserve_defaults) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   787
            $this->language_data['STYLES']['BRACKETS'][0] = $style;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   788
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   789
        else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   790
            $this->language_data['STYLES']['BRACKETS'][0] .= $style;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   791
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   792
    }
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
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   795
     * Turns highlighting on/off for brackets
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
     * This method is DEPRECATED: use set_symbols_highlighting instead.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   798
     * This method will be remove in 1.2.X
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   799
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   800
     * @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
   801
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   802
     * @deprecated In favour of set_symbols_highlighting
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   803
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   804
    function set_brackets_highlighting($flag) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   805
        $this->lexic_permissions['BRACKETS'] = ($flag) ? true : false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   806
    }
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
     * Sets the styles for symbols. If $preserve_defaults is
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   810
     * 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
   811
     * user defined styles having priority
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   812
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   813
     * @param string  The style to make the symbols
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   814
     * @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
   815
     *                to overwrite them
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   816
     * @since 1.0.1
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   817
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   818
    function set_symbols_style($style, $preserve_defaults = false) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   819
        if (!$preserve_defaults) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   820
            $this->language_data['STYLES']['SYMBOLS'][0] = $style;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   821
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   822
        else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   823
            $this->language_data['STYLES']['SYMBOLS'][0] .= $style;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   824
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   825
        // For backward compatibility
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   826
        $this->set_brackets_style ($style, $preserve_defaults);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   827
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   828
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
     * Turns highlighting on/off for symbols
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
     * @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
   833
     * @since 1.0.0
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
    function set_symbols_highlighting($flag) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   836
        $this->lexic_permissions['SYMBOLS'] = ($flag) ? true : false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   837
        // For backward compatibility
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   838
        $this->set_brackets_highlighting ($flag);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   839
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   840
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   841
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   842
     * Sets the styles for strings. If $preserve_defaults is
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   843
     * 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
   844
     * user defined styles having priority
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   845
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   846
     * @param string  The style to make the escape characters
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   847
     * @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
   848
     *                to overwrite them
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   849
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   850
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   851
    function set_strings_style($style, $preserve_defaults = false) {
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->language_data['STYLES']['STRINGS'][0] = $style;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   854
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   855
        else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   856
            $this->language_data['STYLES']['STRINGS'][0] .= $style;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   857
        }
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
     * Turns highlighting on/off for strings
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   862
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   863
     * @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
   864
     * @since 1.0.0
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
    function set_strings_highlighting($flag) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   867
        $this->lexic_permissions['STRINGS'] = ($flag) ? true : false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   868
    }
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
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   871
     * Sets the styles for numbers. If $preserve_defaults is
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   872
     * 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
   873
     * user defined styles having priority
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   874
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   875
     * @param string  The style to make the numbers
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   876
     * @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
   877
     *                to overwrite them
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   878
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   879
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   880
    function set_numbers_style($style, $preserve_defaults = false) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   881
        if (!$preserve_defaults) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   882
            $this->language_data['STYLES']['NUMBERS'][0] = $style;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   883
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   884
        else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   885
            $this->language_data['STYLES']['NUMBERS'][0] .= $style;
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
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   888
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   889
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   890
     * Turns highlighting on/off for numbers
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   891
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   892
     * @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
   893
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   894
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   895
    function set_numbers_highlighting($flag) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   896
        $this->lexic_permissions['NUMBERS'] = ($flag) ? true : false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   897
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   898
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   899
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   900
     * 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
   901
     * appropriate "object splitter" - see the language file for the language
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   902
     * 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
   903
     * 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
   904
     * user defined styles having priority
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   905
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   906
     * @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
   907
     * @param string  The style to make the methods
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   908
     * @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
   909
     *                to overwrite them
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   910
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   911
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   912
    function set_methods_style($key, $style, $preserve_defaults = false) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   913
        if (!$preserve_defaults) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   914
            $this->language_data['STYLES']['METHODS'][$key] = $style;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   915
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   916
        else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   917
            $this->language_data['STYLES']['METHODS'][$key] .= $style;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   918
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   919
    }
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
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   922
     * Turns highlighting on/off for methods
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   923
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   924
     * @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
   925
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   926
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   927
    function set_methods_highlighting($flag) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   928
        $this->lexic_permissions['METHODS'] = ($flag) ? true : false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   929
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   930
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   931
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   932
     * Sets the styles for regexps. If $preserve_defaults is
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   933
     * 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
   934
     * user defined styles having priority
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
     * @param string  The style to make the regular expression matches
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   937
     * @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
   938
     *                to overwrite them
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   939
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   940
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   941
    function set_regexps_style($key, $style, $preserve_defaults = false) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   942
        if (!$preserve_defaults) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   943
            $this->language_data['STYLES']['REGEXPS'][$key] = $style;
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
        else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   946
            $this->language_data['STYLES']['REGEXPS'][$key] .= $style;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   947
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   948
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   949
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
     * Turns highlighting on/off for regexps
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   952
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   953
     * @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
   954
     * @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
   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_regexps_highlighting($key, $flag) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   958
        $this->lexic_permissions['REGEXPS'][$key] = ($flag) ? true : false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   959
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   960
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   961
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   962
     * 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
   963
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   964
     * @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
   965
     * @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
   966
     * @since 1.0.0
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
    function set_case_sensitivity($key, $case) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   969
        $this->language_data['CASE_SENSITIVE'][$key] = ($case) ? true : false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   970
    }
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
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   973
     * 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
   974
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   975
     *  - GESHI_CAPS_NO_CHANGE: leave keywords as-is
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   976
     *  - GESHI_CAPS_UPPER: convert all keywords to uppercase where found
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   977
     *  - GESHI_CAPS_LOWER: convert all keywords to lowercase where found
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   978
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   979
     * @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
   980
     * @since 1.0.1
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   981
     * @todo  Error check the passed value
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   982
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   983
    function set_case_keywords($case) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   984
        $this->language_data['CASE_KEYWORDS'] = $case;
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
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   987
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   988
     * Sets how many spaces a tab is substituted for
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   989
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   990
     * Widths below zero are ignored
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
     * @param int The tab width
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   993
     * @since 1.0.0
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
    function set_tab_width($width) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   996
        $this->tab_width = intval($width);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   997
        //Check if it fit's the constraints:
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   998
        if($this->tab_width < 1) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
   999
            //Return it to the default
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1000
            $this->tab_width = 8;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1001
        }
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 whether or not to use tab-stop width specifed by language
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1006
	 *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1007
	 * @param boolean Whether to use language-specific tab-stop widths
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
	function set_use_language_tab_width($use) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1010
		$this->use_language_tab_width = (bool) $use;
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
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1013
	/**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1014
	 * Returns the tab width to use, based on the current language and user
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1015
	 * preference
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1016
	 *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1017
	 * @return int Tab width
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1018
	 */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1019
	function get_real_tab_width() {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1020
		if (!$this->use_language_tab_width || !isset($this->language_data['TAB_WIDTH'])) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1021
			return $this->tab_width;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1022
		} else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1023
			return $this->language_data['TAB_WIDTH'];
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
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1028
     * Enables/disables strict highlighting. Default is off, calling this
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1029
     * method without parameters will turn it on. See documentation
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1030
     * 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
  1031
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1032
     * @param boolean Whether to enable strict mode or not
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
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1035
    function enable_strict_mode($mode = true) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1036
        if (GESHI_MAYBE == $this->language_data['STRICT_MODE_APPLIES']) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1037
          $this->strict_mode = ($mode) ? 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
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1042
     * Disables all highlighting
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1043
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1044
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1045
     * @todo Rewrite with an array traversal
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1046
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1047
    function disable_highlighting() {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1048
        foreach ($this->lexic_permissions as $key => $value) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1049
            if (is_array($value)) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1050
                foreach ($value as $k => $v) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1051
                    $this->lexic_permissions[$key][$k] = false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1052
                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1053
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1054
            else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1055
                $this->lexic_permissions[$key] = false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1056
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1057
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1058
        // Context blocks
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1059
        $this->enable_important_blocks = false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1060
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1061
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
     * Enables all highlighting
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
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1066
     * @todo  Rewrite with array traversal
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
    function enable_highlighting() {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1069
        foreach ($this->lexic_permissions as $key => $value) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1070
            if (is_array($value)) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1071
                foreach ($value as $k => $v) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1072
                    $this->lexic_permissions[$key][$k] = true;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1073
                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1074
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1075
            else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1076
                $this->lexic_permissions[$key] = true;
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
        // Context blocks
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1080
        $this->enable_important_blocks = true;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1081
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1082
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
     * 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
  1085
     * 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
  1086
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1087
     * @param string The extension to get a language name for
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1088
     * @param array  A lookup array to use instead of the default
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1089
     * @since 1.0.5
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1090
     * @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
  1091
     *       a extension->lang lookup?)
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1092
     * @todo static?
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1093
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1094
    function get_language_name_from_extension( $extension, $lookup = array() ) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1095
        if ( !$lookup ) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1096
            $lookup = array(
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1097
                'actionscript' => array('as'),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1098
                'ada' => array('a', 'ada', 'adb', 'ads'),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1099
                'apache' => array('conf'),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1100
                'asm' => array('ash', 'asm'),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1101
                'asp' => array('asp'),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1102
                'bash' => array('sh'),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1103
                'c' => array('c', 'h'),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1104
                'c_mac' => array('c', 'h'),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1105
                'caddcl' => array(),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1106
                'cadlisp' => array(),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1107
                'cdfg' => array('cdfg'),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1108
                'cpp' => array('cpp', 'h', 'hpp'),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1109
                'csharp' => array(),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1110
                'css' => array('css'),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1111
                'delphi' => array('dpk', 'dpr'),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1112
                'html4strict' => array('html', 'htm'),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1113
                'java' => array('java'),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1114
                'javascript' => array('js'),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1115
                'lisp' => array('lisp'),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1116
                'lua' => array('lua'),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1117
                'mpasm' => array(),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1118
                'nsis' => array(),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1119
                'objc' => array(),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1120
                'oobas' => array(),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1121
                'oracle8' => array(),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1122
                'pascal' => array('pas'),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1123
                'perl' => array('pl', 'pm'),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1124
                'php' => array('php', 'php5', 'phtml', 'phps'),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1125
                'python' => array('py'),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1126
                'qbasic' => array('bi'),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1127
                'sas' => array('sas'),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1128
                'smarty' => array(),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1129
                'vb' => array('bas'),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1130
                'vbnet' => array(),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1131
                'visualfoxpro' => array(),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1132
                'xml' => array('xml')
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
        foreach ($lookup as $lang => $extensions) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1137
            foreach ($extensions as $ext) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1138
                if ($ext == $extension) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1139
                    return $lang;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1140
                }
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
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1143
        return '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1144
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1145
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1146
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1147
     * 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
  1148
     * 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
  1149
     * 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
  1150
     * table is used
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1151
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1152
     * The language table is in the form
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1153
     * <pre>array(
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1154
     *   'lang_name' => array('extension', 'extension', ...),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1155
     *   'lang_name' ...
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1156
     * );</pre>
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1157
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1158
     * @todo Complete rethink of this and above method
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1159
     * @since 1.0.5
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1160
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1161
    function load_from_file($file_name, $lookup = array()) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1162
        if (is_readable($file_name)) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1163
            $this->set_source(implode('', file($file_name)));
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1164
            $this->set_language($this->get_language_name_from_extension(substr(strrchr($file_name, '.'), 1), $lookup));
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
        else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1167
            $this->error = GESHI_ERROR_FILE_NOT_READABLE;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1168
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1169
    }
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
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1172
     * Adds a keyword to a keyword group for highlighting
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1173
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1174
     * @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
  1175
     * @param string The word to add to the keyword group
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1176
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1177
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1178
    function add_keyword($key, $word) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1179
        $this->language_data['KEYWORDS'][$key][] = $word;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1180
    }
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
     * Removes a keyword from a keyword group
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
     * @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
  1186
     * @param string The word to remove from the keyword group
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1187
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1188
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1189
    function remove_keyword($key, $word) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1190
        $this->language_data['KEYWORDS'][$key] =
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1191
            array_diff($this->language_data['KEYWORDS'][$key], array($word));
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1192
    }
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
     * Creates a new keyword group
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1196
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1197
     * @param int    The key of the keyword group to create
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1198
     * @param string The styles for the keyword group
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1199
     * @param boolean Whether the keyword group is case sensitive ornot
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1200
     * @param array  The words to use for the keyword group
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1201
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1202
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1203
    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
  1204
        $words = (array) $words;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1205
        $this->language_data['KEYWORDS'][$key] = $words;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1206
        $this->lexic_permissions['KEYWORDS'][$key] = true;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1207
        $this->language_data['CASE_SENSITIVE'][$key] = $case_sensitive;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1208
        $this->language_data['STYLES']['KEYWORDS'][$key] = $styles;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1209
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1210
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1211
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1212
     * Removes a keyword group
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1213
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1214
     * @param int    The key of the keyword group to remove
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1215
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1216
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1217
    function remove_keyword_group ($key) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1218
        unset($this->language_data['KEYWORDS'][$key]);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1219
        unset($this->lexic_permissions['KEYWORDS'][$key]);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1220
        unset($this->language_data['CASE_SENSITIVE'][$key]);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1221
        unset($this->language_data['STYLES']['KEYWORDS'][$key]);
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
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1225
     * Sets the content of the header block
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1226
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1227
     * @param string The content of the header block
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1228
     * @since 1.0.2
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1229
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1230
    function set_header_content($content) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1231
        $this->header_content = $content;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1232
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1233
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1234
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1235
     * Sets the content of the footer block
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1236
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1237
     * @param string The content of the footer block
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1238
     * @since 1.0.2
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
    function set_footer_content($content) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1241
        $this->footer_content = $content;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1242
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1243
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1244
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1245
     * Sets the style for the header content
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1246
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1247
     * @param string The style for the header content
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1248
     * @since 1.0.2
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1249
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1250
    function set_header_content_style($style) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1251
        $this->header_content_style = $style;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1252
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1253
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1254
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1255
     * Sets the style for the footer content
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1256
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1257
     * @param string The style for the footer content
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1258
     * @since 1.0.2
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1259
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1260
    function set_footer_content_style($style) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1261
        $this->footer_content_style = $style;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1262
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1263
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1264
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1265
     * Sets whether to force a surrounding block around
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1266
     * the highlighted code or not
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
     * @param boolean Tells whether to enable or disable this feature
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1269
     * @since 1.0.7.20
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1270
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1271
    function enable_inner_code_block($flag) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1272
        $this->force_code_block = (bool)$flag;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1273
    }
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
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1276
     * Sets the base URL to be used for keywords
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1277
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1278
     * @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
  1279
     * @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
  1280
     *               the url somewhere, it is replaced by the keyword
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1281
     *               that the URL is being made for
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1282
     * @since 1.0.2
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
    function set_url_for_keyword_group($group, $url) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1285
        $this->language_data['URLS'][$group] = $url;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1286
    }
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
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1289
     * Sets styles for links in code
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
     * @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
  1292
     *            set for - e.g. :hover or :visited
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1293
     * @param string The styles to use for that state
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1294
     * @since 1.0.2
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1295
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1296
    function set_link_styles($type, $styles) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1297
        $this->link_styles[$type] = $styles;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1298
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1299
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1300
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1301
     * Sets the target for links in code
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1302
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1303
     * @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
  1304
     * @since 1.0.3
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1305
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1306
    function set_link_target($target) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1307
        if (!$target) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1308
            $this->link_target = '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1309
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1310
        else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1311
            $this->link_target = ' target="' . $target . '" ';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1312
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1313
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1314
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1315
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1316
     * Sets styles for important parts of the code
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
     * @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
  1319
     * @since 1.0.2
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1320
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1321
    function set_important_styles($styles) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1322
        $this->important_styles = $styles;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1323
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1324
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1325
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1326
     * Sets whether context-important blocks are highlighted
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1327
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1328
     * @todo REMOVE THIS SHIZ FROM GESHI!
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1329
     * @deprecated
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1330
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1331
    function enable_important_blocks($flag) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1332
        $this->enable_important_blocks = ( $flag ) ? true : false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1333
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1334
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1335
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1336
     * Whether CSS IDs should be added to each line
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1337
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1338
     * @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
  1339
     * @since 1.0.2
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1340
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1341
    function enable_ids($flag = true) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1342
        $this->add_ids = ($flag) ? true : false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1343
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1344
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1345
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1346
     * Specifies which lines to highlight extra
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1347
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1348
     * @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
  1349
     *              number on its own.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1350
     * @since 1.0.2
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1351
     * @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
  1352
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1353
    function highlight_lines_extra($lines) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1354
        if (is_array($lines)) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1355
            foreach ($lines as $line) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1356
                $this->highlight_extra_lines[intval($line)] = intval($line);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1357
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1358
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1359
        else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1360
            $this->highlight_extra_lines[intval($lines)] = intval($lines);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1361
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1362
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1363
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1364
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1365
     * Sets the style for extra-highlighted lines
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1366
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1367
     * @param string The style for extra-highlighted lines
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1368
     * @since 1.0.2
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1369
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1370
    function set_highlight_lines_extra_style($styles) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1371
        $this->highlight_extra_lines_style = $styles;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1372
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1373
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1374
	/**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1375
	 * Sets the line-ending
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1376
	 *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1377
	 * @param string The new line-ending
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1378
	 */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1379
	function set_line_ending($line_ending) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1380
		$this->line_ending = (string)$line_ending;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1381
	}
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1382
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1383
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1384
     * Sets what number line numbers should start at. Should
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1385
     * be a positive integer, and will be converted to one.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1386
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1387
     * <b>Warning:</b> Using this method will add the "start"
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1388
     * 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
  1389
     * 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
  1390
     * 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
  1391
     * 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
  1392
     * 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
  1393
     * 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
  1394
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1395
     * @param int The number to start line numbers at
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1396
     * @since 1.0.2
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
    function start_line_numbers_at($number) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1399
        $this->line_numbers_start = abs(intval($number));
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1400
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1401
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1402
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1403
     * Sets the encoding used for htmlspecialchars(), for international
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1404
     * support.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1405
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1406
     * 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
  1407
     * 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
  1408
     * 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
  1409
     * I doubt it.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1410
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1411
     * @param string The encoding to use for the source
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1412
     * @since 1.0.3
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
    function set_encoding($encoding) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1415
        if ($encoding) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1416
          $this->encoding = $encoding;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1417
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1418
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1419
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1420
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1421
     * Turns linking of keywords on or off.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1422
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1423
     * @param boolean If true, links will be added to keywords
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 enable_keyword_links($enable = true) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1426
        $this->keyword_links = ($enable) ? true : false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1427
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1428
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1429
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1430
     * 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
  1431
     * nessecary HTML.
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
     * 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
  1434
     * 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
  1435
     * str_replaces to replace the &lt;span&gt;s
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
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1438
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1439
    function parse_code () {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1440
        // Start the timer
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1441
        $start_time = microtime();
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1442
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1443
        // Firstly, if there is an error, we won't highlight
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1444
        if ($this->error) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1445
            $result = GeSHi::hsc($this->source);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1446
            // Timing is irrelevant
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1447
            $this->set_time($start_time, $start_time);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1448
            return $this->finalise($result);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1449
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1450
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1451
        // Replace all newlines to a common form.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1452
        $code = str_replace("\r\n", "\n", $this->source);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1453
        $code = str_replace("\r", "\n", $code);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1454
        // Add spaces for regular expression matching and line numbers
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1455
        $code = "\n" . $code . "\n";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1456
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1457
        // Initialise various stuff
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1458
        $length           = strlen($code);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1459
        $STRING_OPEN      = '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1460
        $CLOSE_STRING     = false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1461
        $ESCAPE_CHAR_OPEN = false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1462
        $COMMENT_MATCHED  = false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1463
        // Turn highlighting on if strict mode doesn't apply to this language
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1464
        $HIGHLIGHTING_ON  = ( !$this->strict_mode ) ? true : '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1465
        // Whether to highlight inside a block of code
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1466
        $HIGHLIGHT_INSIDE_STRICT = false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1467
        $HARDQUOTE_OPEN = false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1468
        $STRICTATTRS = '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1469
        $stuff_to_parse   = '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1470
        $result           = '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1471
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1472
        // "Important" selections are handled like multiline comments
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1473
        // @todo GET RID OF THIS SHIZ
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1474
        if ($this->enable_important_blocks) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1475
            $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
  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
        if ($this->strict_mode) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1479
            // 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
  1480
            // within script delimiters - for example, HTML between < and >
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1481
            $parts = array(0 => array(0 => ''));
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1482
            $k = 0;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1483
            for ($i = 0; $i < $length; $i++) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1484
                $char = substr($code, $i, 1);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1485
                if (!$HIGHLIGHTING_ON) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1486
                    foreach ($this->language_data['SCRIPT_DELIMITERS'] as $key => $delimiters) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1487
                        foreach ($delimiters as $open => $close) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1488
                            // Get the next little bit for this opening string
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1489
                            $check = substr($code, $i, strlen($open));
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1490
                            // If it matches...
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1491
                            if ($check == $open) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1492
                                // We start a new block with the highlightable
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1493
                                // code in it
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1494
                                $HIGHLIGHTING_ON = $open;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1495
                                $i += strlen($open) - 1;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1496
                                $char = $open;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1497
                                $parts[++$k][0] = $char;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1498
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1499
                                // No point going around again...
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1500
                                break(2);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1501
                            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1502
                        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1503
                    }
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
                else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1506
                    foreach ($this->language_data['SCRIPT_DELIMITERS'] as $key => $delimiters) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1507
                        foreach ($delimiters as $open => $close) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1508
                            if ($open == $HIGHLIGHTING_ON) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1509
                                // Found the closing tag
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1510
                                break(2);
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
                        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1513
                    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1514
                    // We check code from our current position BACKWARDS. This is so
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1515
                    // the ending string for highlighting can be included in the block
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1516
                    $check = substr($code, $i - strlen($close) + 1, strlen($close));
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1517
                    if ($check == $close) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1518
                        $HIGHLIGHTING_ON = '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1519
                        // Add the string to the rest of the string for this part
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1520
                        $parts[$k][1] = ( isset($parts[$k][1]) ) ? $parts[$k][1] . $char : $char;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1521
                        $parts[++$k][0] = '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1522
                        $char = '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1523
                    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1524
                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1525
                $parts[$k][1] = ( isset($parts[$k][1]) ) ? $parts[$k][1] . $char : $char;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1526
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1527
            $HIGHLIGHTING_ON = '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1528
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1529
        else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1530
            // Not strict mode - simply dump the source into
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1531
            // the array at index 1 (the first highlightable block)
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1532
            $parts = array(
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1533
                1 => array(
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1534
                    0 => '',
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1535
                    1 => $code
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
            );
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1538
        }
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
        // 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
  1541
        // 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
  1542
        // be highlighted
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1543
        foreach ($parts as $key => $data) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1544
            $part = $data[1];
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1545
            // If this block should be highlighted...
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1546
            if ($key % 2) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1547
                if ($this->strict_mode) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1548
                    // Find the class key for this block of code
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1549
                    foreach ($this->language_data['SCRIPT_DELIMITERS'] as $script_key => $script_data) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1550
                        foreach ($script_data as $open => $close) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1551
                            if ($data[0] == $open) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1552
                                break(2);
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
                    }
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
                    if ($this->language_data['STYLES']['SCRIPT'][$script_key] != '' &&
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1558
                        $this->lexic_permissions['SCRIPT']) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1559
                        // Add a span element around the source to
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1560
                        // highlight the overall source block
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1561
                        if (!$this->use_classes &&
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1562
                            $this->language_data['STYLES']['SCRIPT'][$script_key] != '') {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1563
                            $attributes = ' style="' . $this->language_data['STYLES']['SCRIPT'][$script_key] . '"';
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
                        else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1566
                            $attributes = ' class="sc' . $script_key . '"';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1567
                        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1568
                        $result .= "<span$attributes>";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1569
                        $STRICTATTRS = $attributes;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1570
                    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1571
                }
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
                if (!$this->strict_mode || $this->language_data['HIGHLIGHT_STRICT_BLOCK'][$script_key]) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1574
                    // Now, highlight the code in this block. This code
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1575
                    // is really the engine of GeSHi (along with the method
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1576
                    // parse_non_string_part).
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1577
                    $length = strlen($part);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1578
                    for ($i = 0; $i < $length; $i++) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1579
                        // Get the next char
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1580
                        $char = substr($part, $i, 1);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1581
                        $hq = isset($this->language_data['HARDQUOTE']) ? $this->language_data['HARDQUOTE'][0] : false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1582
                        // Is this char the newline and line numbers being used?
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1583
                        if (($this->line_numbers != GESHI_NO_LINE_NUMBERS
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1584
                            || count($this->highlight_extra_lines) > 0)
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1585
                            && $char == "\n") {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1586
                            // If so, is there a string open? If there is, we should end it before
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1587
                            // 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
  1588
                            // remains XHTML compliant)
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1589
                            // 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
  1590
                            // that languages can/cannot have multiline strings???
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1591
                            if ($STRING_OPEN) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1592
                                if (!$this->use_classes) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1593
                                    $attributes = ' style="' . $this->language_data['STYLES']['STRINGS'][0] . '"';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1594
                                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1595
                                else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1596
                                    $attributes = ' class="st0"';
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
                                $char = '</span>' . $char . "<span$attributes>";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1599
                            }
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
                        else if ($char == $STRING_OPEN) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1602
                            // A match of a string delimiter
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1603
                            if (($this->lexic_permissions['ESCAPE_CHAR'] && $ESCAPE_CHAR_OPEN) ||
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1604
                                ($this->lexic_permissions['STRINGS'] && !$ESCAPE_CHAR_OPEN)) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1605
                                $char = GeSHi::hsc($char) . '</span>';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1606
                            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1607
                            $escape_me = false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1608
                            if ($HARDQUOTE_OPEN) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1609
                                if ($ESCAPE_CHAR_OPEN) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1610
                                    $escape_me = true;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1611
                                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1612
                                else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1613
                                    foreach ($this->language_data['HARDESCAPE'] as $hardesc) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1614
                                        if (substr($part, $i, strlen($hardesc)) == $hardesc) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1615
                                            $escape_me = true;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1616
                                            break;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1617
                                        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1618
                                    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1619
                                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1620
                            }
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
                            if (!$ESCAPE_CHAR_OPEN) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1623
                                $STRING_OPEN = '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1624
                                $CLOSE_STRING = true;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1625
                            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1626
                            if (!$escape_me) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1627
                                $HARDQUOTE_OPEN = false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1628
                            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1629
                            $ESCAPE_CHAR_OPEN = false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1630
                        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1631
                        else if (in_array($char, $this->language_data['QUOTEMARKS']) &&
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1632
                            ($STRING_OPEN == '') && $this->lexic_permissions['STRINGS']) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1633
                            // The start of a new string
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1634
                            $STRING_OPEN = $char;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1635
                            if (!$this->use_classes) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1636
                                $attributes = ' style="' . $this->language_data['STYLES']['STRINGS'][0] . '"';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1637
                            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1638
                            else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1639
                                $attributes = ' class="st0"';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1640
                            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1641
                            $char = "<span$attributes>" . GeSHi::hsc($char);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1642
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1643
                            $result .= $this->parse_non_string_part( $stuff_to_parse );
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1644
                            $stuff_to_parse = '';
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
                        else if ($hq && substr($part, $i, strlen($hq)) == $hq &&
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1647
                            ($STRING_OPEN == '') && $this->lexic_permissions['STRINGS']) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1648
                            // The start of a hard quoted string
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1649
                            $STRING_OPEN = $this->language_data['HARDQUOTE'][1];
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1650
                            if (!$this->use_classes) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1651
                                $attributes = ' style="' . $this->language_data['STYLES']['STRINGS'][0] . '"';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1652
                            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1653
                            else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1654
                                $attributes = ' class="st0"';
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
                            $char = "<span$attributes>" . $hq;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1657
                            $i += strlen($hq) - 1;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1658
                            $HARDQUOTE_OPEN = true;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1659
                            $result .= $this->parse_non_string_part($stuff_to_parse);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1660
                            $stuff_to_parse = '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1661
                        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1662
                        else if ($char == $this->language_data['ESCAPE_CHAR'] && $STRING_OPEN != '') {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1663
                            // An escape character
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1664
                            if (!$ESCAPE_CHAR_OPEN) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1665
                                $ESCAPE_CHAR_OPEN = !$HARDQUOTE_OPEN;  // true unless $HARDQUOTE_OPEN
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1666
                                if ($HARDQUOTE_OPEN) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1667
                                    foreach ($this->language_data['HARDESCAPE'] as $hard) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1668
                                        if (substr($part, $i, strlen($hard)) == $hard) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1669
                                            $ESCAPE_CHAR_OPEN = true;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1670
                                            break;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1671
                                        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1672
                                    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1673
                                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1674
                                if ($ESCAPE_CHAR_OPEN && $this->lexic_permissions['ESCAPE_CHAR']) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1675
                                    if (!$this->use_classes) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1676
                                        $attributes = ' style="' . $this->language_data['STYLES']['ESCAPE_CHAR'][0] . '"';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1677
                                    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1678
                                    else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1679
                                        $attributes = ' class="es0"';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1680
                                    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1681
                                    $char = "<span$attributes>" . $char;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1682
                                    if (substr($code, $i + 1, 1) == "\n") {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1683
                                        // escaping a newline, what's the point in putting the span around
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1684
                                        // the newline? It only causes hassles when inserting line numbers
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1685
                                        $char .= '</span>';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1686
                                        $ESCAPE_CHAR_OPEN = false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1687
                                    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1688
                                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1689
                            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1690
                            else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1691
                                $ESCAPE_CHAR_OPEN = false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1692
                                if ($this->lexic_permissions['ESCAPE_CHAR']) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1693
                                    $char .= '</span>';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1694
                                }
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
                        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1697
                        else if ($ESCAPE_CHAR_OPEN) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1698
                            if ($this->lexic_permissions['ESCAPE_CHAR']) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1699
                                $char .= '</span>';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1700
                            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1701
                            $ESCAPE_CHAR_OPEN = false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1702
                            $test_str = $char;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1703
                        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1704
                        else if ($STRING_OPEN == '') {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1705
                            // Is this a multiline comment?
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1706
                            foreach ($this->language_data['COMMENT_MULTI'] as $open => $close) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1707
                                $com_len = strlen($open);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1708
                                $test_str = substr( $part, $i, $com_len );
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1709
                                $test_str_match = $test_str;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1710
                                if ($open == $test_str) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1711
                                    $COMMENT_MATCHED = true;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1712
                                    //@todo If remove important do remove here
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1713
                                    if ($this->lexic_permissions['COMMENTS']['MULTI'] ||
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1714
                                        $test_str == GESHI_START_IMPORTANT) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1715
                                        if ($test_str != GESHI_START_IMPORTANT) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1716
                                            if (!$this->use_classes) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1717
                                                $attributes = ' style="' . $this->language_data['STYLES']['COMMENTS']['MULTI'] . '"';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1718
                                            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1719
                                            else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1720
                                                $attributes = ' class="coMULTI"';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1721
                                            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1722
                                            $test_str = "<span$attributes>" . GeSHi::hsc($test_str);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1723
                                        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1724
                                        else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1725
                                            if (!$this->use_classes) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1726
                                                $attributes = ' style="' . $this->important_styles . '"';
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
                                            else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1729
                                                $attributes = ' class="imp"';
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
                                            // We don't include the start of the comment if it's an
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1732
                                            // "important" part
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1733
                                            $test_str = "<span$attributes>";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1734
                                        }
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
                                    else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1737
                                        $test_str = GeSHi::hsc($test_str);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1738
                                    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1739
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1740
                                    $close_pos = strpos( $part, $close, $i + strlen($close) );
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1741
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1742
                                    $oops = false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1743
                                    if ($close_pos === false) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1744
                                        $close_pos = strlen($part);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1745
                                        $oops = true;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1746
                                    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1747
                                    else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1748
                                        $close_pos -= ($com_len - strlen($close));
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
                                    // Short-cut through all the multiline code
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1752
                                    $rest_of_comment = GeSHi::hsc(substr($part, $i + $com_len, $close_pos - $i));
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1753
                                    if (($this->lexic_permissions['COMMENTS']['MULTI'] ||
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1754
                                        $test_str_match == GESHI_START_IMPORTANT) &&
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1755
                                        ($this->line_numbers != GESHI_NO_LINE_NUMBERS ||
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1756
                                        count($this->highlight_extra_lines) > 0)) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1757
                                        // strreplace to put close span and open span around multiline newlines
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1758
                                        $test_str .= str_replace(
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1759
                                            "\n", "</span>\n<span$attributes>", 
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1760
                                            str_replace("\n ", "\n&nbsp;", $rest_of_comment)
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1761
                                        );
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1762
                                    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1763
                                    else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1764
                                        $test_str .= $rest_of_comment;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1765
                                    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1766
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1767
                                    if ($this->lexic_permissions['COMMENTS']['MULTI'] ||
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1768
                                        $test_str_match == GESHI_START_IMPORTANT) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1769
                                        $test_str .= '</span>';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1770
                                        if ($oops) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1771
                                            $test_str .= "\n";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1772
                                        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1773
                                    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1774
									$i = $close_pos + $com_len - 1;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1775
                                    // parse the rest
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1776
                                    $result .= $this->parse_non_string_part($stuff_to_parse);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1777
                                    $stuff_to_parse = '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1778
                                    break;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1779
                                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1780
                            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1781
                            // If we haven't matched a multiline comment, try single-line comments
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1782
                            if (!$COMMENT_MATCHED) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1783
                                foreach ($this->language_data['COMMENT_SINGLE'] as $comment_key => $comment_mark) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1784
                                    $com_len = strlen($comment_mark);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1785
                                    $test_str = substr($part, $i, $com_len);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1786
                                    if ($this->language_data['CASE_SENSITIVE'][GESHI_COMMENTS]) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1787
                                        $match = ($comment_mark == $test_str);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1788
                                    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1789
                                    else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1790
                                        $match = (strtolower($comment_mark) == strtolower($test_str));
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1791
                                    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1792
                                    if ($match) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1793
                                        $COMMENT_MATCHED = true;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1794
                                        if ($this->lexic_permissions['COMMENTS'][$comment_key]) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1795
                                            if (!$this->use_classes) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1796
                                                $attributes = ' style="' . $this->language_data['STYLES']['COMMENTS'][$comment_key] . '"';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1797
                                            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1798
                                            else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1799
                                                $attributes = ' class="co' . $comment_key . '"';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1800
                                            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1801
                                            $test_str = "<span$attributes>" . GeSHi::hsc($this->change_case($test_str));
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1802
                                        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1803
                                        else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1804
                                            $test_str = GeSHi::hsc($test_str);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1805
                                        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1806
                                        $close_pos = strpos($part, "\n", $i);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1807
                                        $oops = false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1808
                                        if ($close_pos === false) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1809
                                            $close_pos = strlen($part);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1810
                                            $oops = true;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1811
                                        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1812
                                        $test_str .= GeSHi::hsc(substr($part, $i + $com_len, $close_pos - $i - $com_len));
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1813
                                        if ($this->lexic_permissions['COMMENTS'][$comment_key]) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1814
                                            $test_str .= "</span>";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1815
                                        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1816
                                        // Take into account that the comment might be the last in the source
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1817
                                        if (!$oops) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1818
                                          $test_str .= "\n";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1819
                                        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1820
                                        $i = $close_pos;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1821
                                        // parse the rest
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1822
                                        $result .= $this->parse_non_string_part($stuff_to_parse);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1823
                                        $stuff_to_parse = '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1824
                                        break;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1825
                                    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1826
                                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1827
                            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1828
                        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1829
                        else if ($STRING_OPEN != '') {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1830
                            // Otherwise, convert it to HTML form
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1831
                            if (strtolower($this->encoding) == 'utf-8') {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1832
                                //only escape <128 (we don't want to break multibyte chars)
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1833
                                if (ord($char) < 128) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1834
                                    $char = GeSHi::hsc($char);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1835
                                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1836
                            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1837
                            else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1838
                                //encode everthing
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1839
                                $char = GeSHi::hsc($char);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1840
                            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1841
                        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1842
                        // Where are we adding this char?
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1843
                        if (!$COMMENT_MATCHED) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1844
                            if (($STRING_OPEN == '') && !$CLOSE_STRING) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1845
                                $stuff_to_parse .= $char;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1846
                            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1847
                            else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1848
                                $result .= $char;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1849
                                $CLOSE_STRING = false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1850
                            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1851
                        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1852
                        else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1853
                            $result .= $test_str;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1854
                            $COMMENT_MATCHED = false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1855
                        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1856
                    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1857
                    // Parse the last bit
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1858
                    $result .= $this->parse_non_string_part($stuff_to_parse);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1859
                    $stuff_to_parse = '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1860
                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1861
                else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1862
                    if ($STRICTATTRS != '') {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1863
                        $part = str_replace("\n", "</span>\n<span$STRICTATTRS>", GeSHi::hsc($part));
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1864
                        $STRICTATTRS = '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1865
                    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1866
                    $result .= $part;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1867
                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1868
                // Close the <span> that surrounds the block
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1869
                if ($this->strict_mode && $this->language_data['STYLES']['SCRIPT'][$script_key] != '' &&
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1870
                    $this->lexic_permissions['SCRIPT']) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1871
                    $result .= '</span>';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1872
                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1873
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1874
            else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1875
                // Else not a block to highlight
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1876
                $result .= GeSHi::hsc($part);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1877
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1878
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1879
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1880
        // Parse the last stuff (redundant?)
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1881
        $result .= $this->parse_non_string_part($stuff_to_parse);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1882
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1883
        // Lop off the very first and last spaces
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1884
        $result = substr($result, 1, -1);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1885
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1886
        // Are we still in a string?
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1887
        if ($STRING_OPEN) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1888
            $result .= '</span>';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1889
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1890
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1891
        // We're finished: stop timing
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1892
        $this->set_time($start_time, microtime());
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1893
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1894
        return $this->finalise($result);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1895
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1896
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1897
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1898
     * 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
  1899
     * the code is in a pre block...
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1900
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1901
     * @param  string The source to indent
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1902
     * @return string The source with HTML indenting applied
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1903
     * @since  1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1904
     * @access private
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1905
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1906
    function indent($result) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1907
        /// Replace tabs with the correct number of spaces
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1908
        if (false !== strpos($result, "\t")) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1909
            $lines = explode("\n", $result);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1910
			$tab_width = $this->get_real_tab_width();
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1911
            foreach ($lines as $key => $line) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1912
                if (false === strpos($line, "\t")) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1913
                    $lines[$key] = $line;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1914
                    continue;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1915
                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1916
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1917
                $pos = 0;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1918
                $length = strlen($line);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1919
                $result_line = '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1920
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1921
                $IN_TAG = false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1922
                for ($i = 0; $i < $length; $i++) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1923
                    $char = substr($line, $i, 1);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1924
                    // 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
  1925
                    // 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
  1926
                    // in the line and only workout the tab replacement
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1927
                    // via the actual content of the string
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1928
                    // This test could be improved to include strings in the
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1929
                    // 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
  1930
                    // (e.g. quotes: '<' '>'; or similar)
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1931
                    if ($IN_TAG && '>' == $char) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1932
                        $IN_TAG = false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1933
                        $result_line .= '>';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1934
                        ++$pos;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1935
                    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1936
                    else if (!$IN_TAG && '<' == $char) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1937
                        $IN_TAG = true;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1938
                        $result_line .= '<';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1939
                        ++$pos;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1940
                    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1941
                    else if (!$IN_TAG && '&' == $char) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1942
                        $substr = substr($line, $i + 3, 4);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1943
                        //$substr_5 = substr($line, 5, 1);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1944
                        $posi = strpos($substr, ';');
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1945
                        if (false !== $posi) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1946
                            $pos += $posi + 3;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1947
                        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1948
                        $result_line .= '&';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1949
                    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1950
                    else if (!$IN_TAG && "\t" == $char) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1951
                        $str = '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1952
                        // OPTIMISE - move $strs out. Make an array:
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1953
                        // $tabs = array(
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1954
                        //  1 => '&nbsp;',
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1955
                        //  2 => '&nbsp; ',
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1956
                        //  3 => '&nbsp; &nbsp;' etc etc
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1957
                        // to use instead of building a string every time
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1958
                        $strs = array(0 => '&nbsp;', 1 => ' ');
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1959
                        for ($k = 0; $k < ($tab_width - (($i - $pos) % $tab_width)); $k++) $str .= $strs[$k % 2];
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1960
                        $result_line .= $str;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1961
                        $pos += ($i - $pos) % $tab_width + 1;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1962
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1963
                        if (false === strpos($line, "\t", $i + 1)) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1964
                            $result_line .= substr($line, $i + 1);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1965
                            break;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1966
                        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1967
                    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1968
                    else if ($IN_TAG) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1969
                        ++$pos;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1970
                        $result_line .= $char;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1971
                    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1972
                    else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1973
                        $result_line .= $char;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1974
                        //++$pos;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1975
                    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1976
                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1977
                $lines[$key] = $result_line;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1978
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1979
            $result = implode("\n", $lines);
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
        // Other whitespace
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1982
        // BenBE: Fix to reduce the number of replacements to be done
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1983
        $result = str_replace("\n ", "\n&nbsp;", $result);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1984
        $result = str_replace('  ', ' &nbsp;', $result);
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
        if ($this->line_numbers == GESHI_NO_LINE_NUMBERS) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1987
			if ($this->line_ending === null) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1988
				$result = nl2br($result);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1989
			} else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1990
				$result = str_replace("\n", $this->line_ending, $result);
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
		}
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1993
        return $result;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1994
    }
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
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1997
     * 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
  1998
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  1999
     * @param  string The keyword to change the case of
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2000
     * @return string The keyword with its case changed
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2001
     * @since  1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2002
     * @access private
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2003
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2004
    function change_case($instr) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2005
        if ($this->language_data['CASE_KEYWORDS'] == GESHI_CAPS_UPPER) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2006
            return strtoupper($instr);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2007
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2008
        else if ($this->language_data['CASE_KEYWORDS'] == GESHI_CAPS_LOWER) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2009
            return strtolower($instr);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2010
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2011
        return $instr;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2012
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2013
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
     * Adds a url to a keyword where needed.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2016
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2017
     * @param  string The keyword to add the URL HTML to
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2018
     * @param  int What group the keyword is from
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2019
     * @param  boolean Whether to get the HTML for the start or end
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2020
     * @return The HTML for either the start or end of the HTML &lt;a&gt; tag
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2021
     * @since  1.0.2
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2022
     * @access private
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2023
     * @todo   Get rid of ender
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2024
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2025
    function add_url_to_keyword($keyword, $group, $start_or_end) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2026
        if (!$this->keyword_links) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2027
            // Keyword links have been disabled
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2028
            return;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2029
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2030
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2031
        if (isset($this->language_data['URLS'][$group]) &&
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2032
            $this->language_data['URLS'][$group] != '' &&
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2033
            substr($keyword, 0, 5) != '&lt;/') {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2034
            // There is a base group for this keyword
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2035
            if ($start_or_end == 'BEGIN') {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2036
                // HTML workaround... not good form (tm) but should work for 1.0.X
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2037
                if ($keyword != '') {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2038
                    // Old system: strtolower
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2039
                    //$keyword = ( $this->language_data['CASE_SENSITIVE'][$group] ) ? $keyword : strtolower($keyword);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2040
                    // New system: get keyword from language file to get correct case
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2041
                    foreach ($this->language_data['KEYWORDS'][$group] as $word) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2042
                        if (strtolower($word) == strtolower($keyword)) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2043
                            break;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2044
                        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2045
                    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2046
                    $word = ( substr($word, 0, 4) == '&lt;' ) ? substr($word, 4) : $word;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2047
                    $word = ( substr($word, -4) == '&gt;' ) ? substr($word, 0, strlen($word) - 4) : $word;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2048
                    if (!$word) return '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2049
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2050
                    return '<|UR1|"' .
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2051
                        str_replace(
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2052
                            array('{FNAME}', '.'),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2053
                            array(GeSHi::hsc($word), '<DOT>'),
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2054
                            $this->language_data['URLS'][$group]
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2055
                        ) . '">';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2056
                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2057
                return '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2058
            // HTML fix. Again, dirty hackage...
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2059
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2060
            else if (!($this->language == 'html4strict' && ('&gt;' == $keyword || '&lt;' == $keyword))) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2061
                return '</a>';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2062
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2063
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2064
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2065
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2066
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2067
     * 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
  2068
     * stuff like keywords, numbers and methods.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2069
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2070
     * @param string The string to parse for keyword, numbers etc.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2071
     * @since 1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2072
     * @access private
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2073
     * @todo BUGGY! Why? Why not build string and return?
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2074
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2075
    function parse_non_string_part(&$stuff_to_parse) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2076
        $stuff_to_parse = ' ' . GeSHi::hsc($stuff_to_parse);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2077
        $stuff_to_parse_pregquote = preg_quote($stuff_to_parse, '/');
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2078
        $func = '$this->change_case';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2079
        $func2 = '$this->add_url_to_keyword';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2080
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
        // Regular expressions
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2083
        //
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2084
        foreach ($this->language_data['REGEXPS'] as $key => $regexp) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2085
            if ($this->lexic_permissions['REGEXPS'][$key]) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2086
                if (is_array($regexp)) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2087
                    $stuff_to_parse = preg_replace(
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2088
                        "/" .
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2089
                        str_replace('/', '\/', $regexp[GESHI_SEARCH]) .
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2090
                        "/{$regexp[GESHI_MODIFIERS]}",
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2091
                        "{$regexp[GESHI_BEFORE]}<|!REG3XP$key!>{$regexp[GESHI_REPLACE]}|>{$regexp[GESHI_AFTER]}",
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2092
                        $stuff_to_parse
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2093
                    );
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2094
                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2095
                else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2096
                    $stuff_to_parse = preg_replace( "/(" . str_replace('/', '\/', $regexp) . ")/", "<|!REG3XP$key!>\\1|>", $stuff_to_parse);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2097
                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2098
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2099
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2100
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2101
        //
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2102
        // Highlight numbers. This regexp sucks... anyone with a regexp that WORKS
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2103
        // here wins a cookie if they send it to me. At the moment there's two doing
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2104
        // almost exactly the same thing, except the second one prevents a number
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2105
        // being highlighted twice (eg <span...><span...>5</span></span>)
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2106
        // Put /NUM!/ in for the styles, which gets replaced at the end.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2107
        //
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2108
        // NEW ONE: Brice Bernard
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2109
        //
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2110
        if ($this->lexic_permissions['NUMBERS'] && preg_match('#[0-9]#', $stuff_to_parse )) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2111
            $stuff_to_parse = preg_replace('/([-+]?\\b(?:[0-9]*\\.)?[0-9]+\\b)/', '<|/NUM!/>\\1|>', $stuff_to_parse);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2112
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2113
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2114
        // Highlight keywords
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2115
        // if there is a couple of alpha symbols there *might* be a keyword
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2116
        if (preg_match('#[a-zA-Z]{2,}#', $stuff_to_parse)) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2117
            foreach ($this->language_data['KEYWORDS'] as $k => $keywordset) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2118
                if ($this->lexic_permissions['KEYWORDS'][$k]) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2119
                    foreach ($keywordset as $keyword) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2120
                        $keyword = preg_quote($keyword, '/');
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2121
                        //
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2122
                        // This replacement checks the word is on it's own (except if brackets etc
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2123
                        // are next to it), then highlights it. We don't put the color=" for the span
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2124
                        // in just yet - otherwise languages with the keywords "color" or "or" have
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2125
                        // a fit.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2126
                        //
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2127
                        if (false !== stristr($stuff_to_parse_pregquote, $keyword )) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2128
                            $stuff_to_parse .= ' ';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2129
                            // Might make a more unique string for putting the number in soon
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2130
                            // Basically, we don't put the styles in yet because then the styles themselves will
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2131
                            // get highlighted if the language has a CSS keyword in it (like CSS, for example ;))
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2132
                            $styles = "/$k/";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2133
                            if ($this->language_data['CASE_SENSITIVE'][$k]) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2134
                                $stuff_to_parse = preg_replace(
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2135
                                    "/([^a-zA-Z0-9\$_\|\#;>|^])($keyword)(?=[^a-zA-Z0-9_<\|%\-&])/e",
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2136
                                    "'\\1' . $func2('\\2', '$k', 'BEGIN') . '<|$styles>' . $func('\\2') . '|>' . $func2('\\2', '$k', 'END')",
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2137
                                    $stuff_to_parse
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2138
                                );
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2139
                            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2140
                            else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2141
                                // Change the case of the word.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2142
                                // hackage again... must... release... 1.2...
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2143
                                if ('smarty' == $this->language) { $hackage = '\/'; } else { $hackage = ''; }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2144
                                $stuff_to_parse = preg_replace(
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2145
                                    "/([^a-zA-Z0-9\$_\|\#;>$hackage|^])($keyword)(?=[^a-zA-Z0-9_<\|%\-&])/ie",
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2146
                                    "'\\1' . $func2('\\2', '$k', 'BEGIN') . '<|$styles>' . $func('\\2') . '|>' . $func2('\\2', '$k', 'END')",
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2147
                                    $stuff_to_parse
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2148
                                );
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2149
                            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2150
                            $stuff_to_parse = substr($stuff_to_parse, 0, strlen($stuff_to_parse) - 1);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2151
                        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2152
                    }
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
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2155
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2156
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2157
        //
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2158
        // 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
  2159
        //
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2160
        foreach ($this->language_data['KEYWORDS'] as $k => $kws) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2161
            if (!$this->use_classes) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2162
                $attributes = ' style="' . $this->language_data['STYLES']['KEYWORDS'][$k] . '"';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2163
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2164
            else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2165
                $attributes = ' class="kw' . $k . '"';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2166
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2167
            $stuff_to_parse = str_replace("/$k/", $attributes, $stuff_to_parse);
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
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2170
        // Put number styles in
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2171
        if (!$this->use_classes && $this->lexic_permissions['NUMBERS']) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2172
            $attributes = ' style="' . $this->language_data['STYLES']['NUMBERS'][0] . '"';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2173
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2174
        else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2175
            $attributes = ' class="nu0"';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2176
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2177
        $stuff_to_parse = str_replace('/NUM!/', $attributes, $stuff_to_parse);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2178
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2179
        //
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2180
        // Highlight methods and fields in objects
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2181
        //
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2182
        if ($this->lexic_permissions['METHODS'] && $this->language_data['OOLANG']) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2183
            foreach ($this->language_data['OBJECT_SPLITTERS'] as $key => $splitter) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2184
                if (false !== stristr($stuff_to_parse, $splitter)) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2185
                    if (!$this->use_classes) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2186
                        $attributes = ' style="' . $this->language_data['STYLES']['METHODS'][$key] . '"';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2187
                    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2188
                    else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2189
                        $attributes = ' class="me' . $key . '"';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2190
                    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2191
                    $stuff_to_parse = preg_replace("/(" . preg_quote($this->language_data['OBJECT_SPLITTERS'][$key], 1) . "[\s]*)([a-zA-Z\*\(][a-zA-Z0-9_\*]*)/", "\\1<|$attributes>\\2|>", $stuff_to_parse);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2192
                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2193
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2194
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2195
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2196
        //
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2197
        // 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
  2198
        // You try it, and see what happens ;)
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2199
        // TODO: Fix lexic permissions not converting entities if shouldn't
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2200
        // be highlighting regardless
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2201
        //
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2202
        if ($this->lexic_permissions['BRACKETS']) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2203
            $code_entities_match = array('[', ']', '(', ')', '{', '}');
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2204
            if (!$this->use_classes) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2205
                $code_entities_replace = array(
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2206
                    '<| style="' . $this->language_data['STYLES']['BRACKETS'][0] . '">&#91;|>',
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2207
                    '<| style="' . $this->language_data['STYLES']['BRACKETS'][0] . '">&#93;|>',
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2208
                    '<| style="' . $this->language_data['STYLES']['BRACKETS'][0] . '">&#40;|>',
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2209
                    '<| style="' . $this->language_data['STYLES']['BRACKETS'][0] . '">&#41;|>',
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2210
                    '<| style="' . $this->language_data['STYLES']['BRACKETS'][0] . '">&#123;|>',
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2211
                    '<| style="' . $this->language_data['STYLES']['BRACKETS'][0] . '">&#125;|>',
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2212
                );
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2213
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2214
            else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2215
                $code_entities_replace = array(
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2216
                    '<| class="br0">&#91;|>',
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2217
                    '<| class="br0">&#93;|>',
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2218
                    '<| class="br0">&#40;|>',
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2219
                    '<| class="br0">&#41;|>',
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2220
                    '<| class="br0">&#123;|>',
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2221
                    '<| class="br0">&#125;|>',
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2222
                );
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2223
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2224
            $stuff_to_parse = str_replace( $code_entities_match,  $code_entities_replace, $stuff_to_parse );
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2225
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2226
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2227
        //
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2228
        // Add class/style for regexps
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2229
        //
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2230
        foreach ($this->language_data['REGEXPS'] as $key => $regexp) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2231
            if ($this->lexic_permissions['REGEXPS'][$key]) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2232
                if (!$this->use_classes) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2233
                    $attributes = ' style="' . $this->language_data['STYLES']['REGEXPS'][$key] . '"';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2234
                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2235
                else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2236
                   if(is_array($this->language_data['REGEXPS'][$key]) &&
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2237
                            array_key_exists(GESHI_CLASS, $this->language_data['REGEXPS'][$key])) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2238
                        $attributes = ' class="'
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2239
                            . $this->language_data['REGEXPS'][$key][GESHI_CLASS] . '"';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2240
                    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2241
                   else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2242
                       $attributes = ' class="re' . $key . '"';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2243
                    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2244
                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2245
                $stuff_to_parse = str_replace("!REG3XP$key!", "$attributes", $stuff_to_parse);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2246
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2247
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2248
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2249
        // Replace <DOT> with . for urls
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2250
        $stuff_to_parse = str_replace('<DOT>', '.', $stuff_to_parse);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2251
        // Replace <|UR1| with <a href= for urls also
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2252
        if (isset($this->link_styles[GESHI_LINK])) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2253
            if ($this->use_classes) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2254
                $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
  2255
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2256
            else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2257
                $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
  2258
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2259
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2260
        else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2261
            $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
  2262
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2263
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2264
        //
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2265
        // NOW we add the span thingy ;)
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2266
        //
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2267
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2268
        $stuff_to_parse = str_replace('<|', '<span', $stuff_to_parse);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2269
        $stuff_to_parse = str_replace ( '|>', '</span>', $stuff_to_parse );
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2270
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2271
        return substr($stuff_to_parse, 1);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2272
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2273
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2274
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2275
     * Sets the time taken to parse the code
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2276
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2277
     * @param microtime The time when parsing started
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2278
     * @param microtime The time when parsing ended
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2279
     * @since 1.0.2
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2280
     * @access private
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2281
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2282
    function set_time($start_time, $end_time) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2283
        $start = explode(' ', $start_time);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2284
        $end = explode(' ', $end_time);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2285
        $this->time = $end[0] + $end[1] - $start[0] - $start[1];
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2286
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2287
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2288
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2289
     * Gets the time taken to parse the code
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2290
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2291
     * @return double The time taken to parse the code
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2292
     * @since  1.0.2
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2293
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2294
    function get_time() {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2295
        return $this->time;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2296
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2297
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2298
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2299
     * Gets language information and stores it for later use
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2300
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2301
     * @access private
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2302
     * @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
  2303
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2304
    function load_language($file_name) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2305
        $this->enable_highlighting();
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2306
        $language_data = array();
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2307
        require $file_name;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2308
        // 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
  2309
        // $language data is a valid thing but maybe not
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2310
        $this->language_data = $language_data;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2311
        // Set strict mode if should be set
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2312
        if ($this->language_data['STRICT_MODE_APPLIES'] == GESHI_ALWAYS) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2313
            $this->strict_mode = true;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2314
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2315
        // Set permissions for all lexics to true
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2316
        // so they'll be highlighted by default
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2317
        foreach ($this->language_data['KEYWORDS'] as $key => $words) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2318
            $this->lexic_permissions['KEYWORDS'][$key] = true;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2319
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2320
        foreach ($this->language_data['COMMENT_SINGLE'] as $key => $comment) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2321
            $this->lexic_permissions['COMMENTS'][$key] = true;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2322
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2323
        foreach ($this->language_data['REGEXPS'] as $key => $regexp) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2324
            $this->lexic_permissions['REGEXPS'][$key] = true;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2325
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2326
        // Set default class for CSS
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2327
        $this->overall_class = $this->language;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2328
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2329
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2330
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2331
     * 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
  2332
     * surrounding it to make it look nice.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2333
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2334
     * @param  string The code already parsed
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2335
     * @return string The code nicely finalised
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2336
     * @since  1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2337
     * @access private
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2338
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2339
    function finalise($parsed_code) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2340
        // Remove end parts of important declarations
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2341
        // 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
  2342
        // @todo Remove this crap
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2343
        if ($this->enable_important_blocks &&
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2344
            (strstr($parsed_code, GeSHi::hsc(GESHI_START_IMPORTANT)) === false)) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2345
            $parsed_code = str_replace(GeSHi::hsc(GESHI_END_IMPORTANT), '', $parsed_code);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2346
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2347
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2348
        // Add HTML whitespace stuff if we're using the <div> header
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2349
        if ($this->header_type != GESHI_HEADER_PRE) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2350
            $parsed_code = $this->indent($parsed_code);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2351
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2352
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2353
        // purge some unnecessary stuff
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2354
        $parsed_code = preg_replace('#<span[^>]+>(\s*)</span>#', '\\1', $parsed_code);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2355
        $parsed_code = preg_replace('#<div[^>]+>(\s*)</div>#', '\\1', $parsed_code);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2356
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2357
        // 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
  2358
        // ID set to prevent collisions.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2359
        if ($this->add_ids && !$this->overall_id) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2360
            $this->overall_id = 'geshi-' . substr(md5(microtime()), 0, 4);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2361
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2362
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2363
        // 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
  2364
        // markup to style them (otherwise we don't need to do anything)
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2365
        if ($this->line_numbers != GESHI_NO_LINE_NUMBERS) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2366
            // 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
  2367
            // the <pre> will line-break them (and the <li>s already do this for us)
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2368
            $ls = ($this->header_type != GESHI_HEADER_PRE) ? "\n" : '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2369
            // Get code into lines
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2370
            $code = explode("\n", $parsed_code);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2371
            // Set vars to defaults for following loop
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2372
            $parsed_code = '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2373
            $i = 0;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2374
            $attrs = array();
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2375
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2376
            // Foreach line...
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2377
            foreach ($code as $line) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2378
                // 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
  2379
                // BenBE: Checking emptiness using trim instead of relying on blanks
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2380
                if ('' == trim($line)) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2381
                    $line = '&nbsp;';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2382
                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2383
                // If this is a "special line"...
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2384
                if ($this->line_numbers == GESHI_FANCY_LINE_NUMBERS &&
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2385
                    $i % $this->line_nth_row == ($this->line_nth_row - 1)) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2386
                    // Set the attributes to style the line
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2387
                    if ($this->use_classes) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2388
                        //$attr = ' class="li2"';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2389
                        $attrs['class'][] = 'li2';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2390
                        $def_attr = ' class="de2"';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2391
                    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2392
                    else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2393
                        //$attr = ' style="' . $this->line_style2 . '"';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2394
                        $attrs['style'][] = $this->line_style2;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2395
                        // 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
  2396
                        // 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
  2397
                        // code on that line
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2398
                        $def_attr = ' style="' . $this->code_style . '"';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2399
                    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2400
                    // Span or div?
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2401
                    $start = "<div$def_attr>";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2402
                    $end = '</div>';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2403
                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2404
                else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2405
                    if ($this->use_classes) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2406
                        //$attr = ' class="li1"';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2407
                        $attrs['class'][] = 'li1';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2408
                        $def_attr = ' class="de1"';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2409
                    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2410
                    else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2411
                        //$attr = ' style="' . $this->line_style1 . '"';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2412
                        $attrs['style'][] = $this->line_style1;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2413
                        $def_attr = ' style="' . $this->code_style . '"';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2414
                    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2415
                    $start = "<div$def_attr>";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2416
                    $end = '</div>';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2417
                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2418
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2419
                ++$i;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2420
                // Are we supposed to use ids? If so, add them
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2421
                if ($this->add_ids) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2422
                    $attrs['id'][] = "$this->overall_id-$i";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2423
                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2424
                if ($this->use_classes && in_array($i, $this->highlight_extra_lines)) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2425
                    $attrs['class'][] = 'ln-xtra';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2426
                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2427
                if (!$this->use_classes && in_array($i, $this->highlight_extra_lines)) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2428
                    $attrs['style'][] = $this->highlight_extra_lines_style;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2429
                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2430
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2431
                // Add in the line surrounded by appropriate list HTML
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2432
                $attr_string = ' ';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2433
                foreach ($attrs as $key => $attr) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2434
                    $attr_string .= $key . '="' . implode(' ', $attr) . '" ';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2435
                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2436
                $attr_string = substr($attr_string, 0, -1);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2437
                $parsed_code .= "<li$attr_string>$start$line$end</li>$ls";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2438
                $attrs = array();
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2439
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2440
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2441
        else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2442
            // 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
  2443
            // Have to use divs so the full width of the code is highlighted
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2444
            $code = explode("\n", $parsed_code);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2445
            $parsed_code = '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2446
            $i = 0;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2447
            foreach ($code as $line) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2448
                // 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
  2449
                // BenBE: Checking emptiness using trim instead of relying on blanks
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2450
                if ('' == trim($line)) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2451
                    $line = '&nbsp;';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2452
                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2453
                if (in_array(++$i, $this->highlight_extra_lines)) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2454
                    if ($this->use_classes) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2455
                        $parsed_code .= '<div class="ln-xtra">';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2456
                    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2457
                    else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2458
                        $parsed_code .= "<div style=\"{$this->highlight_extra_lines_style}\">";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2459
                    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2460
                    // Remove \n because it stuffs up <pre> header
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2461
                    $parsed_code .= $line . "</div>";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2462
                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2463
                else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2464
                    $parsed_code .= $line . "\n";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2465
                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2466
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2467
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2468
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2469
        if ($this->header_type == GESHI_HEADER_PRE) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2470
            // enforce line numbers when using pre
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2471
            $parsed_code = str_replace('<li></li>', '<li>&nbsp;</li>', $parsed_code);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2472
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2473
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2474
        return $this->header() . chop($parsed_code) . $this->footer();
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2475
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2476
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2477
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2478
     * Creates the header for the code block (with correct attributes)
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2479
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2480
     * @return string The header for the code block
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2481
     * @since  1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2482
     * @access private
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2483
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2484
    function header() {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2485
        // Get attributes needed
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2486
        $attributes = $this->get_attributes();
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2487
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2488
        $ol_attributes = '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2489
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2490
        if ($this->line_numbers_start != 1) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2491
            $ol_attributes .= ' start="' . $this->line_numbers_start . '"';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2492
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2493
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2494
        // Get the header HTML
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2495
        $header = $this->format_header_content();
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2496
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2497
        if (GESHI_HEADER_NONE == $this->header_type) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2498
            if ($this->line_numbers != GESHI_NO_LINE_NUMBERS) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2499
                return "$header<ol$ol_attributes>";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2500
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2501
            return $header .
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2502
                ($this->force_code_block ? '<div>' : '');
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2503
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2504
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2505
        // Work out what to return and do it
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2506
        if ($this->line_numbers != GESHI_NO_LINE_NUMBERS) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2507
            if ($this->header_type == GESHI_HEADER_PRE) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2508
                return "<pre$attributes>$header<ol$ol_attributes>";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2509
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2510
            else if ($this->header_type == GESHI_HEADER_DIV) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2511
                return "<div$attributes>$header<ol$ol_attributes>";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2512
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2513
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2514
        else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2515
            if ($this->header_type == GESHI_HEADER_PRE) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2516
                return "<pre$attributes>$header"  .
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2517
                    ($this->force_code_block ? '<div>' : '');
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2518
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2519
            else if ($this->header_type == GESHI_HEADER_DIV) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2520
                return "<div$attributes>$header" .
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2521
                    ($this->force_code_block ? '<div>' : '');
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2522
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2523
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2524
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2525
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2526
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2527
     * Returns the header content, formatted for output
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2528
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2529
     * @return string The header content, formatted for output
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2530
     * @since  1.0.2
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2531
     * @access private
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2532
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2533
    function format_header_content() {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2534
        $header = $this->header_content;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2535
        if ($header) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2536
            if ($this->header_type == GESHI_HEADER_PRE) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2537
                $header = str_replace("\n", '', $header);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2538
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2539
            $header = $this->replace_keywords($header);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2540
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2541
            if ($this->use_classes) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2542
                $attr = ' class="head"';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2543
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2544
            else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2545
                $attr = " style=\"{$this->header_content_style}\"";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2546
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2547
            return "<div$attr>$header</div>";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2548
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2549
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2550
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2551
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2552
     * Returns the footer for the code block.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2553
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2554
     * @return string The footer for the code block
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2555
     * @since  1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2556
     * @access private
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2557
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2558
    function footer() {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2559
        $footer_content = $this->format_footer_content();
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2560
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2561
        if (GESHI_HEADER_NONE == $this->header_type) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2562
            return ($this->line_numbers != GESHI_NO_LINE_NUMBERS) ? '</ol>' . $footer_content
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2563
                : $footer_content;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2564
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2565
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2566
        if ($this->header_type == GESHI_HEADER_DIV) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2567
            if ($this->line_numbers != GESHI_NO_LINE_NUMBERS) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2568
                return "</ol>$footer_content</div>";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2569
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2570
            return ($this->force_code_block ? '</div>' : '') .
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2571
                "$footer_content</div>";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2572
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2573
        else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2574
            if ($this->line_numbers != GESHI_NO_LINE_NUMBERS) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2575
                return "</ol>$footer_content</pre>";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2576
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2577
            return ($this->force_code_block ? '</div>' : '') .
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2578
                "$footer_content</pre>";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2579
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2580
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2581
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2582
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2583
     * Returns the footer content, formatted for output
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2584
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2585
     * @return string The footer content, formatted for output
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2586
     * @since  1.0.2
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2587
     * @access private
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2588
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2589
    function format_footer_content() {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2590
        $footer = $this->footer_content;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2591
        if ($footer) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2592
            if ($this->header_type == GESHI_HEADER_PRE) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2593
                $footer = str_replace("\n", '', $footer);;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2594
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2595
            $footer = $this->replace_keywords($footer);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2596
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2597
            if ($this->use_classes) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2598
                $attr = ' class="foot"';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2599
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2600
            else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2601
                $attr = " style=\"{$this->footer_content_style}\"";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2602
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2603
            return "<div$attr>$footer</div>";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2604
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2605
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2606
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2607
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2608
     * Replaces certain keywords in the header and footer with
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2609
     * certain configuration values
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2610
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2611
     * @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
  2612
     * @return string The header or footer with replaced keywords
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2613
     * @since  1.0.2
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2614
     * @access private
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2615
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2616
    function replace_keywords($instr) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2617
        $keywords = $replacements = array();
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2618
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2619
        $keywords[] = '<TIME>';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2620
        $keywords[] = '{TIME}';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2621
        $replacements[] = $replacements[] = number_format($this->get_time(), 3);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2622
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2623
        $keywords[] = '<LANGUAGE>';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2624
        $keywords[] = '{LANGUAGE}';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2625
        $replacements[] = $replacements[] = $this->language;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2626
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2627
        $keywords[] = '<VERSION>';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2628
        $keywords[] = '{VERSION}';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2629
        $replacements[] = $replacements[] = GESHI_VERSION;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2630
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2631
        return str_replace($keywords, $replacements, $instr);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2632
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2633
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2634
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2635
     * Gets the CSS attributes for this code
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2636
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2637
     * @return The CSS attributes for this code
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2638
     * @since  1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2639
     * @access private
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2640
     * @todo   Document behaviour change - class is outputted regardless of whether we're using classes or not.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2641
     *         Same with style
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2642
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2643
    function get_attributes() {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2644
        $attributes = '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2645
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2646
        if ($this->overall_class != '') {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2647
            $attributes .= " class=\"{$this->overall_class}\"";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2648
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2649
        if ($this->overall_id != '') {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2650
            $attributes .= " id=\"{$this->overall_id}\"";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2651
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2652
        if ($this->overall_style != '') {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2653
            $attributes .= ' style="' . $this->overall_style . '"';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2654
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2655
        return $attributes;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2656
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2657
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2658
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2659
     * Secure replacement for PHP built-in function htmlspecialchars().
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2660
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2661
     * 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
  2662
     * for this replacement function.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2663
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2664
     * 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
  2665
     * htmlspecialchars(), with the same default for quote style; however, there
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2666
     * 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
  2667
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2668
     * The PHP docs say:
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2669
     *      "The third argument charset defines character set used in conversion."
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2670
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2671
     * 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
  2672
     * 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
  2673
     * 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
  2674
     * different character sets. (If indeed htmlspecialchars() works at
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2675
     * 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
  2676
     * 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
  2677
     * htmlentities() which certainly is working at byte-value level.)
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2678
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2679
     * This replacement function however works at character level and should
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2680
     * therefore be "immune" to character set differences - so no charset
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2681
     * 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
  2682
     * be silently ignored.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2683
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2684
     * 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
  2685
     * 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
  2686
     *      get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES)
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2687
     * (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
  2688
     * http://php.net/htmlspecialchars); it also matches the entity definition
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2689
     * for XML 1.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2690
     * (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
  2691
     * 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
  2692
     * 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
  2693
     * references, as PHP is doing.
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2694
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2695
     * @author      {@link http://wikkawiki.org/JavaWoman Marjolein Katsma}
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2696
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2697
     * @license     http://www.gnu.org/copyleft/lgpl.html
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2698
     *              GNU Lesser General Public License
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2699
     * @copyright   Copyright 2007, {@link http://wikkawiki.org/CreditsPage
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2700
     *              Wikka Development Team}
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2701
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2702
     * @access      public
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2703
     * @param       string  $string string to be converted
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2704
     * @param       integer $quote_style
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2705
     *                      - ENT_COMPAT:   escapes &, <, > and double quote (default)
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2706
     *                      - ENT_NOQUOTES: escapes only &, < and >
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2707
     *                      - ENT_QUOTES:   escapes &, <, >, double and single quotes
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2708
     * @return      string  converted string
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2709
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2710
    function hsc($string, $quote_style=ENT_COMPAT) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2711
        // init
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2712
        $aTransSpecchar = array(
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2713
            '&' => '&amp;',
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2714
            '"' => '&quot;',
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2715
            '<' => '&lt;',
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2716
            '>' => '&gt;'
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2717
            );                      // ENT_COMPAT set
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2718
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2719
        if (ENT_NOQUOTES == $quote_style)       // don't convert double quotes
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2720
        {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2721
            unset($aTransSpecchar['"']);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2722
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2723
        elseif (ENT_QUOTES == $quote_style)     // convert single quotes as well
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2724
        {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2725
            $aTransSpecchar["'"] = '&#39;'; // (apos) htmlspecialchars() uses '&#039;'
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2726
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2727
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2728
        // return translated string
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2729
        return strtr($string,$aTransSpecchar);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2730
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2731
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2732
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2733
     * Returns a stylesheet for the highlighted code. If $economy mode
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2734
     * 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
  2735
     * this code block instead of the whole thing
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2736
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2737
     * @param  boolean Whether to use economy mode or not
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2738
     * @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
  2739
     * @since  1.0.0
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2740
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2741
    function get_stylesheet($economy_mode = true) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2742
        // 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
  2743
        // 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
  2744
        // risk getting a stylesheet...
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2745
        if ($this->error) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2746
            return '';
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
        // 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
  2749
        // 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
  2750
        // of '' means that these styles will be applied anywhere
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2751
        $selector = ($this->overall_id != '') ? "#{$this->overall_id} " : '';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2752
        $selector = ($selector == '' && $this->overall_class != '') ? ".{$this->overall_class} " : $selector;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2753
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2754
        // Header of the stylesheet
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2755
        if (!$economy_mode) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2756
            $stylesheet = "/**\n * GeSHi Dynamically Generated Stylesheet\n * --------------------------------------\n * Dynamically generated stylesheet for {$this->language}\n * CSS class: {$this->overall_class}, CSS id: {$this->overall_id}\n * GeSHi (C) 2004 - 2007 Nigel McNie (http://qbnz.com/highlighter)\n */\n";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2757
         } else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2758
            $stylesheet = '/* GeSHi (C) 2004 - 2007 Nigel McNie (http://qbnz.com/highlighter) */' . "\n";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2759
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2760
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2761
        // 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
  2762
        // (<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
  2763
        // 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
  2764
        // <pre> or <div> container). Additionally, set default styles for lines
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2765
        if (!$economy_mode || $this->line_numbers != GESHI_NO_LINE_NUMBERS) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2766
            //$stylesheet .= "$selector, {$selector}ol, {$selector}ol li {margin: 0;}\n";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2767
            $stylesheet .= "$selector.de1, $selector.de2 {{$this->code_style}}\n";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2768
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2769
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2770
        // Add overall styles
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2771
        if (!$economy_mode || $this->overall_style != '') {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2772
            $stylesheet .= "$selector {{$this->overall_style}}\n";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2773
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2774
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2775
        // Add styles for links
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2776
        foreach ($this->link_styles as $key => $style) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2777
            if (!$economy_mode || $key == GESHI_LINK && $style != '') {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2778
                $stylesheet .= "{$selector}a:link {{$style}}\n";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2779
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2780
            if (!$economy_mode || $key == GESHI_HOVER && $style != '') {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2781
                $stylesheet .= "{$selector}a:hover {{$style}}\n";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2782
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2783
            if (!$economy_mode || $key == GESHI_ACTIVE && $style != '') {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2784
                $stylesheet .= "{$selector}a:active {{$style}}\n";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2785
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2786
            if (!$economy_mode || $key == GESHI_VISITED && $style != '') {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2787
                $stylesheet .= "{$selector}a:visited {{$style}}\n";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2788
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2789
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2790
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2791
        // Header and footer
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2792
        if (!$economy_mode || $this->header_content_style != '') {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2793
            $stylesheet .= "$selector.head {{$this->header_content_style}}\n";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2794
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2795
        if (!$economy_mode || $this->footer_content_style != '') {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2796
            $stylesheet .= "$selector.foot {{$this->footer_content_style}}\n";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2797
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2798
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2799
        // Styles for important stuff
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2800
        if (!$economy_mode || $this->important_styles != '') {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2801
            $stylesheet .= "$selector.imp {{$this->important_styles}}\n";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2802
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2803
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2804
        // Styles for lines being highlighted extra
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2805
        if (!$economy_mode || count($this->highlight_extra_lines)) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2806
            $stylesheet .= "$selector.ln-xtra {{$this->highlight_extra_lines_style}}\n";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2807
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2808
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2809
        // Simple line number styles
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2810
        if (!$economy_mode || ($this->line_numbers != GESHI_NO_LINE_NUMBERS && $this->line_style1 != '')) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2811
            $stylesheet .= "{$selector}li {{$this->line_style1}}\n";
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
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2814
        // If there is a style set for fancy line numbers, echo it out
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2815
        if (!$economy_mode || ($this->line_numbers == GESHI_FANCY_LINE_NUMBERS && $this->line_style2 != '')) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2816
            $stylesheet .= "{$selector}li.li2 {{$this->line_style2}}\n";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2817
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2818
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2819
        foreach ($this->language_data['STYLES']['KEYWORDS'] as $group => $styles) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2820
            if (!$economy_mode || !($economy_mode && (!$this->lexic_permissions['KEYWORDS'][$group] || $styles == ''))) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2821
                $stylesheet .= "$selector.kw$group {{$styles}}\n";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2822
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2823
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2824
        foreach ($this->language_data['STYLES']['COMMENTS'] as $group => $styles) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2825
            if (!$economy_mode || !($economy_mode && $styles == '') &&
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2826
                !($economy_mode && !$this->lexic_permissions['COMMENTS'][$group])) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2827
                $stylesheet .= "$selector.co$group {{$styles}}\n";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2828
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2829
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2830
        foreach ($this->language_data['STYLES']['ESCAPE_CHAR'] as $group => $styles) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2831
            if (!$economy_mode || !($economy_mode && $styles == '') && !($economy_mode &&
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2832
                !$this->lexic_permissions['ESCAPE_CHAR'])) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2833
                $stylesheet .= "$selector.es$group {{$styles}}\n";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2834
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2835
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2836
        foreach ($this->language_data['STYLES']['SYMBOLS'] as $group => $styles) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2837
            if (!$economy_mode || !($economy_mode && $styles == '') && !($economy_mode &&
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2838
                !$this->lexic_permissions['BRACKETS'])) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2839
                $stylesheet .= "$selector.br$group {{$styles}}\n";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2840
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2841
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2842
        foreach ($this->language_data['STYLES']['STRINGS'] as $group => $styles) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2843
            if (!$economy_mode || !($economy_mode && $styles == '') && !($economy_mode &&
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2844
                !$this->lexic_permissions['STRINGS'])) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2845
                $stylesheet .= "$selector.st$group {{$styles}}\n";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2846
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2847
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2848
        foreach ($this->language_data['STYLES']['NUMBERS'] as $group => $styles) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2849
            if (!$economy_mode || !($economy_mode && $styles == '') && !($economy_mode &&
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2850
                !$this->lexic_permissions['NUMBERS'])) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2851
                $stylesheet .= "$selector.nu$group {{$styles}}\n";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2852
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2853
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2854
        foreach ($this->language_data['STYLES']['METHODS'] as $group => $styles) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2855
            if (!$economy_mode || !($economy_mode && $styles == '') && !($economy_mode &&
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2856
                !$this->lexic_permissions['METHODS'])) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2857
                $stylesheet .= "$selector.me$group {{$styles}}\n";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2858
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2859
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2860
        foreach ($this->language_data['STYLES']['SCRIPT'] as $group => $styles) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2861
            if (!$economy_mode || !($economy_mode && $styles == '')) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2862
                $stylesheet .= "$selector.sc$group {{$styles}}\n";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2863
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2864
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2865
        foreach ($this->language_data['STYLES']['REGEXPS'] as $group => $styles) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2866
            if (!$economy_mode || !($economy_mode && $styles == '') && !($economy_mode &&
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2867
                !$this->lexic_permissions['REGEXPS'][$group])) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2868
                if (is_array($this->language_data['REGEXPS'][$group]) &&
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2869
                         array_key_exists(GESHI_CLASS,
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2870
                                    $this->language_data['REGEXPS'][$group])) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2871
                    $stylesheet .= "$selector.";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2872
                    $stylesheet .= $this->language_data['REGEXPS'][$group][GESHI_CLASS];
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2873
                    $stylesheet .= " {{$styles}}\n";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2874
                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2875
                else {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2876
                    $stylesheet .= "$selector.re$group {{$styles}}\n";
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2877
                }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2878
            }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2879
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2880
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2881
        return $stylesheet;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2882
    }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2883
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2884
} // End Class GeSHi
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2885
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2886
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2887
if (!function_exists('geshi_highlight')) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2888
    /**
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2889
     * Easy way to highlight stuff. Behaves just like highlight_string
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2890
     *
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2891
     * @param string The code to highlight
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2892
     * @param string The language to highlight the code in
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2893
     * @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
  2894
     *               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
  2895
     * @param boolean Whether to return the result or to echo
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2896
     * @return string The code highlighted (if $return is true)
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2897
     * @since 1.0.2
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2898
     */
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2899
    function geshi_highlight($string, $language, $path = null, $return = false) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2900
        $geshi = new GeSHi($string, $language, $path);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2901
        $geshi->set_header_type(GESHI_HEADER_NONE);
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2902
        if ($return) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2903
            return '<code>' . $geshi->parse_code() . '</code>';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2904
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2905
        echo '<code>' . $geshi->parse_code() . '</code>';
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2906
        if ($geshi->error()) {
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2907
            return false;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2908
        }
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2909
        return true;
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2910
    }
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
441963e5b07a Initial population - based on GeSHi 1.0.7.20
Dan
parents:
diff changeset
  2913
?>