Subscribe for updates on posts
Be the first to read the latest news

Codepress extension – syntax highlighting for Velocity

November 19th, 2008 by Marius Hanganu in Javascript

For the impacients, here’s a link on how Velocity syntax highlighting can be done in a browser.

Codepress is an excellent script for syntax highlighting when editing code using the browser. We needed some syntax highlighting for one of the projects at Tremend which included some Velocity code. So after some hacking I came out with a set of regular expressions which should match almost all instructions for a Velocity template.

Of course, the well known problem of matching paranthesis is not solved, so the expressions work only up to three levels of embedded paranthesis, which should be enough for most projects. If more levels of embedded paranthesis are needed, more expressions can be defined.

Here’s how the editor looks like

Velocity in Codepress

Also, velocity is always used in conjunction with other language. Whether it’s about generating HTML, XML or any other piece of text, Velocity is a template engine.

The rules defined in velocity.js are comprising also HTML and JavaScript rules, since the code we’re generating is HTML + JavaScript.