首页 文章

Markdown中的评论

提问于
浏览
1045

将注释存储在markdown文件中的语法是什么,例如文件顶部的CVS $ Id $评论?我在markdown project什么都没发现 .

15 回答

  • 5

    我相信所有先前提出的解决方案(除了需要特定实现的解决方案之外)导致注释包含在输出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.)
    

    或者你可以走得更远:

    [//]: <> (This is also a comment.)
    

    为了提高平台兼容性(并保存一个击键),还可以使用 # (这是一个合法的超链接目标)而不是 <>

    [//]: # (This may be the most platform independent comment)
    

    为了获得最大的可移植性,在此类注释之前和之后插入一个空行很重要,因为当定义与常规文本相冲突时,某些Markdown解析器无法正常工作 . Babelmark最近的研究表明,前后的空白线都很重要 . 如果之前没有空行,一些解析器将输出注释,如果之后没有空行,则一些解析器将排除以下行 .

    通常,这种方法应该适用于大多数Markdown解析器,因为它是核心规范的一部分 . (即使定义了多个链接时的行为,或者定义了链接但从未使用过时,也没有严格指定) .

  • 5

    这适用于GitHub:

    [](Comment text goes here)
    

    生成的HTML看起来像:

    <a href="Comment%20text%20goes%20here"></a>
    

    这基本上是一个空链接 . 显然你可以在渲染文本的源代码中读到它,但无论如何你都可以在GitHub上做到这一点 .

  • 1084

    另请参阅批评标记,由越来越多的Markdown工具提供支持 .

    http://criticmarkup.com/

    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.
    
  • 10

    Vim Instant-Markdown用户需要使用

    <!---
    First comment line...
    //
    _NO_BLANK_LINES_ARE_ALLOWED_
    //
    _and_try_to_avoid_double_minuses_like_this_: --
    //
    last comment line.
    -->
    
  • 9

    对于pandoc,阻止注释的一种好方法是使用yaml metablock,as suggested by the pandoc author . 我注意到,与许多其他提议的解决方案相比,这给出了更恰当的语法突出显示,至少在我的环境中是这样的( vimvim-pandocvim-pandoc-syntax ) .

    html-comments cannot be nested以来,我将yaml块注释与html-inline注释结合使用 . 不幸的是,有no way of block commenting within the yaml metablock,所以每行必须单独评论 . 幸运的是,软包装段落中应该只有一行 .

    在我的 ~/.vimrc 中,我为块注释设置了自定义快捷方式:

    nmap <Leader>b }o<Esc>O...<Esc>{ji#<Esc>O---<Esc>2<down>
    nmap <Leader>v {jddx}kdd
    

    我使用 , 作为我的 <Leader> -key,所以 ,b,v 注释并分别取消注释一个段落 . 如果我需要评论多个段落,我将 j,b 映射到宏(通常是 Q )并运行 <number-of-paragraphs><name-of-macro> (例如( 3Q ) . 同样适用于取消注释 .

  • 10

    如果你正在使用Jekyll或octopress,也可以使用 .

    {% comment %} 
        These commments will not include inside the source.
    {% endcomment %}
    

    首先解析Liquid标签 {% comment %} ,然后在MarkDown处理器进入之前将其删除 . 访问者在尝试从浏览器中查看源时将看不到 .

  • 29

    披露:我写了插件 .

    由于这个问题并没有提及Comments Pluginpython-markdown,它实现了上面提到的相同的pandoc评论风格 .

  • 138
    <!--- ... -->
    

    在Pandoc Markdown(Pandoc 1.12.2.1)中不起作用 . 评论仍然出现在HTML中 . 以下工作:

    Blank line
    [^Comment]:  Text that will not appear in html source
    Blank line
    

    然后使用脚注扩展名 . 它本质上是一个永远不会被引用的脚注 .

  • 827

    kramdown - 基于Ruby的降价引擎,它是Jekyll的默认值,因此是GitHub Pages- has built-in comment support through its extension syntax

    {::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引擎的缺点 .

  • -1

    你可以试试

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

    你可以这样做(YAML块):

    ---
    # This is a
    # multiline
    # comment
    ...
    

    我只尝试使用乳胶输出,请确认其他人 .

  • 16

    这项小型研究证明并完善了the answer by Magnus

    与平台无关的语法最多

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

    这两个条件都很重要:

    • Using # (and not <>)

    • With an empty line before the comment . 注释后的空行对结果没有影响 .

    严格的Markdown规范CommonMark只能按此语法使用(而不是使用 <> 和/或空行)

    为了证明这一点,我们将使用由John MacFarlane编写的Babelmark2 . 此工具检查28 Markdown实现中特定源代码的呈现 .

    + - 通过了测试, - - 没有通过, ? - 留下了一些未呈现的HTML垃圾) .

    这证明了上述陈述 .

    这些实现失败了所有7个测试 . 没有机会使用带有排除渲染的注释他们 .

    • cebe / markdown 1.1.0

    • cebe / markdown MarkdownExtra 1.1.0

    • cebe / markdown GFM 1.1.0

    • s9e \ TextFormatter(Fatdown / PHP)

  • 12

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

    .comment { display: none; }

    然后,增强MARKDOWN以下

    We do <span class="comment">NOT</span> support comments

    在BROWSER中显示如下

    We do support comments

  • 33

    如何将注释放在非eval,非echo R块中?即,

    ```{r echo=FALSE, eval=FALSE}
    All the comments!
    
    
    似乎对我有用 .
  • 4

    我使用标准的HTML标签,比如

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

    请注意三重破折号 . 优点是它在生成TeX或HTML输出时与pandoc一起使用 . 有关pandoc-discuss组的更多信息 .

相关问题