unbl0ck3r
unbl0ck3r

Reputation: 379

How to fix consecutive hyphens did not terminate a comment error?

with the w3 validator (https://validator.w3.org) scan my project but that's found a error.

Error: Consecutive hyphens did not terminate a comment. -- is not permitted inside a comment, but e.g. - - is. At line 135, column 8 ↩

all of the that line :

</ul></div></div><!-- end #main-nav -->

Why I get this error? How can fix that?

Thank you

Upvotes: 2

Views: 4688

Answers (5)

Ian Atkinson
Ian Atkinson

Reputation: 21

I accidentally introduced this error by having 3 dashes on a normal comment i.e.

<!--- Google Fonts --->

Upvotes: 0

Renee Wendy
Renee Wendy

Reputation: 1

Sadly the first comment is irrelevant as the example offered does not have two consecutive hyphens embedded in a comment.

My website is replete with consecutive dashes inside comments, as I have long been in the habit of using <!-- ---------- --> as a separator. Fortunately the validator is only warning not declaring an error. Do I care if my document is not mappable to XML 1.0? I do not. Recommendation to self and others: Ignore this warning and carry on.

https://validator.w3.org/ warns me  
"The document is not mappable to XML 1.0 due to two 
consecutive hyphens in a comment. (6)"

Upvotes: 0

mihaidp
mihaidp

Reputation: 310

It is an old post but I've stumbled upon a similar problem.

The validation error states that -- are not permitted INSIDE a comment so the following code will throw an error:

<!-- Commented resource

Some HTML here

<!-- /comment stops here -->

This code will not return a validation error:

<!-- Commented resource

Some HTML here

/comments stop here -->

This usually happens when you have somenthing with comments and then decide to comment everything and you leave the closing comment intact.

Upvotes: 5

Reggie Pinkham
Reggie Pinkham

Reputation: 12718

I can't see the validator having any problem with such code.

Are you sure it's not spitting-the-dummy over a BEM-esque class name using double hyphens? For example, using class="MyComponent--modifier" will generate your error, even though it is perfectly valid1.

1 According to the spec a class name cannot begin with two consecutive hyphens.

Upvotes: 0

user3589620
user3589620

Reputation:

If your doctype is correct, there should be no problem. I've tested

<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>

<body>
<div><ul><li>li</li></ul></div><!-- end #main-nav -->
</body>

</html>

with no warnings and errors. There is something wrong somewhere else. (Maybe <<, >> or missing closing tag />)

Upvotes: 0

Related Questions