Skip to content

Commit

Permalink
GeSHi update to 1.0.8.11
Browse files Browse the repository at this point in the history
  • Loading branch information
splitbrain committed Nov 24, 2012
1 parent ebd33fd commit b7183bb
Showing 1 changed file with 44 additions and 24 deletions.
68 changes: 44 additions & 24 deletions inc/geshi.php
Expand Up @@ -41,7 +41,7 @@
//

/** The version of this GeSHi file */
define('GESHI_VERSION', '1.0.8.10');
define('GESHI_VERSION', '1.0.8.11');

// Define the root directory for the GeSHi code tree
if (!defined('GESHI_ROOT')) {
Expand Down Expand Up @@ -604,6 +604,17 @@ function GeSHi($source = '', $language = '', $path = '') {
$this->set_language_path($path);
}

/**
* Returns the version of GeSHi
*
* @return string
* @since 1 0.8.11
*/
function get_version()
{
return GESHI_VERSION;
}

/**
* Returns an error message associated with the last GeSHi operation,
* or false if no error has occured
Expand Down Expand Up @@ -808,7 +819,7 @@ function get_language_fullname($language)
}

// match the langname
if (!preg_match('/\'LANG_NAME\'\s*=>\s*\'((?:[^\']|\\\')+)\'/', $data, $matches)) {
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;
}
Expand Down Expand Up @@ -1437,6 +1448,8 @@ function enable_highlighting($flag = true) {
* @todo static?
*/
function get_language_name_from_extension( $extension, $lookup = array() ) {
$extension = strtolower($extension);

if ( !is_array($lookup) || empty($lookup)) {
$lookup = array(
'6502acme' => array( 'a', 's', 'asm', 'inc' ),
Expand Down Expand Up @@ -1470,6 +1483,7 @@ function get_language_name_from_extension( $extension, $lookup = array() ) {
'gnuplot' => array('plt'),
'groovy' => array('groovy'),
'haskell' => array('hs'),
'haxe' => array('hx'),
'html4strict' => array('html', 'htm'),
'ini' => array('ini', 'desktop'),
'java' => array('java'),
Expand Down Expand Up @@ -1504,6 +1518,7 @@ function get_language_name_from_extension( $extension, $lookup = array() ) {
'smalltalk' => array('st'),
'smarty' => array(),
'tcl' => array('tcl'),
'text' => array('txt'),
'vb' => array('bas'),
'vbnet' => array(),
'visualfoxpro' => array(),
Expand All @@ -1518,7 +1533,8 @@ function get_language_name_from_extension( $extension, $lookup = array() ) {
return $lang;
}
}
return '';

return 'text';
}

/**
Expand Down Expand Up @@ -1555,6 +1571,9 @@ function load_from_file($file_name, $lookup = array()) {
* @since 1.0.0
*/
function add_keyword($key, $word) {
if (!is_array($this->language_data['KEYWORDS'][$key])) {
$this->language_data['KEYWORDS'][$key] = array();
}
if (!in_array($word, $this->language_data['KEYWORDS'][$key])) {
$this->language_data['KEYWORDS'][$key][] = $word;

Expand Down Expand Up @@ -1816,7 +1835,7 @@ function highlight_lines_extra($lines, $style = null) {
//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
} elseif ($style === false) { //Check if to remove this line
unset($this->highlight_extra_lines[$lines]);
unset($this->highlight_extra_lines_styles[$lines]);
} else {
Expand Down Expand Up @@ -1988,7 +2007,7 @@ function build_parse_cache() {
$this->language_data['SYMBOL_DATA'][$symbols] = 0;
if (isset($symbols[1])) { // multiple chars
$symbol_preg_multi[] = preg_quote($symbols, '/');
} else if ($symbols == '-') {
} elseif ($symbols == '-') {
// don't trigger range out of order error
$symbol_preg_single[] = '\-';
} else { // single char
Expand Down Expand Up @@ -2392,7 +2411,7 @@ function parse_code () {
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]])) {
} elseif (is_string($is_string_starter[$quotemark[0]])) {
$is_string_starter[$quotemark[0]] = array(
$is_string_starter[$quotemark[0]],
$quotemark);
Expand Down Expand Up @@ -2478,7 +2497,7 @@ function parse_code () {
continue;
}
$match_i = $comment_regexp_cache_per_key[$comment_key]['pos'];
} else if (
} elseif (
//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))
Expand Down Expand Up @@ -2586,7 +2605,7 @@ function parse_code () {
continue;
}
$match_i = $escape_regexp_cache_per_key[$escape_key]['pos'];
} else if (
} elseif (
//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))
Expand Down Expand Up @@ -2656,13 +2675,13 @@ function parse_code () {
// don't put a newline around newlines
$string .= "</span>\n";
$start = $es_pos + 2;
} else if (ord($es_char) >= 128) {
} elseif (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 . '</span>';
} else if (!GESHI_PHP_PRE_433 && 'utf-8' == $this->encoding) {
} elseif (!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}".
Expand All @@ -2684,7 +2703,7 @@ function parse_code () {
$string .= $this->hsc($es_char) . '</span>';
$start = $es_pos + 2;
}
} else if ($next_escape_regexp_pos < $length &&
} elseif ($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 ...
Expand Down Expand Up @@ -2728,7 +2747,7 @@ function parse_code () {
$string = '';
$i = $start - 1;
continue;
} else if ($this->lexic_permissions['STRINGS'] && $hq && $hq[0] == $char &&
} elseif ($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) {
Expand Down Expand Up @@ -2886,7 +2905,7 @@ function parse_code () {
continue;
}
$match_i = $comment_multi_cache_per_key[$open];
} else if (($match_i = stripos($part, $open, $i)) !== false) {
} elseif (($match_i = stripos($part, $open, $i)) !== false) {
$comment_multi_cache_per_key[$open] = $match_i;
} else {
$comment_multi_cache_per_key[$open] = false;
Expand Down Expand Up @@ -2983,7 +3002,7 @@ function parse_code () {
continue;
}
$match_i = $comment_single_cache_per_key[$comment_key];
} else if (
} elseif (
// case sensitive comments
($this->language_data['CASE_SENSITIVE'][GESHI_COMMENTS] &&
($match_i = stripos($part, $comment_mark, $i)) !== false) ||
Expand Down Expand Up @@ -3140,10 +3159,10 @@ function indent(&$result) {
$IN_TAG = false;
}
$lines[$key] .= $char;
} else if ('<' == $char) {
} elseif ('<' == $char) {
$IN_TAG = true;
$lines[$key] .= '<';
} else if ('&' == $char) {
} elseif ('&' == $char) {
$substr = substr($line, $i + 3, 5);
$posi = strpos($substr, ';');
if (false === $posi) {
Expand All @@ -3152,7 +3171,7 @@ function indent(&$result) {
$pos -= $posi+2;
}
$lines[$key] .= $char;
} else if ("\t" == $char) {
} elseif ("\t" == $char) {
$str = '';
// OPTIMISE - move $strs out. Make an array:
// $tabs = array(
Expand All @@ -3173,7 +3192,7 @@ function indent(&$result) {
$lines[$key] .= substr($line, $i + 1);
break;
}
} else if (0 == $pos && ' ' == $char) {
} elseif (0 == $pos && ' ' == $char) {
$lines[$key] .= '&nbsp;';
++$pos;
} else {
Expand Down Expand Up @@ -3231,6 +3250,7 @@ function change_case($instr) {
function handle_keyword_replace($match) {
$k = $this->_kw_replace_group;
$keyword = $match[0];
$keyword_match = $match[1];

$before = '';
$after = '';
Expand All @@ -3248,12 +3268,12 @@ function handle_keyword_replace($match) {
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) {
if (strcasecmp($word, $keyword_match) == 0) {
break;
}
}
} else {
$word = $keyword;
$word = $keyword_match;
}

$before = '<|UR1|"' .
Expand Down Expand Up @@ -3367,7 +3387,7 @@ function parse_non_string_part($stuff_to_parse) {

foreach (array_keys($this->language_data['KEYWORDS']) as $k) {
if (!isset($this->lexic_permissions['KEYWORDS'][$k]) ||
$this->lexic_permissions['KEYWORDS'][$k]) {
$this->lexic_permissions['KEYWORDS'][$k]) {

$case_sensitive = $this->language_data['CASE_SENSITIVE'][$k];
$modifiers = $case_sensitive ? '' : 'i';
Expand Down Expand Up @@ -3991,7 +4011,7 @@ function finalise(&$parsed_code) {
$parsed_code .= $this->line_numbers_start + $i;
if ($close) {
$parsed_code .= str_repeat('</span>', $close);
} else if ($i != $n) {
} elseif ($i != $n) {
$parsed_code .= "\n";
}
}
Expand Down Expand Up @@ -4123,10 +4143,10 @@ function header() {
if ($this->line_numbers != GESHI_NO_LINE_NUMBERS) {
if ($this->header_type == GESHI_HEADER_PRE) {
return "<pre$attributes>$header<ol$ol_attributes>";
} else if ($this->header_type == GESHI_HEADER_DIV ||
} elseif ($this->header_type == GESHI_HEADER_DIV ||
$this->header_type == GESHI_HEADER_PRE_VALID) {
return "<div$attributes>$header<ol$ol_attributes>";
} else if ($this->header_type == GESHI_HEADER_PRE_TABLE) {
} elseif ($this->header_type == GESHI_HEADER_PRE_TABLE) {
return "<table$attributes>$header<tbody><tr class=\"li1\">";
}
} else {
Expand Down

0 comments on commit b7183bb

Please sign in to comment.