As I've mentioned before, all the entries in this blog are written in asciidoc, which is very nice for a lightweight markup language, particularly in terms of embedding code fragments and having them marked up nicely.
Asciidoc uses GNU Source-highlight as its backend for generating pretty code fragments, which does a reasonable job, and its author is very responsive to feedback - he's fixed a couple of bugs in the Fortran and XML modules for me.
However, I've been growing dissatisfied with its use, for two reasons.
-
it has a very heavyweight dependency on boost, for its regex library. Compiling boost takes several hours, and this seems to me like massive overkill for a bit of code highlighting.
-
It is purely regex-driven. Furthermore, all language front-ends are defined in terms of a mini-regex language. This means that its markup capabilities are fundamentally limited to a very simple regex subset.
In any case, it can't approach the expressiveness of Emacs font-lock highlighting, which is what I'm used to.
So, I thought it ought to be possible to abuse one of several available emacs-lisp packages to do the job, and indeed it was. The script available here is a wrapper around a modified version of htmlfontify, and works like so:
htmlfontify -mode $MODENAME $FILENAME
or if $FILENAME is -, it takes input on stdin. It will print out a properly marked-up fragment of HTML on stdout, marked up according to emacs, in $MODENAME-mode fontification.
|
Note
|
Importantly, it is entirely standalone, with no dependencies beyond Emacs 21 or better, which is installed everywhere these days. |
This was easy to write an asciidoc filter for, so code in this blog will henceforth be marked up by emacs.