summaryrefslogtreecommitdiff
path: root/inc/parserutils.php
diff options
context:
space:
mode:
authorChris Smith <chris.eureka@jalakai.co.uk>2008-03-29 20:44:43 +0100
committerChris Smith <chris.eureka@jalakai.co.uk>2008-03-29 20:44:43 +0100
commit5d568b990e8fc3c849ba1d694019eae8e42763e4 (patch)
treec1ed91244a3b196cc0b64e7c12dd7dd11211139a /inc/parserutils.php
parent54041c77c7e08db6205a57148735b3266b711756 (diff)
downloadrpg-5d568b990e8fc3c849ba1d694019eae8e42763e4.tar.gz
rpg-5d568b990e8fc3c849ba1d694019eae8e42763e4.tar.bz2
Fix for FS#1350
Inline modes, <php> and <html>, when their associated config setting is off, will generate highlighted text wrapped in a <code> element. There is a slight change in behaviour for p_xhtml_cached_geshi(), it will now strip leading and trailing blank lines from the input code string. Also fixes an issue where global $conf wasn't declared, preventing the ['target']['extern'] setting being passed to GeSHi darcs-hash:20080329194443-f07c6-00db3d502b07a6ff0c7f6e5c74a3691438504bcb.gz
Diffstat (limited to 'inc/parserutils.php')
-rw-r--r--inc/parserutils.php24
1 files changed, 19 insertions, 5 deletions
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 :