jablonka.czprosek.czf

websvn

Subversion Repositories:
[/] [lib/] [geshi.php] - Diff between revs 1 and 3

Show entire file Ignore whitespace

Rev 1 Rev 3
Line 39... Line 39...
// their values - you never know when a value may change in a future // their values - you never know when a value may change in a future
// version // version
// //
   
/** The version of this GeSHi file */ /** The version of this GeSHi file */
define('GESHI_VERSION', '1.0.8.1'); define('GESHI_VERSION', '1.0.8.3');
   
// Define the root directory for the GeSHi code tree // Define the root directory for the GeSHi code tree
if (!defined('GESHI_ROOT')) { if (!defined('GESHI_ROOT')) {
/** The root directory for GeSHi */ /** The root directory for GeSHi */
define('GESHI_ROOT', dirname(__FILE__) . DIRECTORY_SEPARATOR); define('GESHI_ROOT', dirname(__FILE__) . DIRECTORY_SEPARATOR);
Line 981... Line 981...
* @param string The style to make the escape characters * @param string The style to make the escape characters
* @param boolean Whether to merge the new styles with the old or just * @param boolean Whether to merge the new styles with the old or just
* to overwrite them * to overwrite them
* @since 1.0.0 * @since 1.0.0
*/ */
function set_escape_characters_style($style, $preserve_defaults = false) { function set_escape_characters_style($style, $preserve_defaults = false, $group = 0) {
if (!$preserve_defaults) { if (!$preserve_defaults) {
$this->language_data['STYLES']['ESCAPE_CHAR'][0] = $style; $this->language_data['STYLES']['ESCAPE_CHAR'][$group] = $style;
} else { } else {
$this->language_data['STYLES']['ESCAPE_CHAR'][0] .= $style; $this->language_data['STYLES']['ESCAPE_CHAR'][$group] .= $style;
} }
} }
   
/** /**
* Turns highlighting on/off for escaped characters * Turns highlighting on/off for escaped characters
Line 1330... Line 1330...
if ( !is_array($lookup) || empty($lookup)) { if ( !is_array($lookup) || empty($lookup)) {
$lookup = array( $lookup = array(
'actionscript' => array('as'), 'actionscript' => array('as'),
'ada' => array('a', 'ada', 'adb', 'ads'), 'ada' => array('a', 'ada', 'adb', 'ads'),
'apache' => array('conf'), 'apache' => array('conf'),
'asm' => array('ash', 'asm'), 'asm' => array('ash', 'asm', 'inc'),
'asp' => array('asp'), 'asp' => array('asp'),
'bash' => array('sh'), 'bash' => array('sh'),
  'bf' => array('bf'),
'c' => array('c', 'h'), 'c' => array('c', 'h'),
'c_mac' => array('c', 'h'), 'c_mac' => array('c', 'h'),
'caddcl' => array(), 'caddcl' => array(),
'cadlisp' => array(), 'cadlisp' => array(),
'cdfg' => array('cdfg'), 'cdfg' => array('cdfg'),
'cobol' => array('cbl'), 'cobol' => array('cbl'),
'cpp' => array('cpp', 'h', 'hpp'), 'cpp' => array('cpp', 'hpp', 'C', 'H', 'CPP', 'HPP'),
'csharp' => array(), 'csharp' => array('cs'),
'css' => array('css'), 'css' => array('css'),
  'd' => array('d'),
'delphi' => array('dpk', 'dpr', 'pp', 'pas'), 'delphi' => array('dpk', 'dpr', 'pp', 'pas'),
  'diff' => array('diff', 'patch'),
'dos' => array('bat', 'cmd'), 'dos' => array('bat', 'cmd'),
'gettext' => array('po', 'pot'), 'gettext' => array('po', 'pot'),
  'gml' => array('gml'),
  'gnuplot' => array('plt'),
  'groovy' => array('groovy'),
  'haskell' => array('hs'),
'html4strict' => array('html', 'htm'), 'html4strict' => array('html', 'htm'),
'ini' => array('ini', 'desktop'), 'ini' => array('ini', 'desktop'),
'java' => array('java'), 'java' => array('java'),
'javascript' => array('js'), 'javascript' => array('js'),
'klonec' => array('kl1'), 'klonec' => array('kl1'),
'klonecpp' => array('klx'), 'klonecpp' => array('klx'),
  'latex' => array('tex'),
'lisp' => array('lisp'), 'lisp' => array('lisp'),
'lua' => array('lua'), 'lua' => array('lua'),
'matlab' => array('m'), 'matlab' => array('m'),
'mpasm' => array(), 'mpasm' => array(),
  'mysql' => array('sql'),
'nsis' => array(), 'nsis' => array(),
'objc' => array(), 'objc' => array(),
'oobas' => array(), 'oobas' => array(),
'oracle8' => array(), 'oracle8' => array(),
'pascal' => array(), 'oracle10' => array(),
  'pascal' => array('pas'),
'perl' => array('pl', 'pm'), 'perl' => array('pl', 'pm'),
'php' => array('php', 'php5', 'phtml', 'phps'), 'php' => array('php', 'php5', 'phtml', 'phps'),
  'povray' => array('pov'),
  'providex' => array('pvc', 'pvx'),
  'prolog' => array('pl'),
'python' => array('py'), 'python' => array('py'),
'qbasic' => array('bi'), 'qbasic' => array('bi'),
  'reg' => array('reg'),
  'ruby' => array('rb'),
'sas' => array('sas'), 'sas' => array('sas'),
  'scala' => array('scala'),
  'scheme' => array('scm'),
'scilab' => array('sci'), 'scilab' => array('sci'),
  'smalltalk' => array('st'),
'smarty' => array(), 'smarty' => array(),
  'tcl' => array('tcl'),
'vb' => array('bas'), 'vb' => array('bas'),
'vbnet' => array(), 'vbnet' => array(),
'visualfoxpro' => array(), 'visualfoxpro' => array(),
'xml' => array('xml') 'whitespace' => array('ws'),
  'xml' => array('xml', 'svg'),
  'z80' => array('z80', 'asm', 'inc')
); );
} }
   
foreach ($lookup as $lang => $extensions) { foreach ($lookup as $lang => $extensions) {
if (in_array($extension, $extensions)) { if (in_array($extension, $extensions)) {
Line 1506... Line 1527...
* @since 1.0.8 * @since 1.0.8
*/ */
function optimize_keyword_group($key) { function optimize_keyword_group($key) {
$this->language_data['CACHED_KEYWORD_LISTS'][$key] = $this->language_data['CACHED_KEYWORD_LISTS'][$key] =
$this->optimize_regexp_list($this->language_data['KEYWORDS'][$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);
  }
  }
} }
   
/** /**
* Sets the content of the header block * Sets the content of the header block
* *
Line 1594... Line 1634...
*/ */
function set_link_target($target) { function set_link_target($target) {
if (!$target) { if (!$target) {
$this->link_target = ''; $this->link_target = '';
} else { } else {
$this->link_target = ' target="' . $target . '" '; $this->link_target = ' target="' . $target . '"';
} }
} }
   
/** /**
* Sets styles for important parts of the code * Sets styles for important parts of the code
Line 2286... Line 2326...
$length = strlen($part); $length = strlen($part);
for ($i = 0; $i < $length; ++$i) { for ($i = 0; $i < $length; ++$i) {
// Get the next char // Get the next char
$char = $part[$i]; $char = $part[$i];
$char_len = 1; $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;
  }
  }
  }
  }
   
$string_started = false; $string_started = false;
   
if (isset($is_string_starter[$char])) { if (isset($is_string_starter[$char])) {
// Possibly the start of a new string ... // Possibly the start of a new string ...
Line 2316... Line 2400...
} }
} }
$char_len = strlen($char); $char_len = strlen($char);
} }
   
if ($string_started) { if ($string_started && $i != $next_comment_regexp_pos) {
// Hand out the correct style information for this string // Hand out the correct style information for this string
$string_key = array_search($char, $this->language_data['QUOTEMARKS']); $string_key = array_search($char, $this->language_data['QUOTEMARKS']);
if (!isset($this->language_data['STYLES']['STRINGS'][$string_key]) || if (!isset($this->language_data['STYLES']['STRINGS'][$string_key]) ||
!isset($this->language_data['STYLES']['ESCAPE_CHAR'][$string_key])) { !isset($this->language_data['STYLES']['ESCAPE_CHAR'][$string_key])) {
$string_key = 0; $string_key = 0;
Line 2528... Line 2612...
   
// look for closing quote // look for closing quote
$start = $i + $hq_strlen; $start = $i + $hq_strlen;
while ($close_pos = strpos($part, $this->language_data['HARDQUOTE'][1], $start)) { while ($close_pos = strpos($part, $this->language_data['HARDQUOTE'][1], $start)) {
$start = $close_pos + 1; $start = $close_pos + 1;
if ($this->lexic_permissions['ESCAPE_CHAR'] && $part[$close_pos - 1] == $this->language_data['ESCAPE_CHAR']) { if ($this->lexic_permissions['ESCAPE_CHAR'] && $part[$close_pos - 1] == $this->language_data['HARDCHAR']) {
// make sure this quote is not escaped // make sure this quote is not escaped
foreach ($this->language_data['HARDESCAPE'] as $hardescape) { foreach ($this->language_data['HARDESCAPE'] as $hardescape) {
if (substr($part, $close_pos - 1, strlen($hardescape)) == $hardescape) { if (substr($part, $close_pos - 1, strlen($hardescape)) == $hardescape) {
// check wether this quote is escaped or if it is something like '\\' // check wether this quote is escaped or if it is something like '\\'
$escape_char_pos = $close_pos - 1; $escape_char_pos = $close_pos - 1;
while ($escape_char_pos > 0 while ($escape_char_pos > 0
&& $part[$escape_char_pos - 1] == $this->language_data['ESCAPE_CHAR']) { && $part[$escape_char_pos - 1] == $this->language_data['HARDCHAR']) {
--$escape_char_pos; --$escape_char_pos;
} }
if (($close_pos - $escape_char_pos) & 1) { if (($close_pos - $escape_char_pos) & 1) {
// uneven number of escape chars => this quote is escaped // uneven number of escape chars => this quote is escaped
continue 2; continue 2;
Line 2615... Line 2699...
   
$result .= "<span$string_attributes>" . $string . '</span>'; $result .= "<span$string_attributes>" . $string . '</span>';
$string = ''; $string = '';
continue; continue;
} else { } else {
// 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;  
}  
}  
}  
}  
//Have a look for regexp comments //Have a look for regexp comments
if ($i == $next_comment_regexp_pos) { if ($i == $next_comment_regexp_pos) {
$COMMENT_MATCHED = true; $COMMENT_MATCHED = true;
$comment = $comment_regexp_cache_per_key[$next_comment_regexp_key]; $comment = $comment_regexp_cache_per_key[$next_comment_regexp_key];
$test_str = $this->hsc(substr($part, $i, $comment['length'])); $test_str = $this->hsc(substr($part, $i, $comment['length']));
Line 3079... Line 3120...
$word = $keyword; $word = $keyword;
} }
   
$before = '<|UR1|"' . $before = '<|UR1|"' .
str_replace( str_replace(
array('{FNAME}', '{FNAMEL}', '{FNAMEU}', '.'), array(
array($this->hsc($word), $this->hsc(strtolower($word)), '{FNAME}',
$this->hsc(strtoupper($word)), '<DOT>'), '{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)))),
  '<DOT>'),
$this->language_data['URLS'][$k] $this->language_data['URLS'][$k]
) . '">'; ) . '">';
$after = '</a>'; $after = '</a>';
} }
} }
Line 3605... Line 3653...
} else { } else {
$this->lexic_permissions[$flag] = $perm; $this->lexic_permissions[$flag] = $perm;
} }
} }
unset($this->language_data['PARSER_CONTROL']['ENABLE_FLAGS']); 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 //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'; $style_filename = substr($file_name, 0, -4) . '.style.php';
if (is_readable($style_filename)) { if (is_readable($style_filename)) {
Line 3975... Line 4029...
if ($this->use_classes) { if ($this->use_classes) {
$attr = ' class="foot"'; $attr = ' class="foot"';
} else { } else {
$attr = " style=\"{$this->footer_content_style}\""; $attr = " style=\"{$this->footer_content_style}\"";
} }
if ($this->header_type == GESHI_HEADER_PRE_TABLE && $this->linenumbers != GESHI_NO_LINE_NUMBERS) { if ($this->header_type == GESHI_HEADER_PRE_TABLE && $this->line_numbers != GESHI_NO_LINE_NUMBERS) {
$footer = "<tfoot><tr><td colspan=\"2\">$footer</td></tr></tfoot>"; $footer = "<tfoot><tr><td colspan=\"2\">$footer</td></tr></tfoot>";
} else { } else {
$footer = "<div$attr>$footer</div>"; $footer = "<div$attr>$footer</div>";
} }
} }
Line 4561... Line 4615...
return true; return true;
} }
} }
   
?> ?>
   

Powered by WebSVN 2.2.1