Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML comments within comments?

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...

like image 950
Tony R Avatar asked Sep 22 '10 21:09

Tony R


People also ask

How do you put a comment in a comment in HTML?

How to Write Inline Comments in HTML. You can also add comments in the middle of a sentence or line of code. Only the text inside the <! -- --> will be commented out, and the rest of the text inside the tag won't be affected.

Can you have nested comments in HTML?

Look for shortcuts in your editor to do nested comments in html. This can with one keypress (un)comment a block of code and do a substitution of <! -- inner-comment --> to <!~~ inner-comment ~~> (just like guido's answer suggests), making commenting and uncommenting blocks just as easy as it is in other languages.

What is a multi line comment in HTML?

In HTML a comment is placed between <!-- and --> <!-- this is a (multi-line) HTML comment --> Note that most scripts ignore this comment style, as it used to help hide scripts from browsers that didn't support scripts. so in scripts you use other commenting markings.

What are the two types of comment tags?

Types of HTML Comments: There are three types of comments in HTML which are: Single-line comment. Multi-lines comment. Using <comment> tag.


1 Answers

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.

like image 87
Álvaro González Avatar answered Sep 29 '22 13:09

Álvaro González