Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 521
aaaidan Avatar asked Oct 28 '14 02:10

aaaidan


1 Answers

[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

like image 177
Bobz Avatar answered Sep 18 '22 08:09

Bobz