diff options
author | chris <chris@jalakai.co.uk> | 2006-07-29 00:56:49 +0200 |
---|---|---|
committer | chris <chris@jalakai.co.uk> | 2006-07-29 00:56:49 +0200 |
commit | 8f7d700c4ef8ddaf2cccb81d5cd641eb975faf90 (patch) | |
tree | 312f4c4d2992070aa36d781aafde8a62d0b4f837 | |
parent | a6ad9963d9c7361f38d1f9da109c6c50d88e2b0a (diff) | |
download | rpg-8f7d700c4ef8ddaf2cccb81d5cd641eb975faf90.tar.gz rpg-8f7d700c4ef8ddaf2cccb81d5cd641eb975faf90.tar.bz2 |
Provide a fragment cache for GeSHi output
darcs-hash:20060728225649-9b6ab-124a5511574bd9955f56d0426586f877b9ec66c8.gz
-rw-r--r-- | inc/parser/xhtml.php | 12 | ||||
-rw-r--r-- | inc/parserutils.php | 33 |
2 files changed, 34 insertions, 11 deletions
diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index 9518cd12e..3c71bb54e 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -389,17 +389,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { } else { //strip leading blank line $text = preg_replace('/^\s*?\n/','',$text); - // Handle with Geshi here - require_once(DOKU_INC . 'inc/geshi.php'); - $geshi = new GeSHi($text, strtolower($language), DOKU_INC . 'inc/geshi'); - $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']); - - $text = $geshi->parse_code(); - $this->doc .= $text; + $this->doc .= p_xhtml_cached_geshi($text, $language); } } diff --git a/inc/parserutils.php b/inc/parserutils.php index 77ef842ab..1bebfc698 100644 --- a/inc/parserutils.php +++ b/inc/parserutils.php @@ -493,4 +493,37 @@ function p_get_first_heading($id){ return null; } +/** + * Wrapper for GeSHi Code Highlighter, provides caching of its output + * + * @author Christopher Smith <chris@jalakai.co.uk> + */ +function p_xhtml_cached_geshi($code, $language) { + + $cache = getCacheName($language.$code,".code"); + + if (@file_exists($cache)) { + + $highlighted_code = io_readFile($cache, false); + touch($cache); + + } else { + + require_once(DOKU_INC . 'inc/geshi.php'); + + $geshi = new GeSHi($code, strtolower($language), DOKU_INC . 'inc/geshi'); + $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(); + + io_saveFile($cache,$highlighted_code); + } + + return $highlighted_code; +} + //Setup VIM: ex: et ts=2 enc=utf-8 : |