troff to html converter

I use troff (OK, groff) to do most of my word processing. I'm comfortable with it, I can use vi to write the text, and I can write programs to generate troff output, which means I can write programs to generate PDFs.

Recently I wanted to convert a troff document to html. One would think this is a solved problem, and I suppose it is, for some limited domains (like man pages). The converters I found (for Linux or FreeBSD) don't seem to work all that well for mm macros using tables. roff2html couldn't render a list or a table at all. groffer, same problem (not surprising, roff2html calls groffer).

It was time to fire up the Perl interpreter and hack out my own converter. It didn't turn out to be as hard as I feared, as long as I limited the program to handle the troff contstructs I use in 99% of my documents.

tr2html.pl handles the following troff and troff/mm/tbl markup:

  1. .AL ordered lists
  2. .BL bulleted lists
  3. .ce centered text
  4. .DS/.DE displays
  5. .ft font changes (any of R,B,I,BI,H,HB,HI,CW)
  6. .P paragraph
  7. .PH page header
  8. .PF page footer (treated as a sub-title)
  9. .sp vertical white space
  10. .TS/.TE tables (not everything, but enough for me)
  11. .ig and the other troff comments \" and \#
  12. \fB bold font in-line (but no other \fX or \f(XY markup)

The program won't handle nested tables, and perhaps not nested lists.

Program is public domain but I'd appreciate it if you'd leave my name in the comments. Oh, and if you make any improvements, I'd love to see them. Email webmaster at this domain to contact me.

Get it here.

Bill Dudley
February, 2018

001397 Views