I've done this sort of thing in the past using XML descriptions of the underlying elements (in this case, G- and M-Code commands) and an XSL style sheet to generate HTML from them. It has the additional advantage that all the boilerplate formatting is done consistently. But maintaining the text in XML format is a pain.