3 ms·
Very nice use of media types and data URIs! Indeed, the root of your document is <script>, which is rather funny. Of course HTML and XML syntaxes are incompatib
by nayuki 5y ago
Very nice use of media types and data URIs! Indeed, the root of your document is <script>, which is rather funny. Of course HTML and XML syntaxes are incompatible, but there is a reasonable polyglot subset that is compatible with both.
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 https://www.nayuki.io/page/practical-guide-to-xhtml
- chrismorgan 5y agohttps://www.w3.org/TR/html-polyglot/ https://www.w3.org/TR/html-polyglot/ is good reading on this topic too. 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.
- TacticalCoder 5y ago> tbody is genuinely optional in the spec IIRC optional in the HTML spec only. Not in the XHMTL one and not in the polyglot syntax.
- chrismorgan 5y agoThe XHTML spec is obsolete and irrelevant. It’s replaced by the HTML spec using XML syntax. (W3C classes it as a Superseded Recommendation.) But tbody was optional even in XHTML 1.0 Strict; quoting https://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd https://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd, <!ELEMENT table (caption?, (col*|colgroup*), thead?, tfoot?, (tbody+|tr+))> I’m pretty sure that this will be the reason it’s optional in the HTML spec, since there’d be no point in it being optional otherwise, since it’s not attainable in the HTML syntax.
- aidos 5y agoBack in the days when we used to nest tables 70 deep for layouts I don’t recall anyone using tbody - was it added later?
- merb 5y agotbody is old, but was not widely used before html5 or modern spa's that required them.
- chrismorgan 5y agothead/tfoot/tbody were introduced in HTML 4, with tbody mandatory (that is, `table > tr` was now invalid), but implied (that is, its start and end tags were both optional, so that <table><tr>…</tr></table> would be parsed the same as <table><tbody><tr>…</tr></tbody></table>). Source: https://www.w3.org/TR/html4/struct/tables.html#h-11.2 https://www.w3.org/TR/html4/struct/tables.html#h-11.2: <!ELEMENT TABLE - - (CAPTION?, (COL*|COLGROUP*), THEAD?, TFOOT?, TBODY+)> <!ELEMENT TBODY O O (TR)+ -- table body -->
- Semaphor 5y agoAh, the times when I was always trying to serve my site in the strictest way possible. I religiously followed everything Anne van Kesteren [0] wrote, and used his code-snippet [1] to serve application/xhtml+xml to browsers that supported it. He was my same-aged teenage hero :) [0]: https://annevankesteren.nl/ https://annevankesteren.nl/ [1]: https://annevankesteren.nl/2003/09/send-applicationxhtmlxml https://annevankesteren.nl/2003/09/send-applicationxhtmlxml