When you do want to insert a <br /> break tag using Markdown, you end a line with two or more spaces, then type return. 当你想使用 Markdown 插入一个 <br /> 断行标签时,你需要在行尾输入两个或更多空格,然后按回车键。 Yes, this takes a tad more effort to create a <br />, but a simplistic “every line break is a <br />” rule wouldn’t work for Markdown. Markdown’s email-style blockquoting and multi-paragraph list items work best — and look better — when you format them with hard breaks. 是的,创建一个 <br /> 需要更多一点的努力,但简单的「每一行换行就是 <br />」规则并不适用于 Markdown。Markdown 的电子邮件风格块引用和多段落列表项,用硬换行格式化效果最好 —— 看起来也更美观。
哎呀,创始人早就写好了这个规则了啊。
GFM 中的规则
去找了一下 github flavored markdown,发现这里的说法是换行有软硬换行之分,
也就是说软换行就是
1 2
<p>换行 换行</p>
而 HTML 中,多个连续的空白字符(包括换行、空格和制表符)都会被浏览器解析为一个空格。所以会被解析为:
1
换行 换行
硬换行就是
1 2
<p>换行<br/> 换行</p>
这和原始的那个规则好像大差不差,总之就是,<br/> 的话就要用两次及以上的空格!
GitHub Flavored Markdown 上的中英对照
6.12 Hard line breaks A line break (not in a code span or HTML tag) that is preceded by two or more spaces and does not occur at the end of a block is parsed as a hard line break (rendered in HTML as a <br /> tag): 换行符(不在代码跨度或 HTML 标签中)若前面有两个或更多空格且未出现在块末尾,则会被解析为硬换行(在 HTML 中渲染为 <br /> 标签):
1 2
foo(空格)(空格) baz
1 2
<p>foo<br /> baz</p>
For a more visible alternative, a backslash before the line ending may be used instead of two spaces: 若需更直观的替代方案,可在行尾使用反斜杠代替两个空格:
1 2
foo\ baz
1 2
<p>foo<br /> baz</p>
More than two spaces can be used: 可以使用超过两个空格:
1 2
foo(空格)(空格)(空格)(空格)(空格) baz
1 2
<p>foo<br /> baz</p>
Leading spaces at the beginning of the next line are ignored: 下一行开头的空格会被忽略:
1 2
foo(空格)(空格) (空格)(空格)(空格)(空格)(空格)bar
1 2
<p>foo<br /> bar</p>
1 2
foo\ (空格)(空格)(空格)(空格)(空格)bar
1 2
<p>foo<br /> bar</p>
Line breaks can occur inside emphasis, links, and other constructs that allow inline content: 换行符可出现在允许内联内容的强调、链接等结构中:
1 2
*foo(空格)(空格) bar*
1 2
<p><em>foo<br /> bar</em></p>
1 2
*foo\ bar*
1 2
<p><em>foo<br /> bar</em></p>
Line breaks do not occur inside code spans: 换行符不会出现在代码跨度内部:
1 2
`code(空格)(空格) span`
1
<p><code>code span</code></p>
1 2
`code\ span`
1
<p><code>code\ span</code></p>
or HTML tags: 或 HTML 标签中:
1 2
<ahref="foo(空格)(空格) bar">
1 2
<p><ahref="foo(空格)(空格) bar"></p>
1 2
<ahref="foo\ bar">
1 2
<p><ahref="foo\ bar"></p>
Hard line breaks are for separating inline content within a block. Neither syntax for hard line breaks works at the end of a paragraph or other block element: 硬换行用于在块内分隔内联内容。硬换行的语法在段落或其他块元素末尾无效:
1
foo\
1
<p>foo\</p>
1
foo(空格)(空格)
1
<p>foo</p>
1
### foo\
1
<h3>foo\</h3>
1
### foo(空格)(空格)
1
<h3>foo</h3>
6.13 Soft line breaks A regular line break (not in a code span or HTML tag) that is not preceded by two or more spaces or a backslash is parsed as a softbreak. (A softbreak may be rendered in HTML either as a line ending or as a space. The result will be the same in browsers. In the examples here, a line ending will be used.) 普通换行符(不在代码跨度或 HTML 标签中)若未被两个以上空格或反斜杠修饰,则解析为软换行(在 HTML 中可能渲染为换行或空格。浏览器效果相同。以下示例使用换行符):
1 2
foo(无空格) baz
1 2
<p>foo baz</p>
Spaces at the end of the line and beginning of the next line are removed: 行尾和下一行开头的空格会被移除:
1 2
foo(空格) (空格)baz
1 2
<p>foo baz</p>
A conforming parser may render a soft line break in HTML either as a line break or as a space. 合规解析器可将软换行在 HTML 中渲染为换行或空格。
A renderer may also provide an option to render soft line breaks as hard line breaks. 渲染器也可提供将软换行渲染为硬换行的选项。