如何在Markdown中编写注释,即HTML输出中未呈现的文本?我在Markdown项目中没有发现任何东西。


当前回答

此Markdown注释不会在带有Jekyll的GitHub Pages网站上呈现

[whatever]: text

因为Jekyll使用Liquid模板语言来处理模板,所以这个Liquid注释也不会在使用Jekyll的GitHubPages网站上呈现

{% comment %}
This is a long comment string 

Newline

Stuff
{% endcomment %}

其他回答

以下方法非常有效

<empty line>
[whatever comment text]::

该方法利用语法通过引用创建链接由于使用[1]创建了链接引用:http://example.org不会呈现,同样,以下任何内容也不会呈现

<empty line>
[whatever]::
[whatever]:whatever
[whatever]: :
[whatever]: whatever
[whatever]: # whatever with spaces

你可以试试

[](
Your comments go here however you cannot leave
// a blank line so fill blank lines with
//
Something
)

我使用标准的HTML标记,例如

<!---
your comment goes here
and here
-->

注意三点划线。其优点是,在生成TeX或HTML输出时,它可以与pandoc一起工作。有关更多信息,请访问pandoc讨论组。

这项小型研究证明并完善了马格努斯的答案

最独立于平台的语法是

(empty line)
[comment]: # (This actually is the most platform independent comment)

这两个条件都很重要:

使用#(而不是<>)注释前有空行。注释后的空行对结果没有影响。

严格的Markdown规范CommonMark仅适用于此语法(而不适用于<>和/或空行)

为了证明这一点,我们将使用Alexandre Mutel的Babelmark I。该工具检查大量Markdown实现上特定源代码的呈现。

(+-通过了测试,--没有通过,?-留下一些垃圾,这些垃圾在呈现的HTML中没有显示)。

无空行,使用<>13+15-注释前空行,使用<>20+,8-注释周围的空行,使用<>20+,8-没有空行,使用#13+1?14-注释前空行,使用#23+1?4-注释周围的空行,使用#23+1?4-带有3个连字符1+2的HTML注释?25-来自chl的答案(注意这是不同的语法)

这证明了上述陈述。

这些实现未通过所有7项测试。没有机会对它们使用excluded on render注释。

cebe/markdown 1.1.0cebe/markdown markdown额外1.1.0cebe/markdown GFM 1.1.0s9e\TextFormatter(Fatdown/PHP)

使用mkdocs时,添加mkdocs.yml:

  - pymdownx.striphtml:
      strip_comments: true
      strip_js_on_attributes: false

然后在任何markdown文件中使用普通的html注释,如

<!-- this is a comment -->

将从html输出中删除。