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.

有帮助吗?

解决方案

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).

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top