Domanda

I read that xmp tag is deprecated, but I need to output code as plain text. So is there some way how to simulate xmp tag behavior? Thanks for help.

È stato utile?

Soluzione

You cannot simulate the special parsing mode of xmp elements in HTML, except in genuine XHTML (i.e., XHTML served with an XML media type), where you can use CDATA sections. The reason is that this is about low-level parsing of HTML, hard-wired into browsers.

So if you don’t want to use xmp, the only way is to “escape” the characters “&” and “<” in the content. Note that HTML5 drafts require browsers to keep supporting xmp (while declaring it as obsolete and forbidden).

Altri suggerimenti

Use <pre> or <code>. From MDN:

Use the <pre> element or, if semantically adequate, the <code> element instead. Note that you will need to escape the '<' character as '<' to make sure it is not interpreted as markup.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top