As a part of a larger sets of development tools which I am working on currently, I have developed a general syntax highlighter generator which does just that (not yet with styles though, this is coming). I wanted to put in on GitHub and do a bit more polishing / development, but since you aksed the question, here goes.
- From a simple lixical specification, a whole package is generated, which provides code highlighting capabilities for a given language. Once you generate the package, you (supposedly) start happily using it, and don't depend on the master package (the generator), unless you want to generate another highlighter package. For those who are familiar with js Google prettify, this is similar in spirit, but less developed as of now.
- The lexical analyzer is generated automatically from your specifications, but you can also override it with a custom one.
- You can customize it in many ways, including colors for keywords etc.
- There are several optimizations which can be switched on and off, to control the responsiveness of the highlighter
- keywords etc are highlighted as you type
- Bracket and paren-matching / highlighting is supported.
- Cells can be evaluatable.
For the impatient, the package and a notebook with an example for C language can be downloaded here and here. I also made a gist where one can look at them as well. The notebook can be regarded as a brief manual to the package.
CodeHighlighterGenerator.mpackage into any directory where Mathematica can find it (e.g.
CodeHighlighterGenerator.nbnotebook and follow the discussion there.
I plan to place the project to GitHub properly in a few days. There are several directions in which I plan to extend the package, it is a work in progress. All comments & suggestions are more than welcome!