Couldn't find wdiff. Falling back to builtin diff colouring... 差异: spec.txt - spec.txt - CommonMark 规范
 spec.txt   spec.txt 
--- ---
标题: CommonMark 规范 标题: CommonMark 规范
作者: John MacFarlane 作者: John MacFarlane
版本: 0.26 版本: 0.27
日期: '2016-07-15' 日期: '2016-11-18'
许可: '[CC-BY-SA 4.0](http://creativecommons.org/licenses/by-sa/4.0/)' 许可: '[CC-BY-SA 4.0](http://creativecommons.org/licenses/by-sa/4.0/)'
... ...
# 引言 # 引言
## 什么是 Markdown? ## 什么是 Markdown?
Markdown 是一种用于编写结构化文档的纯文本格式, Markdown 是一种用于编写结构化文档的纯文本格式,
基于在电子邮件和 usenet 帖子中用于表示格式的约定。 基于在电子邮件和 usenet 帖子中用于表示格式的约定。
它由 John Gruber 于 2004 年开发,他编写了 它由 John Gruber 于 2004 年开发,他编写了
跳过至第 1872 行的更改 跳过至第 1872 行的更改
## HTML blocks ## HTML blocks
An [HTML block](@) is a group of lines that is treated An [HTML block](@) is a group of lines that is treated
as raw HTML (and will not be escaped in HTML output). as raw HTML (and will not be escaped in HTML output).
There are seven kinds of [HTML block], which can be defined There are seven kinds of [HTML block], which can be defined
by their start and end conditions. The block begins with a line that by their start and end conditions. The block begins with a line that
meets a [start condition](@) (after up to three spaces meets a [start condition](@) (after up to three spaces
optional indentation). It ends with the first subsequent line that optional indentation). It ends with the first subsequent line that
meets a matching [end condition](@), or the last line of meets a matching [end condition](@), or the last line of
文档或其他 [容器块](@),如果没有遇到满足以下条件的行 文档或其他 [容器块]),如果没有遇到满足以下条件的行
[end condition]. If the first line meets both the [start condition] [end condition]. If the first line meets both the [start condition]
and the [end condition], the block will contain just that line. and the [end condition], the block will contain just that line.
1. **Start condition:** line begins with the string `<script`, 1. **Start condition:** line begins with the string `<script`,
`<pre`, or `<style` (case-insensitive), followed by whitespace, `<pre`, or `<style` (case-insensitive), followed by whitespace,
the string `>`, or the end of the line.\ the string `>`, or the end of the line.\
**End condition:** line contains an end tag **End condition:** line contains an end tag
`</script>`, `</pre>`, or `</style>` (case-insensitive; it `</script>`, `</pre>`, or `</style>` (case-insensitive; it
need not match the start tag). need not match the start tag).
跳过至第 1902 行的更改 跳过至第 1902 行的更改
5. **开始条件:** 行以字符串 5. **开始条件:** 行以字符串
`<![CDATA[` 开头。\ `<![CDATA[` 开头。\
**结束条件:** 行包含字符串 `]]>`。 **结束条件:** 行包含字符串 `]]>`。
6. **开始条件:** 行以字符串 `<` 或 `</` 开头, 6. **开始条件:** 行以字符串 `<` 或 `</` 开头,
后跟以下字符串之一(不区分大小写):`address`、 后跟以下字符串之一(不区分大小写):`address`、
`article`、`aside`、`base`、`basefont`、`blockquote`、`body`、 `article`、`aside`、`base`、`basefont`、`blockquote`、`body`、
`caption`、`center`、`col`、`colgroup`、`dd`、`details`、`dialog`、 `caption`、`center`、`col`、`colgroup`、`dd`、`details`、`dialog`、
`dir`、`div`、`dl`、`dt`、`fieldset`、`figcaption`、`figure`、 `dir`、`div`、`dl`、`dt`、`fieldset`、`figcaption`、`figure`、
`footer`、`form`、`frame`、`frameset`、`h1`、`head`、`header`、`hr`、 `footer`, `form`, `frame`, `frameset`,
`h1`, `h2`, `h3`, `h4`, `h5`, `h6`, `head`, `header`, `hr`,
`html`, `iframe`, `legend`, `li`, `link`, `main`, `menu`, `menuitem`, `html`, `iframe`, `legend`, `li`, `link`, `main`, `menu`, `menuitem`,
`meta`、`nav`、`noframes`、`ol`、`optgroup`、`option`、`p`、`param`、 `meta`、`nav`、`noframes`、`ol`、`optgroup`、`option`、`p`、`param`、
`section`、`source`、`summary`、`table`、`tbody`、`td`、 `section`、`source`、`summary`、`table`、`tbody`、`td`、
`tfoot`、`th`、`thead`、`title`、`tr`、`track`、`ul`,后跟 `tfoot`、`th`、`thead`、`title`、`tr`、`track`、`ul`,后跟
[空白]、行尾、字符串 `>` 或 [空白]、行尾、字符串 `>` 或
字符串 `/>`。\ 字符串 `/>`。\
**结束条件:** 行后紧跟一个 [空行]。 **结束条件:** 行后紧跟一个 [空行]。
7. **Start condition:** line begins with a complete [open tag] 7. **Start condition:** line begins with a complete [open tag]
或 [结束标签] (其中 [标签名] 不是 `script`、 或 [结束标签] (其中 [标签名] 不是 `script`、
跳过至第 3415 行的更改 跳过至第 3416 行的更改
blocks *Bs* starting with a [non-whitespace character] and not separated blocks *Bs* starting with a [non-whitespace character] and not separated
from each other by more than one blank line, and *M* is a list from each other by more than one blank line, and *M* is a list
marker of width *W* followed by 1 ≤ *N* ≤ 4 spaces, then the result marker of width *W* followed by 1 ≤ *N* ≤ 4 spaces, then the result
of prepending *M* and the following spaces to the first line of of prepending *M* and the following spaces to the first line of
*Ls*, and indenting subsequent lines of *Ls* by *W + N* spaces, is a *Ls*, and indenting subsequent lines of *Ls* by *W + N* spaces, is a
list item with *Bs* as its contents. The type of the list item list item with *Bs* as its contents. The type of the list item
(bullet or ordered) is determined by the type of its list marker. (bullet or ordered) is determined by the type of its list marker.
If the list item is ordered, then it is also assigned a start If the list item is ordered, then it is also assigned a start
number, based on the ordered list marker. number, based on the ordered list marker.
例外:当 列表项中断一个段落时——也就是说 例外:当 [列表] 中的第一个列表项中断
也就是说,当它开始于一个本来会被视为 a paragraph---that is, when it starts on a line that would
[段落续行文本] 的行时——那么 (a) 行 *Ls* 必须 otherwise count as [paragraph continuation text]---then (a)
不能以空行开始,并且 (b) 如果列表项是 行 *Ls* 不能以空行开始,并且 (b) 如果
有序列表,则起始编号必须为 1。 列表项是有序列表,则起始编号必须为 1。
For example, let *Ls* be the lines For example, let *Ls* be the lines
```````````````````````````````` 示例 ```````````````````````````````` 示例
A paragraph A paragraph
with two lines. with two lines.
indented code indented code
> A block quote. > A block quote.
跳过至第 4458 行的更改 跳过至第 4459 行的更改
we don't have a "first paragraph" to measure from? Rule #2 simply stipulates we don't have a "first paragraph" to measure from? Rule #2 simply stipulates
that in such cases, we require one space indentation from the list marker that in such cases, we require one space indentation from the list marker
(and then the normal four spaces for the indented code). This will match the (and then the normal four spaces for the indented code). This will match the
four-space rule in cases where the list marker plus its initial indentation four-space rule in cases where the list marker plus its initial indentation
takes four spaces (a common case), but diverge in other cases. takes four spaces (a common case), but diverge in other cases.
## Lists ## Lists
一个 [列表](@) 是一系列一个或多个 一个 [列表](@) 是一系列一个或多个
[同类型] 列表项的序列。列表项之间 [同类型] 列表项的序列。列表项之间
可以由 单个 [空行] 分隔,但两个 可以由 任意数量的空行分隔。
blank lines end all containing lists.
如果两个列表项以相同类型的 [列表标记] 开头,则它们是 [同类型](@) 的。 如果两个列表项以相同类型的 [列表标记] 开头,则它们是 [同类型](@) 的。
如果它们以相同类型的 [列表标记] 开头。 如果它们以相同类型的 [列表标记] 开头。
Two list markers are of the Two list markers are of the
same type if (a) they are bullet list markers using the same character same type if (a) they are bullet list markers using the same character
(`-`, `+`, or `*`) or (b) they are ordered list numbers with the same (`-`, `+`, or `*`) or (b) they are ordered list numbers with the same
delimiter (either `.` or `)`). delimiter (either `.` or `)`).
一个列表是一个 [有序列表](@) 一个列表是一个 [有序列表](@)
if its constituent list items begin with if its constituent list items begin with
跳过至第 4535 行的更改 跳过至第 4535 行的更改
<p>Foo</p> <p>Foo</p>
<ul> <ul>
<li>bar</li> <li>bar</li>
<li>baz</li> <li>baz</li>
</ul> </ul>
```````````````````````````````` ````````````````````````````````
`Markdown.pl` does not allow this, through fear of triggering a list `Markdown.pl` does not allow this, through fear of triggering a list
via a numeral in a hard-wrapped line via a numeral in a hard-wrapped line
```````````````````````````````` markdown ``` markdown
The number of windows in my house is The number of windows in my house is
14. The number of doors is 6. 14. The number of doors is 6.
```````````````````````````````` ```
奇怪的是,`Markdown.pl` *确实*允许引用块 奇怪的是,`Markdown.pl` *确实*允许引用块
中断一个段落,尽管可能存在相同的考虑。 中断一个段落,尽管可能存在相同的考虑。
适用。 适用。
在 CommonMark 中,我们确实允许列表中断段落,因为 在 CommonMark 中,我们确实允许列表中断段落,因为
有两个原因。首先,人们自然且不罕见地 有两个原因。首先,人们自然且不罕见地
在没有空行的情况下开始列表 在没有空行的情况下开始列表
I need to buy ``` markdown
- new shoes I need to buy
- a coat - new shoes
- 一张机票 - 一件大衣
- a plane ticket
```
其次,我们被一种 其次,我们被一种
> [principle of uniformity](@) > [principle of uniformity](@)
> if a chunk of text has a certain > if a chunk of text has a certain
> meaning, it will continue to have the same meaning when put into a > meaning, it will continue to have the same meaning when put into a
> container block (such as a list item or blockquote). > container block (such as a list item or blockquote).
(事实上,[列表项] 和 [块引用] 的规范预设了 (事实上,[列表项] 和 [块引用] 的规范预设了
this principle.) This principle implies that if this principle.) This principle implies that if
* I need to buy ``` markdown
- new shoes * I need to buy
- a coat - new shoes
- 一张机票 - 一件大衣
- a plane ticket
```
is a list item containing a paragraph followed by a nested sublist, is a list item containing a paragraph followed by a nested sublist,
as all Markdown implementations agree it is (though the paragraph as all Markdown implementations agree it is (though the paragraph
may be rendered without `<p>` tags, since the list is "tight"), may be rendered without `<p>` tags, since the list is "tight"),
then then
I need to buy ``` markdown
- new shoes I need to buy
- a coat - new shoes
- 一张机票 - 一件大衣
- a plane ticket
```
它本身应该是一个段落后跟一个嵌套子列表。 它本身应该是一个段落后跟一个嵌套子列表。
由于在列表项内允许列表中断段落是 Markdown 的既定做法,因此 由于在列表项内允许列表中断段落是 Markdown 的既定做法,因此
[统一性原则] 要求我们允许在列表项之外也这样做。 [统一性原则] 要求我们允许在列表项之外也这样做。
统一性] 要求我们允许在列表项之外也这样做。 统一性] 要求我们允许在列表项之外也这样做。
well. ([reStructuredText](http://docutils.sourceforge.net/rst.html) well. ([reStructuredText](http://docutils.sourceforge.net/rst.html)
takes a different approach, requiring blank lines before lists takes a different approach, requiring blank lines before lists
even inside other list items.) even inside other list items.)
跳过至第 5343 行的更改 跳过至第 5350 行的更改
内部空格和 [换行符] 被合并为 内部空格和 [换行符] 被合并为
单个空格,就像浏览器会做的那样。 单个空格,就像浏览器会做的那样。
```````````````````````````````` 示例 ```````````````````````````````` 示例
`foo bar `foo bar
baz` baz`
. .
<p><code>foo bar baz</code></p> <p><code>foo bar baz</code></p>
```````````````````````````````` ````````````````````````````````
并非所有 [Unicode 空白字符](例如,不间断空格)都会被
合并,然而
```````````````````````````````` 示例
`a  b`
.
<p><code>a  b</code></p>
````````````````````````````````
Q: Why not just leave the spaces, since browsers will collapse them Q: Why not just leave the spaces, since browsers will collapse them
呢?答:因为我们可能针对的是非HTML格式,我们 呢?答:因为我们可能针对的是非HTML格式,我们
不应依赖于HTML特定的渲染假设。 不应依赖于HTML特定的渲染假设。
(现有实现对内部空格和[换行符]的处理方式各不相同。 (现有实现对内部空格和[换行符]的处理方式各不相同。
空格和 [换行符]。有些,包括 `Markdown.pl` 和 空格和 [换行符]。有些,包括 `Markdown.pl` 和
[换行符]转换为`<br />`标签。 [换行符]转换为`<br />`标签。
`<br />` tag. But this makes things difficult for those who like to `<br />` tag. But this makes things difficult for those who like to
因为代码跨度中的换行符会导致输出中出现意外的换行符。 因为代码跨度中的换行符会导致输出中出现意外的换行符。
其他则保持内部空格不变,这在只针对HTML时是可以的。 其他则保持内部空格不变,这在只针对HTML时是可以的。
跳过至第 6158 行的更改 跳过至第 6174 行的更改
<p><em>foo<strong>bar</strong>baz</em></p> <p><em>foo<strong>bar</strong>baz</em></p>
```````````````````````````````` ````````````````````````````````
注意,在上述情况中,这种解释被以下条件所排除:如果一个既能作为开头又能作为结尾的分隔符(例如 foo 后面的 *)所在的分隔符序列总长度是 3 的倍数,那么除非其两个部分的长度都是 3 的倍数,否则它不能形成强调。 注意,在上述情况中,这种解释被以下条件所排除:如果一个既能作为开头又能作为结尾的分隔符(例如 foo 后面的 *)所在的分隔符序列总长度是 3 的倍数,那么除非其两个部分的长度都是 3 的倍数,否则它不能形成强调。
``` markdown ``` markdown
<p><em>foo</em><em>bar<em></em>baz</em></p> <p><em>foo</em><em>bar<em></em>baz</em></p>
``` ```
is precluded by the condition that a delimiter that is precluded by the condition that a delimiter that
可以同时打开和关闭(就像 `foo` 后面的 `*` 可以同时打开和关闭(就像 `foo` 后面的 `*`
如果长度之和不形成强调 如果长度之和不形成强调
the delimiter runs containing the opening and the delimiter runs containing the opening and
closing delimiters is a multiple of 3. closing delimiters is a multiple of 3.
The same condition ensures that the following The same condition ensures that the following
情况都是强调内部嵌套的强强调, 情况都是强调内部嵌套的强强调,
emphasis, even when the interior spaces are emphasis, even when the interior spaces are
omitted omitted
```````````````````````````````` 示例 ```````````````````````````````` 示例
跳过至第 6186 行的更改 跳过至第 6202 行的更改
. .
<p><em>foo <strong>bar</strong></em></p> <p><em>foo <strong>bar</strong></em></p>
```````````````````````````````` ````````````````````````````````
```````````````````````````````` 示例 ```````````````````````````````` 示例
*foo**bar*** *foo**bar***
. .
<p><em>foo<strong>bar</strong></em></p> <p><em>foo<strong>bar</strong></em></p>
```````````````````````````````` ````````````````````````````````
```````````````````````````````` 示例
*foo**bar***
.
<p><em>foo<strong>bar</strong></em></p>
````````````````````````````````
支持无限级的嵌套。 支持无限级的嵌套。
```````````````````````````````` 示例 ```````````````````````````````` 示例
*foo **bar *baz* bim** bop* *foo **bar *baz* bim** bop*
. .
<p><em>foo <strong>bar <em>baz</em> bim</strong> bop</em></p> <p><em>foo <strong>bar <em>baz</em> bim</strong> bop</em></p>
```````````````````````````````` ````````````````````````````````
```````````````````````````````` 示例 ```````````````````````````````` 示例
*foo [*bar*](/url)* *foo [*bar*](/url)*
跳过至第 6871 行的更改 跳过至第 6881 行的更改
反斜杠转义和实体以及数字字符引用 反斜杠转义和实体以及数字字符引用
可以在标题中使用 可以在标题中使用
```````````````````````````````` 示例 ```````````````````````````````` 示例
[链接](/url "标题 \"&quot;") [链接](/url "标题 \"&quot;")
. .
<p><a href="/url" title="标题 &quot;&quot;">链接</a></p> <p><a href="/url" title="标题 &quot;&quot;">链接</a></p>
```````````````````````````````` ````````````````````````````````
标题必须用 [空白符] 与链接分隔。
其他 [Unicode 空白符] 比如不间断空格则不起作用。
```````````````````````````````` 示例
[链接](/url "标题")
.
<p><a href="/url%C2%A0%22title%22">链接</a></p>
````````````````````````````````
除非经过转义,否则不允许嵌套平衡的引号。 除非经过转义,否则不允许嵌套平衡的引号。
```````````````````````````````` 示例 ```````````````````````````````` 示例
[链接](/url "标题 "and" 标题") [链接](/url "标题 "and" 标题")
. .
<p>[链接](/url &quot;标题 &quot;and&quot; 标题&quot;)</p> <p>[链接](/url &quot;标题 &quot;and&quot; 标题&quot;)</p>
```````````````````````````````` ````````````````````````````````
但可以通过使用不同的引号类型轻松解决此问题。 但可以通过使用不同的引号类型轻松解决此问题。
跳过至第 7477 行的更改 跳过至第 7496 行的更改
following closing bracket following closing bracket
```````````````````````````````` 示例 ```````````````````````````````` 示例
[foo*]: /url [foo*]: /url
*[foo*] *[foo*]
. .
<p>*<a href="/url">foo*</a></p> <p>*<a href="/url">foo*</a></p>
```````````````````````````````` ````````````````````````````````
完整 引用优先于快捷引用: 完整 引用和紧凑引用优先于快捷
引用
```````````````````````````````` 示例 ```````````````````````````````` 示例
[foo][bar] [foo][bar]
[foo]: /url1 [foo]: /url1
[bar]: /url2 [bar]: /url2
. .
<p><a href="/url2">foo</a></p> <p><a href="/url2">foo</a></p>
```````````````````````````````` ````````````````````````````````
```````````````````````````````` 示例
[foo][]
[foo]: /url1
.
<p><a href="/url1">foo</a></p>
````````````````````````````````
内联链接也具有优先权
```````````````````````````````` 示例
[foo]()
[foo]: /url1
.
<p><a href="">foo</a></p>
````````````````````````````````
```````````````````````````````` 示例
[foo](不是链接)
[foo]: /url1
.
<p><a href="/url1">foo</a>(不是链接)</p>
````````````````````````````````
在以下情况下,`[bar][baz]` 被解析为引用, 在以下情况下,`[bar][baz]` 被解析为引用,
`[foo]` 被解析为普通文本 `[foo]` 被解析为普通文本
```````````````````````````````` 示例 ```````````````````````````````` 示例
[foo][bar][baz] [foo][bar][baz]
[baz]: /url [baz]: /url
. .
<p>[foo]<a href="/url">bar</a></p> <p>[foo]<a href="/url">bar</a></p>
```````````````````````````````` ````````````````````````````````
跳过至第 8410 行的更改 跳过至第 8456 行的更改
1. 首先,我们遍历开放块,从根文档开始, 1. 首先,我们遍历开放块,从根文档开始,
通过最后一个子块一直下降到最后一个开放块。每个块都施加一个条件,即行必须满足该条件, 通过最后一个子块一直下降到最后一个开放块。每个块都施加一个条件,即行必须满足该条件,
每个块都施加一个条件,如果块要保持开放,则行必须满足该条件。例如,块引用需要一个 每个块都施加一个条件,如果块要保持开放,则行必须满足该条件。例如,块引用需要一个
`>` 字符。一个段落需要一个非空行。 `>` 字符。一个段落需要一个非空行。
在此阶段,我们可能会匹配所有或仅部分开放块。 在此阶段,我们可能会匹配所有或仅部分开放块。
在此阶段,我们可能会匹配所有或仅部分开放块。但是我们还不能关闭不匹配的块,因为我们可能有一个 在此阶段,我们可能会匹配所有或仅部分开放块。但是我们还不能关闭不匹配的块,因为我们可能有一个
但是我们还不能关闭不匹配的块,因为我们可能有一个 但是我们还不能关闭不匹配的块,因为我们可能有一个
[惰性续行]。 [惰性续行]。
2. 接下来,在消耗了现有块的续行标记之后, 2. 接下来,在消耗了现有块的续行标记之后,
我们寻找新的块开始(例如,块引用的 `>`。 块,我们寻找新的块开始(例如,块引用的 `>`
如果我们遇到一个新的区块起始,我们会关闭在步骤 1 中 如果我们遇到一个新的区块起始,我们会关闭在步骤 1 中
未匹配的任何区块,然后再将新区块创建为最后一个 未匹配的任何区块,然后再将新区块创建为最后一个
匹配区块的子级。 匹配区块的子级。
3. 最后,我们查看行中剩余的部分(在区块 3. 最后,我们查看行中剩余的部分(在区块
标记如 `>`、列表标记和缩进被消耗之后)。 标记如 `>`、列表标记和缩进被消耗之后)。
这些文本可以合并到最后一个开放的 这些文本可以合并到最后一个开放的
区块中(段落、代码块、标题或原始 HTML)。 区块中(段落、代码块、标题或原始 HTML)。
当我们看到段落的一行是 Setext 标题行 时, 当我们看到段落的一行是 Setext 标题行 时,
 更改结束。17 个更改块。 
34 行已更改或删除 80 行已更改或添加

This html diff was produced by rfcdiff 1.45. The latest version is available from http://tools.ietf.org/tools/rfcdiff/