Syntax Highlighting for Drupal

Unknown size: m.

While writing my last post, I felt the need to post some source code examples and I wanted them to be pretty. Looking around drupal.org, I failed to find what I wanted. There were a few options, the codefilter module, but that only supported PHP highlighting, the geshifilter module, but that doesn’t support Drupal 5.x which I’m running, or patches against codefilter to add GeSHi support.

So I did what was probably the wrong thing and wrote my own. At least I didn’t write it from scratch, I based it largely on codefilter, with some inspiration from the patches to codefilter that add GeSHi support.

I hacked up GeSHi a little as it wants to link keywords of most languages to reference sites. While this sounds like a good idea in theory it was linking HTML keywords off to some random site I didn’t really like and didn’t think was that good, so I disabled that functionality.

Using the module is pretty straightforward. You wrap your source code in tags that look like

<code language="LANGUAGE">...</code>

where LANGUAGE is a supported language. If there’s an enter in your block then it treats it as a block otherwise it renders it inline. Also, some whitespace is trimmed, so you can force a single line to be treated as a block by putting an enter at the start or the end.

Right now it’s being maintained in the same source control as I’m using for my web site, but I’ll move it into Trac and Subversion eventually. For the time being it’s attached.

This entry was posted in Uncategorized and tagged . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

5 Comments

  1. Posted April 7, 2007 at 3:38 pm | Permalink

    How do I get it to work? Hi Ian.
    I too need a module that does what yours does. I have installed your syntax highlighter and enabled it but it doesn’t seem to do anything.
    Maybe I have missed something?
    Are there any other configurations options that I don’t know about?
    Thanks for any help and thanks for making the module!

    http://www.techjournal.co.uk
    http://www.pagerankings.info

  2. ian
    Posted May 11, 2007 at 11:53 am | Permalink

    Re: Markus The current version of the code is linked off this post: http://ianloic.com/sites/ianloic.com/files/syntax-0.1.tar.gz

  3. Posted April 22, 2007 at 12:27 pm | Permalink

    I am also interested in this I am also interested in this module for my sites powered by Drupal.

  4. Posted December 28, 2007 at 1:23 pm | Permalink

    Images Hi Ian.

    Syntax Highlighting is working normal, thanks to you.

    Perhaps, i should to ask this question on another topic, but i have some problems with images. What modules are needed to ensure that I was able to attach images to news? I can’t find :(

    Thanks. Poul

  5. yo2lux
    Posted July 4, 2007 at 1:33 pm | Permalink

    Bug Geshi filter has a bug, please see this: http://drupal.org/node/156808
    Someone know a solution how to fix this problem, the conflict between geshi filter and bbcode ?

    Please post an answer to drupal forum! Thanks

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

Subscribe without commenting