Man Highlighting With Enscript 16 Nov, 2006
I’ve been fixing a bunch of outstanding things that bugged me in Trac this week, and one of those is missing mime-types on several of the files in the source tree. For example, there are some manpages. I had no idea what mime-type these were supposed to have, so (about three days later) I found out that manpage source is intended to be processed with troff and that nroff is apparently a newer alternative. Most of the interesting-looking commands in manpage source are in some sort of macro package. I thought I’d set the proper mime-type and see if enscript would properly highlight them, and… it won’t. Its dialect called nroff is definitely not the one that manpages, emacs, and vim call nroff format. I had meant to take a class on parser generation at UNT, but it didn’t fit my schedule and thus I never learned all about NFA’s, DFA’s, and how to use unix text processing tools “the right way.”
Left on my own, one further day later, I’ve hacked around with states and enscript enough to make a passable parser which works for what I need it to. It’s kind of a quick hack, and doesn’t do any parsing of complex arguments that nroff.el mentions might exist, but it works for the random manpages that I threw at it. Feel free to send me improvements!
See my manpage.st for states. Place into $PREFIX/share/enscript/hl/ and to test run something like echo "<pre>" > test.html; enscript --color -h -q --language=html -p - -Emanpage /usr/share/man/man1/chmod.1 >> test.html; open test.html on the Mac.