diff options
author | Andreas Gohr <andi@splitbrain.org> | 2007-07-02 22:07:15 +0200 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2007-07-02 22:07:15 +0200 |
commit | 14e7550de1640180bad222469bbe117319313c74 (patch) | |
tree | 2d6a8a9cd27ca8abf8f05fbd067f1d8528826113 /inc/geshi.php | |
parent | db4244666982113c629209be3c2f26a9201a17e9 (diff) | |
download | rpg-14e7550de1640180bad222469bbe117319313c74.tar.gz rpg-14e7550de1640180bad222469bbe117319313c74.tar.bz2 |
GeSHi update to 1.0.7.20
darcs-hash:20070702200715-7ad00-654e2eb59ffaa2d72e907cd7aea5237a903727fa.gz
Diffstat (limited to 'inc/geshi.php')
-rw-r--r-- | inc/geshi.php | 111 |
1 files changed, 96 insertions, 15 deletions
diff --git a/inc/geshi.php b/inc/geshi.php index 358b7a8e2..832b62efe 100644 --- a/inc/geshi.php +++ b/inc/geshi.php @@ -41,7 +41,7 @@ // /** The version of this GeSHi file */ -define('GESHI_VERSION', '1.0.7.19'); +define('GESHI_VERSION', '1.0.7.20'); // Define the root directory for the GeSHi code tree if (!defined('GESHI_ROOT')) { @@ -273,6 +273,13 @@ class GeSHi { var $footer_content_style = ''; /** + * Tells if a block around the highlighted source should be forced + * if not using line numbering + * @var boolean + */ + var $force_code_block = false; + + /** * The styles for hyperlinks in the code * @var array */ @@ -313,6 +320,14 @@ class GeSHi { */ var $highlight_extra_lines_style = 'color: #cc0; background-color: #ffc;'; + /** + * The line ending + * If null, nl2br() will be used on the result string. + * Otherwise, all instances of \n will be replaced with $line_ending + * @var string + */ + var $line_ending = null; + /** * Number at which line numbers should start at * @var int @@ -373,6 +388,12 @@ class GeSHi { */ var $tab_width = 8; + /** + * Should we use language-defined tab stop widths? + * @var int + */ + var $use_language_tab_width = false; + /** * Default target for keyword links * @var string @@ -973,7 +994,35 @@ class GeSHi { */ function set_tab_width($width) { $this->tab_width = intval($width); - } + //Check if it fit's the constraints: + if($this->tab_width < 1) { + //Return it to the default + $this->tab_width = 8; + } + } + + /** + * Sets whether or not to use tab-stop width specifed by language + * + * @param boolean Whether to use language-specific tab-stop widths + */ + function set_use_language_tab_width($use) { + $this->use_language_tab_width = (bool) $use; + } + + /** + * Returns the tab width to use, based on the current language and user + * preference + * + * @return int Tab width + */ + function get_real_tab_width() { + if (!$this->use_language_tab_width || !isset($this->language_data['TAB_WIDTH'])) { + return $this->tab_width; + } else { + return $this->language_data['TAB_WIDTH']; + } + } /** * Enables/disables strict highlighting. Default is off, calling this @@ -1213,6 +1262,17 @@ class GeSHi { } /** + * Sets whether to force a surrounding block around + * the highlighted code or not + * + * @param boolean Tells whether to enable or disable this feature + * @since 1.0.7.20 + */ + function enable_inner_code_block($flag) { + $this->force_code_block = (bool)$flag; + } + + /** * Sets the base URL to be used for keywords * * @param int The key of the keyword group to set the URL for @@ -1311,6 +1371,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 what number line numbers should start at. Should * be a positive integer, and will be converted to one. @@ -1686,7 +1755,10 @@ class GeSHi { ($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", "</span>\n<span$attributes>", $rest_of_comment); + $test_str .= str_replace( + "\n", "</span>\n<span$attributes>", + str_replace("\n ", "\n ", $rest_of_comment) + ); } else { $test_str .= $rest_of_comment; @@ -1699,7 +1771,7 @@ class GeSHi { $test_str .= "\n"; } } - $i = $close_pos + $com_len - 1; + $i = $close_pos + $com_len - 1; // parse the rest $result .= $this->parse_non_string_part($stuff_to_parse); $stuff_to_parse = ''; @@ -1835,6 +1907,7 @@ class GeSHi { /// 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) { if (false === strpos($line, "\t")) { $lines[$key] = $line; @@ -1842,7 +1915,6 @@ class GeSHi { } $pos = 0; - $tab_width = $this->tab_width; $length = strlen($line); $result_line = ''; @@ -1886,7 +1958,7 @@ class GeSHi { $strs = array(0 => ' ', 1 => ' '); for ($k = 0; $k < ($tab_width - (($i - $pos) % $tab_width)); $k++) $str .= $strs[$k % 2]; $result_line .= $str; - $pos++; + $pos += ($i - $pos) % $tab_width + 1; if (false === strpos($line, "\t", $i + 1)) { $result_line .= substr($line, $i + 1); @@ -1907,13 +1979,17 @@ class GeSHi { $result = implode("\n", $lines); } // Other whitespace - $result = str_replace(' ', ' ', $result); - $result = str_replace(' ', ' ', $result); + // BenBE: Fix to reduce the number of replacements to be done $result = str_replace("\n ", "\n ", $result); + $result = str_replace(' ', ' ', $result); if ($this->line_numbers == GESHI_NO_LINE_NUMBERS) { - $result = nl2br($result); - } + if ($this->line_ending === null) { + $result = nl2br($result); + } else { + $result = str_replace("\n", $this->line_ending, $result); + } + } return $result; } @@ -2422,7 +2498,8 @@ class GeSHi { if ($this->line_numbers != GESHI_NO_LINE_NUMBERS) { return "$header<ol$ol_attributes>"; } - return $header; + return $header . + ($this->force_code_block ? '<div>' : ''); } // Work out what to return and do it @@ -2436,10 +2513,12 @@ class GeSHi { } else { if ($this->header_type == GESHI_HEADER_PRE) { - return "<pre$attributes>$header"; + return "<pre$attributes>$header" . + ($this->force_code_block ? '<div>' : ''); } else if ($this->header_type == GESHI_HEADER_DIV) { - return "<div$attributes>$header"; + return "<div$attributes>$header" . + ($this->force_code_block ? '<div>' : ''); } } } @@ -2488,13 +2567,15 @@ class GeSHi { if ($this->line_numbers != GESHI_NO_LINE_NUMBERS) { return "</ol>$footer_content</div>"; } - return "$footer_content</div>"; + return ($this->force_code_block ? '</div>' : '') . + "$footer_content</div>"; } else { if ($this->line_numbers != GESHI_NO_LINE_NUMBERS) { return "</ol>$footer_content</pre>"; } - return "$footer_content</pre>"; + return ($this->force_code_block ? '</div>' : '') . + "$footer_content</pre>"; } } |