有没有HTML / CSS方式来显示HTML标签而不解析? [英] Is there a HTML/CSS way to display HTML tags without parsing?

查看:237
本文介绍了有没有HTML / CSS方式来显示HTML标签而不解析?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法,我可以显示HTML标签而不解析?像 XMP 之前的标签完美工作,但现在它被替换为 PRE 这不是很酷。看看这个例子:

  //这用于NOT PARSE HTML,即使你使用标准<和> ;. 
< XMP>
< a hred =http://example.com>链接< / a>
< / XMP>

//新的PRE标签需要& lt;和&作为<和> ;.
< PRE>
&#60; a href =http://example.com&#62; Link&#60; / A&#62;
< / PRE>

我要找的是相当于旧的XMP标记。

您可以使用脚本元素,其类型设置为表示纯文本,并将其显示属性设置为 / code>。这只影响解析行为:除了元素本身的结束标记< / script> ,不识别标记(标记或实体或字符引用)。 (所以它不是与 xmp 相同,其中识别的标签是< / xmp> 。)你可以分别做出类似于 xmp pre 和/



示例:

 < style> 
script {
display:block;
}
< / style>
然后在文档主体内:
< script type =text / plain>
< i>& eacute;< / i>
< / script>

在最新版本的IE,Chrome,Firefox,Opera上测试。没有工作在IE 8和IE 7的模拟在IE 9,但这可能是一个错误的仿真。



然而,我不明白为什么你会使用这不是 xmp ,它没有停止工作。它不在规格,但如果你担心,你应该总是担心。在HTML 2.0(第一个HTML规范)中提到可以避免,它在HTML 3.2中已弃用,在HTML 4.0(很久以前:1997年)中完全删除。



xmp 正在回归而不是死亡。 W3C HTML5(由W3C工作人员以当前HTML规范为特征)将 xmp 声明为过时和不合格,但它还强制实施要求浏览器:用户代理必须处理 xmp 元素在语义方面等价于 pre 元素的方式。 (解析器对此元素有特殊的行为。)旧的解析行为因此没有明确的要求,但是明确暗示。


Is there any way that I could display HTML tags without parsing? Tags like XMP worked before perfectly but now it's replaced with PRE that isn't so cool. Take a look at this example:

//This used to NOT PARSE HTML even if you used standard < and >.
<XMP>
<a hred="http://example.com">Link</a>
</XMP>

//New PRE tag requires &lt; and &gt; as replacement for < and >.
<PRE>
&#60;a href="http://example.com"&#62;Link&#60;/A&#62;
</PRE>

What I'm looking for is equivalent of old XMP tag. New PRE tag will parse code.

解决方案

You can use a script element with its type set to denote plain text, and set its display property to block. This only affects the parsing behavior: no markup (tags or entity or character references) is recognized, except for the end tag of the element itself </script>. (So it is not quite the same as xmp, where the recognized tag is </xmp>.) You can separately make white space handling similar to that of xmp and pre and/or set the font the monospace as in those elements by default.

Example:

<style>
script {
  display: block;
}
</style>
Then within document body:
<script type="text/plain">
<i>&eacute;</i>
</script>

Tested on newest versions of IE, Chrome, Firefox, Opera. Didn’t work in IE 8 and IE 7 emulation on IE 9, but that’s probably a bug in the emulation.

However, I don’t see why you would use this instead of xmp, which hasn’t stopped working. It’s not in the specs, but if you are worried about that, you should have always been worried. Mentioned in HTML 2.0 (the first HTML spec ever) as avoidable, it was deprecated in HTML 3.2 and completely removed in HTML 4.0 (long ago: in 1997).

The xmp is making a comeback rather than dying. The W3C HTML5 (characterized as the current HTML specification by W3C staff) declares xmp as obsolete and non-conforming, but it also imposes a requirement on browsers: "User agents must treat xmp elements in a manner equivalent to pre elements in terms of semantics and for purposes of rendering. (The parser has special behavior for this element though.)" The old parsing behavior is thus not explicitly required, but clearly implied.

这篇关于有没有HTML / CSS方式来显示HTML标签而不解析?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆