spec.txt   spec.txt 
--- ---
标题: CommonMark 规范 标题: CommonMark 规范
作者: John MacFarlane 作者: John MacFarlane
版本: 0.28 版本: 0.29
日期: '2017-08-01' 日期: '2019-04-06'
许可: '[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 是一种用于编写结构化文档的纯文本格式,
based on conventions for indicating formatting in email based on conventions for indicating formatting in email
and usenet posts. It was developed by John Gruber (with and usenet posts. It was developed by John Gruber (with
跳至第 251行更改 跳至第 251行更改
[foo][] [foo][]
``` ```
在没有规范的情况下,早期的实现者参考 `Markdown.pl` 在没有规范的情况下,早期的实现者参考 `Markdown.pl`
来解决这些歧义。但 `Markdown.pl` 错误百出,并且 来解决这些歧义。但 `Markdown.pl` 错误百出,并且
在许多情况下给出了明显错误的结果,因此它不能 在许多情况下给出了明显错误的结果,因此它不能
令人满意地替代规范。 令人满意地替代规范。
由于没有明确的规范,各种实现差异很大。 由于没有明确的规范,各种实现差异很大。
结果,用户常常惊讶地发现 结果,用户常常惊讶地发现
一个文档在一个系统上以某种方式渲染(例如,github wiki) 一个文档在一个系统上以某种方式渲染(例如,GitHub wiki)
在另一个系统上渲染不同(例如,使用 pandoc 转换为 docbook)。 在另一个系统上渲染不同(例如,使用 pandoc 转换为 docbook)。
更糟糕的是,由于 Markdown 中没有任何东西算作“语法错误”, 更糟糕的是,由于 Markdown 中没有任何东西算作“语法错误”,
这种差异往往不会立即被发现。 这种差异往往不会立即被发现。
## 关于本文档 ## 关于本文档
本文档试图明确指定 Markdown 语法。 本文档试图明确指定 Markdown 语法。
它包含许多 Markdown 和 HTML 并排的示例。 它包含许多 Markdown 和 HTML 并排的示例。
这些示例旨在作为一致性测试。一个 这些示例旨在作为一致性测试。一个
配套脚本 `spec_tests.py` 可用于运行测试。 配套脚本 `spec_tests.py` 可用于运行测试。
跳至第 331行更改 跳至第 331行更改
[Unicode whitespace](@) is a sequence of one [Unicode whitespace](@) is a sequence of one
或更多[Unicode 空格字符]。 或更多[Unicode 空格字符]。
A [space](@) is `U+0020`. A [space](@) is `U+0020`.
A [non-whitespace character](@) is any character A [non-whitespace character](@) is any character
[空白字符] 的字符。 [空白字符] 的字符。
An [ASCII punctuation character](@) An [ASCII punctuation character](@)
是 `!`, `"`, `#`, `$`, `%`, `&`, `'`, `(`, `)`, 是 `!`, `"`, `#`, `$`, `%`, `&`, `'`, `(`, `)`,
`*`, `+`, `,`, `-`, `.`, `/`, `:`, `;`, `<`, `=`, `>`, `?`, `@`, ``*``、``+``、``,``、``-``、``.``、``/`` (U+0021–2F)、
``[``、``\``、``]``、``^``、``_``、``` ```、``{``、``|``、``}``,或``~``。 ``:``、``;``、``<``、``=``、``>``、``?``、``@`` (U+003A–0040)、
``[``、``\``、``]``、``^``、``_``、``` ``` (U+005B–0060)、
``{``、``|``、``}``,或``~`` (U+007B–007E)。
A [punctuation character](@) is an [ASCII A [punctuation character](@) is an [ASCII
标点字符] 或任何在 标点字符] 或任何在
the general Unicode categories `Pc`, `Pd`, `Pe`, `Pf`, `Pi`, `Po`, or `Ps`. the general Unicode categories `Pc`, `Pd`, `Pe`, `Pf`, `Pi`, `Po`, or `Ps`.
## 制表符 ## 制表符
Tabs in lines are not expanded to [spaces]. However, Tabs in lines are not expanded to [spaces]. However,
在空格有助于定义块结构的上下文中, 在空格有助于定义块结构的上下文中,
tabs behave as if they were replaced by spaces with a tab stop tabs behave as if they were replaced by spaces with a tab stop
跳至第 514行更改 跳至第 516行更改
paragraphs, headings, and other block constructs can be parsed for inline paragraphs, headings, and other block constructs can be parsed for inline
structure. The second step requires information about link reference structure. The second step requires information about link reference
definitions that will be available only at the end of the first definitions that will be available only at the end of the first
step. Note that the first step requires processing lines in sequence, step. Note that the first step requires processing lines in sequence,
but the second can be parallelized, since the inline parsing of but the second can be parallelized, since the inline parsing of
one block element does not affect the inline parsing of any other. one block element does not affect the inline parsing of any other.
## Container blocks and leaf blocks ## Container blocks and leaf blocks
We can divide blocks into two types We can divide blocks into two types
[容器块](@), [容器块](@),
它们可以包含其他块,以及[叶子块](@), 它们可以包含其他块,以及[叶子块](@),
which cannot. which cannot.
# Leaf blocks # Leaf blocks
This section describes the different kinds of leaf block that make up a This section describes the different kinds of leaf block that make up a
Markdown document. Markdown document.
## Thematic breaks ## Thematic breaks
由0-3个缩进空格组成的行,后跟一个序列 由0-3个缩进空格组成的行,后跟一个序列
of three or more matching `-`, `_`, or `*` characters, each followed of three or more matching `-`, `_`, or `*` characters, each followed
可选地后面跟着任意数量的空格,形成一个 可选地后面跟着任意数量的空格或制表符,形成一个
[thematic break](@). [thematic break](@).
```````````````````````````````` 示例 ```````````````````````````````` 示例
*** ***
--- ---
___ ___
. .
<hr /> <hr />
<hr /> <hr />
<hr /> <hr />
跳至第 801行更改 跳至第 803行更改
```````````````````````````````` ````````````````````````````````
内容按行内元素解析 内容按行内元素解析
```````````````````````````````` 示例 ```````````````````````````````` 示例
# foo *bar* \*baz\* # foo *bar* \*baz\*
. .
<h1>foo <em>bar</em> *baz*</h1> <h1>foo <em>bar</em> *baz*</h1>
```````````````````````````````` ````````````````````````````````
前导和尾随的空白被忽略,在解析内联内容时 前导和尾随的[空白]被忽略,在解析内联内容时
```````````````````````````````` 示例 ```````````````````````````````` 示例
# foo # foo
. .
<h1>foo</h1> <h1>foo</h1>
```````````````````````````````` ````````````````````````````````
允许 1 到 3 个空格的缩进 允许 1 到 3 个空格的缩进
```````````````````````````````` 示例 ```````````````````````````````` 示例
跳至第 986行更改 跳至第 988行更改
```````````````````````````````` 示例 ```````````````````````````````` 示例
Foo *bar Foo *bar
baz* baz*
==== ====
. .
<h1>Foo <em>bar <h1>Foo <em>bar
baz</em></h1> baz</em></h1>
```````````````````````````````` ````````````````````````````````
内容是解析标题的原始内容作为内联的结果。
标题的原始内容是通过连接行并移除开头和结尾的
连接行并移除开头和结尾的
[空白]形成的。
```````````````````````````````` 示例
Foo *bar
baz*→
====
.
<h1>Foo <em>bar
baz</em></h1>
````````````````````````````````
下划线可以是任意长度 下划线可以是任意长度
```````````````````````````````` 示例 ```````````````````````````````` 示例
Foo Foo
------------------------- -------------------------
Foo Foo
= =
. .
<h2>Foo</h2> <h2>Foo</h2>
跳至第 1501行更改 跳至第 1517行更改
## Fenced code blocks ## Fenced code blocks
A [code fence](@) is a sequence A [code fence](@) is a sequence
of at least three consecutive backtick characters (`` ` ``) or of at least three consecutive backtick characters (`` ` ``) or
tildes (`~`). (Tildes and backticks cannot be mixed.) tildes (`~`). (Tildes and backticks cannot be mixed.)
A [fenced code block](@) A [fenced code block](@)
以代码围栏开始,缩进不超过三个空格。 以代码围栏开始,缩进不超过三个空格。
The line with the opening code fence may optionally contain some text The line with the opening code fence may optionally contain some text
following the code fence; this is trimmed of leading and trailing following the code fence; this is trimmed of leading and trailing
空格,并称为[信息字符串](@)。 空白,并称为[信息字符串](@)。如果[信息字符串]出现在
[信息字符串]不能包含任何反引号 反引号围栏之后,它不能包含任何反引号
characters. (The reason for this restriction is that otherwise characters. (The reason for this restriction is that otherwise
some inline code would be incorrectly interpreted as the some inline code would be incorrectly interpreted as the
beginning of a fenced code block.) beginning of a fenced code block.)
The content of the code block consists of all subsequent lines, until The content of the code block consists of all subsequent lines, until
a closing [code fence] of the same type as the code block a closing [code fence] of the same type as the code block
began with (backticks or tildes), and with at least as many backticks began with (backticks or tildes), and with at least as many backticks
or tildes as the opening code fence. If the leading code fence is or tildes as the opening code fence. If the leading code fence is
indented N spaces, then up to N spaces of indentation are removed from indented N spaces, then up to N spaces of indentation are removed from
each line of the content (if present). (If a content line is not each line of the content (if present). (If a content line is not
跳至第 1768行更改 跳至第 1784行更改
``` ```
</code></pre> </code></pre>
```````````````````````````````` ````````````````````````````````
代码围栏(起始和关闭)不能包含内部空格 代码围栏(起始和关闭)不能包含内部空格
```````````````````````````````` 示例 ```````````````````````````````` 示例
``` ``` ``` ```
aaa aaa
. .
<p><code></code> <p><code> </code>
aaa</p> aaa</p>
```````````````````````````````` ````````````````````````````````
```````````````````````````````` 示例 ```````````````````````````````` 示例
~~~~~~ ~~~~~~
aaa aaa
~~~ ~~ ~~~ ~~
. .
<pre><code>aaa <pre><code>aaa
~~~ ~~ ~~~ ~~
跳至第 1816行更改 跳至第 1832行更改
~~~ ~~~
# baz # baz
. .
<h2>foo</h2> <h2>foo</h2>
<pre><code>bar <pre><code>bar
</code></pre> </code></pre>
<h1>baz</h1> <h1>baz</h1>
```````````````````````````````` ````````````````````````````````
在开头代码围栏之后可以提供[信息字符串]。 在开头代码围栏之后可以提供[信息字符串]。
开头和结尾的空格将被移除,第一个单词,前缀为 尽管本规范没有强制规定[信息字符串]的任何特定处理方式,
`language-`,用作其`class`属性的值 第一个单词通常用于指定
代码元素封闭的`pre`元素内。 代码块的语言在HTML输出中,语言通常通过向
`code`元素添加一个`language-`前缀的类来表示,
后跟语言名称。
```````````````````````````````` 示例 ```````````````````````````````` 示例
```ruby ```ruby
def foo(x) def foo(x)
return 3 return 3
end end
``` ```
. .
<pre><code class="language-ruby">def foo(x) <pre><code class="language-ruby">def foo(x)
return 3 return 3
跳至第 1863行更改 跳至第 1881行更改
反引号代码块的[信息字符串]不能包含反引号 反引号代码块的[信息字符串]不能包含反引号
```````````````````````````````` 示例 ```````````````````````````````` 示例
``` aa ``` ``` aa ```
foo foo
. .
<p><code>aa</code> <p><code>aa</code>
foo</p> foo</p>
```````````````````````````````` ````````````````````````````````
波浪号代码块的[信息字符串]可以包含反引号和波浪号
```````````````````````````````` 示例
~~~ aa ``` ~~~
foo
~~~
.
<pre><code class="language-aa">foo
</code></pre>
````````````````````````````````
结束代码围栏不能有[信息字符串] 结束代码围栏不能有[信息字符串]
```````````````````````````````` 示例 ```````````````````````````````` 示例
``` ```
``` aaa ``` aaa
``` ```
. .
<pre><code>``` aaa <pre><code>``` aaa
</code></pre> </code></pre>
```````````````````````````````` ````````````````````````````````
## 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).
共有七种[HTML块],它们可以通过它们的 共有七种[HTML块],它们可以通过它们的起始和结束条件来定义。
起始和结束条件。该块以符合[起始条件](@)的行开始 起始和结束条件。该块以符合[起始条件](@)的行开始
(最多三个空格可选缩进)。它以符合匹配的[结束 (最多三个空格可选缩进)。它以符合匹配的[结束
条件](@)的第一行结束,或者文档的最后一行, 条件](@)的第一行结束,或者文档的最后一行,
或者其他[容器块]的最后一行,如果没有遇到符合 条件](@),或文档的最后一行或[容器块]的最后一行,
文档的最后一行其他[容器块]),如果未遇到满足条件的行 包含当前HTML块的[容器块](#container-blocks),如果未遇到满足[结束条件]的行。
块,如果未遇到满足[结束条件]的行。如果
[结束条件]。如果第一行同时满足[起始条件] 第一行同时满足[起始条件]和[结束
和[结束条件],则该块将只包含该行。 条件],该块将只包含该行。
1. **起始条件:** 行以字符串 `<script`、 1. **起始条件:** 行以字符串 `<script`、
`<pre` 或 `<style`(不区分大小写)开头,后跟空白符、 `<pre` 或 `<style`(不区分大小写)开头,后跟空白符、
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>` 或 `</style>`(不区分大小写;它 `</script>`、`</pre>` 或 `</style>`(不区分大小写;它
need not match the start tag). need not match the start tag).
2. **Start condition:** line begins with the string `<!--`.\ 2. **Start condition:** line begins with the string `<!--`.\
**End condition:** line contains the string `-->`. **End condition:** line contains the string `-->`.
跳至第 1917行更改 跳至第 1947行更改
**结束条件:** 行包含字符串 `]]>`。 **结束条件:** 行包含字符串 `]]>`。
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`, `footer`, `form`, `frame`, `frameset`,
`h1`, `h2`, `h3`, `h4`, `h5`, `h6`, `head`, `header`, `hr`, `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`,
或 [闭合标签](@) (除了 `script`、`style` 或 `pre` 之外的任何 `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`、
`style` 或 `pre`)后仅跟[空白符]。 `style` 或 `pre`)或一个完整的[闭合标签],
All types of [HTML blocks] except type 7 may interrupt 后仅跟[空白符]或行尾。
**结束条件:** 行后紧跟一个 [空行]。 **结束条件:** 行后紧跟一个 [空行]。
HTML blocks continue until they are closed by their appropriate HTML blocks continue until they are closed by their appropriate
[结束条件],或文档或其他[容器块]的最后一行。 [结束条件],或文档或其他[容器
这意味着**HTML块内的**任何HTML,如果它本可以被识别为起始条件, 块](#container-blocks)。这意味着**HTML块内的**任何HTML,如果它本可以被识别为起始条件,
将被解析器忽略并原样传递,而不会改变解析器的状态。 将被解析器忽略并原样传递,而不会改变
解析器的状态。 解析器的状态。
解析器的状态。
For instance, `<pre>` within a HTML block started by `<table>` will not affect For instance, `<pre>` within a HTML block started by `<table>` will not affect
the parser state; as the HTML block was started in by start condition 6, it the parser state; as the HTML block was started in by start condition 6, it
will end at any blank line. This can be surprising will end at any blank line. This can be surprising
```````````````````````````````` 示例 ```````````````````````````````` 示例
<table><tr><td> <table><tr><td>
<pre> <pre>
**Hello**, **Hello**,
跳至第 1957行更改 跳至第 1988行更改
</td></tr></table> </td></tr></table>
. .
<table><tr><td> <table><tr><td>
<pre> <pre>
**Hello**, **Hello**,
<p><em>world</em>. <p><em>world</em>.
</pre></p> </pre></p>
</td></tr></table> </td></tr></table>
```````````````````````````````` ````````````````````````````````
在这种情况下,HTML块由换行符终止——`**hello**` 在这种情况下,HTML块由换行符终止——`**Hello**`
text remains verbatim — and regular parsing resumes, with a paragraph, text remains verbatim — and regular parsing resumes, with a paragraph,
emphasised `world` and inline and block HTML following. emphasised `world` and inline and block HTML following.
除第 7 类之外的所有 [HTML 块] 类型都可以中断 除第 7 类之外的所有 [HTML 块] 类型都可以中断
一个段落。第 7 类块不能中断段落。 一个段落。第 7 类块不能中断段落。
(This restriction is intended to prevent unwanted interpretation (This restriction is intended to prevent unwanted interpretation
进行意外的 HTML 块起始解释。) 进行意外的 HTML 块起始解释。)
下面是一些简单的例子。以下是第 6 类的一些基本 HTML 块 下面是一些简单的例子。以下是第 6 类的一些基本 HTML 块
of type 6 of type 6
跳至第 2462行更改 跳至第 2493行更改
bar bar
</div> </div>
. .
<p>Foo</p> <p>Foo</p>
<div> <div>
bar bar
</div> </div>
```````````````````````````````` ````````````````````````````````
然而,需要一个后续的空行,除了在文档末尾, 然而,需要一个后续的空行,除了在文档末尾,
以及除了上面类型1-5的块: 文档,除了类型1-5的块,[上面][HTML
块]
```````````````````````````````` 示例 ```````````````````````````````` 示例
<div> <div>
bar bar
</div> </div>
*foo* *foo*
. .
<div> <div>
bar bar
</div> </div>
跳至第 2602行更改 跳至第 2634行更改
<pre><code>&lt;td&gt; <pre><code>&lt;td&gt;
Hi Hi
&lt;/td&gt; &lt;/td&gt;
</code></pre> </code></pre>
</tr> </tr>
</table> </table>
```````````````````````````````` ````````````````````````````````
Fortunately, blank lines are usually not necessary and can be Fortunately, blank lines are usually not necessary and can be
deleted. The exception is inside `<pre>` tags, but as described deleted. The exception is inside `<pre>` tags, but as described
以上,以`<pre>`开头的原始HTML块*可以*包含空行。 [上面][HTML 块],以`<pre>`开头的原始HTML块
行。 *可以*包含空行。
## Link reference definitions ## Link reference definitions
A [link reference definition](@) A [link reference definition](@)
由[链接标签]组成,缩进最多三个空格,然后是 由[链接标签]组成,缩进最多三个空格,然后是
by a colon (`:`), optional [whitespace] (including up to one by a colon (`:`), optional [whitespace] (including up to one
[line ending]), a [link destination], [line ending]), a [link destination],
可选的[空白](包括最多一个 可选的[空白](包括最多一个
[line ending]), and an optional [link [line ending]), and an optional [link
title], which if it is present must be separated title], which if it is present must be separated
跳至第 2652行更改 跳至第 2684行更改
```````````````````````````````` 示例 ```````````````````````````````` 示例
[Foo*bar\]]:my_(url) 'title (with parens)' [Foo*bar\]]:my_(url) 'title (with parens)'
[Foo*bar\]] [Foo*bar\]]
. .
<p><a href="my_(url)" title="title (with parens)">Foo*bar]</a></p> <p><a href="my_(url)" title="title (with parens)">Foo*bar]</a></p>
```````````````````````````````` ````````````````````````````````
```````````````````````````````` 示例 ```````````````````````````````` 示例
[Foo bar] [Foo bar]
<my%20url> <my url>
'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>
```````````````````````````````` ````````````````````````````````
标题可以跨越多行 标题可以跨越多行
```````````````````````````````` 示例 ```````````````````````````````` 示例
跳至第 2714行更改 跳至第 2746行更改
```````````````````````````````` 示例 ```````````````````````````````` 示例
[foo] [foo]
[foo] [foo]
. .
<p>[foo]:</p> <p>[foo]:</p>
<p>[foo]</p> <p>[foo]</p>
```````````````````````````````` ````````````````````````````````
然而,可以使用尖括号指定一个空的链接目的地
尖括号
```````````````````````````````` 示例
[foo]: <>
[foo]
.
<p><a href="">foo</a></p>
````````````````````````````````
标题必须与链接目的地通过
whitespace
```````````````````````````````` 示例
[foo]: <bar>(baz)
[foo]
.
<p>[foo]: <bar>(baz)</p>
<p>[foo]</p>
````````````````````````````````
标题和目的地都可以包含反斜杠转义字符 标题和目的地都可以包含反斜杠转义字符
和字面反斜杠 和字面反斜杠
```````````````````````````````` 示例 ```````````````````````````````` 示例
[foo]: /url\bar\*baz "foo\"bar\baz" [foo]: /url\bar\*baz "foo\"bar\baz"
[foo] [foo]
. .
<p><a href="/url%5Cbar*baz" title="foo&quot;bar\baz">foo</a></p> <p><a href="/url%5Cbar*baz" title="foo&quot;bar\baz">foo</a></p>
```````````````````````````````` ````````````````````````````````
跳至第 2858行更改 跳至第 2913行更改
# [Foo] # [Foo]
[foo]: /url [foo]: /url
> bar > bar
. .
<h1><a href="/url">Foo</a></h1> <h1><a href="/url">Foo</a></h1>
<blockquote> <blockquote>
<p>bar</p> <p>bar</p>
</blockquote> </blockquote>
```````````````````````````````` ````````````````````````````````
```````````````````````````````` 示例
[foo]: /url
bar
===
[foo]
.
<h1>bar</h1>
<p><a href="/url">foo</a></p>
````````````````````````````````
```````````````````````````````` 示例
[foo]: /url
===
[foo]
.
<p>===
<a href="/url">foo</a></p>
````````````````````````````````
多个[链接引用定义] 多个[链接引用定义]
可以一个接一个地出现,中间没有空行。 可以一个接一个地出现,中间没有空行。
```````````````````````````````` 示例 ```````````````````````````````` 示例
[foo]: /foo-url "foo" [foo]: /foo-url "foo"
[bar]: /bar-url [bar]: /bar-url
"bar" "bar"
[baz]: /baz-url [baz]: /baz-url
[foo], [foo],
跳至第 2891行更改 跳至第 2965行更改
```````````````````````````````` 示例 ```````````````````````````````` 示例
[foo] [foo]
> [foo]: /url > [foo]: /url
. .
<p><a href="/url">foo</a></p> <p><a href="/url">foo</a></p>
<blockquote> <blockquote>
</blockquote> </blockquote>
```````````````````````````````` ````````````````````````````````
某物是否为[链接引用定义]
独立于其定义的链接引用是否
在文档中使用。因此,例如,以下
文档只包含一个链接引用定义,并且
没有可见内容
```````````````````````````````` 示例
[foo]: /url
.
````````````````````````````````
## Paragraphs ## Paragraphs
A sequence of non-blank lines that cannot be interpreted as other A sequence of non-blank lines that cannot be interpreted as other
kinds of blocks forms a [paragraph](@). kinds of blocks forms a [paragraph](@).
The contents of the paragraph are the result of parsing the The contents of the paragraph are the result of parsing the
paragraph's raw content as inlines. The paragraph's raw content paragraph's raw content as inlines. The paragraph's raw content
is formed by concatenating the lines and removing initial and final is formed by concatenating the lines and removing initial and final
[空白]形成的。 [空白]形成的。
一个有两个段落的简单示例 一个有两个段落的简单示例
跳至第 3013行更改 跳至第 3098行更改
# aaa # aaa
. .
<p>aaa</p> <p>aaa</p>
<h1>aaa</h1> <h1>aaa</h1>
```````````````````````````````` ````````````````````````````````
# 容器块 # 容器块
[容器块]是一种包含其他块的块。 [容器块](#container-blocks)是一种包含其他块的块。
容器块有两种基本类型:[块引用]和[列表项]。 容器块有两种基本类型:[块引用]和[列表项]。
[块引用]和[列表项]。 [块引用]和[列表项]。
[列表]是[列表项]的元容器。 [列表]是[列表项]的元容器。
我们递归地定义容器块的语法。定义的一般形式是: 我们递归地定义容器块的语法。定义的一般形式是:
形式是 形式是
> 如果X是一个块序列,那么X经过这样或那样的转换 > 如果X是一个块序列,那么X经过这样或那样的转换
> 结果是一个Y类型的容器。 > 结果是一个Y类型的容器。
> with these blocks as its content. > with these blocks as its content.
跳至第 3449行更改 跳至第 3534行更改
An [ordered list marker](@) An [ordered list marker](@)
is a sequence of 1--9 arabic digits (`0-9`), followed by either a is a sequence of 1--9 arabic digits (`0-9`), followed by either a
`.` character or a `)` character. (The reason for the length `.` character or a `)` character. (The reason for the length
limit is that with 10 digits we start seeing integer overflows limit is that with 10 digits we start seeing integer overflows
in some browsers.) in some browsers.)
The following rules define [list items] The following rules define [list items]
1. **Basic case.** If a sequence of lines *Ls* constitute a sequence of 1. **Basic case.** If a sequence of lines *Ls* constitute a sequence of
块*Bs*以[非空白字符]开头,并且彼此之间没有被超过一个空行隔开, 块*Bs*以[非空白字符]开头,且*M*是一个
且*M*是一个宽度为*W*的列表标记,后面跟着1 ≤ *N* ≤ 4个空格,那么结果是 列表标记,宽度为*W*,后跟1 ≤ *N* ≤ 4个空格,则结果
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.
例外 例外
1. When the first list item in a [list] interrupts 1. When the first list item in a [list] interrupts
跳至第 3741行更改 跳至第 3825行更改
起始编号不能为负数 起始编号不能为负数
```````````````````````````````` 示例 ```````````````````````````````` 示例
-1. not ok -1. not ok
. .
<p>-1. not ok</p> <p>-1. not ok</p>
```````````````````````````````` ````````````````````````````````
2. **Item starting with indented code.** If a sequence of lines *Ls* 2. **Item starting with indented code.** If a sequence of lines *Ls*
constitute a sequence of blocks *Bs* starting with an indented code constitute a sequence of blocks *Bs* starting with an indented code
块,且彼此之间没有被超过一个空行隔开, 且*M*是一个宽度为*W*的列表标记,后跟
且*M*是一个宽度为*W*的列表标记,后跟
一个空格,则预置*M*和其后的 一个空格,则预置*M*和其后的
space to the first line of *Ls*, and indenting subsequent lines of space to the first line of *Ls*, and indenting subsequent lines of
*Ls* by *W + 1* spaces, is a list item with *Bs* as its contents. *Ls* by *W + 1* spaces, is a list item with *Bs* as its contents.
If a line is empty, then it need not be indented. The type of the 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 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 marker. If the list item is ordered, then it is also assigned a
start number, based on the ordered list marker. start number, based on the ordered list marker.
一个缩进的代码块需要比段落多缩进四个空格。 一个缩进的代码块需要比段落多缩进四个空格。
the edge of the region where text will be included in the list item. the edge of the region where text will be included in the list item.
跳至第 4194行更改 跳至第 4277行更改
在此处继续。</p> 在此处继续。</p>
</blockquote> </blockquote>
</li> </li>
</ol> </ol>
</blockquote> </blockquote>
```````````````````````````````` ````````````````````````````````
6. **That's all.** Nothing that is not counted as a list item by rules 6. **That's all.** Nothing that is not counted as a list item by rules
#1--5 counts as a [list item](#list-items). #1--5 counts as a [list item](#list-items).
子列表的规则遵循上述一般规则。子列表 子列表的规则遵循上述一般规则。
必须缩进与段落相同的空格数,以便包含在列表项中。 [上面][列表项]。子列表必须缩进相同的空格数,
以便包含在列表项中。 以便包含在列表项中。
以便包含在列表项中。
因此,在这种情况下我们需要两个空格的缩进 因此,在这种情况下我们需要两个空格的缩进
```````````````````````````````` 示例 ```````````````````````````````` 示例
- foo - foo
- bar - bar
- baz - baz
- boo - boo
. .
<ul> <ul>
跳至第 4771行更改 跳至第 4855行更改
列表项不需要缩进到相同的级别。以下 列表项不需要缩进到相同的级别。以下
列表项将被视为同一列表级别的项目, 列表项将被视为同一列表级别的项目,
因为没有一个缩进足够深以属于前一个列表 因为没有一个缩进足够深以属于前一个列表
item item
```````````````````````````````` 示例 ```````````````````````````````` 示例
- a - a
- b - b
- c - c
- d - d
- e - e
- f - f
- g - g
- h
- i
. .
g
<ul> <ul>
<li>a</li> <li>a</li>
<li>b</li> <li>b</li>
<li>c</li> <li>c</li>
<li>d</li> <li>d</li>
<li>e</li> <li>e</li>
<li>f</li> <li>f</li>
<li>g</li> <li>g</li>
<li>h</li>
<li>i</li>
</ul> </ul>
```````````````````````````````` ````````````````````````````````
```````````````````````````````` 示例 ```````````````````````````````` 示例
1. a 1. a
2. b 2. b
3. c 3. c
. .
<ol> <ol>
<li> <li>
<p>a</p> <p>a</p>
</li> </li>
<li> <li>
<p>b</p> <p>b</p>
</li> </li>
<li> <li>
<p>c</p> <p>c</p>
</li> </li>
</ol> </ol>
```````````````````````````````` ````````````````````````````````
但是请注意,列表项的缩进不能超过
三个空格。这里“- e”被视为段落续行,
因为它缩进了超过三个空格。
```````````````````````````````` 示例
- a
- b
- c
- d
- e
.
<ul>
<li>a</li>
<li>b</li>
<li>c</li>
<li>d
- e</li>
</ul>
````````````````````````````````
而这里,“3. c”被视为缩进代码块,
因为它缩进了四个空格,前面有一个
空行。
```````````````````````````````` 示例
1. a
2. b
3. c
.
<ol>
<li>
<p>a</p>
</li>
<li>
<p>b</p>
</li>
</ol>
<pre><code>3. c
</code></pre>
````````````````````````````````
这是一个松散的列表,因为在两个列表项之间有一个空行 这是一个松散的列表,因为在两个列表项之间有一个空行
两个列表项 两个列表项
```````````````````````````````` 示例 ```````````````````````````````` 示例
- a - a
- b - b
- c - c
. .
<ul> <ul>
跳至第 5117行更改 跳至第 5240行更改
```````````````````````````````` 示例 ```````````````````````````````` 示例
\*not emphasized* \*not emphasized*
\<br/> not a tag \<br/> not a tag
\[not a link](/foo) \[not a link](/foo)
\`not code` \`not code`
1\. not a list 1\. not a list
\* not a list \* not a list
\# not a heading \# not a heading
\[foo]: /url "not a reference" \[foo]: /url "not a reference"
\&ouml; 不是字符实体
. .
<p>*not emphasized* <p>*not emphasized*
&lt;br/&gt; not a tag &lt;br/&gt; not a tag
[not a link](/foo) [not a link](/foo)
`not code` `not code`
1. not a list 1. not a list
* not a list * not a list
# not a heading # not a heading
[foo]: /url &quot;不是一个引用&quot;</p> [foo]: /url &quot;不是一个引用&quot;
&amp;ouml; 不是字符实体</p>
```````````````````````````````` ````````````````````````````````
如果反斜杠本身被转义,则随后的字符不被转义 如果反斜杠本身被转义,则随后的字符不被转义
```````````````````````````````` 示例 ```````````````````````````````` 示例
\\*emphasis* \\*emphasis*
. .
<p>\<em>emphasis</em></p> <p>\<em>emphasis</em></p>
```````````````````````````````` ````````````````````````````````
跳至第 5211行更改 跳至第 5336行更改
``` foo\+bar ``` foo\+bar
foo foo
``` ```
. .
<pre><code class="language-foo+bar">foo <pre><code class="language-foo+bar">foo
</code></pre> </code></pre>
```````````````````````````````` ````````````````````````````````
## Entity and numeric character references ## Entity and numeric character references
所有有效的HTML实体引用和数字字符 有效的HTML实体引用和数字字符引用
引用,除了在代码块和代码跨度中出现的, 可以用来代替对应的Unicode字符,
被识别并视为等同于 但有以下例外:
对应的Unicode字符。符合CommonMark的解析器
不需要存储关于某个特定字符的信息, - 实体和字符引用在代码块和代码跨度中
是在源中使用Unicode字符表示还是 不被识别。
实体引用表示。
- 实体字符引用不能替代
CommonMark中定义结构元素的特殊字符。
例如,尽管`&#42;`可以用于
代替字面字符`*`,但`&#42;`不能替代
强调分隔符、项目符号列表标记或主题
中断中的`*`。
符合CommonMark的解析器不需要存储关于
某个特定字符在源中是以Unicode字符表示
还是以实体引用表示的信息。
[Entity references](@) consist of `&` + any of the valid [Entity references](@) consist of `&` + any of the valid
[以下文档](https://html.whatwg.cn/multipage/entities.json) [以下文档](https://html.whatwg.cn/multipage/entities.json)
document <https://html.whatwg.cn/multipage/entities.json> document <https://html.whatwg.cn/multipage/entities.json>
is used as an authoritative source for the valid entity is used as an authoritative source for the valid entity
references and their corresponding code points. references and their corresponding code points.
```````````````````````````````` 示例 ```````````````````````````````` 示例
&nbsp; &amp; &copy; &AElig; &Dcaron; &nbsp; &amp; &copy; &AElig; &Dcaron;
&frac34; &HilbertSpace; &DifferentialD; &frac34; &HilbertSpace; &DifferentialD;
&ClockwiseContourIntegral; &ngE; &ClockwiseContourIntegral; &ngE;
. .
<p>  &amp; © Æ Ď <p>  &amp; © Æ Ď
¾ ℋ ⅆ ¾ ℋ ⅆ
∲ ≧̸</p> ∲ ≧̸</p>
```````````````````````````````` ````````````````````````````````
[Decimal numeric character [Decimal numeric character
references](@) references](@)
由`&#` + 1--8个阿拉伯数字字符串 + `;`组成。一个 由`&#` + 1--7个阿拉伯数字字符串 + `;`组成。一个
numeric character reference is parsed as the corresponding numeric character reference is parsed as the corresponding
Unicode character. Invalid Unicode code points will be replaced by Unicode character. Invalid Unicode code points will be replaced by
REPLACEMENT CHARACTER (`U+FFFD`)。出于安全考虑, REPLACEMENT CHARACTER (`U+FFFD`)。出于安全考虑,
the code point `U+0000` will also be replaced by `U+FFFD`. the code point `U+0000` will also be replaced by `U+FFFD`.
```````````````````````````````` 示例 ```````````````````````````````` 示例
&#35; &#1234; &#992; &#98765432; &#0; &#35; &#1234; &#992; &#0;
. .
<p># Ӓ Ϡ �</p> <p># Ӓ Ϡ �</p>
```````````````````````````````` ````````````````````````````````
[Hexadecimal numeric character [Hexadecimal numeric character
references](@) consist of `&#` + references](@) consist of `&#` +
要么`X`或`x` + 1-8个十六进制数字字符串 + `;`。 要么`X`或`x` + 1-6个十六进制数字字符串 + `;`。
They too are parsed as the corresponding Unicode character (this They too are parsed as the corresponding Unicode character (this
time specified with a hexadecimal numeral instead of decimal). time specified with a hexadecimal numeral instead of decimal).
```````````````````````````````` 示例 ```````````````````````````````` 示例
&#X22; &#XD06; &#xcab; &#X22; &#XD06; &#xcab;
. .
<p>&quot; ആ ಫ</p> <p>&quot; ആ ಫ</p>
```````````````````````````````` ````````````````````````````````
这里是一些非实体引用 这里是一些非实体引用
```````````````````````````````` 示例 ```````````````````````````````` 示例
&nbsp &x; &#; &#x; &nbsp &x; &#; &#x;
&#987654321;
&#abcdef0;
&ThisIsNotDefined; &hi?; &ThisIsNotDefined; &hi?;
. .
<p>&amp;nbsp &amp;x; &amp;#; &amp;#x; <p>&amp;nbsp &amp;x; &amp;#; &amp;#x;
&amp;#987654321;
&amp;#abcdef0;
&amp;ThisIsNotDefined; &amp;hi?;</p> &amp;ThisIsNotDefined; &amp;hi?;</p>
```````````````````````````````` ````````````````````````````````
Although HTML5 does accept some entity references Although HTML5 does accept some entity references
without a trailing semicolon (such as `&copy`), these are not without a trailing semicolon (such as `&copy`), these are not
recognized here, because it makes the grammar too ambiguous recognized here, because it makes the grammar too ambiguous
```````````````````````````````` 示例 ```````````````````````````````` 示例
&copy &copy
. .
跳至第 5339行更改 跳至第 5478行更改
<p><code>f&amp;ouml;&amp;ouml;</code></p> <p><code>f&amp;ouml;&amp;ouml;</code></p>
```````````````````````````````` ````````````````````````````````
```````````````````````````````` 示例 ```````````````````````````````` 示例
f&ouml;f&ouml; f&ouml;f&ouml;
. .
<pre><code>f&amp;ouml;f&amp;ouml; <pre><code>f&amp;ouml;f&amp;ouml;
</code></pre> </code></pre>
```````````````````````````````` ````````````````````````````````
实体和数字字符引用不能用于
代替CommonMark文档中的结构符号。
文档。
```````````````````````````````` 示例
&#42;foo&#42;
*foo*
.
<p>*foo*
<em>foo</em></p>
````````````````````````````````
```````````````````````````````` 示例
&#42; foo
* foo
.
<p>* foo</p>
<ul>
<li>foo</li>
</ul>
````````````````````````````````
```````````````````````````````` 示例
foo&#10;&#10;bar
.
<p>foo
bar</p>
````````````````````````````````
```````````````````````````````` 示例
&#9;foo
.
<p>→foo</p>
````````````````````````````````
```````````````````````````````` 示例
[a](url &quot;tit&quot;)
.
<p>[a](url &quot;tit&quot;)</p>
````````````````````````````````
## Code spans ## Code spans
A [backtick string](@) A [backtick string](@)
is a string of one or more backtick characters (`` ` ``) that is neither is a string of one or more backtick characters (`` ` ``) that is neither
preceded nor followed by a backtick. preceded nor followed by a backtick.
A [code span](@) begins with a backtick string and ends with A [code span](@) begins with a backtick string and ends with
a backtick string of equal length. The contents of the code span are a backtick string of equal length. The contents of the code span are
两个反引号字符串之间的字符,前导和 两个反引号字符串之间的字符,以以下方式标准化:
尾随空格和[换行符]被移除,以及 以下方式
[空白]折叠为单个空格。
- 首先,[换行符]被转换为[空格]
- 如果结果字符串同时以[空格]字符开头和结尾,
但并非完全由[空格]
字符组成,则会从开头和结尾移除一个[空格]字符。
前端和后端。这允许您包含以
反引号字符开头或结尾的代码,这些字符必须与
开头或结尾的反引号字符串通过空白符分隔。
这是一个简单的代码跨度 这是一个简单的代码跨度
```````````````````````````````` 示例 ```````````````````````````````` 示例
`foo` `foo`
. .
<p><code>foo</code></p> <p><code>foo</code></p>
```````````````````````````````` ````````````````````````````````
这里使用了两个反引号,因为代码包含一个反引号。 这里使用了两个反引号,因为代码包含一个反引号。
此示例还演示了前导和尾随空格的剥离: 此示例还演示了剥离一个前导和
尾随空格:
```````````````````````````````` 示例 ```````````````````````````````` 示例
`` foo ` bar `` `` foo ` bar ``
. .
<p><code>foo ` bar</code></p> <p><code>foo ` bar</code></p>
```````````````````````````````` ````````````````````````````````
此示例展示了剥离前导和尾随空格的动机。 此示例展示了剥离前导和尾随空格的动机。
空格 空格
```````````````````````````````` 示例 ```````````````````````````````` 示例
` `` ` ` `` `
. .
<p><code>``</code></p> <p><code>``</code></p>
```````````````````````````````` ````````````````````````````````
[换行符]被视为空格。: 请注意,只剥离*一个*空格。:
```````````````````````````````` 示例 ```````````````````````````````` 示例
`` ` `` `
foo
``
. .
<p><code>foo</code></p> <p><code> `` </code></p>
```````````````````````````````` ````````````````````````````````
内部空格和[换行符]被折叠成 剥离只发生在空格位于
单个空格,就像浏览器会做的那样。 字符串两边
```````````````````````````````` 示例 ```````````````````````````````` 示例
`foo bar ` a`
baz`
. .
<p><code>foo bar baz</code></p> <p><code> a</code></p>
```````````````````````````````` ````````````````````````````````
不是所有[Unicode空格](例如,非断行空格)都 只有[空格],而不是一般的[Unicode空格],被
折叠,然而 以这种方式剥离
```````````````````````````````` 示例 ```````````````````````````````` 示例
`a  b` ` b `
. .
<p><code>a  b</code></p> <p><code> b </code></p>
```````````````````````````````` ````````````````````````````````
问:为什么不直接保留空格,因为浏览器反正会折叠它们 如果代码跨度只包含空格,则不进行剥离:
呢?答:因为我们可能针对的是非HTML格式,我们
不应依赖于HTML特定的渲染假设。
(现有实现对内部空格和[换行符]的处理方式各不相同。 ```````````````````````````````` 示例
有些,包括`Markdown.pl`和`showdown`,会将内部 ` `
[换行符]转换为`<br />`标签。 ` `
`<br />`标签。但这使得那些喜欢硬换行段落的人感到困难, .
因为代码跨度中的换行符会导致输出中出现意外的换行符。 <p><code> </code>
其他则保持内部空格不变,这在只针对HTML时是可以的。 <code> </code></p>
目标。) ````````````````````````````````
目标。)
[换行符]被视为空格:
```````````````````````````````` 示例 ```````````````````````````````` 示例
`foo `` bar` ``
foo
bar
baz
``
. .
<p><code>foo `` bar</code></p> <p><code>foo bar baz</code></p>
```````````````````````````````` ````````````````````````````````
```````````````````````````````` 示例
``
foo
``
.
<p><code>foo </code></p>
````````````````````````````````
内部空格不会折叠
```````````````````````````````` 示例
`foo bar
baz`
.
<p><code>foo bar baz</code></p>
````````````````````````````````
请注意,浏览器在渲染`<code>`元素时通常会折叠连续的空格,
因此建议使用以下CSS:
因此建议使用以下CSS:
code{white-space: pre-wrap;}
请注意,反斜杠转义在代码跨度中不起作用。所有反斜杠 请注意,反斜杠转义在代码跨度中不起作用。所有反斜杠
都被视为字面量。 都被视为字面量。
```````````````````````````````` 示例 ```````````````````````````````` 示例
`foo\`bar` `foo\`bar`
. .
<p><code>foo\</code>bar`</p> <p><code>foo\</code>bar`</p>
```````````````````````````````` ````````````````````````````````
反斜杠转义永远不需要,因为总是可以选择一个由*n*个反引号字符组成的字符串作为分隔符, 反斜杠转义永远不需要,因为总是可以选择一个由*n*个反引号字符组成的字符串作为分隔符,
其中代码不包含任何恰好由*n*个反引号字符组成的字符串。 其中代码不包含任何恰好由*n*个反引号字符组成的字符串。
其中代码不包含任何恰好由*n*个反引号字符组成的字符串。 其中代码不包含任何恰好由*n*个反引号字符组成的字符串。
```````````````````````````````` 示例
``foo`bar``
.
<p><code>foo`bar</code></p>
````````````````````````````````
```````````````````````````````` 示例
` foo `` bar `
.
<p><code>foo `` bar</code></p>
````````````````````````````````
代码跨度反引号的优先级高于除HTML标签和自动链接之外的任何其他内联结构。 代码跨度反引号的优先级高于除HTML标签和自动链接之外的任何其他内联结构。
因此,例如,这不会被解析为强调文本,因为第二个`*`是代码跨度的一部分。 因此,例如,这不会被解析为强调文本,因为第二个`*`是代码跨度的一部分。
不是解析为强调文本,因为第二个`*`是代码 不是解析为强调文本,因为第二个`*`是代码
span span
```````````````````````````````` 示例 ```````````````````````````````` 示例
*foo`*` *foo`*`
. .
<p>*foo<code>*</code></p> <p>*foo<code>*</code></p>
```````````````````````````````` ````````````````````````````````
跳至第 5567行更改 跳至第 5792行更改
下面给出的规则涵盖了所有这些模式,同时允许 下面给出的规则涵盖了所有这些模式,同时允许
使用不需要回溯的高效解析策略。 使用不需要回溯的高效解析策略。
First, some definitions. A [delimiter run](@) is either First, some definitions. A [delimiter run](@) is either
一个或多个 `*` 字符组成的序列,且其前后没有 一个或多个 `*` 字符组成的序列,且其前后没有
后面跟着一个未被反斜杠转义的`*`字符,或者一个序列 后面跟着一个未被反斜杠转义的`*`字符,或者一个序列
of one or more `_` characters that is not preceded or followed by of one or more `_` characters that is not preceded or followed by
a non-backslash-escaped `_` character. a non-backslash-escaped `_` character.
A [left-flanking delimiter run](@) is A [left-flanking delimiter run](@) is
一个[分隔符运行]满足(a)后面没有[Unicode 空格], 一个[分隔符运行]满足(1)后面没有[Unicode 空格],
(b)后面没有[标点符号],或 (2a)后面没有[标点符号],或
(2b)后面有[标点符号]且
preceded by [Unicode whitespace] or a [punctuation character]. preceded by [Unicode whitespace] or a [punctuation character].
就此定义而言,行的开头和结尾 就此定义而言,行的开头和结尾
the line count as Unicode whitespace. the line count as Unicode whitespace.
A [right-flanking delimiter run](@) is A [right-flanking delimiter run](@) is
一个[分隔符运行]满足(a)前面没有[Unicode 空格], 一个[分隔符运行]满足(1)前面没有[Unicode 空格],
(b)前面没有[标点符号],或 (2a)前面没有[标点符号],或
(2b)前面有[标点符号]且
followed by [Unicode whitespace] or a [punctuation character]. followed by [Unicode whitespace] or a [punctuation character].
就此定义而言,行的开头和结尾 就此定义而言,行的开头和结尾
the line count as Unicode whitespace. the line count as Unicode whitespace.
以下是一些定界符序列的示例。 以下是一些定界符序列的示例。
- 左侧分隔但非右侧分隔 - 左侧分隔但非右侧分隔
``` ```
***abc ***abc
跳至第 5667行更改 跳至第 5894行更改
or (b) part of a [left-flanking delimiter run] or (b) part of a [left-flanking delimiter run]
followed by punctuation. followed by punctuation.
9. 强调以一个 [可以开启强调] 的定界符开始,并以 9. 强调以一个 [可以开启强调] 的定界符开始,并以
一个 [可以关闭强调] 的定界符结束,且使用相同的 一个 [可以关闭强调] 的定界符结束,且使用相同的
character (`_` or `*`) as the opening delimiter. The character (`_` or `*`) as the opening delimiter. The
opening and closing delimiters must belong to separate opening and closing delimiters must belong to separate
[delimiter runs]. If one of the delimiters can both [delimiter runs]. If one of the delimiters can both
打开和关闭强调,则包含打开和关闭分隔符的 打开和关闭强调,则包含打开和关闭分隔符的
分隔符运行的长度之和 分隔符运行的长度之和
必须不是3的倍数。 必须不是3的倍数,除非两个长度都是3的倍数。
倍数。 3.
10. 强强调以一个 10. 强强调以一个
[可以开启强强调] 的定界符开始,并以一个定界符结束 [可以开启强强调] 的定界符开始,并以一个定界符结束
[可以关闭强强调],并且使用与打开分隔符相同的字符 [可以关闭强强调],并且使用与打开分隔符相同的字符
(`_` 或 `*`)。该 (`_` 或 `*`)。该
opening and closing delimiters must belong to separate opening and closing delimiters must belong to separate
[分隔符运行]。如果其中一个分隔符既可以打开 [分隔符运行]。如果其中一个分隔符既可以打开
又可以关闭强强调,则包含打开和关闭 又可以关闭强强调,则包含打开和关闭
分隔符的[分隔符运行]的长度之和 分隔符的[分隔符运行]的长度之和
必须不是3的倍数。 分隔符必须不是3的倍数,除非两个长度
都是3的倍数。 3.
11. 字面量`*`字符不能出现在`*`分隔符强调或`**`分隔符强强调的开头或结尾, 11. 字面量`*`字符不能出现在`*`分隔符强调或`**`分隔符强强调的开头或结尾,
除非它 除非它
is backslash-escaped. is backslash-escaped.
12. 字面量`_`字符不能出现在`_`分隔符强调或`__`分隔符强强调的开头或结尾, 12. 字面量`_`字符不能出现在`_`分隔符强调或`__`分隔符强强调的开头或结尾,
`_`-delimited emphasis or `__`-delimited strong emphasis, unless it `_`-delimited emphasis or `__`-delimited strong emphasis, unless it
is backslash-escaped. is backslash-escaped.
Where rules 1--12 above are compatible with multiple parsings, Where rules 1--12 above are compatible with multiple parsings,
跳至第 6234行更改 跳至第 6463行更改
注意,在上述情况中,这种解释被以下条件所排除:如果一个既能作为开头又能作为结尾的分隔符(例如 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>
``` ```
被一个条件阻止,即一个可以同时打开和关闭的分隔符 被一个条件阻止,即一个可以同时打开和关闭的分隔符
(像`foo`后面的`*`) (像`foo`后面的`*`)
不能形成强调,如果包含打开和 不能形成强调,如果包含打开和
关闭分隔符的分隔符运行的长度之和 关闭分隔符的分隔符运行的长度之和
是3的倍数。 关闭分隔符的长度之和是3的倍数,除非
两个长度都是3的倍数。 3.
出于同样的原因,在此示例中我们没有得到两个连续的
强调部分。
```````````````````````````````` 示例
*foo**bar*
.
<p><em>foo**bar</em></p>
````````````````````````````````
相同的条件确保以下 相同的条件确保以下
情况都是强调内部嵌套的强强调, 情况都是强调内部嵌套的强强调,
即使省略了内部空格也是如此。 即使省略了内部空格也是如此。
省略了 省略了
```````````````````````````````` 示例 ```````````````````````````````` 示例
***foo** bar* ***foo** bar*
. .
<p><em><strong>foo</strong> bar</em></p> <p><em><strong>foo</strong> bar</em></p>
跳至第 6259行更改 跳至第 6498行更改
. .
<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>
```````````````````````````````` ````````````````````````````````
当内部的关闭和打开
分隔符运行的长度*都*是3的倍数时,
它们可以匹配以创建强调。
```````````````````````````````` 示例
foo***bar***baz
.
<p>foo<em><strong>bar</strong></em>baz</p>
````````````````````````````````
```````````````````````````````` 示例
foo******bar*********baz
.
<p>foo<strong><strong><strong>bar</strong></strong></strong>***baz</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)*
跳至第 6725行更改 跳至第 6980行更改
比链接文本中的方括号更紧密。因此,例如, 比链接文本中的方括号更紧密。因此,例如,
`` [foo`]` ``不能作为链接文本,因为第二个`]` `` [foo`]` ``不能作为链接文本,因为第二个`]`
是代码跨度的一部分。 是代码跨度的一部分。
- 链接文本中的括号比[强调和强强调]的标记绑定更紧密。 - 链接文本中的括号比[强调和强强调]的标记绑定更紧密。
因此,例如,`*[foo*](url)`是一个链接。 因此,例如,`*[foo*](url)`是一个链接。
A [link destination](@) consists of either A [link destination](@) consists of either
- a sequence of zero or more characters between an opening `<` and a - a sequence of zero or more characters between an opening `<` and a
结束的`>`,其中不包含空格、换行符或未转义的字符。 结束的`>`,其中不包含换行符或未转义的字符。
`<` or `>` characters, or `<` or `>` characters, or
- a nonempty sequence of characters that does not include - 一个非空字符序列,不以`<`开头,不包含ASCII空格或控制字符,
ASCII space or control characters, and includes parentheses 不包含ASCII空格或控制字符,
only if (a) they are backslash-escaped or (b) they are part of 并且只有在(a)它们被反斜杠转义或
一对平衡的未转义括号。(实现可能会 (b)它们是一对平衡的未转义括号的一部分。
施加括号嵌套限制以避免性能 (实现可能会施加括号嵌套限制以
问题,但应支持至少三级嵌套。) 避免性能问题,但至少应支持三级嵌套。)
应支持。)
A [link title](@) consists of either A [link title](@) consists of either
- a sequence of zero or more characters between straight double-quote - a sequence of zero or more characters between straight double-quote
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
- 匹配括号(`(...)`)之间的一个或多个字符序列, - 匹配括号(`(...)`)之间的一个或多个字符序列,
其中`)`字符只在被反斜杠转义时才包含。 (`(...)`),其中`(`或`)`字符只有在被
反斜杠转义时才包含。
尽管[链接标题]可以跨越多行,但它们不能包含 尽管[链接标题]可以跨越多行,但它们不能包含
[空行]。 [空行]。
[内联链接](@)由[链接文本]紧接着一个左括号`(`、 [内联链接](@)由[链接文本]紧接着一个左括号`(`、
可选的[空白]、可选的[链接目的地]、可选的[链接标题]组成, 可选的[空白]、可选的[链接目的地]、可选的[链接标题]组成,
由[空白]与链接目的地分隔,可选的[空白],以及一个右括号`)`。 由[空白]与链接目的地分隔,可选的[空白],以及一个右括号`)`。
链接的文本由[链接文本]中包含的内联内容组成 链接的文本由[链接文本]中包含的内联内容组成
链接的文本由[链接文本]中包含的内联内容组成 链接的文本由[链接文本]中包含的内联内容组成
(不包括封闭的方括号)。 (不包括封闭的方括号)。
跳至第 6793行更改 跳至第 7050行更改
. .
<p><a href="">链接</a></p> <p><a href="">链接</a></p>
```````````````````````````````` ````````````````````````````````
```````````````````````````````` 示例 ```````````````````````````````` 示例
[链接](<>) [链接](<>)
. .
<p><a href="">链接</a></p> <p><a href="">链接</a></p>
```````````````````````````````` ````````````````````````````````
目的地不能包含空格或换行符, 目的地只能包含空格,如果
即使被尖括号包围。 用尖括号括起来。
```````````````````````````````` 示例 ```````````````````````````````` 示例
[链接](/我的 URI) [链接](/我的 URI)
. .
<p>[链接](/我的 URI)</p> <p>[链接](/我的 URI)</p>
```````````````````````````````` ````````````````````````````````
```````````````````````````````` 示例 ```````````````````````````````` 示例
[链接](</我的 URI>) [链接](</我的 URI>)
. .
<p>[链接](&lt;/我的 URI&gt;)</p> <p><a href="/my%20uri">link</a></p>
```````````````````````````````` ````````````````````````````````
目的地不能包含换行符,
即使被尖括号包围。
```````````````````````````````` 示例 ```````````````````````````````` 示例
[link](foo [link](foo
bar) bar)
. .
<p>[link](foo <p>[link](foo
bar)</p> bar)</p>
```````````````````````````````` ````````````````````````````````
```````````````````````````````` 示例 ```````````````````````````````` 示例
[link](<foo [link](<foo
bar>) bar>)
. .
<p>[link](<foo <p>[link](<foo
bar>)</p> bar>)</p>
```````````````````````````````` ````````````````````````````````
目的地可以包含`)`,如果它被
尖括号括起来。
```````````````````````````````` 示例
[a](<b)c>)
.
<p><a href="b)c">a</a></p>
````````````````````````````````
括起链接的尖括号必须是非转义的
```````````````````````````````` 示例
[链接](<foo\>)
.
<p>[链接](&lt;foo&gt;)</p>
````````````````````````````````
这些不是链接,因为开头尖括号
没有正确匹配。
```````````````````````````````` 示例
[a](<b)c
[a](<b)c>
[a](<b>c)
.
<p>[a](&lt;b)c
[a](&lt;b)c&gt;
[a](<b>c)</p>
````````````````````````````````
链接目标内的圆括号可以进行转义 链接目标内的圆括号可以进行转义
```````````````````````````````` 示例 ```````````````````````````````` 示例
[link](\(foo\)) [link](\(foo\))
. .
<p><a href="(foo)">link</a></p> <p><a href="(foo)">link</a></p>
```````````````````````````````` ````````````````````````````````
只要平衡,允许任意数量的括号而不进行转义。 只要平衡,允许任意数量的括号而不进行转义。
平衡 平衡
跳至第 7837行更改 跳至第 8127行更改
<p>!<a href="/url" title="title">foo</a></p> <p>!<a href="/url" title="title">foo</a></p>
```````````````````````````````` ````````````````````````````````
## 自动链接 ## 自动链接
[自动链接](@)是包含在`<`和`>`中的绝对URI和电子邮件地址。 [自动链接](@)是包含在`<`和`>`中的绝对URI和电子邮件地址。
它们被解析为链接,其中URL或电子邮件地址作为链接标签。 它们被解析为链接,其中URL或电子邮件地址作为链接标签。
作为链接标签。 作为链接标签。
[URI自动链接](@)由`<`开头,后跟一个[绝对URI] [URI自动链接](@)由`<`开头,后跟一个[绝对URI]
不包含`<`,后跟`>`。它被解析为 [绝对URI],后跟`>`。它被解析为
一个指向URI的链接,以URI作为链接的标签。 一个指向URI的链接,以URI作为链接的标签。
[绝对URI](@), [绝对URI](@),
就这些目的而言,由[方案]后跟冒号(`:`)组成, 就这些目的而言,由[方案]后跟冒号(`:`)组成,
后跟零个或多个除ASCII[空白]和控制字符、 后跟零个或多个除ASCII[空白]和控制字符、
`<`和`>`之外的字符。 `<`和`>`之外的字符。
如果URI包含这些字符,它们必须进行百分比编码 如果URI包含这些字符,它们必须进行百分比编码
(例如,空格为`%20`)。 (例如,空格为`%20`)。
就本规范而言,[方案](@)是任何序列 就本规范而言,[方案](@)是任何序列
跳至第 8031行更改 跳至第 8321行更改
由可选的[空白]、 由可选的[空白]、
一个`=`字符、可选的[空白]和一个[属性值]组成。 一个`=`字符、可选的[空白]和一个[属性值]组成。
值]。 值]。
[属性值](@) [属性值](@)
由[未加引号的属性值]、 由[未加引号的属性值]、
[单引号属性值]或[双引号属性值]组成。 [单引号属性值]或[双引号属性值]组成。
[未加引号的属性值](@) [未加引号的属性值](@)
是非空字符串, 是非空字符串,
不包含空格、`"`、`'`、`=`、`<`、`>` 或 ``` ` ```。 不包含[空白]、`"`、`'`、`=`、`<`、`>` 或 ``` ` ```。
[单引号属性值](@) [单引号属性值](@)
由`'`、零个或多个 由`'`、零个或多个
不包含`'`的字符,以及一个最终的`'`组成。 不包含`'`的字符,以及一个最终的`'`组成。
[双引号属性值](@) [双引号属性值](@)
由`"`、零个或多个 由`"`、零个或多个
不包含`"`的字符,以及一个最终的`"`组成。 不包含`"`的字符,以及一个最终的`"`组成。
[开放标签](@)由`<`字符、[标签名]组成, [开放标签](@)由`<`字符、[标签名]组成,
跳至第 8144行更改 跳至第 8434行更改
<a href="hi'> <a href=hi'> <a href="hi'> <a href=hi'>
. .
<p>&lt;a href=&quot;hi'&gt; &lt;a href=hi'&gt;</p> <p>&lt;a href=&quot;hi'&gt; &lt;a href=hi'&gt;</p>
```````````````````````````````` ````````````````````````````````
非法[空白] 非法[空白]
```````````````````````````````` 示例 ```````````````````````````````` 示例
< a>< < a><
foo><bar/ > foo><bar/ >
<foo bar=baz
bim!bop />
. .
<p>&lt; a&gt;&lt; <p>&lt; a&gt;&lt;
foo&gt;&lt;bar/ &gt;</p> foo&gt;&lt;bar/ &gt;
&lt;foo bar=baz
bim!bop /&gt;</p>
```````````````````````````````` ````````````````````````````````
缺少[空白] 缺少[空白]
```````````````````````````````` 示例 ```````````````````````````````` 示例
<a href='bar'title=title> <a href='bar'title=title>
. .
<p>&lt;a href='bar'title=title&gt;</p> <p>&lt;a href='bar'title=title&gt;</p>
```````````````````````````````` ````````````````````````````````
跳至第 8326行更改 跳至第 8620行更改
<p><em>foo<br /> <p><em>foo<br />
bar</em></p> bar</em></p>
```````````````````````````````` ````````````````````````````````
换行符不会出现在代码行内 换行符不会出现在代码行内
```````````````````````````````` 示例 ```````````````````````````````` 示例
`代码 `代码
span` span`
. .
<p><code>代码 span</code></p> <p><code>代码 span</code></p>
```````````````````````````````` ````````````````````````````````
```````````````````````````````` 示例 ```````````````````````````````` 示例
`代码\ `代码\
span` span`
. .
<p><code>代码\ span</code></p> <p><code>代码\ span</code></p>
```````````````````````````````` ````````````````````````````````
或者 HTML 标签内 或者 HTML 标签内
跳至第 8731行更改 跳至第 9025行更改
参数`stack_bottom`设置了我们 参数`stack_bottom`设置了我们
在[分隔符堆栈]中下降的下限。如果它是NULL,我们可以 在[分隔符堆栈]中下降的下限。如果它是NULL,我们可以
一直下降到底部。否则,我们在 一直下降到底部。否则,我们在
访问`stack_bottom`之前停止。 访问`stack_bottom`之前停止。
令`current_position`指向[分隔符堆栈]中紧邻`stack_bottom`之上的元素 令`current_position`指向[分隔符堆栈]中紧邻`stack_bottom`之上的元素
(如果`stack_bottom`为NULL,则指向第一个元素)。 (如果`stack_bottom`为NULL,则指向第一个元素)。
为NULL)。 为NULL)。
我们跟踪每种分隔符类型(`*`、`_`)的`openers_bottom`。 我们跟踪每种分隔符类型(`*`、`_`)的`openers_bottom`。
将其初始化为`stack_bottom`。 类型(`*`、`_`)以及每个关闭分隔符运行的长度
(模3)。将其初始化为`stack_bottom`。
然后我们重复以下操作,直到潜在的 然后我们重复以下操作,直到潜在的
关闭器用完。 关闭器用完。
- 在分隔符堆栈中向前移动`current_position`(如果需要), - 在分隔符堆栈中向前移动`current_position`(如果需要),
直到找到第一个具有分隔符`*`或`_`的潜在关闭器。 直到找到第一个具有分隔符`*`或`_`的潜在关闭器。
(这将是离输入开头最近的潜在关闭器—— (这将是离输入开头最近的潜在关闭器——
解析顺序中的第一个。) 解析顺序中的第一个。)
- 现在,在堆栈中向后查找(保持在`stack_bottom`之上, - 现在,在堆栈中向后查找(保持在`stack_bottom`之上,
跳至第 8763行更改 跳至第 9058行更改
+ 从分隔符堆栈中移除所有位于 + 从分隔符堆栈中移除所有位于
打开和关闭分隔符之间的分隔符。 打开和关闭分隔符之间的分隔符。
+ 从打开和关闭文本节点中移除1个(用于普通强调)或2个(用于强强调)分隔符。 + 从打开和关闭文本节点中移除1个(用于普通强调)或2个(用于强强调)分隔符。
如果它们因此变空,则移除它们并移除分隔符堆栈中对应的元素。 如果它们因此变空,则移除它们并移除分隔符堆栈中对应的元素。
如果它们因此变空,则移除它们并移除 如果它们因此变空,则移除它们并移除
如果关闭节点被移除,则将`current_position`重置为堆栈中的下一个元素。 如果关闭节点被移除,则将`current_position`重置为堆栈中的下一个元素。
`current_position`重置为堆栈中的下一个元素。 `current_position`重置为堆栈中的下一个元素。
- 如果未找到 - 如果未找到
+ 将`openers_bottom`设置为`current_position`之前的元素。 + 将`openers_bottom`设置为`current_position`之前的元素。
(我们知道,在此点及之前没有此种关闭器的打开器, (我们知道,在此点及之前没有此种关闭器的打开器,
因此这为未来的搜索设定了下限。) 因此这为未来的搜索设定了下限。)
+ 如果`current_position`处的关闭器不是潜在的打开器, + 如果`current_position`处的关闭器不是潜在的打开器,
则从分隔符堆栈中移除它(因为我们知道它也 则从分隔符堆栈中移除它(因为我们知道它也
不能是关闭器)。 不能是关闭器)。
+ 将`current_position`推进到堆栈中的下一个元素。 + 将`current_position`推进到堆栈中的下一个元素。
 更改结束。79个更改块。 
123行已更改或删除。 416行已更改或添加。

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