Difference between revisions of "Code syntax highlighting"

Jump to: navigation, search
(See also)
Line 55: Line 55:
* [http://moodle.org/mod/forum/discuss.php?d=25413 Forum post introducing the Filter]
* [http://moodle.org/mod/forum/discuss.php?d=25413 Forum post introducing the Filter]
* [http://moodle.org/mod/forum/discuss.php?d=43266 Forum thread for progress reports and feedback]
* [http://qbnz.com/highlighter/ GeSHi homepage]
* [http://qbnz.com/highlighter/ GeSHi homepage]

Revision as of 10:44, 6 April 2006

You can color or highlight code snippets within Moodle resources, forum posts etc. To do so you must install the GeSHi (Generic Syntax Highlighter) Filter. This makes the power of GeSHI available in Moodle through the use of a pair of special tags.


You can download the GeSHi filter from here:


Then follow the instructions for Installing a Filter.

Instructions for use

Enclose your code in spans like so:

<span syntax="langname"> your code goes here </span> 

Supported languages

  • asm,
  • bash,
  • cpp,
  • CSS
  • lisp
  • matlab
  • HTML
  • PHP
  • pascal
  • xml

and many others. See the GeSHi homepage for full details.


You can add the following options to the span tags in the same way you would add HTML attributes. The syntax attribute, specifying the programming language, must come first and all others are optional.

  • linenumbers="yes" - displays linenumbers, defaults to "no"
  • urls="no" - switches off keyword to URL conversion, defaults to "yes"
  • indentsize="num" - alters the width of tabs, measured in characters/columns, default is ?

Example with options:

 <span syntax="langname" linenumbers="yes" urls="no" indentsize="2"> 


The filter has recently been installed on Moodle.org and can be seen in use there. For example see this post:


The GeSHi homepage also has an interactive demo.


See also