问题
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