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

为什么 markdown 都要设计成按 2 次回车,才能换 1 行?

  •  1
     
  •   lisisi · 2019-04-04 12:25:54 +08:00 · 16153 次点击
    这是一个创建于 1820 天前的主题,其中的信息可能已经有所发展或是发生改变。

    好多 markdown 都要按 2 次回车,才能换 1 行,为什么要这么设计呢? github 上的 markdown 只要按 1 次回车就能换 1 行,明显更方便呀

    23 条回复    2019-06-02 21:45:35 +08:00
    boris1993
        1
    boris1993  
       2019-04-04 12:32:08 +08:00 via Android
    我理解是方便源文件排版
    vansl
        2
    vansl  
       2019-04-04 12:32:37 +08:00
    猜测按一次是可视区域换行,并没有加\r\n
    yanring
        3
    yanring  
       2019-04-04 12:32:56 +08:00   ❤️ 4
    行末 2 个空格换行呀
    lisisi
        4
    lisisi  
    OP
       2019-04-04 12:40:08 +08:00
    @boris1993
    @vansl
    这个总容易出错的地方是:表单里 1 次回车换行了,保存的时候结果还是连在一起的。

    @yanring
    github 还是比较人性的,直接回车换行明显比按 2 次空格好
    azh7138m
        5
    azh7138m  
       2019-04-04 12:42:47 +08:00   ❤️ 2
    这个问题 10 年前大家讨论的比较多,本质是设计者设计成这个样子了

    > the single biggest source of inspiration for Markdown ’ s syntax is the format of plain text email.

    同时可以看到 "you need to demarcate paragraphs using something other than a single line-break"

    附链接
    What is the reason for the top secret two space newline markdown weirdness?
    https://meta.stackexchange.com/questions/40976/what-is-the-reason-for-the-top-secret-two-space-newline-markdown-weirdness
    Should the markdown renderer treat a single line break as <br>?
    https://meta.stackexchange.com/questions/26011/should-the-markdown-renderer-treat-a-single-line-break-as-br
    dangyuluo
        6
    dangyuluo  
       2019-04-04 12:43:08 +08:00   ❤️ 3
    因为有的人有强迫症,代码不能超过 80 个字符,所以要引入“代码换行”,但又不是新的段。
    你说的行尾加上两个空格是属于同段落内换行
    aijam
        7
    aijam  
       2019-04-04 12:43:11 +08:00
    比如我会每句话写一行,视觉上舒服,也方便修改。空行代表分段。

    ~~~
    xxxxxxxxxxxxxxxx.
    xxxxxxxxxxxx.
    xxxxxxxxxxxxxxxxxxxxxxxx.

    xxxxxxxxxxxxxxxxxxxxxxxx.
    xxxxxxxxxxxxxxxx.
    xxxxxxx.
    ~~~
    SingeeKing
        8
    SingeeKing  
       2019-04-04 12:45:42 +08:00
    行末加两个空格是换行,对应着 <br>
    两次回车是分段,对应着 <p>

    我为什么记得 github 只按一次回车不会换行
    lisisi
        9
    lisisi  
    OP
       2019-04-04 12:57:51 +08:00
    @azh7138m 谢谢,看到这些话知道起因了

    I am way late to this ball game, but I have to raise a point that I don't think anyone else has mentioned. Markdown behaves this way for a specific reason:

    > Readability, however, is emphasized above all else. A Markdown-formatted document should be publishable as-is, as plain text, without looking like it ’ s been marked up with tags or formatting instructions. Source: Markdown Philosophy

    In other words, Markdown is designed to be equally nicely formatted both as a text document and as an HTML document. That is the reason behind the line break behavior. Markdown documents read nicely as text documents because the author can control the text display without having to depend on the word-wrapping behavior of the editor. This is a feature and by design, not lazy programming as some have suggested.

    I, for one, dislike GitHub for making the change they did, because now I have to make a choice between a Markdown document that looks nicely on GitHub and one that looks nicely to someone reading it in a terminal window.

    @SingeeKing github 确实是 1 次回车换行,你试试
    https://github.com/vuejs/vue/issues/new
    woncode
        10
    woncode  
       2019-04-04 13:00:54 +08:00 via Android
    这个问题也一直让我耿耿于怀,多次尝试效果寻找有有说服力的答案,但是基本都看到什么 markdown 原作者是为 email 设计的,我想是因为以前的 email 编辑有所缺陷,而这样设计去弥补的吧。
    反正现在看来,我认为不管什么场景,还是一个回车就对应一个硬换行<br>更加好
    SuperMild
        11
    SuperMild  
       2019-04-04 13:01:34 +08:00
    设定为怎样都好,最大的问题是标准不统一。
    iasuna
        12
    iasuna  
       2019-04-04 13:03:38 +08:00 via iPhone
    latex 也一样啊 两次换行明显更好 如果你用 gedit 这种编辑器你就明白不允许的源代码换行会很乱
    impl
        13
    impl  
       2019-04-04 13:11:21 +08:00 via Android
    common mark 了解一下
    https://commonmark.org/
    Reficul
        14
    Reficul  
       2019-04-04 13:19:11 +08:00
    LaTeX 单个换行符似乎和 Markdown 的行为是一样的
    no1xsyzy
        15
    no1xsyzy  
       2019-04-04 13:35:58 +08:00
    看一下我的毕设这一段的效果 https://github.com/no1xsyzy/fyp/blame/master/final.md#L112
    源代码是锯齿的,但生成的 pdf 不是。
    锯齿的确实好看(方便),但实在是不适合毕设报告。
    woncode
        16
    woncode  
       2019-04-04 13:49:38 +08:00 via Android
    @lisisi 这段英文大概意思是,他希望原生文本的展示效果,和 html 渲染后的展示效果是相同的,那我认为把回车当做软换行来渲染才真的违反这个初衷呢,你在编辑器明明看到的是有条理的换行了,但是 html 渲染后就粘在一起,连成一坨了
    lisisi
        17
    lisisi  
    OP
       2019-04-04 14:15:50 +08:00
    @iasuna
    @Reficul
    @woncode
    这个起因只能总结为历史问题,当时提出标准的时候针对命令行编辑器,也是程序员的最早提议,所以就是这个结果了。在命令行之外的地方使用 markdown,觉得 github 风格的更合适一些。
    QNLvw5fLfr7c
        18
    QNLvw5fLfr7c  
       2019-04-04 15:54:37 +08:00 via Android
    单个换行被替换成空格,感觉可能是方便英文源文件排版。感觉中文文章用 markdown 总有地方不舒服,感觉作者很少考虑其他语言的习惯。
    HangoX
        19
    HangoX  
       2019-04-04 16:06:39 +08:00
    我觉得 markdown 最大的问题是标准不统一,原本的标准简陋,单单图片这个写法,大小控制每家都不一样,但是写文字的时候又很爽
    geelaw
        20
    geelaw  
       2019-04-04 16:15:08 +08:00
    Markdown 自然语言文本没有“换行”的概念,那个叫做“换段”。连续两个换行翻译为 HTML 换段。用末尾双空格换行是一个超级糟糕的设计,因为很多现代编辑器会删除 trialing space。

    @woncode #16 你似乎理解错了“渲染”的意思,如果你写 Markdown

    Hello,
    world!

    就相当于写 HTML

    <p>Hello,
    world!</p>

    以上叫做 HTML 的渲染结果,在浏览器里你会看到 Hello, world!(默认的 CSS 的情况下)因为 p 这种自然语言文本类型的元素默认 white-space: normal; 相当于 \s+ 替换为一个空格。

    @maokwen #18 这确实是一个问题,但是这个和中文不中文其实没啥关系,是 HTML 的空白处理策略根深蒂固的问题。

    但是加一个空白行的好处是即使不用首行缩进、不用段间距,纯文本查看的时候也能看出哪里切换了一段。

    @woncode #10 这个历史原因挺复杂的,现在还有很多人格式化纯文本邮件的时候自动换行( Outlook 会帮你删除多余的换行符,并把连续两个换行符转换为换段)。
    wobuhuicode
        21
    wobuhuicode  
       2019-04-04 16:44:50 +08:00
    双空格换行
    cyspy
        22
    cyspy  
       2019-04-04 20:53:40 +08:00
    在不自动换行的编辑环境下方便手动换行
    xiii1991
        23
    xiii1991  
       2019-06-02 21:45:35 +08:00
    一句一行,段落之间多空一行;这种方式比较方便 diff 吧?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1006 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 22:14 · PVG 06:14 · LAX 15:14 · JFK 18:14
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.