The output mostly follows the format described by the W3C Polyglot Markup
note, with a few changes to improve compatibility with modern browsers.
In addition, the source document is parsed and normalized mostly
according to the HTML
specification, with some changes to allow it to work in a single
streaming pass, and be more robust against untrusted input. It handles
malformed input (like unclosed tags) more or less the same way as
browsers.
This is a demo of the polyglot
package of github.com/pgaskin/htmlstream,
a Go library for streaming parsing and transformation of HTML, XHTML and
XML which passes input through byte for byte unless modified, tolerates
malformed input, and uses has bounded resource usage, even on untrusted
content.
This tool is also available as a command-line
tool.