diff options
-rw-r--r-- | inc/parser/xhtml.php | 19 | ||||
-rw-r--r-- | inc/parserutils.php | 24 |
2 files changed, 29 insertions, 14 deletions
diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index b45e310ca..4476cbe3b 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -304,9 +304,11 @@ class Doku_Renderer_xhtml extends Doku_Renderer { /** * Execute PHP code if allowed * + * @param string $wrapper html element to wrap result if $conf['phpok'] is okff + * * @author Andreas Gohr <andi@splitbrain.org> */ - function php($text) { + function php($text, $wrapper='code') { global $conf; if($conf['phpok']){ @@ -315,31 +317,33 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $this->doc .= ob_get_contents(); ob_end_clean(); } else { - $this->code($text, 'php'); + $this->doc .= p_xhtml_cached_geshi($text, 'php', $wrapper); } } function phpblock($text) { - $this->php($text); + $this->php($text, 'pre'); } /** * Insert HTML if allowed * + * @param string $wrapper html element to wrap result if $conf['htmlok'] is okff + * * @author Andreas Gohr <andi@splitbrain.org> */ - function html($text) { + function html($text, $wrapper='code') { global $conf; if($conf['htmlok']){ $this->doc .= $text; } else { - $this->code($text, 'html4strict'); + $this->doc .= p_xhtml_cached_geshi($text, 'html4strict', $wrapper); } } function htmlblock($text) { - $this->html($text); + $this->html($text, 'pre'); } function preformatted($text) { @@ -371,9 +375,6 @@ class Doku_Renderer_xhtml extends Doku_Renderer { if ( is_null($language) ) { $this->preformatted($text); } else { - //strip leading and trailing blank line - $text = preg_replace('/^\s*?\n/','',$text); - $text = preg_replace('/\s*?\n$/','',$text); $this->doc .= p_xhtml_cached_geshi($text, $language); } } diff --git a/inc/parserutils.php b/inc/parserutils.php index 2c4da90f9..a171dc0e6 100644 --- a/inc/parserutils.php +++ b/inc/parserutils.php @@ -625,9 +625,18 @@ function p_get_first_heading($id, $render=true){ /** * Wrapper for GeSHi Code Highlighter, provides caching of its output * + * @param string $code source code to be highlighted + * @param string $language language to provide highlighting + * @param string $wrapper html element to wrap the returned highlighted text + * * @author Christopher Smith <chris@jalakai.co.uk> */ -function p_xhtml_cached_geshi($code, $language) { +function p_xhtml_cached_geshi($code, $language, $wrapper='pre') { + global $conf; + + // remove any leading or trailing blank lines + $code = preg_replace('/^\s*?\n|\s*?\n$/','',$code); + $cache = getCacheName($language.$code,".code"); if (@file_exists($cache) && !$_REQUEST['purge'] && @@ -644,15 +653,20 @@ function p_xhtml_cached_geshi($code, $language) { $geshi->set_encoding('utf-8'); $geshi->enable_classes(); $geshi->set_header_type(GESHI_HEADER_PRE); - $geshi->set_overall_class("code $language"); $geshi->set_link_target($conf['target']['extern']); - $highlighted_code = $geshi->parse_code(); - + // remove GeSHi's wrapper element (we'll replace it with our own later) + // we need to use a GeSHi wrapper to avoid <BR> throughout the highlighted text + $highlighted_code = preg_replace('!^<pre[^>]*>|</pre>$!','',$geshi->parse_code()); io_saveFile($cache,$highlighted_code); } - return $highlighted_code; + // add a wrapper element if required + if ($wrapper) { + return "<$wrapper class=\"code $language\">$highlighted_code</$wrapper>"; + } else { + return $highlighted_code; + } } //Setup VIM: ex: et ts=2 enc=utf-8 : |