

Good tools to convert HTML5 to XHTML5? - schrijver

Dear HN—HTML5 is the Lingua Franca of the web. It is everywhere, and because of the forgiving nature of parsers relatively easy to author and to generate.<p>However, sometimes I need to adapt existing HTML5 content to XHTML5, its more strict XML compatible serialisation. For example when I generate eBooks, or want to use XML based processing tools.<p>Is there any tool that automates this translation? I have looked around but couldn’t find anything yet, even if BeautifulSoup seems to be able to do a part of it.<p>The ideal tool needs to re-serialise the document with all the xml rules (lowercase tags, properly cased etc.). It should also wrap inline scripts and styles in CDATA tags… And some other requirements of the spec…<p>Bonus points if it can convert to polyglot XHTML ( http:&#x2F;&#x2F;dev.w3.org&#x2F;html5&#x2F;html-polyglot&#x2F;html-polyglot.html ), which requires also accommodating the oddities of HTML parsing (commenting out CDATA sections, make script tags not self-closing, etc.).<p>And finally I’d like it to be able to normalise whitespace.<p>I’d love for it to be in JS, but Python or Java would work for me as well.<p>Thanks for your suggestions!
======
schrijver
I found this package,
[https://github.com/aleray/html5tidy](https://github.com/aleray/html5tidy) but
that only does the serialising part.

