Why are double hyphens invalid in HTML comments? [duplicate]

我与影子孤独终老i 提交于 2019-12-23 07:29:36

问题


Standards mode HTML forbids double hyphens in comments.

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

There are three additional restrictions, exemplified by these invalid examples:

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

Why bother specifying all these little edge cases? In particular, why forbid double hyphens?


回答1:


[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.

The grammar does not allow a comment ending in --->

It seems to be a feature of XML included solely to ensure that XML remains compatible with SGML http://www.w3.org/TR/REC-xml/#sec-comments



来源:https://stackoverflow.com/questions/26600092/why-are-double-hyphens-invalid-in-html-comments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!