« Back to blog

Blog: CakePHP Syntax Highlighting Helper

Graham Weldon

01 November, 2008

Well, goals rock. You can't get anything really productive done without setting attainable goals. They help structure your thought processes, and give you direction. They keep you on track, and they pay off in the end.

I've had on my list of things to complete for this site 'Syntax Highlighter', for a while... I didn't really know what I was going to do. There are a whole bunch of Javascript solutions out there that can do it, but I don't like that they take a while to render, and you are handing the visual presentation of part of your site off to the clients browser to render, if its got the power to.

So it was pretty much always going to be server side. I set on towards my goal tonight, being a little cocky about it, giving myself under 30 minutes to get it complete and working in some manner on the site. I managed to complete the job with 7 minutes to spare!! So, we not have a syntax highlighting CakePHP Helper thats doing the job nicely. Its based on the GeSHi Syntax Highlighter which is done in PHP and fits nicely into CakePHP as a vendor.

After the initial test and success, I took some time to implement some of the more advanced options provided by GeSHi into the Helper to allow people using the helper some quick and easy customisation of the output. This includes currently: Wrapper tag (using the CakePHP standard 'tag' option), Line number formats, case modification for keywords, Assignment of element ID, Assignment of CSS classes to the code wrapper, Language setting, Source setting and finally, Line Number start specification (so you can start at a line number other than 1).

While this is not yet public, You should look forward to a release onto the CakePHP bakery (and probably here too) in the next week or so.

If I have not released it by then, for God sake.. email me and abuse me till I post it up.

Comments