Skip to content

GeSHi Syntax Highlighter Plugin

World Wide Web Server edited this page Jul 4, 2012 · 12 revisions

This article describes a plugin that I wrote that enables GeSHi syntax highlighting in CodeIgniter Sites.

[h2]What this Is[/h2]

This is a plugin (aka "hook") for CodeIgniter that will convert anything between ... tags to GeSHi-higlighted content. If you're not familiar with GeSHi, you can read more about it at the GeSHi Website ([url]http://qbnz.com/highlighter/[/url]).

[h2]How to Install[/h2]

  1. Ensure that [b]$enable_hooks = TRUE;[/b] in your application/config/config.php file.

  2. Download the GeShi plugin from [url]http://geshiforci.googlecode.com/files/ci_geshi.zip[/url]

  3. Unzip the files, and extract the "geshi_hook.php" file and "geshi" folder to your hooks directory in your application folder. (you may have to create the "hooks" folder if it doesn't already exist)

  4. Add the following code to your application/config/hooks.php file:

[code] /* ----------------------------------------------------- / / -- GeSHi Plugin Hook -- / / ----------------------------------------------------- */ $hook['display_override'] = array( 'class' => 'Geshi_hook', 'function' => 'run_geshi_filter', 'filename' => 'geshi_hook.php', 'filepath' => 'hooks', 'params' => array('line_numbers_on')); [/code]

[h2]How to Use[/h2]

It's simple. Anywhere that you put ... in your output code (in your view files), this plugin will convert it to <pre class='geshi'>..., and automatically highlight everything between the tags.

If you want to specify a language to highlight the code, simply add an attribute to the tag: ... or ..., etc... GeSHi supports dozens of langauges.

[h2]More Information[/h2]

I have a more detailed explanation of this plugin at the Google Code site: [url]http://code.google.com/p/geshiforci/[/url]

Clone this wiki locally