问题
How do I show HTML markup including tags without using the XMP element on an HTML5 website?
The website is made with HTML5 and shows tutorials about HTML, C++ etc.
So I need to show the source code of many programming languages.
回答1:
The most often used alternative is to use the <pre>
or <code>
element and escape characters that have a special meaning in HTML. <
would become <
, >
is escaped to >
.
According to Can I escape html tags within a class (recreate the xmp tag)?, you can still use the XMP tag. Browsers should still support it, although according to What was the <XMP> tag used for?, <pre>
is the preferred element to use.
来源:https://stackoverflow.com/questions/15156549/show-source-code-without-xmp-tag