4 ms·
My favorite (non-conforming, do-not-use) element is <xmp>. It switches the browser's parsing context to "generic raw text"; it emits any "child" markup as-is, w
by spdustin 4y ago
My favorite (non-conforming, do-not-use) element is <xmp>. It switches the browser's parsing context to "generic raw text"; it emits any "child" markup as-is, without parsing it.
[0] https://jsfiddle.net/spdustin/y4m3qd71/1/ https://jsfiddle.net/spdustin/y4m3qd71/1/
- derefr 4y agoI believe you can also just write <![CDATA[whatever]]>. (See https://stackoverflow.com/questions/3302648/should-i-use-cdata-in-html5 https://stackoverflow.com/questions/3302648/should-i-use-cda...). It's normally only used to wrap non-HTML content inside <style> and <script>; but you could put "HTML that should be rendered as text" in there as well!
- missblit 4y agoNote that CData can _only_ be used what HTML calls foreign content. So `<math><![CDATA[x<y]]></math>` will print x<7, but `<p><![CDATA[x<y]]></p>` will emit a `cdata-in-html-content` parse error (your compliant HTML parser is allowed to give up here if it's lazy) and is parsed as `<p><!--[CDATA[x<y]]--></p>` (your HTML parser will actually do this because giving up leads to poor user experience when no one else does)
- missblit 4y ago<plaintext> is also fun. Unlike <xmp> you can't get out of it with a closing tag. Aside: plaintext is one reason browser DOM is a superset of HTML. By which I mean you can add <plaintext> to the middle of your DOM through JavaScript and everything is hunky-dory, but it's impossible to serialize the DOM to HTML so it'll HTML-parse back to the same DOM (at least if the serializer doesn't produce any JavaScript).
- eurasiantiger 4y agoCertainly it is possible. Try document.documentElement.outerHTML. Why would it be impossible?