V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Daring Fireball: Markdown
CommonMark
MacDown Open Source Markdown Editor
Marked
GitHub Flavored Markdown
zhidian
V2EX  ›  Markdown

Markdown 要注释还要萌

  •  2
     
  •   zhidian · 2016-12-21 17:24:16 +08:00 · 14255 次点击
    这是一个创建于 2674 天前的主题,其中的信息可能已经有所发展或是发生改变。

    代码可以注释,不要的代码可以先 comment out 。 写 Markdown 呢?一篇文章写出来,总是有点草稿的,每次都忍痛割爱删掉,可能下次还要再敲一遍。 所以我一般都写到某个特定的 class 的 div 里,再用 CSS 把它们隐藏。

    可惜这种方法既不优雅也不通用。

    刚搜了一下:syntax - Comments in Markdown - Stack Overflow

    你可以用下面这些:

    [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)
    

    我决定以后用:

    [^_^]:
        commentted-out contents
        should be shift to right by four spaces (vim :`>>`).
    

    亲测可用( Pandoc 、 GitHub 、简书、作业部落)。

    如果你想测试一下你的 Markdown 能不能这么用,这是一点测试的文字:

    a
    
    [^_^]:
        b
    
    c
    
    d
    

    显示的 a c d 应当间隔一样长。

    第 1 条附言  ·  2016-12-21 18:03:43 +08:00

    不是每种 Markdown 都能注释多行文字,测试代码:

    a
    
    [^_^]:
        b
        
        c
    
    d
    

    效果:

    a

    c
    

    d

    v2ex 似乎无力了……(在我自己用的 pandoc 下,只有 a 和 d 这两行。)

    我还试了 Pandoc、GitHub、简书和作业部落对此的支持,放在了这里 多行代码注释-简书 - 简书

    19 条回复    2016-12-22 22:00:05 +08:00
    zwh8800
        1
    zwh8800  
       2016-12-21 17:31:42 +08:00
    厉害了,这个评论怎么算结束?空行吗?
    zhidian
        2
    zhidian  
    OP
       2016-12-21 17:37:17 +08:00
    @zwh8800 前后都要一个空行。

    其实 Comment 里面也可以空行,只要空行之后的内容也缩进过(不过这个不通用,刚试了一下 pandoc 可以,简书的不可以。)
    yoke123
        3
    yoke123  
       2016-12-21 17:44:28 +08:00
    好像不能多行注释 必须另起一行
    zhidian
        4
    zhidian  
    OP
       2016-12-21 17:54:57 +08:00
    Pandoc 可以( O ), GitHub 不可以( X ),简书不可以( X ),作业部落可以( O )。其他的,大家自己试吧 ==。不能注释多行确实很麻烦。
    zhidian
        5
    zhidian  
    OP
       2016-12-21 17:56:02 +08:00
    测试:[多行代码注释-简书 /作业部落, etc]( http://www.jianshu.com/p/f46bd33aafa4 )
    yzhen123
        6
    yzhen123  
       2016-12-21 18:17:47 +08:00
    直接使用 html 注释兼容大部分 markdown 解析器 <!-- 注释 -->
    zhujinliang
        7
    zhujinliang  
       2016-12-21 18:50:34 +08:00 via iPhone
    以后要用注释开车么?
    zhidian
        8
    zhidian  
    OP
       2016-12-21 18:59:40 +08:00
    @yzhen123 有道理。除了生成的 html 这个注释还在之外。
    sox
        9
    sox  
       2016-12-21 19:47:07 +08:00
    @zhidian 可是不会显示啊。。
    zhidian
        10
    zhidian  
    OP
       2016-12-21 20:18:46 +08:00
    @sox 我不知道为什么我忘了可以用 html 的注释……现在在忏悔。

    或许是最近都是 markdown 转到 docx (用 pandoc ),直觉上 html 那种注释没用。不过刚才发现……也可以用。

    所以我也不知道为啥自己饶了这么一个圈子。
    Mutoo
        11
    Mutoo  
       2016-12-21 21:08:48 +08:00
    @zhidian comment 的特点是 compile 完不会生成到最终产品里去,<!--会生成,只是不显示而已-->
    gaocegege
        12
    gaocegege  
       2016-12-21 22:22:35 +08:00
    =.= 萌
    xpol
        13
    xpol  
       2016-12-21 22:26:28 +08:00
    <!-- This is the right way to write markdown comment -->
    ioiioi
        14
    ioiioi  
       2016-12-21 22:33:13 +08:00
    看到这里我又忍不住推荐 asciidoc ,这货的功能比 markdown 强大多了。注释、表格、图像、 callout 、复杂列表等等都是原生支持的。而且很容易扩展。
    zhidian
        15
    zhidian  
    OP
       2016-12-21 22:59:49 +08:00
    @ioiioi 看到了“ include::chapter1.txt[]”,似乎不错。现在我 Markdown 引入别的文件都是先用脚本过一遍拼起来……正纠结自己应该用 org-mode 还是 asciidoc 。
    zhidian
        16
    zhidian  
    OP
       2016-12-21 23:16:31 +08:00
    看了下 [7. 附录:轻量级标记语言 — GotGitHub]( http://www.worldhello.net/gotgithub/appendix/markups.html ) 决定上 org-mode 了。
    SilentDepth
        17
    SilentDepth  
       2016-12-22 10:14:08 +08:00
    这个好,还可以根据写注释时的心情决定标记以微笑脸还是严肃脸还是纠结脸,「颜文」并茂
    delogn
        18
    delogn  
       2016-12-22 16:17:59 +08:00   ❤️ 1
    [^_^]:
    1

    [>_<]:
    2

    [>_>]:
    3

    都可以用啊,不错不错!以后吐槽和心情都可以写在注释里了!
    justyy
        19
    justyy  
       2016-12-22 22:00:05 +08:00
    自己弄了一个在线 format Markdown 的工具,
    亲测了上面的 comment 有效
    https://helloacm.com/markdown/
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5901 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 02:39 · PVG 10:39 · LAX 19:39 · JFK 22:39
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.