Html <XMP> 标签是干什么用的?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4545/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 22:06:52  来源:igfitidea点击:

What was the <XMP> tag used for?

htmltags

提问by GateKiller

Does anyone remember the XMPtag?

有谁记得这个XMP标签吗?

What was it used for and why was it deprecated?

它有什么用途,为什么被弃用?

采纳答案by graham.reeds

A quick Google search on W3C reveals that XMPwas introduced for displaying preformatted textin HTML 3.2 and earlier. When W3C deprecated the XMPtag, it suggested using the PREtag as a preferred alternative.

在 W3C 上的快速谷歌搜索显示,它XMP是为了在 HTML 3.2 及更早版本中显示预格式化文本而引入的。当 W3C 弃用该XMP标签时,它建议使用该PRE标签作为首选替代方案。

Update: http://www.w3.org/TR/REC-html32#xmp, http://www.w3.org/MarkUp/html-spec/html-spec_5.html#SEC5.5.2.1

更新:http: //www.w3.org/TR/REC-html32#xmp,http: //www.w3.org/MarkUp/html-spec/html-spec_5.html#SEC5.5.2.1

回答by dadinck

XMPand PREdiffer. Content within PREtags is formatted as follows:

XMPPRE不同。PRE标签内的内容格式如下:

  • Content is shown with a fixed font,
  • All whitespace is preserved, and
  • Each line break begins a new line.
  • 内容以固定字体显示,
  • 保留所有空白,并且
  • 每个换行符开始一个新行。

If you want to include special characters such as <, >and &within PREtags, they must be escaped so that they are not subject to special interpretation by the browser.

如果要在标签中包含诸如<,>&之类的特殊字符PRE,则必须对它们进行转义,以免浏览器对其进行特殊解释。

In contrast, content within XMPtags does notneed to be escaped.

相比之下,中的内容XMP标签就不会需要进行转义。

The only character sequence that cannot be included within XMPtags is the XMPend tag (</XMP>).

唯一不能包含在XMP标签中的字符序列是XMP结束标签 ( </XMP>)。

XMPis still supported by the browsers I have tested. You can try it with xmp.html. View the source to see the tags.

XMP我测试过的浏览器仍然支持。你可以用xmp.html 试试。查看源代码以查看标签。

回答by Thomas

XMP does some things that PRE does not support. I still depend on XMP, there is nosubstitute.

XMP 做了一些 PRE 不支持的事情。我仍然依赖 XMP,没有替代品。

回答by noobninja

<xmp>is used with strapdown.jsin formatting markdown notation. The name strapdowncombining the terms bootstrapand markdown.

<xmp>在格式化 markdown 符号中与stripdown.js一起使用。名称捷联结合了术语bootstrapmarkdown

<!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>

回答by Phil Busby

I used <textarea>, which puts the html code into a neat box and clearly defines the code as different from the text before or after.

我使用了<textarea>,它将html代码放入一个整洁的框中,并清楚地将代码定义为与之前或之后的文本不同。

<textarea><b>boldtext</b><textarea>

<textarea><b>boldtext</b><textarea>

回答by mplungjan

Still works to show raw html - if you use it in script, break the start tag.

仍然可以显示原始 html - 如果您在脚本中使用它,请打破开始标记。

var stuff='<xmp'+'>this is shown as is<br/>hello</xmp>';
document.getElementById("x").innerHTML=stuff;
<div id="x"></div>

回答by Alohci

See http://www.w3.org/Bugs/Public/show_bug.cgi?id=12235

http://www.w3.org/Bugs/Public/show_bug.cgi?id=12235

For HTML5. it was, according to the HTML5 editor (comments 11 and 12), a very close call either way.

对于 HTML5。根据 HTML5 编辑器(评论 11 和 12)的说法,无论哪种方式都是非常接近的。

回答by Adam F

I still use the xmptag for debugging var_dump();in PHP. I just can't remember to use the pretag for some reason.

我仍然使用该xmp标签var_dump();在 PHP 中进行调试。我只是不记得pre出于某种原因使用了这个标签。

I think it doesn't really matter because if you really want to output text, you should use textareawith the readonlyattribute.

我认为这并不重要,因为如果你真的想输出文本,你应该使用textareareadonly属性。