Introducing Camlhighlight
Last time, I told you about Blahcaml, a library that wraps Blahtex, thus providing facilities for converting equations in TeX format into MathML. The news is that in the meantime I've completed the missing pieces in Blahcaml (namely proper error reporting), and released version 1.2. Functionality-wise, I consider the library "finished". Please let me know if you find any glaring omissions or bugs.
Another feature I want for Lambdoc is the ability to display syntax-highlighted source code. And so I spent some time investigating the available options for highlighting source code within Ocaml. Note that I wanted a generic highlighter, one that could handle most common programming and markup languages. Because there is no Ocaml library up to the task, I looked at the C/C++ options and even at the possibility of co-opting Vim for the task.
Using Vim is a seductive idea given the high-quality of Vim's syntax-highlighting, but unfortunately flounders on Vim's manifest unsuitability to be used inside scripts. Yes, you can invoke Vim from the command line with a sequence of commands, but I saw no way of camouflaging the fact that Vim's interface still pops up, even if for a split-second.
On the C/C++ side the options are GNU Source-highlight and Highlight. While both are command line applications, their core routines can easily be extracted and made into a library. Moreover, their licenses are friendly to this operation. The downside is that the quality of the highlight of either application is not as good as Vim's, at least as far as highlighting Ocaml is concerned.
I've chosen Highlight for the time being. The wrapper library is called Camlhighlight and is now at version 0.5. While there are still some features missing, it's already quite usable. The library has functions for generating an Ocsigen-friendly XHTML.M output, both in fancy and more plain style (it's possible to customise whether or not one wants line numbers and/or zebra stripes).

Comments