How to do syntax highlight codes on drupal? The answer is the GeSHi Filter module. This module uses the third-party PHP library Generic Syntax Highlighter (GeSHi ), supporting more than 130 programming languages ( including ASP, C, C++, C#, CSS, Drupal source code, Javascript, MySQL, Objective C, Perl, PHP, Python, Rails, Ruby, Visual Basic, XML and more). Here I will teach how to install and configure this syntax highlighting module on drupal 6 step by step.
- Download GeSHi Filter for syntax highlighting from: http://ftp.drupal.org/files/projects/geshifilter-6.x-1.2.tar.gz , unpack the module and put the “geshifilter” folder to your drupal app, inside sites/all/modules directory ( create this directory if there isn’t one).
-
Download GeSHi Library from: http://sourceforge.net/projects/geshi/files/geshi/GeSHi%201.0.8.4/GeSHi-1.0.8.4.zip/download, unzip the file and put the “geshi” folder inside the GeSHi module ( that will be sites/all/modules/geshifilter)
Enable GeSHi Filter for syntax highlighting module. ( Open http://example.com/admin/build/modules, check the check box with the label GeSHi Filter and save configuration. replacing example.com with your site domain name)
-
Enable GeSHi filter for your input filters. Open http://example.com/admin/settings/filters, Configure the Input format you want to have syntax highlighting feature, turn on the GeSHi filter for that input format and save configuration. For Example, I want to use syntax highlighting text inputed by Filtered HTML input format, I am going to turn the GeSHi filter option for the input format on, and I even Rearrage filters, to make sure the GeSHi filter is under the bottom of the filters.
-
Done! Create a node content with the input format you just added with the new syntax highlighting feature, add codes like:
ruby code example:
<ruby>
a = 6
b = "drupal"
c = "syntax highlighting"
d = b + a.to_s + c
</ruby>
will turn into:
a = 6
b = "drupal"
c = "syntax highlighting"
d = b + a.to_s + c
There is line numbering feature, which by default is turned off. You may enable it if you want.
HTML and CSS code highlighting function is disable by default too, you can turn them on from geshifilter’s configuration page (admin/settings/geshifilter/languages/disabled)
Post new comment