linkedom icon indicating copy to clipboard operation
linkedom copied to clipboard

Fixes how empty XHTML and SVG elements are serialized

Open PolariTOON opened this issue 8 months ago • 2 comments

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.

PolariTOON avatar May 29 '25 16:05 PolariTOON

What issue is this trying to solve?

WebReflection avatar May 29 '25 18:05 WebReflection

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:

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.

PolariTOON avatar May 30 '25 23:05 PolariTOON