8 回答
XMP
和PRE
不同。标签内的内容PRE
格式如下:
- 内容以固定字体显示,
- 保留所有空格,并且
- 每个换行符开始一个新行。
如果您想在标签中包含和等特殊字符<
,则必须对它们进行转义,以免浏览器对其进行特殊解释。>
&
PRE
相反,XMP
标签内的内容不需要转义。
唯一不能包含在XMP
标签中的字符序列是XMP
结束标签 ( </XMP>
)。
XMP
我测试过的浏览器仍然支持。你可以试试xmp.html。查看源代码以查看标签。
在 W3C 上的 Google 快速搜索显示,它是为在 HTML 3.2 及更早版本中XMP
显示预格式化文本而引入的。当 W3C 弃用该XMP
标签时,它建议使用该PRE
标签作为首选替代品。
更新:http ://www.w3.org/TR/REC-html32#xmp,http : //www.w3.org/MarkUp/html-spec/html-spec_5.html#SEC5.5.2.1
XMP does some things that PRE does not support. I still depend on XMP, there is no substitute.
<xmp>
与strapdown.js一起用于格式化markdown 表示法。结合术语bootstrap和markdown的名称捷联。
<!DOCTYPE html>
<html>
<title>Example</title>
<xmp theme="united">
## Example
- note one
- note two
- note three
</xmp>
<script src="http://strapdownjs.com/v/0.2/strapdown.js"></script>
</html>
I still use the xmp
tag for debugging var_dump();
in PHP. I just can't remember to use the pre
tag for some reason.
I think it doesn't really matter because if you really want to output text, you should use textarea
with the readonly
attribute.
见http://www.w3.org/Bugs/Public/show_bug.cgi?id=12235
对于 HTML5。根据 HTML5 编辑器(评论 11 和 12),无论哪种方式,它都是非常接近的。
我使用<textarea>
了 ,它将 html 代码放入一个整洁的框中,并将代码明确定义为与之前或之后的文本不同。
<textarea><b>boldtext</b><textarea>
仍然可以显示原始 html - 如果您在脚本中使用它,请打破开始标记。
var stuff='<xmp'+'>this is shown as is<br/>hello</xmp>';
document.getElementById("x").innerHTML=stuff;
<div id="x"></div>