DokuWiki

It's better when it's simple

User Tools

Site Tools


Sidebar

Translations of this page?:

Learn about DokuWiki

Advanced Use

Corporate Use

Our Community


Follow us on Facebook, Twitter and other social networks.

devel:geshi

Syntax highlighting by Geshi

DokuWiki includes GeSHi - Generic Syntax Highlighter - for formatting <code> and <file> blocks. Please refer to the documentation at http://qbnz.com/highlighter/documentation.php 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, DOKU_INC . 'inc/geshi');
$geshi->set_encoding('utf-8');
$geshi->enable_classes();
$geshi->set_header_type(GESHI_HEADER_PRE);
$geshi->set_link_target($conf['target']['extern']);
 
// 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()),
    "\n\r"
);

See also

devel/geshi.txt · Last modified: 2013-12-10 12:31 by 109.195.194.200