HTML Nested Comments

Suppose some HTML is ...

<section> <h1>Some stuff</h1> <!-- That was some stuff... --> </section> 

I am adding comment tags around HTML that I want to comment on. I want to comment on everything, but the comment is closed by the existing comment.

 <!-- <section> <h1>Some stuff</h1> <!-- That was some stuff... --> </section> --> 

What is the best way to handle this scenario without losing all my inline comments.

+8
html comments
source share
5 answers

HTML comment begins with <!-- and ends on the first one --> encountered. There is no way to change this behavior. If you want to hide a large section with may contain comments during development , you can wrap it. But do not do it in production, it is bad.

+6
source share

To comment on a block with nested comments: sub-internal (block) comments from "-" to "~~"

 <!-- ********************************************************************* * IMPORTANT: to uncomment section * sub inner comments "~~" -> "--" & remove this comment ********************************************************************* <head> <title>my doc title</title> <~~! my doc title ~~> <link rel=stylesheet href="mydoc.css" type="text/css"> </head> <body> <~~! my doc important html stuff ~~> ... ... ... </body> ********************************************************************* * IMPORTANT: to uncomment section * sub inner comments "~~" -> "--" & remove this comment ********************************************************************* --> 

Thus, the external comment of the majority ignores all "invalid" internal (blocked) comments

+4
source share

As far as I know, there is no way to block this. You have to be careful what you comment on or not.

See: http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.4

What you can try is to use PHP to comment out the HTML ... I hope this helps!

+1
source share

You cannot comment on this without removing the internal comments, because HTML will treat the code as

 <!-- <section> ---- ---- //All this code comes under commented ---- some stuff... --> 

It will only consider the start comment tag before <section> and end the comment after the word "some stuff ...". This way, HTML will not process the single comment tag after <h1> , which is already under the comments.

0
source share

This works for me:

 <!--[if False]> Lots of html including <!-- comments --> <![endif]--> 
0
source share

All Articles