summaryrefslogtreecommitdiffstats
path: root/application/libraries/geshi.php
diff options
context:
space:
mode:
Diffstat (limited to 'application/libraries/geshi.php')
-rw-r--r--application/libraries/geshi.php135
1 files changed, 113 insertions, 22 deletions
diff --git a/application/libraries/geshi.php b/application/libraries/geshi.php
index c654fa2a7..d8e9909fa 100644
--- a/application/libraries/geshi.php
+++ b/application/libraries/geshi.php
@@ -41,7 +41,7 @@
//
/** The version of this GeSHi file */
-define('GESHI_VERSION', '1.0.8.6');
+define('GESHI_VERSION', '1.0.8.10');
// Define the root directory for the GeSHi code tree
if (!defined('GESHI_ROOT')) {
@@ -209,12 +209,16 @@ define('GESHI_NUMBER_BIN_PREFIX_0B', 64); //0b[01]+
define('GESHI_NUMBER_OCT_PREFIX', 256); //0[0-7]+
/** Number format to highlight octal numbers with a prefix 0o (logtalk) */
define('GESHI_NUMBER_OCT_PREFIX_0O', 512); //0[0-7]+
+/** Number format to highlight octal numbers with a leading @ (Used in HiSofts Devpac series). */
+define('GESHI_NUMBER_OCT_PREFIX_AT', 1024); //@[0-7]+
/** Number format to highlight octal numbers with a suffix of o */
-define('GESHI_NUMBER_OCT_SUFFIX', 1024); //[0-7]+[oO]
+define('GESHI_NUMBER_OCT_SUFFIX', 2048); //[0-7]+[oO]
/** Number format to highlight hex numbers with a prefix 0x */
define('GESHI_NUMBER_HEX_PREFIX', 4096); //0x[0-9a-fA-F]+
+/** Number format to highlight hex numbers with a prefix $ */
+define('GESHI_NUMBER_HEX_PREFIX_DOLLAR', 8192); //$[0-9a-fA-F]+
/** Number format to highlight hex numbers with a suffix of h */
-define('GESHI_NUMBER_HEX_SUFFIX', 8192); //[0-9][0-9a-fA-F]*h
+define('GESHI_NUMBER_HEX_SUFFIX', 16384); //[0-9][0-9a-fA-F]*h
/** Number format to highlight floating-point numbers without support for scientific notation */
define('GESHI_NUMBER_FLT_NONSCI', 65536); //\d+\.\d+
/** Number format to highlight floating-point numbers without support for scientific notation */
@@ -753,6 +757,88 @@ class Geshi {
}
/**
+ * Get supported langs or an associative array lang=>full_name.
+ * @param boolean $longnames
+ * @return array
+ */
+ function get_supported_languages($full_names=false)
+ {
+ // return array
+ $back = array();
+
+ // we walk the lang root
+ $dir = dir($this->language_path);
+
+ // foreach entry
+ while (false !== ($entry = $dir->read()))
+ {
+ $full_path = $this->language_path.$entry;
+
+ // Skip all dirs
+ if (is_dir($full_path)) {
+ continue;
+ }
+
+ // we only want lang.php files
+ if (!preg_match('/^([^.]+)\.php$/', $entry, $matches)) {
+ continue;
+ }
+
+ // Raw lang name is here
+ $langname = $matches[1];
+
+ // We want the fullname too?
+ if ($full_names === true)
+ {
+ if (false !== ($fullname = $this->get_language_fullname($langname)))
+ {
+ $back[$langname] = $fullname; // we go associative
+ }
+ }
+ else
+ {
+ // just store raw langname
+ $back[] = $langname;
+ }
+ }
+
+ $dir->close();
+
+ return $back;
+ }
+
+ /**
+ * Get full_name for a lang or false.
+ * @param string $language short langname (html4strict for example)
+ * @return mixed
+ */
+ function get_language_fullname($language)
+ {
+ //Clean up the language name to prevent malicious code injection
+ $language = preg_replace('#[^a-zA-Z0-9\-_]#', '', $language);
+
+ $language = strtolower($language);
+
+ // get fullpath-filename for a langname
+ $fullpath = $this->language_path.$language.'.php';
+
+ // we need to get contents :S
+ if (false === ($data = file_get_contents($fullpath))) {
+ $this->error = sprintf('Geshi::get_lang_fullname() Unknown Language: %s', $language);
+ return false;
+ }
+
+ // match the langname
+ if (!preg_match('/\'LANG_NAME\'\s*=>\s*\'((?:[^\']|\\\')+)\'/', $data, $matches)) {
+ $this->error = sprintf('Geshi::get_lang_fullname(%s): Regex can not detect language', $language);
+ return false;
+ }
+
+ // return fullname for langname
+ return stripcslashes($matches[1]);
+ }
+
+ /**
* Sets the type of header to be used.
*
* If GESHI_HEADER_DIV is used, the code is surrounded in a "div".This
@@ -1374,6 +1460,10 @@ class Geshi {
function get_language_name_from_extension( $extension, $lookup = array() ) {
if ( !is_array($lookup) || empty($lookup)) {
$lookup = array(
+ '6502acme' => array( 'a', 's', 'asm', 'inc' ),
+ '6502tasm' => array( 'a', 's', 'asm', 'inc' ),
+ '6502kickass' => array( 'a', 's', 'asm', 'inc' ),
+ '68000devpac' => array( 'a', 's', 'asm', 'inc' ),
'abap' => array('abap'),
'actionscript' => array('as'),
'ada' => array('a', 'ada', 'adb', 'ads'),
@@ -1598,15 +1688,6 @@ class Geshi {
}
/**
- * Alias for parse_code() function
- * @param none
- * @return none
- */
- function output(){
- return $this->parse_code();
- }
-
- /**
* Sets the content of the header block
*
* @param string The content of the header block
@@ -2001,7 +2082,7 @@ class Geshi {
//All this formats are matched case-insensitively!
static $numbers_format = array(
GESHI_NUMBER_INT_BASIC =>
- '(?<![0-9a-z_\.%])(?<![\d\.]e[+\-])([1-9]\d*?|0)(?![0-9a-z]|\.(?:[eE][+\-]?)?\d)',
+ '(?:(?<![0-9a-z_\.%$@])|(?<=\.\.))(?<![\d\.]e[+\-])([1-9]\d*?|0)(?![0-9a-z]|\.(?:[eE][+\-]?)?\d)',
GESHI_NUMBER_INT_CSTYLE =>
'(?<![0-9a-z_\.%])(?<![\d\.]e[+\-])([1-9]\d*?|0)l(?![0-9a-z]|\.(?:[eE][+\-]?)?\d)',
GESHI_NUMBER_BIN_SUFFIX =>
@@ -2014,10 +2095,14 @@ class Geshi {
'(?<![0-9a-z_\.])(?<![\d\.]e[+\-])0[0-7]+?(?![0-9a-z]|\.(?:[eE][+\-]?)?\d)',
GESHI_NUMBER_OCT_PREFIX_0O =>
'(?<![0-9a-z_\.%])(?<![\d\.]e[+\-])0o[0-7]+?(?![0-9a-z]|\.(?:[eE][+\-]?)?\d)',
+ GESHI_NUMBER_OCT_PREFIX_AT =>
+ '(?<![0-9a-z_\.%])(?<![\d\.]e[+\-])\@[0-7]+?(?![0-9a-z]|\.(?:[eE][+\-]?)?\d)',
GESHI_NUMBER_OCT_SUFFIX =>
'(?<![0-9a-z_\.])(?<![\d\.]e[+\-])[0-7]+?o(?![0-9a-z]|\.(?:[eE][+\-]?)?\d)',
GESHI_NUMBER_HEX_PREFIX =>
'(?<![0-9a-z_\.])(?<![\d\.]e[+\-])0x[0-9a-fA-F]+?(?![0-9a-z]|\.(?:[eE][+\-]?)?\d)',
+ GESHI_NUMBER_HEX_PREFIX_DOLLAR =>
+ '(?<![0-9a-z_\.])(?<![\d\.]e[+\-])\$[0-9a-fA-F]+?(?![0-9a-z]|\.(?:[eE][+\-]?)?\d)',
GESHI_NUMBER_HEX_SUFFIX =>
'(?<![0-9a-z_\.])(?<![\d\.]e[+\-])\d[0-9a-fA-F]*?[hH](?![0-9a-z]|\.(?:[eE][+\-]?)?\d)',
GESHI_NUMBER_FLT_NONSCI =>
@@ -2049,7 +2134,11 @@ class Geshi {
}
$this->language_data['NUMBERS_RXCACHE'][$key] =
- "/(?<!<\|\/)(?<!<\|!REG3XP)(?<!<\|\/NUM!)(?<!\d\/>)($regexp)(?!(?:<DOT>|[^\<])+>)(?![^<]*>)(?!\|>)(?!\/>)/i"; //
+ "/(?<!<\|\/)(?<!<\|!REG3XP)(?<!<\|\/NUM!)(?<!\d\/>)($regexp)(?!(?:<DOT>|(?>[^\<]))+>)(?![^<]*>)(?!\|>)(?!\/>)/i"; //
+ }
+
+ if(!isset($this->language_data['PARSER_CONTROL']['NUMBERS']['PRECHECK_RX'])) {
+ $this->language_data['PARSER_CONTROL']['NUMBERS']['PRECHECK_RX'] = '#\d#';
}
}
@@ -2681,7 +2770,8 @@ class Geshi {
$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']) {
+ 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) {
@@ -3267,10 +3357,10 @@ class Geshi {
* @todo BUGGY! Why? Why not build string and return?
*/
function parse_non_string_part($stuff_to_parse) {
- $stuff_to_parse = $this->hsc($stuff_to_parse);
+ $stuff_to_parse = ' ' . $this->hsc($stuff_to_parse);
// Highlight keywords
- $disallowed_before = "(?<![a-zA-Z0-9\$_\|\#;>|^&";
+ $disallowed_before = "(?<![a-zA-Z0-9\$_\|\#|^&";
$disallowed_after = "(?![a-zA-Z0-9_\|%\\-&;";
if ($this->lexic_permissions['STRINGS']) {
$quotemarks = preg_quote(implode($this->language_data['QUOTEMARKS']), '/');
@@ -3328,7 +3418,7 @@ class Geshi {
// 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})(?!\<DOT\>(?:htm|php))$disallowed_after_local/$modifiers",
+ "/$disallowed_before_local({$keywordset})(?!\<DOT\>(?:htm|php|aspx?))$disallowed_after_local/$modifiers",
array($this, 'handle_keyword_replace'),
$stuff_to_parse
);
@@ -3375,7 +3465,8 @@ class Geshi {
// Highlight numbers. As of 1.0.8 we support different types of numbers
$numbers_found = false;
- if ($this->lexic_permissions['NUMBERS'] && preg_match('#\d#', $stuff_to_parse )) {
+
+ 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 ...
@@ -3576,7 +3667,7 @@ class Geshi {
$stuff_to_parse = str_replace('<|', '<span', $stuff_to_parse);
$stuff_to_parse = str_replace ( '|>', '</span>', $stuff_to_parse );
- return $stuff_to_parse;
+ return substr($stuff_to_parse, 1);
}
/**
@@ -4494,7 +4585,7 @@ class Geshi {
* @access private
*/
function optimize_regexp_list($list, $regexp_delimiter = '/') {
- $regex_chars = array('.', '\\', '+', '*', '?', '[', '^', ']', '$',
+ $regex_chars = array('.', '\\', '+', '-', '*', '?', '[', '^', ']', '$',
'(', ')', '{', '}', '=', '!', '<', '>', '|', ':', $regexp_delimiter);
sort($list);
$regexp_list = array('');
@@ -4682,4 +4773,4 @@ if (!function_exists('geshi_highlight')) {
}
}
-?> \ No newline at end of file
+?>