How shall I properly write --> or --> within a comment?
I am maintaining a large html-file with many tiny entries of program code. Say:
a --> b.
which I encode in HTML as -->:
a --> b.
However, from time to time, I change an entry and want to comment out the old entry. (Yes, I do have version control in addition to that.) But when I then write
<!-- a --> b -->
the validator barfs. Indicating that I "forgot" a closing >.
Is this actually an error or just some overcautious warning?
Are there established ways how to "escape" within comments?
You could use a CDATA block to tell the parser to ignore the comment.
<![CDATA[ a --> b ]]>
It's not quite as nice looking as a comment, but it should pass a validator.
Related
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
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.
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 />)
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.
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)"
Line 10, Column 43: Bad value FRSH Studio for attribute href on element link: Whitespace in path component. Use %20 in place of spaces. <link rel="pingback" href="FRSH Studio" />
--- It is my understanding that this is pulled from my settings in Wordpress. When I change the setting to include the %, I'm given an error stating that "Path component contains a percent sign that is not followed by two hexadecimal digits." How do I fix this?
Line 146, Column 7: End tag for body seen, but there were unclosed elements. </body>
--- I believe this is referring to <div id="container">...
Line 54, Column 20: Unclosed element div. <div id="container">
--- When I close the container using </div><!-- end container --> in the footer, I'm told that it is a stray tag. Where should </div><!-- end container --> be?
Not sure why this was sent away from Wordpress Stackexchange. The site validates as HTML. It is only when validating the site, which is Wordpress, using the URI via w3c's validator that these errors arise.
Put the full code inside the HTML Tidy and make it valid. Use this: http://infohound.net/tidy/
HTML Tidy is a tool for checking and cleaning up HTML source files. It is especially useful for finding and correcting errors in deeply nested HTML, or for making grotesque code legible once more.
This online version enables you use it without installing the client tool on your PC.
The "stray tag" error may be due to the fact that the page is being parsed as XHTML, where every opening tag (e.g. <!-- end container -->) requires a closing tag.
The best HTML validator is here:
http://validator.w3.org/
That will offer an option to clean up with HTML Tidy as others have mentioned.
1) The href has to be a valid link.
<link rel="pingback" href="http://frshstudio.com" />
2/3) Perhaps you have closed it in the wrong place?
Can you please post code?
Your site appears to be generating bad HTML pages.
1) The value for "href" should be a URL.
2) If you have a "div" start tag, then there needs to be a "div" end tag as well. This may be missing.
3) Would need to see the entire source to be helpful.
As someone suggested, you can use http://validator.w3.org/. Another validator (for Windows so it's offline and it does a lot more) is CSE HTML Validator at http://www.htmlvalidator.com/
How to write comments in an (x)HTML file? just using <!-- comment -->?
Is it correct also?: <!-"-" comment "-"->?
Any other methods to put a comment in code? (because some editors filter <!-- --> comments).
This is the correct and only way for HTML and XML:
<!-- comment -->
Your other example is not valid.
The only valid type of (x)HTML comment is <!-- -->.
Can I use /* */ comment tags in html .
If not why because they are common for comments ?
No you cannot. You can use <!-- -->
As to the second part of the question, I can't really help you there :)
EDIT - Just realized that /* */ wouldn't be tags at all, which would make sense as to why you can't use them,
No, you can't, because the specification says so:
HTML comments have the following syntax:
<!-- this is a comment --> <!-- and so is this one,
which occupies more than one line -->
White space is not permitted between the markup declaration open
delimiter(""). A common error is to include a
string of hyphens ("---") within a comment. Authors should avoid
putting two or more adjacent hyphens inside comments.
Information that appears between comments has no special meaning
(e.g., character references are not interpreted as such).
Note that comments are markup.
That last line tells you why you can't use /* */ - because HTML comments are markup too, just like any other tag, and those "universal comments" would not be tags.
You need to use:
<!-- A Comment -->
in HTMl as far as I'm aware.
/*
*/
is not universal, although it is common for block comments
<!-- <script type="text/javascript">/*<![CDATA[*/ c-- ;//]]></script> -->
When I have the above line in the <head> section of a plain html page, Firefox 3.5.5 renders the trailing --> as text. If I change c-- to c- it doesn't. Any ideas what's going on here? I getting an artifact on my pages with this due to a very large script that's been crunched. I can change the statement to c-=1 and avoid the problem for now but.... I'd like to know what bit/byte is biting my a$$.
This is due to Firefox implementing SGML (on which HTML was based) comments strictly. This will only occur when the document is loaded in standards mode (i.e. there is a DOCTYPE).
The first <! starts a comment. The first -- enters a section in which > characters are allowed. The second -- (in your script) leaves the section in which > characters are allowed. The > at the end of </script> then ends the comment. The following --> is therefore no longer part of the the comment and gets rendered as text.
See http://www.howtocreate.co.uk/SGMLComments.html for a comprehensive guide to the issue.
Its also worth noting that the HTML 4 Specification says that 'authors should avoid putting two or more adjacent hyphens inside comments' and the HTML 5 Specification says comments must not 'contain two consecutive U+002D HYPHEN-MINUS characters (--)'.
The solution, as you've found, is to not include -- in the middle of a comment.
Technically you are not allowed to have double hyphen in a comment in HTML (or XML). So even if browsers "allow" if it is not valid and should fail an HTML validator.
See Comment section of HTML 4 Specification
I can't replicate this. Doesn't show up on 3.0.1.