简体   繁体   English

评论中的 HTML 评论?

[英]HTML comments within comments?

Is there a way to comment multiple lines... which already have some comments in them?有没有办法评论多行......其中已经有一些评论?

ie

<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...似乎即使是 SO 的语法高亮显示也不会接受这个......

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 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:因为我所有的网站都是用 PHP 编写的,所以我通常用 PHP 注释来注释代码:

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

Perhaps you can use a similar trick.也许您可以使用类似的技巧。

不可以。注释不能嵌套,HTML 只有一种注释样式。

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.您可以在将要注释掉某些独特内容的部分中替换 -->,以便稍后再替换回 --> 如果您选择撤消注释。

If you're really stuck with some piece of HTML – pre-rendered at some uncontrollable source – which contains comments, and you need to make sure none of it is rendered on your page, you can always wrap it with a script tag like below, only thing is, you can't comment out script tags this way.如果您真的坚持使用某些 HTML 片段(在某些无法控制的源中预先呈现),其中包含注释,并且您需要确保没有任何内容呈现在您的页面上,您始终可以使用如下所示的script标记将其包装起来,唯一的问题是,您不能以这种方式注释掉script标签。

 <html> <head> </head> <body> <!-- multiline "comment" below using script type="text/html" --> <script type="text/html"> Hello world! <!-- Look at me, I'm a comment :) --> <div>Yeah, whatever, I'm an element..</div> </script> <span>Who cares, span is the man, the only visible one anyway!</span> </body> </html>

If you need to comment out script tags, you could use a textarea as wrapper instead, off course doing it this way, you can't comment out textarea tags.如果你需要注释掉script标签,你可以使用textarea作为包装器,当然这样做,你不能注释掉textarea标签。

 <html> <head> </head> <body> <!-- multiline "comment" below using textarea style="display:none;" --> <textarea style="display:none;"> <script> alert("which won't show up.."); </script> Hello world! <!-- Look at me, I'm a comment :) --> <div>Yeah, whatever, I'm an element..</div> </textarea> <span>Who cares, span is the man, the only visible one anyway!</span> </body> </html>

不,不幸的是 HTML 注释不嵌套。

One can embed it in single or double quotes as a tag attribute.可以将其作为标签属性嵌入单引号或双引号中。 This requires then of course that the corresponding quotes are not occurring in between.这当然要求相应的引号不会出现在两者之间。

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

http://jsfiddle.net/cehfumb2/2/ http://jsfiddle.net/cehfumb2/2/

it may still be useful for some developers, if use use vsCode as your IDE you can use an extension named Nest Comments in visual studio code market which work like a charm.它可能对某些开发人员仍然有用,如果使用 vsCode 作为您的 IDE,您可以在 Visual Studio 代码市场中使用名为 Nest Comments 的扩展,它就像一个魅力。

this is the link Nest Comments这是链接巢评论

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM