It's better when it's simple

User Tools

Site Tools


Syntax highlighting by Geshi

DokuWiki includes GeSHi - Generic Syntax Highlighter - for formatting <code> and <file> blocks. Please refer to the documentation at for more information about how to use its class.

Please refer to the GeSHi class documentation for implementation details.

Example usage

Example how DokuWiki applies the highlighter for its code and file blocks. It is embedded in a wrapper method p_xhtml_cached_geshi() that caches the output to reduce the server load.

$code = '... syntax to higlight ...';
$geshi = new GeSHi($code, $language);
//when you like to use your own wrapper, remove GeSHi's wrapper element
//we need to use a GeSHi wrapper to avoid <BR> throughout the highlighted text
$highlighted_code = trim(
    preg_replace('!^<pre[^>]*>|</pre>$!', '', $geshi->parse_code()),

See also

devel/geshi.txt · Last modified: 2023-09-16 00:44 by Klap-in

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki