by nayuki · 4y ago · 0 comments
<script>
alert("Hello <!-- Comment 0 -->world");
<!-- Comment 1
alert("Bonjour le monde");
</script>
Comment 0 gets removed by the XML parser so it doesn't go into the alert string. Comment 1 is seen by the JavaScript parser and gets removed at that stage. data:application/xhtml+xml,<script xmlns="http://www.w3.org/1999/xhtml">%0Aalert("Hello <!-- Comment 0 -->world");%0A<!-- Comment 1%0Aalert("Bonjour le monde");%0A</script>
(Observe also how what I’ve written here nets you a document that lacks html, head and body tags—HTML syntax fills those in through the magic of optional start and end tags, but XML syntax takes what it’s given and can be used to do things like nesting hyperlinks or putting a heading inside a paragraph. The HTML and XML syntaxes for HTML are actually mutually incompatible.)Other common things that HTML syntax won't let you do: <p><p></p></p>, <table><tr><td> without an implicit <tbody>.
Why I know this obscure corner of the HTML standard is because I've been running my website on XHTML mode for more than a decade continuously. https://www.nayuki.io/page/practical-guide-to-xhtml
A fun thing that I learned recently is that `table > tr` is actually valid, the tbody is genuinely optional in the spec, even though the HTML syntax injects it.
IIRC optional in the HTML spec only. Not in the XHMTL one and not in the polyglot syntax.
[0]: https://annevankesteren.nl/
[1]: https://annevankesteren.nl/2003/09/send-applicationxhtmlxml