Should I use polyglot documentation?

Hamiltonzth

New Member
It's possible to interleave a C++ source file with an HTML document:\[code\]//<![IGNORE[/*]]><html><head><title>Example</title></head><body><p>Example</p></body></html><![IGNORE[*/#include <iostream>int main(int argc, char** argv) { std::cout << "Hello, world!\n";}/*]]><![IGNORE[*///]]>\[/code\]This leaves a stray \[code\]//\[/code\] at the start of the HTML document, which can be covered up by wrapping the body content in a \[code\]<div>\[/code\]:\[code\]...<body><div id="main"></div></body>...\[/code\]Which is styled to fill the content area with an opaque background:\[code\]#main { background: #ffffff; left: 0; position: absolute; top: 0;}\[/code\]Is it a good idea to document code this way? It's more flexibile than, say, Doxygen, but still allows quite structured formats to be used, such as DocBook. It also has the advantage that the source file not only contains the documentation, but is the documentation. Renaming or linking the source file to a filename ending in \[code\].htm\[/code\] is enough to make a Web browser read it as HTML.The only problem is that stray C++ comment at the start of the XML document, which (correct me if I'm wrong) ought to prevent it from validating. Is there any workaround for that?Edit: Changed to use \[code\]<![IGNORE[...]]>\[/code\] instead of \[code\]<!--...-->\[/code\] to avoid clashes with \[code\]--\[/code\].
 
Top