【问题标题】:How to comment out a line in HAMLC comment如何注释掉 HAMLC 注释中的一行
【发布时间】:2015-12-23 03:17:18
【问题描述】:

想知道如何在 HAMLC 中注释掉一行。 我试过了

# this is commented out

但它不起作用。它创建一个<div> this is commented out </div> 在 HALMC 上找不到很多资源。

知道如何注释掉多行也将不胜感激。

【问题讨论】:

  • @antonie 你试过了吗:%p code-line-1 -# 这是一条评论 %p code-line-2

标签: ruby-on-rails coffeescript comments haml hamlc


【解决方案1】:

这是来自Haml documentation for comments

评论

Haml 支持两种类型的 cmets:在 HTML 输出中显示的和不显示的。

HTML 注释:/

正斜杠字符,当放置在行首时,会将其后的所有文本换行在 HTML 注释中。例如:

%peanutbutterjelly
  / This is the peanutbutterjelly element
  I like sandwiches!

编译为:

<peanutbutterjelly>
  <!-- This is the peanutbutterjelly element -->
  I like sandwiches!
</peanutbutterjelly>

正斜杠还可以包裹缩进的代码段。例如:

/
  %p This doesn't render...
  %div
    %h1 Because it's commented out!

编译为:

<!--
  <p>This doesn't render...</p>
  <div>
    <h1>Because it's commented out!</h1>
  </div>
-->

条件注释:/[]

您还可以使用 Internet Explorer 条件 cmets,方法是将条件括在 / 之后的方括号中。例如:

/[if IE]
  %a{ :href => 'http://www.mozilla.com/en-US/firefox/' }
    %h1 Get Firefox

编译为:

<!--[if IE]>
  <a href='http://www.mozilla.com/en-US/firefox/'>
    <h1>Get Firefox</h1>
  </a>
<![endif]-->

Haml 评论:-#

紧跟在井号后面的连字符表示无声的注释。其后的任何文本根本不会呈现在结果文档中。

例如:

%p foo
-# This is a comment
%p bar

编译为:

<p>foo</p>
<p>bar</p>

您还可以在无声评论下嵌套文本。不会呈现此文本。例如:

%p foo
-#
  This won't be displayed
    Nor will this
                   Nor will this.
%p bar

编译为:

<p>foo</p>
<p>bar</p>

这些是其他参考资料:

【讨论】:

  • 清楚地注明内容来源非常重要。我强烈建议明确说明这是从哪里来的,最好是在答案的顶部。
  • 很抱歉。我将添加答案来自。谢谢@theTinMan。
【解决方案2】:

您可以像这样评论该行

对于haml标签

//%div

and for rails 标签

=# link_to "", ""

这是comment code of haml

【讨论】:

    猜你喜欢
    • 2023-03-12
    • 2011-02-04
    • 2014-12-11
    • 2015-11-18
    • 1970-01-01
    • 2012-01-24
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多