Mag*_*nus 1322
我相信所有先前提出的解决方案(除了需要特定实现的解决方案之外)导致注释包含在输出HTML中,即使它们未被显示.
如果你想要一个严格意义上的评论(转换文档的读者不应该看到它,即使使用"查看源")你可以(ab)使用链接标签(用于参考样式链接)可用于Markdown核心规范:
http://daringfireball.net/projects/markdown/syntax#link
那是:
[comment]: <> (This is a comment, it will not be included)
[comment]: <> (in the output file unless you use it in)
[comment]: <> (a reference style link.)
Run Code Online (Sandbox Code Playgroud)
或者你可以走得更远:
[//]: <> (This is also a comment.)
Run Code Online (Sandbox Code Playgroud)
为了提高平台兼容性(并保存一个击键),还可以使用#(这是一个合法的超链接目标)而不是<>:
[//]: # (This may be the most platform independent comment)
Run Code Online (Sandbox Code Playgroud)
为了获得最大的可移植性,在此类注释之前和之后插入一个空行很重要,因为当定义与常规文本相比时,某些Markdown解析器无法正常工作.Babelmark最近的研究表明,前后的空白线都很重要.如果之前没有空行,一些解析器将输出注释,并且如果之后没有空行,则一些解析器将排除以下行.
通常,这种方法应该适用于大多数Markdown解析器,因为它是核心规范的一部分.(即使定义了多个链接时的行为,或者定义了链接但从未使用过时,也未严格指定).
chl*_*chl 925
我使用标准的HTML标签
<!---
your comment goes here
and here
-->
Run Code Online (Sandbox Code Playgroud)
请注意三重破折号.优点是它在生成TeX或HTML输出时与pandoc一起使用.有关pandoc-discuss组的更多信息,请参阅.
Nic*_*kin 181
这项小型研究证明并改进 了马格努斯的答案
与平台无关的语法最多
(empty line)
[comment]: # (This actually is the most platform independent comment)
Run Code Online (Sandbox Code Playgroud)
这两个条件都很重要:
#(而不是<>)严格的Markdown规范CommonMark只能按照这种语法工作(而不是<>和/或空行)
为了证明这一点,我们将使用由John MacFarlane编写的Babelmark2.此工具检查28 Markdown实现中特定源代码的呈现.
(+- 通过测试,-- 没有通过,?- 留下一些未呈现的HTML垃圾).
<> 13 +,15-<> 20 +,8-<> 20 +,8-# 13+ 1?14-# 23+ 1?4-# 23 + 1?4-这证明了上述陈述.
这些实现失败了所有7个测试.没有机会对它们使用带有渲染的排除注释.
uir*_*han 51
如果您正在使用Jekyll或octopress,也可以使用.
{% comment %}
These commments will not include inside the source.
{% endcomment %}
Run Code Online (Sandbox Code Playgroud)
{% comment %}在MarkDown处理器进入之前,首先解析Liquid标签并将其删除.访问者在尝试从浏览器中查看源时将看不到.
小智 31
另一种方法是将注释放在程式化的HTML标记中.这样,您可以根据需要切换其可见性.例如,在CSS样式表中定义注释类.
.comment { display: none; }
然后,增强MARKDOWN以下
We do <span class="comment">NOT</span> support comments
在浏览器中显示如下
We do support comments
jom*_*omo 29
这适用于GitHub:
[](Comment text goes here)
Run Code Online (Sandbox Code Playgroud)
生成的HTML看起来像:
<a href="Comment%20text%20goes%20here"></a>
Run Code Online (Sandbox Code Playgroud)
这基本上是一个空链接.显然你可以在渲染文本的源代码中读到它,但无论如何你都可以在GitHub上做到这一点.
Ker*_*rim 18
另请参阅Critic Markup,由越来越多的Markdown工具提供支持.
Comment {>> <<}
Lorem ipsum dolor sit amet.{>>This is a comment<<}
Highlight+Comment {== ==}{>> <<}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. {==Vestibulum at orci magna. Phasellus augue justo, sodales eu pulvinar ac, vulputate eget nulla.==}{>>confusing<<} Mauris massa sem, tempor sed cursus et, semper tincidunt lacus.
Run Code Online (Sandbox Code Playgroud)
ale*_*lex 18
Vim Instant-Markdown用户需要使用
<!---
First comment line...
//
_NO_BLANK_LINES_ARE_ALLOWED_
//
_and_try_to_avoid_double_minuses_like_this_: --
//
last comment line.
-->
Run Code Online (Sandbox Code Playgroud)
Edo*_*iel 13
使用mkdocs时,请添加mkdocs.yml:
- pymdownx.striphtml:
strip_comments: true
strip_js_on_attributes: false
Run Code Online (Sandbox Code Playgroud)
然后在任何 Markdown 文件中添加普通的 html 注释,如下所示
<!-- this is a comment -->
Run Code Online (Sandbox Code Playgroud)
将从 html 输出中删除。
Dav*_*man 12
如何将注释放在非eval,非echo R块中?即
```{r echo=FALSE, eval=FALSE}
All the comments!
```
Run Code Online (Sandbox Code Playgroud)
似乎对我有用.
<!--- ... -->
Run Code Online (Sandbox Code Playgroud)
在Pandoc Markdown(Pandoc 1.12.2.1)中不起作用.评论仍然出现在HTML中.以下工作:
Blank line
[^Comment]: Text that will not appear in html source
Blank line
Run Code Online (Sandbox Code Playgroud)
然后使用+脚注扩展名.它本质上是一个永远不会被引用的脚注.
此 Markdown 评论不会在使用 Jekyll 的 GitHub Pages 网站上呈现
[whatever]: text
Run Code Online (Sandbox Code Playgroud)
由于 Jekyll 使用 Liquid 模板语言来处理模板,因此此 Liquid 注释也不会在使用 Jekyll 的 GitHub Pages 网站上呈现
{% comment %}
This is a long comment string
Newline
Stuff
{% endcomment %}
Run Code Online (Sandbox Code Playgroud)
小智 5
你可以试试
[](
Your comments go here however you cannot leave
// a blank line so fill blank lines with
//
Something
)
Run Code Online (Sandbox Code Playgroud)
对于pandoc,阻止评论的一种好方法是使用yaml metablock,如pandoc作者所建议的那样.我注意到,这使评论的更适当的语法高亮相对于很多其他提出的解决方案,至少在我的环境(vim,vim-pandoc,和vim-pandoc-syntax).
我将yaml块注释与html-inline注释结合使用,因为html-comments不能嵌套.不幸的是,没有办法在yaml metablock中进行块注释,因此每行必须单独进行注释.幸运的是,软包装段落中应该只有一行.
在我~/.vimrc,我已经设置了块注释的自定义快捷方式:
nmap <Leader>b }o<Esc>O...<Esc>{ji#<Esc>O---<Esc>2<down>
nmap <Leader>v {jddx}kdd
Run Code Online (Sandbox Code Playgroud)
我用,我的<Leader>-键,所以,b和,v评论,并取消段落,分别.如果我需要评论多个段落,我会映射j,b到一个宏(通常Q)并运行<number-of-paragraphs><name-of-macro>(例如(3Q).同样的工作用于取消注释.
kramdown - 基于Ruby的markdown引擎,它是Jekyll的默认设置,因此GitHub Pages- 通过其扩展语法提供了内置的注释支持:
{::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{:/}
Run Code Online (Sandbox Code Playgroud)
这有利于允许在线评论,但不能移植到其他Markdown引擎的缺点.
The following works very well
<empty line>
[whatever comment text]::
Run Code Online (Sandbox Code Playgroud)
that method takes advantage of syntax to create links via reference
since link reference created with [1]: http://example.org will not be rendered, likewise any of the following will not be rendered as well
<empty line>
[whatever]::
[whatever]:whatever
[whatever]: :
[whatever]: whatever
Run Code Online (Sandbox Code Playgroud)