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


当前回答

使用mkdocs时,添加mkdocs.yml:

  - pymdownx.striphtml:
      strip_comments: true
      strip_js_on_attributes: false

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

<!-- this is a comment -->

将从html输出中删除。

其他回答

披露:我写了这个插件。

由于问题没有指定特定的markdown实现,我想提到python markdown的Comments插件,它实现了上述相同的pandoc注释样式。

kramdown基于Ruby的markdown引擎,这是Jekyll的默认引擎,因此GitHubPages通过其扩展语法内置了注释支持:

{::comment}
This text is completely ignored by kramdown - a comment in the text.
{:/comment}

Do you see {::comment}this text{:/comment}?
{::comment}some other comment{:/}

这样做的好处是允许在线评论,但缺点是不能移植到其他Markdown引擎。

使用mkdocs时,添加mkdocs.yml:

  - pymdownx.striphtml:
      strip_comments: true
      strip_js_on_attributes: false

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

<!-- this is a comment -->

将从html输出中删除。

另一种方法是将注释放在样式化的HTML标记中。这样,您可以根据需要切换它们的可见性。例如,在CSS样式表中定义注释类。

.注释{display:none;}

然后,以下增强的MARKDOWN

我们不支持评论

在浏览器中显示如下

我们支持评论

你可以试试

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