spec.txt   spec.txt 
--- ---
标题: CommonMark 规范 标题: CommonMark 规范
作者: John MacFarlane 作者: John MacFarlane
version: 0.22 version: 0.23
date: 2015-08-23 date: 2015-12-29
许可: '[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 年开发,他编写了
skipping to change at line 39 skipping to change at line 39
1. How much indentation is needed for a sublist? The spec says that 1. How much indentation is needed for a sublist? The spec says that
continuation paragraphs need to be indented four spaces, but is continuation paragraphs need to be indented four spaces, but is
not fully explicit about sublists. It is natural to think that not fully explicit about sublists. It is natural to think that
they, too, must be indented four spaces, but `Markdown.pl` does they, too, must be indented four spaces, but `Markdown.pl` does
not require that. This is hardly a "corner case," and divergences not require that. This is hardly a "corner case," and divergences
between implementations on this issue often lead to surprises for between implementations on this issue often lead to surprises for
users in real documents. (See [this comment by John users in real documents. (See [this comment by John
Gruber](http://article.gmane.org/gmane.text.markdown.general/1997).) Gruber](http://article.gmane.org/gmane.text.markdown.general/1997).)
2. Is a blank line needed before a block quote or header? 2. Is a blank line needed before a block quote or heading?
Most implementations do not require the blank line. However, Most implementations do not require the blank line. However,
this can lead to unexpected results in hard-wrapped text, and this can lead to unexpected results in hard-wrapped text, and
also to ambiguities in parsing (note that some implementations also to ambiguities in parsing (note that some implementations
put the header inside the blockquote, while others do not). put the heading inside the blockquote, while others do not).
(John Gruber has also spoken [in favor of requiring the blank (John Gruber has also spoken [in favor of requiring the blank
lines](http://article.gmane.org/gmane.text.markdown.general/2146).) lines](http://article.gmane.org/gmane.text.markdown.general/2146).)
3. Is a blank line needed before an indented code block? 3. Is a blank line needed before an indented code block?
(`Markdown.pl` requires it, but this is not mentioned in the (`Markdown.pl` requires it, but this is not mentioned in the
documentation, and some implementations do not require it.) documentation, and some implementations do not require it.)
``` markdown ``` markdown
paragraph paragraph
code? code?
skipping to change at line 88 skipping to change at line 88
[here](http://article.gmane.org/gmane.text.markdown.general/2554).) [here](http://article.gmane.org/gmane.text.markdown.general/2554).)
5. Can list markers be indented? Can ordered list markers be right-aligned? 5. Can list markers be indented? Can ordered list markers be right-aligned?
``` markdown ``` markdown
8. item 1 8. item 1
9. item 2 9. item 2
10. item 2a 10. item 2a
``` ```
6. Is this one list with a horizontal rule in its second item, 6. Is this one list with a thematic break in its second item,
or two lists separated by a horizontal rule? or two lists separated by a thematic break?
``` markdown ``` markdown
* a * a
* * * * * * * * * *
* b * b
``` ```
7. When list markers change from numbers to bullets, do we have 7. When list markers change from numbers to bullets, do we have
two lists or one? (The Markdown syntax description suggests two, two lists or one? (The Markdown syntax description suggests two,
but the perl scripts and many other implementations produce one.) but the perl scripts and many other implementations produce one.)
skipping to change at line 131 skipping to change at line 131
``` ```
10. What are the precedence rules between block-level and inline-level 10. What are the precedence rules between block-level and inline-level
structure? For example, how should the following be parsed? structure? For example, how should the following be parsed?
``` markdown ``` markdown
- `a long code span can contain a hyphen like this - `a long code span can contain a hyphen like this
- and it can screw things up` - and it can screw things up`
``` ```
11. Can list items include section headers? (`Markdown.pl` does not 11. Can list items include section headings? (`Markdown.pl` does not
allow this, but does allow blockquotes to include headers.) allow this, but does allow blockquotes to include headings.)
``` markdown ``` markdown
- # Heading - # Heading
``` ```
12. Can list items be empty? 12. Can list items be empty?
``` markdown ``` markdown
* a * a
* *
skipping to change at line 327 skipping to change at line 327
## 不安全字符 ## 不安全字符
出于安全考虑,Unicode 字符 `U+0000` 必须被替换 出于安全考虑,Unicode 字符 `U+0000` 必须被替换
使用替换字符(`U+FFFD`)。 使用替换字符(`U+FFFD`)。
# 区块与行内元素 # 区块与行内元素
我们可以将文档视为一系列的 我们可以将文档视为一系列的
[块](@block)——结构元素,如段落、块 [块](@block)——结构元素,如段落、块
quotations, lists, headers, rules, and code blocks. Some blocks (like quotations, lists, headings, rules, and code blocks. Some blocks (like
block quotes and list items) contain other blocks; others (like block quotes and list items) contain other blocks; others (like
headers and paragraphs) contain [inline](@inline) content---text, headings and paragraphs) contain [inline](@inline) content---text,
links, emphasized text, images, code, and so on. links, emphasized text, images, code, and so on.
## Precedence ## Precedence
Indicators of block structure always take precedence over indicators Indicators of block structure always take precedence over indicators
of inline structure. So, for example, the following is a list with of inline structure. So, for example, the following is a list with
two items, not a list with one item containing a code span two items, not a list with one item containing a code span
. .
- `one - `one
- two` - two`
. .
<ul> <ul>
<li>`one</li> <li>`one</li>
<li>two`</li> <li>two`</li>
</ul> </ul>
. .
This means that parsing can proceed in two steps: first, the block This means that parsing can proceed in two steps: first, the block
structure of the document can be discerned; second, text lines inside structure of the document can be discerned; second, text lines inside
paragraphs, headers, 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
[container block](@container-block)s, [container block](@container-block)s,
which can contain other blocks, and [leaf block](@leaf-block)s, which can contain other blocks, and [leaf block](@leaf-block)s,
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.
## Horizontal rules ## Thematic breaks
由0-3个缩进空格组成的行,后跟一个序列 由0-3个缩进空格组成的行,后跟一个序列
of three or more matching `-`, `_`, or `*` characters, each followed of three or more matching `-`, `_`, or `*` characters, each followed
可选地后面跟着任意数量的空格,形成一个 可选地后面跟着任意数量的空格,形成一个
[horizontal rule](@horizontal-rule). [thematic break](@thematic-break).
. .
*** ***
--- ---
___ ___
. .
<hr /> <hr />
<hr /> <hr />
<hr /> <hr />
. .
skipping to change at line 492 skipping to change at line 492
a------ a------
---a--- ---a---
. .
<p>_ _ _ _ a</p> <p>_ _ _ _ a</p>
<p>a------</p> <p>a------</p>
<p>---a---</p> <p>---a---</p>
. .
It is required that all of the [non-whitespace character]s be the same. It is required that all of the [non-whitespace character]s be the same.
So, this is not a horizontal rule So, this is not a thematic break
. .
*-* *-*
. .
<p><em>-</em></p> <p><em>-</em></p>
. .
Horizontal rules do not need blank lines before or after Thematic breaks do not need blank lines before or after
. .
- foo - foo
*** ***
- bar - bar
. .
<ul> <ul>
<li>foo</li> <li>foo</li>
</ul> </ul>
<hr /> <hr />
<ul> <ul>
<li>bar</li> <li>bar</li>
</ul> </ul>
. .
Horizontal rules can interrupt a paragraph Thematic breaks can interrupt a paragraph
. .
Foo Foo
*** ***
bar bar
. .
<p>Foo</p> <p>Foo</p>
<hr /> <hr />
<p>bar</p> <p>bar</p>
. .
If a line of dashes that meets the above conditions for being a If a line of dashes that meets the above conditions for being a
horizontal rule could also be interpreted as the underline of a [setext thematic break could also be interpreted as the underline of a [setext
header], the interpretation as a heading], the interpretation as a
[setext header] takes precedence. Thus, for example, [setext heading] takes precedence. Thus, for example,
this is a setext header, not a paragraph followed by a horizontal rule: this is a setext heading, not a paragraph followed by a thematic break:
. .
Foo Foo
--- ---
bar bar
. .
<h2>Foo</h2> <h2>Foo</h2>
<p>bar</p> <p>bar</p>
. .
When both a horizontal rule and a list item are possible When both a thematic break and a list item are possible
interpretations of a line, the horizontal rule takes precedence interpretations of a line, the thematic break takes precedence
. .
* Foo * Foo
* * * * * *
* Bar * Bar
. .
<ul> <ul>
<li>Foo</li> <li>Foo</li>
</ul> </ul>
<hr /> <hr />
<ul> <ul>
<li>Bar</li> <li>Bar</li>
</ul> </ul>
. .
If you want a horizontal rule in a list item, use a different bullet If you want a thematic break in a list item, use a different bullet
. .
- Foo - Foo
- * * * - * * *
. .
<ul> <ul>
<li>Foo</li> <li>Foo</li>
<li> <li>
<hr /> <hr />
</li> </li>
</ul> </ul>
. .
## ATX headers ## ATX headings
An [ATX header](@atx-header) An [ATX heading](@atx-heading)
由一串字符组成,被解析为行内内容,位于 由一串字符组成,被解析为行内内容,位于
起始的 1--6 个未转义的 `#` 字符和一个可选的 起始的 1--6 个未转义的 `#` 字符和一个可选的
closing sequence of any number of unescaped `#` characters. closing sequence of any number of unescaped `#` characters.
The opening sequence of `#` characters cannot be followed directly by a The opening sequence of `#` characters must be followed by a
[non-whitespace character]. The optional closing sequence of `#`s must be [space] or by the end of line. The optional closing sequence of `#`s must be
前面有一个 [空格],并且后面只能跟空格。起始的 前面有一个 [空格],并且后面只能跟空格。起始的
`#` 字符可以缩进 0-3 个空格。标题的原始内容 `#` 字符可以缩进 0-3 个空格。标题的原始内容
header are stripped of leading and trailing spaces before being parsed heading are stripped of leading and trailing spaces before being parsed
as inline content. The header level is equal to the number of `#` as inline content. The heading level is equal to the number of `#`
characters in the opening sequence. characters in the opening sequence.
Simple headers Simple headings
. .
# foo # foo
## foo ## foo
### foo ### foo
#### foo #### foo
##### foo ##### foo
###### foo ###### foo
. .
<h1>foo</h1> <h1>foo</h1>
<h2>foo</h2> <h2>foo</h2>
<h3>foo</h3> <h3>foo</h3>
<h4>foo</h4> <h4>foo</h4>
<h5>foo</h5> <h5>foo</h5>
<h6>foo</h6> <h6>foo</h6>
. .
More than six `#` characters is not a header More than six `#` characters is not a heading
. .
####### foo ####### foo
. .
<p>####### foo</p> <p>####### foo</p>
. .
At least one space is required between the `#` characters and the At least one space is required between the `#` characters and the
header's contents, unless the header is empty. Note that many heading's contents, unless the heading is empty. Note that many
implementations currently do not require the space. However, the implementations currently do not require the space. However, the
space was required by the space was required by the
[original ATX implementation](http://www.aaronsw.com/2002/atx/atx.py), [original ATX implementation](http://www.aaronsw.com/2002/atx/atx.py),
and it helps prevent things like the following from being parsed as and it helps prevent things like the following from being parsed as
headers headings
. .
#5 bolt #5 bolt
#foobar #hashtag
. .
<p>#5 bolt</p> <p>#5 bolt</p>
<p>#foobar</p> <p>#hashtag</p>
. .
This is not a header, because the first `#` is escaped 制表符无法生效
.
#→foo
.
<p>#→foo</p>
.
This is not a heading, because the first `#` is escaped
. .
\## foo \## foo
. .
<p>## foo</p> <p>## foo</p>
. .
内容按行内元素解析 内容按行内元素解析
. .
skipping to change at line 714 skipping to change at line 722
结束序列后允许有空格 结束序列后允许有空格
. .
### foo ### ### foo ###
. .
<h3>foo</h3> <h3>foo</h3>
. .
A sequence of `#` characters with anything but [space]s following it A sequence of `#` characters with anything but [space]s following it
不是结尾序列,而是计作标题内容的一部分。 不是结尾序列,而是计作标题内容的一部分。
header heading
. .
### foo ### b ### foo ### b
. .
<h3>foo ### b</h3> <h3>foo ### b</h3>
. .
结束序列前必须有一个空格 结束序列前必须有一个空格
. .
skipping to change at line 743 skipping to change at line 751
. .
### foo \### ### foo \###
## foo #\## ## foo #\##
# foo \# # foo \#
. .
<h3>foo ###</h3> <h3>foo ###</h3>
<h2>foo ###</h2> <h2>foo ###</h2>
<h1>foo #</h1> <h1>foo #</h1>
. .
ATX headers need not be separated from surrounding content by blank ATX headings need not be separated from surrounding content by blank
lines, and they can interrupt paragraphs lines, and they can interrupt paragraphs
. .
**** ****
## foo ## foo
**** ****
. .
<hr /> <hr />
<h2>foo</h2> <h2>foo</h2>
<hr /> <hr />
skipping to change at line 766 skipping to change at line 774
. .
Foo bar Foo bar
# baz # baz
Bar foo Bar foo
. .
<p>Foo bar</p> <p>Foo bar</p>
<h1>baz</h1> <h1>baz</h1>
<p>Bar foo</p> <p>Bar foo</p>
. .
ATX headers can be empty ATX headings can be empty
. .
## ##
# #
### ### ### ###
. .
<h2></h2> <h2></h2>
<h1></h1> <h1></h1>
<h3></h3> <h3></h3>
. .
## Setext headers ## Setext headings
A [setext header](@setext-header) A [setext heading](@setext-heading)
consists of a line of text, containing at least one [non-whitespace character], consists of a line of text, containing at least one [non-whitespace character],
with no more than 3 spaces indentation, followed by a [setext header with no more than 3 spaces indentation, followed by a [setext heading
underline]. The line of text must be underline]. The line of text must be
one that, were it not followed by the setext header underline, one that, were it not followed by the setext heading underline,
would be interpreted as part of a paragraph: it cannot be would be interpreted as part of a paragraph: it cannot be
interpretable as a [code fence], [ATX header][ATX headers], interpretable as a [code fence], [ATX heading][ATX headings],
[block quote][block quotes], [horizontal rule][horizontal rules], [block quote][block quotes], [thematic break][thematic breaks],
[list item][list items], or [HTML block][HTML blocks]. [list item][list items], or [HTML block][HTML blocks].
A [setext header underline](@setext-header-underline) is a sequence of A [setext heading underline](@setext-heading-underline) is a sequence of
`=` characters or a sequence of `-` characters, with no more than 3 `=` characters or a sequence of `-` characters, with no more than 3
spaces indentation and any number of trailing spaces. If a line spaces indentation and any number of trailing spaces. If a line
containing a single `-` can be interpreted as an containing a single `-` can be interpreted as an
empty [list items], it should be interpreted this way empty [list items], it should be interpreted this way
and not as a [setext header underline]. and not as a [setext heading underline].
The header is a level 1 header if `=` characters are used in the The heading is a level 1 heading if `=` characters are used in the
[setext header underline], and a level 2 [setext heading underline], and a level 2
header if `-` characters are used. The contents of the header are the heading if `-` characters are used. The contents of the heading are the
result of parsing the first line as Markdown inline content. result of parsing the first line as Markdown inline content.
In general, a setext header need not be preceded or followed by a In general, a setext heading need not be preceded or followed by a
blank line. However, it cannot interrupt a paragraph, so when a blank line. However, it cannot interrupt a paragraph, so when a
setext header comes after a paragraph, a blank line is needed between setext heading comes after a paragraph, a blank line is needed between
them. them.
简单示例 简单示例
. .
Foo *bar* Foo *bar*
========= =========
Foo *bar* Foo *bar*
--------- ---------
skipping to change at line 833 skipping to change at line 841
Foo Foo
------------------------- -------------------------
Foo Foo
= =
. .
<h2>Foo</h2> <h2>Foo</h2>
<h1>Foo</h1> <h1>Foo</h1>
. .
The header content can be indented up to three spaces, and need The heading content can be indented up to three spaces, and need
not line up with the underlining not line up with the underlining
. .
Foo Foo
--- ---
Foo Foo
----- -----
Foo Foo
skipping to change at line 868 skipping to change at line 876
--- ---
. .
<pre><code>Foo <pre><code>Foo
--- ---
Foo Foo
</code></pre> </code></pre>
<hr /> <hr />
. .
The setext header underline can be indented up to three spaces, and The setext heading underline can be indented up to three spaces, and
may have trailing spaces may have trailing spaces
. .
Foo Foo
---- ----
. .
<h2>Foo</h2> <h2>Foo</h2>
. .
四个空格太多了 四个空格太多了
. .
Foo Foo
--- ---
. .
<p>Foo <p>Foo
---</p> ---</p>
. .
The setext header underline cannot contain internal spaces The setext heading underline cannot contain internal spaces
. .
Foo Foo
= = = =
Foo Foo
--- - --- -
. .
<p>Foo <p>Foo
= =</p> = =</p>
skipping to change at line 922 skipping to change at line 930
结尾的反斜杠也不会导致换行 结尾的反斜杠也不会导致换行
. .
Foo\ Foo\
---- ----
. .
<h2>Foo\</h2> <h2>Foo\</h2>
. .
Since indicators of block structure take precedence over Since indicators of block structure take precedence over
indicators of inline structure, the following are setext headers indicators of inline structure, the following are setext headings
. .
`Foo `Foo
---- ----
` `
<a title="a lot <a title="a lot
--- ---
of dashes"/> of dashes"/>
. .
<h2>`Foo</h2> <h2>`Foo</h2>
<p>`</p> <p>`</p>
<h2>&lt;a title=&quot;a lot</h2> <h2>&lt;a title=&quot;a lot</h2>
<p>of dashes&quot;/&gt;</p> <p>of dashes&quot;/&gt;</p>
. .
The setext header underline cannot be a [lazy continuation The setext heading underline cannot be a [lazy continuation
line] in a list item or block quote line] in a list item or block quote
. .
> Foo > Foo
--- ---
. .
<blockquote> <blockquote>
<p>Foo</p> <p>Foo</p>
</blockquote> </blockquote>
<hr /> <hr />
skipping to change at line 962 skipping to change at line 970
. .
- Foo - Foo
--- ---
. .
<ul> <ul>
<li>Foo</li> <li>Foo</li>
</ul> </ul>
<hr /> <hr />
. .
A setext header cannot interrupt a paragraph A setext heading cannot interrupt a paragraph
. .
Foo Foo
Bar Bar
--- ---
Foo Foo
Bar Bar
=== ===
. .
skipping to change at line 997 skipping to change at line 1005
Bar Bar
--- ---
Baz Baz
. .
<hr /> <hr />
<h2>Foo</h2> <h2>Foo</h2>
<h2>Bar</h2> <h2>Bar</h2>
<p>Baz</p> <p>Baz</p>
. .
Setext headers cannot be empty Setext headings cannot be empty
. .
==== ====
. .
<p>====</p> <p>====</p>
. .
Setext header text lines must not be interpretable as block Setext heading text lines must not be interpretable as block
constructs other than paragraphs. So, the line of dashes constructs other than paragraphs. So, the line of dashes
in these examples gets interpreted as a horizontal rule in these examples gets interpreted as a thematic break
. .
--- ---
--- ---
. .
<hr /> <hr />
<hr /> <hr />
. .
. .
skipping to change at line 1047 skipping to change at line 1055
. .
> foo > foo
----- -----
. .
<blockquote> <blockquote>
<p>foo</p> <p>foo</p>
</blockquote> </blockquote>
<hr /> <hr />
. .
If you want a header with `> foo` as its literal text, you can If you want a heading with `> foo` as its literal text, you can
use backslash escapes use backslash escapes
. .
\> foo \> foo
------ ------
. .
<h2>&gt; foo</h2> <h2>&gt; foo</h2>
. .
## Indented code blocks ## Indented code blocks
skipping to change at line 1189 skipping to change at line 1197
. .
<pre><code>foo <pre><code>foo
</code></pre> </code></pre>
<p>bar</p> <p>bar</p>
. .
And indented code can occur immediately before and after other kinds of And indented code can occur immediately before and after other kinds of
blocks blocks
. .
# Header # Heading
foo foo
Header Heading
------ ------
foo foo
---- ----
. .
<h1>Header</h1> <h1>Heading</h1>
<pre><code>foo <pre><code>foo
</code></pre> </code></pre>
<h2>Header</h2> <h2>Heading</h2>
<pre><code>foo <pre><code>foo
</code></pre> </code></pre>
<hr /> <hr />
. .
第一行可以缩进超过四个空格 第一行可以缩进超过四个空格
. .
foo foo
bar bar
skipping to change at line 1357 skipping to change at line 1365
aaa aaa
~~~ ~~~
~~~~ ~~~~
. .
<pre><code>aaa <pre><code>aaa
~~~ ~~~
</code></pre> </code></pre>
. .
未关闭的代码块会在文档末尾处关闭 未关闭的代码块会在文档末尾处关闭
(or the enclosing [block quote] or [list item]) (or the enclosing [block quote][block quotes] or [list item][list items])
. .
``` ```
. .
<pre><code></code></pre> <pre><code></code></pre>
. .
. .
````` `````
skipping to change at line 1977 skipping to change at line 1985
. .
<style <style
type="text/css"> type="text/css">
h1 {color:red;} h1 {color:red;}
p {color:blue;} p {color:blue;}
</style> </style>
. .
If there is no matching end tag, the block will end at the If there is no matching end tag, the block will end at the
end of the document (or the enclosing [block quote] or end of the document (or the enclosing [block quote][block quotes]
[list item]): or [list item][list items]):
. .
<style <style
type="text/css"> type="text/css">
foo foo
. .
<style <style
type="text/css"> type="text/css">
skipping to change at line 2536 skipping to change at line 2544
Foo Foo
[bar]: /baz [bar]: /baz
[bar] [bar]
. .
<p>Foo <p>Foo
[bar]: /baz</p> [bar]: /baz</p>
<p>[bar]</p> <p>[bar]</p>
. .
However, it can directly follow other block elements, such as headers However, it can directly follow other block elements, such as headings
and horizontal rules, and it need not be followed by a blank line. and thematic breaks, and it need not be followed by a blank line.
. .
# [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>
skipping to change at line 3400 skipping to change at line 3408
<pre><code>bar <pre><code>bar
</code></pre> </code></pre>
<p>baz</p> <p>baz</p>
<blockquote> <blockquote>
<p>bam</p> <p>bam</p>
</blockquote> </blockquote>
</li> </li>
</ol> </ol>
. .
A list item that contains an indented code block will preserve
empty lines within the code block verbatim, unless there are two
or more empty lines in a row (since as described above, two
blank lines end the list)
.
- Foo
bar
baz
.
<ul>
<li>
<p>Foo</p>
<pre><code>bar
baz
</code></pre>
</li>
</ul>
.
.
- Foo
bar
baz
.
<ul>
<li>
<p>Foo</p>
<pre><code>bar
</code></pre>
</li>
</ul>
<pre><code> baz
</code></pre>
.
注意,有序列表的起始编号必须为九位数字或更少 注意,有序列表的起始编号必须为九位数字或更少
. .
123456789. ok 123456789. ok
. .
<ol start="123456789"> <ol start="123456789">
<li>ok</li> <li>ok</li>
</ol> </ol>
. .
skipping to change at line 3967 skipping to change at line 4016
<li> <li>
<ol start="2"> <ol start="2">
<li>foo</li> <li>foo</li>
</ol> </ol>
</li> </li>
</ul> </ul>
</li> </li>
</ol> </ol>
. .
A list item can contain a header A list item can contain a heading
. .
- # Foo - # Foo
- Bar - Bar
--- ---
baz baz
. .
<ul> <ul>
<li> <li>
<h1>Foo</h1> <h1>Foo</h1>
skipping to change at line 4778 skipping to change at line 4827
Escaped characters are treated as regular characters and do Escaped characters are treated as regular characters and do
not have their usual Markdown meanings not have their usual Markdown meanings
. .
\*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 header \# not a heading
\[foo]: /url "not a reference" \[foo]: /url "not a reference"
. .
<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 header # not a heading
[foo]: /url &quot;not a reference&quot;</p> [foo]: /url &quot;not a reference&quot;</p>
. .
如果反斜杠本身被转义,则随后的字符不被转义 如果反斜杠本身被转义,则随后的字符不被转义
. .
\\*emphasis* \\*emphasis*
. .
<p>\<em>emphasis</em></p> <p>\<em>emphasis</em></p>
. .
skipping to change at line 4872 skipping to change at line 4921
. .
``` foo\+bar ``` foo\+bar
foo foo
``` ```
. .
<pre><code class="language-foo+bar">foo <pre><code class="language-foo+bar">foo
</code></pre> </code></pre>
. .
## Entities ## Entity and numeric character references
为了使本标准尽可能与 HTML 无关,所有 All valid HTML entity references and numeric character
valid HTML entities (except in code blocks and code spans) references, except those occuring in code blocks, code spans,
are recognized as such and converted into Unicode characters before and raw HTML, are recognized as such and treated as equivalent to the
they are stored in the AST. This means that renderers to formats other corresponding Unicode characters. Conforming CommonMark parsers
than HTML need not be HTML-entity aware. HTML renderers may either escape need not store information about whether a particular character
Unicode characters as entities or leave them as they are. (However, was represented in the source using a Unicode character or
`"`, `&`, `<` 和 `>` 必须始终作为实体渲染。) 实体引用表示。
[Named entities](@name-entities) consist of `&` + any of the valid [Entity references](@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>
is used as an authoritative source of the valid entity names and their is used as an authoritative source for the valid entity
corresponding code points. 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 entities](@decimal-entities) [Decimal numeric character
consist of `&#` + a string of 1--8 arabic digits + `;`. Again, these references](@decimal-numeric-character-references)
entities need to be recognised and transformed into their corresponding consist of `&#` + a string of 1--8 arabic digits + `;`. A
Unicode code points. Invalid Unicode code points will be replaced by numeric character reference is parsed as the corresponding
Unicode character. Invalid Unicode code points will be replaced by
the "unknown code point" character (`U+FFFD`). For security reasons, the "unknown code point" character (`U+FFFD`). For security reasons,
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; &#98765432; &#0;
. .
<p># Ӓ Ϡ </p> <p># Ӓ Ϡ </p>
. .
[Hexadecimal entities](@hexadecimal-entities) consist of `&#` + either [Hexadecimal numeric character
`X` or `x` + a string of 1-8 hexadecimal digits + `;`. They will also references](@hexadecimal-numeric-character-references) consist of `&#` +
be parsed and turned into the corresponding Unicode code points in the either `X` or `x` + a string of 1-8 hexadecimal digits + `;`.
AST. They too are parsed as the corresponding Unicode character (this
time specified with a hexadecimal numeral instead of decimal).
. .
&#X22; &#XD06; &#xcab; &#X22; &#XD06; &#xcab;
. .
<p>&quot; ആ ಫ</p> <p>&quot; ആ ಫ</p>
. .
这里是一些非实体引用 这里是一些非实体引用
. .
&nbsp &x; &#; &#x; &ThisIsWayTooLongToBeAnEntityIsntIt; &hi?; &nbsp &x; &#; &#x;
&ThisIsWayTooLongToBeAnEntityIsntIt; &hi?;
. .
<p>&amp;nbsp &amp;x; &amp;#; &amp;#x; &amp;ThisIsWayTooLongToBeAnEntityIsntIt; & <p>&amp;nbsp &amp;x; &amp;#; &amp;#x;
amp;hi?;</p> &amp;ThisIsWayTooLongToBeAnEntityIsntIt; &amp;hi?;</p>
. .
Although HTML5 does accept some entities without a trailing semicolon Although HTML5 does accept some entity references
(such as `&copy`), these are not recognized as entities here, because it without a trailing semicolon (such as `&copy`), these are not
makes the grammar too ambiguous recognized here, because it makes the grammar too ambiguous
. .
&copy &copy
. .
<p>&amp;copy</p> <p>&amp;copy</p>
. .
Strings that are not on the list of HTML5 named entities are not Strings that are not on the list of HTML5 named entities are not
recognized as entities either recognized as entity references either
. .
&MadeUpEntity; &MadeUpEntity;
. .
<p>&amp;MadeUpEntity;</p> <p>&amp;MadeUpEntity;</p>
. .
Entities are recognized in any context besides code spans or Entity and numeric character references are recognized in any
code blocks, including raw HTML, URLs, [link title]s, and context besides code spans or code blocks or raw HTML, including
[fenced code block] [info string]s URLs, [link title]s, and [fenced code block][] [info string]s
. .
<a href="&ouml;&ouml;.html"> <a href="&ouml;&ouml;.html">
. .
<a href="&ouml;&ouml;.html"> <a href="&ouml;&ouml;.html">
. .
. .
[foo](/f&ouml;&ouml; "f&ouml;&ouml;") [foo](/f&ouml;&ouml; "f&ouml;&ouml;")
. .
skipping to change at line 4982 skipping to change at line 5035
. .
``` f&ouml;&ouml; ``` f&ouml;&ouml;
foo foo
``` ```
. .
<pre><code class="language-föö">foo <pre><code class="language-föö">foo
</code></pre> </code></pre>
. .
Entities are treated as literal text in code spans and code blocks: Entity and numeric character references are treated as literal
text in code spans and code blocks, and in raw HTML:
. .
`f&ouml;&ouml;` `f&ouml;&ouml;`
. .
<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>
. .
.
<a href="f&ouml;f&ouml;"/>
.
<a href="f&ouml;f&ouml;"/>
.
## Code spans ## Code spans
A [backtick string](@backtick-string) A [backtick string](@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](@code-span) begins with a backtick string and ends with A [code span](@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
the characters between the two backtick strings, with leading and the characters between the two backtick strings, with leading and
trailing spaces and [line ending]s removed, and trailing spaces and [line ending]s removed, and
skipping to change at line 5269 skipping to change at line 5329
比此处给出的规则要复杂一些。) 比此处给出的规则要复杂一些。)
以下规则定义了强调和强强调。 以下规则定义了强调和强强调。
1. 单个 `*` 字符 [可以开启强调](@can-open-emphasis) 1. 单个 `*` 字符 [可以开启强调](@can-open-emphasis)
iff (if and only if) it is part of a [left-flanking delimiter run]. iff (if and only if) it is part of a [left-flanking delimiter run].
2. 单个 `_` 字符 [可以开启强调] 当且仅当 2. 单个 `_` 字符 [可以开启强调] 当且仅当
它是 [左侧定界符序列] 的一部分 它是 [左侧定界符序列] 的一部分
and either (a) not part of a [right-flanking delimiter run] and either (a) not part of a [right-flanking delimiter run]
or (b) part of a [right-flanking delimeter run] or (b) part of a [right-flanking delimiter run]
preceded by punctuation. preceded by punctuation.
3. 单个 `*` 字符 [可以关闭强调](@can-close-emphasis) 3. 单个 `*` 字符 [可以关闭强调](@can-close-emphasis)
当且仅当它是 [右侧定界符序列] 的一部分时。 当且仅当它是 [右侧定界符序列] 的一部分时。
4. A single `_` character [can close emphasis] iff 4. A single `_` character [can close emphasis] iff
it is part of a [right-flanking delimiter run] it is part of a [right-flanking delimiter run]
and either (a) not part of a [left-flanking delimiter run] and either (a) not part of a [left-flanking delimiter run]
or (b) part of a [left-flanking delimeter run] or (b) part of a [left-flanking delimiter run]
followed by punctuation. followed by punctuation.
5. 双 `**` [可以开启强强调](@can-open-strong-emphasis) 5. 双 `**` [可以开启强强调](@can-open-strong-emphasis)
当且仅当它是 [左侧定界符序列] 的一部分时。 当且仅当它是 [左侧定界符序列] 的一部分时。
6. A double `__` [can open strong emphasis] iff 6. A double `__` [can open strong emphasis] iff
它是 [左侧定界符序列] 的一部分 它是 [左侧定界符序列] 的一部分
and either (a) not part of a [right-flanking delimiter run] and either (a) not part of a [right-flanking delimiter run]
or (b) part of a [right-flanking delimeter run] or (b) part of a [right-flanking delimiter run]
preceded by punctuation. preceded by punctuation.
7. 双 `**` [可以关闭强强调](@can-close-strong-emphasis) 7. 双 `**` [可以关闭强强调](@can-close-strong-emphasis)
当且仅当它是 [右侧定界符序列] 的一部分时。 当且仅当它是 [右侧定界符序列] 的一部分时。
8. 双 `__` [可以关闭强强调] 8. 双 `__` [可以关闭强强调]
it is part of a [right-flanking delimiter run] it is part of a [right-flanking delimiter run]
and either (a) not part of a [left-flanking delimiter run] and either (a) not part of a [left-flanking delimiter run]
or (b) part of a [left-flanking delimeter run] or (b) part of a [left-flanking delimiter run]
followed by punctuation. followed by punctuation.
9. 强调以一个 [可以开启强调] 的定界符开始,并以 9. 强调以一个 [可以开启强调] 的定界符开始,并以
一个 [可以关闭强调] 的定界符结束,且使用相同的 一个 [可以关闭强调] 的定界符结束,且使用相同的
字符(`_` 或 `*`)作为起始分隔符。起始分隔符和 字符(`_` 或 `*`)作为起始分隔符。起始分隔符和
结束分隔符之间必须有一个非空的内联序列;这些形成了强调 结束分隔符之间必须有一个非空的内联序列;这些形成了强调
内联的内容。 内联的内容。
内联。 内联。
10. 强强调以一个 10. 强强调以一个
skipping to change at line 6512 skipping to change at line 6572
<p><a href="foo):">link</a></p> <p><a href="foo):">link</a></p>
. .
链接可以包含片段标识符和查询字符串。 链接可以包含片段标识符和查询字符串。
. .
[link](#fragment) [link](#fragment)
[link](http://example.com#fragment) [link](http://example.com#fragment)
[link](http://example.com?foo=bar&baz#fragment) [link](http://example.com?foo=3#frag)
. .
<p><a href="#fragment">link</a></p> <p><a href="#fragment">link</a></p>
<p><a href="http://example.com#fragment">link</a></p> <p><a href="http://example.com#fragment">link</a></p>
<p><a href="http://example.com?foo=bar&amp;baz#fragment">link</a></p> <p><a href="http://example.com?foo=3#frag">link</a></p>
. .
Note that a backslash before a non-escapable character is Note that a backslash before a non-escapable character is
just a backslash just a backslash
. .
[link](foo\bar) [link](foo\bar)
. .
<p><a href="foo%5Cbar">link</a></p> <p><a href="foo%5Cbar">link</a></p>
. .
URL 转义在目的地内部应保持原样,因为所有 URL 转义在目的地内部应保持原样,因为所有
URL-escaped characters are also valid URL characters. HTML entities in URL-escaped characters are also valid URL characters. Entity and
the destination will be parsed into the corresponding Unicode numerical character references in the destination will be parsed
code points, as usual, and optionally URL-escaped when written as HTML. into the corresponding Unicode code points, as usual. These may
be optionally URL-escaped when written as HTML, but this spec
does not enforce any particular policy for rendering URLs in
HTML or other formats. Renderers may make different decisions
about how to escape or normalize URLs in the output.
. .
[link](foo%20b&auml;) [link](foo%20b&auml;)
. .
<p><a href="foo%20b%C3%A4">link</a></p> <p><a href="foo%20b%C3%A4">link</a></p>
. .
注意,由于标题通常可以被解析为目的地, 注意,由于标题通常可以被解析为目的地,
如果你尝试省略目的地而保留标题,你会 如果你尝试省略目的地而保留标题,你会
得到意想不到的结果。 得到意想不到的结果。
skipping to change at line 6561 skipping to change at line 6625
. .
[link](/url "title") [link](/url "title")
[link](/url 'title') [link](/url 'title')
[link](/url (title)) [link](/url (title))
. .
<p><a href="/url" title="title">link</a> <p><a href="/url" title="title">link</a>
<a href="/url" title="title">link</a> <a href="/url" title="title">link</a>
<a href="/url" title="title">link</a></p> <a href="/url" title="title">link</a></p>
. .
Backslash escapes and entities may be used in titles Backslash escapes and entity and numeric character references
可以在标题中使用
. .
[链接](/url "标题 \"&quot;") [链接](/url "标题 \"&quot;")
. .
<p><a href="/url" title="标题 &quot;&quot;">链接</a></p> <p><a href="/url" title="标题 &quot;&quot;">链接</a></p>
. .
除非经过转义,否则不允许嵌套平衡的引号。 除非经过转义,否则不允许嵌套平衡的引号。
. .
skipping to change at line 6589 skipping to change at line 6654
. .
[link](/url 'title "and" title') [link](/url 'title "and" title')
. .
<p><a href="/url" title="title &quot;and&quot; title">link</a></p> <p><a href="/url" title="title &quot;and&quot; title">link</a></p>
. .
(Note: `Markdown.pl` did allow double quotes inside a double-quoted (Note: `Markdown.pl` did allow double quotes inside a double-quoted
title, and its test suite included a test demonstrating this. title, and its test suite included a test demonstrating this.
But it is hard to see a good rationale for the extra complexity this But it is hard to see a good rationale for the extra complexity this
brings, since there are already many ways---backslash escaping, brings, since there are already many ways---backslash escaping,
entities, or using a different quote type for the enclosing title---to entity and numeric character references, or using a different
write titles containing double quotes. `Markdown.pl`'s handling of quote type for the enclosing title---to write titles containing
titles has a number of other strange features. For example, it allows double quotes. `Markdown.pl`'s handling of titles has a number
single-quoted titles in inline links, but not reference links. And, in of other strange features. For example, it allows single-quoted
reference links but not inline links, it allows a title to begin with titles in inline links, but not reference links. And, in
`"` and end with `)`. `Markdown.pl` 1.0.1 even allows titles with no closing reference links but not inline links, it allows a title to begin
quotation mark, though 1.0.2b8 does not. It seems preferable to adopt with `"` and end with `)`. `Markdown.pl` 1.0.1 even allows
a simple, rational rule that works the same way in inline links and titles with no closing quotation mark, though 1.0.2b8 does not.
link reference definitions.) It seems preferable to adopt a simple, rational rule that works
the same way in inline links and link reference definitions.)
[Whitespace] is allowed around the destination and title [Whitespace] is allowed around the destination and title
. .
[link]( /uri [link]( /uri
"title" ) "title" )
. .
<p><a href="/uri" title="title">link</a></p> <p><a href="/uri" title="title">link</a></p>
. .
skipping to change at line 6728 skipping to change at line 6794
[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)
consists of a [link text], optional [whitespace], and a [link label] consists of a [link text] immediately followed by a [link label]
that [matches] a [link reference definition] elsewhere in the document. that [matches] a [link reference definition] elsewhere in the document.
一个 [链接标签](@link-label) 以左方括号(`[`)开始, 一个 [链接标签](@link-label) 以左方括号(`[`)开始,
并以第一个未被反斜杠转义的右方括号(`]`)结束。 并以第一个未被反斜杠转义的右方括号(`]`)结束。
在这些方括号之间必须至少有一个 [非空白字符]。 在这些方括号之间必须至少有一个 [非空白字符]。
未转义的方括号字符在 [链接标签] 中是不允许的。 未转义的方括号字符在 [链接标签] 中是不允许的。
一个链接标签在方括号内最多可以有 999 个字符。 一个链接标签在方括号内最多可以有 999 个字符。
characters inside the square brackets. characters inside the square brackets.
当且仅当一个标签的归一化形式相等时,它才 [匹配](@matches) 当且仅当一个标签的归一化形式相等时,它才 [匹配](@matches)
skipping to change at line 6898 skipping to change at line 6964
. .
[Foo [Foo
bar]: /url bar]: /url
[Baz][Foo bar] [Baz][Foo bar]
. .
<p><a href="/url">Baz</a></p> <p><a href="/url">Baz</a></p>
. .
There can be [whitespace] between the [link text] and the [link label] No [whitespace] is allowed between the [link text] and the
[link label]
. .
[foo] [bar] [foo] [bar]
[bar]: /url "title" [bar]: /url "title"
. .
<p><a href="/url" title="title">foo</a></p> <p>[foo] <a href="/url" title="title">bar</a></p>
. .
. .
[foo] [foo]
[bar] [bar]
[bar]: /url "title" [bar]: /url "title"
. .
<p><a href="/url" title="title">foo</a></p> <p>[foo]
<a href="/url" title="title">bar</a></p>
. .
This is a departure from John Gruber's original Markdown syntax
description, which explicitly allows whitespace between the link
text and the link label. It brings reference links in line with
[inline link]s, which (according to both original Markdown and
this spec) cannot have whitespace after the link text. More
importantly, it prevents inadvertent capture of consecutive
[shortcut reference link]s. If whitespace is allowed between the
link text and the link label, then in the following we will have
a single reference link, not two shortcut reference links, as
intended
``` markdown
[foo]
[bar]
[foo]: /url1
[bar]: /url2
```
(Note that [shortcut reference link]s were introduced by Gruber
himself in a beta version of `Markdown.pl`, but never included
in the official syntax description. Without shortcut reference
links, it is harmless to allow space between the link text and
link label; but once shortcut references are introduced, it is
too dangerous to allow this, as it frequently leads to
unintended results.)
When there are multiple matching [link reference definition]s, When there are multiple matching [link reference definition]s,
the first is used the first is used
. .
[foo]: /url1 [foo]: /url1
[foo]: /url2 [foo]: /url2
[bar][foo] [bar][foo]
. .
skipping to change at line 6980 skipping to change at line 7075
. .
. .
[foo][ref\[] [foo][ref\[]
[ref\[]: /uri [ref\[]: /uri
. .
<p><a href="/uri">foo</a></p> <p><a href="/uri">foo</a></p>
. .
Note that in this example `]` is not backslash-escaped
.
[bar\\]: /uri
[bar\\]
.
<p><a href="/uri">bar\</a></p>
.
A [link label] must contain at least one [non-whitespace character] A [link label] must contain at least one [non-whitespace character]
. .
[] []
[]: /uri []: /uri
. .
<p>[]</p> <p>[]</p>
<p>[]: /uri</p> <p>[]: /uri</p>
. .
skipping to change at line 7007 skipping to change at line 7112
. .
<p>[ <p>[
]</p> ]</p>
<p>[ <p>[
]: /uri</p> ]: /uri</p>
. .
一个 [折叠引用链接](@collapsed-reference-link) 一个 [折叠引用链接](@collapsed-reference-link)
由一个 [链接标签] 组成,该标签[匹配] 由一个 [链接标签] 组成,该标签[匹配]
文档中其他地方的 [链接引用定义]、可选的 [空白] 和字符串 `[]`。 文档中其他地方的 [链接引用定义]、可选的 [空白] 和字符串 `[]`。
document, optional [whitespace], and the string `[]`. document, followed by the string `[]`.
第一个链接标签的内容作为行内元素解析, 第一个链接标签的内容作为行内元素解析,
并用作链接的文本。链接的 URI 和标题由 并用作链接的文本。链接的 URI 和标题由
匹配的引用链接定义提供。因此, 匹配的引用链接定义提供。因此,
`[foo][]` 等同于 `[foo][foo]`。 `[foo][]` 等同于 `[foo][foo]`。
. .
[foo][] [foo][]
[foo]: /url "title" [foo]: /url "title"
. .
skipping to change at line 7039 skipping to change at line 7144
链接标签不区分大小写。 链接标签不区分大小写。
. .
[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>
. .
As with full reference links, [whitespace] is allowed As with full reference links, [whitespace] is not
between the two sets of brackets allowed between the two sets of brackets
. .
[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>
. .
A [shortcut reference link](@shortcut-reference-link) A [shortcut reference link](@shortcut-reference-link)
由一个 [链接标签] 组成,该标签[匹配] 由一个 [链接标签] 组成,该标签[匹配]
文档中其他地方的 [链接引用定义]、可选的 [空白] 和字符串 `[]`。 文档中其他地方的 [链接引用定义]、可选的 [空白] 和字符串 `[]`。
document and is not followed by `[]` or a link label. document and is not followed by `[]` or a link label.
第一个链接标签的内容作为行内元素解析, 第一个链接标签的内容作为行内元素解析,
which are used as the link's text. the link's URI and title which are used as the link's text. the link's URI and title
are provided by the matching link reference definition. are provided by the matching link reference definition.
Thus, `[foo]` is equivalent to `[foo][]`. Thus, `[foo]` is equivalent to `[foo][]`.
skipping to change at line 7268 skipping to change at line 7374
. .
![](/url) ![](/url)
. .
<p><img src="/url" alt="" /></p> <p><img src="/url" alt="" /></p>
. .
引用式: 引用式:
. .
![foo] [bar] ![foo][bar]
[bar]: /url [bar]: /url
. .
<p><img src="/url" alt="foo" /></p> <p><img src="/url" alt="foo" /></p>
. .
. .
![foo] [bar] ![foo][bar]
[BAR]: /url [BAR]: /url
. .
<p><img src="/url" alt="foo" /></p> <p><img src="/url" alt="foo" /></p>
. .
折叠式: 折叠式:
. .
![foo][] ![foo][]
skipping to change at line 7311 skipping to change at line 7417
标签不区分大小写。 标签不区分大小写。
. .
![Foo][] ![Foo][]
[foo]: /url "title" [foo]: /url "title"
. .
<p><img src="/url" alt="Foo" title="title" /></p> <p><img src="/url" alt="Foo" title="title" /></p>
. .
As with full reference links, [whitespace] is allowed As with reference links, [whitespace] is not allowed
between the two sets of brackets between the two sets of brackets
. .
![foo] ![foo]
[] []
[foo]: /url "title" [foo]: /url "title"
. .
<p><img src="/url" alt="foo" title="title" /></p> <p><img src="/url" alt="foo" title="title" />
[]</p>
. .
快捷式: 快捷式:
. .
![foo] ![foo]
[foo]: /url "title" [foo]: /url "title"
. .
<p><img src="/url" alt="foo" title="title" /></p> <p><img src="/url" alt="foo" title="title" /></p>
skipping to change at line 7594 skipping to change at line 7701
A [single-quoted attribute value](@single-quoted-attribute-value) A [single-quoted attribute value](@single-quoted-attribute-value)
由`'`、零个或多个 由`'`、零个或多个
不包含`'`的字符,以及一个最终的`'`组成。 不包含`'`的字符,以及一个最终的`'`组成。
A [double-quoted attribute value](@double-quoted-attribute-value) A [double-quoted attribute value](@double-quoted-attribute-value)
由`"`、零个或多个 由`"`、零个或多个
characters not including `"`, and a final `"`. characters not including `"`, and a final `"`.
An [open tag](@open-tag) consists of a `<` character, a [tag name], An [open tag](@open-tag) consists of a `<` character, a [tag name],
zero or more [attributes](@attribute], optional [whitespace], an optional `/` zero or more [attribute]s, optional [whitespace], an optional `/`
字符,和一个 `>` 字符。 字符,和一个 `>` 字符。
一个 [闭合标签](@closing-tag) 由字符串 `</`,一个 一个 [闭合标签](@closing-tag) 由字符串 `</`,一个
[tag name], optional [whitespace], and the character `>`. [tag name], optional [whitespace], and the character `>`.
An [HTML comment](@html-comment) consists of `<!--` + *text* + `-->`, An [HTML comment](@html-comment) consists of `<!--` + *text* + `-->`,
where *text* does not start with `>` or `->`, does not end with `-`, where *text* does not start with `>` or `->`, does not end with `-`,
and does not contain `--`. (See the and does not contain `--`. (See the
[HTML5 spec](http://www.w3.org/TR/html5/syntax.html#comments).) [HTML5 spec](http://www.w3.org/TR/html5/syntax.html#comments).)
skipping to change at line 7662 skipping to change at line 7769
<a foo="bar" bam = 'baz <em>"</em>' <a foo="bar" bam = 'baz <em>"</em>'
_boolean zoop:33=zoop:33 /> _boolean zoop:33=zoop:33 />
. .
<p><a foo="bar" bam = 'baz <em>"</em>' <p><a foo="bar" bam = 'baz <em>"</em>'
_boolean zoop:33=zoop:33 /></p> _boolean zoop:33=zoop:33 /></p>
. .
可以使用自定义标签名称 可以使用自定义标签名称
. .
<responsive-image src="foo.jpg" /> Foo <responsive-image src="foo.jpg" />
<My-Tag>
foo
</My-Tag>
. .
<responsive-image src="foo.jpg" /> <p>Foo <responsive-image src="foo.jpg" /></p>
<My-Tag>
foo
</My-Tag>
. .
非法标签名称,不会被解析为 HTML 非法标签名称,不会被解析为 HTML
. .
<33> <__> <33> <__>
. .
<p>&lt;33&gt; &lt;__&gt;</p> <p>&lt;33&gt; &lt;__&gt;</p>
. .
skipping to change at line 7719 skipping to change at line 7819
. .
<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>
. .
结束标签 结束标签
. .
</a> </a></foo >
</foo >
. .
</a> <p></a></foo ></p>
</foo >
. .
结束标签中的非法属性 结束标签中的非法属性
. .
</a href="foo"> </a href="foo">
. .
<p>&lt;/a href=&quot;foo&quot;&gt;</p> <p>&lt;/a href=&quot;foo&quot;&gt;</p>
. .
skipping to change at line 7785 skipping to change at line 7883
. .
CDATA 部分 CDATA 部分
. .
foo <![CDATA[>&<]]> foo <![CDATA[>&<]]>
. .
<p>foo <![CDATA[>&<]]></p> <p>foo <![CDATA[>&<]]></p>
. .
Entities are preserved in HTML attributes Entity and numeric character references are preserved in HTML
attributes
. .
<a href="&ouml;"> foo <a href="&ouml;">
. .
<a href="&ouml;"> <p>foo <a href="&ouml;"></p>
. .
反斜杠转义在 HTML 属性中无效 反斜杠转义在 HTML 属性中无效
. .
<a href="\*"> foo <a href="\*">
. .
<a href="\*"> <p>foo <a href="\*"></p>
. .
. .
<a href="\""> <a href="\"">
. .
<p>&lt;a href=&quot;&quot;&quot;&gt;</p> <p>&lt;a href=&quot;&quot;&quot;&gt;</p>
. .
## Hard line breaks ## Hard line breaks
skipping to change at line 8017 skipping to change at line 8116
## Overview {-} ## Overview {-}
解析分为两个阶段 解析分为两个阶段
1. In the first phase, lines of input are consumed and the block 1. In the first phase, lines of input are consumed and the block
structure of the document---its division into paragraphs, block quotes, structure of the document---its division into paragraphs, block quotes,
list items, and so on---is constructed. Text is assigned to these list items, and so on---is constructed. Text is assigned to these
blocks but not parsed. Link reference definitions are parsed and a blocks but not parsed. Link reference definitions are parsed and a
map of links is constructed. map of links is constructed.
2. In the second phase, the raw text contents of paragraphs and headers 2. In the second phase, the raw text contents of paragraphs and headings
are parsed into sequences of Markdown inline elements (strings, are parsed into sequences of Markdown inline elements (strings,
code spans, links, emphasis, and so on), using the map of link code spans, links, emphasis, and so on), using the map of link
references constructed in phase 1. references constructed in phase 1.
At each point in processing, the document is represented as a tree of At each point in processing, the document is represented as a tree of
**blocks**. The root of the tree is a `document` block. The `document` **blocks**. The root of the tree is a `document` block. The `document`
may have any number of other blocks as **children**. These children may have any number of other blocks as **children**. These children
may, in turn, have other blocks as children. The last child of a block may, in turn, have other blocks as children. The last child of a block
is normally considered **open**, meaning that subsequent lines of input is normally considered **open**, meaning that subsequent lines of input
can alter its contents. (Blocks that are not open are **closed**.) can alter its contents. (Blocks that are not open are **closed**.)
skipping to change at line 8080 skipping to change at line 8179
2. 接下来,在消耗了现有块的续行标记之后, 2. 接下来,在消耗了现有块的续行标记之后,
我们寻找新的块开始(例如,块引用的 `>`。 我们寻找新的块开始(例如,块引用的 `>`。
如果我们遇到一个新的区块起始,我们会关闭在步骤 1 中 如果我们遇到一个新的区块起始,我们会关闭在步骤 1 中
未匹配的任何区块,然后再将新区块创建为最后一个 未匹配的任何区块,然后再将新区块创建为最后一个
匹配区块的子级。 匹配区块的子级。
3. 最后,我们查看行中剩余的部分(在区块 3. 最后,我们查看行中剩余的部分(在区块
标记如 `>`、列表标记和缩进被消耗之后)。 标记如 `>`、列表标记和缩进被消耗之后)。
这些文本可以合并到最后一个开放的 这些文本可以合并到最后一个开放的
block (a paragraph, code block, header, or raw HTML). block (a paragraph, code block, heading, or raw HTML).
Setext headers are formed when we detect that the second line of Setext headings are formed when we detect that the second line of
a paragraph is a setext header line. a paragraph is a setext heading line.
当段落关闭时,会检测引用链接定义; 当段落关闭时,会检测引用链接定义;
解析已累积的文本行,查看它们是否以 解析已累积的文本行,查看它们是否以
一个或多个引用链接定义开头。任何剩余部分都将成为 一个或多个引用链接定义开头。任何剩余部分都将成为
普通段落。 普通段落。
我们可以通过观察上述树状结构是如何由 我们可以通过观察上述树状结构是如何由
四行 Markdown 生成的来了解其工作原理 四行 Markdown 生成的来了解其工作原理
``` markdown ``` markdown
skipping to change at line 8192 skipping to change at line 8291
-> list_item -> list_item
-> paragraph -> paragraph
"aliquando id" "aliquando id"
``` ```
## Phase 2: inline structure {-} ## Phase 2: inline structure {-}
一旦所有输入都被解析完毕,所有的开放块都会被关闭。 一旦所有输入都被解析完毕,所有的开放块都会被关闭。
We then "walk the tree," visiting every node, and parse raw We then "walk the tree," visiting every node, and parse raw
string contents of paragraphs and headers as inlines. At this string contents of paragraphs and headings as inlines. At this
point we have seen all the link reference definitions, so we can point we have seen all the link reference definitions, so we can
resolve reference links as we go. resolve reference links as we go.
``` tree ``` tree
document document
block_quote block_quote
paragraph paragraph
str "Lorem ipsum dolor" str "Lorem ipsum dolor"
softbreak softbreak
str "sit amet." str "sit amet."
 End of changes. 110 change blocks. 
160 lines changed or deleted 258 lines changed or added

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