Couldn't find wdiff. Falling back to builtin diff colouring... 差异: spec.txt - spec.txt - CommonMark 规范
 spec.txt   spec.txt 
--- ---
标题: CommonMark 规范 标题: CommonMark 规范
作者: John MacFarlane 作者: John MacFarlane
version: 0.29 version: '0.30'
date: '2019-04-06' date: '2021-06-19'
许可: '[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
skipping to change at line 273 skipping to change at line 273
python test/spec_tests.py --spec spec.txt --program PROGRAM python test/spec_tests.py --spec spec.txt --program PROGRAM
Since this document describes how Markdown is to be parsed into Since this document describes how Markdown is to be parsed into
an abstract syntax tree, it would have made sense to use an abstract an abstract syntax tree, it would have made sense to use an abstract
representation of the syntax tree instead of HTML. But HTML is capable representation of the syntax tree instead of HTML. But HTML is capable
of representing the structural distinctions we need to make, and the of representing the structural distinctions we need to make, and the
choice of HTML for the tests makes it possible to run the tests against choice of HTML for the tests makes it possible to run the tests against
an implementation without writing an abstract syntax tree renderer. an implementation without writing an abstract syntax tree renderer.
Note that not every feature of the HTML samples is mandated by
the spec. For example, the spec says what counts as a link
destination, but it doesn't mandate that non-ASCII characters in
the URL be percent-encoded. To use the automatic tests,
implementers will need to provide a renderer that conforms to
the expectations of the spec examples (percent-encoding
non-ASCII characters in URLs). But a conforming implementation
can use a different renderer and may choose not to
percent-encode non-ASCII characters in URLs.
This document is generated from a text file, `spec.txt`, written This document is generated from a text file, `spec.txt`, written
in Markdown with a small extension for the side-by-side tests. in Markdown with a small extension for the side-by-side tests.
The script `tools/makespec.py` can be used to convert `spec.txt` into The script `tools/makespec.py` can be used to convert `spec.txt` into
HTML or CommonMark (which can then be converted into other formats). HTML or CommonMark (which can then be converted into other formats).
在示例中,使用 `→` 字符来表示制表符(tab)。 在示例中,使用 `→` 字符来表示制表符(tab)。
# 序言 # 序言
## 字符与行 ## 字符与行
skipping to change at line 297 skipping to change at line 307
A [character](@) is a Unicode code point. Although some A [character](@) is a Unicode code point. Although some
码位(例如,组合变音符号)在直觉上并不对应于 码位(例如,组合变音符号)在直觉上并不对应于
字符,但就本规范而言,所有码位都算作字符。 字符,但就本规范而言,所有码位都算作字符。
for purposes of this spec. for purposes of this spec.
本规范未指定编码;它将行视为由 本规范未指定编码;它将行视为由
of [characters] rather than bytes. A conforming parser may be limited of [characters] rather than bytes. A conforming parser may be limited
特定的编码。 特定的编码。
A [line](@) is a sequence of zero or more [characters] A [line](@) is a sequence of zero or more [characters]
other than newline (`U+000A`) or carriage return (`U+000D`), other than line feed (`U+000A`) or carriage return (`U+000D`),
并以 [行结束符] 或文件结束符结尾。 并以 [行结束符] 或文件结束符结尾。
A [line ending](@) is a newline (`U+000A`), a carriage return A [line ending](@) is a line feed (`U+000A`), a carriage return
(`U+000D`) not followed by a newline, or a carriage return and a (`U+000D`) not followed by a line feed, or a carriage return and a
following newline. following line feed.
不包含任何字符的行,或仅包含空格 不包含任何字符的行,或仅包含空格
(`U+0020`) or tabs (`U+0009`), is called a [blank line](@). (`U+0020`) or tabs (`U+0009`), is called a [blank line](@).
本规范将使用以下字符类定义: 本规范将使用以下字符类定义:
A [whitespace character](@) is a space
(`U+0020`)、制表符(`U+0009`)、换行符(`U+000A`)、行制表符(`U+000B`)、
换页符(`U+000C`)或回车符(`U+000D`)。
[Whitespace](@) is a sequence of one or more [whitespace
characters].
A [Unicode whitespace character](@) is A [Unicode whitespace character](@) is
any code point in the Unicode `Zs` general category, or a tab (`U+0009`), any code point in the Unicode `Zs` general category, or a tab (`U+0009`),
回车符(`U+000D`)、换行符(`U+000A`)或换页符 line feed (`U+000A`), form feed (`U+000C`), or carriage return (`U+000D`).
(`U+000C`)。
[Unicode whitespace](@) is a sequence of one [Unicode whitespace](@) is a sequence of one or more
or more [Unicode whitespace characters]. [Unicode whitespace characters].
A [tab](@) is `U+0009`.
A [space](@) is `U+0020`. A [space](@) is `U+0020`.
A [non-whitespace character](@) is any character An [ASCII control character](@) is a character between `U+0000–1F` (both
that is not a [whitespace character]. including) or `U+007F`.
An [ASCII punctuation character](@) An [ASCII punctuation character](@)
是 `!`, `"`, `#`, `$`, `%`, `&`, `'`, `(`, `)`, 是 `!`, `"`, `#`, `$`, `%`, `&`, `'`, `(`, `)`,
`*`, `+`, `,`, `-`, `.`, `/` (U+0021–2F), `*`, `+`, `,`, `-`, `.`, `/` (U+0021–2F),
`:`, `;`, `<`, `=`, `>`, `?`, `@` (U+003A–0040), `:`, `;`, `<`, `=`, `>`, `?`, `@` (U+003A–0040),
`[`, `\`, `]`, `^`, `_`, `` ` `` (U+005B–0060), `[`, `\`, `]`, `^`, `_`, `` ` `` (U+005B–0060),
`{`, `|`, `}`, or `~` (U+007B–007E). `{`, `|`, `}`, or `~` (U+007B–007E).
A [punctuation character](@) is an [ASCII A [Unicode 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,
in contexts where whitespace helps to define block structure, in contexts where spaces help to define block structure,
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
of 4 characters. of 4 characters.
Thus, for example, a tab can be used instead of four spaces Thus, for example, a tab can be used instead of four spaces
in an indented code block. (Note, however, that internal in an indented code block. (Note, however, that internal
tabs are passed through as literal tabs, not expanded to tabs are passed through as literal tabs, not expanded to
spaces.) spaces.)
```````````````````````````````` 示例 ```````````````````````````````` 示例
→foo→baz→→bim →foo→baz→→bim
skipping to change at line 479 skipping to change at line 483
*→*→*→ *→*→*→
. .
<hr /> <hr />
```````````````````````````````` ````````````````````````````````
## 不安全字符 ## 不安全字符
出于安全考虑,Unicode 字符 `U+0000` 必须被替换 出于安全考虑,Unicode 字符 `U+0000` 必须被替换
为替换字符 (`U+FFFD`)。 为替换字符 (`U+FFFD`)。
## Backslash escapes
任何 ASCII 标点字符都可以使用反斜杠转义
```````````````````````````````` 示例
\!\"\#\$\%\&\'\(\)\*\+\,\-\.\/\:\;\<\=\>\?\@\[\\\]\^\_\`\{\|\}\~
.
<p>!&quot;#$%&amp;'()*+,-./:;&lt;=&gt;?@[\]^_`{|}~</p>
````````````````````````````````
Backslashes before other characters are treated as literal
backslashes
```````````````````````````````` 示例
\→\A\a\ \3\φ\«
.
<p>\→\A\a\ \3\φ\«</p>
````````````````````````````````
Escaped characters are treated as regular characters and do
not have their usual Markdown meanings
```````````````````````````````` 示例
\*not emphasized*
\<br/> not a tag
\[not a link](/foo)
\`not code`
1\. not a list
\* not a list
\# not a heading
\[foo]: /url "not a reference"
\&ouml; not a character entity
.
<p>*not emphasized*
&lt;br/&gt; not a tag
[not a link](/foo)
`not code`
1. not a list
* not a list
# not a heading
[foo]: /url &quot;not a reference&quot;
&amp;ouml; not a character entity</p>
````````````````````````````````
如果反斜杠本身被转义,则随后的字符不被转义
```````````````````````````````` 示例
\\*emphasis*
.
<p>\<em>emphasis</em></p>
````````````````````````````````
行末的反斜杠是一个 [硬换行]
```````````````````````````````` 示例
foo\
bar
.
<p>foo<br />
bar</p>
````````````````````````````````
Backslash escapes do not work in code blocks, code spans, autolinks, or
raw HTML
```````````````````````````````` 示例
`` \[\` ``
.
<p><code>\[\`</code></p>
````````````````````````````````
```````````````````````````````` 示例
\[\]
.
<pre><code>\[\]
</code></pre>
````````````````````````````````
```````````````````````````````` 示例
~~~
\[\]
~~~
.
<pre><code>\[\]
</code></pre>
````````````````````````````````
```````````````````````````````` 示例
<http://example.com?find=\*>
.
<p><a href="http://example.com?find=%5C*">http://example.com?find=\*</a></p>
````````````````````````````````
```````````````````````````````` 示例
<a href="/bar\/)">
.
<a href="/bar\/)">
````````````````````````````````
But they work in all other contexts, including URLs and link titles,
link references, and [info strings] in [fenced code blocks]
```````````````````````````````` 示例
[foo](/bar\* "ti\*tle")
.
<p><a href="/bar*" title="ti*tle">foo</a></p>
````````````````````````````````
```````````````````````````````` 示例
[foo]
[foo]: /bar\* "ti\*tle"
.
<p><a href="/bar*" title="ti*tle">foo</a></p>
````````````````````````````````
```````````````````````````````` 示例
``` foo\+bar
foo
```
.
<pre><code class="language-foo+bar">foo
</code></pre>
````````````````````````````````
## Entity and numeric character references
Valid HTML entity references and numeric character references
can be used in place of the corresponding Unicode character,
with the following exceptions
- Entity and character references are not recognized in code
blocks and code spans.
- Entity and character references cannot stand in place of
special characters that define structural elements in
CommonMark. For example, although `&#42;` can be used
in place of a literal `*` character, `&#42;` cannot replace
`*` in emphasis delimiters, bullet list markers, or thematic
breaks.
Conforming CommonMark parsers need not store information about
whether a particular character was represented in the source
using a Unicode character or an entity reference.
[Entity references](@) consist of `&` + any of the valid
[以下文档](https://html.whatwg.cn/multipage/entities.json)
document <https://html.whatwg.cn/entities.json>
is used as an authoritative source for the valid entity
references and their corresponding code points.
```````````````````````````````` 示例
&nbsp; &amp; &copy; &AElig; &Dcaron;
&frac34; &HilbertSpace; &DifferentialD;
&ClockwiseContourIntegral; &ngE;
.
<p>  &amp; © Æ Ď
¾ ℋ ⅆ
∲ ≧̸</p>
````````````````````````````````
[Decimal numeric character
references](@)
consist of `&#` + a string of 1--7 arabic digits + `;`. A
numeric character reference is parsed as the corresponding
Unicode character. Invalid Unicode code points will be replaced by
the REPLACEMENT CHARACTER (`U+FFFD`). For security reasons,
the code point `U+0000` will also be replaced by `U+FFFD`.
```````````````````````````````` 示例
&#35; &#1234; &#992; &#0;
.
<p># Ӓ Ϡ �</p>
````````````````````````````````
[Hexadecimal numeric character
references](@) consist of `&#` +
either `X` or `x` + a string of 1-6 hexadecimal digits + `;`.
They too are parsed as the corresponding Unicode character (this
time specified with a hexadecimal numeral instead of decimal).
```````````````````````````````` 示例
&#X22; &#XD06; &#xcab;
.
<p>&quot; ആ ಫ</p>
````````````````````````````````
这里是一些非实体引用
```````````````````````````````` 示例
&nbsp &x; &#; &#x;
&#87654321;
&#abcdef0;
&ThisIsNotDefined; &hi?;
.
<p>&amp;nbsp &amp;x; &amp;#; &amp;#x;
&amp;#87654321;
&amp;#abcdef0;
&amp;ThisIsNotDefined; &amp;hi?;</p>
````````````````````````````````
Although HTML5 does accept some entity references
without a trailing semicolon (such as `&copy`), these are not
recognized here, because it makes the grammar too ambiguous
```````````````````````````````` 示例
&copy
.
<p>&amp;copy</p>
````````````````````````````````
Strings that are not on the list of HTML5 named entities are not
recognized as entity references either
```````````````````````````````` 示例
&MadeUpEntity;
.
<p>&amp;MadeUpEntity;</p>
````````````````````````````````
Entity and numeric character references are recognized in any
context besides code spans or code blocks, including
URLs, [link titles], and [fenced code block][] [info strings]
```````````````````````````````` 示例
<a href="&ouml;&ouml;.html">
.
<a href="&ouml;&ouml;.html">
````````````````````````````````
```````````````````````````````` 示例
[foo](/f&ouml;&ouml; "f&ouml;&ouml;")
.
<p><a href="/f%C3%B6%C3%B6" title="föö">foo</a></p>
````````````````````````````````
```````````````````````````````` 示例
[foo]
[foo]: /f&ouml;&ouml; "f&ouml;&ouml;"
.
<p><a href="/f%C3%B6%C3%B6" title="föö">foo</a></p>
````````````````````````````````
```````````````````````````````` 示例
``` f&ouml;&ouml;
foo
```
.
<pre><code class="language-föö">foo
</code></pre>
````````````````````````````````
Entity and numeric character references are treated as literal
text in code spans and code blocks
```````````````````````````````` 示例
`f&ouml;&ouml;`
.
<p><code>f&amp;ouml;&amp;ouml;</code></p>
````````````````````````````````
```````````````````````````````` 示例
f&ouml;f&ouml;
.
<pre><code>f&amp;ouml;f&amp;ouml;
</code></pre>
````````````````````````````````
Entity and numeric character references cannot be used
in place of symbols indicating structure in CommonMark
documents.
```````````````````````````````` 示例
&#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>
````````````````````````````````
# 区块与行内元素 # 区块与行内元素
我们可以将文档视为一系列的 我们可以将文档视为一系列的
[区块](@)---即段落、区块引用、 [区块](@)---即段落、区块引用、
列表、标题、分割线和代码块等结构元素。某些区块(例如 列表、标题、分割线和代码块等结构元素。某些区块(例如
block quotes and list items) contain other blocks; others (like block quotes and list items) contain other blocks; others (like
headings and paragraphs) contain [inline](@) content---text, headings and paragraphs) contain [inline](@) content---text,
links, emphasized text, images, code spans, and so on. links, emphasized text, images, code spans, and so on.
## Precedence ## Precedence
skipping to change at line 516 skipping to change at line 832
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
[container blocks](@), [container blocks](#container-blocks),
which can contain other blocks, and [leaf blocks](@), which can contain other blocks, and [leaf blocks](#leaf-blocks),
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
A line consisting of 0-3 spaces of indentation, followed by a sequence A line consisting of optionally up to three spaces of indentation, followed by a
of three or more matching `-`, `_`, or `*` characters, each followed sequence of three or more matching `-`, `_`, or `*` characters, each followed
optionally by any number of spaces or tabs, forms a optionally by any number of spaces or tabs, forms a
[thematic break](@). [thematic break](@).
```````````````````````````````` 示例 ```````````````````````````````` 示例
*** ***
--- ---
___ ___
. .
<hr /> <hr />
<hr /> <hr />
skipping to change at line 568 skipping to change at line 884
```````````````````````````````` 示例 ```````````````````````````````` 示例
-- --
** **
__ __
. .
<p>-- <p>--
** **
__</p> __</p>
```````````````````````````````` ````````````````````````````````
One to three spaces indent are allowed Up to three spaces of indentation are allowed
```````````````````````````````` 示例 ```````````````````````````````` 示例
*** ***
*** ***
*** ***
. .
<hr /> <hr />
<hr /> <hr />
<hr /> <hr />
```````````````````````````````` ````````````````````````````````
四个空格太多了 Four spaces of indentation is too many
```````````````````````````````` 示例 ```````````````````````````````` 示例
*** ***
. .
<pre><code>*** <pre><code>***
</code></pre> </code></pre>
```````````````````````````````` ````````````````````````````````
```````````````````````````````` 示例 ```````````````````````````````` 示例
Foo Foo
skipping to change at line 605 skipping to change at line 921
```````````````````````````````` ````````````````````````````````
可以使用超过三个字符 可以使用超过三个字符
```````````````````````````````` 示例 ```````````````````````````````` 示例
_____________________________________ _____________________________________
. .
<hr /> <hr />
```````````````````````````````` ````````````````````````````````
字符之间允许有空格 Spaces and tabs are allowed between the characters
```````````````````````````````` 示例 ```````````````````````````````` 示例
- - - - - -
. .
<hr /> <hr />
```````````````````````````````` ````````````````````````````````
```````````````````````````````` 示例 ```````````````````````````````` 示例
** * ** * ** * ** ** * ** * ** * **
. .
<hr /> <hr />
```````````````````````````````` ````````````````````````````````
```````````````````````````````` 示例 ```````````````````````````````` 示例
- - - - - - - -
. .
<hr /> <hr />
```````````````````````````````` ````````````````````````````````
末尾允许有空格 Spaces and tabs are allowed at the end
```````````````````````````````` 示例 ```````````````````````````````` 示例
- - - - - - - -
. .
<hr /> <hr />
```````````````````````````````` ````````````````````````````````
然而,行中不能出现其他任何字符 然而,行中不能出现其他任何字符
```````````````````````````````` 示例 ```````````````````````````````` 示例
skipping to change at line 647 skipping to change at line 963
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 characters] be the same. It is required that all of the characters other than spaces or tabs be the same.
So, this is not a thematic break So, this is not a thematic break
```````````````````````````````` 示例 ```````````````````````````````` 示例
*-* *-*
. .
<p><em>-</em></p> <p><em>-</em></p>
```````````````````````````````` ````````````````````````````````
主题分割线之前或之后不需要空行 主题分割线之前或之后不需要空行
skipping to change at line 736 skipping to change at line 1052
</li> </li>
</ul> </ul>
```````````````````````````````` ````````````````````````````````
## ATX headings ## ATX headings
An [ATX heading](@) An [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 must be followed by a The opening sequence of `#` characters must be followed by spaces or tabs, or
[space] or by the end of line. The optional closing sequence of `#`s must be by the end of line. The optional closing sequence of `#`s must be preceded by
preceded by a [space] and may be followed by spaces only. The opening spaces or tabs and may be followed by spaces or tabs only. The opening
`#` character may be indented 0-3 spaces. The raw contents of the `#` character may be preceded by up to three spaces of indentation. The raw
heading are stripped of leading and trailing spaces before being parsed contents of the heading are stripped of leading and trailing space or tabs
as inline content. The heading level is equal to the number of `#` before being parsed as inline content. The heading level is equal to the number
characters in the opening sequence. of `#` characters in the opening sequence.
简单的标题 简单的标题
```````````````````````````````` 示例 ```````````````````````````````` 示例
# foo # foo
## foo ## foo
### foo ### foo
#### foo #### foo
##### foo ##### foo
###### foo ###### foo
skipping to change at line 770 skipping to change at line 1086
```````````````````````````````` ````````````````````````````````
More than six `#` characters is not a heading 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 or tab is required between the `#` characters and the
heading's contents, unless the heading 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
headings headings
```````````````````````````````` 示例 ```````````````````````````````` 示例
#5 bolt #5 bolt
skipping to change at line 803 skipping to change at line 1119
```````````````````````````````` ````````````````````````````````
内容按行内元素解析 内容按行内元素解析
```````````````````````````````` 示例 ```````````````````````````````` 示例
# foo *bar* \*baz\* # foo *bar* \*baz\*
. .
<h1>foo <em>bar</em> *baz*</h1> <h1>foo <em>bar</em> *baz*</h1>
```````````````````````````````` ````````````````````````````````
Leading and trailing [whitespace] is ignored in parsing inline content Leading and trailing spaces or tabs are ignored in parsing inline content
```````````````````````````````` 示例 ```````````````````````````````` 示例
# foo # foo
. .
<h1>foo</h1> <h1>foo</h1>
```````````````````````````````` ````````````````````````````````
One to three spaces indentation are allowed Up to three spaces of indentation are allowed
```````````````````````````````` 示例 ```````````````````````````````` 示例
### foo ### foo
## foo ## foo
# foo # foo
. .
<h3>foo</h3> <h3>foo</h3>
<h2>foo</h2> <h2>foo</h2>
<h1>foo</h1> <h1>foo</h1>
```````````````````````````````` ````````````````````````````````
Four spaces are too much Four spaces of indentation is too many
```````````````````````````````` 示例 ```````````````````````````````` 示例
# foo # foo
. .
<pre><code># foo <pre><code># foo
</code></pre> </code></pre>
```````````````````````````````` ````````````````````````````````
```````````````````````````````` 示例 ```````````````````````````````` 示例
foo foo
skipping to change at line 860 skipping to change at line 1176
它不需要与起始序列长度相同 它不需要与起始序列长度相同
```````````````````````````````` 示例 ```````````````````````````````` 示例
# foo ################################## # foo ##################################
##### foo ## ##### foo ##
. .
<h1>foo</h1> <h1>foo</h1>
<h5>foo</h5> <h5>foo</h5>
```````````````````````````````` ````````````````````````````````
结束序列后允许有空格 Spaces or tabs are allowed after the closing sequence
```````````````````````````````` 示例 ```````````````````````````````` 示例
### foo ### ### foo ###
. .
<h3>foo</h3> <h3>foo</h3>
```````````````````````````````` ````````````````````````````````
A sequence of `#` characters with anything but [spaces] following it A sequence of `#` characters with anything but spaces or tabs following it
不是结尾序列,而是计作标题内容的一部分。 不是结尾序列,而是计作标题内容的一部分。
heading heading
```````````````````````````````` 示例 ```````````````````````````````` 示例
### foo ### b ### foo ### b
. .
<h3>foo ### b</h3> <h3>foo ### b</h3>
```````````````````````````````` ````````````````````````````````
结束序列前必须有一个空格 The closing sequence must be preceded by a space or tab
```````````````````````````````` 示例 ```````````````````````````````` 示例
# foo# # foo#
. .
<h1>foo#</h1> <h1>foo#</h1>
```````````````````````````````` ````````````````````````````````
Backslash-escaped `#` characters do not count as part Backslash-escaped `#` characters do not count as part
of the closing sequence of the closing sequence
skipping to change at line 937 skipping to change at line 1253
### ### ### ###
. .
<h2></h2> <h2></h2>
<h1></h1> <h1></h1>
<h3></h3> <h3></h3>
```````````````````````````````` ````````````````````````````````
## Setext headings ## Setext headings
A [setext heading](@) consists of one or more A [setext heading](@) consists of one or more
lines of text, each containing at least one [non-whitespace lines of text, not interrupted by a blank line, of which the first line does not
character], with no more than 3 spaces indentation, followed by have more than 3 spaces of indentation, followed by
a [setext heading underline]. The lines of text must be such a [setext heading underline]. The lines of text must be such
that, were they not followed by the setext heading underline, that, were they not followed by the setext heading underline,
they would be interpreted as a paragraph: they cannot be they would be interpreted as a paragraph: they cannot be
interpretable as a [code fence], [ATX heading][ATX headings], interpretable as a [code fence], [ATX heading][ATX headings],
[block quote][block quotes], [thematic break][thematic breaks], [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 heading underline](@) is a sequence of A [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 of indentation and any number of trailing spaces or tabs. 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 heading underline]. and not as a [setext heading underline].
The heading is a level 1 heading if `=` characters are used in The heading is a level 1 heading if `=` characters are used in
the [setext heading underline], and a level 2 heading if `-` the [setext heading underline], and a level 2 heading if `-`
characters are used. The contents of the heading are the result characters are used. The contents of the heading are the result
of parsing the preceding lines of text as CommonMark inline of parsing the preceding lines of text as CommonMark inline
content. content.
skipping to change at line 991 skipping to change at line 1307
baz* baz*
==== ====
. .
<h1>Foo <em>bar <h1>Foo <em>bar
baz</em></h1> baz</em></h1>
```````````````````````````````` ````````````````````````````````
The contents are the result of parsing the headings's raw The contents are the result of parsing the headings's raw
content as inlines. The heading's raw content is formed by content as inlines. The heading's raw content is formed by
concatenating the lines and removing initial and final concatenating the lines and removing initial and final
[whitespace]. spaces or tabs.
```````````````````````````````` 示例 ```````````````````````````````` 示例
Foo *bar Foo *bar
baz*→ baz*→
==== ====
. .
<h1>Foo <em>bar <h1>Foo <em>bar
baz</em></h1> baz</em></h1>
```````````````````````````````` ````````````````````````````````
skipping to change at line 1015 skipping to change at line 1331
Foo Foo
------------------------- -------------------------
Foo Foo
= =
. .
<h2>Foo</h2> <h2>Foo</h2>
<h1>Foo</h1> <h1>Foo</h1>
```````````````````````````````` ````````````````````````````````
The heading content can be indented up to three spaces, and need The heading content can be preceded by up to three spaces of indentation, and
not line up with the underlining need not line up with the underlining
```````````````````````````````` 示例 ```````````````````````````````` 示例
Foo Foo
--- ---
Foo Foo
----- -----
Foo Foo
=== ===
. .
<h2>Foo</h2> <h2>Foo</h2>
<h2>Foo</h2> <h2>Foo</h2>
<h1>Foo</h1> <h1>Foo</h1>
```````````````````````````````` ````````````````````````````````
Four spaces indent is too much Four spaces of indentation is too many
```````````````````````````````` 示例 ```````````````````````````````` 示例
Foo Foo
--- ---
Foo Foo
--- ---
. .
<pre><code>Foo <pre><code>Foo
--- ---
Foo Foo
</code></pre> </code></pre>
<hr /> <hr />
```````````````````````````````` ````````````````````````````````
The setext heading underline can be indented up to three spaces, and The setext heading underline can be preceded by up to three spaces of
may have trailing spaces indentation, and may have trailing spaces or tabs
```````````````````````````````` 示例 ```````````````````````````````` 示例
Foo Foo
---- ----
. .
<h2>Foo</h2> <h2>Foo</h2>
```````````````````````````````` ````````````````````````````````
Four spaces is too much Four spaces of indentation is too many
```````````````````````````````` 示例 ```````````````````````````````` 示例
Foo Foo
--- ---
. .
<p>Foo <p>Foo
---</p> ---</p>
```````````````````````````````` ````````````````````````````````
Setext 标题下划线不能包含内部空格 The setext heading underline cannot contain internal spaces or tabs
```````````````````````````````` 示例 ```````````````````````````````` 示例
Foo Foo
= = = =
Foo Foo
--- - --- -
. .
<p>Foo <p>Foo
= =</p> = =</p>
<p>Foo</p> <p>Foo</p>
<hr /> <hr />
```````````````````````````````` ````````````````````````````````
Trailing spaces in the content line do not cause a line break Trailing spaces or tabs in the content line do not cause a hard line break
```````````````````````````````` 示例 ```````````````````````````````` 示例
Foo Foo
----- -----
. .
<h2>Foo</h2> <h2>Foo</h2>
```````````````````````````````` ````````````````````````````````
结尾的反斜杠也不会导致换行 结尾的反斜杠也不会导致换行
skipping to change at line 1332 skipping to change at line 1648
bar bar
--- ---
baz</p> baz</p>
```````````````````````````````` ````````````````````````````````
## Indented code blocks ## Indented code blocks
An [indented code block](@) is composed of one or more An [indented code block](@) is composed of one or more
[indented chunks] separated by blank lines. [indented chunks] separated by blank lines.
An [indented chunk](@) is a sequence of non-blank lines, An [indented chunk](@) is a sequence of non-blank lines,
each indented four or more spaces. The contents of the code block are each preceded by four or more spaces of indentation. The contents of the code
the literal contents of the lines, including trailing block are the literal contents of the lines, including trailing
[line endings], minus four spaces of indentation. [line endings], minus four spaces of indentation.
An indented code block has no [info string]. An indented code block has no [info string].
An indented code block cannot interrupt a paragraph, so there must be An indented code block cannot interrupt a paragraph, so there must be
a blank line between a paragraph and a following indented code block. a blank line between a paragraph and a following indented code block.
(A blank line is not needed, however, between a code block and a following (A blank line is not needed, however, between a code block and a following
paragraph.) paragraph.)
```````````````````````````````` 示例 ```````````````````````````````` 示例
a simple a simple
skipping to change at line 1416 skipping to change at line 1732
chunk3 chunk3
. .
<pre><code>chunk1 <pre><code>chunk1
chunk2 chunk2
chunk3 chunk3
</code></pre> </code></pre>
```````````````````````````````` ````````````````````````````````
Any initial spaces beyond four will be included in the content, even Any initial spaces or tabs beyond four spaces of indentation will be included in
in interior blank lines the content, even in interior blank lines
```````````````````````````````` 示例 ```````````````````````````````` 示例
chunk1 chunk1
chunk2 chunk2
. .
<pre><code>chunk1 <pre><code>chunk1
chunk2 chunk2
</code></pre> </code></pre>
skipping to change at line 1442 skipping to change at line 1758
```````````````````````````````` 示例 ```````````````````````````````` 示例
Foo Foo
bar bar
. .
<p>Foo <p>Foo
bar</p> bar</p>
```````````````````````````````` ````````````````````````````````
However, any non-blank line with fewer than four leading spaces ends However, any non-blank line with fewer than four spaces of indentation ends
the code block immediately. So a paragraph may occur immediately the code block immediately. So a paragraph may occur immediately
after indented code after indented code
```````````````````````````````` 示例 ```````````````````````````````` 示例
foo foo
bar bar
. .
<pre><code>foo <pre><code>foo
</code></pre> </code></pre>
<p>bar</p> <p>bar</p>
skipping to change at line 1475 skipping to change at line 1791
. .
<h1>Heading</h1> <h1>Heading</h1>
<pre><code>foo <pre><code>foo
</code></pre> </code></pre>
<h2>Heading</h2> <h2>Heading</h2>
<pre><code>foo <pre><code>foo
</code></pre> </code></pre>
<hr /> <hr />
```````````````````````````````` ````````````````````````````````
The first line can be indented more than four spaces The first line can be preceded by more than four spaces of indentation
```````````````````````````````` 示例 ```````````````````````````````` 示例
foo foo
bar bar
. .
<pre><code> foo <pre><code> foo
bar bar
</code></pre> </code></pre>
```````````````````````````````` ````````````````````````````````
skipping to change at line 1498 skipping to change at line 1814
```````````````````````````````` 示例 ```````````````````````````````` 示例
foo foo
. .
<pre><code>foo <pre><code>foo
</code></pre> </code></pre>
```````````````````````````````` ````````````````````````````````
末尾空格被包含在代码块的内容中 Trailing spaces or tabs are included in the code block's content
```````````````````````````````` 示例 ```````````````````````````````` 示例
foo foo
. .
<pre><code>foo <pre><code>foo
</code></pre> </code></pre>
```````````````````````````````` ````````````````````````````````
## 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](@)
begins with a code fence, indented no more than three spaces. begins with a code fence, preceded by up to three spaces of indentation.
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
whitespace and called the [info string](@). If the [info string] comes spaces or tabs and called the [info string](@). If the [info string] comes
after a backtick fence, it may not contain any backtick after a backtick fence, it may not contain any backtick
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 preceded by N spaces of indentation, then up to N spaces of indentation are
each line of the content (if present). (If a content line is not removed from each line of the content (if present). (If a content line is not
indented, it is preserved unchanged. If it is indented less than N indented, it is preserved unchanged. If it is indented N spaces or less, all
spaces, all of the indentation is removed.) of the indentation is removed.)
The closing code fence may be indented up to three spaces, and may be The closing code fence may be preceded by up to three spaces of indentation, and
followed only by spaces, which are ignored. If the end of the may be followed only by spaces or tabs, which are ignored. If the end of the
containing block (or document) is reached and no closing code fence containing block (or document) is reached and no closing code fence
has been found, the code block contains all of the lines after the has been found, the code block contains all of the lines after the
opening code fence until the end of the containing block (or opening code fence until the end of the containing block (or
document). (An alternative spec would require backtracking in the document). (An alternative spec would require backtracking in the
event that a closing code fence is not found. But this makes parsing event that a closing code fence is not found. But this makes parsing
much less efficient, and there seems to be no real down side to the much less efficient, and there seems to be no real down side to the
behavior described here.) behavior described here.)
A fenced code block may interrupt a paragraph, and does not require A fenced code block may interrupt a paragraph, and does not require
a blank line either before or after. a blank line either before or after.
skipping to change at line 1732 skipping to change at line 2048
aaa aaa
aaa aaa
``` ```
. .
<pre><code>aaa <pre><code>aaa
aaa aaa
aaa aaa
</code></pre> </code></pre>
```````````````````````````````` ````````````````````````````````
Four spaces indentation produces an indented code block Four spaces of indentation is too many
```````````````````````````````` 示例 ```````````````````````````````` 示例
``` ```
aaa aaa
``` ```
. .
<pre><code>``` <pre><code>```
aaa aaa
``` ```
</code></pre> </code></pre>
```````````````````````````````` ````````````````````````````````
Closing fences may be indented by 0-3 spaces, and their indentation Closing fences may be preceded by up to three spaces of indentation, and their
need not match that of the opening fence indentation need not match that of the opening fence
```````````````````````````````` 示例 ```````````````````````````````` 示例
``` ```
aaa aaa
``` ```
. .
<pre><code>aaa <pre><code>aaa
</code></pre> </code></pre>
```````````````````````````````` ````````````````````````````````
skipping to change at line 1778 skipping to change at line 2094
```````````````````````````````` 示例 ```````````````````````````````` 示例
``` ```
aaa aaa
``` ```
. .
<pre><code>aaa <pre><code>aaa
``` ```
</code></pre> </code></pre>
```````````````````````````````` ````````````````````````````````
代码围栏(起始和关闭)不能包含内部空格 Code fences (opening and closing) cannot contain internal spaces or tabs
```````````````````````````````` 示例 ```````````````````````````````` 示例
``` ``` ``` ```
aaa aaa
. .
<p><code> </code> <p><code> </code>
aaa</p> aaa</p>
```````````````````````````````` ````````````````````````````````
```````````````````````````````` 示例 ```````````````````````````````` 示例
skipping to change at line 1910 skipping to change at line 2226
</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).
There are seven kinds of [HTML block], which can be defined by their There are seven kinds of [HTML block], which can be defined by their
start and end conditions. The block begins with a line that meets a start and end conditions. The block begins with a line that meets a
[start condition](@) (after up to three spaces optional indentation). [start condition](@) (after up to three optional spaces of indentation).
It ends with the first subsequent line that meets a matching [end It ends with the first subsequent line that meets a matching
condition](@), or the last line of the document, or the last line of [end condition](@), or the last line of the document, or the last line of
the [container block](#container-blocks) containing the current HTML the [container block](#container-blocks) containing the current HTML
block, if no line is encountered that meets the [end condition]. If block, if no line is encountered that meets the [end condition]. If
the first line meets both the [start condition] and the [end the first line meets both the [start condition] and the [end
condition], the block will contain just that line. condition], the block will contain just that line.
1. **Start condition:** line begins with the string `<script`, 1. **Start condition:** line begins with the string `<pre`,
`<pre`, or `<style` (case-insensitive), followed by whitespace, `<script`, `<style`, or `<textarea` (case-insensitive), followed by a space,
the string `>`, or the end of the line.\ a tab, the string `>`, or the end of the line.\
**End condition:** line contains an end tag **End condition:** line contains an end tag
`</script>`, `</pre>`, or `</style>` (case-insensitive; it `</pre>`, `</script>`, `</style>`, or `</textarea>` (case-insensitive; it
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 `-->`.
3. **Start condition:** line begins with the string `<?`.\ 3. **Start condition:** line begins with the string `<?`.\
**End condition:** line contains the string `?>`. **End condition:** line contains the string `?>`.
4. **Start condition:** line begins with the string `<!` 4. **Start condition:** line begins with the string `<!`
followed by an uppercase ASCII letter.\ followed by an ASCII letter.\
**End condition:** line contains the character `>`. **End condition:** line contains the character `>`.
5. **开始条件:** 行以字符串 5. **开始条件:** 行以字符串
`<![CDATA[` 开头。\ `<![CDATA[` 开头。\
**结束条件:** 行包含字符串 `]]>`。 **结束条件:** 行包含字符串 `]]>`。
6. **开始条件:** 行以字符串 `<` 或 `</` 开头, 6. **开始条件:** 行以字符串 `<` 或 `</` 开头,
后跟以下字符串之一(不区分大小写):`address`、 后跟以下字符串之一(不区分大小写):`address`、
`article`、`aside`、`base`、`basefont`、`blockquote`、`body`、 `article`、`aside`、`base`、`basefont`、`blockquote`、`body`、
`caption`、`center`、`col`、`colgroup`、`dd`、`details`、`dialog`、 `caption`、`center`、`col`、`colgroup`、`dd`、`details`、`dialog`、
`dir`、`div`、`dl`、`dt`、`fieldset`、`figcaption`、`figure`、 `dir`、`div`、`dl`、`dt`、`fieldset`、`figcaption`、`figure`、
`footer`, `form`, `frame`, `frameset`, `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`,
`nav`, `noframes`, `ol`, `optgroup`, `option`, `p`, `param`, `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`,后跟
by [whitespace], the end of the line, the string `>`, or by a space, a tab, the end of the line, the string `>`, or
字符串 `/>`。\ 字符串 `/>`。\
**结束条件:** 行后紧跟一个 [空行]。 **结束条件:** 行后紧跟一个 [空行]。
7. **Start condition:** line begins with a complete [open tag] 7. **Start condition:** line begins with a complete [open tag]
(with any [tag name] other than `script`, (with any [tag name] other than `pre`, `script`,
`style`, or `pre`) or a complete [closing tag], `style`, or `textarea`) or a complete [closing tag],
followed only by [whitespace] or the end of the line.\ followed by zero or more spaces and tabs, followed by the end of the line.\
**结束条件:** 行后紧跟一个 [空行]。 **结束条件:** 行后紧跟一个 [空行]。
HTML blocks continue until they are closed by their appropriate HTML blocks continue until they are closed by their appropriate
[end condition], or the last line of the document or other [container [end condition], or the last line of the document or other [container
block](#container-blocks). This means any HTML **within an HTML block](#container-blocks). This means any HTML **within an HTML
block** that might otherwise be recognised as a start condition will block** that might otherwise be recognised as a start condition will
be ignored by the parser and passed through as-is, without changing be ignored by the parser and passed through as-is, without changing
the parser's state. the parser's state.
For instance, `<pre>` within a HTML block started by `<table>` will not affect For instance, `<pre>` within an 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**,
_world_. _world_.
</pre> </pre>
</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>
```````````````````````````````` ````````````````````````````````
In this case, the HTML block is terminated by the newline — the `**Hello**` In this case, the HTML block is terminated by the blank line — the `**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
skipping to change at line 2245 skipping to change at line 2561
the tag is not on a line by itself, we get inline HTML the tag is not on a line by itself, we get inline HTML
rather than an [HTML block].) rather than an [HTML block].)
```````````````````````````````` 示例 ```````````````````````````````` 示例
<del>*foo*</del> <del>*foo*</del>
. .
<p><del><em>foo</em></del></p> <p><del><em>foo</em></del></p>
```````````````````````````````` ````````````````````````````````
HTML tags designed to contain literal content HTML tags designed to contain literal content
(`script`, `style`, `pre`), comments, processing instructions, (`pre`, `script`, `style`, `textarea`), comments, processing instructions,
and declarations are treated somewhat differently. and declarations are treated somewhat differently.
Instead of ending at the first blank line, these blocks Instead of ending at the first blank line, these blocks
end at the first line containing a corresponding end tag. end at the first line containing a corresponding end tag.
As a result, these blocks can contain blank lines As a result, these blocks can contain blank lines
pre 标签(第 1 类) pre 标签(第 1 类)
```````````````````````````````` 示例 ```````````````````````````````` 示例
<pre language="haskell"><code> <pre language="haskell"><code>
import Text.HTML.TagSoup import Text.HTML.TagSoup
skipping to change at line 2289 skipping to change at line 2605
okay okay
. .
<script type="text/javascript"> <script type="text/javascript">
// JavaScript example // JavaScript example
document.getElementById("demo").innerHTML = "Hello JavaScript!"; document.getElementById("demo").innerHTML = "Hello JavaScript!";
</script> </script>
<p>okay</p> <p>okay</p>
```````````````````````````````` ````````````````````````````````
一个 textarea 标签(类型 1)
```````````````````````````````` 示例
<textarea>
*foo*
_bar_
</textarea>
.
<textarea>
*foo*
_bar_
</textarea>
````````````````````````````````
style 标签(第 1 类) style 标签(第 1 类)
```````````````````````````````` 示例 ```````````````````````````````` 示例
<style <style
type="text/css"> type="text/css">
h1 {color:red;} h1 {color:red;}
p {color:blue;} p {color:blue;}
</style> </style>
okay okay
skipping to change at line 2455 skipping to change at line 2791
} else { } else {
return 0; return 0;
} }
} }
]]> ]]>
<p>okay</p> <p>okay</p>
```````````````````````````````` ````````````````````````````````
The opening tag can be indented 1-3 spaces, but not 4: The opening tag can be preceded by up to three spaces of indentation, but not
four
```````````````````````````````` 示例 ```````````````````````````````` 示例
<!-- foo --> <!-- foo -->
<!-- foo --> <!-- foo -->
. .
<!-- foo --> <!-- foo -->
<pre><code>&lt;!-- foo --&gt; <pre><code>&lt;!-- foo --&gt;
</code></pre> </code></pre>
```````````````````````````````` ````````````````````````````````
skipping to change at line 2526 skipping to change at line 2863
<a href="bar"> <a href="bar">
baz</p> baz</p>
```````````````````````````````` ````````````````````````````````
This rule differs from John Gruber's original Markdown syntax This rule differs from John Gruber's original Markdown syntax
specification, which says specification, which says
> The only restrictions are that block-level HTML elements — > The only restrictions are that block-level HTML elements —
> e.g. `<div>`, `<table>`, `<pre>`, `<p>`, etc. — must be separated from > e.g. `<div>`, `<table>`, `<pre>`, `<p>`, etc. — must be separated from
> surrounding content by blank lines, and the start and end tags of the > surrounding content by blank lines, and the start and end tags of the
> block should not be indented with tabs or spaces. > block should not be indented with spaces or tabs.
In some ways Gruber's rule is more restrictive than the one given In some ways Gruber's rule is more restrictive than the one given
here here
- It requires that an HTML block be preceded by a blank line. - It requires that an HTML block be preceded by a blank line.
- It does not allow the start tag to be indented. - It does not allow the start tag to be indented.
- It requires a matching end tag, which it also does not allow to - It requires a matching end tag, which it also does not allow to
be indented. be indented.
Most Markdown implementations (including some of Gruber's own) do not Most Markdown implementations (including some of Gruber's own) do not
skipping to change at line 2640 skipping to change at line 2977
```````````````````````````````` ````````````````````````````````
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
[above][HTML blocks], raw HTML blocks starting with `<pre>` [above][HTML blocks], raw HTML blocks starting with `<pre>`
*can* contain blank lines. *can* contain blank lines.
## Link reference definitions ## Link reference definitions
A [link reference definition](@) A [link reference definition](@)
consists of a [link label], indented up to three spaces, followed consists of a [link label], optionally preceded by up to three spaces of
by a colon (`:`), optional [whitespace] (including up to one indentation, followed
by a colon (`:`), optional spaces or tabs (including up to one
[line ending]), a [link destination], [line ending]), a [link destination],
optional [whitespace] (including up to one optional spaces or tabs (including up to one
[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
from the [link destination] by [whitespace]. from the [link destination] by spaces or tabs.
No further [non-whitespace characters] may occur on the line. No further character may occur.
A [link reference definition] A [link reference definition]
does not correspond to a structural element of a document. Instead, it does not correspond to a structural element of a document. Instead, it
defines a label which can be used in [reference links] defines a label which can be used in [reference links]
and reference-style [images] elsewhere in the document. [Link and reference-style [images] elsewhere in the document. [Link
reference definitions] can come either before or after the links that use reference definitions] can come either before or after the links that use
them. them.
```````````````````````````````` 示例 ```````````````````````````````` 示例
[foo]: /url "title" [foo]: /url "title"
skipping to change at line 2758 skipping to change at line 3096
```````````````````````````````` 示例 ```````````````````````````````` 示例
[foo]: <> [foo]: <>
[foo] [foo]
. .
<p><a href="">foo</a></p> <p><a href="">foo</a></p>
```````````````````````````````` ````````````````````````````````
The title must be separated from the link destination by The title must be separated from the link destination by
whitespace: spaces or tabs:
```````````````````````````````` 示例 ```````````````````````````````` 示例
[foo]: <bar>(baz) [foo]: <bar>(baz)
[foo] [foo]
. .
<p>[foo]: <bar>(baz)</p> <p>[foo]: <bar>(baz)</p>
<p>[foo]</p> <p>[foo]</p>
```````````````````````````````` ````````````````````````````````
skipping to change at line 2821 skipping to change at line 3159
```````````````````````````````` ````````````````````````````````
```````````````````````````````` 示例 ```````````````````````````````` 示例
[ΑΓΩ]: /φου [ΑΓΩ]: /φου
[αγω] [αγω]
. .
<p><a href="/%CF%86%CE%BF%CF%85">αγω</a></p> <p><a href="/%CF%86%CE%BF%CF%85">αγω</a></p>
```````````````````````````````` ````````````````````````````````
Here is a link reference definition with no corresponding link. Whether something is a [link reference definition] is
It contributes nothing to the document. independent of whether the link reference it defines is
used in the document. Thus, for example, the following
document contains just a link reference definition, and
no visible content
```````````````````````````````` 示例 ```````````````````````````````` 示例
[foo]: /url [foo]: /url
. .
```````````````````````````````` ````````````````````````````````
这里是另一个 这里是另一个
```````````````````````````````` 示例 ```````````````````````````````` 示例
[ [
foo foo
]: /url ]: /url
bar bar
. .
<p>bar</p> <p>bar</p>
```````````````````````````````` ````````````````````````````````
This is not a link reference definition, because there are This is not a link reference definition, because there are
[non-whitespace characters] after the title characters other than spaces or tabs after the title
```````````````````````````````` 示例 ```````````````````````````````` 示例
[foo]: /url "title" ok [foo]: /url "title" ok
. .
<p>[foo]: /url &quot;title&quot; ok</p> <p>[foo]: /url &quot;title&quot; ok</p>
```````````````````````````````` ````````````````````````````````
这是一个链接引用定义,但它没有标题 这是一个链接引用定义,但它没有标题
```````````````````````````````` 示例 ```````````````````````````````` 示例
skipping to change at line 2965 skipping to change at line 3306
```````````````````````````````` 示例 ```````````````````````````````` 示例
[foo] [foo]
> [foo]: /url > [foo]: /url
. .
<p><a href="/url">foo</a></p> <p><a href="/url">foo</a></p>
<blockquote> <blockquote>
</blockquote> </blockquote>
```````````````````````````````` ````````````````````````````````
Whether something is a [link reference definition] is
independent of whether the link reference it defines is
used in the document. Thus, for example, the following
document contains just a link reference definition, and
no visible content
```````````````````````````````` 示例
[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
[whitespace]. spaces or tabs.
一个有两个段落的简单示例 一个有两个段落的简单示例
```````````````````````````````` 示例 ```````````````````````````````` 示例
aaa aaa
bbb bbb
. .
<p>aaa</p> <p>aaa</p>
<p>bbb</p> <p>bbb</p>
skipping to change at line 3011 skipping to change at line 3341
ccc ccc
ddd ddd
. .
<p>aaa <p>aaa
bbb</p> bbb</p>
<p>ccc <p>ccc
ddd</p> ddd</p>
```````````````````````````````` ````````````````````````````````
段落之间的多个空行无效 Multiple blank lines between paragraphs have no effect
```````````````````````````````` 示例 ```````````````````````````````` 示例
aaa aaa
bbb bbb
. .
<p>aaa</p> <p>aaa</p>
<p>bbb</p> <p>bbb</p>
```````````````````````````````` ````````````````````````````````
前导空格会被忽略 Leading spaces or tabs are skipped
```````````````````````````````` 示例 ```````````````````````````````` 示例
aaa aaa
bbb bbb
. .
<p>aaa <p>aaa
bbb</p> bbb</p>
```````````````````````````````` ````````````````````````````````
Lines after the first may be indented any amount, since indented Lines after the first may be indented any amount, since indented
skipping to change at line 3045 skipping to change at line 3375
```````````````````````````````` 示例 ```````````````````````````````` 示例
aaa aaa
bbb bbb
ccc ccc
. .
<p>aaa <p>aaa
bbb bbb
ccc</p> ccc</p>
```````````````````````````````` ````````````````````````````````
However, the first line may be indented at most three spaces, However, the first line may be preceded by up to three spaces of indentation.
or an indented code block will be triggered: 四个空格的缩进太多了:
```````````````````````````````` 示例 ```````````````````````````````` 示例
aaa aaa
bbb bbb
. .
<p>aaa <p>aaa
bbb</p> bbb</p>
```````````````````````````````` ````````````````````````````````
```````````````````````````````` 示例 ```````````````````````````````` 示例
aaa aaa
bbb bbb
. .
<pre><code>aaa <pre><code>aaa
</code></pre> </code></pre>
<p>bbb</p> <p>bbb</p>
```````````````````````````````` ````````````````````````````````
Final spaces are stripped before inline parsing, so a paragraph Final spaces or tabs are stripped before inline parsing, so a paragraph
that ends with two or more spaces will not end with a [hard line that ends with two or more spaces will not end with a [hard line
break] break]
```````````````````````````````` 示例 ```````````````````````````````` 示例
aaa aaa
bbb bbb
. .
<p>aaa<br /> <p>aaa<br />
bbb</p> bbb</p>
```````````````````````````````` ````````````````````````````````
skipping to change at line 3118 skipping to change at line 3448
> with these blocks as its content. > with these blocks as its content.
So, we explain what counts as a block quote or list item by explaining So, we explain what counts as a block quote or list item by explaining
how these can be *generated* from their contents. This should suffice how these can be *generated* from their contents. This should suffice
to define the syntax, although it does not give a recipe for *parsing* to define the syntax, although it does not give a recipe for *parsing*
these constructions. (A recipe is provided below in the section entitled these constructions. (A recipe is provided below in the section entitled
[A parsing strategy](#appendix-a-parsing-strategy).) [A parsing strategy](#appendix-a-parsing-strategy).)
## Block quotes ## Block quotes
A [block quote marker](@) A [block quote marker](@),
consists of 0-3 spaces of initial indent, plus (a) the character `>` together optionally preceded by up to three spaces of indentation,
with a following space, or (b) a single character `>` not followed by a space. consists of (a) the character `>` together with a following space of
indentation, or (b) a single character `>` not followed by a space of
indentation.
The following rules define [block quotes] The following rules define [block quotes]
1. **Basic case.** If a string of lines *Ls* constitute a sequence 1. **Basic case.** If a string of lines *Ls* constitute a sequence
of blocks *Bs*, then the result of prepending a [block quote of blocks *Bs*, then the result of prepending a [block quote
marker] to the beginning of each line in *Ls* marker] to the beginning of each line in *Ls*
is a [block quote](#block-quotes) containing *Bs*. is a [block quote](#block-quotes) containing *Bs*.
2. **Laziness.** If a string of lines *Ls* constitute a [block 2. **Laziness.** If a string of lines *Ls* constitute a [block
quote](#block-quotes) with contents *Bs*, then the result of deleting quote](#block-quotes) with contents *Bs*, then the result of deleting
the initial [block quote marker] from one or the initial [block quote marker] from one or
more lines in which the next [non-whitespace character] after the [block more lines in which the next character other than a space or tab after the
quote marker] is [paragraph continuation [block quote marker] is [paragraph continuation
text] is a block quote with *Bs* as its content. text] is a block quote with *Bs* as its content.
[Paragraph continuation text](@) is text [Paragraph continuation text](@) is text
that will be parsed as part of the content of a paragraph, but does that will be parsed as part of the content of a paragraph, but does
not occur at the beginning of the paragraph. not occur at the beginning of the paragraph.
3. **Consecutiveness.** A document cannot contain two [block 3. **Consecutiveness.** A document cannot contain two [block
quotes] in a row unless there is a [blank line] between them. quotes] in a row unless there is a [blank line] between them.
Nothing else counts as a [block quote](#block-quotes). Nothing else counts as a [block quote](#block-quotes).
skipping to change at line 3158 skipping to change at line 3490
> bar > bar
> baz > baz
. .
<blockquote> <blockquote>
<h1>Foo</h1> <h1>Foo</h1>
<p>bar <p>bar
baz</p> baz</p>
</blockquote> </blockquote>
```````````````````````````````` ````````````````````````````````
The spaces after the `>` characters can be omitted The space or tab after the `>` characters can be omitted
```````````````````````````````` 示例 ```````````````````````````````` 示例
># Foo ># Foo
>bar >bar
> baz > baz
. .
<blockquote> <blockquote>
<h1>Foo</h1> <h1>Foo</h1>
<p>bar <p>bar
baz</p> baz</p>
</blockquote> </blockquote>
```````````````````````````````` ````````````````````````````````
The `>` characters can be indented 1-3 spaces The `>` characters can be preceded by up to three spaces of indentation
```````````````````````````````` 示例 ```````````````````````````````` 示例
> # Foo > # Foo
> bar > bar
> baz > baz
. .
<blockquote> <blockquote>
<h1>Foo</h1> <h1>Foo</h1>
<p>bar <p>bar
baz</p> baz</p>
</blockquote> </blockquote>
```````````````````````````````` ````````````````````````````````
Four spaces gives us a code block Four spaces of indentation is too many
```````````````````````````````` 示例 ```````````````````````````````` 示例
> # Foo > # Foo
> bar > bar
> baz > baz
. .
<pre><code>&gt; # Foo <pre><code>&gt; # Foo
&gt; bar &gt; bar
&gt; baz &gt; baz
</code></pre> </code></pre>
skipping to change at line 3500 skipping to change at line 3832
<p>foo <p>foo
bar bar
baz</p> baz</p>
</blockquote> </blockquote>
</blockquote> </blockquote>
</blockquote> </blockquote>
```````````````````````````````` ````````````````````````````````
When including an indented code block in a block quote, When including an indented code block in a block quote,
remember that the [block quote marker] includes remember that the [block quote marker] includes
both the `>` and a following space. So *five spaces* are needed after both the `>` and a following space of indentation. So *five spaces* are needed
the `>` after the `>`
```````````````````````````````` 示例 ```````````````````````````````` 示例
> code > code
> not code > not code
. .
<blockquote> <blockquote>
<pre><code>code <pre><code>code
</code></pre> </code></pre>
</blockquote> </blockquote>
skipping to change at line 3534 skipping to change at line 3866
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
blocks *Bs* starting with a [non-whitespace character], and *M* is a blocks *Bs* starting with a character other than a space or tab, and *M* is
list marker of width *W* followed by 1 ≤ *N* ≤ 4 spaces, then the result a list marker of width *W* followed by 1 ≤ *N* ≤ 4 spaces of indentation,
of prepending *M* and the following spaces to the first line of then the result of prepending *M* and the following spaces to the first line
*Ls*, and indenting subsequent lines of *Ls* by *W + N* spaces, is a of 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
a paragraph---that is, when it starts on a line that would a paragraph---that is, when it starts on a line that would
otherwise count as [paragraph continuation text]---then (a) otherwise count as [paragraph continuation text]---then (a)
skipping to change at line 3600 skipping to change at line 3932
<blockquote> <blockquote>
<p>A block quote.</p> <p>A block quote.</p>
</blockquote> </blockquote>
</li> </li>
</ol> </ol>
```````````````````````````````` ````````````````````````````````
The most important thing to notice is that the position of The most important thing to notice is that the position of
the text after the list marker determines how much indentation the text after the list marker determines how much indentation
is needed in subsequent blocks in the list item. If the list is needed in subsequent blocks in the list item. If the list
marker takes up two spaces, and there are three spaces between marker takes up two spaces of indentation, and there are three spaces between
the list marker and the next [non-whitespace character], then blocks the list marker and the next character other than a space or tab, then blocks
must be indented five spaces in order to fall under the list must be indented five spaces in order to fall under the list
item. item.
Here are some examples showing how far content must be indented to be Here are some examples showing how far content must be indented to be
put under the list item put under the list item
```````````````````````````````` 示例 ```````````````````````````````` 示例
- one - one
two two
skipping to change at line 3658 skipping to change at line 3990
. .
<ul> <ul>
<li> <li>
<p>one</p> <p>one</p>
<p>two</p> <p>two</p>
</li> </li>
</ul> </ul>
```````````````````````````````` ````````````````````````````````
It is tempting to think of this in terms of columns: the continuation It is tempting to think of this in terms of columns: the continuation
blocks must be indented at least to the column of the first blocks must be indented at least to the column of the first character other than
[non-whitespace character] after the list marker. However, that is not quite rig ht. a space or tab after the list marker. However, that is not quite right.
The spaces after the list marker determine how much relative indentation The spaces of indentation after the list marker determine how much relative
is needed. Which column this indentation reaches will depend on indentation is needed. Which column this indentation reaches will depend on
how the list item is embedded in other constructions, as shown by how the list item is embedded in other constructions, as shown by
this example this example
```````````````````````````````` 示例 ```````````````````````````````` 示例
> > 1. one > > 1. one
>> >>
>> two >> two
. .
<blockquote> <blockquote>
<blockquote> <blockquote>
skipping to change at line 3706 skipping to change at line 4038
<blockquote> <blockquote>
<blockquote> <blockquote>
<ul> <ul>
<li>one</li> <li>one</li>
</ul> </ul>
<p>two</p> <p>two</p>
</blockquote> </blockquote>
</blockquote> </blockquote>
```````````````````````````````` ````````````````````````````````
Note that at least one space is needed between the list marker and Note that at least one space or tab is needed between the list marker and
any following content, so these are not list items any following content, so these are not list items
```````````````````````````````` 示例 ```````````````````````````````` 示例
-one -one
2.two 2.two
. .
<p>-one</p> <p>-one</p>
<p>2.two</p> <p>2.two</p>
```````````````````````````````` ````````````````````````````````
skipping to change at line 3826 skipping to change at line 4158
```````````````````````````````` 示例 ```````````````````````````````` 示例
-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
block, and *M* is a list marker of width *W* followed by block, and *M* is a list marker of width *W* followed by
one space, then the result of prepending *M* and the following one space of indentation, then the result of prepending *M* and the
space to the first line of *Ls*, and indenting subsequent lines of following space to the first line of *Ls*, and indenting subsequent lines
*Ls* by *W + 1* spaces, is a list item with *Bs* as its contents. of *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.
An indented code block will have to be indented four spaces beyond An indented code block will have to be preceded by four spaces of indentation
the edge of the region where text will be included in the list item. beyond the edge of the region where text will be included in the list item.
In the following case that is 6 spaces In the following case that is 6 spaces
```````````````````````````````` 示例 ```````````````````````````````` 示例
- foo - foo
bar bar
. .
<ul> <ul>
<li> <li>
<p>foo</p> <p>foo</p>
skipping to change at line 3869 skipping to change at line 4201
<ol start="10"> <ol start="10">
<li> <li>
<p>foo</p> <p>foo</p>
<pre><code>bar <pre><code>bar
</code></pre> </code></pre>
</li> </li>
</ol> </ol>
```````````````````````````````` ````````````````````````````````
If the *first* block in the list item is an indented code block, If the *first* block in the list item is an indented code block,
then by rule #2, the contents must be indented *one* space after the then by rule #2, the contents must be preceded by *one* space of indentation
list marker after the list marker
```````````````````````````````` 示例 ```````````````````````````````` 示例
indented code indented code
paragraph paragraph
more code more code
. .
<pre><code>indented code <pre><code>indented code
</code></pre> </code></pre>
skipping to change at line 3904 skipping to change at line 4236
<li> <li>
<pre><code>indented code <pre><code>indented code
</code></pre> </code></pre>
<p>paragraph</p> <p>paragraph</p>
<pre><code>more code <pre><code>more code
</code></pre> </code></pre>
</li> </li>
</ol> </ol>
```````````````````````````````` ````````````````````````````````
Note that an additional space indent is interpreted as space Note that an additional space of indentation is interpreted as space
inside the code block inside the code block
```````````````````````````````` 示例 ```````````````````````````````` 示例
1. indented code 1. indented code
paragraph paragraph
more code more code
. .
<ol> <ol>
skipping to change at line 3927 skipping to change at line 4259
</code></pre> </code></pre>
<p>paragraph</p> <p>paragraph</p>
<pre><code>more code <pre><code>more code
</code></pre> </code></pre>
</li> </li>
</ol> </ol>
```````````````````````````````` ````````````````````````````````
Note that rules #1 and #2 only apply to two cases: (a) cases Note that rules #1 and #2 only apply to two cases: (a) cases
in which the lines to be included in a list item begin with a in which the lines to be included in a list item begin with a
[non-whitespace character], and (b) cases in which characer other than a space or tab, and (b) cases in which
they begin with an indented code they begin with an indented code
block. In a case like the following, where the first block begins with block. In a case like the following, where the first block begins with
a three-space indent, the rules do not allow us to form a list item by three spaces of indentation, the rules do not allow us to form a list item by
indenting the whole thing and prepending a list marker indenting the whole thing and prepending a list marker
```````````````````````````````` 示例 ```````````````````````````````` 示例
foo foo
bar bar
. .
<p>foo</p> <p>foo</p>
<p>bar</p> <p>bar</p>
```````````````````````````````` ````````````````````````````````
skipping to change at line 3953 skipping to change at line 4285
- foo - foo
bar bar
. .
<ul> <ul>
<li>foo</li> <li>foo</li>
</ul> </ul>
<p>bar</p> <p>bar</p>
```````````````````````````````` ````````````````````````````````
This is not a significant restriction, because when a block begins This is not a significant restriction, because when a block is preceded by up to
with 1-3 spaces indent, the indentation can always be removed without three spaces of indentation, the indentation can always be removed without
a change in interpretation, allowing rule #1 to be applied. So, in a change in interpretation, allowing rule #1 to be applied. So, in
the above case the above case
```````````````````````````````` 示例 ```````````````````````````````` 示例
- foo - foo
bar bar
. .
<ul> <ul>
<li> <li>
<p>foo</p> <p>foo</p>
<p>bar</p> <p>bar</p>
</li> </li>
</ul> </ul>
```````````````````````````````` ````````````````````````````````
3. **Item starting with a blank line.** If a sequence of lines *Ls* 3. **Item starting with a blank line.** If a sequence of lines *Ls*
starting with a single [blank line] constitute a (possibly empty) starting with a single [blank line] constitute a (possibly empty)
sequence of blocks *Bs*, not separated from each other by more than sequence of blocks *Bs*, and *M* is a list marker of width *W*,
one blank line, and *M* is a list marker of width *W*,
then the result of prepending *M* to the first line of *Ls*, and then the result of prepending *M* to the first line of *Ls*, and
indenting subsequent lines of *Ls* by *W + 1* spaces, is a list preceding subsequent lines of *Ls* by *W + 1* spaces of indentation, is a
item with *Bs* as its contents. 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.
以下是一些以空行开头但不为空的列表项 以下是一些以空行开头但不为空的列表项
```````````````````````````````` 示例 ```````````````````````````````` 示例
- -
foo foo
skipping to change at line 4049 skipping to change at line 4380
- -
- bar - bar
. .
<ul> <ul>
<li>foo</li> <li>foo</li>
<li></li> <li></li>
<li>bar</li> <li>bar</li>
</ul> </ul>
```````````````````````````````` ````````````````````````````````
It does not matter whether there are spaces following the [list marker] It does not matter whether there are spaces or tabs following the [list marker]
```````````````````````````````` 示例 ```````````````````````````````` 示例
- foo - foo
- -
- bar - bar
. .
<ul> <ul>
<li>foo</li> <li>foo</li>
<li></li> <li></li>
<li>bar</li> <li>bar</li>
skipping to change at line 4103 skipping to change at line 4434
foo foo
1. 1.
. .
<p>foo <p>foo
*</p> *</p>
<p>foo <p>foo
1.</p> 1.</p>
```````````````````````````````` ````````````````````````````````
4. **Indentation.** If a sequence of lines *Ls* constitutes a list item 4. **Indentation.** If a sequence of lines *Ls* constitutes a list item
according to rule #1, #2, or #3, then the result of indenting each line according to rule #1, #2, or #3, then the result of preceding each line
of *Ls* by 1-3 spaces (the same for each line) also constitutes a of *Ls* by up to three spaces of indentation (the same for each line) also
list item with the same contents and attributes. If a line is constitutes a list item with the same contents and attributes. If a line is
empty, then it need not be indented. empty, then it need not be indented.
缩进一个空格 缩进一个空格
```````````````````````````````` 示例 ```````````````````````````````` 示例
1. A paragraph 1. A paragraph
with two lines. with two lines.
indented code indented code
skipping to change at line 4199 skipping to change at line 4530
indented code indented code
&gt; A block quote. &gt; A block quote.
</code></pre> </code></pre>
```````````````````````````````` ````````````````````````````````
5. **Laziness.** If a string of lines *Ls* constitute a [list 5. **Laziness.** If a string of lines *Ls* constitute a [list
item](#list-items) with contents *Bs*, then the result of deleting item](#list-items) with contents *Bs*, then the result of deleting
some or all of the indentation from one or more lines in which the some or all of the indentation from one or more lines in which the
next [non-whitespace character] after the indentation is next character other than a space or tab after the indentation is
[paragraph continuation text] is a [paragraph continuation text] is a
list item with the same contents and attributes. The unindented list item with the same contents and attributes. The unindented
lines are called lines are called
[lazy continuation line](@)s. [lazy continuation line](@)s.
Here is an example with [lazy continuation lines] Here is an example with [lazy continuation lines]
```````````````````````````````` 示例 ```````````````````````````````` 示例
1. A paragraph 1. A paragraph
with two lines. with two lines.
skipping to change at line 4279 skipping to change at line 4610
</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).
The rules for sublists follow from the general rules The rules for sublists follow from the general rules
[above][List items]. A sublist must be indented the same number [above][List items]. A sublist must be indented the same number
of spaces a paragraph would need to be in order to be included of spaces of indentation a paragraph would need to be in order to be included
in the list item. in the list item.
因此,在这种情况下我们需要两个空格的缩进 因此,在这种情况下我们需要两个空格的缩进
```````````````````````````````` 示例 ```````````````````````````````` 示例
- foo - foo
- bar - bar
- baz - baz
- boo - boo
. .
skipping to change at line 4505 skipping to change at line 4836
<li>baz</li> <li>baz</li>
</ul> </ul>
</li> </li>
</ul> </ul>
``` ```
The choice of four spaces is arbitrary. It can be learned, but it is The choice of four spaces is arbitrary. It can be learned, but it is
not likely to be guessed, and it trips up beginners regularly. not likely to be guessed, and it trips up beginners regularly.
Would it help to adopt a two-space rule? The problem is that such Would it help to adopt a two-space rule? The problem is that such
a rule, together with the rule allowing 1--3 spaces indentation of the a rule, together with the rule allowing up to three spaces of indentation for
initial list marker, allows text that is indented *less than* the the initial list marker, allows text that is indented *less than* the
original list marker to be included in the list item. For example, original list marker to be included in the list item. For example,
`Markdown.pl` parses `Markdown.pl` parses
``` markdown ``` markdown
- one - one
two two
``` ```
as a single list item, with `two` a continuation paragraph as a single list item, with `two` a continuation paragraph
skipping to change at line 4890 skipping to change at line 5221
</li> </li>
<li> <li>
<p>b</p> <p>b</p>
</li> </li>
<li> <li>
<p>c</p> <p>c</p>
</li> </li>
</ol> </ol>
```````````````````````````````` ````````````````````````````````
Note, however, that list items may not be indented more than Note, however, that list items may not be preceded by more than
three spaces. Here `- e` is treated as a paragraph continuation three spaces of indentation. Here `- e` is treated as a paragraph continuation
line, because it is indented more than three spaces line, because it is indented more than three spaces
```````````````````````````````` 示例 ```````````````````````````````` 示例
- a - a
- b - b
- c - c
- d - d
- e - e
. .
<ul> <ul>
skipping to change at line 4974 skipping to change at line 5305
<li> <li>
<p>a</p> <p>a</p>
</li> </li>
<li></li> <li></li>
<li> <li>
<p>c</p> <p>c</p>
</li> </li>
</ul> </ul>
```````````````````````````````` ````````````````````````````````
These are loose lists, even though there is no space between the items, These are loose lists, even though there are no blank lines between the items,
because one of the items directly contains two block-level elements because one of the items directly contains two block-level elements
with a blank line between them with a blank line between them
```````````````````````````````` 示例 ```````````````````````````````` 示例
- a - a
- b - b
c c
- d - d
. .
skipping to change at line 5209 skipping to change at line 5540
```````````````````````````````` 示例 ```````````````````````````````` 示例
`hi`lo` `hi`lo`
. .
<p><code>hi</code>lo`</p> <p><code>hi</code>lo`</p>
```````````````````````````````` ````````````````````````````````
`hi` is parsed as code, leaving the backtick at the end as a literal `hi` is parsed as code, leaving the backtick at the end as a literal
backtick. backtick.
## Backslash escapes
任何 ASCII 标点字符都可以使用反斜杠转义
```````````````````````````````` 示例
\!\"\#\$\%\&\'\(\)\*\+\,\-\.\/\:\;\<\=\>\?\@\[\\\]\^\_\`\{\|\}\~
.
<p>!&quot;#$%&amp;'()*+,-./:;&lt;=&gt;?@[\]^_`{|}~</p>
````````````````````````````````
Backslashes before other characters are treated as literal
backslashes
```````````````````````````````` 示例
\→\A\a\ \3\φ\«
.
<p>\→\A\a\ \3\φ\«</p>
````````````````````````````````
Escaped characters are treated as regular characters and do
not have their usual Markdown meanings
```````````````````````````````` 示例
\*not emphasized*
\<br/> not a tag
\[not a link](/foo)
\`not code`
1\. not a list
\* not a list
\# not a heading
\[foo]: /url "not a reference"
\&ouml; not a character entity
.
<p>*not emphasized*
&lt;br/&gt; not a tag
[not a link](/foo)
`not code`
1. not a list
* not a list
# not a heading
[foo]: /url &quot;not a reference&quot;
&amp;ouml; not a character entity</p>
````````````````````````````````
如果反斜杠本身被转义,则随后的字符不被转义
```````````````````````````````` 示例
\\*emphasis*
.
<p>\<em>emphasis</em></p>
````````````````````````````````
行末的反斜杠是一个 [硬换行]
```````````````````````````````` 示例
foo\
bar
.
<p>foo<br />
bar</p>
````````````````````````````````
Backslash escapes do not work in code blocks, code spans, autolinks, or
raw HTML
```````````````````````````````` 示例
`` \[\` ``
.
<p><code>\[\`</code></p>
````````````````````````````````
```````````````````````````````` 示例
\[\]
.
<pre><code>\[\]
</code></pre>
````````````````````````````````
```````````````````````````````` 示例
~~~
\[\]
~~~
.
<pre><code>\[\]
</code></pre>
````````````````````````````````
```````````````````````````````` 示例
<http://example.com?find=\*>
.
<p><a href="http://example.com?find=%5C*">http://example.com?find=\*</a></p>
````````````````````````````````
```````````````````````````````` 示例
<a href="/bar\/)">
.
<a href="/bar\/)">
````````````````````````````````
But they work in all other contexts, including URLs and link titles,
link references, and [info strings] in [fenced code blocks]
```````````````````````````````` 示例
[foo](/bar\* "ti\*tle")
.
<p><a href="/bar*" title="ti*tle">foo</a></p>
````````````````````````````````
```````````````````````````````` 示例
[foo]
[foo]: /bar\* "ti\*tle"
.
<p><a href="/bar*" title="ti*tle">foo</a></p>
````````````````````````````````
```````````````````````````````` 示例
``` foo\+bar
foo
```
.
<pre><code class="language-foo+bar">foo
</code></pre>
````````````````````````````````
## Entity and numeric character references
Valid HTML entity references and numeric character references
can be used in place of the corresponding Unicode character,
with the following exceptions
- Entity and character references are not recognized in code
blocks and code spans.
- Entity and character references cannot stand in place of
special characters that define structural elements in
CommonMark. For example, although `&#42;` can be used
in place of a literal `*` character, `&#42;` cannot replace
`*` in emphasis delimiters, bullet list markers, or thematic
breaks.
Conforming CommonMark parsers need not store information about
whether a particular character was represented in the source
using a Unicode character or an entity reference.
[Entity references](@) consist of `&` + any of the valid
[以下文档](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
references and their corresponding code points.
```````````````````````````````` 示例
&nbsp; &amp; &copy; &AElig; &Dcaron;
&frac34; &HilbertSpace; &DifferentialD;
&ClockwiseContourIntegral; &ngE;
.
<p>  &amp; © Æ Ď
¾ ℋ ⅆ
∲ ≧̸</p>
````````````````````````````````
[Decimal numeric character
references](@)
consist of `&#` + a string of 1--7 arabic digits + `;`. A
numeric character reference is parsed as the corresponding
Unicode character. Invalid Unicode code points will be replaced by
the REPLACEMENT CHARACTER (`U+FFFD`). For security reasons,
the code point `U+0000` will also be replaced by `U+FFFD`.
```````````````````````````````` 示例
&#35; &#1234; &#992; &#0;
.
<p># Ӓ Ϡ �</p>
````````````````````````````````
[Hexadecimal numeric character
references](@) consist of `&#` +
either `X` or `x` + a string of 1-6 hexadecimal digits + `;`.
They too are parsed as the corresponding Unicode character (this
time specified with a hexadecimal numeral instead of decimal).
```````````````````````````````` 示例
&#X22; &#XD06; &#xcab;
.
<p>&quot; ആ ಫ</p>
````````````````````````````````
这里是一些非实体引用
```````````````````````````````` 示例
&nbsp &x; &#; &#x;
&#987654321;
&#abcdef0;
&ThisIsNotDefined; &hi?;
.
<p>&amp;nbsp &amp;x; &amp;#; &amp;#x;
&amp;#987654321;
&amp;#abcdef0;
&amp;ThisIsNotDefined; &amp;hi?;</p>
````````````````````````````````
Although HTML5 does accept some entity references
without a trailing semicolon (such as `&copy`), these are not
recognized here, because it makes the grammar too ambiguous
```````````````````````````````` 示例
&copy
.
<p>&amp;copy</p>
````````````````````````````````
Strings that are not on the list of HTML5 named entities are not
recognized as entity references either
```````````````````````````````` 示例
&MadeUpEntity;
.
<p>&amp;MadeUpEntity;</p>
````````````````````````````````
Entity and numeric character references are recognized in any
context besides code spans or code blocks, including
URLs, [link titles], and [fenced code block][] [info strings]
```````````````````````````````` 示例
<a href="&ouml;&ouml;.html">
.
<a href="&ouml;&ouml;.html">
````````````````````````````````
```````````````````````````````` 示例
[foo](/f&ouml;&ouml; "f&ouml;&ouml;")
.
<p><a href="/f%C3%B6%C3%B6" title="föö">foo</a></p>
````````````````````````````````
```````````````````````````````` 示例
[foo]
[foo]: /f&ouml;&ouml; "f&ouml;&ouml;"
.
<p><a href="/f%C3%B6%C3%B6" title="föö">foo</a></p>
````````````````````````````````
```````````````````````````````` 示例
``` f&ouml;&ouml;
foo
```
.
<pre><code class="language-föö">foo
</code></pre>
````````````````````````````````
Entity and numeric character references are treated as literal
text in code spans and code blocks
```````````````````````````````` 示例
`f&ouml;&ouml;`
.
<p><code>f&amp;ouml;&amp;ouml;</code></p>
````````````````````````````````
```````````````````````````````` 示例
f&ouml;f&ouml;
.
<pre><code>f&amp;ouml;f&amp;ouml;
</code></pre>
````````````````````````````````
Entity and numeric character references cannot be used
in place of symbols indicating structure in CommonMark
documents.
```````````````````````````````` 示例
&#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
the characters between the two backtick strings, normalized in the the characters between these two backtick strings, normalized in the
following ways following ways
- First, [line endings] are converted to [spaces]. - First, [line endings] are converted to [spaces].
- If the resulting string both begins *and* ends with a [space] - If the resulting string both begins *and* ends with a [space]
character, but does not consist entirely of [space] character, but does not consist entirely of [space]
characters, a single [space] character is removed from the characters, a single [space] character is removed from the
front and back. This allows you to include code that begins front and back. This allows you to include code that begins
or ends with backtick characters, which must be separated by or ends with backtick characters, which must be separated by
whitespace from the opening or closing backtick strings. whitespace from the opening or closing backtick strings.
skipping to change at line 5793 skipping to change at line 5812
使用不需要回溯的高效解析策略。 使用不需要回溯的高效解析策略。
First, some definitions. A [delimiter run](@) is either First, some definitions. A [delimiter run](@) is either
一个或多个 `*` 字符组成的序列,且其前后没有 一个或多个 `*` 字符组成的序列,且其前后没有
followed by a non-backslash-escaped `*` character, or a sequence followed by a non-backslash-escaped `*` character, or a sequence
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 [delimiter run] that is (1) not followed by [Unicode whitespace], a [delimiter run] that is (1) not followed by [Unicode whitespace],
and either (2a) not followed by a [punctuation character], or and either (2a) not followed by a [Unicode punctuation character], or
(2b) followed by a [punctuation character] and (2b) followed by a [Unicode punctuation character] and
preceded by [Unicode whitespace] or a [punctuation character]. preceded by [Unicode whitespace] or a [Unicode 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 [delimiter run] that is (1) not preceded by [Unicode whitespace], a [delimiter run] that is (1) not preceded by [Unicode whitespace],
and either (2a) not preceded by a [punctuation character], or and either (2a) not preceded by a [Unicode punctuation character], or
(2b) preceded by a [punctuation character] and (2b) preceded by a [Unicode punctuation character] and
followed by [Unicode whitespace] or a [punctuation character]. followed by [Unicode whitespace] or a [Unicode punctuation character].
就此定义而言,行的开头和结尾 就此定义而言,行的开头和结尾
the line count as Unicode whitespace. the line count as Unicode whitespace.
以下是一些定界符序列的示例。 以下是一些定界符序列的示例。
- 左侧分隔但非右侧分隔 - 左侧分隔但非右侧分隔
``` ```
***abc ***abc
_abc _abc
skipping to change at line 5858 skipping to change at line 5877
以下规则定义了强调和强强调。 以下规则定义了强调和强强调。
1. A single `*` character [can open emphasis](@) 1. A single `*` character [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 delimiter run] or (b) part of a [right-flanking delimiter run]
preceded by punctuation. preceded by a [Unicode punctuation character].
3. A single `*` character [can close emphasis](@) 3. A single `*` character [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 delimiter run] or (b) part of a [left-flanking delimiter run]
followed by punctuation. followed by a [Unicode punctuation character].
5. A double `**` [can open strong emphasis](@) 5. A double `**` [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 delimiter run] or (b) part of a [right-flanking delimiter run]
preceded by punctuation. preceded by a [Unicode punctuation character].
7. A double `**` [can close strong emphasis](@) 7. A double `**` [can close strong emphasis](@)
当且仅当它是 [右侧定界符序列] 的一部分时。 当且仅当它是 [右侧定界符序列] 的一部分时。
8. A double `__` [can close strong emphasis] iff 8. A double `__` [can close strong 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 delimiter run] or (b) part of a [left-flanking delimiter run]
followed by punctuation. followed by a [Unicode punctuation character].
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
open and close emphasis, then the sum of the lengths of the open and close emphasis, then the sum of the lengths of the
delimiter runs containing the opening and closing delimiters delimiter runs containing the opening and closing delimiters
must not be a multiple of 3 unless both lengths are must not be a multiple of 3 unless both lengths are
multiples of 3. multiples of 3.
skipping to change at line 6081 skipping to change at line 6100
This is not emphasis, because the closing `*` is preceded by This is not emphasis, because the closing `*` is preceded by
whitespace whitespace
```````````````````````````````` 示例 ```````````````````````````````` 示例
*foo bar * *foo bar *
. .
<p>*foo bar *</p> <p>*foo bar *</p>
```````````````````````````````` ````````````````````````````````
A newline also counts as whitespace A line ending also counts as whitespace
```````````````````````````````` 示例 ```````````````````````````````` 示例
*foo bar *foo bar
* *
. .
<p>*foo bar <p>*foo bar
*</p> *</p>
```````````````````````````````` ````````````````````````````````
这不是强调,因为第二个 `*` 这不是强调,因为第二个 `*`
skipping to change at line 6228 skipping to change at line 6247
This is not strong emphasis, because the opening delimiter is This is not strong emphasis, because the opening delimiter is
后跟空白字符 后跟空白字符
```````````````````````````````` 示例 ```````````````````````````````` 示例
__ foo bar__ __ foo bar__
. .
<p>__ foo bar__</p> <p>__ foo bar__</p>
```````````````````````````````` ````````````````````````````````
A newline counts as whitespace A line ending counts as whitespace
```````````````````````````````` 示例 ```````````````````````````````` 示例
__ __
foo bar__ foo bar__
. .
<p>__ <p>__
foo bar__</p> foo bar__</p>
```````````````````````````````` ````````````````````````````````
This is not strong emphasis, because the opening `__` is preceded This is not strong emphasis, because the opening `__` is preceded
一个字母数字,后面是标点符号 一个字母数字,后面是标点符号
skipping to change at line 6477 skipping to change at line 6496
emphasis sections in this example emphasis sections in this example
```````````````````````````````` 示例 ```````````````````````````````` 示例
*foo**bar* *foo**bar*
. .
<p><em>foo**bar</em></p> <p><em>foo**bar</em></p>
```````````````````````````````` ````````````````````````````````
The same condition ensures that the following The same condition ensures that the following
情况都是强调内部嵌套的强强调, 情况都是强调内部嵌套的强强调,
emphasis, even when the interior spaces are emphasis, even when the interior whitespace is
omitted omitted
```````````````````````````````` 示例 ```````````````````````````````` 示例
***foo** bar* ***foo** bar*
. .
<p><em><strong>foo</strong> bar</em></p> <p><em><strong>foo</strong> bar</em></p>
```````````````````````````````` ````````````````````````````````
```````````````````````````````` 示例 ```````````````````````````````` 示例
*foo **bar*** *foo **bar***
skipping to change at line 6980 skipping to change at line 6999
than the brackets in link text. Thus, for example, than the brackets in link text. Thus, for example,
`` [foo`]` `` could not be a link text, since the second `]` `` [foo`]` `` could not be a link text, since the second `]`
is part of a code span. is part of a code span.
- The brackets in link text bind more tightly than markers for - The brackets in link text bind more tightly than markers for
因此,例如,`*[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
closing `>` that contains no line breaks or unescaped closing `>` that contains no line endings or unescaped
`<` or `>` characters, or `<` or `>` characters, or
- a nonempty sequence of characters that does not start with - a nonempty sequence of characters that does not start with `<`,
`<`, does not include ASCII space or control characters, and does not include [ASCII control characters][ASCII control character]
includes parentheses only if (a) they are backslash-escaped or or [space] character, and includes parentheses only if (a) they are
(b) they are part of a balanced pair of unescaped parentheses. backslash-escaped or (b) they are part of a balanced pair of
unescaped parentheses.
(Implementations may impose limits on parentheses nesting to (Implementations may impose limits on parentheses nesting to
avoid performance issues, but at least three levels of nesting avoid performance issues, but at least three levels of nesting
should be supported.) should be supported.)
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
skipping to change at line 7009 skipping to change at line 7029
backslash-escaped, or backslash-escaped, or
- 匹配括号(`(...)`)之间的一个或多个字符序列, - 匹配括号(`(...)`)之间的一个或多个字符序列,
(`(...)`), including a `(` or `)` character only if it is (`(...)`), including a `(` or `)` character only if it is
backslash-escaped. backslash-escaped.
Although [link titles] may span multiple lines, they may not contain Although [link titles] may span multiple lines, they may not contain
[空行]。 [空行]。
[内联链接](@)由[链接文本]紧接着一个左括号`(`、 [内联链接](@)由[链接文本]紧接着一个左括号`(`、
by a left parenthesis `(`, optional [whitespace], an optional by a left parenthesis `(`, an optional [link destination], an optional
[link destination], an optional [link title] separated from the link [link title], and a right parenthesis `)`.
链接的文本由[链接文本]中包含的内联内容组成 These four components may be separated by spaces, tabs, and up to one line
链接的文本由[链接文本]中包含的内联内容组成 ending.
If both [link destination] and [link title] are present, they *must* be
separated by spaces, tabs, and up to one line ending.
The link's text consists of the inlines contained
(不包括封闭的方括号)。 (不包括封闭的方括号)。
The link's URI consists of the link destination, excluding enclosing The link's URI consists of the link destination, excluding enclosing
`<...>` if present, with backslash-escapes in effect as described `<...>` if present, with backslash-escapes in effect as described
above. The link's title consists of the link title, excluding its above. The link's title consists of the link title, excluding its
enclosing delimiters, with backslash-escapes in effect as described enclosing delimiters, with backslash-escapes in effect as described
above. above.
这是一个简单的行内链接: 这是一个简单的行内链接:
```````````````````````````````` 示例 ```````````````````````````````` 示例
[link](/uri "title") [link](/uri "title")
. .
<p><a href="/uri" title="title">link</a></p> <p><a href="/uri" title="title">link</a></p>
```````````````````````````````` ````````````````````````````````
The title may be omitted: The title, the link text and even
the destination may be omitted
```````````````````````````````` 示例 ```````````````````````````````` 示例
[link](/uri) [link](/uri)
. .
<p><a href="/uri">link</a></p> <p><a href="/uri">link</a></p>
```````````````````````````````` ````````````````````````````````
标题和目标均可省略。 ```````````````````````````````` 示例
[](./target.md)
.
<p><a href="./target.md"></a></p>
````````````````````````````````
```````````````````````````````` 示例 ```````````````````````````````` 示例
[link]() [link]()
. .
<p><a href="">链接</a></p> <p><a href="">链接</a></p>
```````````````````````````````` ````````````````````````````````
```````````````````````````````` 示例 ```````````````````````````````` 示例
[链接](<>) [链接](<>)
. .
<p><a href="">链接</a></p> <p><a href="">链接</a></p>
```````````````````````````````` ````````````````````````````````
```````````````````````````````` 示例
[]()
.
<p><a href=""></a></p>
````````````````````````````````
The destination can only contain spaces if it is The destination can only contain spaces if it is
enclosed in pointy brackets enclosed in pointy brackets
```````````````````````````````` 示例 ```````````````````````````````` 示例
[链接](/我的 URI) [链接](/我的 URI)
. .
<p>[链接](/我的 URI)</p> <p>[链接](/我的 URI)</p>
```````````````````````````````` ````````````````````````````````
```````````````````````````````` 示例 ```````````````````````````````` 示例
[链接](</我的 URI>) [链接](</我的 URI>)
. .
<p><a href="/my%20uri">link</a></p> <p><a href="/my%20uri">link</a></p>
```````````````````````````````` ````````````````````````````````
The destination cannot contain line breaks, The destination cannot contain line endings,
even if enclosed in pointy brackets even if enclosed in pointy brackets
```````````````````````````````` 示例 ```````````````````````````````` 示例
[link](foo [link](foo
bar) bar)
. .
<p>[link](foo <p>[link](foo
bar)</p> bar)</p>
```````````````````````````````` ````````````````````````````````
skipping to change at line 7135 skipping to change at line 7170
```````````````````````````````` 示例 ```````````````````````````````` 示例
[link](foo(and(bar))) [link](foo(and(bar)))
. .
<p><a href="foo(and(bar))">link</a></p> <p><a href="foo(and(bar))">link</a></p>
```````````````````````````````` ````````````````````````````````
However, if you have unbalanced parentheses, you need to escape or use the However, if you have unbalanced parentheses, you need to escape or use the
`<...>` form `<...>` form
```````````````````````````````` 示例 ```````````````````````````````` 示例
[link](foo(and(bar))
.
<p>[link](foo(and(bar))</p>
````````````````````````````````
```````````````````````````````` 示例
[link](foo\(and\(bar\)) [link](foo\(and\(bar\))
. .
<p><a href="foo(and(bar)">link</a></p> <p><a href="foo(and(bar)">link</a></p>
```````````````````````````````` ````````````````````````````````
```````````````````````````````` 示例 ```````````````````````````````` 示例
[link](<foo(and(bar)>) [link](<foo(and(bar)>)
. .
<p><a href="foo(and(bar)">link</a></p> <p><a href="foo(and(bar)">link</a></p>
```````````````````````````````` ````````````````````````````````
skipping to change at line 7224 skipping to change at line 7265
Backslash escapes and entity and numeric character references Backslash escapes and entity and numeric character references
may be used in titles may be used in titles
```````````````````````````````` 示例 ```````````````````````````````` 示例
[link](/url "title \"&quot;") [link](/url "title \"&quot;")
. .
<p><a href="/url" title="title &quot;&quot;">link</a></p> <p><a href="/url" title="title &quot;&quot;">link</a></p>
```````````````````````````````` ````````````````````````````````
Titles must be separated from the link using a [whitespace]. Titles must be separated from the link using spaces, tabs, and up to one line
ending.
Other [Unicode whitespace] like non-breaking space doesn't work. Other [Unicode whitespace] like non-breaking space doesn't work.
```````````````````````````````` 示例 ```````````````````````````````` 示例
[link](/url "title") [link](/url "title")
. .
<p><a href="/url%C2%A0%22title%22">link</a></p> <p><a href="/url%C2%A0%22title%22">link</a></p>
```````````````````````````````` ````````````````````````````````
除非经过转义,否则不允许嵌套平衡的引号。 除非经过转义,否则不允许嵌套平衡的引号。
skipping to change at line 7264 skipping to change at line 7306
quote type for the enclosing title---to write titles containing quote type for the enclosing title---to write titles containing
double quotes. `Markdown.pl`'s handling of titles has a number double quotes. `Markdown.pl`'s handling of titles has a number
of other strange features. For example, it allows single-quoted of other strange features. For example, it allows single-quoted
titles in inline links, but not reference links. And, in titles in inline links, but not reference links. And, in
reference links but not inline links, it allows a title to begin reference links but not inline links, it allows a title to begin
with `"` and end with `)`. `Markdown.pl` 1.0.1 even allows with `"` and end with `)`. `Markdown.pl` 1.0.1 even allows
titles with no closing quotation mark, though 1.0.2b8 does not. titles with no closing quotation mark, though 1.0.2b8 does not.
It seems preferable to adopt a simple, rational rule that works It seems preferable to adopt a simple, rational rule that works
the same way in inline links and link reference definitions.) the same way in inline links and link reference definitions.)
[Whitespace] is allowed around the destination and title Spaces, tabs, and up to one line ending 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>
```````````````````````````````` ````````````````````````````````
But it is not allowed between the link text and the But it is not allowed between the link text and the
following parenthesis following parenthesis
skipping to change at line 7398 skipping to change at line 7441
There are three kinds of [reference link](@)s There are three kinds of [reference link](@)s
[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).
A [full reference link](@) A [full reference link](@)
consists of a [link text] immediately followed by 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.
A [link label](@) begins with a left bracket (`[`) and ends A [link label](@) begins with a left bracket (`[`) and ends
并以第一个未被反斜杠转义的右方括号(`]`)结束。 并以第一个未被反斜杠转义的右方括号(`]`)结束。
Between these brackets there must be at least one [non-whitespace character]. Between these brackets there must be at least one character that is not a space,
tab, or line ending.
Unescaped square bracket characters are not allowed inside the Unescaped square bracket characters are not allowed inside the
opening and closing square brackets of [link labels]. A link opening and closing square brackets of [link labels]. A link
label can have at most 999 characters inside the square label can have at most 999 characters inside the square
brackets. brackets.
One label [matches](@) One label [matches](@)
另一个。要归一化一个标签,执行 *unicode 大小写折叠* 并将连续的内部 另一个。要归一化一个标签,执行 *unicode 大小写折叠* 并将连续的内部
label, strip off the opening and closing brackets, label, strip off the opening and closing brackets,
perform the *Unicode case fold*, strip leading and trailing perform the *Unicode case fold*, strip leading and trailing
[whitespace] and collapse consecutive internal spaces, tabs, and line endings, and collapse consecutive internal
[whitespace] to a single space. If there are multiple spaces, tabs, and line endings to a single space. If there are multiple
(在这种情况下,发出警告是可取的。) (在这种情况下,发出警告是可取的。)
第一个链接标签的内容被解析为行内内容, 第一个链接标签的内容被解析为行内内容,
The contents of the first link label are parsed as inlines, which are The link's URI and title are provided by the matching [link
匹配的 [链接引用定义] 提供。 reference definition].
matching [link reference definition].
这是一个简单的例子 这是一个简单的例子
```````````````````````````````` 示例 ```````````````````````````````` 示例
[foo][bar] [foo][bar]
[bar]: /url "title" [bar]: /url "title"
. .
<p><a href="/url" title="title">foo</a></p> <p><a href="/url" title="title">foo</a></p>
```````````````````````````````` ````````````````````````````````
skipping to change at line 7500 skipping to change at line 7543
```````````````````````````````` 示例 ```````````````````````````````` 示例
*[foo*][ref] *[foo*][ref]
[ref]: /uri [ref]: /uri
. .
<p>*<a href="/uri">foo*</a></p> <p>*<a href="/uri">foo*</a></p>
```````````````````````````````` ````````````````````````````````
```````````````````````````````` 示例 ```````````````````````````````` 示例
[foo *bar][ref] [foo *bar][ref]*
[ref]: /uri [ref]: /uri
. .
<p><a href="/uri">foo *bar</a></p> <p><a href="/uri">foo *bar</a>*</p>
```````````````````````````````` ````````````````````````````````
These cases illustrate the precedence of HTML tags, code spans, These cases illustrate the precedence of HTML tags, code spans,
and autolinks over link grouping and autolinks over link grouping
```````````````````````````````` 示例 ```````````````````````````````` 示例
[foo <bar attr="][ref]"> [foo <bar attr="][ref]">
[ref]: /uri [ref]: /uri
. .
skipping to change at line 7547 skipping to change at line 7590
[foo][BaR] [foo][BaR]
[bar]: /url "title" [bar]: /url "title"
. .
<p><a href="/url" title="title">foo</a></p> <p><a href="/url" title="title">foo</a></p>
```````````````````````````````` ````````````````````````````````
使用 Unicode 大小写折叠。 使用 Unicode 大小写折叠。
```````````````````````````````` 示例 ```````````````````````````````` 示例
[Толпой][Толпой] is a Russian word. [ẞ]
[ТОЛПОЙ]: /url [SS]: /url
. .
<p><a href="/url">Толпой</a> is a Russian word.</p> <p><a href="/url">ẞ</a></p>
```````````````````````````````` ````````````````````````````````
Consecutive internal [whitespace] is treated as one space for Consecutive internal spaces, tabs, and line endings are treated as one space for
purposes of determining matching purposes of determining matching
```````````````````````````````` 示例 ```````````````````````````````` 示例
[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>
```````````````````````````````` ````````````````````````````````
No [whitespace] is allowed between the [link text] and the No spaces, tabs, or line endings are allowed between the [link text] and the
[link label] [link label]
```````````````````````````````` 示例 ```````````````````````````````` 示例
[foo] [bar] [foo] [bar]
[bar]: /url "title" [bar]: /url "title"
. .
<p>[foo] <a href="/url" title="title">bar</a></p> <p>[foo] <a href="/url" title="title">bar</a></p>
```````````````````````````````` ````````````````````````````````
skipping to change at line 7687 skipping to change at line 7730
Note that in this example `]` is not backslash-escaped Note that in this example `]` is not backslash-escaped
```````````````````````````````` 示例 ```````````````````````````````` 示例
[bar\\]: /uri [bar\\]: /uri
[bar\\] [bar\\]
. .
<p><a href="/uri">bar\</a></p> <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 character that is not a space, tab, or
line ending
```````````````````````````````` 示例 ```````````````````````````````` 示例
[] []
[]: /uri []: /uri
. .
<p>[]</p> <p>[]</p>
<p>[]: /uri</p> <p>[]: /uri</p>
```````````````````````````````` ````````````````````````````````
skipping to change at line 7746 skipping to change at line 7790
链接标签不区分大小写。 链接标签不区分大小写。
```````````````````````````````` 示例 ```````````````````````````````` 示例
[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 not As with full reference links, spaces, tabs, or line endings are not
allowed 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><a href="/url" title="title">foo</a>
[]</p> []</p>
skipping to change at line 8046 skipping to change at line 8090
标签不区分大小写。 标签不区分大小写。
```````````````````````````````` 示例 ```````````````````````````````` 示例
![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 reference links, [whitespace] is not allowed As with reference links, spaces, tabs, and line endings, are 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><img src="/url" alt="foo" title="title" />
[]</p> []</p>
skipping to change at line 8132 skipping to change at line 8176
[Autolink](@)s are absolute URIs and email addresses inside [Autolink](@)s are absolute URIs and email addresses inside
`<` and `>`. They are parsed as links, with the URL or email address `<` and `>`. They are parsed as links, with the URL or email address
as the link label. as the link label.
A [URI autolink](@) consists of `<`, followed by an A [URI autolink](@) consists of `<`, followed by an
[absolute URI] followed by `>`. It is parsed as [absolute URI] followed by `>`. It is parsed as
a link to the URI, with the URI as the link's label. a link to the URI, with the URI as the link's label.
An [absolute URI](@), An [absolute URI](@),
for these purposes, consists of a [scheme] followed by a colon (`:`) for these purposes, consists of a [scheme] followed by a colon (`:`)
followed by zero or more characters other than ASCII followed by zero or more characters other [ASCII control
`<`和`>`之外的字符。 characters][ASCII control character], [space], `<`, and `>`.
the URI includes these characters, they must be percent-encoded If the URI includes these characters, they must be percent-encoded
(e.g. `%20` for a space). (e.g. `%20` for a space).
For purposes of this spec, a [scheme](@) is any sequence For purposes of this spec, a [scheme](@) is any sequence
of 2--32 characters beginning with an ASCII letter and followed of 2--32 characters beginning with an ASCII letter and followed
by any combination of ASCII letters, digits, or the symbols plus by any combination of ASCII letters, digits, or the symbols plus
("+"), period ("."), or hyphen ("-"). ("+"), period ("."), or hyphen ("-").
以下是一些有效的自动链接: 以下是一些有效的自动链接:
```````````````````````````````` 示例 ```````````````````````````````` 示例
skipping to change at line 8301 skipping to change at line 8345
raw HTML tag and will be rendered in HTML without escaping. raw HTML tag and will be rendered in HTML without escaping.
Tag and attribute names are not limited to current HTML tags, Tag and attribute names are not limited to current HTML tags,
so custom tags (and even, say, DocBook tags) may be used. so custom tags (and even, say, DocBook tags) may be used.
这是标签语法: 这是标签语法:
A [tag name](@) consists of an ASCII letter A [tag name](@) consists of an ASCII letter
followed by zero or more ASCII letters, digits, or followed by zero or more ASCII letters, digits, or
hyphens (`-`). hyphens (`-`).
An [attribute](@) consists of [whitespace], An [attribute](@) consists of spaces, tabs, and up to one line ending,
an [attribute name], and an optional an [attribute name], and an optional
[attribute value specification]. [attribute value specification].
An [attribute name](@) An [attribute name](@)
consists of an ASCII letter, `_`, or `:`, followed by zero or more ASCII consists of an ASCII letter, `_`, or `:`, followed by zero or more ASCII
letters, digits, `_`, `.`, `:`, or `-`. (Note: This is the XML letters, digits, `_`, `.`, `:`, or `-`. (Note: This is the XML
specification restricted to ASCII. HTML5 is laxer.) specification restricted to ASCII. HTML5 is laxer.)
An [attribute value specification](@) An [attribute value specification](@)
consists of optional [whitespace], consists of optional spaces, tabs, and up to one line ending,
a `=` character, optional [whitespace], and an [attribute a `=` character, optional spaces, tabs, and up to one line ending,
值]。 and an [attribute value].
[属性值](@) [属性值](@)
由[未加引号的属性值]、 由[未加引号的属性值]、
[单引号属性值]或[双引号属性值]组成。 [单引号属性值]或[双引号属性值]组成。
[未加引号的属性值](@) [未加引号的属性值](@)
是非空字符串, 是非空字符串,
including [whitespace], `"`, `'`, `=`, `<`, `>`, or `` ` ``. including spaces, tabs, line endings, `"`, `'`, `=`, `<`, `>`, or `` ` ``.
[单引号属性值](@) [单引号属性值](@)
由`'`、零个或多个 由`'`、零个或多个
不包含`'`的字符,以及一个最终的`'`组成。 不包含`'`的字符,以及一个最终的`'`组成。
[双引号属性值](@) [双引号属性值](@)
由`"`、零个或多个 由`"`、零个或多个
characters not including `"`, and a final `"`. characters not including `"`, and a final `"`.
An [open tag](@) consists of a `<` character, a [tag name], An [open tag](@) consists of a `<` character, a [tag name],
zero or more [attributes], optional [whitespace], an optional `/` zero or more [attributes], optional spaces, tabs, and up to one line ending,
字符,和一个 `>` 字符。 an optional `/` character, and a `>` character.
A [closing tag](@) consists of the string `</`, a A [closing tag](@) consists of the string `</`, a
[tag name], optional [whitespace], and the character `>`. [tag name], optional spaces, tabs, and up to one line ending, and the character
`>`.
An [HTML comment](@) consists of `<!--` + *text* + `-->`, An [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).)
A [processing instruction](@) A [processing instruction](@)
consists of the string `<?`, a string consists of the string `<?`, a string
of characters not including the string `?>`, and the string of characters not including the string `?>`, and the string
`?>`. `?>`.
A [declaration](@) consists of the A [declaration](@) consists of the string `<!`, an ASCII letter, zero or more
字符串 `<!`,一个由一个或多个大写 ASCII 字母组成的名称, characters not including the character `>`, and the character `>`.
[空白],一个不包含字符 `>` 的字符串,以及
字符 `>`,以及字符 `>` 组成。
A [CDATA section](@) consists of A [CDATA section](@) consists of
字符串 `<![CDATA[`,一个不包含字符串 `]]>` 的字符序列,以及字符串 `]]>` 组成。 字符串 `<![CDATA[`,一个不包含字符串 `]]>` 的字符序列,以及字符串 `]]>` 组成。
`]]>`,以及字符串 `]]>` 组成。 `]]>`,以及字符串 `]]>` 组成。
An [HTML tag](@) consists of an [open tag], a [closing tag], An [HTML tag](@) consists of an [open tag], a [closing tag],
an [HTML comment], a [processing instruction], a [declaration], an [HTML comment], a [processing instruction], a [declaration],
or a [CDATA section]. or a [CDATA section].
以下是一些简单的开始标签 以下是一些简单的开始标签
skipping to change at line 8377 skipping to change at line 8420
```````````````````````````````` ````````````````````````````````
空元素 空元素
```````````````````````````````` 示例 ```````````````````````````````` 示例
<a/><b2/> <a/><b2/>
. .
<p><a/><b2/></p> <p><a/><b2/></p>
```````````````````````````````` ````````````````````````````````
[Whitespace] is allowed Whitespace is allowed
```````````````````````````````` 示例 ```````````````````````````````` 示例
<a /><b2 <a /><b2
data="foo" > data="foo" >
. .
<p><a /><b2 <p><a /><b2
data="foo" ></p> data="foo" ></p>
```````````````````````````````` ````````````````````````````````
带有属性 带有属性
skipping to change at line 8429 skipping to change at line 8472
```````````````````````````````` ````````````````````````````````
非法属性值 非法属性值
```````````````````````````````` 示例 ```````````````````````````````` 示例
<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>
```````````````````````````````` ````````````````````````````````
Illegal [whitespace] Illegal whitespace
```````````````````````````````` 示例 ```````````````````````````````` 示例
< a>< < a><
foo><bar/ > foo><bar/ >
<foo bar=baz <foo bar=baz
bim!bop /> bim!bop />
. .
<p>&lt; a&gt;&lt; <p>&lt; a&gt;&lt;
foo&gt;&lt;bar/ &gt; foo&gt;&lt;bar/ &gt;
&lt;foo bar=baz &lt;foo bar=baz
bim!bop /&gt;</p> bim!bop /&gt;</p>
```````````````````````````````` ````````````````````````````````
Missing [whitespace] Missing whitespace
```````````````````````````````` 示例 ```````````````````````````````` 示例
<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>
```````````````````````````````` ````````````````````````````````
结束标签 结束标签
```````````````````````````````` 示例 ```````````````````````````````` 示例
skipping to change at line 8543 skipping to change at line 8586
```````````````````````````````` ````````````````````````````````
```````````````````````````````` 示例 ```````````````````````````````` 示例
<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
A line break (not in a code span or HTML tag) that is preceded A line ending (not in a code span or HTML tag) that is preceded
by two or more spaces and does not occur at the end of a block by two or more spaces and does not occur at the end of a block
is parsed as a [hard line break](@) (rendered is parsed as a [hard line break](@) (rendered
in HTML as a `<br />` tag) in HTML as a `<br />` tag)
```````````````````````````````` 示例 ```````````````````````````````` 示例
foo foo
baz baz
. .
<p>foo<br /> <p>foo<br />
baz</p> baz</p>
```````````````````````````````` ````````````````````````````````
为了更清晰的替代方案,在 [换行符](#line-ending) 前使用反斜杠代替两个空格 为了更清晰的替代方案,在 [换行符](#line-ending) 前使用反斜杠代替两个空格
[换行符] 可以代替两个空格使用 [line ending] may be used instead of two or more spaces
```````````````````````````````` 示例 ```````````````````````````````` 示例
foo\ foo\
baz baz
. .
<p>foo<br /> <p>foo<br />
baz</p> baz</p>
```````````````````````````````` ````````````````````````````````
可以使用超过两个的空格 可以使用超过两个的空格
skipping to change at line 8595 skipping to change at line 8638
```````````````````````````````` ````````````````````````````````
```````````````````````````````` 示例 ```````````````````````````````` 示例
foo\ foo\
bar bar
. .
<p>foo<br /> <p>foo<br />
bar</p> bar</p>
```````````````````````````````` ````````````````````````````````
Line breaks can occur inside emphasis, links, and other constructs Hard line breaks can occur inside emphasis, links, and other constructs
that allow inline content that allow inline content
```````````````````````````````` 示例 ```````````````````````````````` 示例
*foo *foo
bar* bar*
. .
<p><em>foo<br /> <p><em>foo<br />
bar</em></p> bar</em></p>
```````````````````````````````` ````````````````````````````````
```````````````````````````````` 示例 ```````````````````````````````` 示例
*foo\ *foo\
bar* bar*
. .
<p><em>foo<br /> <p><em>foo<br />
bar</em></p> bar</em></p>
```````````````````````````````` ````````````````````````````````
Line breaks do not occur inside code spans Hard line breaks do not occur inside code spans
```````````````````````````````` 示例 ```````````````````````````````` 示例
`代码 `代码
span` span`
. .
<p><code>代码 span</code></p> <p><code>code span</code></p>
```````````````````````````````` ````````````````````````````````
```````````````````````````````` 示例 ```````````````````````````````` 示例
`代码\ `代码\
span` span`
. .
<p><code>代码\ span</code></p> <p><code>代码\ span</code></p>
```````````````````````````````` ````````````````````````````````
或者 HTML 标签内 或者 HTML 标签内
skipping to change at line 8678 skipping to change at line 8721
```````````````````````````````` ````````````````````````````````
```````````````````````````````` 示例 ```````````````````````````````` 示例
### foo ### foo
. .
<h3>foo</h3> <h3>foo</h3>
```````````````````````````````` ````````````````````````````````
## Soft line breaks ## Soft line breaks
A regular line break (not in a code span or HTML tag) that is not A regular line ending (not in a code span or HTML tag) that is not
preceded by two or more spaces or a backslash is parsed as a preceded by two or more spaces or a backslash is parsed as a
[softbreak](@). (A softbreak may be rendered in HTML either as a [softbreak](@). (A soft line break may be rendered in HTML either as a
[line ending] or as a space. The result will be the same in [line ending] or as a space. The result will be the same in
browsers. In the examples here, a [line ending] will be used.) browsers. In the examples here, a [line ending] will be used.)
```````````````````````````````` 示例 ```````````````````````````````` 示例
foo foo
baz baz
. .
<p>foo <p>foo
baz</p> baz</p>
```````````````````````````````` ````````````````````````````````
skipping to change at line 8704 skipping to change at line 8747
```````````````````````````````` 示例 ```````````````````````````````` 示例
foo foo
baz baz
. .
<p>foo <p>foo
baz</p> baz</p>
```````````````````````````````` ````````````````````````````````
A conforming parser may render a soft line break in HTML either as a A conforming parser may render a soft line break in HTML either as a
line break or as a space. line ending or as a space.
A renderer may also provide an option to render soft line breaks A renderer may also provide an option to render soft line breaks
as hard line breaks. as hard line breaks.
## Textual content ## Textual content
Any characters not given an interpretation by the above rules will Any characters not given an interpretation by the above rules will
be parsed as plain textual content. be parsed as plain textual content.
```````````````````````````````` 示例 ```````````````````````````````` 示例
skipping to change at line 8809 skipping to change at line 8852
if the block is to remain open. For example, a block quote requires a if the block is to remain open. For example, a block quote requires a
`>` character. A paragraph requires a non-blank line. `>` character. A paragraph requires a non-blank line.
In this phase we may match all or just some of the open In this phase we may match all or just some of the open
blocks. But we cannot close unmatched blocks yet, because we may have a blocks. But we cannot close unmatched blocks yet, because we may have a
[lazy continuation line]. [lazy continuation line].
2. Next, after consuming the continuation markers for existing 2. Next, after consuming the continuation markers for existing
blocks, we look for new block starts (e.g. `>` for a block quote). blocks, we look for new block starts (e.g. `>` for a block quote).
如果我们遇到一个新的区块起始,我们会关闭在步骤 1 中 如果我们遇到一个新的区块起始,我们会关闭在步骤 1 中
未匹配的任何区块,然后再将新区块创建为最后一个 未匹配的任何区块,然后再将新区块创建为最后一个
匹配区块的子级。 matched container block.
3. 最后,我们查看行中剩余的部分(在区块 3. 最后,我们查看行中剩余的部分(在区块
标记如 `>`、列表标记和缩进被消耗之后)。 标记如 `>`、列表标记和缩进被消耗之后)。
这些文本可以合并到最后一个开放的 这些文本可以合并到最后一个开放的
区块中(段落、代码块、标题或原始 HTML)。 区块中(段落、代码块、标题或原始 HTML)。
当我们看到段落的一行是 Setext 标题行 时, 当我们看到段落的一行是 Setext 标题行 时,
that is a [setext heading underline]. that is a [setext heading underline].
当段落关闭时,会检测引用链接定义; 当段落关闭时,会检测引用链接定义;
skipping to change at line 9025 skipping to change at line 9068
参数`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`。
type (`*`, `_`) and each length of the closing delimiter run type (`*`, `_`), indexed to the length of the closing delimiter run
(modulo 3). Initialize this to `stack_bottom`. (modulo 3) and to whether the closing delimiter can also be an
opener. Initialize this to `stack_bottom`.
然后我们重复以下操作,直到潜在的 然后我们重复以下操作,直到潜在的
关闭器用完。 关闭器用完。
- 在分隔符堆栈中向前移动`current_position`(如果需要), - 在分隔符堆栈中向前移动`current_position`(如果需要),
直到找到第一个具有分隔符`*`或`_`的潜在关闭器。 直到找到第一个具有分隔符`*`或`_`的潜在关闭器。
(这将是离输入开头最近的潜在关闭器—— (这将是离输入开头最近的潜在关闭器——
解析顺序中的第一个。) 解析顺序中的第一个。)
- 现在,在堆栈中向后查找(保持在`stack_bottom`之上, - 现在,在堆栈中向后查找(保持在`stack_bottom`之上,
 End of changes. 151 change blocks. 
551 lines changed or deleted 595 lines changed or added

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