views:

87

answers:

4

Is there a way to comment multiple lines... which already have some comments in them?

i.e.

<html>
<!-- Multi-line comment begin
  <head>
    <!-- This script does abcxyz -->
    <script>...</script>
  </head>
  <body>
    Hello world!
  </body>
Multi-line comment end -->
</html>

It seems that even SO's syntax hilighting won't accept this...

+1  A: 

No. Comments cannot be nested and HTML has only one style of comment.

David Dorward
A: 

Nope, unfortunately HTML comments don't nest.

Matti Virkkunen
+2  A: 

I think the key point is this:

Note that comments are markup.

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

This is not valid markup:

<div <span/> />

... so neither is the one you mention.


Since all my sites are written in PHP I normally comment out code with PHP comments:

<?/*?>
<div>...</div>
<p>...</p>
<?*/?>

Perhaps you can use a similar trick.

Álvaro G. Vicario
sheesh, really? Am I the only one aggravated by this? o.O Thanks for the php advice though...
Tony R
It's even worse in CSS :)
Álvaro G. Vicario
A: 

No. The closing comment tag --> will always end the comment section so if your comment includes a comment the closing tag of your included comment will end the comment section.

You can do a replace of --> in the section you are about to comment out to something unique so you can later just do another replace back to --> if you choose to undo your commenting.

Florian