GeSHi Filter on Drupal 6

When writing articles about drupal or anything that requires code to be shown, its great to have syntax highlighting just to liven up the page.

UPDATE: Setup GeSHi on Drupal 7

Requirements:

  1. Drupal 6
  2. GeSHi Filter drupal Module http://drupal.org/project/geshifilter
  3. GeSHi Code http://qbnz.com/highlighter/

Step 1 Install GeSHi

Go to http://drupal.org/project/geshifilter and download the module and place it in sites/all/modules. Download the geshi library from http://qbnz.com/highlighter/ and extract the geshi folder in the zip file into sites/all/modules/geshifilter.

Right now you should have two folders:

  1. sites/all/modules/geshifilter (Module folder)
  2. sites/all/modules/geshifilter/geshifilter (geshi library folder)

Once everything has be copied over go to Administer >> Site Building >> Modules and enable the module.

Step2 Configure GeSHi

Go to Administer >> Site Configuration >> Input Filters and on your default filter click on configure.
fig1_1.jpg

Tick the GeSHi filter check box under filters.

fig2_1.jpg

Creating a story
Go to create content and click on story. If you click on “Input Filters” you’ll notice the following:
fig3_2.jpg

From there you can see that GeSHi is enabled.
To add php code just add the following code:
fig4_1.jpg

Make sure you wrap all php code around the . Check out the end result.

fig5_1.jpg

NOTE:To get a bunch of examples click on “More information about formatting options” link.

The module also gives you a “Source code node” content type where you can paste in a bunch of code in the body and set language type via a drop down. You don’t have to wrap the code wrap the tag. You would use this content type to just display code.

fig6_0.jpg

GeSHi Configuration options

To change any options for the module go to Administer >> Site Configuration >> GeSHi Filter.

By default the module doesn’t enable all languages, to enable or disable click on the languages tab then All to view available languages.
fig7_0.jpg

To enable a language just tick the check box and hit save configuration.