diff --git a/htdocs/application/libraries/geshi/contrib/aliased.php b/htdocs/application/libraries/geshi/contrib/aliased.php old mode 100755 new mode 100644 index 32bec92..e57b495 --- a/htdocs/application/libraries/geshi/contrib/aliased.php +++ b/htdocs/application/libraries/geshi/contrib/aliased.php @@ -13,7 +13,7 @@ * aliased.php/file.name.ext. * * @author Ross Golder - * @version $Id: aliased.php 785 2006-07-19 10:09:45Z oracleshinoda $ + * @version $Id: aliased.php 881 2007-01-10 11:14:38Z oracleshinoda $ */ // Your config here diff --git a/htdocs/application/libraries/geshi/contrib/cssgen.php b/htdocs/application/libraries/geshi/contrib/cssgen.php old mode 100755 new mode 100644 index a749786..f746b00 --- a/htdocs/application/libraries/geshi/contrib/cssgen.php +++ b/htdocs/application/libraries/geshi/contrib/cssgen.php @@ -4,7 +4,7 @@ * ---------- * Author: Nigel McNie (nigel@geshi.org) * Copyright: (c) 2004 Nigel McNie - * Release Version: 1.0.7.19 + * Release Version: 1.0.8.6 * Date Started: 2004/05/20 * * Application to generate custom CSS files for GeSHi (based on an idea by Andreas @@ -295,7 +295,7 @@ Detected languages:
'; } } - echo "Select: All, None, Invert
\n"; + echo "Select: All, None, Invert
\n"; echo 'If you\'d like any other languages not detected here to be supported, please enter them here, one per line:

diff --git a/htdocs/application/libraries/geshi/contrib/cssgen2.php b/htdocs/application/libraries/geshi/contrib/cssgen2.php new file mode 100644 index 0000000..cc3c39c --- /dev/null +++ b/htdocs/application/libraries/geshi/contrib/cssgen2.php @@ -0,0 +1,59 @@ + geshi.css`. + * + * This file is part of GeSHi. + * + * GeSHi is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GeSHi is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GeSHi; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * @package geshi + * @subpackage contrib + * @author revulo + * @copyright 2008 revulo + * @license http://gnu.org/copyleft/gpl.html GNU GPL + * + */ + +require dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'geshi.php'; +$geshi = new GeSHi; + +$languages = array(); +if ($handle = opendir($geshi->language_path)) { + while (($file = readdir($handle)) !== false) { + $pos = strpos($file, '.'); + if ($pos > 0 && substr($file, $pos) == '.php') { + $languages[] = substr($file, 0, $pos); + } + } + closedir($handle); +} +sort($languages); + +header('Content-Type: application/octet-stream'); +header('Content-Disposition: attachment; filename="geshi.css"'); + +echo "/**\n". + " * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann\n" . + " * (http://qbnz.com/highlighter/ and http://geshi.org/)\n". + " */\n"; + +foreach ($languages as $language) { + $geshi->set_language($language); + // note: the false argument is required for stylesheet generators, see API documentation + $css = $geshi->get_stylesheet(false); + echo preg_replace('/^\/\*\*.*?\*\//s', '', $css); +} diff --git a/htdocs/application/libraries/geshi/contrib/example.php b/htdocs/application/libraries/geshi/contrib/example.php old mode 100755 new mode 100644 index 0d72cb8..bc1735c --- a/htdocs/application/libraries/geshi/contrib/example.php +++ b/htdocs/application/libraries/geshi/contrib/example.php @@ -4,59 +4,68 @@ * * Just point your browser at this script (with geshi.php in the parent directory, * and the language files in subdirectory "../geshi/") - * + * * @author Nigel McNie - * @version $Id: example.php 706 2006-05-19 11:40:16Z oracleshinoda $ + * @version $Id: example.php 1422 2008-07-11 20:30:55Z milianw $ */ +header('Content-Type: text/html; charset=utf-8'); + +error_reporting(E_ALL); // Rudimentary checking of where GeSHi is. In a default install it will be in ../, but // it could be in the current directory if the include_path is set. There's nowhere else // we can reasonably guess. -if (!@include '../geshi.php') { - if (!@include 'geshi.php') { - die('Could not find geshi.php - make sure it is in your include path!'); - } else { - $path = './'; - } -} else { +if (is_readable('../geshi.php')) { $path = '../'; +} elseif (is_readable('geshi.php')) { + $path = './'; +} else { + die('Could not find geshi.php - make sure it is in your include path!'); } +require $path . 'geshi.php'; -if ( isset($_POST['submit']) ) -{ - if ( get_magic_quotes_gpc() ) $_POST['source'] = stripslashes($_POST['source']); - if ( !strlen(trim($_POST['source'])) ) - { +$fill_source = false; +if (isset($_POST['submit'])) { + if (get_magic_quotes_gpc()) { + $_POST['source'] = stripslashes($_POST['source']); + } + if (!strlen(trim($_POST['source']))) { $_POST['language'] = preg_replace('#[^a-zA-Z0-9\-_]#', '', $_POST['language']); - $_POST['source'] = implode('', @file($path . 'geshi/' . $_POST['language'] . '.php')); - $_POST['language'] = 'php'; - } - + $_POST['source'] = implode('', @file($path . 'geshi/' . $_POST['language'] . '.php')); + $_POST['language'] = 'php'; + } else { + $fill_source = true; + } + // Here's a free demo of how GeSHi works. - + // First the initialisation: source code to highlight and the language to use. Make sure // you sanitise correctly if you use $_POST of course - this very script has had a security // advisory against it in the past because of this. Please try not to use this script on a // live site. - $geshi =& new GeSHi($_POST['source'], $_POST['language']); - - // Use the PRE header. This means less output source since we don't have to output   + $geshi = new GeSHi($_POST['source'], $_POST['language']); + + // Use the PRE_VALID header. This means less output source since we don't have to output   // everywhere. Of course it also means you can't set the tab width. - $geshi->set_header_type(GESHI_HEADER_PRE); - + // HEADER_PRE_VALID puts the
 tag inside the list items (
  • ) thus producing valid HTML markup. + // HEADER_PRE puts the
     tag around the list (
      ) which is invalid in HTML 4 and XHTML 1 + // HEADER_DIV puts a
      tag arount the list (valid!) but needs to replace whitespaces with   + // thus producing much larger overhead. You can set the tab width though. + $geshi->set_header_type(GESHI_HEADER_PRE_VALID); + // Enable CSS classes. You can use get_stylesheet() to output a stylesheet for your code. Using // CSS classes results in much less output source. - $geshi->enable_classes(); - + $geshi->enable_classes(); + // Enable line numbers. We want fancy line numbers, and we want every 5th line number to be fancy - $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 5); - + $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 5); + // Set the style for the PRE around the code. The line numbers are contained within this box (not // XHTML compliant btw, but if you are liberally minded about these things then you'll appreciate // the reduced source output). - $geshi->set_overall_style('color: #000066; border: 1px solid #d0d0d0; background-color: #f0f0f0;', true); - - // Set the style for line numbers. In order to get style for line numbers working, the
    1. element + $geshi->set_overall_style('font: normal normal 90% monospace; color: #000066; border: 1px solid #d0d0d0; background-color: #f0f0f0;', false); + + // Set the style for line numbers. In order to get style for line numbers working, the
    2. element // is being styled. This means that the code on the line will also be styled, and most of the time // you don't want this. So the set_code_style reverts styles for the line (by using a
      on the line). // So the source output looks like this: @@ -65,85 +74,87 @@ if ( isset($_POST['submit']) ) //
    3. - GeSHi examples - + echo $geshi->get_stylesheet(true); + } + ?> + html { + background-color: #f0f0f0; + } + body { + font-family: Verdana, Arial, sans-serif; + margin: 10px; + border: 2px solid #e0e0e0; + background-color: #fcfcfc; + padding: 5px; + } + h2 { + margin: .1em 0 .2em .5em; + border-bottom: 1px solid #b0b0b0; + color: #b0b0b0; + font-weight: normal; + font-size: 150%; + } + h3 { + margin: .1em 0 .2em .5em; + color: #b0b0b0; + font-weight: normal; + font-size: 120%; + } + #footer { + text-align: center; + font-size: 80%; + color: #a9a9a9; + } + #footer a { + color: #9999ff; + } + textarea { + border: 1px solid #b0b0b0; + font-size: 90%; + color: #333; + margin-left: 20px; + } + select, input { + margin-left: 20px; + } + p { + font-size: 90%; + margin-left: .5em; + } + --> +

      GeSHi Example Script

      @@ -152,18 +163,20 @@ include_path, and that the language files are in a subdirectory of GeSHi's direc

      Enter your source and a language to highlight the source in and submit, or just choose a language to have that language file highlighted in PHP.

      parse_code(); - echo '
      '; + echo $geshi->parse_code(); + echo '
      '; } ?> -
      +

      Source to highlight

      - +

      + +

      Choose a language

      - ' . $lang . "\n"; + if (isset($_POST['language']) && $_POST['language'] == $lang) { + $selected = 'selected="selected"'; + } else { + $selected = ''; + } + echo '\n"; } ?> -
      - + +

      +

      + + +

      - \ No newline at end of file + diff --git a/htdocs/application/libraries/geshi/contrib/langcheck.php b/htdocs/application/libraries/geshi/contrib/langcheck.php new file mode 100644 index 0000000..7ca8229 --- /dev/null +++ b/htdocs/application/libraries/geshi/contrib/langcheck.php @@ -0,0 +1,769 @@ +'; + $colors = array( + TYPE_NOTICE => '', + TYPE_WARNING => '', + TYPE_ERROR => '', + TYPE_OK => '' + ); + } else { + $end = chr(27).'[0m'; + $colors = array( + TYPE_NOTICE => chr(27).'[1m', + TYPE_WARNING => chr(27).'[1;33m', + TYPE_ERROR => chr(27).'[1;31m', + TYPE_OK => chr(27).'[1;32m' + ); + } + } + + if ( !isset($colors[$level]) ) { + trigger_error("no colors for level $level", E_USER_ERROR); + } + + return $colors[$level].$string.$end; +} + +define ('TYPE_NOTICE', 0); +define ('TYPE_WARNING', 1); +define ('TYPE_ERROR', 2); +define ('TYPE_OK', 3); + +$error_abort = false; +$error_cache = array(); +function output_error_cache(){ + global $error_cache, $error_abort; + + if(count($error_cache)) { + echo colorize(TYPE_ERROR, "Failed"); + if ( PHP_SAPI == 'cli' ) { + echo "\n\n"; + } else { + echo "
        \n"; + } + foreach($error_cache as $error_msg) { + if ( PHP_SAPI == 'cli' ) { + echo "\n"; + } else { + echo "
      1. "; + } + switch($error_msg['t']) { + case TYPE_NOTICE: + $msg = 'NOTICE'; + break; + case TYPE_WARNING: + $msg = 'WARNING'; + break; + case TYPE_ERROR: + $msg = 'ERROR'; + break; + } + echo colorize($error_msg['t'], $msg); + if ( PHP_SAPI == 'cli' ) { + echo "\t" . $error_msg['m']; + } else { + echo " " . $error_msg['m'] . "
      2. "; + } + } + if ( PHP_SAPI == 'cli' ) { + echo "\n"; + } else { + echo "
      \n"; + } + } else { + echo colorize(TYPE_OK, "OK"); + if ( PHP_SAPI == 'cli' ) { + echo "\n"; + } else { + echo "\n
      "; + } + } + echo "\n"; + + $error_cache = array(); +} + +function report_error($type, $message) { + global $error_cache, $error_abort; + + $error_cache[] = array('t' => $type, 'm' => $message); + if(TYPE_ERROR == $type) { + $error_abort = true; + } +} + +function dupfind_strtolower(&$value){ + $value = strtolower($value); +} + +if ( PHP_SAPI != 'cli' ) { ?> + + + + GeSHi Language File Validation Script + + + +

      GeSHi Language File Validation Script

      +

      To use this script, make sure that geshi.php is in the +parent directory or in your include_path, and that the language files are in a +subdirectory of GeSHi's directory called geshi/.

      +

      Everything else will be done by this script automatically. After the script +finished you should see messages of what could cause trouble with GeSHi or where +your language files can be improved. Please be patient, as this might take some time.

      + +
        +
      1. Checking where to find GeSHi installation ... + + + +To use this script, make sure that is in the +parent directory or in your include_path, and that the language files are in a +subdirectory of GeSHi's directory called . + +Everything else will be done by this script automatically. After the script +finished you should see messages of what could cause trouble with GeSHi or where +your language files can be improved. Please be patient, as this might take some time. + + +Checking where to find GeSHi installation ...\n
      2. Listing available language files ... "; + } + + if (!($dir = @opendir(GESHI_LANG_ROOT))) { + report_error(TYPE_ERROR, 'Error requesting listing for available language files!'); + } + + $languages = array(); + + if(!$error_abort) { + while ($file = readdir($dir)) { + if (!$file || $file[0] == '.' || strpos($file, '.php') === false) { + continue; + } + $lang = substr($file, 0, strpos($file, '.')); + if(4 != strlen($file) - strlen($lang)) { + continue; + } + $languages[] = $lang; + } + closedir($dir); + } + + $languages = array_unique($languages); + sort($languages); + + if(!count($languages)) { + report_error(TYPE_WARNING, 'Unable to locate any usable language files in "'.GESHI_LANG_ROOT.'"!'); + } + + output_error_cache(); +} + +if ( PHP_SAPI == 'cli' ) { + if (isset($_SERVER['argv'][1]) && in_array($_SERVER['argv'][1], $languages)) { + $languages = array($_SERVER['argv'][1]); + } +} else { + if (isset($_REQUEST['show']) && in_array($_REQUEST['show'], $languages)) { + $languages = array($_REQUEST['show']); + } +} + +if(!$error_abort) { + foreach ($languages as $lang) { + + if ( PHP_SAPI == 'cli' ) { + echo "Validating language file for '$lang' ...\t\t"; + } else { + echo "
      3. \n
      4. Validating language file for '$lang' ... "; + } + + $langfile = GESHI_LANG_ROOT . $lang . '.php'; + + $language_data = array(); + + if(!is_file($langfile)) { + report_error(TYPE_ERROR, 'The path "' .$langfile. '" does not ressemble a regular file!'); + } else if(!is_readable($langfile)) { + report_error(TYPE_ERROR, 'Cannot read file "' .$langfile. '"!'); + } else { + $langfile_content = file_get_contents($langfile); + if(preg_match("/\?>(?:\r?\n|\r(?!\n)){2,}\Z/", $langfile_content)) { + report_error(TYPE_ERROR, 'Language file contains trailing empty lines at EOF!'); + } + if(!preg_match("/\?>(?:\r?\n|\r(?!\n))?\Z/", $langfile_content)) { + report_error(TYPE_ERROR, 'Language file contains no PHP end marker at EOF!'); + } + if(preg_match("/\t/", $langfile_content)) { + report_error(TYPE_NOTICE, 'Language file contains unescaped tabulator chars (probably for indentation)!'); + } + if(preg_match('/^(?: )*(?! )(?! \*) /m', $langfile_content)) { + report_error(TYPE_NOTICE, 'Language file contains irregular indentation (other than 4 spaces per indentation level)!'); + } + + if(!preg_match("/\/\*\*((?!\*\/).)*?Author:((?!\*\/).)*?\*\//s", $langfile_content)) { + report_error(TYPE_WARNING, 'Language file does not contain a specification of an author!'); + } + if(!preg_match("/\/\*\*((?!\*\/).)*?Copyright:((?!\*\/).)*?\*\//s", $langfile_content)) { + report_error(TYPE_WARNING, 'Language file does not contain a specification of the copyright!'); + } + if(!preg_match("/\/\*\*((?!\*\/).)*?Release Version:((?!\*\/).)*?\*\//s", $langfile_content)) { + report_error(TYPE_WARNING, 'Language file does not contain a specification of the release version!'); + } + if(!preg_match("/\/\*\*((?!\*\/).)*?Date Started:((?!\*\/).)*?\*\//s", $langfile_content)) { + report_error(TYPE_WARNING, 'Language file does not contain a specification of the date it was started!'); + } + if(!preg_match("/\/\*\*((?!\*\/).)*?This file is part of GeSHi\.((?!\*\/).)*?\*\//s", $langfile_content)) { + report_error(TYPE_WARNING, 'Language file does not state that it belongs to GeSHi!'); + } + if(!preg_match("/\/\*\*((?!\*\/).)*?language file for GeSHi\.((?!\*\/).)*?\*\//s", $langfile_content)) { + report_error(TYPE_WARNING, 'Language file does not state that it is a language file for GeSHi!'); + } + if(!preg_match("/\/\*\*((?!\*\/).)*?GNU General Public License((?!\*\/).)*?\*\//s", $langfile_content)) { + report_error(TYPE_WARNING, 'Language file does not state that it is provided under the terms of the GNU GPL!'); + } + + unset($langfile_content); + + include $langfile; + + if(!isset($language_data)) { + report_error(TYPE_ERROR, 'Language file does not contain a $language_data structure to check!'); + } else if (!is_array($language_data)) { + report_error(TYPE_ERROR, 'Language file contains a $language_data structure which is not an array!'); + } + } + + if(!$error_abort) { + if(!isset($language_data['LANG_NAME'])) { + report_error(TYPE_ERROR, 'Language file contains no $language_data[\'LANG_NAME\'] specification!'); + } else if (!is_string($language_data['LANG_NAME'])) { + report_error(TYPE_ERROR, 'Language file contains a $language_data[\'LANG_NAME\'] specification which is not a string!'); + } + + if(!isset($language_data['COMMENT_SINGLE'])) { + report_error(TYPE_ERROR, 'Language file contains no $language_data[\'COMMENT_SIGNLE\'] structure to check!'); + } else if (!is_array($language_data['COMMENT_SINGLE'])) { + report_error(TYPE_ERROR, 'Language file contains a $language_data[\'COMMENT_SINGLE\'] structure which is not an array!'); + } + + if(!isset($language_data['COMMENT_MULTI'])) { + report_error(TYPE_ERROR, 'Language file contains no $language_data[\'COMMENT_MULTI\'] structure to check!'); + } else if (!is_array($language_data['COMMENT_MULTI'])) { + report_error(TYPE_ERROR, 'Language file contains a $language_data[\'COMMENT_MULTI\'] structure which is not an array!'); + } + + if(isset($language_data['COMMENT_REGEXP'])) { + if (!is_array($language_data['COMMENT_REGEXP'])) { + report_error(TYPE_ERROR, 'Language file contains a $language_data[\'COMMENT_REGEXP\'] structure which is not an array!'); + } + } + + if(!isset($language_data['QUOTEMARKS'])) { + report_error(TYPE_ERROR, 'Language file contains no $language_data[\'QUOTEMARKS\'] structure to check!'); + } else if (!is_array($language_data['QUOTEMARKS'])) { + report_error(TYPE_ERROR, 'Language file contains a $language_data[\'QUOTEMARKS\'] structure which is not an array!'); + } + + if(isset($language_data['HARDQUOTE'])) { + if (!is_array($language_data['HARDQUOTE'])) { + report_error(TYPE_ERROR, 'Language file contains a $language_data[\'HARDQUOTE\'] structure which is not an array!'); + } + } + + if(!isset($language_data['ESCAPE_CHAR'])) { + report_error(TYPE_ERROR, 'Language file contains no $language_data[\'ESCAPE_CHAR\'] specification to check!'); + } else if (!is_string($language_data['ESCAPE_CHAR'])) { + report_error(TYPE_ERROR, 'Language file contains a $language_data[\'ESCAPE_CHAR\'] specification which is not a string!'); + } else if (1 < strlen($language_data['ESCAPE_CHAR'])) { + report_error(TYPE_ERROR, 'Language file contains a $language_data[\'ESCAPE_CHAR\'] specification is not empty or exactly one char!'); + } + + if(!isset($language_data['CASE_KEYWORDS'])) { + report_error(TYPE_ERROR, 'Language file contains no $language_data[\'CASE_KEYWORDS\'] specification!'); + } else if (!is_int($language_data['CASE_KEYWORDS'])) { + report_error(TYPE_ERROR, 'Language file contains a $language_data[\'CASE_KEYWORDS\'] specification which is not an integer!'); + } else if (GESHI_CAPS_NO_CHANGE != $language_data['CASE_KEYWORDS'] && + GESHI_CAPS_LOWER != $language_data['CASE_KEYWORDS'] && + GESHI_CAPS_UPPER != $language_data['CASE_KEYWORDS']) { + report_error(TYPE_ERROR, 'Language file contains a $language_data[\'CASE_KEYWORDS\'] specification which is neither of GESHI_CAPS_NO_CHANGE, GESHI_CAPS_LOWER nor GESHI_CAPS_UPPER!'); + } + + if(!isset($language_data['KEYWORDS'])) { + report_error(TYPE_ERROR, 'Language file contains no $language_data[\'KEYWORDS\'] structure to check!'); + } else if (!is_array($language_data['KEYWORDS'])) { + report_error(TYPE_ERROR, 'Language file contains a $language_data[\'KEYWORDS\'] structure which is not an array!'); + } else { + foreach($language_data['KEYWORDS'] as $kw_key => $kw_value) { + if(!is_integer($kw_key)) { + report_error(TYPE_WARNING, "Language file contains an key '$kw_key' in \$language_data['KEYWORDS'] that is not integer!"); + } else if (!is_array($kw_value)) { + report_error(TYPE_ERROR, "Language file contains a \$language_data['CASE_SENSITIVE']['$kw_value'] structure which is not an array!"); + } + } + } + + if(!isset($language_data['SYMBOLS'])) { + report_error(TYPE_ERROR, 'Language file contains no $language_data[\'SYMBOLS\'] structure to check!'); + } else if (!is_array($language_data['SYMBOLS'])) { + report_error(TYPE_ERROR, 'Language file contains a $language_data[\'SYMBOLS\'] structure which is not an array!'); + } + + if(!isset($language_data['CASE_SENSITIVE'])) { + report_error(TYPE_ERROR, 'Language file contains no $language_data[\'CASE_SENSITIVE\'] structure to check!'); + } else if (!is_array($language_data['CASE_SENSITIVE'])) { + report_error(TYPE_ERROR, 'Language file contains a $language_data[\'CASE_SENSITIVE\'] structure which is not an array!'); + } else { + foreach($language_data['CASE_SENSITIVE'] as $cs_key => $cs_value) { + if(!is_integer($cs_key)) { + report_error(TYPE_WARNING, "Language file contains an key '$cs_key' in \$language_data['CASE_SENSITIVE'] that is not integer!"); + } else if (!is_bool($cs_value)) { + report_error(TYPE_ERROR, "Language file contains a Case Sensitivity specification for \$language_data['CASE_SENSITIVE']['$cs_value'] which is not a boolean!"); + } + } + } + + if(!isset($language_data['URLS'])) { + report_error(TYPE_ERROR, 'Language file contains no $language_data[\'URLS\'] structure to check!'); + } else if (!is_array($language_data['URLS'])) { + report_error(TYPE_ERROR, 'Language file contains a $language_data[\'URLS\'] structure which is not an array!'); + } else { + foreach($language_data['URLS'] as $url_key => $url_value) { + if(!is_integer($url_key)) { + report_error(TYPE_WARNING, "Language file contains an key '$url_key' in \$language_data['URLS'] that is not integer!"); + } else if (!is_string($url_value)) { + report_error(TYPE_ERROR, "Language file contains a Documentation URL specification for \$language_data['URLS']['$url_value'] which is not a string!"); + } else if (preg_match('#&([^;]*(=|$))#U', $url_value)) { + report_error(TYPE_ERROR, "Language file contains unescaped ampersands (&) in \$language_data['URLS']!"); + } + } + } + + if(!isset($language_data['OOLANG'])) { + report_error(TYPE_ERROR, 'Language file contains no $language_data[\'OOLANG\'] specification!'); + } else if (!is_int($language_data['OOLANG']) && !is_bool($language_data['OOLANG'])) { + report_error(TYPE_ERROR, 'Language file contains a $language_data[\'OOLANG\'] specification which is neither boolean nor integer!'); + } else if (false !== $language_data['OOLANG'] && + true !== $language_data['OOLANG'] && + 2 !== $language_data['OOLANG']) { + report_error(TYPE_ERROR, 'Language file contains a $language_data[\'OOLANG\'] specification which is neither of false, true or 2!'); + } + + if(!isset($language_data['OBJECT_SPLITTERS'])) { + report_error(TYPE_ERROR, 'Language file contains no $language_data[\'OBJECT_SPLITTERS\'] structure to check!'); + } else if (!is_array($language_data['OBJECT_SPLITTERS'])) { + report_error(TYPE_ERROR, 'Language file contains a $language_data[\'OBJECT_SPLITTERS\'] structure which is not an array!'); + } + + if(!isset($language_data['REGEXPS'])) { + report_error(TYPE_ERROR, 'Language file contains no $language_data[\'REGEXPS\'] structure to check!'); + } else if (!is_array($language_data['REGEXPS'])) { + report_error(TYPE_ERROR, 'Language file contains a $language_data[\'REGEXPS\'] structure which is not an array!'); + } + + if(!isset($language_data['STRICT_MODE_APPLIES'])) { + report_error(TYPE_ERROR, 'Language file contains no $language_data[\'STRICT_MODE_APPLIES\'] specification!'); + } else if (!is_int($language_data['STRICT_MODE_APPLIES'])) { + report_error(TYPE_ERROR, 'Language file contains a $language_data[\'STRICT_MODE_APPLIES\'] specification which is not an integer!'); + } else if (GESHI_MAYBE != $language_data['STRICT_MODE_APPLIES'] && + GESHI_ALWAYS != $language_data['STRICT_MODE_APPLIES'] && + GESHI_NEVER != $language_data['STRICT_MODE_APPLIES']) { + report_error(TYPE_ERROR, 'Language file contains a $language_data[\'STRICT_MODE_APPLIES\'] specification which is neither of GESHI_MAYBE, GESHI_ALWAYS nor GESHI_NEVER!'); + } + + if(!isset($language_data['SCRIPT_DELIMITERS'])) { + report_error(TYPE_ERROR, 'Language file contains no $language_data[\'SCRIPT_DELIMITERS\'] structure to check!'); + } else if (!is_array($language_data['SCRIPT_DELIMITERS'])) { + report_error(TYPE_ERROR, 'Language file contains a $language_data[\'SCRIPT_DELIMITERS\'] structure which is not an array!'); + } + + if(!isset($language_data['HIGHLIGHT_STRICT_BLOCK'])) { + report_error(TYPE_ERROR, 'Language file contains no $language_data[\'HIGHLIGHT_STRICT_BLOCK\'] structure to check!'); + } else if (!is_array($language_data['HIGHLIGHT_STRICT_BLOCK'])) { + report_error(TYPE_ERROR, 'Language file contains a $language_data[\'HIGHLIGHT_STRICT_BLOCK\'] structure which is not an array!'); + } + + if(isset($language_data['TAB_WIDTH'])) { + if (!is_int($language_data['TAB_WIDTH'])) { + report_error(TYPE_ERROR, 'Language file contains a $language_data[\'TAB_WIDTH\'] specification which is not an integer!'); + } else if (1 > $language_data['TAB_WIDTH']) { + report_error(TYPE_ERROR, 'Language file contains a $language_data[\'TAB_WIDTH\'] specification which is less than 1!'); + } + } + + if(isset($language_data['PARSER_CONTROL'])) { + if (!is_array($language_data['PARSER_CONTROL'])) { + report_error(TYPE_ERROR, 'Language file contains a $language_data[\'PARSER_CONTROL\'] structure which is not an array!'); + } + } + + if(!isset($language_data['STYLES'])) { + report_error(TYPE_ERROR, 'Language file contains no $language_data[\'STYLES\'] structure to check!'); + } else if (!is_array($language_data['STYLES'])) { + report_error(TYPE_ERROR, 'Language file contains a $language_data[\'STYLES\'] structure which is not an array!'); + } else { + $style_arrays = array('KEYWORDS', 'COMMENTS', 'ESCAPE_CHAR', + 'BRACKETS', 'STRINGS', 'NUMBERS', 'METHODS', 'SYMBOLS', + 'REGEXPS', 'SCRIPT'); + foreach($style_arrays as $style_kind) { + if(!isset($language_data['STYLES'][$style_kind])) { + report_error(TYPE_ERROR, "Language file contains no \$language_data['STYLES']['$style_kind'] structure to check!"); + } else if (!is_array($language_data['STYLES'][$style_kind])) { + report_error(TYPE_ERROR, "Language file contains a \$language_data['STYLES\']['$style_kind'] structure which is not an array!"); + } else { + foreach($language_data['STYLES'][$style_kind] as $sk_key => $sk_value) { + if(!is_int($sk_key) && ('COMMENTS' != $style_kind && 'MULTI' != $sk_key) + && !(('STRINGS' == $style_kind || 'ESCAPE_CHAR' == $style_kind) && 'HARD' == $sk_key)) { + report_error(TYPE_WARNING, "Language file contains an key '$sk_key' in \$language_data['STYLES']['$style_kind'] that is not integer!"); + } else if (!is_string($sk_value)) { + report_error(TYPE_WARNING, "Language file contains a CSS specification for \$language_data['STYLES']['$style_kind'][$key] which is not a string!"); + } + } + } + } + + unset($style_arrays); + } + } + + if(!$error_abort) { + //Initial sanity checks survived? --> Let's dig deeper! + foreach($language_data['KEYWORDS'] as $key => $keywords) { + if(!isset($language_data['CASE_SENSITIVE'][$key])) { + report_error(TYPE_ERROR, "Language file contains no \$language_data['CASE_SENSITIVE'] specification for keyword group $key!"); + } + if(!isset($language_data['URLS'][$key])) { + report_error(TYPE_ERROR, "Language file contains no \$language_data['URLS'] specification for keyword group $key!"); + } + if(empty($keywords)) { + report_error(TYPE_WARNING, "Language file contains an empty keyword list in \$language_data['KEYWORDS'] for group $key!"); + } + foreach($keywords as $id => $kw) { + if(!is_string($kw)) { + report_error(TYPE_WARNING, "Language file contains an non-string entry at \$language_data['KEYWORDS'][$key][$id]!"); + } else if (!strlen($kw)) { + report_error(TYPE_ERROR, "Language file contains an empty string entry at \$language_data['KEYWORDS'][$key][$id]!"); + } else if (preg_match('/^([\(\)\{\}\[\]\^=.,:;\-+\*\/%\$\"\'\?]|&[\w#]\w*;)+$/i', $kw)) { + report_error(TYPE_NOTICE, "Language file contains an keyword ('$kw') at \$language_data['KEYWORDS'][$key][$id] which seems to be better suited for the symbols section!"); + } + } + if(isset($language_data['CASE_SENSITIVE'][$key]) && !$language_data['CASE_SENSITIVE'][$key]) { + array_walk($keywords, 'dupfind_strtolower'); + } + if(count($keywords) != count(array_unique($keywords))) { + $kw_diffs = array_count_values($keywords); + foreach($kw_diffs as $kw => $kw_count) { + if($kw_count > 1) { + report_error(TYPE_WARNING, "Language file contains per-group duplicate keyword '$kw' in \$language_data['KEYWORDS'][$key]!"); + } + } + } + } + + $disallowed_before = "(?|^&"; + $disallowed_after = "(?![a-zA-Z0-9_\|%\\-&;"; + + foreach($language_data['KEYWORDS'] as $key => $keywords) { + foreach($language_data['KEYWORDS'] as $key2 => $keywords2) { + if($key2 <= $key) { + continue; + } + $kw_diffs = array_intersect($keywords, $keywords2); + foreach($kw_diffs as $kw) { + if(isset($language_data['PARSER_CONTROL']['KEYWORDS'])) { + //Check the precondition\post-cindition for the involved keyword groups + $g1_pre = $disallowed_before; + $g2_pre = $disallowed_before; + $g1_post = $disallowed_after; + $g2_post = $disallowed_after; + if(isset($language_data['PARSER_CONTROL']['KEYWORDS']['DISALLOWED_BEFORE'])) { + $g1_pre = $language_data['PARSER_CONTROL']['KEYWORDS']['DISALLOWED_BEFORE']; + $g2_pre = $language_data['PARSER_CONTROL']['KEYWORDS']['DISALLOWED_BEFORE']; + } + if(isset($language_data['PARSER_CONTROL']['KEYWORDS']['DISALLOWED_AFTER'])) { + $g1_post = $language_data['PARSER_CONTROL']['KEYWORDS']['DISALLOWED_AFTER']; + $g2_post = $language_data['PARSER_CONTROL']['KEYWORDS']['DISALLOWED_AFTER']; + } + + if(isset($language_data['PARSER_CONTROL']['KEYWORDS'][$key]['DISALLOWED_BEFORE'])) { + $g1_pre = $language_data['PARSER_CONTROL']['KEYWORDS'][$key]['DISALLOWED_BEFORE']; + } + if(isset($language_data['PARSER_CONTROL']['KEYWORDS'][$key]['DISALLOWED_AFTER'])) { + $g1_post = $language_data['PARSER_CONTROL']['KEYWORDS'][$key]['DISALLOWED_AFTER']; + } + + if(isset($language_data['PARSER_CONTROL']['KEYWORDS'][$key2]['DISALLOWED_BEFORE'])) { + $g2_pre = $language_data['PARSER_CONTROL']['KEYWORDS'][$key2]['DISALLOWED_BEFORE']; + } + if(isset($language_data['PARSER_CONTROL']['KEYWORDS'][$key2]['DISALLOWED_AFTER'])) { + $g2_post = $language_data['PARSER_CONTROL']['KEYWORDS'][$key2]['DISALLOWED_AFTER']; + } + + if($g1_pre != $g2_pre || $g1_post != $g2_post) { + continue; + } + } + report_error(TYPE_WARNING, "Language file contains cross-group duplicate keyword '$kw' in \$language_data['KEYWORDS'][$key] and \$language_data['KEYWORDS'][$key2]!"); + } + } + } + foreach($language_data['CASE_SENSITIVE'] as $key => $keywords) { + if(!isset($language_data['KEYWORDS'][$key]) && $key != GESHI_COMMENTS) { + report_error(TYPE_WARNING, "Language file contains an superfluous \$language_data['CASE_SENSITIVE'] specification for non-existing keyword group $key!"); + } + } + foreach($language_data['URLS'] as $key => $keywords) { + if(!isset($language_data['KEYWORDS'][$key])) { + report_error(TYPE_WARNING, "Language file contains an superfluous \$language_data['URLS'] specification for non-existing keyword group $key!"); + } + } + foreach($language_data['STYLES']['KEYWORDS'] as $key => $keywords) { + if(!isset($language_data['KEYWORDS'][$key])) { + report_error(TYPE_WARNING, "Language file contains an superfluous \$language_data['STYLES']['KEYWORDS'] specification for non-existing keyword group $key!"); + } + } + + foreach($language_data['COMMENT_SINGLE'] as $ck => $cv) { + if(!is_int($ck)) { + report_error(TYPE_WARNING, "Language file contains an key '$ck' in \$language_data['COMMENT_SINGLE'] that is not integer!"); + } + if(!is_string($cv)) { + report_error(TYPE_WARNING, "Language file contains an non-string entry at \$language_data['COMMENT_SINGLE'][$ck]!"); + } + if(!isset($language_data['STYLES']['COMMENTS'][$ck])) { + report_error(TYPE_WARNING, "Language file contains no \$language_data['STYLES']['COMMENTS'] specification for comment group $ck!"); + } + } + if(isset($language_data['COMMENT_REGEXP'])) { + foreach($language_data['COMMENT_REGEXP'] as $ck => $cv) { + if(!is_int($ck)) { + report_error(TYPE_WARNING, "Language file contains an key '$ck' in \$language_data['COMMENT_REGEXP'] that is not integer!"); + } + if(!is_string($cv)) { + report_error(TYPE_WARNING, "Language file contains an non-string entry at \$language_data['COMMENT_REGEXP'][$ck]!"); + } + if(!isset($language_data['STYLES']['COMMENTS'][$ck])) { + report_error(TYPE_WARNING, "Language file contains no \$language_data['STYLES']['COMMENTS'] specification for comment group $ck!"); + } + } + } + foreach($language_data['STYLES']['COMMENTS'] as $ck => $cv) { + if($ck != 'MULTI' && !isset($language_data['COMMENT_SINGLE'][$ck]) && + !isset($language_data['COMMENT_REGEXP'][$ck])) { + report_error(TYPE_NOTICE, "Language file contains an superfluous \$language_data['STYLES']['COMMENTS'] specification for Single Line or Regular-Expression Comment key $ck!"); + } + } + if (isset($language_data['STYLES']['STRINGS']['HARD'])) { + if (empty($language_data['HARDQUOTE'])) { + report_error(TYPE_NOTICE, "Language file contains superfluous \$language_data['STYLES']['STRINGS'] specification for key 'HARD', but no 'HARDQUOTE's are defined!"); + } + unset($language_data['STYLES']['STRINGS']['HARD']); + } + foreach($language_data['STYLES']['STRINGS'] as $sk => $sv) { + if($sk && !isset($language_data['QUOTEMARKS'][$sk])) { + report_error(TYPE_NOTICE, "Language file contains an superfluous \$language_data['STYLES']['STRINGS'] specification for non-existing quotemark key $sk!"); + } + } + + foreach($language_data['REGEXPS'] as $rk => $rv) { + if(!is_int($rk)) { + report_error(TYPE_WARNING, "Language file contains an key '$rk' in \$language_data['REGEXPS'] that is not integer!"); + } + if(is_string($rv)) { + //Check for unmasked / in regular expressions ... + if(empty($rv)) { + report_error(TYPE_WARNING, "Language file contains an empty regular expression at \$language_data['REGEXPS'][$rk]!"); + } else { + if(preg_match("/(?)/s", $rv)) { + report_error(TYPE_WARNING, "Language file contains a regular expression with an unescaped match for a pipe character '|' which needs escaping as '<PIPE>' instead at \$language_data['REGEXPS'][$rk]!"); + } + } + } elseif(is_array($rv)) { + if(!isset($rv[GESHI_SEARCH])) { + report_error(TYPE_ERROR, "Language file contains no GESHI_SEARCH entry in extended regular expression at \$language_data['REGEXPS'][$rk]!"); + } elseif(!is_string($rv[GESHI_SEARCH])) { + report_error(TYPE_ERROR, "Language file contains a GESHI_SEARCH entry in extended regular expression at \$language_data['REGEXPS'][$rk] which is not a string!"); + } else { + if(preg_match("/(?)/s", $rv[GESHI_SEARCH])) { + report_error(TYPE_WARNING, "Language file contains a regular expression with an unescaped match for a pipe character '|' which needs escaping as '<PIPE>' instead at \$language_data['REGEXPS'][$rk]!"); + } + } + if(!isset($rv[GESHI_REPLACE])) { + report_error(TYPE_WARNING, "Language file contains no GESHI_REPLACE entry in extended regular expression at \$language_data['REGEXPS'][$rk]!"); + } elseif(!is_string($rv[GESHI_REPLACE])) { + report_error(TYPE_ERROR, "Language file contains a GESHI_REPLACE entry in extended regular expression at \$language_data['REGEXPS'][$rk] which is not a string!"); + } + if(!isset($rv[GESHI_MODIFIERS])) { + report_error(TYPE_WARNING, "Language file contains no GESHI_MODIFIERS entry in extended regular expression at \$language_data['REGEXPS'][$rk]!"); + } elseif(!is_string($rv[GESHI_MODIFIERS])) { + report_error(TYPE_ERROR, "Language file contains a GESHI_MODIFIERS entry in extended regular expression at \$language_data['REGEXPS'][$rk] which is not a string!"); + } + if(!isset($rv[GESHI_BEFORE])) { + report_error(TYPE_WARNING, "Language file contains no GESHI_BEFORE entry in extended regular expression at \$language_data['REGEXPS'][$rk]!"); + } elseif(!is_string($rv[GESHI_BEFORE])) { + report_error(TYPE_ERROR, "Language file contains a GESHI_BEFORE entry in extended regular expression at \$language_data['REGEXPS'][$rk] which is not a string!"); + } + if(!isset($rv[GESHI_AFTER])) { + report_error(TYPE_WARNING, "Language file contains no GESHI_AFTER entry in extended regular expression at \$language_data['REGEXPS'][$rk]!"); + } elseif(!is_string($rv[GESHI_AFTER])) { + report_error(TYPE_ERROR, "Language file contains a GESHI_AFTER entry in extended regular expression at \$language_data['REGEXPS'][$rk] which is not a string!"); + } + } else { + report_error(TYPE_WARNING, "Language file contains an non-string and non-array entry at \$language_data['REGEXPS'][$rk]!"); + } + if(!isset($language_data['STYLES']['REGEXPS'][$rk])) { + report_error(TYPE_WARNING, "Language file contains no \$language_data['STYLES']['REGEXPS'] specification for regexp group $rk!"); + } + } + foreach($language_data['STYLES']['REGEXPS'] as $rk => $rv) { + if(!isset($language_data['REGEXPS'][$rk])) { + report_error(TYPE_NOTICE, "Language file contains an superfluous \$language_data['STYLES']['REGEXPS'] specification for regexp key $rk!"); + } + } + + + } + + output_error_cache(); + + flush(); + + if($error_abort) { + break; + } + } +} + +$time_end = explode(' ', microtime()); +$time_diff = $time_end[0] + $time_end[1] - $time_start[0] - $time_start[1]; + +if ( PHP_SAPI != 'cli' ) { +?>
      5. +
      + +

      Validation process completed in seconds.

      + + + + + + + +Validation process completed in seconds. + +GeSHi © 2004-2007 Nigel McNie, 2007-2008 Benny Baumann, released under the GNU GPL + + \ No newline at end of file diff --git a/htdocs/application/libraries/geshi/contrib/langwiz.php b/htdocs/application/libraries/geshi/contrib/langwiz.php new file mode 100644 index 0000000..6e2b842 --- /dev/null +++ b/htdocs/application/libraries/geshi/contrib/langwiz.php @@ -0,0 +1,1170 @@ +Failed

      "; + echo "
        \n"; + foreach($error_cache as $error_msg) { + echo "
      1. "; + switch($error_msg['t']) { + case TYPE_NOTICE: + echo "NOTICE:"; + break; + case TYPE_WARNING: + echo "WARNING:"; + break; + case TYPE_ERROR: + echo "ERROR:"; + break; + } + echo " " . $error_msg['m'] . "
      2. "; + } + echo "
      \n"; + } else { + echo "OK
      "; + } + echo "\n"; + + $error_cache = array(); +} + +function report_error($type, $message) { + global $error_cache, $error_abort; + + $error_cache[] = array('t' => $type, 'm' => $message); + if(TYPE_ERROR == $type) { + $error_abort = true; + } +} + +function extvar($name, $default){ + if(isset($_POST[$name])) { + return $_POST[$name]; + } + if(isset($_GET[$name])) { + return $_GET[$name]; + } + return $default; +} + +?> + + + + GeSHi Language File Generator Script + + + +

      GeSHi Language File Generator Script

      +

      To use this script, make sure that geshi.php is in the +parent directory or in your include_path, and that the language files are in a +subdirectory of GeSHi's directory called geshi/.

      +

      If not already done, select a language file below that will be used as +base for the language file to generate or create a blank one. Following this +you can do whatever you like to edit your language file. But note that not all +features are made available through this script.

      + +

      Checking GeSHi installation ... 'example', + 'name' => 'Example' + ); + +$ai = array( + 'name' => 'Benny Baumann', + 'email' => 'BenBE@geshi.org', + 'web' => 'http://qbnz.com/highlighter/' + ); + +$ld = array( + 'cmt' => array( + 'sl' => array( + 1 => array( + 'start' => '//', + 'style' => 'font-style: italic; color: #666666;' + ), + 2 => array( + 'start' => '#', + 'style' => 'font-style: italic; color: #666666;' + ) + ), + 'ml' => array( + 1 => array( + 'start' => '/*', + 'end' => '*/', + 'style' => 'font-style: italic; color: #666666;' + ), + 2 => array( + 'start' => '/**', + 'end' => '*/', + 'style' => 'font-style: italic; color: #006600;' + ) + ), + 'rxc' => array( + 1 => array( + 'rx' => '/Hello RegExp/', + 'style' => 'font-style: italic; color: #666666;' + ) + ) + ), + 'str' => array( + 'qm' => array( + 1 => array( + 'delim' => "'", + 'style' => 'color: #0000FF;' + ), + 2 => array( + 'delim' => """, + 'style' => 'color: #0000FF;' + ) + ), + 'ec' => array( + 'char' => '\\', + 'style' => 'font-weight: bold; color: #000080;' + ), + 'erx' => array( + 1 => array( + 'rx' => '/\{\\\\$\w+\}/', + 'style' => 'font-weight: bold; color: #008080;' + ), + 2 => array( + 'rx'=> '/\{\\\\$\w+\}/', + 'style' => 'font-weight: bold; color: #008080;' + ) + ) + ), + 'kw_case' => 'GESHI_CAPS_NO_CHANGE', + 'kw' => array( + 1 => array( + 'list' => '', + 'case' => '0', + 'style' => 'color: #0000FF; font-weight: bold;', + 'docs' => '' + ) + ), + 'sy' => array( + 0 => array( + 'list' => '', + 'style' => 'color: #0000FF; font-weight: bold;' + ) + ) + ); + +$kw_case_sel = array( + 'GESHI_CAPS_NO_CHANGE' => '', + 'GESHI_CAPS_UPPER' => '', + 'GESHI_CAPS_LOWER' => '' + ); + +$kw_cases_sel = array( + 1 => array( + 0 => '', + 1 => '' + ) + ); +// --- empty variables for values of $_POST - end --- + +echo "

      ";
      +//var_dump($languages);
      +var_dump($_GET);
      +var_dump($_POST);
      +
      +foreach($post_var_names as $varName) { // export wanted variables of $_POST array...
      +    if(array_key_exists($varName, $_POST)) {
      +      $$varName = htmlspecialchars_deep($_POST[$varName]);
      +    }
      +}
      +
      +// determine the selected kw_case...
      +$kw_case_sel[$ld['kw_case']] = ' selected="selected"';
      +
      +// determine the selected kw_cases...
      +for($i = 1; $i <= count($kw_cases_sel); $i += 1) {
      +    $kw_cases_sel[$i][(int) $ld['kw'][$i]['case']] = ' selected="selected"';
      +}
      +
      +$lang = validate_lang();
      +var_dump($lang);
      +echo "
      "; + +?> + +
      +
      + Generic Information + + + + + + + + + + + + +
      + + + +
      + + + +
      +
      + +
      + Author + + + + + + + + + + + + + + + + +
      + + + +
      + + + +
      + + + +
      +
      + +
      + Comments + +
      + Single Line + +
      + Comment Group 1 + + + + + + + + + + + +
      + + + +
      + + + +
      +
      + +
      + Comment Group 2 + + + + + + + + + + + +
      + + + +
      + + + +
      +
      +
      + +
      + Multiple Lines + +
      + Comment Group 1 + + + + + + + + + + + + + + + + +
      + + + +
      + + + +
      + + + +
      +
      + +
      + Comment Group 2 + + + + + + + + + + + + + + + + +
      + + + +
      + + + +
      + + + +
      +
      +
      + +
      + Regular Expressions + +
      + Comment Group 1 + + + + + + + + + + + +
      + + + +
      + + + +
      +
      +
      +
      + +
      + Strings + +
      + String \ Quotes (delimiters, parsed) + +
      + Quotemark Group 1 + + + + + + + + + + + +
      + + + +
      + + + +
      +
      +
      + Quotemark Group 2 + + + + + + + + + + + +
      + + + +
      + + + +
      +
      + + +
      + +
      + Escape Sequences + +
      + Generic Escape Char + + + + + + + + + + + +
      + + + +
      + + + +
      +
      + +
      + Escape Regexp Group 1 + + + + + + + + + + + +
      + + + +
      + + + +
      +
      + +
      + Escape Regexp Group 2 + + + + + + + + + + + +
      + + + +
      + + + +
      +
      +
      +
      + +
      + Keywords + +
      + Case of Keywords + + + + + + +
      + + + +
      +
      + +
      + Keyword Group 1 + + + + + + + + + + + + + + + + + + + + + +
      + + + +
      + + + +
      + + + +
      + + + +
      +
      + +
      + + +
      + Symbols + +
      + Symbols Group 1 + + + + + + + + + + + +
      + + + +
      + + + +
      +
      + +
      + + +
      +
      + Language File Source +set_source($langfile_source); +echo $G->parse_code(); +unset($G); +?> +
      +
      + + +
      + +

      Operation completed in seconds.

      + + + + + "\\\"", + "\\" => "\\\\", + "\0" => "\\0", + "\n" => "\\n", + "\r" => "\\r", + "\t" => "\\t", + "\$" => "\\\$" + ) + ) . '"'; + } else { + return "'" . strtr($str, + array( + "'" => "\\'", + "\\" => "\\\\" + ) + ) . "'"; + } +} + +function validate_lang(){ + $ai = array( + 'name' => 'Benny Baumann', + 'email' => 'BenBE@geshi.org', + 'web' => 'http://qbnz.com/highlighter/' + ); + + $li = array( + 'file' => 'example', + 'desc' => 'Example' + ); + + if(isset($_POST['ld'])) { + $ld = $_POST['ld']; + } else { + $ld = array( + 'cmt' => array( + 'sl' => array( + 1 => array( + 'start' => '//', + 'style' => 'test' + ) + ), + 'ml' => array( + 1 => array( + 'start' => '/*', + 'end' => '*/', + 'style' => 'font-style: italic; color: #666666;' + ) + ), + 'rxc' => array( + 1 => array( + 'rx' => '/Hello/', + 'style' => 'color: #00000' + ) + ) + ), + 'str' => array( + 'qm' => array(), + 'ec' => array( + 'char' => '' + ), + 'erx' => array() + ), + 'kw' => array(), + 'kw_case' => 'GESHI_CAPS_NO_CHANGE', + 'sy' => array() + ); + } + + return array('ai' => $ai, 'li' => $li, 'ld' => $ld); +} + +function gen_langfile($lang){ + $langfile = $lang['li']['file']; + $langdesc = $lang['li']['desc']; + + $langauthor_name = $lang['ai']['name']; + $langauthor_email = $lang['ai']['email']; + $langauthor_web = $lang['ai']['web']; + + $langversion = GESHI_VERSION; + + $langdate = date('Y/m/d'); + $langyear = date('Y'); + + $i = ' '; + $i = array('', $i, $i.$i, $i.$i.$i); + + $src = << ".str_to_phpstring($langdesc).",\n"; + + //Comments + $src .= $i[1] . "'COMMENT_SINGLE' => array(\n"; + foreach($lang['ld']['cmt']['sl'] as $idx_cmt_sl => $tmp_cmt_sl) { + $src .= $i[2] . ((int)$idx_cmt_sl). " => ". str_to_phpstring($tmp_cmt_sl['start']) . ",\n"; + } + $src .= $i[2] . "),\n"; + $src .= $i[1] . "'COMMENT_MULTI' => array(\n"; + foreach($lang['ld']['cmt']['ml'] as $tmp_cmt_ml) { + $src .= $i[2] . str_to_phpstring($tmp_cmt_ml['start']). " => ". str_to_phpstring($tmp_cmt_ml['end']) . ",\n"; + } + $src .= $i[2] . "),\n"; + $src .= $i[1] . "'COMMENT_REGEXP' => array(\n"; + foreach($lang['ld']['cmt']['rxc'] as $idx_cmt_rxc => $tmp_cmt_rxc) { + $src .= $i[2] . ((int)$idx_cmt_rxc). " => ". str_to_phpstring($tmp_cmt_rxc['rx']) . ",\n"; + } + $src .= $i[2] . "),\n"; + + //Case Keywords + $src .= $i[1] . "'CASE_KEYWORDS' => " . $lang['ld']['kw_case'] . ",\n"; + + //Quotes \ Strings + $src .= $i[1] . "'QUOTEMARKS' => array(\n"; + foreach($lang['ld']['str']['qm'] as $idx_str_qm => $tmp_str_qm) { + $src .= $i[2] . ((int)$idx_str_qm). " => ". str_to_phpstring($tmp_str_qm['delim']) . ",\n"; + } + $src .= $i[2] . "),\n"; + $src .= $i[1] . "'ESCAPE_CHAR' => " . str_to_phpstring($lang['ld']['str']['ec']['char']) . ",\n"; + $src .= $i[1] . "'ESCAPE_REGEXP' => array(\n"; + foreach($lang['ld']['str']['erx'] as $idx_str_erx => $tmp_str_erx) { + $src .= $i[2] . ((int)$idx_str_erx). " => ". str_to_phpstring($tmp_str_erx['rx']) . ",\n"; + } + $src .= $i[2] . "),\n"; + + //HardQuotes + $src .= $i[1] . "'HARDQUOTE' => array(\n"; + $src .= $i[2] . "),\n"; + $src .= $i[1] . "'HARDESCAPE' => array(\n"; + $src .= $i[2] . "),\n"; + $src .= $i[1] . "'HARDCHAR' => '',\n"; + + //Numbers + $src .= $i[1] . "'NUMBERS' =>\n"; + $src .= $i[2] . "GESHI_NUMBER_INT_BASIC | GESHI_NUMBER_OCT_PREFIX | GESHI_NUMBER_HEX_PREFIX |\n"; + $src .= $i[2] . "GESHI_NUMBER_FLT_SCI_ZERO,\n"; + + //Keywords + $src .= $i[1] . "'KEYWRODS' => array(\n"; + foreach($lang['ld']['kw'] as $idx_kw => $tmp_kw) { + $src .= $i[2] . ((int)$idx_kw) . " => array(\n"; + if(!is_array($tmp_kw['list'])) { + $tmp_kw['list'] = explode("\n", $tmp_kw['list']); + } + $tmp_kw['list'] = array_map('trim', $tmp_kw['list']); + sort($tmp_kw['list']); + $kw_esc = array_map('str_to_phpstring', $tmp_kw['list']); + $kw_nl = true; + $kw_pos = 0; + foreach($kw_esc as $kw_data) { + if((strlen($kw_data) + $kw_pos > 79) && $kw_pos > strlen($i[3])) { + $src .= "\n"; + $kw_nl = true; + $kw_pos = 0; + } + if($kw_nl) { + $src .= $i[3]; + $kw_pos += strlen($i[3]); + $kw_nl = false; + } + $src .= $kw_data . ', '; + $kw_pos += strlen($kw_data) + 2; + } + $src .= "\n"; + $src .= $i[3] . "),\n"; + } + $src .= $i[2] . "),\n"; + + //Case Sensitivity + $src .= $i[1] . "'CASE_SENSITIVE' => array(\n"; + foreach($lang['ld']['kw'] as $idx_kw => $tmp_kw) { + $src .= $i[2] . ((int)$idx_kw) . " => " . ($tmp_kw['case'] ? 'true' : 'false') . ",\n"; + } + $src .= $i[2] . "),\n"; + + //Symbols + $src .= $i[1] . "'SYMBOLS' => array(\n"; + foreach($lang['ld']['sy'] as $idx_kw => $tmp_kw) { + $src .= $i[2] . ((int)$idx_kw) . " => array(\n"; + $tmp_kw['list'] = (array)$tmp_kw['list']; + sort($tmp_kw['list']); + $kw_esc = array_map('str_to_phpstring', $tmp_kw['list']); + $kw_nl = true; + $kw_pos = strlen($i[3]); + foreach($kw_esc as $kw_data) { + if((strlen($kw_data) + $kw_pos > 79) && $kw_pos > strlen($i[3])) { + $src .= "\n"; + $kw_nl = true; + $kw_pos = 0; + } + if($kw_nl) { + $src .= $i[3]; + $kw_pos += strlen($i[3]); + $kw_nl = false; + } + $src .= $kw_data . ', '; + $kw_pos += strlen($kw_data) + 2; + } + $src .= "\n"; + $src .= $i[3] . "),\n"; + } + $src .= $i[2] . "),\n"; + + //Styles \ CSS + $src .= $i[1] . "'STYLES' => array(\n"; + $src .= $i[2] . "'KEYWRODS' => array(\n"; + foreach($lang['ld']['kw'] as $idx_kw => $tmp_kw) { + $src .= $i[3] . ((int)$idx_kw) . " => " . str_to_phpstring($tmp_kw['style']) . ",\n"; + } + $src .= $i[3] . "),\n"; + $src .= $i[2] . "'COMMENTS' => array(\n"; + foreach($lang['ld']['cmt']['sl'] as $idx_cmt_sl => $tmp_cmt_sl) { + $src .= $i[3] . ((int)$idx_cmt_sl) . " => " . str_to_phpstring($tmp_cmt_sl['style']) . ",\n"; + } + foreach($lang['ld']['cmt']['rxc'] as $idx_cmt_rxc => $tmp_cmt_rxc) { + $src .= $i[3] . ((int)$idx_cmt_rxc) . " => " . str_to_phpstring($tmp_cmt_rxc['style']) . ",\n"; + } + $src .= $i[3] . "'MULTI' => " . str_to_phpstring($lang['ld']['cmt']['ml'][1]['style']) . "\n"; + $src .= $i[3] . "),\n"; + $src .= $i[2] . "'ESCAPE_CHAR' => array(\n"; + foreach($lang['ld']['str']['erx'] as $idx_str_erx => $tmp_str_erx) { + $src .= $i[3] . ((int)$idx_str_erx). " => ". str_to_phpstring($tmp_str_erx['style']) . ",\n"; + } + // 'HARD' => 'color: #000099; font-weight: bold;' + $src .= $i[3] . "),\n"; + $src .= $i[2] . "'BRACKETS' => array(\n"; + $src .= $i[3] . "),\n"; + $src .= $i[2] . "'STRINGS' => array(\n"; + foreach($lang['ld']['str']['qm'] as $idx_str_qm => $tmp_str_qm) { + $src .= $i[3] . ((int)$idx_str_qm). " => ". str_to_phpstring($tmp_str_qm['style']) . ",\n"; + } + // 'HARD' => 'color: #0000ff;' + $src .= $i[3] . "),\n"; + $src .= $i[2] . "'NUMBERS' => array(\n"; + $src .= $i[3] . "),\n"; + $src .= $i[2] . "'METHODS' => array(\n"; + $src .= $i[3] . "),\n"; + $src .= $i[2] . "'SYMBOLS' => array(\n"; + foreach($lang['ld']['sy'] as $idx_kw => $tmp_kw) { + $src .= $i[3] . ((int)$idx_kw) . " => " . str_to_phpstring($tmp_kw['style']) . ",\n"; + } + $src .= $i[3] . "),\n"; + $src .= $i[2] . "'REGEXPS' => array(\n"; + $src .= $i[3] . "),\n"; + $src .= $i[2] . "'SCRIPT' => array(\n"; + $src .= $i[3] . "),\n"; + $src .= $i[2] . "),\n"; + + //Keyword Documentation + $src .= $i[1] . "'URLS' => array(\n"; + foreach($lang['ld']['kw'] as $idx_kw => $tmp_kw) { + $src .= $i[2] . ((int)$idx_kw) . " => " . str_to_phpstring($tmp_kw['docs']) . ",\n"; + } + $src .= $i[2] . "),\n"; + $src .= $i[1] . "'OOLANG' => false,\n"; + $src .= $i[1] . "'OBJECT_SPLITTERS' => array(\n"; + $src .= $i[2] . "),\n"; + $src .= $i[1] . "'REGEXPS' => array(\n"; + $src .= $i[2] . "),\n"; + $src .= $i[1] . "'STRICT_MODE_APPLIES' => GESHI_MAYBE,\n"; + $src .= $i[1] . "'SCRIPT_DELIMITERS' => array(\n"; + $src .= $i[2] . "),\n"; + $src .= $i[1] . "'HIGHLIGHT_STRICT_BLOCK' => array(\n"; + $src .= $i[2] . "),\n"; + $src .= $i[1] . "'TAB_WIDTH' => 4,\n"; + + $src .= << +GESHI_LANGFILE_FOOTER; + + //Reduce source ... + $src = preg_replace('/array\(\s*\)/s', 'array()', $src); + $src = preg_replace('/\,(\s*\))/s', '\1', $src); + $src = preg_replace('/\s+$/m', '', $src); + + return $src; +} + +// vim: shiftwidth=4 softtabstop=4 +?> diff --git a/htdocs/application/libraries/geshi/docs/.cvsignore b/htdocs/application/libraries/geshi/docs/.cvsignore deleted file mode 100755 index eedd89b..0000000 --- a/htdocs/application/libraries/geshi/docs/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -api diff --git a/htdocs/application/libraries/geshi/docs/BUGS b/htdocs/application/libraries/geshi/docs/BUGS deleted file mode 100755 index 78eff68..0000000 --- a/htdocs/application/libraries/geshi/docs/BUGS +++ /dev/null @@ -1,31 +0,0 @@ - - BUGS - list of known bugs in GeSHi - Version 1.0.7.20 - -- Putting a > inside an HTML comment will close the comment abruptly. There's nothing that - can be done about this (at least in the 1.0.X series of GeSHi), but version 1.2 will fix - this bug. Likewise for putting ?> inside a PHP string when in strict mode. -- Number highlighting is quite poor [possibly better now] -- I'm not happy with URLS - there still could be extra bugs, and it's rather unflexible - (see TODO for a possible fix) -- "Important" sections for some reason seem to have their spans added after every - newline up until the next lexic, instead of stopping at the part. In fact, - context sensitiveness is quite poor... -- Using the extra line number highlighting feature without actually using line numbers - will result in malformed XHTML (not sure about this one though...) -- Slow!!! Especially for source with lots of strings in it. GeSHi will work acceptably - for sourcecode under 5K (for simple language files like SQL, a 100K file can be - highlighted in just 6 seconds), but above about 25K things get a little slow... If - you're using this as part of some larger software, you may want to think about - making some sort of "cache" effect to speed things up and reduce server load. -- The result is built by string replacement instead of by building another string based - on the source, that would be much safer. The focus of releases beyond 1.0.7 will be on - changing this behaviour, which may well fix some of the other bugs mentioned above. -- As of 1.0.7.1, dots (.) are allowed before keywords. This may change highlighting of some - things slightly, if you notice anything odd about the highlighting then please report - it to me. -- Perl/Javascript /.../ regex syntax isn't supported. -- The
       header output is not XHTML compliant. Please use the 
      header instead. - -Send any bug reports to nigel@geshi.org, or submit them via the bug tracker at -sourceforge (http://sourceforge.net/tracker/?group_id=114997&atid=670231) diff --git a/htdocs/application/libraries/geshi/docs/CHANGES b/htdocs/application/libraries/geshi/docs/CHANGES deleted file mode 100755 index 38974e9..0000000 --- a/htdocs/application/libraries/geshi/docs/CHANGES +++ /dev/null @@ -1,370 +0,0 @@ - - CHANGES - Changelog for GeSHi (geshi.php only) - -Changes to the code are listed under the version they occured in, with who suggested -it by each one (if there's nobody listed as suggesting it I dreamed it up :)). Users -who suggested an idea often also provided the code that was used as a basis for the -changes - thanks to all who suggested these ideas and gave me the code to show me how! - -Language files listed under each version were made by the author beside them, and then -modified by me for consistency/bug fixing. - -Please send any bug reports to nigel@geshi.org, or use the bug report tracker -at sourceforge (http://sourceforge.net/tracker/?group_id=114997&atid=670231) - -Version 1.0.7.20 - - Added language files - * Genero (logic) and Per (forms) (FOURJ's Genero 4GL) (Lars Gersmann) - * Haskell (Dagit) - * ABAP (Andres Picazo) - * Motorola 68k Assembler (for MC68HC908GP32 Microcontroller) (BenBE) - * Dot (Adrien Friggeri) - - Fixed java documentation search for keywords to actually go to the - documentation (spaze) - - Applied fix for bug 1688864 (bad regexes) (Tim Starling) - - Fixed comment CSS rule in visualfoxpro - - ThinBASIC language update (Eros Olmi) - - mIRC language update (BenBE) - - Fixed outdated documentation URL of Perl language file (RuralMoon by BenBE) - - Fixed tab replacement code not generating the correct number of spaces in - some cases (Guillermo Calvo) - - Fixed two typos in Z80 language file - - Applied fix for bug 1730168 (Daniel Naber) - - Applied fix for bug 1705482 (Jason Frame) - * Configurable line endings (Replace \n by custom string) - * per-language tab-widths (Adjustable for width>=1) - * Included defaults for ASM (x86, m68k, z80), C, C (Mac), C++, C++ (QT), C#, - Delphi, CSS,, HTML, PHP, PHP (Brief), QBasic, Ruby, XML - - Added a possibility to force generation of a surrounding tag around - the highlighted source - - Applied fix for additional keywords for the bash language - (cf. http://bash.thefreebizhost.com/bash_geshi.php, BenBE / Jan G) - - Fix bad colour definition in GML language (Andreas Gohr) - - Fixed phpdoc comments not being indented one space if they should be (Andy - Hassall) -Version 1.0.7.19 - - Added language files - * X++ (Simon Butcher) - * Rails (Moises Deniz) - - Fixed invalid HTML being generated and doctypes not being highlighted over - multiple lines properly when line numbers are on (Validome) - - Improved the ruby syntax highlighting by basing it off the Rails file - - Changed some regular expressions to possibly help with badly performing - regex support in PHP (Tim Starling) - - Allow {TIME}, {LANGUAGE} and {VERSION} to be used in the header as well as - the normal
      - \ No newline at end of file diff --git a/htdocs/application/libraries/geshi/docs/api/index.html b/htdocs/application/libraries/geshi/docs/api/index.html deleted file mode 100755 index 1397afc..0000000 --- a/htdocs/application/libraries/geshi/docs/api/index.html +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - GeSHi - - - - - - - - - - - <H2>Frame Alert</H2> - <P>This document is designed to be viewed using the frames feature. - If you see this message, you are using a non-frame-capable web client.</P> - - - \ No newline at end of file diff --git a/htdocs/application/libraries/geshi/docs/api/li_geshi.html b/htdocs/application/libraries/geshi/docs/api/li_geshi.html deleted file mode 100755 index 198a8b6..0000000 --- a/htdocs/application/libraries/geshi/docs/api/li_geshi.html +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - - - - - -
      geshi
      -
      - -
      - -
      Description
      -
      - Class trees
      - Index of elements
      - Todo List
      -
      - - - - - - - -
      Sub-packagecore
      -
      -
      -
       Classes
      -
      ClassGeSHi
      -
       Functions
      -
      Functiongeshi_highlight
      -
       Files
      -
      Filegeshi.php
      -
      -
      - - -
      -
      -

      phpDocumentor v 1.3.0

      - - \ No newline at end of file diff --git a/htdocs/application/libraries/geshi/docs/api/media/banner.css b/htdocs/application/libraries/geshi/docs/api/media/banner.css deleted file mode 100755 index 032b037..0000000 --- a/htdocs/application/libraries/geshi/docs/api/media/banner.css +++ /dev/null @@ -1,33 +0,0 @@ -body -{ - background-color: #EEEEEE; - margin: 0px; - padding: 0px; -} - -/* Banner (top bar) classes */ - -.banner { } - -.banner-menu -{ - text-align: right; - clear: both; - padding: .5em; - border-top: 2px solid #AAAAAA; -} - -.banner-title -{ - text-align: right; - font-size: 20pt; - font-weight: bold; - margin: .2em; -} - -.package-selector -{ - background-color: #DDDDDD; - border: 1px solid #AAAAAA; - color: #000090; -} diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/AbstractClass.png b/htdocs/application/libraries/geshi/docs/api/media/images/AbstractClass.png deleted file mode 100755 index afa9d1d..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/AbstractClass.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/AbstractClass_logo.png b/htdocs/application/libraries/geshi/docs/api/media/images/AbstractClass_logo.png deleted file mode 100755 index 8f65c39..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/AbstractClass_logo.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/AbstractMethod.png b/htdocs/application/libraries/geshi/docs/api/media/images/AbstractMethod.png deleted file mode 100755 index 605ccbe..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/AbstractMethod.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/AbstractPrivateClass.png b/htdocs/application/libraries/geshi/docs/api/media/images/AbstractPrivateClass.png deleted file mode 100755 index 53d76c6..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/AbstractPrivateClass.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/AbstractPrivateClass_logo.png b/htdocs/application/libraries/geshi/docs/api/media/images/AbstractPrivateClass_logo.png deleted file mode 100755 index 4e68f57..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/AbstractPrivateClass_logo.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/AbstractPrivateMethod.png b/htdocs/application/libraries/geshi/docs/api/media/images/AbstractPrivateMethod.png deleted file mode 100755 index 41cc9f0..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/AbstractPrivateMethod.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/Class.png b/htdocs/application/libraries/geshi/docs/api/media/images/Class.png deleted file mode 100755 index cf548d2..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/Class.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/Class_logo.png b/htdocs/application/libraries/geshi/docs/api/media/images/Class_logo.png deleted file mode 100755 index 6f223c4..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/Class_logo.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/Constant.png b/htdocs/application/libraries/geshi/docs/api/media/images/Constant.png deleted file mode 100755 index a9c6f28..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/Constant.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/Constructor.png b/htdocs/application/libraries/geshi/docs/api/media/images/Constructor.png deleted file mode 100755 index 3f16222..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/Constructor.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/Destructor.png b/htdocs/application/libraries/geshi/docs/api/media/images/Destructor.png deleted file mode 100755 index f28528f..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/Destructor.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/Function.png b/htdocs/application/libraries/geshi/docs/api/media/images/Function.png deleted file mode 100755 index 902fe25..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/Function.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/Global.png b/htdocs/application/libraries/geshi/docs/api/media/images/Global.png deleted file mode 100755 index 7281bd2..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/Global.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/I.png b/htdocs/application/libraries/geshi/docs/api/media/images/I.png deleted file mode 100755 index e8512fb..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/I.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/Index.png b/htdocs/application/libraries/geshi/docs/api/media/images/Index.png deleted file mode 100755 index 6558ec3..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/Index.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/Interface.png b/htdocs/application/libraries/geshi/docs/api/media/images/Interface.png deleted file mode 100755 index e6cd51e..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/Interface.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/Interface_logo.png b/htdocs/application/libraries/geshi/docs/api/media/images/Interface_logo.png deleted file mode 100755 index 6f223c4..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/Interface_logo.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/L.png b/htdocs/application/libraries/geshi/docs/api/media/images/L.png deleted file mode 100755 index eb334ed..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/L.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/Lminus.png b/htdocs/application/libraries/geshi/docs/api/media/images/Lminus.png deleted file mode 100755 index f7c43c0..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/Lminus.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/Lplus.png b/htdocs/application/libraries/geshi/docs/api/media/images/Lplus.png deleted file mode 100755 index 848ec2f..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/Lplus.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/Method.png b/htdocs/application/libraries/geshi/docs/api/media/images/Method.png deleted file mode 100755 index 9b21578..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/Method.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/Page.png b/htdocs/application/libraries/geshi/docs/api/media/images/Page.png deleted file mode 100755 index ffe7986..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/Page.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/Page_logo.png b/htdocs/application/libraries/geshi/docs/api/media/images/Page_logo.png deleted file mode 100755 index 44ce0b3..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/Page_logo.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/PrivateClass.png b/htdocs/application/libraries/geshi/docs/api/media/images/PrivateClass.png deleted file mode 100755 index 470e6d5..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/PrivateClass.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/PrivateClass_logo.png b/htdocs/application/libraries/geshi/docs/api/media/images/PrivateClass_logo.png deleted file mode 100755 index 590e006..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/PrivateClass_logo.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/PrivateMethod.png b/htdocs/application/libraries/geshi/docs/api/media/images/PrivateMethod.png deleted file mode 100755 index d01f2b3..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/PrivateMethod.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/PrivateVariable.png b/htdocs/application/libraries/geshi/docs/api/media/images/PrivateVariable.png deleted file mode 100755 index d76b21d..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/PrivateVariable.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/StaticMethod.png b/htdocs/application/libraries/geshi/docs/api/media/images/StaticMethod.png deleted file mode 100755 index 9b21578..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/StaticMethod.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/StaticVariable.png b/htdocs/application/libraries/geshi/docs/api/media/images/StaticVariable.png deleted file mode 100755 index 8e82019..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/StaticVariable.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/T.png b/htdocs/application/libraries/geshi/docs/api/media/images/T.png deleted file mode 100755 index 3017325..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/T.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/Tminus.png b/htdocs/application/libraries/geshi/docs/api/media/images/Tminus.png deleted file mode 100755 index 2260e42..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/Tminus.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/Tplus.png b/htdocs/application/libraries/geshi/docs/api/media/images/Tplus.png deleted file mode 100755 index 2c8d8f4..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/Tplus.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/Variable.png b/htdocs/application/libraries/geshi/docs/api/media/images/Variable.png deleted file mode 100755 index 8e82019..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/Variable.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/blank.png b/htdocs/application/libraries/geshi/docs/api/media/images/blank.png deleted file mode 100755 index cee9cd3..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/blank.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/class_folder.png b/htdocs/application/libraries/geshi/docs/api/media/images/class_folder.png deleted file mode 100755 index 84e9587..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/class_folder.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/empty.png b/htdocs/application/libraries/geshi/docs/api/media/images/empty.png deleted file mode 100755 index d568386..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/empty.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/file.png b/htdocs/application/libraries/geshi/docs/api/media/images/file.png deleted file mode 100755 index 0bb2427..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/file.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/folder.png b/htdocs/application/libraries/geshi/docs/api/media/images/folder.png deleted file mode 100755 index a2d79f8..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/folder.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/function_folder.png b/htdocs/application/libraries/geshi/docs/api/media/images/function_folder.png deleted file mode 100755 index 8b3d6e3..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/function_folder.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/next_button.png b/htdocs/application/libraries/geshi/docs/api/media/images/next_button.png deleted file mode 100755 index cdbc615..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/next_button.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/next_button_disabled.png b/htdocs/application/libraries/geshi/docs/api/media/images/next_button_disabled.png deleted file mode 100755 index 4a11780..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/next_button_disabled.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/package.png b/htdocs/application/libraries/geshi/docs/api/media/images/package.png deleted file mode 100755 index b04cf56..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/package.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/package_folder.png b/htdocs/application/libraries/geshi/docs/api/media/images/package_folder.png deleted file mode 100755 index 6162baf..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/package_folder.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/previous_button.png b/htdocs/application/libraries/geshi/docs/api/media/images/previous_button.png deleted file mode 100755 index 327fdbc..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/previous_button.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/previous_button_disabled.png b/htdocs/application/libraries/geshi/docs/api/media/images/previous_button_disabled.png deleted file mode 100755 index c02ff64..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/previous_button_disabled.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/private_class_logo.png b/htdocs/application/libraries/geshi/docs/api/media/images/private_class_logo.png deleted file mode 100755 index 590e006..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/private_class_logo.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/tutorial.png b/htdocs/application/libraries/geshi/docs/api/media/images/tutorial.png deleted file mode 100755 index bc19737..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/tutorial.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/tutorial_folder.png b/htdocs/application/libraries/geshi/docs/api/media/images/tutorial_folder.png deleted file mode 100755 index 2a468b2..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/tutorial_folder.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/images/up_button.png b/htdocs/application/libraries/geshi/docs/api/media/images/up_button.png deleted file mode 100755 index ff36c59..0000000 Binary files a/htdocs/application/libraries/geshi/docs/api/media/images/up_button.png and /dev/null differ diff --git a/htdocs/application/libraries/geshi/docs/api/media/stylesheet.css b/htdocs/application/libraries/geshi/docs/api/media/stylesheet.css deleted file mode 100755 index 167c430..0000000 --- a/htdocs/application/libraries/geshi/docs/api/media/stylesheet.css +++ /dev/null @@ -1,146 +0,0 @@ -a { color: #000090; text-decoration: none; } -a:hover, a:active, a:focus { color: highlighttext; background-color: highlight; text-decoration: none; } - -body { background: #FFFFFF; } -body, table { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt; } - -a img { border: 0px; } - -/* Page layout/boxes */ - -.info-box { } -.info-box-title { margin: 1em 0em 0em 0em; font-weight: normal; font-size: 14pt; color: #999999; border-bottom: 2px solid #999999; } -.info-box-body { border: 1px solid #999999; padding: .5em; } -.nav-bar { font-size: 8pt; white-space: nowrap; text-align: right; padding: .2em; margin: 0em 0em 1em 0em; } - -.oddrow { background-color: #F8F8F8; border: 1px solid #AAAAAA; padding: .5em; margin-bottom: 1em} -.evenrow { border: 1px solid #AAAAAA; padding: .5em; margin-bottom: 1em} - -.page-body { max-width: 800px; margin: auto; } -.tree { white-space: nowrap; font: icon } -.tree dd { margin-left: 19px } -.tree dl { margin: 0px } -.tree-icon { vertical-align: middle; border: 0px; margin-right: 3px } - -/* Index formatting classes */ - -.index-item-body { margin-top: .5em; margin-bottom: .5em} -.index-item-description { margin-top: .25em } -.index-item-details { font-weight: normal; font-style: italic; font-size: 8pt } -.index-letter-section { background-color: #EEEEEE; border: 1px dotted #999999; padding: .5em; margin-bottom: 1em} -.index-letter-title { font-size: 12pt; font-weight: bold } -.index-letter-menu { text-align: center; margin: 1em } -.index-letter { font-size: 12pt } - -/* Docbook classes */ - -.description {} -.short-description { font-weight: bold; color: #666666; } -.tags { padding-left: 0em; margin-left: 3em; color: #666666; list-style-type: square; } -.parameters { padding-left: 0em; margin-left: 3em; color: #014fbe; list-style-type: square; } -.redefinitions { font-size: 8pt; padding-left: 0em; margin-left: 2em; } -.package { font-weight: bold; } -.package-title { font-weight: bold; font-size: 14pt; border-bottom: 1px solid black } -.package-details { font-size: 85%; } -.sub-package { font-weight: bold; } -.tutorial { border-width: thin; border-color: #0066ff; } -.tutorial-nav-box { width: 100%; border: 1px solid #999999; background-color: #F8F8F8; } -.folder-title { font-style: italic; font-family: Verdana, Arial, Helvetica, sans-serif } - -/* Generic formatting */ - -.field { font-weight: bold; } -.detail { font-size: 8pt; } -.notes { font-style: italic; font-size: 8pt; } -.separator { background-color: #999999; height: 2px; } -.warning { color: #FF6600; } -.disabled { font-style: italic; color: #999999; } - -/* Code elements */ - -.line-number { } - -.class-table { width: 100%; } -.class-table-header { border-bottom: 1px dotted #666666; text-align: left} -.class-name { color: #0000AA; font-weight: bold; } - -.method-summary { color: #009000; padding-left: 1em; font-size: 8pt; } -.method-header { } -.method-definition { margin-bottom: .2em } -.method-title { color: #009000; font-weight: bold; } -.method-name { font-weight: bold; } -.method-signature { font-size: 85%; color: #666666; margin: .5em 0em } -.method-result { font-style: italic; } - -.var-summary { padding-left: 1em; font-size: 8pt; } -.var-header { } -.var-title { color: #014fbe; margin-bottom: .3em } -.var-type { font-style: italic; } -.var-name { font-weight: bold; } -.var-default {} -.var-description { font-weight: normal; color: #000000; } - -.include-title { color: #014fbe;} -.include-type { font-style: italic; } -.include-name { font-weight: bold; } - -.const-title { color: #FF6600; } -.const-name { font-weight: bold; } - -/* Syntax highlighting */ - -.src-code { font-family: 'Courier New', Courier, monospace; font-weight: normal; } -.src-line { font-family: 'Courier New', Courier, monospace; font-weight: normal; } - -.src-code a:link { padding: 1px; text-decoration: underline; color: #0000DD; } -.src-code a:visited { text-decoration: underline; color: #0000DD; } -.src-code a:active { background-color: #FFFF66; color: #008000; } -.src-code a:hover { background-color: #FFFF66; text-decoration: overline underline; color: #008000; } - -.src-comm { color: #666666; } -.src-id { color: #FF6600; font-style: italic; } -.src-inc { color: #0000AA; font-weight: bold; } -.src-key { color: #0000AA; font-weight: bold; } -.src-num { color: #CC0000; } -.src-str { color: #CC0000; } -.src-sym { } -.src-var { } - -.src-php { font-weight: bold; } - -.src-doc { color: #666666; } -.src-doc-close-template { color: #666666 } -.src-doc-coretag { color: #008000; } -.src-doc-inlinetag {} -.src-doc-internal {} -.src-doc-tag { color: #0080CC; } -.src-doc-template { color: #666666 } -.src-doc-type { font-style: italic; color: #444444 } -.src-doc-var { color: #444444 } - -.tute-tag { color: #009999 } -.tute-attribute-name { color: #0000FF } -.tute-attribute-value { color: #0099FF } -.tute-entity { font-weight: bold; } -.tute-comment { font-style: italic } -.tute-inline-tag { color: #636311; font-weight: bold } - -/* tutorial */ - -.authors { } -.author { font-style: italic; font-weight: bold } -.author-blurb { margin: .5em 0em .5em 2em; font-size: 85%; font-weight: normal; font-style: normal } -.example { border: 1px dashed #999999; background-color: #EEEEEE; padding: .5em; } -*[class="example"] { line-height : 0.5em; } -.listing { border: 1px dashed #999999; background-color: #EEEEEE; padding: .5em; white-space: nowrap; } -*[class="listing"] { line-height : 0.5em; } -.release-info { font-size: 85%; font-style: italic; margin: 1em 0em } -.ref-title-box { } -.ref-title { } -.ref-purpose { font-style: italic; color: #666666 } -.ref-synopsis { } -.title { font-weight: bold; border-bottom: 1px solid #999999; color: #999999; } -.cmd-synopsis { margin: 1em 0em } -.cmd-title { font-weight: bold } -.toc { margin-left: 2em; padding-left: 0em } - diff --git a/htdocs/application/libraries/geshi/docs/api/packages.html b/htdocs/application/libraries/geshi/docs/api/packages.html deleted file mode 100755 index d8c4c04..0000000 --- a/htdocs/application/libraries/geshi/docs/api/packages.html +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/htdocs/application/libraries/geshi/docs/api/todolist.html b/htdocs/application/libraries/geshi/docs/api/todolist.html deleted file mode 100755 index 2104888..0000000 --- a/htdocs/application/libraries/geshi/docs/api/todolist.html +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - Todo List - - - - -

      Todo List

      -

      geshi

      -

      GeSHi::disable_highlighting()

      -
        -
      • Rewrite with an array traversal
      • -
      -

      GeSHi::enable_highlighting()

      -
        -
      • Rewrite with array traversal
      • -
      -

      GeSHi::enable_important_blocks()

      -
        -
      • REMOVE THIS SHIZ FROM GESHI!
      • -
      -

      GeSHi::get_language_name_from_extension()

      -
        -
      • Re-think about how this method works (maybe make it private and/or make it a extension->lang lookup?)
      • -
      • static?
      • -
      -

      GeSHi::highlight_lines_extra()

      -
        -
      • Some data replication here that could be cut down on
      • -
      -

      GeSHi::load_from_file()

      -
        -
      • Complete rethink of this and above method
      • -
      -

      GeSHi::set_case_keywords()

      -
        -
      • Error check the passed value
      • -
      -

      - Documentation generated on Sun, 25 Feb 2007 21:29:34 +1300 by phpDocumentor 1.3.0 -

      - - \ No newline at end of file diff --git a/htdocs/application/libraries/geshi/docs/geshi-doc.html b/htdocs/application/libraries/geshi/docs/geshi-doc.html deleted file mode 100755 index 236d29f..0000000 --- a/htdocs/application/libraries/geshi/docs/geshi-doc.html +++ /dev/null @@ -1,2570 +0,0 @@ - - - - GeSHi Documentation - - - -

      GeSHi Documentation

      -
      Version 1.0.7.20
      -
      Author:          Nigel McNie
      -Copyright:       © 2004 - 2007 Nigel McNie
      -Email:           nigel@geshi.org
      -GeSHi Website:   http://qbnz.com/highlighter
      - -

      This is the documentation for GeSHi - Generic Syntax Highlighter. -The most modern version of this document is available on the web - -go to http://qbnz.com/highlighter/documentation.php to view it.

      - -

      Any comments, questions, confusing points? Please contact me! I -need all the information I can get to make the use of GeSHi and -everything related to it (including this documentation) a breeze.

      - -

      Contents

      - - - -

      1: Introduction

      - - -

      GeSHi is exactly what the acronym stands for: a Generic Syntax Highlighter. As long -as you have a language file for almost any computer language - whether it be a -scripting language, object orientated, markup or anything in between - GeSHi can -highlight it! GeSHi is extremely customisable - the same source can be highlighted -multiple times in multiple ways - the same source even with a different language. -GeSHi outputs XHTML strict compliant code*, and can -make use of CSS to save on the amount of output. And what is the cost for all of this? You need -PHP. That's all! - -

      *Most of the time. -Some languages do not output XHTML strict code, and using line numbers with the PRE header is not legal either. -These problems will be fixed in 1.2.

      - -

      1.1: Features

      - - -

      Here are some of the standout features of GeSHi:

      - -
        -
      • Programmed in PHP: GeSHi is coded entirely in PHP. This means that where ever you have PHP, you - can have GeSHi! Almost any free webhost supports PHP, and GeSHi works fine with PHP > 4.1.0.
      • -
      • Support for many languages: GeSHi comes with over 50 languages, including PHP, - HTML, CSS, Java, C, Lisp, XML, Perl, Python, ASM and many more!
      • -
      • XHTML compliant output: GeSHi produces XHTML compliant output, using stylesheets, so you need not worry about - GeSHi ruining your claims to perfection in the standards department ;)
      • -
      • Highly customisable: GeSHi allows you to change the style of the output on the fly, use CSS classes or not, use an external - stylesheet or not, use line numbering, change the case of output keywords... the list goes on and on!
      • -
      • Flexible: Unfortunately, GeSHi is quite load/time intensive for large blocks of code. However, you want speed? - Turn off any features you don't like, pre-make a stylesheet and use CSS classes to reduce the amount of output and more - it's easy - to strike a balance that suits you.
      • -
      - -

      This is just a taste of what you get with GeSHi - the best syntax highlighter for the web in the world!

      - -

      1.2: About GeSHi

      - - -

      GeSHi started as a mod for the phpBB forum system, to enable highlighting of more -languages than the available (which was 0 ;)). However, it quickly spawned into an -entire project on its own. But now it has been released, work continues on a mod -for phpBB* - and hopefully for many forum systems, blogs and other web-based systems.

      - -

      *I am no longer working on this MOD, however if someone else wants to they -can contact me for more information.

      - -

      Several systems are using GeSHi now, including:

      - - - -

      * Available as plugin only. In addition, some of the other entries mentioned -here may only have GeSHi available as a plugin.

      - -

      GeSHi is the work of me, Nigel McNie. Others have helped with aspects of GeSHi -also, they're mentioned in the THANKS file.

      - -

      1.3: Credits

      - - -

      Many people have helped out with GeSHi, whether by creating language files, submitting bug -reports, suggesting new ideas or simply pointing out a new idea or something I'd missed. All -of these people have helped to build a better GeSHi, you can see them in the THANKS -file.

      - -

      Do you want your name on this -list? Why not make a language file, or submit a valid bug? Or perhaps help me with an -added feature I can't get my head around, or suggest a new feature, or even port -GeSHi to anothe language? There's lots you can do to help out, and I need it all :)

      - -

      1.4: Feedback

      - - -

      I need your feedback! ANYthing you have to say is fine, whether it be a query, -congratulations, a bug report or complaint, I don't care! I want to make this software -the best it can be, and I need your help! You can contact me in the following ways:

      - - - -

      Remember, any help I am grateful for :)

      - -

      2: The Basics

      - - -

      In this section, you'll learn a bit about GeSHi, how it works and what it uses, how -to install it and how to use it to perform basic highlighting.

      - -

      2.1: Getting GeSHi

      - - -

      If you're reading this and don't have GeSHi, that's a problem ;). So, how do you get -your hands on it? Visit http://qbnz.com/highlighter/downloads.php to obtain the latest -version.

      - -

      2.2: Installing GeSHi

      - - -

      Installing GeSHi is a snap, even for those most new to PHP. There's no tricks involved. Honest!

      - -
      2.2.1: Requirements
      - - -

      GeSHi requires the following to be installable:

      - -
        -
      • PHP. It's untested with anything other than 4.3.X. I hope to extend this range soon. - I see no reason why it won't work with any version of PHP above 4.1.0.
      • -
      • Approximately 700 kilobytes of space. The actual script is small - around 85K - but most - of the size comes from the large number of language files (over 50!). If you're pushed for space, make sure - you don't upload to your server the docs/ or contrib/ directory, and you may want to leave - out any language files that don't take your fancy either.
      • -
      - -

      As you can see, the requirements are very small. If GeSHi does NOT work for you in a -particular version of PHP, let me know why and I'll fix it.

      - -

      Packages come in .zip, .tar.gz and .tar.bz2 format, so there's no complaining about whether -it's available for you. *nix users probably want .tar.gz or .tar.bz2 and windows users -probably want .zip.

      - -
      2.2.2: Extracting GeSHi
      - - -

      To extract GeSHi in Linux (.tar.gz):

      - -
        -
      1. Open a shell
      2. -
      3. cd to the directory where the archive lies
      4. -
      5. Type tar -xzvf [filename] where [filename] is the name of the archive (typically GeSHi-1.X.X.tar.gz)
      6. -
      7. GeSHi will be extracted to its own directory -
      - -

      To extract GeSHi in Windows (.zip):

      - -
        -
      1. Open Explorer
      2. -
      3. Navigate to the directory where the archive lies
      4. -
      5. Extract the archive. The method you use will depend on your configuration. - Some people can right-click upon the archive and select "Extract" from there, - others may have to drag the archive and drop it upon an extraction program.
      6. -
      - -

      To extract from .zip you'll need an unzipping program - unzip in Linux, or Winzip, -Winrar or similar for Windows.

      - -
      2.2.3: Installation
      - - -

      GeSHi is nothing more than a PHP class with related language support files. -Those of you familiar with PHP can then guess how easy the installation will -be: simply copy it into your include path somewhere. You can put it wherever -you like in this include path. I recommend that you put the language files -in a subdirectory of your include path too - perhaps the same subdirectory -that geshi.php is in. Remember this path for later.

      - -

      If you don't know what an include path is, don't worry. Simply copy GeSHi to -your webserver. So for example, say your site is at http://mysite.com/myfolder, -you can copy GeSHi to your site so the directory structure is like this:

      - -
      http://mysite.com/myfolder/geshi/[language files]
      -http://mysite.com/myfolder/geshi.php
      - -

      Or you can put it in any subdirectory you like:

      - -
      http://mysite.com/myfolder/includes/geshi/[language files]
      -http://mysite.com/myfolder/includes/geshi.php
      - -
      Caution:

      When using GeSHi on a live site, the only directory -required is the geshi/ subdirectory. Both contrib/ and docs/ are worthless, and furthermore, -as some people discovered, one of the files in contrib had a security hole (fixed as of 1.0.7.3). I suggest you delete -these directories from any live site they are on.

      - -

      2.3: Basic Usage

      - - -

      Use of GeSHi is very easy. Here's a simple example:

      - -//
      -// Include the GeSHi library
      - -//
      -include_once('geshi.php');
      -
      -//
      -// Define some source to highlight, a language to use
      -// and the path to the language files
      - -//
      -$source = '$foo = 45;
      -for ( $i = 1; $i < $foo; $i++ )
      -{
      - -  echo "$foo<br />\n";
      -  --$foo;
      -}'
      ;
      -$language = 'php';
      - -//
      -// Create a GeSHi object
      -//
      - -$geshi =& new GeSHi($source, $language);
      -
      -//
      - -// And echo the result!
      -//
      -echo $geshi->parse_code(); -
      - -

      As you can see, there's only three really important lines:

      - -include_once('geshi.php'); - -

      This line includes the GeSHi class for use

      - -$geshi = new GeSHi($source, $language); - -

      This line creates a new GeSHi object, holding the source and the language -you want to use for highlighting.

      - -echo $geshi->parse_code(); - -

      This line spits out the result :)

      - -

      So as you can see, simple usage of GeSHi is really easy. Just create a new -GeSHi object and get the code!

      - -

      Since version 1.0.2, there is a function included with GeSHi called geshi_highlight. -This behaves exactly as the php function highlight_string behaves - all you do is pass -it the language you want to use to highlight and the path to the language files as well as the source. -Here are some examples:

      - -// Simply echo the highlighted code
      -geshi_highlight($source, 'php', $path);
      - -
      -// Get the code back, for use later
      -$code = geshi_highlight($source, 'java', $path, true)
      -
      -// Check if there is an error with parsing this code
      - -ob_start();
      -$result = geshi_highlight($source, 'perl', $path);
      -$code = ob_get_contents();
      - -ob_end_clean();
      -if ( !$result )
      -{
      -        // There was an error with highlighting...
      - -}
      -else
      -{
      -        // All OK :)
      -} -
      - -

      However, these are really simple examples and doesn't even begin to cover all -the advanced features of GeSHi. If you want to learn more, continue on to -section 3: Advanced Features.

      - - -

      3: Advanced Features

      - - -

      This section documents the advanced features of GeSHi - strict mode, using -CSS classes, changing styles on the fly, disabling highlighting of some things -and more.

      - -

      In this section there are many code snippets. For all of these, you should assume -that the GeSHi library has been included, and a GeSHi object has been created -and is referenced by the variable $geshi. Normally, the source, language and path -used are arbitary.

      - -

      3.1 The Code Container

      - - -

      The Code Container has a fundamental effect on the layout of your code before you -even begin to style. What is the Code Container? It's the bit of markup that goes -around your code to contain it. By default your code is surrounded by a <pre>, but -you can also specify a <div>.

      - -

      The <pre> header is the default. If you're familiar with HTML you'll know that -whitespace is rendered "as is" by a <pre> element. The advantage for you is that -if you use <pre> the whitespace you use will appear pretty much exactly how it is -in the source, and what's more GeSHi won't have to add a whole lot of <br />'s and -non-breaking spaces (&nbsp;) to your code to indent it. This saves you source code -(and your valuable visitors waiting time and your bandwidth).

      - -

      But if you don't like <pre> or it looks stupid in your browser no matter what styles -you try to apply to it or something similar, you might want to use a <div> instead. -A <div> will result in more source - GeSHi will have to insert whitespace markup - -but in return you can wrap long lines of code that would otherwise have your browser's -horizontal scrollbar appear. Of course with <div> you can *not* wrap lines if you please. -The highlighter demo at the GeSHi home page uses the -<div> approach for this reason.

      - -

      At this stage there isn't an option to wrap the code in <code> tags (unless you use the -function geshi_highlight), partly because of the inconsistent and unexpected ways stuff in <code> -tags is highlighted. Besides, <code> is an inline element. But this may become an option in future versions.

      - -

      As of GeSHi 1.0.7.2 there is a new header type, that specifies that the code should not be wrapped in -anything at all.

      - -

      To change/set the header to use, you call the set_header_type() method:

      - -$geshi->set_header_type(GESHI_HEADER_DIV);
      -// or...
      -$geshi->set_header_type(GESHI_HEADER_PRE); -// or...
      -$geshi->set_header_type(GESHI_HEADER_NONE);
      - -

      Those are the only three arguments you should pass to set_header_type. Passing anything -else may cause inconsistencies in what is used as the Code Container (although it -*should* simply use a <pre>). Better not to risk it.

      - -
      Note:

      GESHI_HEADER_DIV, GESHI_HEADER_PRE and GESHI_HEADER_NONE are constants, so don't put them -in strings!

      - -
      Caution:

      The default styles for the <pre> and <div> will -be different, especially if you use line numbers!. I have found that a <pre> results -in code that is smaller than for that of a <div>, you should rectify this difference -by using set_overall_style() if you need to. But be aware of this -difference for if you are changing the header type!

      - -

      3.2: Line Numbers

      - - -

      GeSHi has the ability to add line numbers to your code (see the demo available at -http://qbnz.com/highlighter/demo.php to see what can be achieved). Line numbers are -a great way to make your code look professional, especially if you use the fancy -line numbers feature.

      - -
      3.2.1: Enabling Line Numbers
      - - -

      To highlight a source with line numbers, you call the enable_line_numbers() method:

      - -$geshi->enable_line_numbers($flag); - -

      Where $flag is one of the following:

      - -
        -
      • GESHI_NORMAL_LINE_NUMBERS - Use normal line numbering
      • -
      • GESHI_FANCY_LINE_NUMBERS - Use fancy line numbering
      • -
      • GESHI_NO_LINE_NUMBERS - Disable line numbers (default)
      • -
      - -

      Normal line numbers means you specify a style for them, and that style gets applied -to all of them. Fancy line numbers means that you can specify a different style -for each nth line number. You change the value of n (default 5):

      - -$geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 37); - -

      The second parameter is not used in any other mode. Setting it to 0 is the same as -simply using normal line numbers. Setting it to 1 applies the fancy style to every -line number.

      - -
      Note:

      The values above are CONSTANTS - so don't put them in strings!

      - -
      3.2.2 Styling Line Numbers
      - - -

      As of GeSHi 1.0.2, line numbers are added by the use of ordered lists. This solves -the old issues of line number styles inheriting from styles meant for the code. Also, -this solves an important issue about selecting code. For example, line numbers look -nice, but when you go to select the code in your browser to copy it? You got the line -numbers too! Not such a good thing, but thankfully this issue is now solved. What is -the price? Unfortunately the whole way that styles are inherited/used has changed for -those of you who were familiar with 1.0.1, and there is quite a bit more HTML -involved. So think carefully about these things before you enable line numbers.

      - -

      Now, onto how to style line numbers:

      - -

      Styles are set for line numbers using the set_line_style() method:

      - -$geshi->set_line_style('background: #fcfcfc;'); - -

      If you're using Fancy Line Numbers mode, you pass a second string for the style -of the nth line number:

      - -$geshi->set_line_style('background: #fcfcfc;', 'background: #f0f0f0;'); - -

      The second style will have no effect if you're not using Fancy Line Numbers mode.

      - -

      By default, the styles you pass overwrite the current styles. Add a boolean "true" -after the styles you specify to combine them with the current styles:

      - -$geshi->set_line_style('background: red;', true);
      - -// or, for fancy line numbers
      -$geshi->set_line_style('background: red;', 'background: blue;', true);
      - -
      Caution:

      When you set line number styles, the code will inherit those styles! This -is the main issue to come out of the 1.0.2 release. If you want your code to be styled in a predictable -manner, you'll have to call the set_code_style() method to rectify this problem.

      - -

      Note also that you cannot apply background colours to line numbers unless you use set_overall_style(). -Here's how you'd style:

      - -
        -
      1. Use set_overall_style() to style the overall code block. - For example, you can set the border style/colour, any margins and padding etc. using this - method. In addition: set the background colour for all the line numbers - using this method.
      2. -
      3. Use set_line_style() to style the foreground of the line - numbers. For example, you can set the colour, weight, font, padding etc. of the line - numbers using this method.
      4. -
      5. Use set_code_style() to explicitly override the styles - you set for line numbers using set_line_style. For example, - if you'd set the line numbers to be bold (or even if you'd only set the fancy line number - style to be bold), and you didn't actually want your code to be bold, you'd make sure - that font-weight: normal; was in the stylesheet rule you passed to set_code_style
      6. -
      - -

      This is the one major change from GeSHi 1.0.1 - make sure you become familiar with this, and make -sure that you check any code you have already styled with 1.0.1 when you upgrade to make sure nothing -bad happens to it.

      - -
      3.2.3: Choosing a Start Number
      - - -

      As of GeSHi 1.0.2, you can now make the line numbers start at any number, rather than just 1. This feature -is useful if you're highlighting code from a file from around a certain line number in that file, as an additional -guide to those who will view the code. You set the line numbers by calling the start_line_numbers_at() -method:

      - -$geshi->start_line_numbers_at($number); - -

      $number must be a positive integer (or zero). If it is not, GeSHi will convert it anyway.

      - -

      If you have not enabled line numbers, this will have no effect.

      - -
      Caution:

      Although I'd like GeSHi to have XHTML strict compliance, this feature will break -compliancy (however transitional compliancy remains). This is because the only widely supported way to -change the start value for line numbers is by using the start="number" attribute of the -<ol> tag. Although CSS does provide a mechanism for doing this, it is only supported in -Opera versions 7.5 and above (not even Firefox supports this).

      - -

      3.3: Using CSS Classes

      - - -

      Using CSS to highlight your code instead of in-lining the styles is a definate -bonus. Not only is it more compliant (the w3c is deprecating the style attribute -in XHTML 2.0) but it results in far less outputted code - up to a whopping 50% -saving - which makes a *huge* difference to those of us on modems!

      - -
      3.3.1: Enabling CSS Classes
      - - -

      By default, GeSHi doesn't use the classes, so it's easy just to whack out some -highlighted code if you need without worrying about stylesheets. However, if you're -a bit more organised about it, you should use the classes ;). To turn the use of -classes on, you call the enable_classes() method:

      - -$geshi->enable_classes(); - -

      If you want to turn classes OFF for some reason later:

      - -$geshi->enable_classes(false); - -

      If classes are enabled when parse_code() is called, then the resultant source will -use CSS classes in the output, otherwise it will in-line the styles. The advantages -of using classes are great - the reduction in source will be very noticeable, and -what's more you can use one stylesheet for several different highlights on the same -page. In fact, you can even use an external stylesheet and link to that, saving even -more time and source (because stylesheets are cached by browsers).

      - -
      Caution:

      This should be the very first method you call after creating a new -GeSHi object! That way, various other methods can act upon your choice to use classes -correctly. In theory, you could call this method just before parsing the code, but this -may result in unexpected behaviour.

      - -
      3.3.2: Setting the CSS class and ID
      - - -

      You can set an overall CSS class and id for the code. This is a good feature -that allows you to use the same stylesheet for many different snippets of code. -You call set_overall_class() and set_overall_id to accomplish this:

      - -$geshi->set_overall_class('mycode');
      -$geshi->set_overall_id('dk48ck');
      - -

      The default classname is the name of the language being used. This means you can use -just the one stylesheet for all sources that use the same language, and incidentally -means that you probably won't have to call these methods too often.

      - -

      CSS IDs are supposed to be unique, and you should use them as such. Basically, you can -specify an ID for your code and then use that ID to highlight that code in a unique way. -You'd do this for a block of code that you expressly wanted to be highlighted in a -different way (see the section below on gettting the stylesheet for your code for an example).

      - -
      3.3.3: Getting the stylesheet for your code
      - - -

      The other half of using CSS classes is getting the stylesheet for use with the classes. -GeSHi makes it very easy to get a stylesheet for your code, with one easy method call:

      - -$geshi->enable_classes();
      - -
      -// Here we have code that will spit out a header for
      -// a stylesheet. For example:
      -
      -echo '<html>
      -<head><title>Code</title>
      -<style type="text/css">
      - -<!--'
      ;
      -
      -// Echo out the stylesheet for this code block
      -
      -echo $geshi->get_stylesheet();
      -
      -// And continue echoing the page
      - -
      -echo '-->
      -</style></head>
      -<body>'
      ;
      - -

      The get_stylesheet() method gets the stylesheet for your code in one easy call. All you -need to do is output it in the correct place. As you can also see, you don't even have -to enable class usage to get the stylesheet nessecary either - however not enabling -classes but using the stylesheet may result in problems later.

      - -

      By default, get_stylesheet() tries to echo the least amount of code possible. Although -currently it doesn't check to see if a certain lexic is even in the source, you can -expect this feature in the future. At least for the present however, if you explicitly -disable the highlighting of a certain lexic, or disable line numbers, the related CSS -will not be outputted. This may be a bad thing for you perhaps you're going to use -the stylesheet for many blocks of code, some with line numbers, others with some lexic -enabled where this source has it disabled. Or perhaps you're building an external stylesheet -and want all lexics included. So to get around this problem, you do this:

      - -$geshi->get_stylesheet(false); - -

      This turns economy mode off, and all of the stylesheet will be outputted regardless.

      - -

      Now lets say you have several snippets of code, using the same language. In most of them -you don't mind if they're highlighted the same way (in fact, that's exactly what you want) -but in one of them you'd like the source to be highlighted differently. Here's how you -can do that:

      - -// assume path is the default "geshi/" relative to the current directory
      - -$geshi1 = new GeSHi($source1, $lang);
      -$geshi2 = new GeSHi($source2, $lang);
      - -$geshi3 = new GeSHi($source3, $lang);
      -
      -// Turn classes on for all sources
      -$geshi1->enable_classes();
      - -$geshi2->enable_classes();
      -$geshi3->enable_classes();
      -
      -// Make $geshi3 unique
      -$geshi3->set_overall_id('different');
      - -
      -//
      -// Methods are called on $geshi3 to change styles...
      -//
      -
      -echo '<html>
      -<head><title>Code</title>
      - -<style type="text/css">
      -<!--
      -'
      ;
      -
      -// Get the nessecary stylesheets
      -echo $geshi1->get_stylesheet();
      - -echo $geshi3->get_stylesheet();
      -
      -echo '-->
      -</style></head>
      -<body>'
      ;
      - -
      -
      -echo 'Code snippet 1:';
      -echo $geshi1->parse_code();
      -echo 'Code snippet 2 (same highlighting as 1):';
      - -echo $geshi2->parse_code();
      -echo 'Code snippet 3 (DIFFERENT highlighting):';
      -echo $geshi3->parse_code();
      - -
      -echo '</body></html>';
      - -

      Before version 1.0.2, you needed to set the class of the code you wanted to be -unique to the empty string. This limitation has been removed in version 1.0.2 - if -you set the ID of a block of code, all styling will be done based on that ID alone.

      - -
      3.3.4: Using an External Stylesheet
      - - -

      An external stylesheet can reduce even more the amount of code needed to highlight -some source. However there are some drawbacks with this. To use an external stylesheet, -it's up to you to link it in to your document, normally with the following HTML:

      - -<html>
      -<head>
      -<link rel="stylesheet" type="text/css" href="url_to_stylesheet.css" />
      - -

      In your external stylesheet you put CSS declarations for your code. Then just make sure -you're using the correct class (use set_overall_class() to ensure this) and this should -work fine.

      - -

      This method is great if you don't mind the source always being highlighted the same (in particular, -if you're making a plugin for a forum/wiki/other system, using an external stylesheet is a good idea!). -It saves a small amount of code and your bandwidth, and it's relatively easy to just change -the stylesheet should you need to. However, using this will render the methods that -change the styles of the code useless, because of course the stylesheet is no longer being -dynamically generated. You can still disable highlighting of certain lexics dynamically, -however.

      - -
      Note:

      As of version 1.0.2, GeSHi comes with a contrib/ directory, which in it contains -a "wizard" script for creating a stylesheet. Although this script is by no means a complete solution, -it will create the necessary rules for the basic lexics - comments, strings for example. Things -not included in the wizard include regular expressions for any language that uses them (PHP and XML -are two languages that use them), and keyword-link styles. However, this script should take some of -the tedium out of the job of making an external stylesheet. Expect a much better version of this -script in version 1.2!

      - -

      3.4: Changing Styles

      - - -

      One of the more powerful features of GeSHi is the ability to change the style of the -output dynamically. Why be chained to the boring styles the language authors make up? -You can change almost every single aspect of highlighted code - and can even say whether -something is to be highlighted at all.

      - -

      If you're confused about "styles", you probably want to have a quick tutorial in them -so you know what you can do with them. Checkout the homepage of CSS at http://www.w3.org/Style/CSS.

      - -
      3.4.1: The Overall Styles
      - - -

      The code outputted by GeSHi is either in a <div> or a <pre> (see the section entitled -"The Code Container"), and this can be styled.

      - -$geshi->set_overall_style('... styles ...'); - -

      Where styles is a string containing valid CSS declarations. By default, these styles -overwrite the current styles, but you can change this by adding a second parameter:

      - -$geshi->set_overall_style('color: blue;', true); - -

      The default styles "shine through" wherever anything isn't highlighted. Also, you can -apply more advanced styles, like position: (fixed|relative) etc, because a <div>/<pre> -is a block level element.

      - -
      Note:

      Remember that a <div> will by default have a larger font size than a <pre>, -as discussed in the section "The Code Container".

      - -
      3.4.2: Line Number Styles
      - - -

      You may wish to refer to the section Styling Line Numbers before -reading this section.

      - -

      As of version 1.0.2, the way line numbers are generated is different, so therefore the way -that they are styled is different. In particular, now you cannot set the background style of -the fancy line numbers to be different from that of the normal line numbers.

      - -

      Line number styles are set by using the method set_line_style:

      - -$geshi->set_line_style($style1, $style2); - -

      $style1 is the style of the line numbers by default, and $style2 is the style of the -fancy line numbers.

      - -
      Caution:

      Things have changed since 1.0.1! This note is very important - -please make sure you check this twice before complaining about line numbers!

      - -

      Because of the way that ordered lists are done in HTML, there really isn't normally a way -to style the actual numbers in the list. I've cheated somewhat with GeSHi - I've made it -possible to use CSS to style the foreground of the line numbers. So therefore, you -can change the color, font size and type, and padding on them. If you want to have a pretty -background, you must use set_overall_style() to do -this, and use set_code_style() to style the actual code! This is -explained in the section above: Styling Line Numbers.

      - -

      In addition, the styles for fancy line numbers is now the difference between the normal -styles and the styles you want to achieve. For example, in GeSHi prior to 1.0.2 you may -have done this to style line numbers:

      - -$geshi->set_line_style('color: red; font-weight: bold;', 'color: green; font-weight: bold'); - -

      Now you instead can do this:

      - -$geshi->set_line_style('color: red; font-weight: bold;', 'color: green;'); - -

      The font-weight: bold; will automatically carry through to the fancy styles. This is -actually a small saving in code - but the difference may be confusing for anyone using 1.0.1 at first.

      - -
      3.4.3: Setting Keyword Styles
      - - -

      Perhaps the most regular change you will make will be to the styles of a keyword set. In -order to change the styles for a particular set, you'll have to know what the set is -called first. Sets are numbered from 1 up. Typically, set 1 contains keywords like if, -while, do, for, switch etc, set 2 contains null, false, true etc, set 3 contains -function inbuilt into the language (echo, htmlspecialchars etc. in PHP) and set 4 contains -data types and similar variable modifiers: int, double, real, static etc. However -these things are not fixed, and you should check the language file to see what key -you want. Having a familiarity with a language file is definately a plus for using it.

      - -

      To change the styles for a keyword set, call the set_keyword_group_style() method:

      - -$geshi->set_keyword_group_style($group, $styles); - -

      Where $group is the group to change the styles for and $styles is a string containing -the styles to apply to that group.

      - -

      By default, the styles you pass overwrite the current styles. Add a boolean "true" -after the styles you specify to combine them with the current styles:

      - -$geshi->set_keyword_group_style(3, 'color: white;', true); - -
      3.4.4: Setting Comment Styles
      - - -

      To change the styles for a comment group, call the set_comments_style() method:

      - -$geshi->set_comments_style($group, $styles); - -

      Where $group is either a number corresponding to a single-line comment, or the string -'MULTI' to specify multiline comments:

      - -$geshi->set_comments_style(1, 'font-style: italic;');
      -$geshi->set_comments_style('MULTI', 'display: hidden;');
      - -

      By default, the styles you pass overwrite the current styles. Add a boolean "true" -after the styles you specify to combine them with the current styles:

      - -$geshi->set_comments_style(1, 'font-weight: 100;', true); - -
      3.4.5: Setting Other Styles
      - - -

      GeSHi can highlight many other aspects of your source other than just keywords and -comments. Strings, Numbers, Methods and Brackets among other things can all also be -highlighted. Here are the related methods:

      - -$geshi->set_escape_characters_style($styles[, $preserve_defaults]);
      -$geshi->set_symbols_style($styles[, $preserve_defaults]);
      - -$geshi->set_strings_style($styles[, $preserve_defaults]);
      -$geshi->set_numbers_style($styles[, $preserve_defaults]);
      -$geshi->set_methods_style($key, $styles, [, $preserve_defaults]);
      - -

      $styles is a string containing valid stylesheet declarations, while $preserve_defaults -should be set to true if you want your styles to be merged with the previous styles. In the case of set_methods_style, -you should select a group to set the styles of, check the language files for the number used for each "object splitter".

      - -

      3.5: Case Sensitivity and Auto Casing

      - - -

      Controlling the case of the outputted source is an easy job with GeSHi. You can control which keywords are converted in case, and also control whether -keywords are checked in a case sensitive manner.

      - -
      3.5.1: Auto-Caps/Nocaps
      - - -

      Auto-Caps/Nocaps is a nifty little feature that capitalises or lowercases automatically -certain lexics when they are styled. I dabble in QuickBASIC, a dialect of BASIC which is well -known for it's capatalisation, and SQL is another language well known for using caps -for readability.

      - -

      To change what case lexics are rendered in, you call the set_case_keywords() method:

      - -$geshi->set_case_keywords($caps_modifier); - -

      The valid values to pass to this method are:

      - -
        -
      • GESHI_CAPS_NO_CHANGE - Don't change the case of any lexics, leave as they are found
      • -
      • GESHI_CAPS_UPPER - Uppercase all lexics found
      • -
      • GESHI_CAPS_LOWER - Lowercase all lexics found
      • -
      - -
      Caution:

      When I say "lexic", I mean "keywords". Any keyword in any keyword -array will be modified using this option! This is one small area of inflexibility I hope to fix in 1.2.X.

      - -

      I suspect this will only be used to specify GESHI_CAPS_NO_CHANGE to turn off autocaps -for languages like SQL and BASIC variants, like so:

      - -$geshi = new GeSHi($source, 'sql');
      -$geshi->set_case_keywords(GESHI_CAPS_NO_CHANGE); // don't want keywords capatalised
      - -

      All the same, it can be used for some interesting effects:

      - -$geshi = new GeSHi($source, 'java');
      -// Anyone who's used java knows how picky it is about CapitalLetters...
      -$geshi->set_case_keywords(GESHI_CAPS_LOWER);
      -// No *way* the source will look right now ;)
      - -
      3.5.2: Setting Case Sensitivity
      - - -

      Some languages, like PHP, don't mind what case function names and keywords are in, while others, like Java, depend -on such pickiness to maintain their bad reputations ;). In any event, you can use the set_case_sensitivity -to change the case sensitiveness of a particular keyword group from the default:

      - -$geshi->set_case_sensitivity($key, $sensitivity); - -

      Where $key is the key of the group for which you wish to change case sensitivness for (see the language file for that language), and -$sensitivity is a boolean value - true if the keyword is case sensitive, and false if not.

      - -

      3.6: Changing the Source, Language, Config Options

      - - -

      What happens if you want to change the source to be highlighted on the fly, or the -language. Or if you want to specify any of those basic fields after you've created -a GeSHi object? Well, that's where these methods come in.

      - -
      3.6.1: Changing the Source Code
      - - -

      To change the source code, you call the set_source() method:

      - -$geshi->set_source($newsource); - -

      Example:

      - -$geshi = new GeSHi($source1, 'php');
      - -
      -// Method calls to specify various options...
      -
      -$code1 = $geshi->parse_code();
      -
      -$geshi->set_source($source2);
      - -$code2 = $geshi->parse_code();
      - -
      3.6.2: Changing the Language
      - - -

      What happens if you want to change the language used for highlighting? Just call -set_language():

      - -$geshi->set_language('newlanguage'); - -

      Example:

      - -$geshi = new GeSHi($source, 'php');
      - -
      -$code = $geshi->parse_code();
      -
      -// Highlight GeSHi's output
      -$geshi->set_source($code);
      - -$geshi->set_language('html4strict');
      -$geshi->enable_classes(false);
      -echo $geshi->parse_code();
      - -
      Note:

      Names are case-insensitive - they will be converted to lower case to match a language -file however. So if you're making a language file, remember it should have a name in lower case.

      - -
      Note:

      What you pass to this method is the name of a language file, minus the .php extension. If you're -writing a plugin for a particular application, it's up to you to somehow convert user input into a valid language -name.

      - -
      Caution:

      GeSHi include()s the language file, so be careful to make sure -that users can't pass some wierd language name to include any old script! GeSHi tries to strip non-valid characters -out of a language name, but you should always do this your self anyway. In particular, language files are always -lower-case, with either alphanumeric characters, dashes or underscores in their name.

      - -

      At the very least, strip "/" characters out of a language name.

      - -
      3.6.3: Changing the Language Path
      - - -

      What happens if all of a sudden you want to use language files from a different -directory from the current language file location? You call the set_language_path() -method:

      - -$geshi->set_language_path($newpath); - -

      It doesn't matter whether the path has a trailing slash after it or not - only that -it points to a valid folder. If it doesn't, that's your tough luck ;)

      - -
      3.6.4: Changing the Character Set
      - - -
      Note:

      As of GeSHi 1.0.7.18, you don't need to use this, as htmlspecialchars is not being used due to a security flaw in it (that is unpatched in even the most recent PHP4 versions, and in PHP5 < 5.2). As long as you set the encoding properly with a php header() call, your foreign characters will be displayed correctly.

      - -

      As of version 1.0.3, you can use the method set_encoding to specify the character set that your -source is in. Valid names are those names that are valid for the PHP function htmlentities():

      - -$geshi->set_encoding($encoding); - -

      There is a table of valid strings for $encoding at the php.net manual linked to above. If you do not specify an encoding, or specify an -invalid encoding, the character set used is ISO-8859-1.

      - -
      Using load_from_file to Change the Language and Source Code
      - - -

      As of GeSHi 1.0.5, you can use the method load_from_file to load the source code and language from a file. Simply pass -this method a file name and it will attempt to load the source and set the language.

      - -$geshi->load_from_file($file_name, $lookup); - -

      $file_name is the file name to use, and $lookup is an optional parameter that contains a lookup array to use for -deciding which language to choose. You can use this to override GeSHi's default lookup array, which may not contain the extension of the file -you're after, or perhaps does have your extension but under a different language. The lookup array is of the form:

      - -
      array(
      -	 *   'lang_name' => array('extension', 'extension', ...),
      -	 *   'lang_name' ...
      -	 * );
      - -

      Also, you can use the method get_language_name_from_extension if you need to convert a file extension to a valid language name. -This method will return the empty string if it could not find a match in the lookup, and like load_from_file it accepts an -optional second parameter that contains a lookup array.

      - -

      3.7: Error Handling

      - - -

      What happens if you try to highlight using a language that doesn't exist? Or if GeSHi can't read a required file? The results -you get may be confusing. You may check your code over and over, and never find anything wrong. GeSHi provides ways of finding -out if GeSHi itself found anything wrong with what you tried to do. After highlighting, you can call the error() -method:

      - -$geshi = new GeSHi('hi', 'thisLangIsNotSupported');
      - -
      -echo $geshi->error()// echoes error message
      - -

      The error message you will get will look like this:

      - -
      GeSHi Error: GeSHi could not find the language thisLangIsNotSupported (using path geshi/) (code 2)
      - -

      The error outputted will be the last error GeSHi came across, just like how mysql_error() works.

      - -

      3.8: Disabling styling of some Lexics

      - - -

      One disadvantage of GeSHi is that for large source files using complex languages, it can be quite slow with every option -turned on. Although future releases will concentrate on the speed/resource side of highlighting, for now you can gain -speed increases by disabling some of the highlighting options. This is done by using a series of set_*_highlighting methods:

      - -
        -
      • set_keyword_group_highlighting($group, $flag): Sets whether a particular - $group of keywords is to be highlighted or not. Consult the necessary language file(s) to see what $group - should be for each group (typically a positive integer). $flag is false if you want to disable highlighting - of this group, and true if you want to re-enable higlighting of this group. If you disable a keyword group then - even if the keyword group has a related URL one will not be generated for that keyword.
      • -
      • set_comments_highlighting($group, $flag): Sets whether a particular - $group of comments is to be highlighted or not. Consult the necessary language file(s) to see what $group - should be for each group (typically a positive integer, or the string 'MULTI' for multiline comments. $flag is - false if you want to disable highlighting of this group, and true if you want to re-enable - highlighting of this group.
      • -
      • set_regexps_highlighting($regexp, $flag): Sets whether a particular - $regexp is to be highlighted or not. Consult the necessary language file(s) to see what $regexp - should be for each regexp (typically a positive integer, or the string 'MULTI' for multiline comments. $flag is - false if you want to disable highlighting of this group, and true if you want to re-enable - highlighting of this group.
      • -
      • The following methods: -
          -
        • set_escape_characters_highlighting($flag)
        • -
        • set_symbols_highlighting($flag)
        • -
        • set_strings_highlighting($flag)
        • -
        • set_numbers_highlighting($flag)
        • -
        • set_methods_highlighting($flag)
        • -
        - Work on their respective lexics (e.g. set_methods_highlighting will disable/enable highlighting of methods). For each - method, if $flag is false then the related lexics will not be highlighted at all (this - means no HTML will surround the lexic like usual, saving on time and bandwidth.
      • -
      - -

      3.9: Setting the Tab Width

      - - -

      If you're using the <pre> header, tabs are handled automatically by your browser, and in general you can count on good results. However, -if you're using the <div> header, you may want to specify a tab width explicitly.

      - -

      Note that tabs created in this fashion won't be like normal tabs - there won't be "tab-stops" as such, instead -tabs will be replaced with the specified number of spaces.

      - -

      To change the tab width, you call the set_tab_width() method:

      - -$geshi->set_tab_width($width); - -

      Where $width is the width in spaces that you'd like tabs to be.

      - -

      3.10: Using Strict Mode

      - - -

      Some languages like to get tricky, and jump in and out of the file that they're in. For example, the vast majority of you reading -this will have used a PHP file. And you know that PHP code is only executed if it's within delimiters like <?php and ?> (there -are others of course...). So what happens if you do the following in a php file?

      - -<img src="<?php echo rand(1, 100) ?>" /> - -

      Well normally using GeSHi with PHP, or using a bad highlighter, you'll end up with this:

      - -<img src="<?php echo rand(1, 100) ?>" /> - -

      What a mess! Especially if you're being slack about where you're putting your quotes, you could end up with the rest of your -file as bright red. Fortunately, you can tell GeSHi to be "strict" about just when it highlights and when it does not, -using the enable_strict_mode method:

      - -$geshi->enable_strict_mode($mode); - -

      Where $mode is true or not specified to enable strict mode, or false to disable strict mode -if you've already turned it and don't want it now.

      - -

      Here's the result: much better!

      - -<img src="<?php echo rand(1, 100) ?>" /> - -

      3.11: Adding/Removing Keywords

      - - -

      Lets say that you're working on a large project, with many files, many classes and many functions. Perhaps also you have the source code -on the web and highlighted by GeSHi, perhaps as a front end to CVS, as a learning tool, something to refer to, whatever. Well, why not highlight -the names of the functions and classes *your* project uses, as well as the standard functions and classes? Or perhaps you're not interested in -highlighting certain functions, and would like to remove them? Or maybe you don't mind if an entire function group goes west in the interest -of speed? GeSHi can handle all of this!

      - -
      3.11.1: Adding a Keyword
      - - -

      If you want to add a keyword to an existing keyword group, you use the add_keyword method:

      - -$geshi->add_keyword($key, $word); - -

      Where $key is the index of the group of keywords you want to add this keyword to, and $word is the word to add.

      - -

      This implies knowledge of the language file to know the correct index.

      - -
      Note:

      Keywords should contain at least two alphabetical characters (lower or upper case letters -only). This is to enable GeSHi to work much faster by not bothering to try to detect keywords in parts of your source where there is no alphabetical -characters.

      - -
      3.11.2: Removing a Keyword
      - - -

      Perhaps you want to remove a keyword from an existing group. Maybe you don't use it and want to save yourself some time. Whatever the -reason, you can remove it using the remove_keyword method:

      - -$geshi->remove_keyword($key, $word); - -

      Where $key is the index of the gropu of keywords that you want to remove this keyword from, and $word is the word to remove.

      - -

      This implies knowledge of the language file to know the correct index - most of the time the keywords you'll want to remove will be in -group 3, but this is not guaranteed and you should check the language file first.

      - -

      This function is silent - if the keyword is not in the group you specified, nothing awful will happen ;)

      - -
      3.11.3: Adding a Keyword Group
      - - -

      Lets say for your big project you have several main functions and classes that you'd like highlighted. Why not add them as their own group -instead of having them highlighted the same way as other keywords? Then you can make them stand out, and people can instantly see which functions -and classes are user defined or inbuilt. Furthermore, you could set the URL for this group to point at the API documentation of your project.

      - -

      You add a keyword group by using the add_keyword_group method:

      - -$geshi->add_keyword_group($key, $styles, $case_sensitive, $words); - -

      Where $key is the key that you want to use to refer to this group, $styles is the styles that you want to -use to style this group, $case_sensitive is true or false depending on whether you want -this group of keywords to be case sensitive or not and $words is an array of words (or a string) of which words to add -to this group. For example:

      - -$geshi->add_keyword_group(10, 'color: #600000;', false, array('myfunc_1', 'myfunc_2', 'myfunc_3')); - -

      Adds a keyword group referenced by index 10, of which all keywords in the group will be dark red, -each keyword can be in any case and which contains the keywords "myfunc_1", "myfunc_2" and "myfunc_3".

      - -

      After creating such a keyword group, you may call other GeSHi methods on it, just as you would for any other keyword group.

      - -
      Caution:

      If you specify a $key for which there is already a keyword -group, the old keyword group will be overwritten! Most language files don't use numbers larger than 5, so I recommend you play it -safe and use a number like 10 or 42.

      - -
      3.11.4: Removing a Keyword Group
      - - -

      Perhaps you *really* need speed? Why not just remove an entire keyword group? GeSHi won't have to loop through each -keyword checking for its existance, saving much time. You removing a keyword group by using the remove_keyword_group -method:

      - -$geshi->remove_keyword_group($key); - -

      Where $key is the key of the group you wish to remove. This implies knowleged of the language file.

      - -

      3.12: Headers and Footers for Your Code

      - - -

      So you want to add some special information to the highlighted source? GeSHi can do that too! You can specify headers -and footers for your code, style them, and insert information from the highlighted source into your header or footer.

      - -
      3.12.1: Keyword Substitution
      - - -

      In your header and footer, you can put special keywords that will be replaced with actual configuration values for -this GeSHi object. The keywords you can use are:

      - -
        -
      • <TIME> or {TIME}: Is replaced by the time it took for the parse_code method - i.e., how - long it took for your code to be highlighted. The time is returned to three decimal places.
      • -
      • <LANGUAGE> or {LANGUAGE}: Is replaced by a nice, friendly version of the language name used to - highlight this code.
      • -
      • <VERSION> or {VERSION}: The GeSHi version used to highlight the code.
      • -
      - -
      3.12.2: Setting Header Content
      - - -

      The header for your code is a <div>, which is inside the containing block. Therefore, it is affected by -the method set_overall_style, and should contain the sort of HTML that belongs in a <div>. -You may use any HTML you like, and format it as an HTML document. You should use valid HTML - convert to entities -any quotemarks or angle brackets you want displayed. You set the header content using the method set_header_content:

      - -$geshi->set_header_content($content); - -

      Where $content is the HTML you want to use for the header.

      - - - - -

      The footer for your code is a <div>, which is inside the containing block. Therefore, it is affected by -the method set_overall_style, and should contain the sort of HTML that belongs in a <div>. -You may use any HTML you like, and format it as an HTML document. You should use valid HTML - convert to entities -any quotemarks or angle brackets you want displayed. You set the footer content using the method set_footer_content:

      - -$geshi->set_footer_content($content); - -

      Where $content is the HTML you want to use for the footer.

      - -
      3.12.4: Styling Header Content
      - - -

      You can apply styles to the header content you have set with the set_header_content_style:

      - -$geshi->set_header_content_style($styles); - -

      Where $styles is the stylesheet declarations you want to use to style the header content.

      - - - - -

      You can apply styles to the footer content you have set with the set_footer_content_style:

      - -$geshi->set_footer_content_style($styles); - -

      Where $styles is the stylesheet declarations you want to use to style the footer content.

      - -

      3.13: Keyword URLs

      - - -

      As of version 1.0.2, GeSHi allows you to specify a URL for keyword groups. This URL is used by GeSHi to convert the -keywords in that group into URLs to appropriate documentation. And using add_keyword_group you -can add functions and classes from your own projects and use the URL functionality to provide a link to your own API -documentation.

      - -
      3.13.1: Setting a URL for a Keyword Group
      - - -

      To set the URL to be used for a keyword group, you use the set_url_for_keyword_group method:

      - -$geshi->set_url_for_keyword_group($group, $url); - -

      Where $group is the keyword group you want to assign the URL for, and $url is the URL for this -group of keywords.

      - -

      You may be wondering how to make each keyword in the group point to the correct URL. You do this by putting {FNAME} -in the URL at the correct place. For example, PHP makes it easy by linking www.php.net/function-name to the documentation for -that function, so the URL used is http://www.php.net/{FNAME}.

      - -

      Of course, when you get to a language like Java, that puts its class documentation in related folders, it gets a little trickier -to work out an appropriate URL (see the Java language file!). I hope to provide some kind of redirection service at -the GeSHi website in the future.

      - -
      3.13.2: Disabling a URL for a Keyword Group
      - - -

      It's easy to disable a URL for a keyword group: Simply use the method set_url_for_keyword_group to pass an empty string -as the URL:

      - -$geshi->set_url_for_keyword_group($group, ''); - -
      3.13.3 Disabling all URLs for Keywords
      - - -

      As of GeSHi 1.0.7.18, you can disable all URL linking for keywords:

      - -$geshi->enable_keyword_links(false); - - - - -

      You can also style the function links. You can style their default status, hovered, active and visited status. -All of this is controlled by one method, set_link_styles:

      - -$geshi->set_link_styles($mode, $styles); - -

      Where $mode is one of four values:

      - -
        -
      • GESHI_LINK: The default style of the links.
      • -
      • GESHI_HOVER: The style of the links when they have focus (the mouse is hovering - over them).
      • -
      • GESHI_ACTIVE: The style of the links when they are being clicked.
      • -
      • GESHI_VISITED: The style of links that the user has already visited.
      • -
      - -

      And $styles is the stylesheet declarations to apply to the links.

      - -
      3.13.5: Setting the Link Target
      - - -

      Perhaps you want to set the target of link attributes, so the manual pages open in a new window? Use the set_link_target method:

      - -$geshi->set_link_target($target, $styles); - -

      Where $target is any valid (X)HTML target value - _blank or _top for example.

      - -

      3.14: Using Contextual Importance

      - - -
      Caution:

      This functionality is not only buggy, but is proving -very hard to implement in 1.1.X. Therefore, this functionality may well be removed in 1.2.0. You are -hereby warned!

      - -

      3.15: Highlighting Special Lines "Extra"

      - - -

      An alternative (and more stable) method of highlighting code that is important is to use extra highlighting by line. -Although you may not know what line numbers contain the important lines, if you do this method is a much more flexible -way of making important lines stand out.

      - -
      3.15.1: Specifying the Lines to Highlight Extra
      - - -

      To specify which lines to highlight extra, you past an array containing the line numbers to highlight_lines_extra:

      - -$geshi->highlight_lines_extra($array); - -

      The array could be in the form array(2, 3, 4, 7, 12, 344, 4242), made from a DB query, generated from looking -through the source for certain important things and working out what line those things are... however you get the line numbers, -the array should simply be an array of integers.

      - -

      Here's an example, using the same source as before:

      - -//
      -// Here we go again! This time we'll simply highlight the 8th line
      -//
      -$source = 'public int[][] product ( n, m )
      -{
      -  int [][] ans = new int[n][m];
      -  for ( int i = 0; i < n; i++ )
      -  {
      -    for ( int j = 0; i < m; j++ )
      - -    {
      -      ans[i][j] = i * j;
      -    }
      -  }
      - -  return ans;
      -}'
      ;
      -
      - -$geshi = new GeSHi($source, 'java');
      - -
      -$geshi->highlight_lines_extra(array(8)); - -
      -echo $geshi->parse_code();
      - -

      Which produces:

      - -public int[][] product ( n, m )
      -{
      - -  int [][] ans = new int[n][m];
      for ( int i = 0; i < n; i++ )
      - -  {
      -    for ( int j = 0; i < m; j++ )
      -    {
      -
      -
            ans[i][j] = i * j;
      -    }
      }
      return ans;
      - -}
      - -

      What's more, as you can see the code on a highlighted line is still actually highlighted itself.

      - -
      Note:

      As you can see, this is a little buggy, but that is because of HTML laws -(code elements should not contain div elements). This works just fine if you use line numbers.

      - -
      3.15.2: Styles for the Highlighted Lines
      - - -

      Again as with contextual importance, you're not chained to the yellow theme that is the default. You can use the -set_highlight_lines_extra_style method:

      - -$geshi->set_highlight_lines_extra_style($styles); - -

      Where $styles is the stylesheet declarations that you want to apply to highlighted lines.

      - -

      3.16: Adding IDs to Each Line

      - - -

      Perhaps you're a javascript junkie? GeSHi provides a way to give each line an ID so you can access that line with -javascript, or perhaps just by plain CSS (though if you want to access lines by CSS you should use the method in the -previous section). To enable IDs you call the enable_ids method:

      - -$geshi->enable_ids($flag); - -

      Where $flag is true or not present to enable IDs, and false to disable them -again if you need.

      - -

      The ID generated is in the form {overall-css-id}-{line-number}. So for example, if you set the overall -CSS id to be "mycode", then the IDs for each line would by "mycode-1", "mycode-2" etc. -If there is no CSS ID set, then one is made up in the form geshi-[4 random characters], but this is not -so useful for if you want to do javascript manipulation.

      - -

      3.17: Getting the Time of Styling

      - - -

      Once you've called parse_code, you can get the time it took to run the highlighting by calling the -get_time method:

      - -$geshi = new GeSHi($source, $language, $path);
      - -
      -$code = addslashes($geshi->parse_code());
      -$time = $geshi->get_time();
      - -
      -// do something with it
      -mysql_query("INSERT INTO code VALUES ('$code', '$time')");
      - - -

      4: Language Files

      - - -

      So now you know what features GeSHi offers, and perhaps you've even meddled with the source. Or perhaps -you'd like a language file for language X but it doesn't seem to be supported? Rubbish! GeSHi will highlight -anything, what do you think I coded this for? ^_^ You'll just have to learn how to make a language file -yourself. And I promise it's not too hard - and if you're here you're in the right place!

      - -

      4.1: An Example Language File

      - - -

      Let's begin by looking at an example language file - the language file for the first language ever supported, -PHP.

      - -
      <?php
      -/*************************************************************************************
      - * php.php
      - * --------
      - * Author: Nigel McNie (nigel@geshi.org)
      - * Copyright: (c) 2004 Nigel McNie (http://qbnz.com/highlighter/)
      - * Release Version: 1.0.2
      - * CVS Revision Version: $Revision$
      - * Date Started: 2004/06/20
      - * Last Modified: $Date$
      - *
      - * PHP language file for GeSHi.
      - *
      - * CHANGES
      - * -------
      - * 2004/XX/XX (1.0.2)
      - *  -  Added URL support
      - *  -  Added extra constants
      - * 2004/08/05 (1.0.1)
      - *  -  Added support for symbols
      - * 2004/07/14 (1.0.0)
      - *  -  First Release
      - *
      - * TODO (updated 2004/07/14)
      - * -------------------------
      - * * Make sure the last few function I may have missed
      - *   (like eval()) are included for highlighting
      - * * Split to several files - php4, php5 etc
      - *
      - *************************************************************************************
      - *
      - *     This file is part of GeSHi.
      - *
      - *   GeSHi is free software; you can redistribute it and/or modify
      - *   it under the terms of the GNU General Public License as published by
      - *   the Free Software Foundation; either version 2 of the License, or
      - *   (at your option) any later version.
      - *
      - *   GeSHi is distributed in the hope that it will be useful,
      - *   but WITHOUT ANY WARRANTY; without even the implied warranty of
      - *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      - *   GNU General Public License for more details.
      - *
      - *   You should have received a copy of the GNU General Public License
      - *   along with GeSHi; if not, write to the Free Software
      - *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
      - *
      - ************************************************************************************/
      - 
      -$language_data = array (
      -	'LANG_NAME' => 'PHP',
      -	'COMMENT_SINGLE' => array(1 => '//', 2 => '#'),
      -	'COMMENT_MULTI' => array('/*' => '*/'),
      -	'CASE_KEYWORDS' => GESHI_CAPS_NO_CHANGE,
      -	'QUOTEMARKS' => array("'", '"'),
      -	'ESCAPE_CHAR' => '\\',
      -	'KEYWORDS' => array(
      -		1 => array(
      -			'include', 'require', 'include_once', 'require_once',
      -			'for', 'foreach', 'as', 'if', 'elseif', 'else', 'while', 'do', 'endwhile', 'endif', 'switch', 'case', 'endswitch',
      -			'return', 'break'
      -			),
      -		2 => array(
      -			'null', '__LINE__', '__FILE__',
      -			'false', '&lt;?php', '?&gt;', '&lt;?',
      -			'&lt;script language=', '&lt;/script&gt;',
      -			'true', 'var', 'default',
      -			'function', 'class', 'new',
      -			'__FUNCTION__', '__CLASS__', '__METHOD__', 'PHP_VERSION',
      -			'PHP_OS', 'DEFAULT_INCLUDE_PATH', 'PEAR_INSTALL_DIR', 'PEAR_EXTENSION_DIR',
      -			'PHP_EXTENSION_DIR', 'PHP_BINDIR', 'PHP_LIBDIR', 'PHP_DATADIR', 'PHP_SYSCONFDIR',
      -			'PHP_LOCALSTATEDIR', 'PHP_CONFIG_FILE_PATH', 'PHP_OUTPUT_HANDLER_START', 'PHP_OUTPUT_HANDLER_CONT',
      -			'PHP_OUTPUT_HANDLER_END', 'E_ERROR', 'E_WARNING', 'E_PARSE', 'E_NOTICE',
      -			'E_CORE_ERROR', 'E_CORE_WARNING', 'E_COMPILE_ERROR', 'E_COMPILE_WARNING', 'E_USER_ERROR',
      -			'E_USER_WARNING', 'E_USER_NOTICE', 'E_ALL'
      -			),
      -		3 => array(
      -			'zlib_get_coding_type','zend_version','zend_logo_guid','yp_order','yp_next',
      -			'yp_match','yp_master','yp_get_default_domain','yp_first','yp_errno','yp_err_string',
      -			'yp_cat','yp_all','xml_set_unparsed_entity_decl_handler','xml_set_start_namespace_decl_handler','xml_set_processing_instruction_handler','xml_set_object',
      -			'xml_set_notation_decl_handler','xml_set_external_entity_ref_handler','xml_set_end_namespace_decl_handler','xml_set_element_handler','xml_set_default_handler','xml_set_character_data_handler',
      -			'xml_parser_set_option','xml_parser_get_option','xml_parser_free','xml_parser_create_ns','xml_parser_create','xml_parse_into_struct',
      -			'xml_parse','xml_get_error_code','xml_get_current_line_number','xml_get_current_column_number','xml_get_current_byte_index','xml_error_string',
      -			'wordwrap','wddx_serialize_vars','wddx_serialize_value','wddx_packet_start','wddx_packet_end','wddx_deserialize',
      -			'wddx_add_vars','vsprintf','vprintf','virtual','version_compare','var_export',
      -			'var_dump','utf8_encode','utf8_decode','usort','usleep','user_error',
      -			'urlencode','urldecode','unserialize','unregister_tick_function','unpack','unlink',
      -			'unixtojd','uniqid','umask','uksort','ucwords','ucfirst',
      -			'uasort','trim','trigger_error','touch','token_name','token_get_all',
      -			'tmpfile','time','textdomain','tempnam','tanh','tan',
      -			'system','syslog','symlink','substr_replace','substr_count','substr',
      -			'strval','strtr','strtoupper','strtotime','strtolower','strtok',
      -			'strstr','strspn','strrpos','strrev','strrchr','strpos',
      -			'strncmp','strncasecmp','strnatcmp','strnatcasecmp','strlen','stristr',
      -			'stripslashes','stripcslashes','strip_tags','strftime','stream_wrapper_register','stream_set_write_buffer',
      -			'stream_set_timeout','stream_set_blocking','stream_select','stream_register_wrapper','stream_get_meta_data','stream_filter_prepend',
      -			'stream_filter_append','stream_context_set_params','stream_context_set_option','stream_context_get_options','stream_context_create','strcspn',
      -			'strcoll','strcmp','strchr','strcasecmp','str_word_count','str_shuffle',
      -			'str_rot13','str_replace','str_repeat','str_pad','stat','sscanf',
      -			'srand','sqrt','sql_regcase','sprintf','spliti','split',
      -			'soundex','sort','socket_writev','socket_write','socket_strerror','socket_shutdown',
      -			'socket_setopt','socket_set_timeout','socket_set_option','socket_set_nonblock','socket_set_blocking','socket_set_block',
      -			'socket_sendto','socket_sendmsg','socket_send','socket_select','socket_recvmsg','socket_recvfrom',
      -			'socket_recv','socket_readv','socket_read','socket_listen','socket_last_error','socket_iovec_set',
      -			'socket_iovec_free','socket_iovec_fetch','socket_iovec_delete','socket_iovec_alloc','socket_iovec_add','socket_getsockname',
      -			'socket_getpeername','socket_getopt','socket_get_status','socket_get_option','socket_create_pair','socket_create_listen',
      -			'socket_create','socket_connect','socket_close','socket_clear_error','socket_bind','socket_accept',
      -			'sleep','sizeof','sinh','sin','similar_text','shuffle',
      -			'show_source','shmop_write','shmop_size','shmop_read','shmop_open','shmop_delete',
      -			'shmop_close','shm_remove_var','shm_remove','shm_put_var','shm_get_var','shm_detach',
      -			'shm_attach','shell_exec','sha1_file','sha1','settype','setlocale',
      -			'setcookie','set_time_limit','set_socket_blocking','set_magic_quotes_runtime','set_include_path','set_file_buffer',
      -			'set_error_handler','session_write_close','session_unset','session_unregister','session_start','session_set_save_handler',
      -			'session_set_cookie_params','session_save_path','session_register','session_regenerate_id','session_name','session_module_name',
      -			'session_is_registered','session_id','session_get_cookie_params','session_encode','session_destroy','session_decode',
      -			'session_cache_limiter','session_cache_expire','serialize','sem_remove','sem_release','sem_get',
      -			'sem_acquire','rtrim','rsort','round','rmdir','rewinddir',
      -			'rewind','restore_include_path','restore_error_handler','reset','rename','register_tick_function',
      -			'register_shutdown_function','realpath','readlink','readgzfile','readfile','readdir',
      -			'read_exif_data','rawurlencode','rawurldecode','range','rand','rad2deg',
      -			'quotemeta','quoted_printable_decode','putenv','proc_open','proc_close','printf',
      -			'print_r','prev','preg_split','preg_replace_callback','preg_replace','preg_quote',
      -			'preg_match_all','preg_match','preg_grep','pow','posix_uname','posix_ttyname',
      -			'posix_times','posix_strerror','posix_setuid','posix_setsid','posix_setpgid','posix_setgid',
      -			'posix_seteuid','posix_setegid','posix_mkfifo','posix_kill','posix_isatty','posix_getuid',
      -			'posix_getsid','posix_getrlimit','posix_getpwuid','posix_getpwnam','posix_getppid','posix_getpid',
      -			'posix_getpgrp','posix_getpgid','posix_getlogin','posix_getgroups','posix_getgrnam','posix_getgrgid',
      -			'posix_getgid','posix_geteuid','posix_getegid','posix_getcwd','posix_get_last_error','posix_errno',
      -			'posix_ctermid','pos','popen','pi','phpversion','phpinfo',
      -			'phpcredits','php_uname','php_sapi_name','php_logo_guid','php_ini_scanned_files','pg_update',
      -			'pg_untrace','pg_unescape_bytea','pg_tty','pg_trace','pg_setclientencoding','pg_set_client_encoding',
      -			'pg_send_query','pg_select','pg_result_status','pg_result_seek','pg_result_error','pg_result',
      -			'pg_query','pg_put_line','pg_port','pg_ping','pg_pconnect','pg_options',
      -			'pg_numrows','pg_numfields','pg_num_rows','pg_num_fields','pg_meta_data','pg_lowrite',
      -			'pg_lounlink','pg_loreadall','pg_loread','pg_loopen','pg_loimport','pg_loexport',
      -			'pg_locreate','pg_loclose','pg_lo_write','pg_lo_unlink','pg_lo_tell','pg_lo_seek',
      -			'pg_lo_read_all','pg_lo_read','pg_lo_open','pg_lo_import','pg_lo_export','pg_lo_create',
      -			'pg_lo_close','pg_last_oid','pg_last_notice','pg_last_error','pg_insert','pg_host',
      -			'pg_getlastoid','pg_get_result','pg_get_pid','pg_get_notify','pg_freeresult','pg_free_result',
      -			'pg_fieldtype','pg_fieldsize','pg_fieldprtlen','pg_fieldnum','pg_fieldname','pg_fieldisnull',
      -			'pg_field_type','pg_field_size','pg_field_prtlen','pg_field_num','pg_field_name','pg_field_is_null',
      -			'pg_fetch_row','pg_fetch_result','pg_fetch_object','pg_fetch_assoc','pg_fetch_array','pg_fetch_all',
      -			'pg_exec','pg_escape_string','pg_escape_bytea','pg_errormessage','pg_end_copy','pg_delete',
      -			'pg_dbname','pg_copy_to','pg_copy_from','pg_convert','pg_connection_status','pg_connection_reset',
      -			'pg_connection_busy','pg_connect','pg_cmdtuples','pg_close','pg_clientencoding','pg_client_encoding',
      -			'pg_cancel_query','pg_affected_rows','pfsockopen','pclose','pathinfo','passthru',
      -			'parse_url','parse_str','parse_ini_file','pack','overload','output_reset_rewrite_vars',
      -			'output_add_rewrite_var','ord','openssl_x509_read','openssl_x509_parse','openssl_x509_free','openssl_x509_export_to_file',
      -			'openssl_x509_export','openssl_x509_checkpurpose','openssl_x509_check_private_key','openssl_verify','openssl_sign','openssl_seal',
      -			'openssl_public_encrypt','openssl_public_decrypt','openssl_private_encrypt','openssl_private_decrypt','openssl_pkey_new','openssl_pkey_get_public',
      -			'openssl_pkey_get_private','openssl_pkey_free','openssl_pkey_export_to_file','openssl_pkey_export','openssl_pkcs7_verify','openssl_pkcs7_sign',
      -			'openssl_pkcs7_encrypt','openssl_pkcs7_decrypt','openssl_open','openssl_get_publickey','openssl_get_privatekey','openssl_free_key',
      -			'openssl_error_string','openssl_csr_sign','openssl_csr_new','openssl_csr_export_to_file','openssl_csr_export','openlog',
      -			'opendir','octdec','ob_start','ob_list_handlers','ob_implicit_flush','ob_iconv_handler',
      -			'ob_gzhandler','ob_get_status','ob_get_level','ob_get_length','ob_get_flush','ob_get_contents',
      -			'ob_get_clean','ob_flush','ob_end_flush','ob_end_clean','ob_clean','number_format',
      -			'nl_langinfo','nl2br','ngettext','next','natsort','natcasesort',
      -			'mysql_unbuffered_query','mysql_thread_id','mysql_tablename','mysql_table_name','mysql_stat','mysql_selectdb',
      -			'mysql_select_db','mysql_result','mysql_real_escape_string','mysql_query','mysql_ping','mysql_pconnect',
      -			'mysql_numrows','mysql_numfields','mysql_num_rows','mysql_num_fields','mysql_listtables','mysql_listfields',
      -			'mysql_listdbs','mysql_list_tables','mysql_list_processes','mysql_list_fields','mysql_list_dbs','mysql_insert_id',
      -			'mysql_info','mysql_get_server_info','mysql_get_proto_info','mysql_get_host_info','mysql_get_client_info','mysql_freeresult',
      -			'mysql_free_result','mysql_fieldtype','mysql_fieldtable','mysql_fieldname','mysql_fieldlen','mysql_fieldflags',
      -			'mysql_field_type','mysql_field_table','mysql_field_seek','mysql_field_name','mysql_field_len','mysql_field_flags',
      -			'mysql_fetch_row','mysql_fetch_object','mysql_fetch_lengths','mysql_fetch_field','mysql_fetch_assoc','mysql_fetch_array',
      -			'mysql_escape_string','mysql_error','mysql_errno','mysql_dropdb','mysql_drop_db','mysql_dbname',
      -			'mysql_db_query','mysql_db_name','mysql_data_seek','mysql_createdb','mysql_create_db','mysql_connect',
      -			'mysql_close','mysql_client_encoding','mysql_affected_rows','mysql','mt_srand','mt_rand',
      -			'mt_getrandmax','move_uploaded_file','money_format','mktime','mkdir','min',
      -			'microtime','method_exists','metaphone','memory_get_usage','md5_file','md5',
      -			'mbsubstr','mbstrrpos','mbstrpos','mbstrlen','mbstrcut','mbsplit',
      -			'mbregex_encoding','mberegi_replace','mberegi','mbereg_search_setpos','mbereg_search_regs','mbereg_search_pos',
      -			'mbereg_search_init','mbereg_search_getregs','mbereg_search_getpos','mbereg_search','mbereg_replace','mbereg_match',
      -			'mbereg','mb_substr_count','mb_substr','mb_substitute_character','mb_strwidth','mb_strtoupper',
      -			'mb_strtolower','mb_strrpos','mb_strpos','mb_strlen','mb_strimwidth','mb_strcut',
      -			'mb_split','mb_send_mail','mb_regex_set_options','mb_regex_encoding','mb_preferred_mime_name','mb_parse_str',
      -			'mb_output_handler','mb_language','mb_internal_encoding','mb_http_output','mb_http_input','mb_get_info',
      -			'mb_eregi_replace','mb_eregi','mb_ereg_search_setpos','mb_ereg_search_regs','mb_ereg_search_pos','mb_ereg_search_init',
      -			'mb_ereg_search_getregs','mb_ereg_search_getpos','mb_ereg_search','mb_ereg_replace','mb_ereg_match','mb_ereg',
      -			'mb_encode_numericentity','mb_encode_mimeheader','mb_detect_order','mb_detect_encoding','mb_decode_numericentity','mb_decode_mimeheader',
      -			'mb_convert_variables','mb_convert_kana','mb_convert_encoding','mb_convert_case','max','mail',
      -			'magic_quotes_runtime','ltrim','lstat','long2ip','log1p','log10',
      -			'log','localtime','localeconv','linkinfo','link','levenshtein',
      -			'lcg_value','ksort','krsort','key_exists','key','juliantojd',
      -			'join','jewishtojd','jdtounix','jdtojulian','jdtojewish','jdtogregorian',
      -			'jdtofrench','jdmonthname','jddayofweek','is_writeable','is_writable','is_uploaded_file',
      -			'is_subclass_of','is_string','is_scalar','is_resource','is_real','is_readable',
      -			'is_object','is_numeric','is_null','is_nan','is_long','is_link',
      -			'is_integer','is_int','is_infinite','is_float','is_finite','is_file',
      -			'is_executable','is_double','is_dir','is_callable','is_bool','is_array',
      -			'is_a','iptcparse','iptcembed','ip2long','intval','ini_set',
      -			'ini_restore','ini_get_all','ini_get','ini_alter','in_array','import_request_variables',
      -			'implode','image_type_to_mime_type','ignore_user_abort','iconv_set_encoding','iconv_get_encoding','iconv',
      -			'i18n_mime_header_encode','i18n_mime_header_decode','i18n_ja_jp_hantozen','i18n_internal_encoding','i18n_http_output','i18n_http_input',
      -			'i18n_discover_encoding','i18n_convert','hypot','htmlspecialchars','htmlentities','html_entity_decode',
      -			'highlight_string','highlight_file','hexdec','hebrevc','hebrev','headers_sent',
      -			'header','gzwrite','gzuncompress','gztell','gzseek','gzrewind',
      -			'gzread','gzputs','gzpassthru','gzopen','gzinflate','gzgetss',
      -			'gzgets','gzgetc','gzfile','gzeof','gzencode','gzdeflate',
      -			'gzcompress','gzclose','gregoriantojd','gmstrftime','gmmktime','gmdate',
      -			'glob','gettype','gettimeofday','gettext','getservbyport','getservbyname',
      -			'getrusage','getrandmax','getprotobynumber','getprotobyname','getopt','getmyuid',
      -			'getmypid','getmyinode','getmygid','getmxrr','getlastmod','getimagesize',
      -			'gethostbynamel','gethostbyname','gethostbyaddr','getenv','getdate','getcwd',
      -			'getallheaders','get_resource_type','get_required_files','get_parent_class','get_object_vars','get_meta_tags',
      -			'get_magic_quotes_runtime','get_magic_quotes_gpc','get_loaded_extensions','get_included_files','get_include_path','get_html_translation_table',
      -			'get_extension_funcs','get_defined_vars','get_defined_functions','get_defined_constants','get_declared_classes','get_current_user',
      -			'get_class_vars','get_class_methods','get_class','get_cfg_var','get_browser','fwrite',
      -			'function_exists','func_num_args','func_get_args','func_get_arg','ftruncate','ftp_systype',
      -			'ftp_ssl_connect','ftp_size','ftp_site','ftp_set_option','ftp_rmdir','ftp_rename',
      -			'ftp_rawlist','ftp_quit','ftp_pwd','ftp_put','ftp_pasv','ftp_nlist',
      -			'ftp_nb_put','ftp_nb_get','ftp_nb_fput','ftp_nb_fget','ftp_nb_continue','ftp_mkdir',
      -			'ftp_mdtm','ftp_login','ftp_get_option','ftp_get','ftp_fput','ftp_fget',
      -			'ftp_exec','ftp_delete','ftp_connect','ftp_close','ftp_chdir','ftp_cdup',
      -			'ftok','ftell','fstat','fsockopen','fseek','fscanf',
      -			'frenchtojd','fread','fputs','fpassthru','fopen','fnmatch',
      -			'fmod','flush','floor','flock','floatval','filetype',
      -			'filesize','filepro_rowcount','filepro_retrieve','filepro_fieldwidth','filepro_fieldtype','filepro_fieldname',
      -			'filepro_fieldcount','filepro','fileperms','fileowner','filemtime','fileinode',
      -			'filegroup','filectime','fileatime','file_get_contents','file_exists','file',
      -			'fgetss','fgets','fgetcsv','fgetc','fflush','feof',
      -			'fclose','ezmlm_hash','extract','extension_loaded','expm1','explode',
      -			'exp','exif_thumbnail','exif_tagname','exif_read_data','exif_imagetype','exec',
      -			'escapeshellcmd','escapeshellarg','error_reporting','error_log','eregi_replace','eregi',
      -			'ereg_replace','ereg','end','easter_days','easter_date','each',
      -			'doubleval','dngettext','dl','diskfreespace','disk_total_space','disk_free_space',
      -			'dirname','dir','dgettext','deg2rad','defined','define_syslog_variables',
      -			'define','decoct','dechex','decbin','debug_zval_dump','debug_backtrace',
      -			'deaggregate','dcngettext','dcgettext','dba_sync','dba_replace','dba_popen',
      -			'dba_optimize','dba_open','dba_nextkey','dba_list','dba_insert','dba_handlers',
      -			'dba_firstkey','dba_fetch','dba_exists','dba_delete','dba_close','date',
      -			'current','ctype_xdigit','ctype_upper','ctype_space','ctype_punct','ctype_print',
      -			'ctype_lower','ctype_graph','ctype_digit','ctype_cntrl','ctype_alpha','ctype_alnum',
      -			'crypt','create_function','crc32','count_chars','count','cosh',
      -			'cos','copy','convert_cyr_string','constant','connection_status','connection_aborted',
      -			'compact','closelog','closedir','clearstatcache','class_exists','chunk_split',
      -			'chr','chown','chop','chmod','chgrp','checkdnsrr',
      -			'checkdate','chdir','ceil','call_user_method_array','call_user_method','call_user_func_array',
      -			'call_user_func','cal_to_jd','cal_info','cal_from_jd','cal_days_in_month','bzwrite',
      -			'bzread','bzopen','bzflush','bzerrstr','bzerror','bzerrno',
      -			'bzdecompress','bzcompress','bzclose','bindtextdomain','bindec','bind_textdomain_codeset',
      -			'bin2hex','bcsub','bcsqrt','bcscale','bcpow','bcmul',
      -			'bcmod','bcdiv','bccomp','bcadd','basename','base_convert',
      -			'base64_encode','base64_decode','atanh','atan2','atan','assert_options',
      -			'assert','asort','asinh','asin','arsort','array_walk',
      -			'array_values','array_unshift','array_unique','array_sum','array_splice','array_slice',
      -			'array_shift','array_search','array_reverse','array_reduce','array_rand','array_push',
      -			'array_pop','array_pad','array_multisort','array_merge_recursive','array_merge','array_map',
      -			'array_keys','array_key_exists','array_intersect_assoc','array_intersect','array_flip','array_filter',
      -			'array_fill','array_diff_assoc','array_diff','array_count_values','array_chunk','array_change_key_case',
      -			'apache_setenv','apache_response_headers','apache_request_headers','apache_note','apache_lookup_uri','apache_get_version',
      -			'apache_child_terminate','aggregation_info','aggregate_properties_by_regexp','aggregate_properties_by_list','aggregate_properties','aggregate_methods_by_regexp',
      -			'aggregate_methods_by_list','aggregate_methods','aggregate','addslashes','addcslashes','acosh',
      -			'acos','abs','_','echo', 'print', 'global', 'static', 'exit', 'array', 'empty', 'eval', 'isset', 'unset', 'die'
      -			)
      -		),
      -	'SYMBOLS' => array(
      -		'(', ')', '[', ']', '{', '}', '!', '@', '%', '&', '*', '|', '/', '<', '>'
      -		),
      -	'CASE_SENSITIVE' => array(
      -		GESHI_COMMENTS => false,
      -		1 => false,
      -		2 => false,
      -		3 => false,
      -		),
      -	'STYLES' => array(
      -		'KEYWORDS' => array(
      -			1 => 'color: #b1b100;',
      -			2 => 'color: #000000; font-weight: bold;',
      -			3 => 'color: #000066;'
      -			),
      -		'COMMENTS' => array(
      -			1 => 'color: #808080; font-style: italic;',
      -			2 => 'color: #808080; font-style: italic;',
      -			'MULTI' => 'color: #808080; font-style: italic;'
      -			),
      -		'ESCAPE_CHAR' => array(
      -			0 => 'color: #000099; font-weight: bold;'
      -			),
      -		'BRACKETS' => array(
      -			0 => 'color: #66cc66;'
      -			),
      -		'STRINGS' => array(
      -			0 => 'color: #ff0000;'
      -			),
      -		'NUMBERS' => array(
      -			0 => 'color: #cc66cc;'
      -			),
      -		'METHODS' => array(
      -			0 => 'color: #006600;'
      -			),
      -		'SYMBOLS' => array(
      -			0 => 'color: #66cc66;'
      -			),
      -		'REGEXPS' => array(
      -			0 => 'color: #0000ff;'
      -			),
      -		'SCRIPT' => array(
      -			0 => '',
      -			1 => '',
      -			2 => '',
      -			3 => ''
      -			)
      -		),
      -	'URLS' => array(
      -		1 => '',
      -		2 => '',
      -		3 => 'http://www.php.net/{FNAME}',
      -		4 => ''
      -		),
      -	'OOLANG' => true,
      -	'OBJECT_SPLITTER' => '-&gt;',
      -	'REGEXPS' => array(
      -		0 => "[\\$]{1,2}[a-zA-Z_][a-zA-Z0-9_]*"
      -		),
      -	'STRICT_MODE_APPLIES' => GESHI_MAYBE,
      -	'SCRIPT_DELIMITERS' => array(
      -		0 => array(
      -			'<?php' => '?>'
      -			),
      -		1 => array(
      -			'<?' => '?>'
      -			),
      -		2 => array(
      -			'<%' => '%>'
      -			),
      -		3 => array(
      -			'<script language="php">' => '</script>'
      -			)
      -		),
      -	'HIGHLIGHT_STRICT_BLOCK' => array(
      -		0 => true,
      -		1 => true,
      -		2 => true,
      -		3 => true
      -		)
      -);
      - 
      -?>
      - -

      If you're remotely familiar with PHP (or even if you're not), you can see that all that a language file -consists of is a glorified variable assignment. Easy! All a language file does is assign a variable $language_data. -Though still, there's a lot of indices to that array... but this section is here to break each index down -and explain it to you.

      - -

      4.2: Language File Conventions

      - - -

      There are several conventions that are used in language files. For ease of use and readability, your language -files should obey the following rules:

      - -
        -
      • Indentation is in tabs, not spaces: Use tabs! There's no excuse for using - spaces in this day and age, where almost every good editor allows you to change the tab width. Tabs also - take up less space, and ensure proper alignment. When you indent, use tabs, and if your editor converts - tabs to spaces, tell it not to.
      • -
      • Strings are in single quotes: Every string in a language file should be in single quotes ('), - unless you are specifying a single quote as a quotemark or escape character, in which case they can be in double - quotes for readability; or if you are specifying a REGEXP (see below)
      • -
      • Large arrays are multi-lined: An array with more than three or four values should be broken - into multiple lines. In any case, lines should not be wider than a full-screen window (about 100 chars per line max).
      • -
      • Ending brackets for multi-lined arrays on a new line: Also with a comma after them, unless the - array is the last one in a parent array. See the PHP language file for examples of where to use commas.
      • -
      • Use GeSHi's constants: For capatalisation, regular expressions etc. use the GeSHi constants, not - their actual values.
      • -
      - -

      There are more notes on each convention where it may appear in the language file sections below.

      - -

      4.3: Language File Sections

      - - -

      This section will look at all the sections of a language file, and how they relate to the final highlighting -result.

      - -
      4.3.1: The Header
      - - -

      The header of a language file is the first lines with the big comment and the start of the variable -$language_data:

      - -
      <?php
      -/*************************************************************************************
      - * <name-of-language-file.php>
      - * ---------------------------------
      - * Author: <name> (<e-mail address>)
      - * Copyright: (c) 2004 <name> (<website URL>)
      - * Release Version: 1.0.0
      - * CVS Revision Version: $Revision: 995 $
      - * Date Started: <date started>
      - * Last Modified: $Date: 2007-07-02 00:21:31 +1200 (Mon, 02 Jul 2007) $
      - *
      - * <name-of-language> language file for GeSHi.
      - *
      - * <any-comments...>
      - *
      - * CHANGES
      - * -------
      - * <date-of-release> (1.0.0)
      - *  -  First Release
      - *
      - * TODO (updated <date-of-release>)
      - * -------------------------
      - * <things-to-do>
      - *
      - *************************************************************************************
      - *
      - *     This file is part of GeSHi.
      - *
      - *   GeSHi is free software; you can redistribute it and/or modify
      - *   it under the terms of the GNU General Public License as published by
      - *   the Free Software Foundation; either version 2 of the License, or
      - *   (at your option) any later version.
      - *
      - *   GeSHi is distributed in the hope that it will be useful,
      - *   but WITHOUT ANY WARRANTY; without even the implied warranty of
      - *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      - *   GNU General Public License for more details.
      - *
      - *   You should have received a copy of the GNU General Public License
      - *   along with GeSHi; if not, write to the Free Software
      - *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
      - *
      - ************************************************************************************/
      -
      -$language_data = array (
      -
      - -

      The parts in angle brackets are the parts that you change for your language file. Everything -else *must* remain the same!

      - -

      Here are the parts you should change:

      - -
        -
      • <name-of-language-file.php> - This should become the name of your language file. - Language file names are in lower case and contain only alphanumeric characters, dashes and underscores. - Language files end with .php (which you should put with the name of your language file, eg language.php)
      • -
      • <name> - Your name, or alias.
      • -
      • <e-mail address> - Your e-mail address. If you want your language file included with - GeSHi you must include an e-mail address that refers to an inbox controlled by you.
      • -
      • <website> - A URL of a website of yours (perhaps to a page that deals with your - contribution to GeSHi, or your home page/blog)
      • -
      • <date-started> - The date you started working on the language file. If you can't - remember, guestimate.
      • -
      • <name-of-language> - The name of the language you made this language file for - (probably similar to the language file name).
      • -
      • <any-comments> - Any comments you have to make about this language file, perhaps - on where you got the keywords for, what dialect of the language this language file is for etc etc. - If you don't have any comments, remove the space for them.
      • -
      • <date-of-release - The date you released the language file to the public. If you simply - send it to me for inclusion in a new GeSHi and don't release it, leave this blank, and I'll replace - it with the date of the GeSHi release that it is first added to.
      • -
      - -

      Everything should remain the same, including $Revision: 995 $ and $Date: 2007-07-02 00:21:31 +1200 (Mon, 02 Jul 2007) $ (I know these may -look funny but they have their purpose for those of you who don't know about SVN).

      - -

      Also: I'm not sure about the copyright on a new language file. I'm not a lawyer, could -someone contact me about whether the copyright for a new language file should be exclusivly the authors, -or joint with me (if included in a GeSHi release)?

      - -
      4.3.2: The First Indices
      - - -

      Here is an example from the php language file of the first indices:

      - -
      	'LANG_NAME' => 'PHP',
      -	'COMMENT_SINGLE' => array(1 => '//', 2 => '#'),
      -	'COMMENT_MULTI' => array('/*' => '*/'),
      -	'CASE_KEYWORDS' => GESHI_CAPS_NO_CHANGE,
      -	'QUOTEMARKS' => array("'", '"'),
      -	'ESCAPE_CHAR' => '\\',
      - -

      The first indices are the first few lines of a language file before the KEYWORDS index. These indices specify:

      - -
        -
      • 'LANG_NAME': The name of the language. This name should be a human-readable version of the - name (e.g. HTML 4 (transitional) instead of html4trans)
      • -
      • 'COMMENT_SINGLE': An array of single-line comments in your language, indexed by integers - starting from 1. A single line comment is a comment that starts at the marker and goes until the end of the line. - These comments may be any length > 0, and since they can be styled individually, can be used for other things than - comments (for example the Java language file defines "import" as a single line comment). If you are making - a language that uses a ' (apostrophe) as a comment (or in the comment marker somewhere), use double quotes. e.g.: - "'"
      • -
      • 'COMMENT_MULTI': Used to specify multiline comments, an array in the form 'OPEN' => 'CLOSE'. - Unfortunately, all of these comments you add here will be styled the same way (an area of improvement for GeSHi 1.2.X). - These comment markers may be any length > 0.
      • -
      • 'CASE_KEYWORDS': Used to set whether the case of keywords should be changed automatically - as they are found. For example, in an SQL or BASIC dialect you may want all keywords to be upper case. The accepted - values for this are: -
          -
        • GESHI_CAPS_UPPER: Convert the case of all keywords to upper case.
        • -
        • GESHI_CAPS_LOWER: Convert the case of all keywords to lower case.
        • -
        • GESHI_CAPS_NO_CHANGE: Don't change the case of any keyword.
        • -
        -
      • 'QUOTEMARKS': Specifies the characters that mark the beginning and end of a string. This is - another example where if your language includes the ' string delimiter you should use double quotes around it.
      • -
      • 'ESCAPE_CHAR': Specifies the escape character used in all strings. If your language does not - have an escape character then make this the empty string (''). This is not an array! If found, any character - after an escape character and the escape character itself will be highlighted differently, and the character after - the escape character cannot end a string.
      • -
      - -
      4.3.3: Keywords
      - - -

      Keywords will make up the bulk of a language file. In this part you add keywords for your language, including -inbuilt functions, data types, predefined constants etc etc.

      - -

      Here's a (shortened) example from the php language file:

      - -
      	'KEYWORDS' => array(
      -		1 => array(
      -			'include', 'require', 'include_once', 'require_once',
      -			'for', 'foreach', 'as', 'if', 'elseif', 'else', 'while', 'do', 'endwhile', 'endif', 'switch', 'case', 'endswitch',
      -			'return', 'break'
      -			),
      -		2 => array(
      -			'null', '__LINE__', '__FILE__',
      -			'false', '<?php', '?>', '<?',
      -			'<script language=', '</script>',
      -			'true', 'var', 'default',
      -			'function', 'class', 'new',
      -			'__FUNCTION__', '__CLASS__', '__METHOD__', 'PHP_VERSION',
      -			'PHP_OS', 'DEFAULT_INCLUDE_PATH', 'PEAR_INSTALL_DIR', 'PEAR_EXTENSION_DIR',
      -			'PHP_EXTENSION_DIR', 'PHP_BINDIR', 'PHP_LIBDIR', 'PHP_DATADIR', 'PHP_SYSCONFDIR',
      -			'PHP_LOCALSTATEDIR', 'PHP_CONFIG_FILE_PATH', 'PHP_OUTPUT_HANDLER_START', 'PHP_OUTPUT_HANDLER_CONT',
      -			'PHP_OUTPUT_HANDLER_END', 'E_ERROR', 'E_WARNING', 'E_PARSE', 'E_NOTICE',
      -			'E_CORE_ERROR', 'E_CORE_WARNING', 'E_COMPILE_ERROR', 'E_COMPILE_WARNING', 'E_USER_ERROR',
      -			'E_USER_WARNING', 'E_USER_NOTICE', 'E_ALL'
      -			),
      -		3 => array(
      -			'zlib_get_coding_type','zend_version','zend_logo_guid','yp_order','yp_next',
      -			'yp_match','yp_master','yp_get_default_domain','yp_first','yp_errno','yp_err_string',
      -			'yp_cat','yp_all','xml_set_unparsed_entity_decl_handler','xml_set_start_namespace_decl_handler','xml_set_processing_instruction_handler','xml_set_object',
      -			'xml_set_notation_decl_handler','xml_set_external_entity_ref_handler','xml_set_end_namespace_decl_handler','xml_set_element_handler','xml_set_default_handler','xml_set_character_data_handler',
      -			'xml_parser_set_option','xml_parser_get_option','xml_parser_free','xml_parser_create_ns','xml_parser_create','xml_parse_into_struct'
      -			)
      -		),
      - -

      You can see that the index 'KEYWORDS' refers to an array of arrays, indexed by positive integers. In each array, there -are some keywords (in the actual php language file there is in fact many more keywords in the array indexed by 3). Here -are some points to note about these keywords:

      - -
        -
      • Indexed by positive integers: Use nothing else! I may change this in 1.2.X, but for the 1.0.X - series, use positive integers only.
      • -
      • Keywords sorted in reverse: Keywords *should* be sorted in reverse order. I know that - many of the language files I've made do not follow this rule, but that's because I made the files before I discovered - the following issue with GeSHi: If you have two keywords, as and ascfor example, - then when GeSHi encounters the "as" keyword it will be highlighted even if the "as" is - part of "asc". I would get GeSHi to reverse-sort keyword arrays, but there's no harm in you - doing this yourself and saving some processing time. At the least (and in fact this is sufficient) you should - swap any keywords you come across that would be caught by this issue.
      • -
      • Keywords are case sensitive (sometimes): If your language is case-sensitive, the correct - casing of the keywords is defined as the case of the keywords in these keyword arrays. If you check the java - language file you will see that everything is in exact casing. So if any of these keyword arrays are case - sensitive, put the keywords in as their correct case! (note that which groups are case sensitive and which are - not is configurable, see later on)
      • -
      • Keywords must be in htmlentities() form: All keywords should be written as if they - had been run through the php function htmlentities(). E.g, the keyword is &lt;foo&gt;, not - <foo>
      • -
      • Don't use keywords to highlight symbols: Just don't. It doesn't work, and there will be seperate - support for symbols later.
      • -
      • Markup Languages are special cases: Check the html4strict language file for an example: keywords - have to be specified twice for opening tags and twice for each closing tag.
      • -
      - -
      4.3.4: Symbols and Case Sensitivity
      - - -

      So you've put all the keywords for your language in? Now for a breather before we style them :). Symbols define -what symbols your language uses, these are things like colons, brackets/braces, and other such general punctuation (it's -important to note that in the 1.0.X series these will not be used), and case sensitivity alludes to the previous -section: here you can set which keyword groups are case sensitive.

      - -

      Here's an example:

      - -
      	'SYMBOLS' => array(
      -		'(', ')', '[', ']', '{', '}', '!', '@', '%', '&', '*', '|', '/', '<', '>'
      -		),
      -	'CASE_SENSITIVE' => array(
      -		GESHI_COMMENTS => false,
      -		1 => false,
      -		2 => false,
      -		3 => false,
      -		),
      - -
        -
      • 'SYMBOLS': An array of the symbols used in your language. Please note that in 1.0.X these - are not used. Hopefully they will be used in 1.2.X.
      • -
      • 'CASE_SENSITIVE': Note the GESHI_COMMENTS! This is used to set whether comments - are case sensitive or not (for example, BASIC has the REM statement which while not being case sensitive is still - alphanumeric, and as in the example given before about the Java language file using "import" as a single line comment, - this can be useful sometimes. true if comments are case sensitive, false otherwise. All of the other - indices correspond to indices in the 'KEYWORDS' section (see above).
      • -
      - -
      4.3.5: Styles for your Language File
      - - -

      This is the fun part! Here you get to choose the colours, fonts, backgrounds and anything else you'd like for your -language file.

      - -

      Here's an example:

      - -
      	'STYLES' => array(
      -		'KEYWORDS' => array(
      -			1 => 'color: #b1b100;',
      -			2 => 'color: #000000; font-weight: bold;',
      -			3 => 'color: #000066;'
      -			),
      -		'COMMENTS' => array(
      -			1 => 'color: #808080; font-style: italic;',
      -			2 => 'color: #808080; font-style: italic;',
      -			'MULTI' => 'color: #808080; font-style: italic;'
      -			),
      -		'ESCAPE_CHAR' => array(
      -			0 => 'color: #000099; font-weight: bold;'
      -			),
      -		'BRACKETS' => array(
      -			0 => 'color: #66cc66;'
      -			),
      -		'STRINGS' => array(
      -			0 => 'color: #ff0000;'
      -			),
      -		'NUMBERS' => array(
      -			0 => 'color: #cc66cc;'
      -			),
      -		'METHODS' => array(
      -			0 => 'color: #006600;'
      -			),
      -		'SYMBOLS' => array(
      -			0 => 'color: #66cc66;'
      -			),
      -		'REGEXPS' => array(
      -			0 => 'color: #0000ff;'
      -			),
      -		'SCRIPT' => array(
      -			0 => '',
      -			1 => '',
      -			2 => '',
      -			3 => ''
      -			)
      -		),
      - -

      Note that all style rules should end with a semi-colon! This is important: GeSHi may add extra rules to the rules -you specify (and will do so if a user tries to change your styles on the fly), so the last semi-colon in any stylesheet -rule is important.

      - -

      All strings here should contain valid stylesheet declarations (it's also find to have the empty string).

      - -
        -
      • 'KEYWORDS': This is an array, from keyword index to style. The index you use is the index - you used in the keywords section to specify the keywords belonging to that group.
      • -
      • 'COMMENTS': This is an array, from single-line comment index to style for that index. The - index 'MULTI' is used for multiline comments (and cannot be an array)
      • -
      • 'ESCAPE_CHAR' down to 'REGEXPS': These are arrays with only one index: 0. You cannot add other indices to - these arrays.
      • -
      • 'SCRIPT': For languages that use script delimiters, this is where you can style each block - of script. For example, HTML and XML have blocks that begin with < and end with > (i.e. tags) and blocks - that begin with & and end with ; (i.e. character entities), and you can set a style to apply to each whole - block. You specify the delimiters for the blocks below. Note that many languages will not need this feature.
      • -
      - -
      4.3.6: URLs for Functions
      - - -

      This section lets you specify a url to visit for each keyword group. Useful for pointing functions at their -online manual entries.

      - -

      Here is an example:

      - -
      	'URLS' => array(
      -		1 => '',
      -		2 => '',
      -		3 => 'http://www.php.net/{FNAME}',
      -		4 => ''
      -		),
      - -

      The indices of this array correspond to the keyword groups you specified in the keywords section. The string {FNAME} -marks where the name of the function is substituted in. So for the example above, if the keyword being highlighted is "echo", -then the keyword will be a URL pointing to http://www.php.net/echo. Because some languages (Java!) don't keep a -uniform URL for functions/classes, you may have trouble in creating a URL for that language (though look in the java language -file for a novel solution to it's problem)

      - -
      4.3.7: Object Orientation Support
      - - -

      Now we're reaching the most little-used section of a language file, which includes such goodies as object orientation -support and context support. GeSHi can highlight methods and data fields of objects easily, all you need to do is to -tell it to do so and what the "splitter" is between object/method etc.

      - -

      Here's an example:

      - -
      	'OOLANG' => true,
      -	'OBJECT_SPLITTER' => '->',
      - -

      If your language has object orientation, the value of 'OOLANG' is true, otherwise it is false. If it is -object orientated, in the 'OBJECT_SPLITTER' value you put the htmlentities() version of the "splitter" -between objects and methods/fields. If it is not, then make this the empty string.

      - -
      4.3.8: Using Regular Expressions
      - - -

      Regular expressions are a good way to catch any other lexic that fits certain rules but can't be listed as a keyword. -A good example is variables in PHP: variables always start with either one or two "$" signs, then alphanumeric -characters (a simplification). This is easy to catch with regular expressions.

      - -

      And new to version 1.0.2, there is an advanced way of using regular expressions to catch certain things but highlight -only part of those things. This is particularly useful for languages like XML.

      - -
      Caution:

      Regular expressions use the PCRE syntax (perl-style), not the ereg() style!

      - -

      Here is an example (this time the PHP file merged with the XML file):

      - -
      		0 => array(
      -			GESHI_SEARCH => '(((xml:)?[a-z\-]+))(=)',
      -			GESHI_REPLACE => '\\1',
      -			GESHI_MODIFIERS => '',
      -			GESHI_BEFORE => '',
      -			GESHI_AFTER => '\\4'
      -			),
      -		1 => array(
      -			GESHI_SEARCH => '(</?[a-z0-9]*(>)?)',
      -			GESHI_REPLACE => '\\1',
      -			GESHI_MODIFIERS => '',
      -			GESHI_BEFORE => '',
      -			GESHI_AFTER => ''
      -			),
      -		2 => "[\\$]{1,2}[a-zA-Z_][a-zA-Z0-9_]*"
      - -

      As you can see there are two formats. One is the "simple" format used in GeSHi < 1.0.2, and the other -is a more advanced syntax. Firstly, the simple syntax:

      - -
        -
      • May be in double quotes: To make it easier for those who always place their regular expressions - in double quotes, you may place any regular expression here in double quotes if you wish.
      • -
      • Don't use curly brackets where possible: If you want to use curly brackets (()) then - by all means give it a try, but I'm not sure whether under some circumstances GeSHi may throw a wobbly. You have - been warned! If you want to use brackets, it would be better to use the advanced syntax.
      • -
      • Don't use the "everything" regex: (That's the .*? regex). Use advanced - syntax instead.
      • -
      - -

      And now for advanced syntax, which gives you much more control over exactly what is highlighted:

      - -
        -
      • GESHI_SEARCH: This element specifies the regular expression to search for. If you plan - to capture the output, use brackets (()). See how in the first example above, most of the regular - expression is in one set of brackets (with the equals sign in other brackets). You should make sure that the - part of the regular expression that is supposed to match what is highlighted is in brackets.
      • -
      • GESHI_REPLACE: This is what the stuff matched by the regular expression will be replaced - with. If you've grouped the stuff you want highlighted into brackets in the GESHI_SEARCH element, then you can - use \\number to match that group, where number is a number corresponding to how many open brackets - are between the open bracket of the group you want highlighted and the start of the GESHI_SEARCH string + 1. This - may sound confusing, and it probably is, but if you're familiar with how PHP's regular expressions work you - should understand. In the example above, the opening bracket for the stuff we want highlighted is the very first - bracket in the string, so the number of brackets before that bracket and the start of the string is 0. So we add - 1 and get our replacement string of \\1 (whew!).
         
        If you - didn't understand a word of that, make sure that there are brackets around the string in GESHI_SEARCH and use - \\1 for GESHI_REPLACE ;)
      • -
      • GESHI_MODIFIERS: Specify modifiers for your regular expression. If your regular expression includes - the everything matcher (.*?), then your modifiers should include "s" and "i" (e.g. use - 'si' for this).
      • -
      • GESHI_BEFORE:Specifies a bracket group that should appear before the highlighted match (this - bracketed group will not be highlighted). Use this if you had to match what you wanted by matching part of your - regexp string to something before what you wanted to highlight, and you don't want that part to disappear in - the highlighted result.
      • -
      • GESHI_AFTER:Specifies a bracket group that should appear after the highlighted match (this - bracketed group will not be highlighted). Use this if you had to match what you wanted by matching part of your - regexp string to something after what you wanted to highlight, and you don't want that part to disappear in - the highlighted result.
      • -
      - -

      Is that totally confusing? Here's the test for if you're an android or not: If you found that perfectly understandable -then you're an android ;). Here's a better example:

      - -

      Let's say that I'm making a language, and variables in this language always start with a dollar sign ($), are always -written in lowercase letters and always end with an ampersand (&). eg:

      - -$foo& = 'bar' - -

      I want to highlight only the text between the $ and the &. How do I do that? With simple regular -expressions I can't, but with advanced, it's relatively easy:

      - -
      		1 => array(
      -			GESHI_SEARCH => '(\$)([a-z]+)(&)',   // search for a dollar sign, then one or more of the characters a-z, then an ampersand
      -			GESHI_REPLACE => '\\2',                  // we wanna highlight the characters, which are in the second bracketed group
      -			GESHI_MODIFIERS => '',                   // no modifiers, since we're not matching the "anything" regex
      -			GESHI_BEFORE => '\\1',                   // before the highlighted characters should be the first bracketed group (always a dollar sign in this example)
      -			GESHI_AFTER => '\\3'                     // after the highlighted characters should be the third bracketed group (always an ampersand in this example)
      -			),
      - -

      So if someone tried to highlight using my language, all cases of $foo& would turn into:

      - -$<span style="color: blue;">foo</span>& - -

      (which would of course be viewed in a browser to get something like $foo&)

      - -
      4.3.9: Contextual Highlighting and Strict Mode
      - - -

      For languages like HTML, it's good if we can highlight a tag (like <a> for example). But how do we stop -every single "a" in the source getting highlighted? What about for attributes? If I've got the word -"colspan" in my text I don't want that highlighted! So how do you tell GeSHi not to highlight in that -case? You do it with "Strict Blocks".

      - -

      Here is an example:

      - -
      	'STRICT_MODE_APPLIES' => GESHI_MAYBE,
      -	'SCRIPT_DELIMITERS' => array(
      -		0 => array(
      -			'<?php' => '?>'
      -			),
      -		1 => array(
      -			'<?' => '?>'
      -			),
      -		2 => array(
      -			'<%' => '%>'
      -			),
      -		3 => array(
      -			'<script language="php">' => '</script>'
      -			)
      -		),
      -	'HIGHLIGHT_STRICT_BLOCK' => array(
      -		0 => true,
      -		1 => true,
      -		2 => true,
      -		3 => true
      -		)
      - -

      What is strict mode? Strict mode says that highlighting only occurs inside the blocks you specify. You can see from -the example above that highlighting will only occur if the source is inside <?php ... ?> (though note the GESHI_MAYBE!). -Here are some points about strict highlighting:

      -
        -
      • 'STRICT_MODE_APPLIES': This takes three values (all constants): -
          -
        • GESHI_ALWAYS: Strict mode always applies for all of the blocks you specify. Users of - your language file cannot turn strict mode off. This should be used for markup languages.
        • -
        • GESHI_NEVER: Strict mode is never used. Users of your language file cannot turn strict mode - on. Use this value if there is no such thing as a block of code that would not be highlighted in - your language (most languages, like C, Java etc. use this because anything in a C file should be highlighted).
        • -
        • GESHI_MAYBE: Strict mode *sometimes* applies. It defaults to "off". Users can turn - strict mode on if they please. If strict mode is off then everything in the source will be highlighted, even - things outside the strict block markers. If strict mode is on the nothing outside strict block markers will - be highlighted.
        • -
        -
      • SCRIPT_DELIMITERS: This is an array of script delimiters, in the format of the above. The indices are - use in the 'SCRIPT' part of the styles section for highlighting everything in a strict block in a certain way. For example, - you could set up your language file to make the background yellow of any code inside a strict block this way. The delimiters - are in the form 'OPEN' => 'CLOSE'. Delimiters can be of any length > 0. Delimiters are not formatted as if they - were run through htmlentities()!
      • -
      • 'HIGHLIGHT_STRICT_BLOCK': specifies whether any highlighting should go on inside each block. Most - of the time this should be true, but for example, in the XML language file highlighting is turned off for blocks beginning - with <!DOCTYPE and ending with >. However, you can still style the overall block using the method described above, - and the XML language file does just that.
      • -
      - -
      Note:

      The delimiters should be in reverse alphabetical order. Note that in the above example, -<?php comes before <?.

      - -

      4.3.10: Tidying Up

      - - -

      All language files should end with:

      - -
      );
      -
      -?>
      - - -

      5: Method/Constant Reference

      - - -

      I'm afraid I have been lying for a little while about this now! Since 1.0.7 I have been including a phpdoc API for -the sourcecode in the api directory, but have forgot to update the documentation! However, it is -available, and may assist you in coding, especially for plugin coders.

      - -
      - -

      That's all, folks!

      - -

      I've improved the documentation greatly from version 1.0.1, but there may still be -problems with it, or it may still be confusing for you. Or perhaps I was just plain -wrong about one point! If so, contact me and I'll do my best to sort it out.

      - -

      In case you were wondering, I've finished development of the 1.0.X thread of -GeSHi. The only releases I'll make in this thread will be of the bug-fix/add language files -type. In particular, version 1.0.2 was a "concept" release - testing how -far I could take the highlighting idea (as well as ideas from others).

      - -

      I'm planning a code rewrite for 1.2.X, which will be based on a new engine - a -"psuedo-tokenizer" engine. Hopefully it will massively reduce the server -load and time taken (by almost eliminating regexps), while providing superior -highlighting. But fear not! The interface and method names should all remain the -same ^_^ (though I can't say the same for language files!)

      - -

      And finally, a couple of people have been asking me: how did you generate that documentation? -The amazing answer is: my brain. And yes, it took a long time, and I don't reccommend doing it this -way. And yes, you can borrow the styles if you like, though flick me an e-mail if you do.

      - -

      Anyway, enough blather from me. Get GeSHi working for you already! :D

      - -
      Nigel McNie
      -nigel@geshi.org
      -http://qbnz.com/highlighter/
      - - - diff --git a/htdocs/application/libraries/geshi/docs/geshi-doc.txt b/htdocs/application/libraries/geshi/docs/geshi-doc.txt deleted file mode 100755 index 9587021..0000000 --- a/htdocs/application/libraries/geshi/docs/geshi-doc.txt +++ /dev/null @@ -1,1694 +0,0 @@ -[NOTE: This documentation has simply been copy-pasted from the HTML form and is NOT up to date, I recommend you -read that instead] - -GeSHi Documentation -Version 1.0.7.20 - -Author: Nigel McNie -Copyright: � 2004 - 2007, Nigel McNie -Email: nigel@geshi.org -GeSHi Website: http://qbnz.com/highlighter - -This is the documentation for GeSHi - Generic Syntax Highlighter. The most modern version of this document is available on the web - go to http://qbnz.com/highlighter/documentation.php to view it. - -Any comments, questions, confusing points? Please contact me! I need all the information I can get to make the use of GeSHi and everything related to it (including this documentation) a breeze. -Contents - - * 1. Introduction - o 1.1 Features - o 1.2 About GeSHi - o 1.3 Credits - o 1.4 Feedback - * 2. The Basics - o 2.1 Getting GeSHi - o 2.2 Installing GeSHi - + 2.2.1 Requirements - + 2.2.2 Extracting GeSHi - + 2.2.3 Installation - o 2.3 Basic Usage - * 3. Advanced Features - o 3.1 The Code Container - o 3.2 Line Numbers - + 3.2.1 Enabling Line Numbers - + 3.2.2 Styling Line Numbers - + 3.2.3 Choosing a Start Number - o 3.3 Using CSS Classes - + 3.3.1 Enabling CSS Classes - + 3.3.2 Setting the CSS Class/ID - + 3.3.3 Getting the Stylesheet - + 3.3.4 Using an External Stylesheet - o 3.4 Changing Styles - + 3.4.1 The Overall Styles - + 3.4.2 Line Number Styles - + 3.4.3 Setting Keyword Styles - + 3.4.4 Setting Comment Styles - + 3.4.5 Setting Other Styles - o 3.5 Case Sensitivity and Auto Casing - + 3.5.1 Auto Caps/Nocaps - + 3.5.2 Setting Case Sensitivity - o 3.6 Changing the Source/Language/Path/Charset - + 3.6.1 Changing the Source Code - + 3.6.2 Changing the Language - + 3.6.3 Changing the Path - + 3.6.4 Changing the Character Set - + 3.6.5 Using load_from_file to change the language and source code - o 3.7 Error Handling - o 3.8 Disabling Styling of Some Lexics - o 3.9 Setting the Tab Width - o 3.10 Using Strict Mode - o 3.11 Adding/Removing Keywords - + 3.11.1 Adding a Keyword - + 3.11.2 Removing a Keyword - + 3.11.3 Adding a Keyword Group - + 3.11.4 Removing a Keyword Group - o 3.12 Headers and Footers for your code - + 3.12.1 Keyword Substitution - + 3.12.2 Setting Header Content - + 3.12.3 Setting Footer Content - + 3.12.4 Styling Header Content - + 3.12.5 Styling Footer Content - o 3.13 Keyword URLs - + 3.13.1 Setting a URL for a Keyword Group - + 3.13.2 Disabling URLs for a Keyword Group - + 3.13.3 Disabling all URLs for Keywords - + 3.13.4 Styling Links - + 3.13.5 Setting the Link Target - o 3.14 Using Contextual Importance - o 3.15 Highlighting Special Lines "Extra" - + Specifying the Lines to Highlight Extra - + Styles for the Highlighted Lines - o 3.16 Adding IDs to Each Line - o 3.17 Getting the Time of Styling - * 4 Language Files - o 4.1 An Example Language File - o 4.2 Language File Conventions - o 4.3 Language File Sections - + 4.3.1 The Header - + 4.3.2 The First Indices - + 4.3.3 Keywords - + 4.3.4 Symbols and Case Sensitivity - + 4.3.5 Styles for your Language Files - + 4.3.6 URLs for Functions - + 4.3.7 Object Orientation Support - + 4.3.8 Using Regular Expressions - + 4.3.9 Contextual Highlighting and Strict Mode - + 4.3.10 Tidying Up - * 5 Method/Constant Reference - -1: Introduction -Top | Contents | Next | Previous - -GeSHi is exactly what the acronym stands for: a Generic Syntax Highlighter. As long as you have a language file for almost any computer language - whether it be a scripting language, object orientated, markup or anything in between - GeSHi can highlight it! GeSHi is extremely customisable - the same source can be highlighted multiple times in multiple ways - the same source even with a different language. GeSHi outputs XHTML strict compliant code*, and can make use of CSS to save on the amount of output. And what is the cost for all of this? You need PHP. That's all! - -*Most of the time. Some languages do not output XHTML strict code, and using line numbers with the PRE header is not legal either. These problems will be fixed in 1.2. -1.1: Features -Top | Contents | Next | Previous - -Here are some of the standout features of GeSHi: - - * Programmed in PHP: GeSHi is coded entirely in PHP. This means that where ever you have PHP, you can have GeSHi! Almost any free webhost supports PHP, and GeSHi works fine with PHP > 4.1.0. - * Support for many languages: GeSHi comes with over 50 languages, including PHP, HTML, CSS, Java, C, Lisp, XML, Perl, Python, ASM and many more! - * XHTML compliant output: GeSHi produces XHTML compliant output, using stylesheets, so you need not worry about GeSHi ruining your claims to perfection in the standards department ;) - * Highly customisable: GeSHi allows you to change the style of the output on the fly, use CSS classes or not, use an external stylesheet or not, use line numbering, change the case of output keywords... the list goes on and on! - * Flexible: Unfortunately, GeSHi is quite load/time intensive for large blocks of code. However, you want speed? Turn off any features you don't like, pre-make a stylesheet and use CSS classes to reduce the amount of output and more - it's easy to strike a balance that suits you. - -This is just a taste of what you get with GeSHi - the best syntax highlighter for the web in the world! -1.2: About GeSHi -Top | Contents | Next | Previous - -GeSHi started as a mod for the phpBB forum system, to enable highlighting of more languages than the available (which was 0 ;)). However, it quickly spawned into an entire project on its own. But now it has been released, work continues on a mod for phpBB* - and hopefully for many forum systems, blogs and other web-based systems. - -*I am no longer working on this MOD, however if someone else wants to they can contact me for more information. - -Several systems are using GeSHi now, including: - - * Dokuwiki - An advanced wiki engine - * gtk.php.net - Their manual uses GeSHi for syntax highlighting - * WordPress - A powerful blogging system* - * PHP-Fusion - A constantly evovling CMS - * SQL Manager - A Postgres DBAL - * Mambo - A popular open source CMS - * MediaWiki - A leader in Wikis* - * TikiWiki - A megapowerful Wiki/CMS - * TikiPro - Another powerful Wiki based on Tikiwiki - * RWeb - A site-building tool - -* Available as plugin only. In addition, some of the other entries mentioned here may only have GeSHi available as a plugin. - -GeSHi is the work of me, Nigel McNie. Others have helped with aspects of GeSHi also, they're mentioned in the THANKS file. -1.3: Credits -Top | Contents | Next | Previous - -Many people have helped out with GeSHi, whether by creating language files, submitting bug reports, suggesting new ideas or simply pointing out a new idea or something I'd missed. All of these people have helped to build a better GeSHi, you can see them in the THANKS file. - -Do you want your name on this list? Why not make a language file, or submit a valid bug? Or perhaps help me with an added feature I can't get my head around, or suggest a new feature, or even port GeSHi to anothe language? There's lots you can do to help out, and I need it all :) -1.4: Feedback -Top | Contents | Next | Previous - -I need your feedback! ANYthing you have to say is fine, whether it be a query, congratulations, a bug report or complaint, I don't care! I want to make this software the best it can be, and I need your help! You can contact me in the following ways: - - * E-mail: nigel@geshi.org - * Forums: Sourceforge.net Forums or GeSHi home forums - -Remember, any help I am grateful for :) -2: The Basics -Top | Contents | Next | Previous - -In this section, you'll learn a bit about GeSHi, how it works and what it uses, how to install it and how to use it to perform basic highlighting. -2.1: Getting GeSHi -Top | Contents | Next | Previous - -If you're reading this and don't have GeSHi, that's a problem ;). So, how do you get your hands on it? Visit http://qbnz.com/highlighter/downloads.php to obtain the latest version. -2.2: Installing GeSHi -Top | Contents | Next | Previous - -Installing GeSHi is a snap, even for those most new to PHP. There's no tricks involved. Honest! -2.2.1: Requirements -Top | Contents | Next | Previous - -GeSHi requires the following to be installable: - - * PHP. It's untested with anything other than 4.3.X. I hope to extend this range soon. I see no reason why it won't work with any version of PHP above 4.1.0. - * Approximately 700 kilobytes of space. The actual script is small - around 85K - but most of the size comes from the large number of language files (over 50!). If you're pushed for space, make sure you don't upload to your server the docs/ or contrib/ directory, and you may want to leave out any language files that don't take your fancy either. - -As you can see, the requirements are very small. If GeSHi does NOT work for you in a particular version of PHP, let me know why and I'll fix it. - -Packages come in .zip, .tar.gz and .tar.bz2 format, so there's no complaining about whether it's available for you. *nix users probably want .tar.gz or .tar.bz2 and windows users probably want .zip. -2.2.2: Extracting GeSHi -Top | Contents | Next | Previous - -To extract GeSHi in Linux (.tar.gz): - - 1. Open a shell - 2. cd to the directory where the archive lies - 3. Type tar -xzvf [filename] where [filename] is the name of the archive (typically GeSHi-1.X.X.tar.gz) - 4. GeSHi will be extracted to its own directory - -To extract GeSHi in Windows (.zip): - - 1. Open Explorer - 2. Navigate to the directory where the archive lies - 3. Extract the archive. The method you use will depend on your configuration. Some people can right-click upon the archive and select "Extract" from there, others may have to drag the archive and drop it upon an extraction program. - -To extract from .zip you'll need an unzipping program - unzip in Linux, or Winzip, Winrar or similar for Windows. -2.2.3: Installation -Top | Contents | Next | Previous - -GeSHi is nothing more than a PHP class with related language support files. Those of you familiar with PHP can then guess how easy the installation will be: simply copy it into your include path somewhere. You can put it wherever you like in this include path. I recommend that you put the language files in a subdirectory of your include path too - perhaps the same subdirectory that geshi.php is in. Remember this path for later. - -If you don't know what an include path is, don't worry. Simply copy GeSHi to your webserver. So for example, say your site is at http://mysite.com/myfolder, you can copy GeSHi to your site so the directory structure is like this: - -http://mysite.com/myfolder/geshi/[language files] -http://mysite.com/myfolder/geshi.php - -Or you can put it in any subdirectory you like: - -http://mysite.com/myfolder/includes/geshi/[language files] -http://mysite.com/myfolder/includes/geshi.php - -Caution: - -When using GeSHi on a live site, the only directory required is the geshi/ subdirectory. Both contrib/ and docs/ are worthless, and furthermore, as some people discovered, one of the files in contrib had a security hole (fixed as of 1.0.7.3). I suggest you delete these directories from any live site they are on. -2.3: Basic Usage -Top | Contents | Next | Previous - -Use of GeSHi is very easy. Here's a simple example: -// -// Include the GeSHi library -// -include_once('geshi.php'); - -// -// Define some source to highlight, a language to use -// and the path to the language files -// -$source = '$foo = 45; -for ( $i = 1; $i < $foo; $i++ ) -{ - echo "$foo
      \n"; - --$foo; -}'; -$language = 'php'; -// -// Create a GeSHi object -// -$geshi =& new GeSHi($source, $language); - -// -// And echo the result! -// -echo $geshi->parse_code(); - -As you can see, there's only three really important lines: -include_once('geshi.php'); - -This line includes the GeSHi class for use -$geshi = new GeSHi($source, $language); - -This line creates a new GeSHi object, holding the source and the language you want to use for highlighting. -echo $geshi->parse_code(); - -This line spits out the result :) - -So as you can see, simple usage of GeSHi is really easy. Just create a new GeSHi object and get the code! - -Since version 1.0.2, there is a function included with GeSHi called geshi_highlight. This behaves exactly as the php function highlight_string behaves - all you do is pass it the language you want to use to highlight and the path to the language files as well as the source. Here are some examples: -// Simply echo the highlighted code -geshi_highlight($source, 'php', $path); - -// Get the code back, for use later -$code = geshi_highlight($source, 'java', $path, true) - -// Check if there is an error with parsing this code -ob_start(); -$result = geshi_highlight($source, 'perl', $path); -$code = ob_get_contents(); -ob_end_clean(); -if ( !$result ) -{ - // There was an error with highlighting... -} -else -{ - // All OK :) -} - -However, these are really simple examples and doesn't even begin to cover all the advanced features of GeSHi. If you want to learn more, continue on to section 3: Advanced Features. -3: Advanced Features -Top | Contents | Next | Previous - -This section documents the advanced features of GeSHi - strict mode, using CSS classes, changing styles on the fly, disabling highlighting of some things and more. - -In this section there are many code snippets. For all of these, you should assume that the GeSHi library has been included, and a GeSHi object has been created and is referenced by the variable $geshi. Normally, the source, language and path used are arbitary. -3.1 The Code Container -Top | Contents | Next | Previous - -The Code Container has a fundamental effect on the layout of your code before you even begin to style. What is the Code Container? It's the bit of markup that goes around your code to contain it. By default your code is surrounded by a
      , but you can also specify a 
      . - -The
       header is the default. If you're familiar with HTML you'll know that whitespace is rendered "as is" by a 
       element. The advantage for you is that if you use 
       the whitespace you use will appear pretty much exactly how it is in the source, and what's more GeSHi won't have to add a whole lot of 
      's and non-breaking spaces ( ) to your code to indent it. This saves you source code (and your valuable visitors waiting time and your bandwidth). - -But if you don't like
       or it looks stupid in your browser no matter what styles you try to apply to it or something similar, you might want to use a 
      instead. A
      will result in more source - GeSHi will have to insert whitespace markup - but in return you can wrap long lines of code that would otherwise have your browser's horizontal scrollbar appear. Of course with
      you can *not* wrap lines if you please. The highlighter demo at the GeSHi home page uses the
      approach for this reason. - -At this stage there isn't an option to wrap the code in tags (unless you use the function geshi_highlight), partly because of the inconsistent and unexpected ways stuff in tags is highlighted. Besides, is an inline element. But this may become an option in future versions. - -As of GeSHi 1.0.7.2 there is a new header type, that specifies that the code should not be wrapped in anything at all. - -To change/set the header to use, you call the set_header_type() method: -$geshi->set_header_type(GESHI_HEADER_DIV); -// or... -$geshi->set_header_type(GESHI_HEADER_PRE); // or... -$geshi->set_header_type(GESHI_HEADER_NONE); - -Those are the only three arguments you should pass to set_header_type. Passing anything else may cause inconsistencies in what is used as the Code Container (although it *should* simply use a
      ). Better not to risk it.
      -Note:
      -
      -GESHI_HEADER_DIV, GESHI_HEADER_PRE and GESHI_HEADER_NONE are constants, so don't put them in strings!
      -Caution:
      -
      -The default styles for the 
       and 
      will be different, especially if you use line numbers!. I have found that a
       results in code that is smaller than for that of a 
      , you should rectify this difference by using set_overall_style() if you need to. But be aware of this difference for if you are changing the header type! -3.2: Line Numbers -Top | Contents | Next | Previous - -GeSHi has the ability to add line numbers to your code (see the demo available at http://qbnz.com/highlighter/demo.php to see what can be achieved). Line numbers are a great way to make your code look professional, especially if you use the fancy line numbers feature. -3.2.1: Enabling Line Numbers -Top | Contents | Next | Previous - -To highlight a source with line numbers, you call the enable_line_numbers() method: -$geshi->enable_line_numbers($flag); - -Where $flag is one of the following: - - * GESHI_NORMAL_LINE_NUMBERS - Use normal line numbering - * GESHI_FANCY_LINE_NUMBERS - Use fancy line numbering - * GESHI_NO_LINE_NUMBERS - Disable line numbers (default) - -Normal line numbers means you specify a style for them, and that style gets applied to all of them. Fancy line numbers means that you can specify a different style for each nth line number. You change the value of n (default 5): -$geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 37); - -The second parameter is not used in any other mode. Setting it to 0 is the same as simply using normal line numbers. Setting it to 1 applies the fancy style to every line number. -Note: - -The values above are CONSTANTS - so don't put them in strings! -3.2.2 Styling Line Numbers -Top | Contents | Next | Previous - -As of GeSHi 1.0.2, line numbers are added by the use of ordered lists. This solves the old issues of line number styles inheriting from styles meant for the code. Also, this solves an important issue about selecting code. For example, line numbers look nice, but when you go to select the code in your browser to copy it? You got the line numbers too! Not such a good thing, but thankfully this issue is now solved. What is the price? Unfortunately the whole way that styles are inherited/used has changed for those of you who were familiar with 1.0.1, and there is quite a bit more HTML involved. So think carefully about these things before you enable line numbers. - -Now, onto how to style line numbers: - -Styles are set for line numbers using the set_line_style() method: -$geshi->set_line_style('background: #fcfcfc;'); - -If you're using Fancy Line Numbers mode, you pass a second string for the style of the nth line number: -$geshi->set_line_style('background: #fcfcfc;', 'background: #f0f0f0;'); - -The second style will have no effect if you're not using Fancy Line Numbers mode. - -By default, the styles you pass overwrite the current styles. Add a boolean "true" after the styles you specify to combine them with the current styles: -$geshi->set_line_style('background: red;', true); -// or, for fancy line numbers -$geshi->set_line_style('background: red;', 'background: blue;', true); -Caution: - -When you set line number styles, the code will inherit those styles! This is the main issue to come out of the 1.0.2 release. If you want your code to be styled in a predictable manner, you'll have to call the set_code_style() method to rectify this problem. - -Note also that you cannot apply background colours to line numbers unless you use set_overall_style(). Here's how you'd style: - - 1. Use set_overall_style() to style the overall code block. For example, you can set the border style/colour, any margins and padding etc. using this method. In addition: set the background colour for all the line numbers using this method. - 2. Use set_line_style() to style the foreground of the line numbers. For example, you can set the colour, weight, font, padding etc. of the line numbers using this method. - 3. Use set_code_style() to explicitly override the styles you set for line numbers using set_line_style. For example, if you'd set the line numbers to be bold (or even if you'd only set the fancy line number style to be bold), and you didn't actually want your code to be bold, you'd make sure that font-weight: normal; was in the stylesheet rule you passed to set_code_style - -This is the one major change from GeSHi 1.0.1 - make sure you become familiar with this, and make sure that you check any code you have already styled with 1.0.1 when you upgrade to make sure nothing bad happens to it. -3.2.3: Choosing a Start Number -Top | Contents | Next | Previous - -As of GeSHi 1.0.2, you can now make the line numbers start at any number, rather than just 1. This feature is useful if you're highlighting code from a file from around a certain line number in that file, as an additional guide to those who will view the code. You set the line numbers by calling the start_line_numbers_at() method: -$geshi->start_line_numbers_at($number); - -$number must be a positive integer (or zero). If it is not, GeSHi will convert it anyway. - -If you have not enabled line numbers, this will have no effect. -Caution: - -Although I'd like GeSHi to have XHTML strict compliance, this feature will break compliancy (however transitional compliancy remains). This is because the only widely supported way to change the start value for line numbers is by using the start="number" attribute of the
        tag. Although CSS does provide a mechanism for doing this, it is only supported in Opera versions 7.5 and above (not even Firefox supports this). -3.3: Using CSS Classes -Top | Contents | Next | Previous - -Using CSS to highlight your code instead of in-lining the styles is a definate bonus. Not only is it more compliant (the w3c is deprecating the style attribute in XHTML 2.0) but it results in far less outputted code - up to a whopping 50% saving - which makes a *huge* difference to those of us on modems! -3.3.1: Enabling CSS Classes -Top | Contents | Next | Previous - -By default, GeSHi doesn't use the classes, so it's easy just to whack out some highlighted code if you need without worrying about stylesheets. However, if you're a bit more organised about it, you should use the classes ;). To turn the use of classes on, you call the enable_classes() method: -$geshi->enable_classes(); - -If you want to turn classes OFF for some reason later: -$geshi->enable_classes(false); - -If classes are enabled when parse_code() is called, then the resultant source will use CSS classes in the output, otherwise it will in-line the styles. The advantages of using classes are great - the reduction in source will be very noticeable, and what's more you can use one stylesheet for several different highlights on the same page. In fact, you can even use an external stylesheet and link to that, saving even more time and source (because stylesheets are cached by browsers). -Caution: - -This should be the very first method you call after creating a new GeSHi object! That way, various other methods can act upon your choice to use classes correctly. In theory, you could call this method just before parsing the code, but this may result in unexpected behaviour. -3.3.2: Setting the CSS class and ID -Top | Contents | Next | Previous - -You can set an overall CSS class and id for the code. This is a good feature that allows you to use the same stylesheet for many different snippets of code. You call set_overall_class() and set_overall_id to accomplish this: -$geshi->set_overall_class('mycode'); -$geshi->set_overall_id('dk48ck'); - -The default classname is the name of the language being used. This means you can use just the one stylesheet for all sources that use the same language, and incidentally means that you probably won't have to call these methods too often. - -CSS IDs are supposed to be unique, and you should use them as such. Basically, you can specify an ID for your code and then use that ID to highlight that code in a unique way. You'd do this for a block of code that you expressly wanted to be highlighted in a different way (see the section below on gettting the stylesheet for your code for an example). -3.3.3: Getting the stylesheet for your code -Top | Contents | Next | Previous - -The other half of using CSS classes is getting the stylesheet for use with the classes. GeSHi makes it very easy to get a stylesheet for your code, with one easy method call: -$geshi->enable_classes(); - -// Here we have code that will spit out a header for -// a stylesheet. For example: - -echo ' -Code - -'; - -The get_stylesheet() method gets the stylesheet for your code in one easy call. All you need to do is output it in the correct place. As you can also see, you don't even have to enable class usage to get the stylesheet nessecary either - however not enabling classes but using the stylesheet may result in problems later. - -By default, get_stylesheet() tries to echo the least amount of code possible. Although currently it doesn't check to see if a certain lexic is even in the source, you can expect this feature in the future. At least for the present however, if you explicitly disable the highlighting of a certain lexic, or disable line numbers, the related CSS will not be outputted. This may be a bad thing for you perhaps you're going to use the stylesheet for many blocks of code, some with line numbers, others with some lexic enabled where this source has it disabled. Or perhaps you're building an external stylesheet and want all lexics included. So to get around this problem, you do this: -$geshi->get_stylesheet(false); - -This turns economy mode off, and all of the stylesheet will be outputted regardless. - -Now lets say you have several snippets of code, using the same language. In most of them you don't mind if they're highlighted the same way (in fact, that's exactly what you want) but in one of them you'd like the source to be highlighted differently. Here's how you can do that: -// assume path is the default "geshi/" relative to the current directory -$geshi1 = new GeSHi($source1, $lang); -$geshi2 = new GeSHi($source2, $lang); -$geshi3 = new GeSHi($source3, $lang); - -// Turn classes on for all sources -$geshi1->enable_classes(); -$geshi2->enable_classes(); -$geshi3->enable_classes(); - -// Make $geshi3 unique -$geshi3->set_overall_id('different'); - -// -// Methods are called on $geshi3 to change styles... -// - -echo ' -Code - -'; - - -echo 'Code snippet 1:'; -echo $geshi1->parse_code(); -echo 'Code snippet 2 (same highlighting as 1):'; -echo $geshi2->parse_code(); -echo 'Code snippet 3 (DIFFERENT highlighting):'; -echo $geshi3->parse_code(); - -echo ''; - -Before version 1.0.2, you needed to set the class of the code you wanted to be unique to the empty string. This limitation has been removed in version 1.0.2 - if you set the ID of a block of code, all styling will be done based on that ID alone. -3.3.4: Using an External Stylesheet -Top | Contents | Next | Previous - -An external stylesheet can reduce even more the amount of code needed to highlight some source. However there are some drawbacks with this. To use an external stylesheet, it's up to you to link it in to your document, normally with the following HTML: - - - - -In your external stylesheet you put CSS declarations for your code. Then just make sure you're using the correct class (use set_overall_class() to ensure this) and this should work fine. - -This method is great if you don't mind the source always being highlighted the same (in particular, if you're making a plugin for a forum/wiki/other system, using an external stylesheet is a good idea!). It saves a small amount of code and your bandwidth, and it's relatively easy to just change the stylesheet should you need to. However, using this will render the methods that change the styles of the code useless, because of course the stylesheet is no longer being dynamically generated. You can still disable highlighting of certain lexics dynamically, however. -Note: - -As of version 1.0.2, GeSHi comes with a contrib/ directory, which in it contains a "wizard" script for creating a stylesheet. Although this script is by no means a complete solution, it will create the necessary rules for the basic lexics - comments, strings for example. Things not included in the wizard include regular expressions for any language that uses them (PHP and XML are two languages that use them), and keyword-link styles. However, this script should take some of the tedium out of the job of making an external stylesheet. Expect a much better version of this script in version 1.2! -3.4: Changing Styles -Top | Contents | Next | Previous - -One of the more powerful features of GeSHi is the ability to change the style of the output dynamically. Why be chained to the boring styles the language authors make up? You can change almost every single aspect of highlighted code - and can even say whether something is to be highlighted at all. - -If you're confused about "styles", you probably want to have a quick tutorial in them so you know what you can do with them. Checkout the homepage of CSS at http://www.w3.org/Style/CSS. -3.4.1: The Overall Styles -Top | Contents | Next | Previous - -The code outputted by GeSHi is either in a
        or a
         (see the section entitled "The Code Container"), and this can be styled.
        -$geshi->set_overall_style('... styles ...');
        -
        -Where styles is a string containing valid CSS declarations. By default, these styles overwrite the current styles, but you can change this by adding a second parameter:
        -$geshi->set_overall_style('color: blue;', true);
        -
        -The default styles "shine through" wherever anything isn't highlighted. Also, you can apply more advanced styles, like position: (fixed|relative) etc, because a 
        /
         is a block level element.
        -Note:
        -
        -Remember that a 
        will by default have a larger font size than a
        , as discussed in the section "The Code Container".
        -3.4.2: Line Number Styles
        -Top | Contents | Next | Previous
        -
        -You may wish to refer to the section Styling Line Numbers before reading this section.
        -
        -As of version 1.0.2, the way line numbers are generated is different, so therefore the way that they are styled is different. In particular, now you cannot set the background style of the fancy line numbers to be different from that of the normal line numbers.
        -
        -Line number styles are set by using the method set_line_style:
        -$geshi->set_line_style($style1, $style2);
        -
        -$style1 is the style of the line numbers by default, and $style2 is the style of the fancy line numbers.
        -Caution:
        -
        -Things have changed since 1.0.1! This note is very important - please make sure you check this twice before complaining about line numbers!
        -
        -Because of the way that ordered lists are done in HTML, there really isn't normally a way to style the actual numbers in the list. I've cheated somewhat with GeSHi - I've made it possible to use CSS to style the foreground of the line numbers. So therefore, you can change the color, font size and type, and padding on them. If you want to have a pretty background, you must use set_overall_style() to do this, and use set_code_style() to style the actual code! This is explained in the section above: Styling Line Numbers.
        -
        -In addition, the styles for fancy line numbers is now the difference between the normal styles and the styles you want to achieve. For example, in GeSHi prior to 1.0.2 you may have done this to style line numbers:
        -$geshi->set_line_style('color: red; font-weight: bold;', 'color: green; font-weight: bold');
        -
        -Now you instead can do this:
        -$geshi->set_line_style('color: red; font-weight: bold;', 'color: green;');
        -
        -The font-weight: bold; will automatically carry through to the fancy styles. This is actually a small saving in code - but the difference may be confusing for anyone using 1.0.1 at first.
        -3.4.3: Setting Keyword Styles
        -Top | Contents | Next | Previous
        -
        -Perhaps the most regular change you will make will be to the styles of a keyword set. In order to change the styles for a particular set, you'll have to know what the set is called first. Sets are numbered from 1 up. Typically, set 1 contains keywords like if, while, do, for, switch etc, set 2 contains null, false, true etc, set 3 contains function inbuilt into the language (echo, htmlspecialchars etc. in PHP) and set 4 contains data types and similar variable modifiers: int, double, real, static etc. However these things are not fixed, and you should check the language file to see what key you want. Having a familiarity with a language file is definately a plus for using it.
        -
        -To change the styles for a keyword set, call the set_keyword_group_style() method:
        -$geshi->set_keyword_group_style($group, $styles);
        -
        -Where $group is the group to change the styles for and $styles is a string containing the styles to apply to that group.
        -
        -By default, the styles you pass overwrite the current styles. Add a boolean "true" after the styles you specify to combine them with the current styles:
        -$geshi->set_keyword_group_style(3, 'color: white;', true);
        -3.4.4: Setting Comment Styles
        -Top | Contents | Next | Previous
        -
        -To change the styles for a comment group, call the set_comments_style() method:
        -$geshi->set_comments_style($group, $styles);
        -
        -Where $group is either a number corresponding to a single-line comment, or the string 'MULTI' to specify multiline comments:
        -$geshi->set_comments_style(1, 'font-style: italic;');
        -$geshi->set_comments_style('MULTI', 'display: hidden;');
        -
        -By default, the styles you pass overwrite the current styles. Add a boolean "true" after the styles you specify to combine them with the current styles:
        -$geshi->set_comments_style(1, 'font-weight: 100;', true);
        -3.4.5: Setting Other Styles
        -Top | Contents | Next | Previous
        -
        -GeSHi can highlight many other aspects of your source other than just keywords and comments. Strings, Numbers, Methods and Brackets among other things can all also be highlighted. Here are the related methods:
        -$geshi->set_escape_characters_style($styles[, $preserve_defaults]);
        -$geshi->set_symbols_style($styles[, $preserve_defaults]);
        -$geshi->set_strings_style($styles[, $preserve_defaults]);
        -$geshi->set_numbers_style($styles[, $preserve_defaults]);
        -$geshi->set_methods_style($key, $styles, [, $preserve_defaults]);
        -
        -$styles is a string containing valid stylesheet declarations, while $preserve_defaults should be set to true if you want your styles to be merged with the previous styles. In the case of set_methods_style, you should select a group to set the styles of, check the language files for the number used for each "object splitter".
        -3.5: Case Sensitivity and Auto Casing
        -Top | Contents | Next | Previous
        -
        -Controlling the case of the outputted source is an easy job with GeSHi. You can control which keywords are converted in case, and also control whether keywords are checked in a case sensitive manner.
        -3.5.1: Auto-Caps/Nocaps
        -Top | Contents | Next | Previous
        -
        -Auto-Caps/Nocaps is a nifty little feature that capitalises or lowercases automatically certain lexics when they are styled. I dabble in QuickBASIC, a dialect of BASIC which is well known for it's capatalisation, and SQL is another language well known for using caps for readability.
        -
        -To change what case lexics are rendered in, you call the set_case_keywords() method:
        -$geshi->set_case_keywords($caps_modifier);
        -
        -The valid values to pass to this method are:
        -
        -    * GESHI_CAPS_NO_CHANGE - Don't change the case of any lexics, leave as they are found
        -    * GESHI_CAPS_UPPER - Uppercase all lexics found
        -    * GESHI_CAPS_LOWER - Lowercase all lexics found
        -
        -Caution:
        -
        -When I say "lexic", I mean "keywords". Any keyword in any keyword array will be modified using this option! This is one small area of inflexibility I hope to fix in 1.2.X.
        -
        -I suspect this will only be used to specify GESHI_CAPS_NO_CHANGE to turn off autocaps for languages like SQL and BASIC variants, like so:
        -$geshi = new GeSHi($source, 'sql');
        -$geshi->set_case_keywords(GESHI_CAPS_NO_CHANGE); // don't want keywords capatalised
        -
        -All the same, it can be used for some interesting effects:
        -$geshi = new GeSHi($source, 'java');
        -// Anyone who's used java knows how picky it is about CapitalLetters...
        -$geshi->set_case_keywords(GESHI_CAPS_LOWER);
        -// No *way* the source will look right now ;)
        -3.5.2: Setting Case Sensitivity
        -Top | Contents | Next | Previous
        -
        -Some languages, like PHP, don't mind what case function names and keywords are in, while others, like Java, depend on such pickiness to maintain their bad reputations ;). In any event, you can use the set_case_sensitivity to change the case sensitiveness of a particular keyword group from the default:
        -$geshi->set_case_sensitivity($key, $sensitivity);
        -
        -Where $key is the key of the group for which you wish to change case sensitivness for (see the language file for that language), and $sensitivity is a boolean value - true if the keyword is case sensitive, and false if not.
        -3.6: Changing the Source, Language, Config Options
        -Top | Contents | Next | Previous
        -
        -What happens if you want to change the source to be highlighted on the fly, or the language. Or if you want to specify any of those basic fields after you've created a GeSHi object? Well, that's where these methods come in.
        -3.6.1: Changing the Source Code
        -Top | Contents | Next | Previous
        -
        -To change the source code, you call the set_source() method:
        -$geshi->set_source($newsource);
        -
        -Example:
        -$geshi = new GeSHi($source1, 'php');
        -
        -// Method calls to specify various options...
        -
        -$code1 = $geshi->parse_code();
        -
        -$geshi->set_source($source2);
        -$code2 = $geshi->parse_code();
        -3.6.2: Changing the Language
        -Top | Contents | Next | Previous
        -
        -What happens if you want to change the language used for highlighting? Just call set_language():
        -$geshi->set_language('newlanguage');
        -
        -Example:
        -$geshi = new GeSHi($source, 'php');
        -
        -$code = $geshi->parse_code();
        -
        -// Highlight GeSHi's output
        -$geshi->set_source($code);
        -$geshi->set_language('html4strict');
        -$geshi->enable_classes(false);
        -echo $geshi->parse_code();
        -Note:
        -
        -Names are case-insensitive - they will be converted to lower case to match a language file however. So if you're making a language file, remember it should have a name in lower case.
        -Note:
        -
        -What you pass to this method is the name of a language file, minus the .php extension. If you're writing a plugin for a particular application, it's up to you to somehow convert user input into a valid language name.
        -Caution:
        -
        -GeSHi include()s the language file, so be careful to make sure that users can't pass some wierd language name to include any old script! GeSHi tries to strip non-valid characters out of a language name, but you should always do this your self anyway. In particular, language files are always lower-case, with either alphanumeric characters, dashes or underscores in their name.
        -
        -At the very least, strip "/" characters out of a language name.
        -3.6.3: Changing the Language Path
        -Top | Contents | Next | Previous
        -
        -What happens if all of a sudden you want to use language files from a different directory from the current language file location? You call the set_language_path() method:
        -$geshi->set_language_path($newpath);
        -
        -It doesn't matter whether the path has a trailing slash after it or not - only that it points to a valid folder. If it doesn't, that's your tough luck ;)
        -3.6.4: Changing the Character Set
        -Top | Contents | Next | Previous
        -
        -As of version 1.0.3, you can use the method set_encoding to specify the character set that your source is in. Valid names are those names that are valid for the PHP function htmlentities():
        -$geshi->set_encoding($encoding);
        -
        -There is a table of valid strings for $encoding at the php.net manual linked to above. If you do not specify an encoding, or specify an invalid encoding, the character set used is ISO-8859-1.
        -Using load_from_file to Change the Language and Source Code
        -Top | Contents | Next | Previous
        -
        -As of GeSHi 1.0.5, you can use the method load_from_file to load the source code and language from a file. Simply pass this method a file name and it will attempt to load the source and set the language.
        -$geshi->load_from_file($file_name, $lookup);
        -
        -$file_name is the file name to use, and $lookup is an optional parameter that contains a lookup array to use for deciding which language to choose. You can use this to override GeSHi's default lookup array, which may not contain the extension of the file you're after, or perhaps does have your extension but under a different language. The lookup array is of the form:
        -
        -array(
        -	 *   'lang_name' => array('extension', 'extension', ...),
        -	 *   'lang_name' ...
        -	 * );
        -
        -Also, you can use the method get_language_name_from_extension if you need to convert a file extension to a valid language name. This method will return the empty string if it could not find a match in the lookup, and like load_from_file it accepts an optional second parameter that contains a lookup array.
        -3.7: Error Handling
        -Top | Contents | Next | Previous
        -
        -What happens if you try to highlight using a language that doesn't exist? Or if GeSHi can't read a required file? The results you get may be confusing. You may check your code over and over, and never find anything wrong. GeSHi provides ways of finding out if GeSHi itself found anything wrong with what you tried to do. After highlighting, you can call the error() method:
        -$geshi = new GeSHi('hi', 'thisLangIsNotSupported');
        -
        -echo $geshi->error();  // echoes error message
        -
        -The error message you will get will look like this:
        -
        -    GeSHi Error: GeSHi could not find the language thisLangIsNotSupported (using path geshi/) (code 2)
        -
        -The error outputted will be the last error GeSHi came across, just like how mysql_error() works.
        -3.8: Disabling styling of some Lexics
        -Top | Contents | Next | Previous
        -
        -One disadvantage of GeSHi is that for large source files using complex languages, it can be quite slow with every option turned on. Although future releases will concentrate on the speed/resource side of highlighting, for now you can gain speed increases by disabling some of the highlighting options. This is done by using a series of set_*_highlighting methods:
        -
        -    * set_keyword_group_highlighting($group, $flag): Sets whether a particular $group of keywords is to be highlighted or not. Consult the necessary language file(s) to see what $group should be for each group (typically a positive integer). $flag is false if you want to disable highlighting of this group, and true if you want to re-enable higlighting of this group. If you disable a keyword group then even if the keyword group has a related URL one will not be generated for that keyword.
        -    * set_comments_highlighting($group, $flag): Sets whether a particular $group of comments is to be highlighted or not. Consult the necessary language file(s) to see what $group should be for each group (typically a positive integer, or the string 'MULTI' for multiline comments. $flag is false if you want to disable highlighting of this group, and true if you want to re-enable highlighting of this group.
        -    * set_regexps_highlighting($regexp, $flag): Sets whether a particular $regexp is to be highlighted or not. Consult the necessary language file(s) to see what $regexp should be for each regexp (typically a positive integer, or the string 'MULTI' for multiline comments. $flag is false if you want to disable highlighting of this group, and true if you want to re-enable highlighting of this group.
        -    * The following methods:
        -          o set_escape_characters_highlighting($flag)
        -          o set_symbols_highlighting($flag)
        -          o set_strings_highlighting($flag)
        -          o set_numbers_highlighting($flag)
        -          o set_methods_highlighting($flag)
        -      Work on their respective lexics (e.g. set_methods_highlighting will disable/enable highlighting of methods). For each method, if $flag is false then the related lexics will not be highlighted at all (this means no HTML will surround the lexic like usual, saving on time and bandwidth.
        -
        -3.9: Setting the Tab Width
        -Top | Contents | Next | Previous
        -
        -If you're using the 
         header, tabs are handled automatically by your browser, and in general you can count on good results. However, if you're using the 
        header, you may want to specify a tab width explicitly. - -Note that tabs created in this fashion won't be like normal tabs - there won't be "tab-stops" as such, instead tabs will be replaced with the specified number of spaces. - -To change the tab width, you call the set_tab_width() method: -$geshi->set_tab_width($width); - -Where $width is the width in spaces that you'd like tabs to be. -3.10: Using Strict Mode -Top | Contents | Next | Previous - -Some languages like to get tricky, and jump in and out of the file that they're in. For example, the vast majority of you reading this will have used a PHP file. And you know that PHP code is only executed if it's within delimiters like (there are others of course...). So what happens if you do the following in a php file? - - -Well normally using GeSHi with PHP, or using a bad highlighter, you'll end up with this: - - -What a mess! Especially if you're being slack about where you're putting your quotes, you could end up with the rest of your file as bright red. Fortunately, you can tell GeSHi to be "strict" about just when it highlights and when it does not, using the enable_strict_mode method: -$geshi->enable_strict_mode($mode); - -Where $mode is true or not specified to enable strict mode, or false to disable strict mode if you've already turned it and don't want it now. - -Here's the result: much better! - -3.11: Adding/Removing Keywords -Top | Contents | Next | Previous - -Lets say that you're working on a large project, with many files, many classes and many functions. Perhaps also you have the source code on the web and highlighted by GeSHi, perhaps as a front end to CVS, as a learning tool, something to refer to, whatever. Well, why not highlight the names of the functions and classes *your* project uses, as well as the standard functions and classes? Or perhaps you're not interested in highlighting certain functions, and would like to remove them? Or maybe you don't mind if an entire function group goes west in the interest of speed? GeSHi can handle all of this! -3.11.1: Adding a Keyword -Top | Contents | Next | Previous - -If you want to add a keyword to an existing keyword group, you use the add_keyword method: -$geshi->add_keyword($key, $word); - -Where $key is the index of the group of keywords you want to add this keyword to, and $word is the word to add. - -This implies knowledge of the language file to know the correct index. -Note: - -Keywords should contain at least two alphabetical characters (lower or upper case letters only). This is to enable GeSHi to work much faster by not bothering to try to detect keywords in parts of your source where there is no alphabetical characters. -3.11.2: Removing a Keyword -Top | Contents | Next | Previous - -Perhaps you want to remove a keyword from an existing group. Maybe you don't use it and want to save yourself some time. Whatever the reason, you can remove it using the remove_keyword method: -$geshi->remove_keyword($key, $word); - -Where $key is the index of the gropu of keywords that you want to remove this keyword from, and $word is the word to remove. - -This implies knowledge of the language file to know the correct index - most of the time the keywords you'll want to remove will be in group 3, but this is not guaranteed and you should check the language file first. - -This function is silent - if the keyword is not in the group you specified, nothing awful will happen ;) -3.11.3: Adding a Keyword Group -Top | Contents | Next | Previous - -Lets say for your big project you have several main functions and classes that you'd like highlighted. Why not add them as their own group instead of having them highlighted the same way as other keywords? Then you can make them stand out, and people can instantly see which functions and classes are user defined or inbuilt. Furthermore, you could set the URL for this group to point at the API documentation of your project. - -You add a keyword group by using the add_keyword_group method: -$geshi->add_keyword_group($key, $styles, $case_sensitive, $words); - -Where $key is the key that you want to use to refer to this group, $styles is the styles that you want to use to style this group, $case_sensitive is true or false depending on whether you want this group of keywords to be case sensitive or not and $words is an array of words (or a string) of which words to add to this group. For example: -$geshi->add_keyword_group(10, 'color: #600000;', false, array('myfunc_1', 'myfunc_2', 'myfunc_3')); - -Adds a keyword group referenced by index 10, of which all keywords in the group will be dark red, each keyword can be in any case and which contains the keywords "myfunc_1", "myfunc_2" and "myfunc_3". - -After creating such a keyword group, you may call other GeSHi methods on it, just as you would for any other keyword group. -Caution: - -If you specify a $key for which there is already a keyword group, the old keyword group will be overwritten! Most language files don't use numbers larger than 5, so I recommend you play it safe and use a number like 10 or 42. -3.11.4: Removing a Keyword Group -Top | Contents | Next | Previous - -Perhaps you *really* need speed? Why not just remove an entire keyword group? GeSHi won't have to loop through each keyword checking for its existance, saving much time. You removing a keyword group by using the remove_keyword_group method: -$geshi->remove_keyword_group($key); - -Where $key is the key of the group you wish to remove. This implies knowleged of the language file. -3.12: Headers and Footers for Your Code -Top | Contents | Next | Previous - -So you want to add some special information to the highlighted source? GeSHi can do that too! You can specify headers and footers for your code, style them, and insert information from the highlighted source into your header or footer. -3.12.1: Keyword Substitution -Top | Contents | Next | Previous - -In your header and footer, you can put special keywords that will be replaced with actual configuration values for this GeSHi object. The keywords you can use are: - - *
        * + * @param string The filename to load the source from + * @param array A lookup array to use instead of the default one * @todo Complete rethink of this and above method * @since 1.0.5 */ function load_from_file($file_name, $lookup = array()) { if (is_readable($file_name)) { - $this->set_source(implode('', file($file_name))); + $this->set_source(file_get_contents($file_name)); $this->set_language($this->get_language_name_from_extension(substr(strrchr($file_name, '.'), 1), $lookup)); - } - else { + } else { $this->error = GESHI_ERROR_FILE_NOT_READABLE; } } @@ -1176,7 +1555,15 @@ class GeSHi { * @since 1.0.0 */ function add_keyword($key, $word) { - $this->language_data['KEYWORDS'][$key][] = $word; + if (!in_array($word, $this->language_data['KEYWORDS'][$key])) { + $this->language_data['KEYWORDS'][$key][] = $word; + + //NEW in 1.0.8 don't recompile the whole optimized regexp, simply append it + if ($this->parse_cache_built) { + $subkey = count($this->language_data['CACHED_KEYWORD_LISTS'][$key]) - 1; + $this->language_data['CACHED_KEYWORD_LISTS'][$key][$subkey] .= '|' . preg_quote($word, '/'); + } + } } /** @@ -1184,11 +1571,24 @@ class GeSHi { * * @param int The key of the keyword group to remove the keyword from * @param string The word to remove from the keyword group + * @param bool Wether to automatically recompile the optimized regexp list or not. + * Note: if you set this to false and @see GeSHi->parse_code() was already called once, + * for the current language, you have to manually call @see GeSHi->optimize_keyword_group() + * or the removed keyword will stay in cache and still be highlighted! On the other hand + * it might be too expensive to recompile the regexp list for every removal if you want to + * remove a lot of keywords. * @since 1.0.0 */ - function remove_keyword($key, $word) { - $this->language_data['KEYWORDS'][$key] = - array_diff($this->language_data['KEYWORDS'][$key], array($word)); + function remove_keyword($key, $word, $recompile = true) { + $key_to_remove = array_search($word, $this->language_data['KEYWORDS'][$key]); + if ($key_to_remove !== false) { + unset($this->language_data['KEYWORDS'][$key][$key_to_remove]); + + //NEW in 1.0.8, optionally recompile keyword group + if ($recompile && $this->parse_cache_built) { + $this->optimize_keyword_group($key); + } + } } /** @@ -1202,10 +1602,21 @@ class GeSHi { */ function add_keyword_group($key, $styles, $case_sensitive = true, $words = array()) { $words = (array) $words; + if (empty($words)) { + // empty word lists mess up highlighting + return false; + } + + //Add the new keyword group internally $this->language_data['KEYWORDS'][$key] = $words; $this->lexic_permissions['KEYWORDS'][$key] = true; $this->language_data['CASE_SENSITIVE'][$key] = $case_sensitive; $this->language_data['STYLES']['KEYWORDS'][$key] = $styles; + + //NEW in 1.0.8, cache keyword regexp + if ($this->parse_cache_built) { + $this->optimize_keyword_group($key); + } } /** @@ -1215,10 +1626,44 @@ class GeSHi { * @since 1.0.0 */ function remove_keyword_group ($key) { + //Remove the keyword group internally unset($this->language_data['KEYWORDS'][$key]); unset($this->lexic_permissions['KEYWORDS'][$key]); unset($this->language_data['CASE_SENSITIVE'][$key]); unset($this->language_data['STYLES']['KEYWORDS'][$key]); + + //NEW in 1.0.8 + unset($this->language_data['CACHED_KEYWORD_LISTS'][$key]); + } + + /** + * compile optimized regexp list for keyword group + * + * @param int The key of the keyword group to compile & optimize + * @since 1.0.8 + */ + function optimize_keyword_group($key) { + $this->language_data['CACHED_KEYWORD_LISTS'][$key] = + $this->optimize_regexp_list($this->language_data['KEYWORDS'][$key]); + $space_as_whitespace = false; + if(isset($this->language_data['PARSER_CONTROL'])) { + if(isset($this->language_data['PARSER_CONTROL']['KEYWORDS'])) { + if(isset($this->language_data['PARSER_CONTROL']['KEYWORDS']['SPACE_AS_WHITESPACE'])) { + $space_as_whitespace = $this->language_data['PARSER_CONTROL']['KEYWORDS']['SPACE_AS_WHITESPACE']; + } + if(isset($this->language_data['PARSER_CONTROL']['KEYWORDS'][$key]['SPACE_AS_WHITESPACE'])) { + if(isset($this->language_data['PARSER_CONTROL']['KEYWORDS'][$key]['SPACE_AS_WHITESPACE'])) { + $space_as_whitespace = $this->language_data['PARSER_CONTROL']['KEYWORDS'][$key]['SPACE_AS_WHITESPACE']; + } + } + } + } + if($space_as_whitespace) { + foreach($this->language_data['CACHED_KEYWORD_LISTS'][$key] as $rxk => $rxv) { + $this->language_data['CACHED_KEYWORD_LISTS'][$key][$rxk] = + str_replace(" ", "\\s+", $rxv); + } + } } /** @@ -1306,9 +1751,8 @@ class GeSHi { function set_link_target($target) { if (!$target) { $this->link_target = ''; - } - else { - $this->link_target = ' target="' . $target . '" '; + } else { + $this->link_target = ' target="' . $target . '"'; } } @@ -1325,8 +1769,10 @@ class GeSHi { /** * Sets whether context-important blocks are highlighted * + * @param boolean Tells whether to enable or disable highlighting of important blocks * @todo REMOVE THIS SHIZ FROM GESHI! * @deprecated + * @since 1.0.2 */ function enable_important_blocks($flag) { $this->enable_important_blocks = ( $flag ) ? true : false; @@ -1345,19 +1791,37 @@ class GeSHi { /** * Specifies which lines to highlight extra * + * The extra style parameter was added in 1.0.7.21. + * * @param mixed An array of line numbers to highlight, or just a line * number on its own. + * @param string A string specifying the style to use for this line. + * If null is specified, the default style is used. + * If false is specified, the line will be removed from + * special highlighting * @since 1.0.2 * @todo Some data replication here that could be cut down on */ - function highlight_lines_extra($lines) { + function highlight_lines_extra($lines, $style = null) { if (is_array($lines)) { + //Split up the job using single lines at a time foreach ($lines as $line) { - $this->highlight_extra_lines[intval($line)] = intval($line); + $this->highlight_lines_extra($line, $style); + } + } else { + //Mark the line as being highlighted specially + $lines = intval($lines); + $this->highlight_extra_lines[$lines] = $lines; + + //Decide on which style to use + if ($style === null) { //Check if we should use default style + unset($this->highlight_extra_lines_styles[$lines]); + } else if ($style === false) { //Check if to remove this line + unset($this->highlight_extra_lines[$lines]); + unset($this->highlight_extra_lines_styles[$lines]); + } else { + $this->highlight_extra_lines_styles[$lines] = $style; } - } - else { - $this->highlight_extra_lines[intval($lines)] = intval($lines); } } @@ -1371,14 +1835,15 @@ class GeSHi { $this->highlight_extra_lines_style = $styles; } - /** - * Sets the line-ending - * - * @param string The new line-ending - */ - function set_line_ending($line_ending) { - $this->line_ending = (string)$line_ending; - } + /** + * Sets the line-ending + * + * @param string The new line-ending + * @since 1.0.2 + */ + function set_line_ending($line_ending) { + $this->line_ending = (string)$line_ending; + } /** * Sets what number line numbers should start at. Should @@ -1413,7 +1878,7 @@ class GeSHi { */ function set_encoding($encoding) { if ($encoding) { - $this->encoding = $encoding; + $this->encoding = strtolower($encoding); } } @@ -1421,9 +1886,242 @@ class GeSHi { * Turns linking of keywords on or off. * * @param boolean If true, links will be added to keywords + * @since 1.0.2 */ function enable_keyword_links($enable = true) { - $this->keyword_links = ($enable) ? true : false; + $this->keyword_links = (bool) $enable; + } + + /** + * Setup caches needed for styling. This is automatically called in + * parse_code() and get_stylesheet() when appropriate. This function helps + * stylesheet generators as they rely on some style information being + * preprocessed + * + * @since 1.0.8 + * @access private + */ + function build_style_cache() { + //Build the style cache needed to highlight numbers appropriate + if($this->lexic_permissions['NUMBERS']) { + //First check what way highlighting information for numbers are given + if(!isset($this->language_data['NUMBERS'])) { + $this->language_data['NUMBERS'] = 0; + } + + if(is_array($this->language_data['NUMBERS'])) { + $this->language_data['NUMBERS_CACHE'] = $this->language_data['NUMBERS']; + } else { + $this->language_data['NUMBERS_CACHE'] = array(); + if(!$this->language_data['NUMBERS']) { + $this->language_data['NUMBERS'] = + GESHI_NUMBER_INT_BASIC | + GESHI_NUMBER_FLT_NONSCI; + } + + for($i = 0, $j = $this->language_data['NUMBERS']; $j > 0; ++$i, $j>>=1) { + //Rearrange style indices if required ... + if(isset($this->language_data['STYLES']['NUMBERS'][1<<$i])) { + $this->language_data['STYLES']['NUMBERS'][$i] = + $this->language_data['STYLES']['NUMBERS'][1<<$i]; + unset($this->language_data['STYLES']['NUMBERS'][1<<$i]); + } + + //Check if this bit is set for highlighting + if($j&1) { + //So this bit is set ... + //Check if it belongs to group 0 or the actual stylegroup + if(isset($this->language_data['STYLES']['NUMBERS'][$i])) { + $this->language_data['NUMBERS_CACHE'][$i] = 1 << $i; + } else { + if(!isset($this->language_data['NUMBERS_CACHE'][0])) { + $this->language_data['NUMBERS_CACHE'][0] = 0; + } + $this->language_data['NUMBERS_CACHE'][0] |= 1 << $i; + } + } + } + } + } + } + + /** + * Setup caches needed for parsing. This is automatically called in parse_code() when appropriate. + * This function makes stylesheet generators much faster as they do not need these caches. + * + * @since 1.0.8 + * @access private + */ + function build_parse_cache() { + // cache symbol regexp + //As this is a costy operation, we avoid doing it for multiple groups ... + //Instead we perform it for all symbols at once. + // + //For this to work, we need to reorganize the data arrays. + if ($this->lexic_permissions['SYMBOLS'] && !empty($this->language_data['SYMBOLS'])) { + $this->language_data['MULTIPLE_SYMBOL_GROUPS'] = count($this->language_data['STYLES']['SYMBOLS']) > 1; + + $this->language_data['SYMBOL_DATA'] = array(); + $symbol_preg_multi = array(); // multi char symbols + $symbol_preg_single = array(); // single char symbols + foreach ($this->language_data['SYMBOLS'] as $key => $symbols) { + if (is_array($symbols)) { + foreach ($symbols as $sym) { + $sym = $this->hsc($sym); + if (!isset($this->language_data['SYMBOL_DATA'][$sym])) { + $this->language_data['SYMBOL_DATA'][$sym] = $key; + if (isset($sym[1])) { // multiple chars + $symbol_preg_multi[] = preg_quote($sym, '/'); + } else { // single char + if ($sym == '-') { + // don't trigger range out of order error + $symbol_preg_single[] = '\-'; + } else { + $symbol_preg_single[] = preg_quote($sym, '/'); + } + } + } + } + } else { + $symbols = $this->hsc($symbols); + if (!isset($this->language_data['SYMBOL_DATA'][$symbols])) { + $this->language_data['SYMBOL_DATA'][$symbols] = 0; + if (isset($symbols[1])) { // multiple chars + $symbol_preg_multi[] = preg_quote($symbols, '/'); + } else if ($symbols == '-') { + // don't trigger range out of order error + $symbol_preg_single[] = '\-'; + } else { // single char + $symbol_preg_single[] = preg_quote($symbols, '/'); + } + } + } + } + + //Now we have an array with each possible symbol as the key and the style as the actual data. + //This way we can set the correct style just the moment we highlight ... + // + //Now we need to rewrite our array to get a search string that + $symbol_preg = array(); + if (!empty($symbol_preg_multi)) { + rsort($symbol_preg_multi); + $symbol_preg[] = implode('|', $symbol_preg_multi); + } + if (!empty($symbol_preg_single)) { + rsort($symbol_preg_single); + $symbol_preg[] = '[' . implode('', $symbol_preg_single) . ']'; + } + $this->language_data['SYMBOL_SEARCH'] = implode("|", $symbol_preg); + } + + // cache optimized regexp for keyword matching + // remove old cache + $this->language_data['CACHED_KEYWORD_LISTS'] = array(); + foreach (array_keys($this->language_data['KEYWORDS']) as $key) { + if (!isset($this->lexic_permissions['KEYWORDS'][$key]) || + $this->lexic_permissions['KEYWORDS'][$key]) { + $this->optimize_keyword_group($key); + } + } + + // brackets + if ($this->lexic_permissions['BRACKETS']) { + $this->language_data['CACHE_BRACKET_MATCH'] = array('[', ']', '(', ')', '{', '}'); + if (!$this->use_classes && isset($this->language_data['STYLES']['BRACKETS'][0])) { + $this->language_data['CACHE_BRACKET_REPLACE'] = array( + '<| style="' . $this->language_data['STYLES']['BRACKETS'][0] . '">[|>', + '<| style="' . $this->language_data['STYLES']['BRACKETS'][0] . '">]|>', + '<| style="' . $this->language_data['STYLES']['BRACKETS'][0] . '">(|>', + '<| style="' . $this->language_data['STYLES']['BRACKETS'][0] . '">)|>', + '<| style="' . $this->language_data['STYLES']['BRACKETS'][0] . '">{|>', + '<| style="' . $this->language_data['STYLES']['BRACKETS'][0] . '">}|>', + ); + } + else { + $this->language_data['CACHE_BRACKET_REPLACE'] = array( + '<| class="br0">[|>', + '<| class="br0">]|>', + '<| class="br0">(|>', + '<| class="br0">)|>', + '<| class="br0">{|>', + '<| class="br0">}|>', + ); + } + } + + //Build the parse cache needed to highlight numbers appropriate + if($this->lexic_permissions['NUMBERS']) { + //Check if the style rearrangements have been processed ... + //This also does some preprocessing to check which style groups are useable ... + if(!isset($this->language_data['NUMBERS_CACHE'])) { + $this->build_style_cache(); + } + + //Number format specification + //All this formats are matched case-insensitively! + static $numbers_format = array( + GESHI_NUMBER_INT_BASIC => + '(?:(? + '(? + '(? + '(? + '(? + '(? + '(? + '(? + '(? + '(? + '(? + '(? + '(? + '(? + '(? + '(?language_data['NUMBERS_RXCACHE'] = array(); + foreach($this->language_data['NUMBERS_CACHE'] as $key => $rxdata) { + if(is_string($rxdata)) { + $regexp = $rxdata; + } else { + //This is a bitfield of number flags to highlight: + //Build an array, implode them together and make this the actual RX + $rxuse = array(); + for($i = 1; $i <= $rxdata; $i<<=1) { + if($rxdata & $i) { + $rxuse[] = $numbers_format[$i]; + } + } + $regexp = implode("|", $rxuse); + } + + $this->language_data['NUMBERS_RXCACHE'][$key] = + "/(?)($regexp)(?!(?:|(?>[^\<]))+>)(?![^<]*>)(?!\|>)(?!\/>)/i"; // + } + + if(!isset($this->language_data['PARSER_CONTROL']['NUMBERS']['PRECHECK_RX'])) { + $this->language_data['PARSER_CONTROL']['NUMBERS']['PRECHECK_RX'] = '#\d#'; + } + } + + $this->parse_cache_built = true; } /** @@ -1440,34 +2138,35 @@ class GeSHi { // Start the timer $start_time = microtime(); - // Firstly, if there is an error, we won't highlight - if ($this->error) { - $result = GeSHi::hsc($this->source); - // Timing is irrelevant - $this->set_time($start_time, $start_time); - return $this->finalise($result); - } - // Replace all newlines to a common form. $code = str_replace("\r\n", "\n", $this->source); $code = str_replace("\r", "\n", $code); - // Add spaces for regular expression matching and line numbers - $code = "\n" . $code . "\n"; + + // Firstly, if there is an error, we won't highlight + if ($this->error) { + //Escape the source for output + $result = $this->hsc($this->source); + + //This fix is related to SF#1923020, but has to be applied regardless of + //actually highlighting symbols. + $result = str_replace(array('', ''), array(';', '|'), $result); + + // Timing is irrelevant + $this->set_time($start_time, $start_time); + $this->finalise($result); + return $result; + } + + // make sure the parse cache is up2date + if (!$this->parse_cache_built) { + $this->build_parse_cache(); + } // Initialise various stuff $length = strlen($code); - $STRING_OPEN = ''; - $CLOSE_STRING = false; - $ESCAPE_CHAR_OPEN = false; $COMMENT_MATCHED = false; - // Turn highlighting on if strict mode doesn't apply to this language - $HIGHLIGHTING_ON = ( !$this->strict_mode ) ? true : ''; - // Whether to highlight inside a block of code - $HIGHLIGHT_INSIDE_STRICT = false; - $HARDQUOTE_OPEN = false; - $STRICTATTRS = ''; $stuff_to_parse = ''; - $result = ''; + $endresult = ''; // "Important" selections are handled like multiline comments // @todo GET RID OF THIS SHIZ @@ -1478,449 +2177,957 @@ class GeSHi { if ($this->strict_mode) { // Break the source into bits. Each bit will be a portion of the code // within script delimiters - for example, HTML between < and > - $parts = array(0 => array(0 => '')); $k = 0; - for ($i = 0; $i < $length; $i++) { - $char = substr($code, $i, 1); - if (!$HIGHLIGHTING_ON) { - foreach ($this->language_data['SCRIPT_DELIMITERS'] as $key => $delimiters) { + $parts = array(); + $matches = array(); + $next_match_pointer = null; + // we use a copy to unset delimiters on demand (when they are not found) + $delim_copy = $this->language_data['SCRIPT_DELIMITERS']; + $i = 0; + while ($i < $length) { + $next_match_pos = $length + 1; // never true + foreach ($delim_copy as $dk => $delimiters) { + if(is_array($delimiters)) { foreach ($delimiters as $open => $close) { - // Get the next little bit for this opening string - $check = substr($code, $i, strlen($open)); - // If it matches... - if ($check == $open) { - // We start a new block with the highlightable - // code in it - $HIGHLIGHTING_ON = $open; - $i += strlen($open) - 1; - $char = $open; - $parts[++$k][0] = $char; + // make sure the cache is setup properly + if (!isset($matches[$dk][$open])) { + $matches[$dk][$open] = array( + 'next_match' => -1, + 'dk' => $dk, - // No point going around again... - break(2); + 'open' => $open, // needed for grouping of adjacent code blocks (see below) + 'open_strlen' => strlen($open), + + 'close' => $close, + 'close_strlen' => strlen($close), + ); } + // Get the next little bit for this opening string + if ($matches[$dk][$open]['next_match'] < $i) { + // only find the next pos if it was not already cached + $open_pos = strpos($code, $open, $i); + if ($open_pos === false) { + // no match for this delimiter ever + unset($delim_copy[$dk][$open]); + continue; + } + $matches[$dk][$open]['next_match'] = $open_pos; + } + if ($matches[$dk][$open]['next_match'] < $next_match_pos) { + //So we got a new match, update the close_pos + $matches[$dk][$open]['close_pos'] = + strpos($code, $close, $matches[$dk][$open]['next_match']+1); + + $next_match_pointer =& $matches[$dk][$open]; + $next_match_pos = $matches[$dk][$open]['next_match']; + } + } + } else { + //So we should match an RegExp as Strict Block ... + /** + * The value in $delimiters is expected to be an RegExp + * containing exactly 2 matching groups: + * - Group 1 is the opener + * - Group 2 is the closer + */ + if(!GESHI_PHP_PRE_433 && //Needs proper rewrite to work with PHP >=4.3.0; 4.3.3 is guaranteed to work. + preg_match($delimiters, $code, $matches_rx, PREG_OFFSET_CAPTURE, $i)) { + //We got a match ... + if(isset($matches_rx['start']) && isset($matches_rx['end'])) + { + $matches[$dk] = array( + 'next_match' => $matches_rx['start'][1], + 'dk' => $dk, + + 'close_strlen' => strlen($matches_rx['end'][0]), + 'close_pos' => $matches_rx['end'][1], + ); + } else { + $matches[$dk] = array( + 'next_match' => $matches_rx[1][1], + 'dk' => $dk, + + 'close_strlen' => strlen($matches_rx[2][0]), + 'close_pos' => $matches_rx[2][1], + ); + } + } else { + // no match for this delimiter ever + unset($delim_copy[$dk]); + continue; + } + + if ($matches[$dk]['next_match'] <= $next_match_pos) { + $next_match_pointer =& $matches[$dk]; + $next_match_pos = $matches[$dk]['next_match']; } } } - else { - foreach ($this->language_data['SCRIPT_DELIMITERS'] as $key => $delimiters) { - foreach ($delimiters as $open => $close) { - if ($open == $HIGHLIGHTING_ON) { - // Found the closing tag - break(2); + + // non-highlightable text + $parts[$k] = array( + 1 => substr($code, $i, $next_match_pos - $i) + ); + ++$k; + + if ($next_match_pos > $length) { + // out of bounds means no next match was found + break; + } + + // highlightable code + $parts[$k][0] = $next_match_pointer['dk']; + + //Only combine for non-rx script blocks + if(is_array($delim_copy[$next_match_pointer['dk']])) { + // group adjacent script blocks, e.g. should be one block, not three! + $i = $next_match_pos + $next_match_pointer['open_strlen']; + while (true) { + $close_pos = strpos($code, $next_match_pointer['close'], $i); + if ($close_pos == false) { + break; + } + $i = $close_pos + $next_match_pointer['close_strlen']; + if ($i == $length) { + break; + } + if ($code[$i] == $next_match_pointer['open'][0] && ($next_match_pointer['open_strlen'] == 1 || + substr($code, $i, $next_match_pointer['open_strlen']) == $next_match_pointer['open'])) { + // merge adjacent but make sure we don't merge things like + foreach ($matches as $submatches) { + foreach ($submatches as $match) { + if ($match['next_match'] == $i) { + // a different block already matches here! + break 3; + } + } } + } else { + break; } } - // We check code from our current position BACKWARDS. This is so - // the ending string for highlighting can be included in the block - $check = substr($code, $i - strlen($close) + 1, strlen($close)); - if ($check == $close) { - $HIGHLIGHTING_ON = ''; - // Add the string to the rest of the string for this part - $parts[$k][1] = ( isset($parts[$k][1]) ) ? $parts[$k][1] . $char : $char; - $parts[++$k][0] = ''; - $char = ''; - } + } else { + $close_pos = $next_match_pointer['close_pos'] + $next_match_pointer['close_strlen']; + $i = $close_pos; + } + + if ($close_pos === false) { + // no closing delimiter found! + $parts[$k][1] = substr($code, $next_match_pos); + ++$k; + break; + } else { + $parts[$k][1] = substr($code, $next_match_pos, $i - $next_match_pos); + ++$k; } - $parts[$k][1] = ( isset($parts[$k][1]) ) ? $parts[$k][1] . $char : $char; } - $HIGHLIGHTING_ON = ''; - } - else { + unset($delim_copy, $next_match_pointer, $next_match_pos, $matches); + $num_parts = $k; + + if ($num_parts == 1 && $this->strict_mode == GESHI_MAYBE) { + // when we have only one part, we don't have anything to highlight at all. + // if we have a "maybe" strict language, this should be handled as highlightable code + $parts = array( + 0 => array( + 0 => '', + 1 => '' + ), + 1 => array( + 0 => null, + 1 => $parts[0][1] + ) + ); + $num_parts = 2; + } + + } else { // Not strict mode - simply dump the source into // the array at index 1 (the first highlightable block) $parts = array( - 1 => array( + 0 => array( 0 => '', + 1 => '' + ), + 1 => array( + 0 => null, 1 => $code ) ); + $num_parts = 2; + } + + //Unset variables we won't need any longer + unset($code); + + //Preload some repeatedly used values regarding hardquotes ... + $hq = isset($this->language_data['HARDQUOTE']) ? $this->language_data['HARDQUOTE'][0] : false; + $hq_strlen = strlen($hq); + + //Preload if line numbers are to be generated afterwards + //Added a check if line breaks should be forced even without line numbers, fixes SF#1727398 + $check_linenumbers = $this->line_numbers != GESHI_NO_LINE_NUMBERS || + !empty($this->highlight_extra_lines) || !$this->allow_multiline_span; + + //preload the escape char for faster checking ... + $escaped_escape_char = $this->hsc($this->language_data['ESCAPE_CHAR']); + + // this is used for single-line comments + $sc_disallowed_before = ""; + $sc_disallowed_after = ""; + + if (isset($this->language_data['PARSER_CONTROL'])) { + if (isset($this->language_data['PARSER_CONTROL']['COMMENTS'])) { + if (isset($this->language_data['PARSER_CONTROL']['COMMENTS']['DISALLOWED_BEFORE'])) { + $sc_disallowed_before = $this->language_data['PARSER_CONTROL']['COMMENTS']['DISALLOWED_BEFORE']; + } + if (isset($this->language_data['PARSER_CONTROL']['COMMENTS']['DISALLOWED_AFTER'])) { + $sc_disallowed_after = $this->language_data['PARSER_CONTROL']['COMMENTS']['DISALLOWED_AFTER']; + } + } + } + + //Fix for SF#1932083: Multichar Quotemarks unsupported + $is_string_starter = array(); + if ($this->lexic_permissions['STRINGS']) { + foreach ($this->language_data['QUOTEMARKS'] as $quotemark) { + if (!isset($is_string_starter[$quotemark[0]])) { + $is_string_starter[$quotemark[0]] = (string)$quotemark; + } else if (is_string($is_string_starter[$quotemark[0]])) { + $is_string_starter[$quotemark[0]] = array( + $is_string_starter[$quotemark[0]], + $quotemark); + } else { + $is_string_starter[$quotemark[0]][] = $quotemark; + } + } } // Now we go through each part. We know that even-indexed parts are // code that shouldn't be highlighted, and odd-indexed parts should // be highlighted - foreach ($parts as $key => $data) { - $part = $data[1]; + for ($key = 0; $key < $num_parts; ++$key) { + $STRICTATTRS = ''; + // If this block should be highlighted... - if ($key % 2) { - if ($this->strict_mode) { - // Find the class key for this block of code - foreach ($this->language_data['SCRIPT_DELIMITERS'] as $script_key => $script_data) { - foreach ($script_data as $open => $close) { - if ($data[0] == $open) { - break(2); + if (!($key & 1)) { + // Else not a block to highlight + $endresult .= $this->hsc($parts[$key][1]); + unset($parts[$key]); + continue; + } + + $result = ''; + $part = $parts[$key][1]; + + $highlight_part = true; + if ($this->strict_mode && !is_null($parts[$key][0])) { + // get the class key for this block of code + $script_key = $parts[$key][0]; + $highlight_part = $this->language_data['HIGHLIGHT_STRICT_BLOCK'][$script_key]; + if ($this->language_data['STYLES']['SCRIPT'][$script_key] != '' && + $this->lexic_permissions['SCRIPT']) { + // Add a span element around the source to + // highlight the overall source block + if (!$this->use_classes && + $this->language_data['STYLES']['SCRIPT'][$script_key] != '') { + $attributes = ' style="' . $this->language_data['STYLES']['SCRIPT'][$script_key] . '"'; + } else { + $attributes = ' class="sc' . $script_key . '"'; + } + $result .= ""; + $STRICTATTRS = $attributes; + } + } + + if ($highlight_part) { + // Now, highlight the code in this block. This code + // is really the engine of GeSHi (along with the method + // parse_non_string_part). + + // cache comment regexps incrementally + $next_comment_regexp_key = ''; + $next_comment_regexp_pos = -1; + $next_comment_multi_pos = -1; + $next_comment_single_pos = -1; + $comment_regexp_cache_per_key = array(); + $comment_multi_cache_per_key = array(); + $comment_single_cache_per_key = array(); + $next_open_comment_multi = ''; + $next_comment_single_key = ''; + $escape_regexp_cache_per_key = array(); + $next_escape_regexp_key = ''; + $next_escape_regexp_pos = -1; + + $length = strlen($part); + for ($i = 0; $i < $length; ++$i) { + // Get the next char + $char = $part[$i]; + $char_len = 1; + + // update regexp comment cache if needed + if (isset($this->language_data['COMMENT_REGEXP']) && $next_comment_regexp_pos < $i) { + $next_comment_regexp_pos = $length; + foreach ($this->language_data['COMMENT_REGEXP'] as $comment_key => $regexp) { + $match_i = false; + if (isset($comment_regexp_cache_per_key[$comment_key]) && + ($comment_regexp_cache_per_key[$comment_key]['pos'] >= $i || + $comment_regexp_cache_per_key[$comment_key]['pos'] === false)) { + // we have already matched something + if ($comment_regexp_cache_per_key[$comment_key]['pos'] === false) { + // this comment is never matched + continue; + } + $match_i = $comment_regexp_cache_per_key[$comment_key]['pos']; + } else if ( + //This is to allow use of the offset parameter in preg_match and stay as compatible with older PHP versions as possible + (GESHI_PHP_PRE_433 && preg_match($regexp, substr($part, $i), $match, PREG_OFFSET_CAPTURE)) || + (!GESHI_PHP_PRE_433 && preg_match($regexp, $part, $match, PREG_OFFSET_CAPTURE, $i)) + ) { + $match_i = $match[0][1]; + if (GESHI_PHP_PRE_433) { + $match_i += $i; + } + + $comment_regexp_cache_per_key[$comment_key] = array( + 'key' => $comment_key, + 'length' => strlen($match[0][0]), + 'pos' => $match_i + ); + } else { + $comment_regexp_cache_per_key[$comment_key]['pos'] = false; + continue; + } + + if ($match_i !== false && $match_i < $next_comment_regexp_pos) { + $next_comment_regexp_pos = $match_i; + $next_comment_regexp_key = $comment_key; + if ($match_i === $i) { + break; + } } } } - if ($this->language_data['STYLES']['SCRIPT'][$script_key] != '' && - $this->lexic_permissions['SCRIPT']) { - // Add a span element around the source to - // highlight the overall source block - if (!$this->use_classes && - $this->language_data['STYLES']['SCRIPT'][$script_key] != '') { - $attributes = ' style="' . $this->language_data['STYLES']['SCRIPT'][$script_key] . '"'; - } - else { - $attributes = ' class="sc' . $script_key . '"'; - } - $result .= ""; - $STRICTATTRS = $attributes; - } - } + $string_started = false; - if (!$this->strict_mode || $this->language_data['HIGHLIGHT_STRICT_BLOCK'][$script_key]) { - // Now, highlight the code in this block. This code - // is really the engine of GeSHi (along with the method - // parse_non_string_part). - $length = strlen($part); - for ($i = 0; $i < $length; $i++) { - // Get the next char - $char = substr($part, $i, 1); - $hq = isset($this->language_data['HARDQUOTE']) ? $this->language_data['HARDQUOTE'][0] : false; - // Is this char the newline and line numbers being used? - if (($this->line_numbers != GESHI_NO_LINE_NUMBERS - || count($this->highlight_extra_lines) > 0) - && $char == "\n") { - // If so, is there a string open? If there is, we should end it before + if (isset($is_string_starter[$char])) { + // Possibly the start of a new string ... + + //Check which starter it was ... + //Fix for SF#1932083: Multichar Quotemarks unsupported + if (is_array($is_string_starter[$char])) { + $char_new = ''; + foreach ($is_string_starter[$char] as $testchar) { + if ($testchar === substr($part, $i, strlen($testchar)) && + strlen($testchar) > strlen($char_new)) { + $char_new = $testchar; + $string_started = true; + } + } + if ($string_started) { + $char = $char_new; + } + } else { + $testchar = $is_string_starter[$char]; + if ($testchar === substr($part, $i, strlen($testchar))) { + $char = $testchar; + $string_started = true; + } + } + $char_len = strlen($char); + } + + if ($string_started && ($i != $next_comment_regexp_pos)) { + // Hand out the correct style information for this string + $string_key = array_search($char, $this->language_data['QUOTEMARKS']); + if (!isset($this->language_data['STYLES']['STRINGS'][$string_key]) || + !isset($this->language_data['STYLES']['ESCAPE_CHAR'][$string_key])) { + $string_key = 0; + } + + // parse the stuff before this + $result .= $this->parse_non_string_part($stuff_to_parse); + $stuff_to_parse = ''; + + if (!$this->use_classes) { + $string_attributes = ' style="' . $this->language_data['STYLES']['STRINGS'][$string_key] . '"'; + } else { + $string_attributes = ' class="st'.$string_key.'"'; + } + + // now handle the string + $string = "" . GeSHi::hsc($char); + $start = $i + $char_len; + $string_open = true; + + if(empty($this->language_data['ESCAPE_REGEXP'])) { + $next_escape_regexp_pos = $length; + } + + do { + //Get the regular ending pos ... + $close_pos = strpos($part, $char, $start); + if(false === $close_pos) { + $close_pos = $length; + } + + if($this->lexic_permissions['ESCAPE_CHAR']) { + // update escape regexp cache if needed + if (isset($this->language_data['ESCAPE_REGEXP']) && $next_escape_regexp_pos < $start) { + $next_escape_regexp_pos = $length; + foreach ($this->language_data['ESCAPE_REGEXP'] as $escape_key => $regexp) { + $match_i = false; + if (isset($escape_regexp_cache_per_key[$escape_key]) && + ($escape_regexp_cache_per_key[$escape_key]['pos'] >= $start || + $escape_regexp_cache_per_key[$escape_key]['pos'] === false)) { + // we have already matched something + if ($escape_regexp_cache_per_key[$escape_key]['pos'] === false) { + // this comment is never matched + continue; + } + $match_i = $escape_regexp_cache_per_key[$escape_key]['pos']; + } else if ( + //This is to allow use of the offset parameter in preg_match and stay as compatible with older PHP versions as possible + (GESHI_PHP_PRE_433 && preg_match($regexp, substr($part, $start), $match, PREG_OFFSET_CAPTURE)) || + (!GESHI_PHP_PRE_433 && preg_match($regexp, $part, $match, PREG_OFFSET_CAPTURE, $start)) + ) { + $match_i = $match[0][1]; + if (GESHI_PHP_PRE_433) { + $match_i += $start; + } + + $escape_regexp_cache_per_key[$escape_key] = array( + 'key' => $escape_key, + 'length' => strlen($match[0][0]), + 'pos' => $match_i + ); + } else { + $escape_regexp_cache_per_key[$escape_key]['pos'] = false; + continue; + } + + if ($match_i !== false && $match_i < $next_escape_regexp_pos) { + $next_escape_regexp_pos = $match_i; + $next_escape_regexp_key = $escape_key; + if ($match_i === $start) { + break; + } + } + } + } + + //Find the next simple escape position + if('' != $this->language_data['ESCAPE_CHAR']) { + $simple_escape = strpos($part, $this->language_data['ESCAPE_CHAR'], $start); + if(false === $simple_escape) { + $simple_escape = $length; + } + } else { + $simple_escape = $length; + } + } else { + $next_escape_regexp_pos = $length; + $simple_escape = $length; + } + + if($simple_escape < $next_escape_regexp_pos && + $simple_escape < $length && + $simple_escape < $close_pos) { + //The nexxt escape sequence is a simple one ... + $es_pos = $simple_escape; + + //Add the stuff not in the string yet ... + $string .= $this->hsc(substr($part, $start, $es_pos - $start)); + + //Get the style for this escaped char ... + if (!$this->use_classes) { + $escape_char_attributes = ' style="' . $this->language_data['STYLES']['ESCAPE_CHAR'][0] . '"'; + } else { + $escape_char_attributes = ' class="es0"'; + } + + //Add the style for the escape char ... + $string .= "" . + GeSHi::hsc($this->language_data['ESCAPE_CHAR']); + + //Get the byte AFTER the ESCAPE_CHAR we just found + $es_char = $part[$es_pos + 1]; + if ($es_char == "\n") { + // don't put a newline around newlines + $string .= "\n"; + $start = $es_pos + 2; + } else if (ord($es_char) >= 128) { + //This is an non-ASCII char (UTF8 or single byte) + //This code tries to work around SF#2037598 ... + if(function_exists('mb_substr')) { + $es_char_m = mb_substr(substr($part, $es_pos+1, 16), 0, 1, $this->encoding); + $string .= $es_char_m . ''; + } else if (!GESHI_PHP_PRE_433 && 'utf-8' == $this->encoding) { + if(preg_match("/[\xC2-\xDF][\x80-\xBF]". + "|\xE0[\xA0-\xBF][\x80-\xBF]". + "|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}". + "|\xED[\x80-\x9F][\x80-\xBF]". + "|\xF0[\x90-\xBF][\x80-\xBF]{2}". + "|[\xF1-\xF3][\x80-\xBF]{3}". + "|\xF4[\x80-\x8F][\x80-\xBF]{2}/s", + $part, $es_char_m, null, $es_pos + 1)) { + $es_char_m = $es_char_m[0]; + } else { + $es_char_m = $es_char; + } + $string .= $this->hsc($es_char_m) . ''; + } else { + $es_char_m = $this->hsc($es_char); + } + $start = $es_pos + strlen($es_char_m) + 1; + } else { + $string .= $this->hsc($es_char) . ''; + $start = $es_pos + 2; + } + } else if ($next_escape_regexp_pos < $length && + $next_escape_regexp_pos < $close_pos) { + $es_pos = $next_escape_regexp_pos; + //Add the stuff not in the string yet ... + $string .= $this->hsc(substr($part, $start, $es_pos - $start)); + + //Get the key and length of this match ... + $escape = $escape_regexp_cache_per_key[$next_escape_regexp_key]; + $escape_str = substr($part, $es_pos, $escape['length']); + $escape_key = $escape['key']; + + //Get the style for this escaped char ... + if (!$this->use_classes) { + $escape_char_attributes = ' style="' . $this->language_data['STYLES']['ESCAPE_CHAR'][$escape_key] . '"'; + } else { + $escape_char_attributes = ' class="es' . $escape_key . '"'; + } + + //Add the style for the escape char ... + $string .= "" . + $this->hsc($escape_str) . ''; + + $start = $es_pos + $escape['length']; + } else { + //Copy the remainder of the string ... + $string .= $this->hsc(substr($part, $start, $close_pos - $start + $char_len)) . ''; + $start = $close_pos + $char_len; + $string_open = false; + } + } while($string_open); + + if ($check_linenumbers) { + // Are line numbers used? If, we should end the string before // the newline and begin it again (so when
      1. s are put in the source // remains XHTML compliant) // note to self: This opens up possibility of config files specifying // that languages can/cannot have multiline strings??? - if ($STRING_OPEN) { - if (!$this->use_classes) { - $attributes = ' style="' . $this->language_data['STYLES']['STRINGS'][0] . '"'; - } - else { - $attributes = ' class="st0"'; - } - $char = '' . $char . ""; - } + $string = str_replace("\n", "\n", $string); } - else if ($char == $STRING_OPEN) { - // A match of a string delimiter - if (($this->lexic_permissions['ESCAPE_CHAR'] && $ESCAPE_CHAR_OPEN) || - ($this->lexic_permissions['STRINGS'] && !$ESCAPE_CHAR_OPEN)) { - $char = GeSHi::hsc($char) . ''; - } - $escape_me = false; - if ($HARDQUOTE_OPEN) { - if ($ESCAPE_CHAR_OPEN) { - $escape_me = true; - } - else { - foreach ($this->language_data['HARDESCAPE'] as $hardesc) { - if (substr($part, $i, strlen($hardesc)) == $hardesc) { - $escape_me = true; - break; + + $result .= $string; + $string = ''; + $i = $start - 1; + continue; + } else if ($this->lexic_permissions['STRINGS'] && $hq && $hq[0] == $char && + substr($part, $i, $hq_strlen) == $hq && ($i != $next_comment_regexp_pos)) { + // The start of a hard quoted string + if (!$this->use_classes) { + $string_attributes = ' style="' . $this->language_data['STYLES']['STRINGS']['HARD'] . '"'; + $escape_char_attributes = ' style="' . $this->language_data['STYLES']['ESCAPE_CHAR']['HARD'] . '"'; + } else { + $string_attributes = ' class="st_h"'; + $escape_char_attributes = ' class="es_h"'; + } + // parse the stuff before this + $result .= $this->parse_non_string_part($stuff_to_parse); + $stuff_to_parse = ''; + + // now handle the string + $string = ''; + + // look for closing quote + $start = $i + $hq_strlen; + while ($close_pos = strpos($part, $this->language_data['HARDQUOTE'][1], $start)) { + $start = $close_pos + 1; + if ($this->lexic_permissions['ESCAPE_CHAR'] && $part[$close_pos - 1] == $this->language_data['HARDCHAR'] && + (($i + $hq_strlen) != ($close_pos))) { //Support empty string for HQ escapes if Starter = Escape + // make sure this quote is not escaped + foreach ($this->language_data['HARDESCAPE'] as $hardescape) { + if (substr($part, $close_pos - 1, strlen($hardescape)) == $hardescape) { + // check wether this quote is escaped or if it is something like '\\' + $escape_char_pos = $close_pos - 1; + while ($escape_char_pos > 0 + && $part[$escape_char_pos - 1] == $this->language_data['HARDCHAR']) { + --$escape_char_pos; + } + if (($close_pos - $escape_char_pos) & 1) { + // uneven number of escape chars => this quote is escaped + continue 2; } } } } - if (!$ESCAPE_CHAR_OPEN) { - $STRING_OPEN = ''; - $CLOSE_STRING = true; - } - if (!$escape_me) { - $HARDQUOTE_OPEN = false; - } - $ESCAPE_CHAR_OPEN = false; + // found closing quote + break; } - else if (in_array($char, $this->language_data['QUOTEMARKS']) && - ($STRING_OPEN == '') && $this->lexic_permissions['STRINGS']) { - // The start of a new string - $STRING_OPEN = $char; - if (!$this->use_classes) { - $attributes = ' style="' . $this->language_data['STYLES']['STRINGS'][0] . '"'; - } - else { - $attributes = ' class="st0"'; - } - $char = "" . GeSHi::hsc($char); - $result .= $this->parse_non_string_part( $stuff_to_parse ); - $stuff_to_parse = ''; + //Found the closing delimiter? + if (!$close_pos) { + // span till the end of this $part when no closing delimiter is found + $close_pos = $length; } - else if ($hq && substr($part, $i, strlen($hq)) == $hq && - ($STRING_OPEN == '') && $this->lexic_permissions['STRINGS']) { - // The start of a hard quoted string - $STRING_OPEN = $this->language_data['HARDQUOTE'][1]; - if (!$this->use_classes) { - $attributes = ' style="' . $this->language_data['STYLES']['STRINGS'][0] . '"'; + + //Get the actual string + $string = substr($part, $i, $close_pos - $i + 1); + $i = $close_pos; + + // handle escape chars and encode html chars + // (special because when we have escape chars within our string they may not be escaped) + if ($this->lexic_permissions['ESCAPE_CHAR'] && $this->language_data['ESCAPE_CHAR']) { + $start = 0; + $new_string = ''; + while ($es_pos = strpos($string, $this->language_data['ESCAPE_CHAR'], $start)) { + // hmtl escape stuff before + $new_string .= $this->hsc(substr($string, $start, $es_pos - $start)); + // check if this is a hard escape + foreach ($this->language_data['HARDESCAPE'] as $hardescape) { + if (substr($string, $es_pos, strlen($hardescape)) == $hardescape) { + // indeed, this is a hardescape + $new_string .= "" . + $this->hsc($hardescape) . ''; + $start = $es_pos + strlen($hardescape); + continue 2; + } + } + // not a hard escape, but a normal escape + // they come in pairs of two + $c = 0; + while (isset($string[$es_pos + $c]) && isset($string[$es_pos + $c + 1]) + && $string[$es_pos + $c] == $this->language_data['ESCAPE_CHAR'] + && $string[$es_pos + $c + 1] == $this->language_data['ESCAPE_CHAR']) { + $c += 2; + } + if ($c) { + $new_string .= "" . + str_repeat($escaped_escape_char, $c) . + ''; + $start = $es_pos + $c; + } else { + // this is just a single lonely escape char... + $new_string .= $escaped_escape_char; + $start = $es_pos + 1; + } } - else { - $attributes = ' class="st0"'; + $string = $new_string . $this->hsc(substr($string, $start)); + } else { + $string = $this->hsc($string); + } + + if ($check_linenumbers) { + // Are line numbers used? If, we should end the string before + // the newline and begin it again (so when
      2. s are put in the source + // remains XHTML compliant) + // note to self: This opens up possibility of config files specifying + // that languages can/cannot have multiline strings??? + $string = str_replace("\n", "\n", $string); + } + + $result .= "" . $string . ''; + $string = ''; + continue; + } else { + //Have a look for regexp comments + if ($i == $next_comment_regexp_pos) { + $COMMENT_MATCHED = true; + $comment = $comment_regexp_cache_per_key[$next_comment_regexp_key]; + $test_str = $this->hsc(substr($part, $i, $comment['length'])); + + //@todo If remove important do remove here + if ($this->lexic_permissions['COMMENTS']['MULTI']) { + if (!$this->use_classes) { + $attributes = ' style="' . $this->language_data['STYLES']['COMMENTS'][$comment['key']] . '"'; + } else { + $attributes = ' class="co' . $comment['key'] . '"'; + } + + $test_str = "" . $test_str . ""; + + // Short-cut through all the multiline code + if ($check_linenumbers) { + // strreplace to put close span and open span around multiline newlines + $test_str = str_replace( + "\n", "\n", + str_replace("\n ", "\n ", $test_str) + ); + } } - $char = "" . $hq; - $i += strlen($hq) - 1; - $HARDQUOTE_OPEN = true; + + $i += $comment['length'] - 1; + + // parse the rest $result .= $this->parse_non_string_part($stuff_to_parse); $stuff_to_parse = ''; } - else if ($char == $this->language_data['ESCAPE_CHAR'] && $STRING_OPEN != '') { - // An escape character - if (!$ESCAPE_CHAR_OPEN) { - $ESCAPE_CHAR_OPEN = !$HARDQUOTE_OPEN; // true unless $HARDQUOTE_OPEN - if ($HARDQUOTE_OPEN) { - foreach ($this->language_data['HARDESCAPE'] as $hard) { - if (substr($part, $i, strlen($hard)) == $hard) { - $ESCAPE_CHAR_OPEN = true; + + // If we haven't matched a regexp comment, try multi-line comments + if (!$COMMENT_MATCHED) { + // Is this a multiline comment? + if (!empty($this->language_data['COMMENT_MULTI']) && $next_comment_multi_pos < $i) { + $next_comment_multi_pos = $length; + foreach ($this->language_data['COMMENT_MULTI'] as $open => $close) { + $match_i = false; + if (isset($comment_multi_cache_per_key[$open]) && + ($comment_multi_cache_per_key[$open] >= $i || + $comment_multi_cache_per_key[$open] === false)) { + // we have already matched something + if ($comment_multi_cache_per_key[$open] === false) { + // this comment is never matched + continue; + } + $match_i = $comment_multi_cache_per_key[$open]; + } else if (($match_i = stripos($part, $open, $i)) !== false) { + $comment_multi_cache_per_key[$open] = $match_i; + } else { + $comment_multi_cache_per_key[$open] = false; + continue; + } + if ($match_i !== false && $match_i < $next_comment_multi_pos) { + $next_comment_multi_pos = $match_i; + $next_open_comment_multi = $open; + if ($match_i === $i) { break; } } } - if ($ESCAPE_CHAR_OPEN && $this->lexic_permissions['ESCAPE_CHAR']) { - if (!$this->use_classes) { - $attributes = ' style="' . $this->language_data['STYLES']['ESCAPE_CHAR'][0] . '"'; + } + if ($i == $next_comment_multi_pos) { + $open = $next_open_comment_multi; + $close = $this->language_data['COMMENT_MULTI'][$open]; + $open_strlen = strlen($open); + $close_strlen = strlen($close); + $COMMENT_MATCHED = true; + $test_str_match = $open; + //@todo If remove important do remove here + if ($this->lexic_permissions['COMMENTS']['MULTI'] || + $open == GESHI_START_IMPORTANT) { + if ($open != GESHI_START_IMPORTANT) { + if (!$this->use_classes) { + $attributes = ' style="' . $this->language_data['STYLES']['COMMENTS']['MULTI'] . '"'; + } else { + $attributes = ' class="coMULTI"'; + } + $test_str = "" . $this->hsc($open); + } else { + if (!$this->use_classes) { + $attributes = ' style="' . $this->important_styles . '"'; + } else { + $attributes = ' class="imp"'; + } + + // We don't include the start of the comment if it's an + // "important" part + $test_str = ""; } - else { - $attributes = ' class="es0"'; + } else { + $test_str = $this->hsc($open); + } + + $close_pos = strpos( $part, $close, $i + $open_strlen ); + + if ($close_pos === false) { + $close_pos = $length; + } + + // Short-cut through all the multiline code + $rest_of_comment = $this->hsc(substr($part, $i + $open_strlen, $close_pos - $i - $open_strlen + $close_strlen)); + if (($this->lexic_permissions['COMMENTS']['MULTI'] || + $test_str_match == GESHI_START_IMPORTANT) && + $check_linenumbers) { + + // strreplace to put close span and open span around multiline newlines + $test_str .= str_replace( + "\n", "\n", + str_replace("\n ", "\n ", $rest_of_comment) + ); + } else { + $test_str .= $rest_of_comment; + } + + if ($this->lexic_permissions['COMMENTS']['MULTI'] || + $test_str_match == GESHI_START_IMPORTANT) { + $test_str .= ''; + } + + $i = $close_pos + $close_strlen - 1; + + // parse the rest + $result .= $this->parse_non_string_part($stuff_to_parse); + $stuff_to_parse = ''; + } + } + + // If we haven't matched a multiline comment, try single-line comments + if (!$COMMENT_MATCHED) { + // cache potential single line comment occurances + if (!empty($this->language_data['COMMENT_SINGLE']) && $next_comment_single_pos < $i) { + $next_comment_single_pos = $length; + foreach ($this->language_data['COMMENT_SINGLE'] as $comment_key => $comment_mark) { + $match_i = false; + if (isset($comment_single_cache_per_key[$comment_key]) && + ($comment_single_cache_per_key[$comment_key] >= $i || + $comment_single_cache_per_key[$comment_key] === false)) { + // we have already matched something + if ($comment_single_cache_per_key[$comment_key] === false) { + // this comment is never matched + continue; + } + $match_i = $comment_single_cache_per_key[$comment_key]; + } else if ( + // case sensitive comments + ($this->language_data['CASE_SENSITIVE'][GESHI_COMMENTS] && + ($match_i = stripos($part, $comment_mark, $i)) !== false) || + // non case sensitive + (!$this->language_data['CASE_SENSITIVE'][GESHI_COMMENTS] && + (($match_i = strpos($part, $comment_mark, $i)) !== false))) { + $comment_single_cache_per_key[$comment_key] = $match_i; + } else { + $comment_single_cache_per_key[$comment_key] = false; + continue; } - $char = "" . $char; - if (substr($code, $i + 1, 1) == "\n") { - // escaping a newline, what's the point in putting the span around - // the newline? It only causes hassles when inserting line numbers - $char .= ''; - $ESCAPE_CHAR_OPEN = false; + if ($match_i !== false && $match_i < $next_comment_single_pos) { + $next_comment_single_pos = $match_i; + $next_comment_single_key = $comment_key; + if ($match_i === $i) { + break; + } } } } - else { - $ESCAPE_CHAR_OPEN = false; - if ($this->lexic_permissions['ESCAPE_CHAR']) { - $char .= ''; - } - } - } - else if ($ESCAPE_CHAR_OPEN) { - if ($this->lexic_permissions['ESCAPE_CHAR']) { - $char .= ''; - } - $ESCAPE_CHAR_OPEN = false; - $test_str = $char; - } - else if ($STRING_OPEN == '') { - // Is this a multiline comment? - foreach ($this->language_data['COMMENT_MULTI'] as $open => $close) { - $com_len = strlen($open); - $test_str = substr( $part, $i, $com_len ); - $test_str_match = $test_str; - if ($open == $test_str) { + if ($next_comment_single_pos == $i) { + $comment_key = $next_comment_single_key; + $comment_mark = $this->language_data['COMMENT_SINGLE'][$comment_key]; + $com_len = strlen($comment_mark); + + // This check will find special variables like $# in bash + // or compiler directives of Delphi beginning {$ + if ((empty($sc_disallowed_before) || ($i == 0) || + (false === strpos($sc_disallowed_before, $part[$i-1]))) && + (empty($sc_disallowed_after) || ($length <= $i + $com_len) || + (false === strpos($sc_disallowed_after, $part[$i + $com_len])))) + { + // this is a valid comment $COMMENT_MATCHED = true; - //@todo If remove important do remove here - if ($this->lexic_permissions['COMMENTS']['MULTI'] || - $test_str == GESHI_START_IMPORTANT) { - if ($test_str != GESHI_START_IMPORTANT) { - if (!$this->use_classes) { - $attributes = ' style="' . $this->language_data['STYLES']['COMMENTS']['MULTI'] . '"'; - } - else { - $attributes = ' class="coMULTI"'; - } - $test_str = "" . GeSHi::hsc($test_str); + if ($this->lexic_permissions['COMMENTS'][$comment_key]) { + if (!$this->use_classes) { + $attributes = ' style="' . $this->language_data['STYLES']['COMMENTS'][$comment_key] . '"'; + } else { + $attributes = ' class="co' . $comment_key . '"'; } - else { - if (!$this->use_classes) { - $attributes = ' style="' . $this->important_styles . '"'; - } - else { - $attributes = ' class="imp"'; - } - // We don't include the start of the comment if it's an - // "important" part - $test_str = ""; - } - } - else { - $test_str = GeSHi::hsc($test_str); + $test_str = "" . $this->hsc($this->change_case($comment_mark)); + } else { + $test_str = $this->hsc($comment_mark); } - $close_pos = strpos( $part, $close, $i + strlen($close) ); - + //Check if this comment is the last in the source + $close_pos = strpos($part, "\n", $i); $oops = false; if ($close_pos === false) { - $close_pos = strlen($part); + $close_pos = $length; $oops = true; } - else { - $close_pos -= ($com_len - strlen($close)); + $test_str .= $this->hsc(substr($part, $i + $com_len, $close_pos - $i - $com_len)); + if ($this->lexic_permissions['COMMENTS'][$comment_key]) { + $test_str .= ""; } - // Short-cut through all the multiline code - $rest_of_comment = GeSHi::hsc(substr($part, $i + $com_len, $close_pos - $i)); - if (($this->lexic_permissions['COMMENTS']['MULTI'] || - $test_str_match == GESHI_START_IMPORTANT) && - ($this->line_numbers != GESHI_NO_LINE_NUMBERS || - count($this->highlight_extra_lines) > 0)) { - // strreplace to put close span and open span around multiline newlines - $test_str .= str_replace( - "\n", "\n", - str_replace("\n ", "\n ", $rest_of_comment) - ); - } - else { - $test_str .= $rest_of_comment; + // Take into account that the comment might be the last in the source + if (!$oops) { + $test_str .= "\n"; } - if ($this->lexic_permissions['COMMENTS']['MULTI'] || - $test_str_match == GESHI_START_IMPORTANT) { - $test_str .= ''; - if ($oops) { - $test_str .= "\n"; - } - } - $i = $close_pos + $com_len - 1; + $i = $close_pos; + // parse the rest $result .= $this->parse_non_string_part($stuff_to_parse); $stuff_to_parse = ''; - break; } } - // If we haven't matched a multiline comment, try single-line comments - if (!$COMMENT_MATCHED) { - foreach ($this->language_data['COMMENT_SINGLE'] as $comment_key => $comment_mark) { - $com_len = strlen($comment_mark); - $test_str = substr($part, $i, $com_len); - if ($this->language_data['CASE_SENSITIVE'][GESHI_COMMENTS]) { - $match = ($comment_mark == $test_str); - } - else { - $match = (strtolower($comment_mark) == strtolower($test_str)); - } - if ($match) { - $COMMENT_MATCHED = true; - if ($this->lexic_permissions['COMMENTS'][$comment_key]) { - if (!$this->use_classes) { - $attributes = ' style="' . $this->language_data['STYLES']['COMMENTS'][$comment_key] . '"'; - } - else { - $attributes = ' class="co' . $comment_key . '"'; - } - $test_str = "" . GeSHi::hsc($this->change_case($test_str)); - } - else { - $test_str = GeSHi::hsc($test_str); - } - $close_pos = strpos($part, "\n", $i); - $oops = false; - if ($close_pos === false) { - $close_pos = strlen($part); - $oops = true; - } - $test_str .= GeSHi::hsc(substr($part, $i + $com_len, $close_pos - $i - $com_len)); - if ($this->lexic_permissions['COMMENTS'][$comment_key]) { - $test_str .= ""; - } - // Take into account that the comment might be the last in the source - if (!$oops) { - $test_str .= "\n"; - } - $i = $close_pos; - // parse the rest - $result .= $this->parse_non_string_part($stuff_to_parse); - $stuff_to_parse = ''; - break; - } - } - } - } - else if ($STRING_OPEN != '') { - // Otherwise, convert it to HTML form - if (strtolower($this->encoding) == 'utf-8') { - //only escape <128 (we don't want to break multibyte chars) - if (ord($char) < 128) { - $char = GeSHi::hsc($char); - } - } - else { - //encode everthing - $char = GeSHi::hsc($char); - } - } - // Where are we adding this char? - if (!$COMMENT_MATCHED) { - if (($STRING_OPEN == '') && !$CLOSE_STRING) { - $stuff_to_parse .= $char; - } - else { - $result .= $char; - $CLOSE_STRING = false; - } - } - else { - $result .= $test_str; - $COMMENT_MATCHED = false; } } - // Parse the last bit - $result .= $this->parse_non_string_part($stuff_to_parse); - $stuff_to_parse = ''; - } - else { - if ($STRICTATTRS != '') { - $part = str_replace("\n", "\n", GeSHi::hsc($part)); - $STRICTATTRS = ''; + + // Where are we adding this char? + if (!$COMMENT_MATCHED) { + $stuff_to_parse .= $char; + } else { + $result .= $test_str; + unset($test_str); + $COMMENT_MATCHED = false; } - $result .= $part; - } - // Close the that surrounds the block - if ($this->strict_mode && $this->language_data['STYLES']['SCRIPT'][$script_key] != '' && - $this->lexic_permissions['SCRIPT']) { - $result .= ''; } + // Parse the last bit + $result .= $this->parse_non_string_part($stuff_to_parse); + $stuff_to_parse = ''; + } else { + $result .= $this->hsc($part); } - else { - // Else not a block to highlight - $result .= GeSHi::hsc($part); + // Close the that surrounds the block + if ($STRICTATTRS != '') { + $result = str_replace("\n", "\n", $result); + $result .= ''; } + + $endresult .= $result; + unset($part, $parts[$key], $result); } - // Parse the last stuff (redundant?) - $result .= $this->parse_non_string_part($stuff_to_parse); + //This fix is related to SF#1923020, but has to be applied regardless of + //actually highlighting symbols. + /** NOTE: memorypeak #3 */ + $endresult = str_replace(array('', ''), array(';', '|'), $endresult); + +// // Parse the last stuff (redundant?) +// $result .= $this->parse_non_string_part($stuff_to_parse); // Lop off the very first and last spaces - $result = substr($result, 1, -1); - - // Are we still in a string? - if ($STRING_OPEN) { - $result .= ''; - } +// $result = substr($result, 1, -1); // We're finished: stop timing $this->set_time($start_time, microtime()); - return $this->finalise($result); + $this->finalise($endresult); + return $endresult; } /** * Swaps out spaces and tabs for HTML indentation. Not needed if * the code is in a pre block... * - * @param string The source to indent - * @return string The source with HTML indenting applied + * @param string The source to indent (reference!) * @since 1.0.0 * @access private */ - function indent($result) { + function indent(&$result) { /// Replace tabs with the correct number of spaces if (false !== strpos($result, "\t")) { $lines = explode("\n", $result); - $tab_width = $this->get_real_tab_width(); - foreach ($lines as $key => $line) { + $result = null;//Save memory while we process the lines individually + $tab_width = $this->get_real_tab_width(); + $tab_string = ' ' . str_repeat(' ', $tab_width); + + for ($key = 0, $n = count($lines); $key < $n; $key++) { + $line = $lines[$key]; if (false === strpos($line, "\t")) { - $lines[$key] = $line; continue; } $pos = 0; $length = strlen($line); - $result_line = ''; + $lines[$key] = ''; // reduce memory $IN_TAG = false; - for ($i = 0; $i < $length; $i++) { - $char = substr($line, $i, 1); + for ($i = 0; $i < $length; ++$i) { + $char = $line[$i]; // Simple engine to work out whether we're in a tag. // If we are we modify $pos. This is so we ignore HTML // in the line and only workout the tab replacement @@ -1928,26 +3135,24 @@ class GeSHi { // This test could be improved to include strings in the // html so that < or > would be allowed in user's styles // (e.g. quotes: '<' '>'; or similar) - if ($IN_TAG && '>' == $char) { - $IN_TAG = false; - $result_line .= '>'; - ++$pos; - } - else if (!$IN_TAG && '<' == $char) { - $IN_TAG = true; - $result_line .= '<'; - ++$pos; - } - else if (!$IN_TAG && '&' == $char) { - $substr = substr($line, $i + 3, 4); - //$substr_5 = substr($line, 5, 1); - $posi = strpos($substr, ';'); - if (false !== $posi) { - $pos += $posi + 3; + if ($IN_TAG) { + if ('>' == $char) { + $IN_TAG = false; } - $result_line .= '&'; - } - else if (!$IN_TAG && "\t" == $char) { + $lines[$key] .= $char; + } else if ('<' == $char) { + $IN_TAG = true; + $lines[$key] .= '<'; + } else if ('&' == $char) { + $substr = substr($line, $i + 3, 5); + $posi = strpos($substr, ';'); + if (false === $posi) { + ++$pos; + } else { + $pos -= $posi+2; + } + $lines[$key] .= $char; + } else if ("\t" == $char) { $str = ''; // OPTIMISE - move $strs out. Make an array: // $tabs = array( @@ -1955,42 +3160,43 @@ class GeSHi { // 2 => '  ', // 3 => '   ' etc etc // to use instead of building a string every time - $strs = array(0 => ' ', 1 => ' '); - for ($k = 0; $k < ($tab_width - (($i - $pos) % $tab_width)); $k++) $str .= $strs[$k % 2]; - $result_line .= $str; - $pos += ($i - $pos) % $tab_width + 1; + $tab_end_width = $tab_width - ($pos % $tab_width); //Moved out of the look as it doesn't change within the loop + if (($pos & 1) || 1 == $tab_end_width) { + $str .= substr($tab_string, 6, $tab_end_width); + } else { + $str .= substr($tab_string, 0, $tab_end_width+5); + } + $lines[$key] .= $str; + $pos += $tab_end_width; if (false === strpos($line, "\t", $i + 1)) { - $result_line .= substr($line, $i + 1); + $lines[$key] .= substr($line, $i + 1); break; } - } - else if ($IN_TAG) { + } else if (0 == $pos && ' ' == $char) { + $lines[$key] .= ' '; + ++$pos; + } else { + $lines[$key] .= $char; ++$pos; - $result_line .= $char; - } - else { - $result_line .= $char; - //++$pos; } } - $lines[$key] = $result_line; } $result = implode("\n", $lines); + unset($lines);//We don't need the lines separated beyond this --- free them! } // Other whitespace // BenBE: Fix to reduce the number of replacements to be done - $result = str_replace("\n ", "\n ", $result); + $result = preg_replace('/^ /m', ' ', $result); $result = str_replace(' ', '  ', $result); - if ($this->line_numbers == GESHI_NO_LINE_NUMBERS) { - if ($this->line_ending === null) { - $result = nl2br($result); - } else { - $result = str_replace("\n", $this->line_ending, $result); - } - } - return $result; + if ($this->line_numbers == GESHI_NO_LINE_NUMBERS && $this->header_type != GESHI_HEADER_PRE_TABLE) { + if ($this->line_ending === null) { + $result = nl2br($result); + } else { + $result = str_replace("\n", $this->line_ending, $result); + } + } } /** @@ -2002,65 +3208,122 @@ class GeSHi { * @access private */ function change_case($instr) { - if ($this->language_data['CASE_KEYWORDS'] == GESHI_CAPS_UPPER) { - return strtoupper($instr); + switch ($this->language_data['CASE_KEYWORDS']) { + case GESHI_CAPS_UPPER: + return strtoupper($instr); + case GESHI_CAPS_LOWER: + return strtolower($instr); + default: + return $instr; } - else if ($this->language_data['CASE_KEYWORDS'] == GESHI_CAPS_LOWER) { - return strtolower($instr); - } - return $instr; } /** - * Adds a url to a keyword where needed. + * Handles replacements of keywords to include markup and links if requested * - * @param string The keyword to add the URL HTML to - * @param int What group the keyword is from - * @param boolean Whether to get the HTML for the start or end - * @return The HTML for either the start or end of the HTML <a> tag - * @since 1.0.2 + * @param string The keyword to add the Markup to + * @return The HTML for the match found + * @since 1.0.8 * @access private - * @todo Get rid of ender + * + * @todo Get rid of ender in keyword links */ - function add_url_to_keyword($keyword, $group, $start_or_end) { - if (!$this->keyword_links) { - // Keyword links have been disabled - return; - } + function handle_keyword_replace($match) { + $k = $this->_kw_replace_group; + $keyword = $match[0]; - if (isset($this->language_data['URLS'][$group]) && - $this->language_data['URLS'][$group] != '' && - substr($keyword, 0, 5) != '</') { - // There is a base group for this keyword - if ($start_or_end == 'BEGIN') { - // HTML workaround... not good form (tm) but should work for 1.0.X - if ($keyword != '') { - // Old system: strtolower - //$keyword = ( $this->language_data['CASE_SENSITIVE'][$group] ) ? $keyword : strtolower($keyword); - // New system: get keyword from language file to get correct case - foreach ($this->language_data['KEYWORDS'][$group] as $word) { - if (strtolower($word) == strtolower($keyword)) { + $before = ''; + $after = ''; + + if ($this->keyword_links) { + // Keyword links have been ebabled + + if (isset($this->language_data['URLS'][$k]) && + $this->language_data['URLS'][$k] != '') { + // There is a base group for this keyword + + // Old system: strtolower + //$keyword = ( $this->language_data['CASE_SENSITIVE'][$group] ) ? $keyword : strtolower($keyword); + // New system: get keyword from language file to get correct case + if (!$this->language_data['CASE_SENSITIVE'][$k] && + strpos($this->language_data['URLS'][$k], '{FNAME}') !== false) { + foreach ($this->language_data['KEYWORDS'][$k] as $word) { + if (strcasecmp($word, $keyword) == 0) { break; } } - $word = ( substr($word, 0, 4) == '<' ) ? substr($word, 4) : $word; - $word = ( substr($word, -4) == '>' ) ? substr($word, 0, strlen($word) - 4) : $word; - if (!$word) return ''; - - return '<|UR1|"' . - str_replace( - array('{FNAME}', '.'), - array(GeSHi::hsc($word), ''), - $this->language_data['URLS'][$group] - ) . '">'; + } else { + $word = $keyword; } - return ''; - // HTML fix. Again, dirty hackage... - } - else if (!($this->language == 'html4strict' && ('>' == $keyword || '<' == $keyword))) { - return ''; + + $before = '<|UR1|"' . + str_replace( + array( + '{FNAME}', + '{FNAMEL}', + '{FNAMEU}', + '.'), + array( + str_replace('+', '%20', urlencode($this->hsc($word))), + str_replace('+', '%20', urlencode($this->hsc(strtolower($word)))), + str_replace('+', '%20', urlencode($this->hsc(strtoupper($word)))), + ''), + $this->language_data['URLS'][$k] + ) . '">'; + $after = ''; } } + + return $before . '<|/'. $k .'/>' . $this->change_case($keyword) . '|>' . $after; + } + + /** + * handles regular expressions highlighting-definitions with callback functions + * + * @note this is a callback, don't use it directly + * + * @param array the matches array + * @return The highlighted string + * @since 1.0.8 + * @access private + */ + function handle_regexps_callback($matches) { + // before: "' style=\"' . call_user_func(\"$func\", '\\1') . '\"\\1|>'", + return ' style="' . call_user_func($this->language_data['STYLES']['REGEXPS'][$this->_rx_key], $matches[1]) . '"'. $matches[1] . '|>'; + } + + /** + * handles newlines in REGEXPS matches. Set the _hmr_* vars before calling this + * + * @note this is a callback, don't use it directly + * + * @param array the matches array + * @return string + * @since 1.0.8 + * @access private + */ + function handle_multiline_regexps($matches) { + $before = $this->_hmr_before; + $after = $this->_hmr_after; + if ($this->_hmr_replace) { + $replace = $this->_hmr_replace; + $search = array(); + + foreach (array_keys($matches) as $k) { + $search[] = '\\' . $k; + } + + $before = str_replace($search, $matches, $before); + $after = str_replace($search, $matches, $after); + $replace = str_replace($search, $matches, $replace); + } else { + $replace = $matches[0]; + } + return $before + . '<|!REG3XP' . $this->_hmr_key .'!>' + . str_replace("\n", "|>\n<|!REG3XP" . $this->_hmr_key . '!>', $replace) + . '|>' + . $after; } /** @@ -2072,123 +3335,186 @@ class GeSHi { * @access private * @todo BUGGY! Why? Why not build string and return? */ - function parse_non_string_part(&$stuff_to_parse) { - $stuff_to_parse = ' ' . GeSHi::hsc($stuff_to_parse); - $stuff_to_parse_pregquote = preg_quote($stuff_to_parse, '/'); - $func = '$this->change_case'; - $func2 = '$this->add_url_to_keyword'; + function parse_non_string_part($stuff_to_parse) { + $stuff_to_parse = ' ' . $this->hsc($stuff_to_parse); - // - // Regular expressions - // - foreach ($this->language_data['REGEXPS'] as $key => $regexp) { - if ($this->lexic_permissions['REGEXPS'][$key]) { - if (is_array($regexp)) { - $stuff_to_parse = preg_replace( - "/" . - str_replace('/', '\/', $regexp[GESHI_SEARCH]) . - "/{$regexp[GESHI_MODIFIERS]}", - "{$regexp[GESHI_BEFORE]}<|!REG3XP$key!>{$regexp[GESHI_REPLACE]}|>{$regexp[GESHI_AFTER]}", - $stuff_to_parse - ); + // Highlight keywords + $disallowed_before = "(?lexic_permissions['STRINGS']) { + $quotemarks = preg_quote(implode($this->language_data['QUOTEMARKS']), '/'); + $disallowed_before .= $quotemarks; + $disallowed_after .= $quotemarks; + } + $disallowed_before .= "])"; + $disallowed_after .= "])"; + + $parser_control_pergroup = false; + if (isset($this->language_data['PARSER_CONTROL'])) { + if (isset($this->language_data['PARSER_CONTROL']['KEYWORDS'])) { + $x = 0; // check wether per-keyword-group parser_control is enabled + if (isset($this->language_data['PARSER_CONTROL']['KEYWORDS']['DISALLOWED_BEFORE'])) { + $disallowed_before = $this->language_data['PARSER_CONTROL']['KEYWORDS']['DISALLOWED_BEFORE']; + ++$x; } - else { - $stuff_to_parse = preg_replace( "/(" . str_replace('/', '\/', $regexp) . ")/", "<|!REG3XP$key!>\\1|>", $stuff_to_parse); + if (isset($this->language_data['PARSER_CONTROL']['KEYWORDS']['DISALLOWED_AFTER'])) { + $disallowed_after = $this->language_data['PARSER_CONTROL']['KEYWORDS']['DISALLOWED_AFTER']; + ++$x; + } + $parser_control_pergroup = (count($this->language_data['PARSER_CONTROL']['KEYWORDS']) - $x) > 0; + } + } + + foreach (array_keys($this->language_data['KEYWORDS']) as $k) { + if (!isset($this->lexic_permissions['KEYWORDS'][$k]) || + $this->lexic_permissions['KEYWORDS'][$k]) { + + $case_sensitive = $this->language_data['CASE_SENSITIVE'][$k]; + $modifiers = $case_sensitive ? '' : 'i'; + + // NEW in 1.0.8 - per-keyword-group parser control + $disallowed_before_local = $disallowed_before; + $disallowed_after_local = $disallowed_after; + if ($parser_control_pergroup && isset($this->language_data['PARSER_CONTROL']['KEYWORDS'][$k])) { + if (isset($this->language_data['PARSER_CONTROL']['KEYWORDS'][$k]['DISALLOWED_BEFORE'])) { + $disallowed_before_local = + $this->language_data['PARSER_CONTROL']['KEYWORDS'][$k]['DISALLOWED_BEFORE']; + } + + if (isset($this->language_data['PARSER_CONTROL']['KEYWORDS'][$k]['DISALLOWED_AFTER'])) { + $disallowed_after_local = + $this->language_data['PARSER_CONTROL']['KEYWORDS'][$k]['DISALLOWED_AFTER']; + } + } + + $this->_kw_replace_group = $k; + + //NEW in 1.0.8, the cached regexp list + // since we don't want PHP / PCRE to crash due to too large patterns we split them into smaller chunks + for ($set = 0, $set_length = count($this->language_data['CACHED_KEYWORD_LISTS'][$k]); $set < $set_length; ++$set) { + $keywordset =& $this->language_data['CACHED_KEYWORD_LISTS'][$k][$set]; + // Might make a more unique string for putting the number in soon + // Basically, we don't put the styles in yet because then the styles themselves will + // get highlighted if the language has a CSS keyword in it (like CSS, for example ;)) + $stuff_to_parse = preg_replace_callback( + "/$disallowed_before_local({$keywordset})(?!\(?:htm|php|aspx?))$disallowed_after_local/$modifiers", + array($this, 'handle_keyword_replace'), + $stuff_to_parse + ); } } } - // - // Highlight numbers. This regexp sucks... anyone with a regexp that WORKS - // here wins a cookie if they send it to me. At the moment there's two doing - // almost exactly the same thing, except the second one prevents a number - // being highlighted twice (eg 5) - // Put /NUM!/ in for the styles, which gets replaced at the end. - // - // NEW ONE: Brice Bernard - // - if ($this->lexic_permissions['NUMBERS'] && preg_match('#[0-9]#', $stuff_to_parse )) { - $stuff_to_parse = preg_replace('/([-+]?\\b(?:[0-9]*\\.)?[0-9]+\\b)/', '<|/NUM!/>\\1|>', $stuff_to_parse); - } - - // Highlight keywords - // if there is a couple of alpha symbols there *might* be a keyword - if (preg_match('#[a-zA-Z]{2,}#', $stuff_to_parse)) { - foreach ($this->language_data['KEYWORDS'] as $k => $keywordset) { - if ($this->lexic_permissions['KEYWORDS'][$k]) { - foreach ($keywordset as $keyword) { - $keyword = preg_quote($keyword, '/'); - // - // This replacement checks the word is on it's own (except if brackets etc - // are next to it), then highlights it. We don't put the color=" for the span - // in just yet - otherwise languages with the keywords "color" or "or" have - // a fit. - // - if (false !== stristr($stuff_to_parse_pregquote, $keyword )) { - $stuff_to_parse .= ' '; - // Might make a more unique string for putting the number in soon - // Basically, we don't put the styles in yet because then the styles themselves will - // get highlighted if the language has a CSS keyword in it (like CSS, for example ;)) - $styles = "/$k/"; - if ($this->language_data['CASE_SENSITIVE'][$k]) { - $stuff_to_parse = preg_replace( - "/([^a-zA-Z0-9\$_\|\#;>|^])($keyword)(?=[^a-zA-Z0-9_<\|%\-&])/e", - "'\\1' . $func2('\\2', '$k', 'BEGIN') . '<|$styles>' . $func('\\2') . '|>' . $func2('\\2', '$k', 'END')", - $stuff_to_parse - ); - } - else { - // Change the case of the word. - // hackage again... must... release... 1.2... - if ('smarty' == $this->language) { $hackage = '\/'; } else { $hackage = ''; } - $stuff_to_parse = preg_replace( - "/([^a-zA-Z0-9\$_\|\#;>$hackage|^])($keyword)(?=[^a-zA-Z0-9_<\|%\-&])/ie", - "'\\1' . $func2('\\2', '$k', 'BEGIN') . '<|$styles>' . $func('\\2') . '|>' . $func2('\\2', '$k', 'END')", - $stuff_to_parse - ); - } - $stuff_to_parse = substr($stuff_to_parse, 0, strlen($stuff_to_parse) - 1); - } + // Regular expressions + foreach ($this->language_data['REGEXPS'] as $key => $regexp) { + if ($this->lexic_permissions['REGEXPS'][$key]) { + if (is_array($regexp)) { + if ($this->line_numbers != GESHI_NO_LINE_NUMBERS) { + // produce valid HTML when we match multiple lines + $this->_hmr_replace = $regexp[GESHI_REPLACE]; + $this->_hmr_before = $regexp[GESHI_BEFORE]; + $this->_hmr_key = $key; + $this->_hmr_after = $regexp[GESHI_AFTER]; + $stuff_to_parse = preg_replace_callback( + "/" . $regexp[GESHI_SEARCH] . "/{$regexp[GESHI_MODIFIERS]}", + array($this, 'handle_multiline_regexps'), + $stuff_to_parse); + $this->_hmr_replace = false; + $this->_hmr_before = ''; + $this->_hmr_after = ''; + } else { + $stuff_to_parse = preg_replace( + '/' . $regexp[GESHI_SEARCH] . '/' . $regexp[GESHI_MODIFIERS], + $regexp[GESHI_BEFORE] . '<|!REG3XP'. $key .'!>' . $regexp[GESHI_REPLACE] . '|>' . $regexp[GESHI_AFTER], + $stuff_to_parse); + } + } else { + if ($this->line_numbers != GESHI_NO_LINE_NUMBERS) { + // produce valid HTML when we match multiple lines + $this->_hmr_key = $key; + $stuff_to_parse = preg_replace_callback( "/(" . $regexp . ")/", + array($this, 'handle_multiline_regexps'), $stuff_to_parse); + $this->_hmr_key = ''; + } else { + $stuff_to_parse = preg_replace( "/(" . $regexp . ")/", "<|!REG3XP$key!>\\1|>", $stuff_to_parse); } } } } + // Highlight numbers. As of 1.0.8 we support different types of numbers + $numbers_found = false; + + if ($this->lexic_permissions['NUMBERS'] && preg_match($this->language_data['PARSER_CONTROL']['NUMBERS']['PRECHECK_RX'], $stuff_to_parse )) { + $numbers_found = true; + + //For each of the formats ... + foreach($this->language_data['NUMBERS_RXCACHE'] as $id => $regexp) { + //Check if it should be highlighted ... + $stuff_to_parse = preg_replace($regexp, "<|/NUM!$id/>\\1|>", $stuff_to_parse); + } + } + // // Now that's all done, replace /[number]/ with the correct styles // - foreach ($this->language_data['KEYWORDS'] as $k => $kws) { + foreach (array_keys($this->language_data['KEYWORDS']) as $k) { if (!$this->use_classes) { - $attributes = ' style="' . $this->language_data['STYLES']['KEYWORDS'][$k] . '"'; - } - else { + $attributes = ' style="' . + (isset($this->language_data['STYLES']['KEYWORDS'][$k]) ? + $this->language_data['STYLES']['KEYWORDS'][$k] : "") . '"'; + } else { $attributes = ' class="kw' . $k . '"'; } - $stuff_to_parse = str_replace("/$k/", $attributes, $stuff_to_parse); + $stuff_to_parse = str_replace("<|/$k/>", "<|$attributes>", $stuff_to_parse); } - // Put number styles in - if (!$this->use_classes && $this->lexic_permissions['NUMBERS']) { - $attributes = ' style="' . $this->language_data['STYLES']['NUMBERS'][0] . '"'; - } - else { - $attributes = ' class="nu0"'; - } - $stuff_to_parse = str_replace('/NUM!/', $attributes, $stuff_to_parse); + if ($numbers_found) { + // Put number styles in + foreach($this->language_data['NUMBERS_RXCACHE'] as $id => $regexp) { + //Commented out for now, as this needs some review ... + // if ($numbers_permissions & $id) { + //Get the appropriate style ... + //Checking for unset styles is done by the style cache builder ... + if (!$this->use_classes) { + $attributes = ' style="' . $this->language_data['STYLES']['NUMBERS'][$id] . '"'; + } else { + $attributes = ' class="nu'.$id.'"'; + } + + //Set in the correct styles ... + $stuff_to_parse = str_replace("/NUM!$id/", $attributes, $stuff_to_parse); + // } + } + } - // // Highlight methods and fields in objects - // if ($this->lexic_permissions['METHODS'] && $this->language_data['OOLANG']) { + $oolang_spaces = "[\s]*"; + $oolang_before = ""; + $oolang_after = "[a-zA-Z][a-zA-Z0-9_]*"; + if (isset($this->language_data['PARSER_CONTROL'])) { + if (isset($this->language_data['PARSER_CONTROL']['OOLANG'])) { + if (isset($this->language_data['PARSER_CONTROL']['OOLANG']['MATCH_BEFORE'])) { + $oolang_before = $this->language_data['PARSER_CONTROL']['OOLANG']['MATCH_BEFORE']; + } + if (isset($this->language_data['PARSER_CONTROL']['OOLANG']['MATCH_AFTER'])) { + $oolang_after = $this->language_data['PARSER_CONTROL']['OOLANG']['MATCH_AFTER']; + } + if (isset($this->language_data['PARSER_CONTROL']['OOLANG']['MATCH_SPACES'])) { + $oolang_spaces = $this->language_data['PARSER_CONTROL']['OOLANG']['MATCH_SPACES']; + } + } + } + foreach ($this->language_data['OBJECT_SPLITTERS'] as $key => $splitter) { - if (false !== stristr($stuff_to_parse, $splitter)) { + if (false !== strpos($stuff_to_parse, $splitter)) { if (!$this->use_classes) { $attributes = ' style="' . $this->language_data['STYLES']['METHODS'][$key] . '"'; - } - else { + } else { $attributes = ' class="me' . $key . '"'; } - $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); + $stuff_to_parse = preg_replace("/($oolang_before)(" . preg_quote($this->language_data['OBJECT_SPLITTERS'][$key], '/') . ")($oolang_spaces)($oolang_after)/", "\\1\\2\\3<|$attributes>\\4|>", $stuff_to_parse); } } } @@ -2200,49 +3526,104 @@ class GeSHi { // be highlighting regardless // if ($this->lexic_permissions['BRACKETS']) { - $code_entities_match = array('[', ']', '(', ')', '{', '}'); - if (!$this->use_classes) { - $code_entities_replace = array( - '<| style="' . $this->language_data['STYLES']['BRACKETS'][0] . '">[|>', - '<| style="' . $this->language_data['STYLES']['BRACKETS'][0] . '">]|>', - '<| style="' . $this->language_data['STYLES']['BRACKETS'][0] . '">(|>', - '<| style="' . $this->language_data['STYLES']['BRACKETS'][0] . '">)|>', - '<| style="' . $this->language_data['STYLES']['BRACKETS'][0] . '">{|>', - '<| style="' . $this->language_data['STYLES']['BRACKETS'][0] . '">}|>', - ); - } - else { - $code_entities_replace = array( - '<| class="br0">[|>', - '<| class="br0">]|>', - '<| class="br0">(|>', - '<| class="br0">)|>', - '<| class="br0">{|>', - '<| class="br0">}|>', - ); - } - $stuff_to_parse = str_replace( $code_entities_match, $code_entities_replace, $stuff_to_parse ); + $stuff_to_parse = str_replace( $this->language_data['CACHE_BRACKET_MATCH'], + $this->language_data['CACHE_BRACKET_REPLACE'], $stuff_to_parse ); } - // + + //FIX for symbol highlighting ... + if ($this->lexic_permissions['SYMBOLS'] && !empty($this->language_data['SYMBOLS'])) { + //Get all matches and throw away those witin a block that is already highlighted... (i.e. matched by a regexp) + $n_symbols = preg_match_all("/<\|(?:|[^>])+>(?:(?!\|>).*?)\|>|<\/a>|(?:" . $this->language_data['SYMBOL_SEARCH'] . ")+(?![^<]+?>)/", $stuff_to_parse, $pot_symbols, PREG_OFFSET_CAPTURE | PREG_SET_ORDER); + $global_offset = 0; + for ($s_id = 0; $s_id < $n_symbols; ++$s_id) { + $symbol_match = $pot_symbols[$s_id][0][0]; + if (strpos($symbol_match, '<') !== false || strpos($symbol_match, '>') !== false) { + // already highlighted blocks _must_ include either < or > + // so if this conditional applies, we have to skip this match + // BenBE: UNLESS the block contains or + if(strpos($symbol_match, '') === false && + strpos($symbol_match, '') === false) { + continue; + } + } + + // if we reach this point, we have a valid match which needs to be highlighted + + $symbol_length = strlen($symbol_match); + $symbol_offset = $pot_symbols[$s_id][0][1]; + unset($pot_symbols[$s_id]); + $symbol_end = $symbol_length + $symbol_offset; + $symbol_hl = ""; + + // if we have multiple styles, we have to handle them properly + if ($this->language_data['MULTIPLE_SYMBOL_GROUPS']) { + $old_sym = -1; + // Split the current stuff to replace into its atomic symbols ... + preg_match_all("/" . $this->language_data['SYMBOL_SEARCH'] . "/", $symbol_match, $sym_match_syms, PREG_PATTERN_ORDER); + foreach ($sym_match_syms[0] as $sym_ms) { + //Check if consequtive symbols belong to the same group to save output ... + if (isset($this->language_data['SYMBOL_DATA'][$sym_ms]) + && ($this->language_data['SYMBOL_DATA'][$sym_ms] != $old_sym)) { + if (-1 != $old_sym) { + $symbol_hl .= "|>"; + } + $old_sym = $this->language_data['SYMBOL_DATA'][$sym_ms]; + if (!$this->use_classes) { + $symbol_hl .= '<| style="' . $this->language_data['STYLES']['SYMBOLS'][$old_sym] . '">'; + } else { + $symbol_hl .= '<| class="sy' . $old_sym . '">'; + } + } + $symbol_hl .= $sym_ms; + } + unset($sym_match_syms); + + //Close remaining tags and insert the replacement at the right position ... + //Take caution if symbol_hl is empty to avoid doubled closing spans. + if (-1 != $old_sym) { + $symbol_hl .= "|>"; + } + } else { + if (!$this->use_classes) { + $symbol_hl = '<| style="' . $this->language_data['STYLES']['SYMBOLS'][0] . '">'; + } else { + $symbol_hl = '<| class="sy0">'; + } + $symbol_hl .= $symbol_match . '|>'; + } + + $stuff_to_parse = substr_replace($stuff_to_parse, $symbol_hl, $symbol_offset + $global_offset, $symbol_length); + + // since we replace old text with something of different size, + // we'll have to keep track of the differences + $global_offset += strlen($symbol_hl) - $symbol_length; + } + } + //FIX for symbol highlighting ... + // Add class/style for regexps - // - foreach ($this->language_data['REGEXPS'] as $key => $regexp) { + foreach (array_keys($this->language_data['REGEXPS']) as $key) { if ($this->lexic_permissions['REGEXPS'][$key]) { - if (!$this->use_classes) { - $attributes = ' style="' . $this->language_data['STYLES']['REGEXPS'][$key] . '"'; - } - else { - if(is_array($this->language_data['REGEXPS'][$key]) && + if (is_callable($this->language_data['STYLES']['REGEXPS'][$key])) { + $this->_rx_key = $key; + $stuff_to_parse = preg_replace_callback("/!REG3XP$key!(.*)\|>/U", + array($this, 'handle_regexps_callback'), + $stuff_to_parse); + } else { + if (!$this->use_classes) { + $attributes = ' style="' . $this->language_data['STYLES']['REGEXPS'][$key] . '"'; + } else { + if (is_array($this->language_data['REGEXPS'][$key]) && array_key_exists(GESHI_CLASS, $this->language_data['REGEXPS'][$key])) { - $attributes = ' class="' - . $this->language_data['REGEXPS'][$key][GESHI_CLASS] . '"'; - } - else { - $attributes = ' class="re' . $key . '"'; + $attributes = ' class="' . + $this->language_data['REGEXPS'][$key][GESHI_CLASS] . '"'; + } else { + $attributes = ' class="re' . $key . '"'; + } } + $stuff_to_parse = str_replace("!REG3XP$key!", "$attributes", $stuff_to_parse); } - $stuff_to_parse = str_replace("!REG3XP$key!", "$attributes", $stuff_to_parse); } } @@ -2252,12 +3633,10 @@ class GeSHi { if (isset($this->link_styles[GESHI_LINK])) { if ($this->use_classes) { $stuff_to_parse = str_replace('<|UR1|', 'link_target . ' href=', $stuff_to_parse); - } - else { + } else { $stuff_to_parse = str_replace('<|UR1|', 'link_target . ' style="' . $this->link_styles[GESHI_LINK] . '" href=', $stuff_to_parse); } - } - else { + } else { $stuff_to_parse = str_replace('<|UR1|', 'link_target . ' href=', $stuff_to_parse); } @@ -2267,7 +3646,6 @@ class GeSHi { $stuff_to_parse = str_replace('<|', '', '', $stuff_to_parse ); - return substr($stuff_to_parse, 1); } @@ -2295,64 +3673,169 @@ class GeSHi { return $this->time; } + /** + * Merges arrays recursively, overwriting values of the first array with values of later arrays + * + * @since 1.0.8 + * @access private + */ + function merge_arrays() { + $arrays = func_get_args(); + $narrays = count($arrays); + + // check arguments + // comment out if more performance is necessary (in this case the foreach loop will trigger a warning if the argument is not an array) + for ($i = 0; $i < $narrays; $i ++) { + if (!is_array($arrays[$i])) { + // also array_merge_recursive returns nothing in this case + trigger_error('Argument #' . ($i+1) . ' is not an array - trying to merge array with scalar! Returning false!', E_USER_WARNING); + return false; + } + } + + // the first array is in the output set in every case + $ret = $arrays[0]; + + // merege $ret with the remaining arrays + for ($i = 1; $i < $narrays; $i ++) { + foreach ($arrays[$i] as $key => $value) { + if (is_array($value) && isset($ret[$key])) { + // if $ret[$key] is not an array you try to merge an scalar value with an array - the result is not defined (incompatible arrays) + // in this case the call will trigger an E_USER_WARNING and the $ret[$key] will be false. + $ret[$key] = $this->merge_arrays($ret[$key], $value); + } else { + $ret[$key] = $value; + } + } + } + + return $ret; + } + /** * Gets language information and stores it for later use * + * @param string The filename of the language file you want to load + * @since 1.0.0 * @access private * @todo Needs to load keys for lexic permissions for keywords, regexps etc */ function load_language($file_name) { + if ($file_name == $this->loaded_language) { + // this file is already loaded! + return; + } + + //Prepare some stuff before actually loading the language file + $this->loaded_language = $file_name; + $this->parse_cache_built = false; $this->enable_highlighting(); $language_data = array(); + + //Load the language file require $file_name; + // Perhaps some checking might be added here later to check that // $language data is a valid thing but maybe not $this->language_data = $language_data; + // Set strict mode if should be set - if ($this->language_data['STRICT_MODE_APPLIES'] == GESHI_ALWAYS) { - $this->strict_mode = true; - } + $this->strict_mode = $this->language_data['STRICT_MODE_APPLIES']; + // Set permissions for all lexics to true // so they'll be highlighted by default - foreach ($this->language_data['KEYWORDS'] as $key => $words) { - $this->lexic_permissions['KEYWORDS'][$key] = true; + foreach (array_keys($this->language_data['KEYWORDS']) as $key) { + if (!empty($this->language_data['KEYWORDS'][$key])) { + $this->lexic_permissions['KEYWORDS'][$key] = true; + } else { + $this->lexic_permissions['KEYWORDS'][$key] = false; + } } - foreach ($this->language_data['COMMENT_SINGLE'] as $key => $comment) { + + foreach (array_keys($this->language_data['COMMENT_SINGLE']) as $key) { $this->lexic_permissions['COMMENTS'][$key] = true; } - foreach ($this->language_data['REGEXPS'] as $key => $regexp) { + foreach (array_keys($this->language_data['REGEXPS']) as $key) { $this->lexic_permissions['REGEXPS'][$key] = true; } - // Set default class for CSS - $this->overall_class = $this->language; + + // for BenBE and future code reviews: + // we can use empty here since we only check for existance and emptiness of an array + // if it is not an array at all but rather false or null this will work as intended as well + // even if $this->language_data['PARSER_CONTROL'] is undefined this won't trigger a notice + if (!empty($this->language_data['PARSER_CONTROL']['ENABLE_FLAGS'])) { + foreach ($this->language_data['PARSER_CONTROL']['ENABLE_FLAGS'] as $flag => $value) { + // it's either true or false and maybe is true as well + $perm = $value !== GESHI_NEVER; + if ($flag == 'ALL') { + $this->enable_highlighting($perm); + continue; + } + if (!isset($this->lexic_permissions[$flag])) { + // unknown lexic permission + continue; + } + if (is_array($this->lexic_permissions[$flag])) { + foreach ($this->lexic_permissions[$flag] as $key => $val) { + $this->lexic_permissions[$flag][$key] = $perm; + } + } else { + $this->lexic_permissions[$flag] = $perm; + } + } + unset($this->language_data['PARSER_CONTROL']['ENABLE_FLAGS']); + } + + //Fix: Problem where hardescapes weren't handled if no ESCAPE_CHAR was given + //You need to set one for HARDESCAPES only in this case. + if(!isset($this->language_data['HARDCHAR'])) { + $this->language_data['HARDCHAR'] = $this->language_data['ESCAPE_CHAR']; + } + + //NEW in 1.0.8: Allow styles to be loaded from a separate file to override defaults + $style_filename = substr($file_name, 0, -4) . '.style.php'; + if (is_readable($style_filename)) { + //Clear any style_data that could have been set before ... + if (isset($style_data)) { + unset($style_data); + } + + //Read the Style Information from the style file + include $style_filename; + + //Apply the new styles to our current language styles + if (isset($style_data) && is_array($style_data)) { + $this->language_data['STYLES'] = + $this->merge_arrays($this->language_data['STYLES'], $style_data); + } + } } /** * Takes the parsed code and various options, and creates the HTML * surrounding it to make it look nice. * - * @param string The code already parsed - * @return string The code nicely finalised + * @param string The code already parsed (reference!) * @since 1.0.0 * @access private */ - function finalise($parsed_code) { + function finalise(&$parsed_code) { // Remove end parts of important declarations // This is BUGGY!! My fault for bad code: fix coming in 1.2 // @todo Remove this crap if ($this->enable_important_blocks && - (strstr($parsed_code, GeSHi::hsc(GESHI_START_IMPORTANT)) === false)) { - $parsed_code = str_replace(GeSHi::hsc(GESHI_END_IMPORTANT), '', $parsed_code); + (strpos($parsed_code, $this->hsc(GESHI_START_IMPORTANT)) === false)) { + $parsed_code = str_replace($this->hsc(GESHI_END_IMPORTANT), '', $parsed_code); } // Add HTML whitespace stuff if we're using the
        header - if ($this->header_type != GESHI_HEADER_PRE) { - $parsed_code = $this->indent($parsed_code); + if ($this->header_type != GESHI_HEADER_PRE && $this->header_type != GESHI_HEADER_PRE_VALID) { + $this->indent($parsed_code); } // purge some unnecessary stuff + /** NOTE: memorypeak #1 */ $parsed_code = preg_replace('#]+>(\s*)#', '\\1', $parsed_code); - $parsed_code = preg_replace('#]+>(\s*)
        #', '\\1', $parsed_code); // If we are using IDs for line numbers, there needs to be an overall // ID set to prevent collisions. @@ -2360,26 +3843,32 @@ class GeSHi { $this->overall_id = 'geshi-' . substr(md5(microtime()), 0, 4); } + // Get code into lines + /** NOTE: memorypeak #2 */ + $code = explode("\n", $parsed_code); + $parsed_code = $this->header(); + // If we're using line numbers, we insert
      3. s and appropriate // markup to style them (otherwise we don't need to do anything) - if ($this->line_numbers != GESHI_NO_LINE_NUMBERS) { + if ($this->line_numbers != GESHI_NO_LINE_NUMBERS && $this->header_type != GESHI_HEADER_PRE_TABLE) { // If we're using the
         header, we shouldn't add newlines because
                     // the 
         will line-break them (and the 
      4. s already do this for us) - $ls = ($this->header_type != GESHI_HEADER_PRE) ? "\n" : ''; - // Get code into lines - $code = explode("\n", $parsed_code); + $ls = ($this->header_type != GESHI_HEADER_PRE && $this->header_type != GESHI_HEADER_PRE_VALID) ? "\n" : ''; + // Set vars to defaults for following loop - $parsed_code = ''; $i = 0; - $attrs = array(); // Foreach line... - foreach ($code as $line) { + for ($i = 0, $n = count($code); $i < $n;) { + //Reset the attributes for a new line ... + $attrs = array(); + // Make lines have at least one space in them if they're empty // BenBE: Checking emptiness using trim instead of relying on blanks - if ('' == trim($line)) { - $line = ' '; + if ('' == trim($code[$i])) { + $code[$i] = ' '; } + // If this is a "special line"... if ($this->line_numbers == GESHI_FANCY_LINE_NUMBERS && $i % $this->line_nth_row == ($this->line_nth_row - 1)) { @@ -2388,8 +3877,7 @@ class GeSHi { //$attr = ' class="li2"'; $attrs['class'][] = 'li2'; $def_attr = ' class="de2"'; - } - else { + } else { //$attr = ' style="' . $this->line_style2 . '"'; $attrs['style'][] = $this->line_style2; // This style "covers up" the special styles set for special lines @@ -2397,81 +3885,179 @@ class GeSHi { // code on that line $def_attr = ' style="' . $this->code_style . '"'; } - // Span or div? - $start = ""; - $end = '
      5. '; - } - else { + } else { if ($this->use_classes) { //$attr = ' class="li1"'; $attrs['class'][] = 'li1'; $def_attr = ' class="de1"'; - } - else { + } else { //$attr = ' style="' . $this->line_style1 . '"'; $attrs['style'][] = $this->line_style1; $def_attr = ' style="' . $this->code_style . '"'; } + } + + //Check which type of tag to insert for this line + if ($this->header_type == GESHI_HEADER_PRE_VALID) { + $start = ""; + $end = '
        '; + } else { + // Span or div? $start = ""; $end = '
        '; } ++$i; + // Are we supposed to use ids? If so, add them if ($this->add_ids) { $attrs['id'][] = "$this->overall_id-$i"; } - if ($this->use_classes && in_array($i, $this->highlight_extra_lines)) { - $attrs['class'][] = 'ln-xtra'; - } - if (!$this->use_classes && in_array($i, $this->highlight_extra_lines)) { - $attrs['style'][] = $this->highlight_extra_lines_style; + + //Is this some line with extra styles??? + if (in_array($i, $this->highlight_extra_lines)) { + if ($this->use_classes) { + if (isset($this->highlight_extra_lines_styles[$i])) { + $attrs['class'][] = "lx$i"; + } else { + $attrs['class'][] = "ln-xtra"; + } + } else { + array_push($attrs['style'], $this->get_line_style($i)); + } } // Add in the line surrounded by appropriate list HTML - $attr_string = ' '; + $attr_string = ''; foreach ($attrs as $key => $attr) { - $attr_string .= $key . '="' . implode(' ', $attr) . '" '; + $attr_string .= ' ' . $key . '="' . implode(' ', $attr) . '"'; } - $attr_string = substr($attr_string, 0, -1); - $parsed_code .= "$start$line$end$ls"; - $attrs = array(); + + $parsed_code .= "$start{$code[$i-1]}$end$ls"; + unset($code[$i - 1]); + } + } else { + $n = count($code); + if ($this->use_classes) { + $attributes = ' class="de1"'; + } else { + $attributes = ' style="'. $this->code_style .'"'; + } + if ($this->header_type == GESHI_HEADER_PRE_VALID) { + $parsed_code .= ''; + } elseif ($this->header_type == GESHI_HEADER_PRE_TABLE) { + if ($this->line_numbers != GESHI_NO_LINE_NUMBERS) { + if ($this->use_classes) { + $attrs = ' class="ln"'; + } else { + $attrs = ' style="'. $this->table_linenumber_style .'"'; + } + $parsed_code .= ''; + // get linenumbers + // we don't merge it with the for below, since it should be better for + // memory consumption this way + // @todo: but... actually it would still be somewhat nice to merge the two loops + // the mem peaks are at different positions + for ($i = 0; $i < $n; ++$i) { + $close = 0; + // fancy lines + if ($this->line_numbers == GESHI_FANCY_LINE_NUMBERS && + $i % $this->line_nth_row == ($this->line_nth_row - 1)) { + // Set the attributes to style the line + if ($this->use_classes) { + $parsed_code .= ''; + } else { + // This style "covers up" the special styles set for special lines + // so that styles applied to special lines don't apply to the actual + // code on that line + $parsed_code .= '' + .''; + } + $close += 2; + } + //Is this some line with extra styles??? + if (in_array($i + 1, $this->highlight_extra_lines)) { + if ($this->use_classes) { + if (isset($this->highlight_extra_lines_styles[$i])) { + $parsed_code .= ""; + } else { + $parsed_code .= ""; + } + } else { + $parsed_code .= "get_line_style($i) . "\">"; + } + ++$close; + } + $parsed_code .= $this->line_numbers_start + $i; + if ($close) { + $parsed_code .= str_repeat('', $close); + } else if ($i != $n) { + $parsed_code .= "\n"; + } + } + $parsed_code .= '
        '; + } + $parsed_code .= ''; } - } - else { // No line numbers, but still need to handle highlighting lines extra. // Have to use divs so the full width of the code is highlighted - $code = explode("\n", $parsed_code); - $parsed_code = ''; - $i = 0; - foreach ($code as $line) { + $close = 0; + for ($i = 0; $i < $n; ++$i) { // Make lines have at least one space in them if they're empty // BenBE: Checking emptiness using trim instead of relying on blanks - if ('' == trim($line)) { - $line = ' '; + if ('' == trim($code[$i])) { + $code[$i] = ' '; } - if (in_array(++$i, $this->highlight_extra_lines)) { + // fancy lines + if ($this->line_numbers == GESHI_FANCY_LINE_NUMBERS && + $i % $this->line_nth_row == ($this->line_nth_row - 1)) { + // Set the attributes to style the line if ($this->use_classes) { - $parsed_code .= '
        '; + $parsed_code .= ''; + } else { + // This style "covers up" the special styles set for special lines + // so that styles applied to special lines don't apply to the actual + // code on that line + $parsed_code .= '' + .''; } - else { - $parsed_code .= "
        highlight_extra_lines_style}\">"; + $close += 2; + } + //Is this some line with extra styles??? + if (in_array($i + 1, $this->highlight_extra_lines)) { + if ($this->use_classes) { + if (isset($this->highlight_extra_lines_styles[$i])) { + $parsed_code .= ""; + } else { + $parsed_code .= ""; + } + } else { + $parsed_code .= "get_line_style($i) . "\">"; } - // Remove \n because it stuffs up
         header
        -                    $parsed_code .= $line . "
        "; + ++$close; } - else { - $parsed_code .= $line . "\n"; + + $parsed_code .= $code[$i]; + + if ($close) { + $parsed_code .= str_repeat('
        ', $close); + $close = 0; } + elseif ($i + 1 < $n) { + $parsed_code .= "\n"; + } + unset($code[$i]); + } + + if ($this->header_type == GESHI_HEADER_PRE_VALID || $this->header_type == GESHI_HEADER_PRE_TABLE) { + $parsed_code .= '
      '; + } + if ($this->header_type == GESHI_HEADER_PRE_TABLE && $this->line_numbers != GESHI_NO_LINE_NUMBERS) { + $parsed_code .= ''; } } - if ($this->header_type == GESHI_HEADER_PRE) { - // enforce line numbers when using pre - $parsed_code = str_replace('
    4. ', '
    5.  
    6. ', $parsed_code); - } - - return $this->header() . chop($parsed_code) . $this->footer(); + $parsed_code .= $this->footer(); } /** @@ -2483,7 +4069,22 @@ class GeSHi { */ function header() { // Get attributes needed - $attributes = $this->get_attributes(); + /** + * @todo Document behaviour change - class is outputted regardless of whether + * we're using classes or not. Same with style + */ + $attributes = ' class="' . $this->_genCSSName($this->language); + if ($this->overall_class != '') { + $attributes .= " ".$this->_genCSSName($this->overall_class); + } + $attributes .= '"'; + + if ($this->overall_id != '') { + $attributes .= " id=\"{$this->overall_id}\""; + } + if ($this->overall_style != '' && !$this->use_classes) { + $attributes .= ' style="' . $this->overall_style . '"'; + } $ol_attributes = ''; @@ -2492,59 +4093,50 @@ class GeSHi { } // Get the header HTML - $header = $this->format_header_content(); - - if (GESHI_HEADER_NONE == $this->header_type) { - if ($this->line_numbers != GESHI_NO_LINE_NUMBERS) { - return "$header"; - } - return $header . - ($this->force_code_block ? '
      ' : ''); - } - - // Work out what to return and do it - if ($this->line_numbers != GESHI_NO_LINE_NUMBERS) { - if ($this->header_type == GESHI_HEADER_PRE) { - return "$header"; - } - else if ($this->header_type == GESHI_HEADER_DIV) { - return "$header"; - } - } - else { - if ($this->header_type == GESHI_HEADER_PRE) { - return "$header" . - ($this->force_code_block ? '
      ' : ''); - } - else if ($this->header_type == GESHI_HEADER_DIV) { - return "$header" . - ($this->force_code_block ? '
      ' : ''); - } - } - } - - /** - * Returns the header content, formatted for output - * - * @return string The header content, formatted for output - * @since 1.0.2 - * @access private - */ - function format_header_content() { $header = $this->header_content; if ($header) { - if ($this->header_type == GESHI_HEADER_PRE) { + if ($this->header_type == GESHI_HEADER_PRE || $this->header_type == GESHI_HEADER_PRE_VALID) { $header = str_replace("\n", '', $header); } $header = $this->replace_keywords($header); if ($this->use_classes) { $attr = ' class="head"'; - } - else { + } else { $attr = " style=\"{$this->header_content_style}\""; } - return "$header
      "; + if ($this->header_type == GESHI_HEADER_PRE_TABLE && $this->line_numbers != GESHI_NO_LINE_NUMBERS) { + $header = "$header"; + } else { + $header = "$header
      "; + } + } + + if (GESHI_HEADER_NONE == $this->header_type) { + if ($this->line_numbers != GESHI_NO_LINE_NUMBERS) { + return "$header"; + } + return $header . ($this->force_code_block ? '
      ' : ''); + } + + // Work out what to return and do it + if ($this->line_numbers != GESHI_NO_LINE_NUMBERS) { + if ($this->header_type == GESHI_HEADER_PRE) { + return "$header"; + } else if ($this->header_type == GESHI_HEADER_DIV || + $this->header_type == GESHI_HEADER_PRE_VALID) { + return "$header"; + } else if ($this->header_type == GESHI_HEADER_PRE_TABLE) { + return "$header"; + } + } else { + if ($this->header_type == GESHI_HEADER_PRE) { + return "$header" . + ($this->force_code_block ? '
      ' : ''); + } else { + return "$header" . + ($this->force_code_block ? '
      ' : ''); + } } } @@ -2556,37 +4148,6 @@ class GeSHi { * @access private */ function footer() { - $footer_content = $this->format_footer_content(); - - if (GESHI_HEADER_NONE == $this->header_type) { - return ($this->line_numbers != GESHI_NO_LINE_NUMBERS) ? '
    ' . $footer_content - : $footer_content; - } - - if ($this->header_type == GESHI_HEADER_DIV) { - if ($this->line_numbers != GESHI_NO_LINE_NUMBERS) { - return "$footer_content"; - } - return ($this->force_code_block ? '' : '') . - "$footer_content"; - } - else { - if ($this->line_numbers != GESHI_NO_LINE_NUMBERS) { - return "$footer_content
    "; - } - return ($this->force_code_block ? '' : '') . - "$footer_content
  • "; - } - } - - /** - * Returns the footer content, formatted for output - * - * @return string The footer content, formatted for output - * @since 1.0.2 - * @access private - */ - function format_footer_content() { $footer = $this->footer_content; if ($footer) { if ($this->header_type == GESHI_HEADER_PRE) { @@ -2596,11 +4157,40 @@ class GeSHi { if ($this->use_classes) { $attr = ' class="foot"'; - } - else { + } else { $attr = " style=\"{$this->footer_content_style}\""; } - return "$footer"; + if ($this->header_type == GESHI_HEADER_PRE_TABLE && $this->line_numbers != GESHI_NO_LINE_NUMBERS) { + $footer = "$footer"; + } else { + $footer = "$footer"; + } + } + + if (GESHI_HEADER_NONE == $this->header_type) { + return ($this->line_numbers != GESHI_NO_LINE_NUMBERS) ? '' . $footer : $footer; + } + + if ($this->header_type == GESHI_HEADER_DIV || $this->header_type == GESHI_HEADER_PRE_VALID) { + if ($this->line_numbers != GESHI_NO_LINE_NUMBERS) { + return "$footer"; + } + return ($this->force_code_block ? '' : '') . + "$footer"; + } + elseif ($this->header_type == GESHI_HEADER_PRE_TABLE) { + if ($this->line_numbers != GESHI_NO_LINE_NUMBERS) { + return "$footer"; + } + return ($this->force_code_block ? '' : '') . + "$footer"; + } + else { + if ($this->line_numbers != GESHI_NO_LINE_NUMBERS) { + return "$footer"; + } + return ($this->force_code_block ? '' : '') . + "$footer"; } } @@ -2618,43 +4208,33 @@ class GeSHi { $keywords[] = '