Fixes how empty XHTML and SVG elements are serialized
The DOM Parsing and Serialization spec defines that only some empty elements should be autoclosed when serializing XHTML: https://w3c.github.io/DOM-Parsing/#ref-for-dfn-html-namespace-3 . This PR aligns with this spec.
It also tells that among empty elements, only those ones get a space before the slash (<link /> instead of <link/>). As such, SVG elements should not have a space for example (<rect/> instead of <rect />). This implements such change. Ideally it should also be applied on other XML documents, but i wanted to keep things simple and not too invasive for the codebase.
What issue is this trying to solve?
Issues happen if you feed the HTML parser (of a browser) with XHTML content generated by LinkeDOM, resulting in the wrong DOM, because the HTML parser treats self-closing tags of non void elements as opening tags.
People should likely not do that, but realistically that can happen if, for example:
- you send XHTML with the wrong MIME type (
text/htmlinstead ofapplication/xhtml+xml) : Self-closing iframe VS Not self-closing iframe - you embed an SVG document (such as an icon) containing XHTML in a HTML document : Self-closing div VS Not self-closing div (minimal example inspired by a CSS Tricks article)
This PR prevents LinkedDOM to generate such not roundtripping code when serializing an XHTML document. I can add the examples above as testcases if you want.