spec.txt   spec.txt 
--- ---
标题: CommonMark 规范 标题: CommonMark 规范
作者: John MacFarlane 作者: John MacFarlane
版本: 0.17 版本: 0.18
日期: 2015-01-24 日期: 2015-03-03
许可: '[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 年开发,他编写了
跳至第 228 行更改 跳至第 228 行更改
出于安全原因,一个符合规范的解析器必须去除或替换 出于安全原因,一个符合规范的解析器必须去除或替换
Unicode 字符 `U+0000`。 Unicode 字符 `U+0000`。
不包含任何字符的行,或仅包含空格 不包含任何字符的行,或仅包含空格
(`U+0020`)或制表符(`U+0009`)的行,称为 [空行](@blank-line)。 (`U+0020`)或制表符(`U+0009`)的行,称为 [空行](@blank-line)。
本规范将使用以下字符类定义: 本规范将使用以下字符类定义:
一个 [空白字符](@whitespace-character) 是空格 一个 [空白字符](@whitespace-character) 是空格
(`U+0020`)、制表符 (`U+0009`)、回车符 (`U+000D`),或 (`U+0020`)、制表符 (`U+0009`)、换行符 (`U+000A`)、行制表符 (`U+000B`)、
newline (`U+000A`). 换页符 (`U+000C`),或回车符 (`U+000D`)。
[空白](@whitespace) 是一个或多个 [空白字符] 的序列。 [空白](@whitespace) 是一个或多个 [空白字符] 的序列。
字符]s。 字符]s。
一个 [Unicode 空格字符](@unicode-whitespace-character) 是指 一个 [Unicode 空格字符](@unicode-whitespace-character) 是指
Unicode `Zs` 类中的任何码点,或者一个制表符(`U+0009`), Unicode `Zs` 类中的任何码点,或者一个制表符(`U+0009`),
回车符(`U+000D`)、换行符(`U+000A`)或换页符 回车符(`U+000D`)、换行符(`U+000A`)或换页符
(`U+000C`)。 (`U+000C`)。
[Unicode 空白](@unicode-whitespace) 是一个或多个 [Unicode 空白](@unicode-whitespace) 是一个或多个
跳至第 1847 行更改 跳至第 1847 行更改
. .
[Foo bar] [Foo bar]
<我的网址> <我的网址>
'title' 'title'
[Foo bar] [Foo bar]
. .
<p><a href="my%20url" title="title">Foo bar</a></p> <p><a href="my%20url" title="title">Foo bar</a></p>
. .
标题可以跨越多行
.
[foo]: /url '
标题
第一行
第二行
'
[foo]
.
<p><a href="/url" title="
标题
第一行
第二行
">foo</a></p>
.
但是,它不能包含 [空行]
.
[foo]: /url '标题
带空行'
[foo]
.
<p>[foo]: /url '标题</p>
<p>带空行'</p>
<p>[foo]</p>
.
标题可以省略 标题可以省略
. .
[foo] [foo]
/url /url
[foo] [foo]
. .
<p><a href="/url">foo</a></p> <p><a href="/url">foo</a></p>
. .
跳至第 1918 行更改 跳至第 1950 行更改
. .
Here is a link reference definition with no corresponding link. Here is a link reference definition with no corresponding link.
It contributes nothing to the document. It contributes nothing to the document.
. .
[foo]: /url [foo]: /url
. .
. .
这里是另一个
.
[
foo
]: /url
bar
.
<p>bar</p>
.
This is not a link reference definition, because there are This is not a link reference definition, because there are
标题后的 [非空格字符] 标题后的 [非空格字符]
. .
[foo]: /url "title" ok [foo]: /url "title" ok
. .
<p>[foo]: /url &quot;title&quot; ok</p> <p>[foo]: /url &quot;title&quot; ok</p>
. .
This is not a link reference definition, because it is indented This is not a link reference definition, because it is indented
跳至第 2691 行更改 跳至第 2734 行更改
<blockquote> <blockquote>
<blockquote> <blockquote>
<ul> <ul>
<li>one</li> <li>one</li>
</ul> </ul>
<p>two</p> <p>two</p>
</blockquote> </blockquote>
</blockquote> </blockquote>
. .
Note that at least one space is needed between the list marker and
any following content, so these are not list items
.
-one
2.two
.
<p>-one</p>
<p>2.two</p>
.
A list item may not contain blocks that are separated by more than A list item may not contain blocks that are separated by more than
one blank line. Thus, two blank lines will end a list, unless the one blank line. Thus, two blank lines will end a list, unless the
two blanks are contained in a [fenced code block]. two blanks are contained in a [fenced code block].
. .
- foo - foo
bar bar
- foo - foo
跳至第 2924 行更改 跳至第 2979 行更改
bar bar
. .
<ul> <ul>
<li> <li>
<p>foo</p> <p>foo</p>
<p>bar</p> <p>bar</p>
</li> </li>
</ul> </ul>
. .
3. **空列表项。**一个 [列表标记] 后面紧跟着一行 3. **以空行开头的项。**如果行序列 *Ls*
只包含 [空白字符] 是一个没有内容的列表项。 starting with a single [blank line] constitute a (possibly empty)
块序列 *Bs*,它们之间没有超过
一个空行分隔开,并且 *M* 是一个 宽度为 *W* 的 列表标记 *M*,
那么将 *M* 附加到 *Ls* 的第一行,并
将 *Ls* 的后续行缩进 *W + 1* 个空格, 结果就是一个列表
项,其内容为 *Bs*。
If a line is empty, then it need not be indented. The type of the
list item (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 number, based on the ordered list marker.
以下是一些以空行开头但不为空的列表项
.
-
foo
-
```
bar
```
-
baz
.
<ul>
<li>foo</li>
<li>
<pre><code>bar
</code></pre>
</li>
<li>
<pre><code>baz
</code></pre>
</li>
</ul>
.
这是一个空的无序列表项 这是一个空的无序列表项
. .
- foo - foo
- -
- bar - bar
. .
<ul> <ul>
<li>foo</li> <li>foo</li>
跳至第 3480 行更改 跳至第 3569 行更改
if its constituent list items begin with if its constituent list items begin with
[有序列表标记],和一个 [有序列表标记],和一个
[无序列表](@bullet-list) 如果其组成列表 [无序列表](@bullet-list) 如果其组成列表
项以 [无序列表标记] 开头。 项以 [无序列表标记] 开头。
[起始编号](@start-number) [起始编号](@start-number)
of an [ordered list] is determined by the list number of of an [ordered list] is determined by the list number of
its initial list item. The numbers of subsequent list items are its initial list item. The numbers of subsequent list items are
disregarded. disregarded.
如果任何一个组成项,列表就是 [松散的](@loose)。 如果其任何组成项,列表就是 [松散的](@loose)。
list items are separated by blank lines, or if any of its constituent list items are separated by blank lines, or if any of its constituent
list items directly contain two block-level elements with a blank line list items directly contain two block-level elements with a blank line
它们之间。否则,列表是 [紧密的](@tight)。 它们之间。否则,列表是 [紧密的](@tight)。
(The difference in HTML output is that paragraphs in a loose list are (The difference in HTML output is that paragraphs in a loose list are
wrapped in `<p>` tags, while paragraphs in a tight list are not.) wrapped in `<p>` tags, while paragraphs in a tight list are not.)
更改无序或有序列表分隔符会开始一个新的列表 更改无序或有序列表分隔符会开始一个新的列表
. .
- foo - foo
跳至第 4462 行更改 跳至第 4551 行更改
使用不需要回溯的高效解析策略。 使用不需要回溯的高效解析策略。
首先,是一些定义。[分隔符序列](@delimiter-run)(delimiter run)是指 首先,是一些定义。[分隔符序列](@delimiter-run)(delimiter run)是指
一个或多个 `*` 字符组成的序列,且其前后没有 一个或多个 `*` 字符组成的序列,且其前后没有
`*` 字符,或者一个或多个 `_` `*` 字符,或者一个或多个 `_`
字符组成的序列,且其前后没有 `_` 字符。 字符组成的序列,且其前后没有 `_` 字符。
一个 [左侧分隔符运行](@left-flanking-delimiter-run) 是 一个 [左侧分隔符运行](@left-flanking-delimiter-run) 是
一个 [分隔符运行],该运行 (a) 后不跟 [Unicode 空格], 一个 [分隔符运行],该运行 (a) 后不跟 [Unicode 空格],
并且 (b) 要么后面没有 [标点字符],或者 并且 (b) 要么后面没有 [标点字符],或者
前面有 [Unicode 空格] 或 [标点 符号]。 前面有 [Unicode 空格] 或 [标点 符号] 或
行的开头。
一个 [右侧分隔符运行](@right-flanking-delimiter-run) 是 一个 [右侧分隔符运行](@right-flanking-delimiter-run) 是
一个 [分隔符运行],该运行 (a) 前不跟 [Unicode 空格], 一个 [分隔符运行],该运行 (a) 前不跟 [Unicode 空格],
并且 (b) 要么前面没有 [标点字符],或者 并且 (b) 要么前面没有 [标点字符],或者
后跟 [Unicode 空格] 或 [标点 符号]。 后跟 [Unicode 空格] 或 [标点 符号] 或
行的末尾。
以下是一些定界符序列的示例。 以下是一些定界符序列的示例。
- 左侧分隔但非右侧分隔 - 左侧分隔但非右侧分隔
``` ```
***abc ***abc
_abc _abc
**"abc" **"abc"
_"abc" _"abc"
跳至第 4730 行更改 跳至第 4821 行更改
This is not emphasis, because the closing `*` is preceded by This is not emphasis, because the closing `*` is preceded by
whitespace whitespace
. .
*foo bar * *foo bar *
. .
<p>*foo bar *</p> <p>*foo bar *</p>
. .
换行符也被计为空白字符。
.
*foo bar
*
.
<p>*foo bar</p>
<ul>
<li></li>
</ul>
.
这不是强调,因为第二个 `*` 这不是强调,因为第二个 `*`
前面是标点符号,后面是字母数字 前面是标点符号,后面是字母数字
(hence it is not part of a [right-flanking delimiter run] (hence it is not part of a [right-flanking delimiter run]
. .
*(*foo) *(*foo)
. .
<p>*(*foo)</p> <p>*(*foo)</p>
. .
跳至第 4857 行更改 跳至第 4960 行更改
This is not strong emphasis, because the opening delimiter is This is not strong emphasis, because the opening delimiter is
后跟空白字符 后跟空白字符
. .
__ foo bar__ __ foo bar__
. .
<p>__ foo bar__</p> <p>__ foo bar__</p>
. .
换行符计为空白字符。
.
__
foo bar__
.
<p>__
foo bar__</p>
.
This is not strong emphasis, because the opening `__` is preceded This is not strong emphasis, because the opening `__` is preceded
一个字母数字,后面是标点符号 一个字母数字,后面是标点符号
. .
a__"foo"__ a__"foo"__
. .
<p>a__&quot;foo&quot;__</p> <p>a__&quot;foo&quot;__</p>
. .
使用 `__` 禁止单词内强强调 使用 `__` 禁止单词内强强调
跳至第 5507 行更改 跳至第 5619 行更改
<p><em>a <code>*</code></em></p> <p><em>a <code>*</code></em></p>
. .
. .
_a `_`_ _a `_`_
. .
<p><em>a <code>_</code></em></p> <p><em>a <code>_</code></em></p>
. .
. .
**a<http://foo.bar?q=**> **a<http://foo.bar/?q=**>
. .
<p>**a<a href="http://foo.bar?q=**">http://foo.bar?q=**</a></p> <p>**a<a href="http://foo.bar/?q=**">http://foo.bar/?q=**</a></p>
. .
. .
__a<http://foo.bar?q=__> __a<http://foo.bar/?q=__>
. .
<p>__a<a href="http://foo.bar?q=__">http://foo.bar?q=__</a></p> <p>__a<a href="http://foo.bar/?q=__">http://foo.bar/?q=__</a></p>
. .
## Links ## Links
A link contains [link text] (the visible text), a [link destination] A link contains [link text] (the visible text), a [link destination]
(the URI that is the link destination), and optionally a [link title]. (the URI that is the link destination), and optionally a [link title].
Markdown 中有两种基本类型的链接。在 [内联链接] 中 Markdown 中有两种基本类型的链接。在 [内联链接] 中
destination and title are given immediately after the link text. In destination and title are given immediately after the link text. In
[引用链接] 的目标和标题在文档其他地方定义 [引用链接] 的目标和标题在文档其他地方定义
the document. the document.
跳至第 5571 行更改 跳至第 5683 行更改
characters (`"`), including a `"` character only if it is characters (`"`), including a `"` character only if it is
backslash-escaped, or backslash-escaped, or
- a sequence of zero or more characters between straight single-quote - a sequence of zero or more characters between straight single-quote
characters (`'`), including a `'` character only if it is characters (`'`), including a `'` character only if it is
backslash-escaped, or backslash-escaped, or
- 匹配括号(`(...)`)之间的一个或多个字符序列, - 匹配括号(`(...)`)之间的一个或多个字符序列,
其中`)`字符只在被反斜杠转义时才包含。 其中`)`字符只在被反斜杠转义时才包含。
尽管 [链接标题] 可以跨多行,但不能包含
[空行]。
[内联链接](@inline-link) 由 [链接文本] 紧随其后组成 [内联链接](@inline-link) 由 [链接文本] 紧随其后组成
可选的[空白]、可选的[链接目的地]、可选的[链接标题]组成, 可选的[空白]、可选的[链接目的地]、可选的[链接标题]组成,
由[空白]与链接目的地分隔,可选的[空白],以及一个右括号`)`。 由[空白]与链接目的地分隔,可选的[空白],以及一个右括号`)`。
链接的文本由[链接文本]中包含的内联内容组成 链接的文本由[链接文本]中包含的内联内容组成
链接的文本由[链接文本]中包含的内联内容组成 链接的文本由[链接文本]中包含的内联内容组成
(不包括封闭的方括号)。 (不包括封闭的方括号)。
The link's URI consists of the link destination, excluding enclosing The link's URI consists of the link destination, excluding enclosing
`<...>` if present, with backslash-escapes in effect as described `<...>` if present, with backslash-escapes in effect as described
above. The link's title consists of the link title, excluding its above. The link's title consists of the link title, excluding its
enclosing delimiters, with backslash-escapes in effect as described enclosing delimiters, with backslash-escapes in effect as described
跳至第 5874 行更改 跳至第 5989 行更改
<p>[foo <bar attr="](baz)"></p> <p>[foo <bar attr="](baz)"></p>
. .
. .
[foo`](/uri)` [foo`](/uri)`
. .
<p>[foo<code>](/uri)</code></p> <p>[foo<code>](/uri)</code></p>
. .
. .
[foo<http://example.com?search=](uri)> [foo<http://example.com/?search=](uri)>
. .
<p>[foo<a href="http://example.com?search=%5D(uri)">http://example.com?search=]( uri)</a></p> <p>[foo<a href="http://example.com/?search=%5D(uri)">http://example.com/?search= ](uri)</a></p>
. .
有三种 [引用链接](@reference-link) 有三种 [引用链接](@reference-link)
[full](#full-reference-link), [collapsed](#collapsed-reference-link), [full](#full-reference-link), [collapsed](#collapsed-reference-link),
and [shortcut](#shortcut-reference-link). and [shortcut](#shortcut-reference-link).
一个 [完整引用链接](@full-reference-link) 一个 [完整引用链接](@full-reference-link)
由 [链接文本]、可选的 [空白] 和 [链接标签] 组成。 由 [链接文本]、可选的 [空白] 和 [链接标签] 组成。
that [matches] a [link reference definition] elsewhere in the document. that [matches] a [link reference definition] elsewhere in the document.
跳至第 6014 行更改 跳至第 6129 行更改
. .
[foo`][ref]` [foo`][ref]`
[ref]: /uri [ref]: /uri
. .
<p>[foo<code>][ref]</code></p> <p>[foo<code>][ref]</code></p>
. .
. .
[foo<http://example.com?search=][ref]> [foo<http://example.com/?search=][ref]>
[ref]: /uri [ref]: /uri
. .
<p>[foo<a href="http://example.com?search=%5D%5Bref%5D">http://example.com?searc h=][ref]</a></p> <p>[foo<a href="http://example.com/?search=%5D%5Bref%5D">http://example.com/?sea rch=][ref]</a></p>
. .
匹配时大小写不敏感。 匹配时大小写不敏感。
. .
[foo][BaR] [foo][BaR]
[bar]: /url "title" [bar]: /url "title"
. .
<p><a href="/url" title="title">foo</a></p> <p><a href="/url" title="title">foo</a></p>
跳至第 6215 行更改 跳至第 6330 行更改
. .
. .
[[*foo* bar]] [[*foo* bar]]
[*foo* bar]: /url "title" [*foo* bar]: /url "title"
. .
<p>[<a href="/url" title="title"><em>foo</em> bar</a>]</p> <p>[<a href="/url" title="title"><em>foo</em> bar</a>]</p>
. .
.
[[bar [foo]
[foo]: /url
.
<p>[[bar <a href="/url">foo</a></p>
.
链接标签不区分大小写。 链接标签不区分大小写。
. .
[Foo] [Foo]
[foo]: /url "title" [foo]: /url "title"
. .
<p><a href="/url" title="title">Foo</a></p> <p><a href="/url" title="title">Foo</a></p>
. .
跳至第 6559 行更改 跳至第 6682 行更改
以下是一些有效的自动链接: 以下是一些有效的自动链接:
. .
<http://foo.bar.baz> <http://foo.bar.baz>
. .
<p><a href="http://foo.bar.baz">http://foo.bar.baz</a></p> <p><a href="http://foo.bar.baz">http://foo.bar.baz</a></p>
. .
. .
<http://foo.bar.baz?q=hello&id=22&boolean> <http://foo.bar.baz/test?q=hello&id=22&boolean>
. .
<p><a href="http://foo.bar.baz?q=hello&amp;id=22&amp;boolean">http://foo.bar.baz ?q=hello&amp;id=22&amp;boolean</a></p> <p><a href="http://foo.bar.baz/test?q=hello&amp;id=22&amp;boolean">http://foo.ba r.baz/test?q=hello&amp;id=22&amp;boolean</a></p>
. .
. .
<irc://foo.bar:2233/baz> <irc://foo.bar:2233/baz>
. .
<p><a href="irc://foo.bar:2233/baz">irc://foo.bar:2233/baz</a></p> <p><a href="irc://foo.bar:2233/baz">irc://foo.bar:2233/baz</a></p>
. .
大写字母也可以。 大写字母也可以。
跳至第 6586 行更改 跳至第 6709 行更改
. .
自动链接中不允许出现空格。 自动链接中不允许出现空格。
. .
<http://foo.bar/baz bim> <http://foo.bar/baz bim>
. .
<p>&lt;http://foo.bar/baz bim&gt;</p> <p>&lt;http://foo.bar/baz bim&gt;</p>
. .
反斜杠转义在自动链接内不起作用。
.
<http://example.com/\[\>
.
<p><a href="http://example.com/%5C%5B%5C">http://example.com/\[\</a></p>
.
An [email autolink](@email-autolink) An [email autolink](@email-autolink)
consists of `<`, followed by an [email address], consists of `<`, followed by an [email address],
followed by `>`. The link's label is the email address, followed by `>`. The link's label is the email address,
and the URL is `mailto:` followed by the email address. and the URL is `mailto:` followed by the email address.
An [email address](@email-address), An [email address](@email-address),
for these purposes, is anything that matches for these purposes, is anything that matches
the [non-normative regex from the HTML5 the [non-normative regex from the HTML5
spec](https://html.whatwg.cn/multipage/forms.html#e-mail-state-(type=email )) spec](https://html.whatwg.cn/multipage/forms.html#e-mail-state-(type=email ))
跳至第 6613 行更改 跳至第 6744 行更改
. .
<p><a href="mailto:foo@bar.example.com">foo@bar.example.com</a></p> <p><a href="mailto:foo@bar.example.com">foo@bar.example.com</a></p>
. .
. .
<foo+special@Bar.baz-bar0.com> <foo+special@Bar.baz-bar0.com>
. .
<p><a href="mailto:foo+special@Bar.baz-bar0.com">foo+special@Bar.baz-bar0.com</a ></p> <p><a href="mailto:foo+special@Bar.baz-bar0.com">foo+special@Bar.baz-bar0.com</a ></p>
. .
反斜杠转义在电子邮件自动链接内不起作用。
.
<foo\+@bar.example.com>
.
<p>&lt;foo+@bar.example.com&gt;</p>
.
这些不是自动链接: 这些不是自动链接:
. .
<> <>
. .
<p>&lt;&gt;</p> <p>&lt;&gt;</p>
. .
. .
<heck://bing.bong> <heck://bing.bong>
 更改结束。共 25 个更改块。 
19 行被更改或删除 158 行被更改或添加

此 HTML 差异由 rfcdiff 1.41 生成。最新版本可从 http://tools.ietf.org/tools/rfcdiff/ 获取