html - 为什么双连字符在 HTML 注释中无效?

标签 html web-standards

<分区>

标准模式 HTML forbids double hyphens在评论中。

<!-- This is a perfectly valid comment - I think. -->
<!-- Invalid comment -- definitely. -->

还有三个额外的限制,以这些无效示例为例:

<!--> invalid -->
<!---> invalid -->
<!-- invalid --->

为什么要费心指定所有这些小的边缘情况?特别是,为什么禁止使用双连字符?

最佳答案

[Definition: Comments may appear anywhere in a document outside other markup; in addition, they may appear within the document type declaration at places allowed by the grammar. They are not part of the document's character data; an XML processor may, but need not, make it possible for an application to retrieve the text of comments. For compatibility, the string " -- " (double-hyphen) must not occur within comments.] Parameter entity references must not be recognized within comments.

语法不允许以--->结尾的注释

它似乎是 XML 的一个特性,只是为了确保 XML 与 SGML 保持兼容 http://www.w3.org/TR/REC-xml/#sec-comments

关于html - 为什么双连字符在 HTML 注释中无效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26600092/

相关文章:

html - 具有负号位置的子 div 正在切割

google-chrome - Google Chrome 和 Chromium 是否等同于网页设计/开发?

html - 遵循网络标准有多重要?

html - 如何在网络标准中混合链接( <a> 标签)和标题( <h1> 标签)?

javascript - select2 选项空间不搜索

html - 将标题定位在中心

html - 带有图像的 anchor 标记在浏览器页面上移动调整大小

html - Electron 中的视频标签

css - `outline: inherit 0` 是如何解释的?

http - URI 不透明和缓存公理