I wanted to have a syntax highlighting facility for this site as I knew there would be plenty of code on here. First I just used PHP's highlight_string function, but soon realised it's drawbacks - not XHTML compliant, no line numbers, only works for PHP...

So I did a bit of Googling and found two major contenders, the PEAR::Package::Text_Highlighter library, and GeSHI. The PEAR one looks a little more complex and bulky, but GeSHI seemed perfect.

So I started playing with GeSHI and found it incredibly easy to get to grips with. The highlighting was very customiseable and it natively supported more languages than I would ever need.

The main issue I have with GeSHI was that it killed my lovely lined display. for some reason I couldn't get it to follow the lines. Eventually I realised that it was a Firefox / IE issue, with IE behaving and Firefox being odd (?!). I didn't see that one coming. However I found that by removing all of the inline styles and using CSS instead I managed to allieviate this issue.

Now I have the facility to syntax highlight code in any one of the 53 odd languages GeSHI supports. Pretty nice!

The next step was to integrate this with my existing CakePHP text-to-html converting helper. I created some new BBCode tags like [code syntax='javascript'] to make it easy.