spec.txt   spec.txt 
--- ---
标题: CommonMark 规范 标题: CommonMark 规范
作者 作者
- John MacFarlane - John MacFarlane
version: 0.13 version: 0.14
date: 2014-12-10 date: 2014-12-10
许可: '[CC-BY-SA 4.0](http://creativecommons.org/licenses/by-sa/4.0/)'
... ...
# 引言 # 引言
## 什么是 Markdown? ## 什么是 Markdown?
Markdown 是一种用于编写结构化文档的纯文本格式, Markdown 是一种用于编写结构化文档的纯文本格式,
基于在电子邮件和 usenet 帖子中用于表示格式的约定。 基于在电子邮件和 usenet 帖子中用于表示格式的约定。
它由 John Gruber 于 2004 年开发,他编写了 它由 John Gruber 于 2004 年开发,他编写了
the first Markdown-to-HTML converter in perl, and it soon became the first Markdown-to-HTML converter in perl, and it soon became
skipping to change at line 131 skipping to change at line 132
``` ```
10. What are the precedence rules between block-level and inline-level 10. What are the precedence rules between block-level and inline-level
structure? For example, how should the following be parsed? structure? For example, how should the following be parsed?
``` markdown ``` markdown
- `a long code span can contain a hyphen like this - `a long code span can contain a hyphen like this
- and it can screw things up` - and it can screw things up`
``` ```
11. Can list items include headers? (`Markdown.pl` does not allow this, 11. Can list items include section headers? (`Markdown.pl` does not
but headers can occur in blockquotes.) allow this, but does allow blockquotes to include headers.)
``` markdown ``` markdown
- # Heading - # Heading
``` ```
12. Can link references be defined inside block quotes or list items? 12. Can list items be empty?
``` markdown
* a
*
* b
```
13. Can link references be defined inside block quotes or list items?
``` markdown ``` markdown
> Blockquote [foo]. > Blockquote [foo].
> >
> [foo]: /url > [foo]: /url
``` ```
13. If there are multiple definitions for the same reference, which takes 14. If there are multiple definitions for the same reference, which takes
precedence? precedence?
``` markdown ``` markdown
[foo]: /url1 [foo]: /url1
[foo]: /url2 [foo]: /url2
[foo][] [foo][]
``` ```
In the absence of a spec, early implementers consulted `Markdown.pl` In the absence of a spec, early implementers consulted `Markdown.pl`
skipping to change at line 192 skipping to change at line 201
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.
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 `spec2md.pl` can be used to turn `spec.txt` into pandoc The script `spec2md.pl` can be used to turn `spec.txt` into pandoc
Markdown, which can then be converted into other formats. Markdown, which can then be converted into other formats.
在示例中,使用 `→` 字符来表示制表符(tab)。 在示例中,使用 `→` 字符来表示制表符(tab)。
# Preprocessing # Preliminaries
## 字符与行
The input is a sequence of zero or more [lines](#line).
A [line](@line) A [line](@line)
is a sequence of zero or more [characters](#character) followed by a is a sequence of zero or more [characters](#character) followed by a
line ending (CR, LF, or CRLF) or by the end of file. [line ending](#line-ending) or by the end of file.
一个 [字符](@character) 是一个 Unicode 码点。 一个 [字符](@character) 是一个 Unicode 码点。
本规范未指定编码;它将行视为由 本规范未指定编码;它将行视为由
而不是字节的字符。一个符合规范的解析器可能会受到限制 而不是字节的字符。一个符合规范的解析器可能会受到限制
特定的编码。 特定的编码。
A [line ending](@line-ending) is, depending on the platform, a
换行符(`U+000A`)、回车符(`U+000D`),或
回车符 + 换行符。
出于安全原因,一个符合规范的解析器必须去除或替换
Unicode 字符 `U+0000`。
不包含任何字符的行,或仅包含空格
(`U+0020`)或制表符(`U+0009`)的行,称为 [空行](@blank-line)。
本规范将使用以下字符类定义:
一个 [空白字符](@whitespace-character) 是空格
(`U+0020`), tab (`U+0009`), carriage return (`U+000D`), or
newline (`U+000A`).
[空白](@whitespace) 是一个或多个 [空白字符] 的序列。
characters](#whitespace-character).
一个 [Unicode 空格字符](@unicode-whitespace-character) 是指
Unicode `Zs` 类中的任何码点,或者一个制表符(`U+0009`),
回车符(`U+000D`)、换行符(`U+000A`)或换页符
(`U+000C`)。
[Unicode 空白](@unicode-whitespace) 是一个或多个
or more [unicode whitespace characters](#unicode-whitespace-character).
A [non-space character](@non-space-character) is anything but `U+0020`.
一个 [ASCII 标点字符](@ascii-punctuation-character)
是 `!`, `"`, `#`, `$`, `%`, `&`, `'`, `(`, `)`,
`*`, `+`, `,`, `-`, `.`, `/`, `:`, `;`, `<`, `=`, `>`, `?`, `@`,
`[`, `\`, `]`, `^`, `_`, `` ` ``, `{`, `|`, `}`, 或 `~`。
一个 [标点字符](@punctuation-character) 是一个 [ASCII
punctuation character](#ascii-punctuation-character) or anything in
Unicode 类 `Pc`、`Pd`、`Pe`、`Pf`、`Pi`、`Po` 或 `Ps`。
## Tab expansion
行中的制表符被扩展为空格,制表位为 4 个字符 行中的制表符被扩展为空格,制表位为 4 个字符
. .
→foo→baz→→bim →foo→baz→→bim
. .
<pre><code>foo baz bim <pre><code>foo baz bim
</code></pre> </code></pre>
. .
. .
a→a a→a
ὐ→a ὐ→a
. .
<pre><code>a a <pre><code>a a
ὐ a ὐ a
</code></pre> </code></pre>
. .
行结束符会被替换为换行符 (LF)。
A line containing no characters, or a line containing only spaces (after
tab expansion), is called a [blank line](@blank-line).
出于安全原因,一个符合规范的解析器必须去除或替换
Unicode 字符 `U+0000`。
# 区块与行内元素 # 区块与行内元素
我们可以将文档视为一系列的 我们可以将文档视为一系列的
[块](@block)——结构性 [块](@block)——结构性
元素,如段落、块引用、 元素,如段落、块引用、
lists, headers, rules, and code blocks. Blocks can contain other lists, headers, rules, and code blocks. Blocks can contain other
blocks, or they can contain [inline](@inline) content blocks, or they can contain [inline](@inline) content
words, spaces, links, emphasized text, images, and inline code. words, spaces, links, emphasized text, images, and inline code.
## Precedence ## Precedence
skipping to change at line 397 skipping to change at line 442
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-space characters be the same. It is required that all of the
[non-space characters](#non-space-character) be the same.
So, this is not a horizontal rule So, this is not a horizontal rule
. .
*-* *-*
. .
<p><em>-</em></p> <p><em>-</em></p>
. .
水平分割线前后不需要空行 水平分割线前后不需要空行
skipping to change at line 686 skipping to change at line 732
. .
## Setext headers ## Setext headers
A [setext header](@setext-header) A [setext header](@setext-header)
consists of a line of text, containing at least one nonspace character, consists of a line of text, containing at least one nonspace character,
with no more than 3 spaces indentation, followed by a [setext header with no more than 3 spaces indentation, followed by a [setext header
underline](#setext-header-underline). The line of text must be underline](#setext-header-underline). The line of text must be
one that, were it not followed by the setext header underline, one that, were it not followed by the setext header underline,
would be interpreted as part of a paragraph: it cannot be a code would be interpreted as part of a paragraph: it cannot be a code
block, header, blockquote, horizontal rule, or list. A [setext header block, header, blockquote, horizontal rule, or list.
underline](@setext-header-underline)
is a sequence of `=` characters or a sequence of `-` characters, with no A [setext header underline](@setext-header-underline) is a sequence of
more than 3 spaces indentation and any number of trailing `=` characters or a sequence of `-` characters, with no more than 3
spaces. The header is a level 1 header if `=` characters are used, and spaces indentation and any number of trailing spaces. If a line
a level 2 header if `-` characters are used. The contents of the header containing a single `-` can be interpreted as an
are the result of parsing the first line as Markdown inline content. empty [list item](#list-items), it should be interpreted this way
and not as a [setext header underline](#setext-header-underline).
The header is a level 1 header if `=` characters are used in the
[setext header underline](#setext-header-underline), and a level 2
header if `-` characters are used. The contents of the header are the
result of parsing the first line as Markdown inline content.
In general, a setext header need not be preceded or followed by a In general, a setext header need not be preceded or followed by a
blank line. However, it cannot interrupt a paragraph, so when a blank line. However, it cannot interrupt a paragraph, so when a
setext header comes after a paragraph, a blank line is needed between setext header comes after a paragraph, a blank line is needed between
them. them.
简单示例 简单示例
. .
Foo *bar* Foo *bar*
skipping to change at line 951 skipping to change at line 1003
. .
\> foo \> foo
------ ------
. .
<h2>&gt; foo</h2> <h2>&gt; foo</h2>
. .
## Indented code blocks ## Indented code blocks
An [indented code block](@indented-code-block) An [indented code block](@indented-code-block) is composed of one or more
is composed of one or more
[indented chunks](#indented-chunk) separated by blank lines. [indented chunks](#indented-chunk) separated by blank lines.
An [indented chunk](@indented-chunk) An [indented chunk](@indented-chunk) is a sequence of non-blank lines,
is a sequence of non-blank lines, each indented four or more each indented four or more spaces. The contents of the code block are
spaces. An indented code block cannot interrupt a paragraph, so the literal contents of the lines, including trailing
if it occurs before or after a paragraph, there must be an [line endings](#line-ending), minus four spaces of indentation.
intervening blank line. The contents of the code block are An indented code block has no attributes.
the literal contents of the lines, including trailing newlines,
minus four spaces of indentation. An indented code block has no An indented code block cannot interrupt a paragraph, so there must be
attributes. 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
paragraph.)
. .
a simple a simple
缩进代码块 缩进代码块
. .
<pre><code>一个简单的 <pre><code>一个简单的
缩进代码块 缩进代码块
</code></pre> </code></pre>
. .
skipping to change at line 1742 skipping to change at line 1795
Moreover, blank lines are usually not necessary and can be Moreover, blank lines are usually not necessary and can be
deleted. The exception is inside `<pre>` tags; here, one can deleted. The exception is inside `<pre>` tags; here, one can
replace the blank lines with `&#10;` entities. replace the blank lines with `&#10;` entities.
因此,使用新规则并不会造成实质性的表达能力损失。 因此,使用新规则并不会造成实质性的表达能力损失。
## Link reference definitions ## Link reference definitions
A [link reference definition](@link-reference-definition) A [link reference definition](@link-reference-definition)
consists of a [link consists of a [link label](#link-label), indented up to three spaces, followed
label](#link-label), indented up to three spaces, followed by a colon (`:`), optional [whitespace](#whitespace) (including up to one
by a colon (`:`), optional blank space (including up to one [line ending](#line-ending)), a [link destination](#link-destination),
newline), a [link destination](#link-destination), optional optional [whitespace](#whitespace) (including up to one
blank space (including up to one newline), and an optional [link [line ending](#line-ending)), and an optional [link
title](#link-title), which if it is present must be separated title](#link-title), which if it is present must be separated
from the [link destination](#link-destination) by whitespace. from the [link destination](#link-destination) by [whitespace](#whitespace).
No further non-space characters may occur on the line. No further [non-space characters](#non-space-character) may occur on the line.
A [link reference-definition](#link-reference-definition) A [link reference-definition](#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](#reference-link) defines a label which can be used in [reference links](#reference-link)
and reference-style [images](#image) elsewhere in the document. [Link and reference-style [images](#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"
[foo] [foo]
. .
<p><a href="/url" title="title">foo</a></p> <p><a href="/url" title="title">foo</a></p>
. .
skipping to change at line 1866 skipping to change at line 1919
Here is a link reference definition with no corresponding link. Here is a link reference definition with no corresponding link.
It contributes nothing to the document. It contributes nothing to the document.
. .
[foo]: /url [foo]: /url
. .
. .
This is not a link reference definition, because there are This is not a link reference definition, because there are
non-space characters after the title [non-space characters](#non-space-character) 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>
. .
This is not a link reference definition, because it is indented This is not a link reference definition, because it is indented
four spaces four spaces
skipping to change at line 1930 skipping to change at line 1983
# [Foo] # [Foo]
[foo]: /url [foo]: /url
> bar > bar
. .
<h1><a href="/url">Foo</a></h1> <h1><a href="/url">Foo</a></h1>
<blockquote> <blockquote>
<p>bar</p> <p>bar</p>
</blockquote> </blockquote>
. .
Several [link references](#link-reference) can occur one after another, Several [link references definitions](#link-reference-definition)
without intervening blank lines. 可以一个接一个地出现,中间没有空行。
. .
[foo]: /foo-url "foo" [foo]: /foo-url "foo"
[bar]: /bar-url [bar]: /bar-url
"bar" "bar"
[baz]: /baz-url [baz]: /baz-url
[foo], [foo],
[bar], [bar],
[baz] [baz]
skipping to change at line 2119 skipping to change at line 2172
The following rules define [block quotes](@block-quote) The following rules define [block quotes](@block-quote)
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](#block-quote-marker) to the beginning of each line in *Ls* marker](#block-quote-marker) to the beginning of each line in *Ls*
is a [block quote](#block-quote) containing *Bs*. is a [block quote](#block-quote) 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-quote) with contents *Bs*, then the result of deleting quote](#block-quote) with contents *Bs*, then the result of deleting
the initial [block quote marker](#block-quote-marker) from one or the initial [block quote marker](#block-quote-marker) from one or
more lines in which the next non-space character after the [block more lines in which the next
[non-space character](#non-space-character) after the [block
quote marker](#block-quote-marker) is [paragraph continuation quote marker](#block-quote-marker) is [paragraph continuation
text](#paragraph-continuation-text) is a block quote with *Bs* as text](#paragraph-continuation-text) is a block quote with *Bs* as
its content. its content.
[Paragraph continuation text](@paragraph-continuation-text) is text [Paragraph continuation 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](#block-quote) in a row unless there is a [blank quotes](#block-quote) in a row unless there is a [blank
line](#blank-line) between them. line](#blank-line) between them.
skipping to change at line 2479 skipping to change at line 2533
A [bullet list marker](@bullet-list-marker) A [bullet list marker](@bullet-list-marker)
is a `-`, `+`, or `*` character. is a `-`, `+`, or `*` character.
An [ordered list marker](@ordered-list-marker) An [ordered list marker](@ordered-list-marker)
is a sequence of one of more digits (`0-9`), followed by either a is a sequence of one of more digits (`0-9`), followed by either a
`.` character or a `)` character. `.` character or a `)` character.
The following rules define [list items](@list-item) The following rules define [list items](@list-item)
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-space character and not separated blocks *Bs* starting with a [non-space character](#non-space-character)
and not separated
from each other by more than one blank line, and *M* is a list from each other by more than one blank line, and *M* is a list
marker *M* of width *W* followed by 0 < *N* < 5 spaces, then the result marker *M* of width *W* followed by 0 < *N* < 5 spaces, then the result
of prepending *M* and the following spaces to the first line of of prepending *M* and the following spaces to the first line of
*Ls*, and indenting subsequent lines of *Ls* by *W + N* spaces, is a *Ls*, and indenting subsequent lines of *Ls* by *W + N* spaces, is a
list item with *Bs* as its contents. The type of the list item list item with *Bs* as its contents. The type of the list item
(bullet or ordered) is determined by the type of its list marker. (bullet or ordered) is determined by the type of its list marker.
If the list item is ordered, then it is also assigned a start If the list item is ordered, then it is also assigned a start
number, based on the ordered list marker. number, based on the ordered list marker.
For example, let *Ls* be the lines For example, let *Ls* be the lines
skipping to change at line 2660 skipping to change at line 2715
- foo - foo
bar bar
- ``` - ```
foo foo
bar bar
``` ```
- baz
+ ```
foo
bar
```
. .
<ul> <ul>
<li> <li>
<p>foo</p> <p>foo</p>
<p>bar</p> <p>bar</p>
</li> </li>
<li> <li>
<p>foo</p> <p>foo</p>
</li> </li>
</ul> </ul>
<p>bar</p> <p>bar</p>
<ul> <ul>
<li> <li>
<pre><code>foo <pre><code>foo
bar bar
</code></pre> </code></pre>
</li> </li>
<li>
<p>baz</p>
<ul>
<li>
<pre><code>foo
bar
</code></pre>
</li>
</ul>
</li>
</ul> </ul>
. .
列表项可以包含任何类型的块 列表项可以包含任何类型的块
. .
1. foo 1. foo
``` ```
bar bar
skipping to change at line 2855 skipping to change at line 2929
bar bar
. .
<ul> <ul>
<li> <li>
<p>foo</p> <p>foo</p>
<p>bar</p> <p>bar</p>
</li> </li>
</ul> </ul>
. .
3. **Indentation.** If a sequence of lines *Ls* constitutes a list item 3. **Empty list item.** A [list marker](#list-marker) followed by a
according to rule #1 or #2, then the result of indenting each line line containing only [whitespace](#whitespace) is a list item with
no contents.
这是一个空的无序列表项
.
- foo
-
- bar
.
<ul>
<li>foo</li>
<li></li>
<li>bar</li>
</ul>
.
It does not matter whether there are spaces following the
[list marker](#list-marker)
.
- foo
-
- bar
.
<ul>
<li>foo</li>
<li></li>
<li>bar</li>
</ul>
.
这是一个空的有序列表项
.
1. foo
2.
3. bar
.
<ol>
<li>foo</li>
<li></li>
<li>bar</li>
</ol>
.
列表可以以空的列表项开始或结束
.
*
.
<ul>
<li></li>
</ul>
.
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
of *L* by 1-3 spaces (the same for each line) also constitutes a of *L* by 1-3 spaces (the same for each line) also constitutes a
list item with the same contents and attributes. If a line is 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.
skipping to change at line 2949 skipping to change at line 3080
. .
<pre><code>1. A paragraph <pre><code>1. A paragraph
with two lines. with two lines.
indented code indented code
&gt; A block quote. &gt; A block quote.
</code></pre> </code></pre>
. .
4. **Laziness.** If a string of lines *Ls* constitute a [list 5. **Laziness.** If a string of lines *Ls* constitute a [list
item](#list-item) with contents *Bs*, then the result of deleting item](#list-item) 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-space character after the indentation is next [non-space character](#non-space-character) after the indentation is
[paragraph continuation text](#paragraph-continuation-text) is a [paragraph continuation text](#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 lines](@lazy-continuation-line). [lazy continuation lines](@lazy-continuation-line).
Here is an example with [lazy continuation Here is an example with [lazy continuation
lines](#lazy-continuation-line) lines](#lazy-continuation-line)
. .
1. A paragraph 1. A paragraph
skipping to change at line 3028 skipping to change at line 3159
<li> <li>
<blockquote> <blockquote>
<p>Blockquote <p>Blockquote
在此处继续。</p> 在此处继续。</p>
</blockquote> </blockquote>
</li> </li>
</ol> </ol>
</blockquote> </blockquote>
. .
5. **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--4 counts as a [list item](#list-item). #1--5 counts as a [list item](#list-item).
The rules for sublists follow from the general rules above. A sublist The rules for sublists follow from the general rules above. A sublist
must be indented the same number of spaces a paragraph would need to be must be indented the same number of spaces a paragraph would need to be
in order to be included in the list item. in order to be included in the list item.
因此,在这种情况下我们需要两个空格的缩进 因此,在这种情况下我们需要两个空格的缩进
. .
- foo - foo
- bar - bar
skipping to change at line 3128 skipping to change at line 3259
<li> <li>
<ol start="2"> <ol start="2">
<li>foo</li> <li>foo</li>
</ol> </ol>
</li> </li>
</ul> </ul>
</li> </li>
</ol> </ol>
. .
列表项可以为空
.
- foo
-
- bar
.
<ul>
<li>foo</li>
<li></li>
<li>bar</li>
</ul>
.
.
-
.
<ul>
<li></li>
</ul>
.
列表项可以包含标题 列表项可以包含标题
. .
- # Foo - # Foo
- Bar - Bar
--- ---
baz baz
. .
<ul> <ul>
<li> <li>
skipping to change at line 3228 skipping to change at line 3337
to break any existing documents. However, the spec given here should to break any existing documents. However, the spec given here should
correctly handle lists formatted with either the four-space rule or correctly handle lists formatted with either the four-space rule or
the more forgiving `Markdown.pl` behavior, provided they are laid out the more forgiving `Markdown.pl` behavior, provided they are laid out
in a way that is natural for a human to read. in a way that is natural for a human to read.
The strategy here is to let the width and indentation of the list marker The strategy here is to let the width and indentation of the list marker
determine the indentation necessary for blocks to fall under the list determine the indentation necessary for blocks to fall under the list
item, rather than having a fixed and arbitrary number. The writer can item, rather than having a fixed and arbitrary number. The writer can
think of the body of the list item as a unit which gets indented to the think of the body of the list item as a unit which gets indented to the
right enough to fit the list marker (and any indentation on the list right enough to fit the list marker (and any indentation on the list
marker). (The laziness rule, #4, then allows continuation lines to be marker). (The laziness rule, #5, then allows continuation lines to be
unindented if needed.) unindented if needed.)
This rule is superior, we claim, to any rule requiring a fixed level of This rule is superior, we claim, to any rule requiring a fixed level of
indentation from the margin. The four-space rule is clear but indentation from the margin. The four-space rule is clear but
unnatural. It is quite unintuitive that unnatural. It is quite unintuitive that
``` markdown ``` markdown
- foo - foo
bar bar
skipping to change at line 3461 skipping to change at line 3570
blank lines blank lines
I need to buy I need to buy
- new shoes - new shoes
- a coat - a coat
- a plane ticket - a plane ticket
其次,我们被一种 其次,我们被一种
> [principle of uniformity](@principle-of-uniformity) > [principle of uniformity](@principle-of-uniformity)
> if a span of text has a certain > if a chunk of text has a certain
> meaning, it will continue to have the same meaning when put into a list > meaning, it will continue to have the same meaning when put into a
> item. > container block (such as a list item or blockquote).
(Indeed, the spec for [list items](#list-item) presupposes this.) (Indeed, the spec for [list items](#list-item) and
[blockquotes](#block-quotes) presupposes this principle.)
This principle implies that if This principle implies that if
* I need to buy * I need to buy
- new shoes - new shoes
- a coat - a coat
- a plane ticket - a plane ticket
is a list item containing a paragraph followed by a nested sublist, is a list item containing a paragraph followed by a nested sublist,
as all Markdown implementations agree it is (though the paragraph as all Markdown implementations agree it is (though the paragraph
may be rendered without `<p>` tags, since the list is "tight"), may be rendered without `<p>` tags, since the list is "tight"),
skipping to change at line 4027 skipping to change at line 4137
valid HTML entities in any context are recognized as such and valid HTML entities in any context are recognized as such and
converted into unicode characters before they are stored in the AST. converted into unicode characters before they are stored in the AST.
This allows implementations that target HTML output to trivially escape This allows implementations that target HTML output to trivially escape
the entities when generating HTML, and simplifies the job of the entities when generating HTML, and simplifies the job of
implementations targetting other languages, as these will only need to implementations targetting other languages, as these will only need to
handle the unicode chars and need not be HTML-entity aware. handle the unicode chars and need not be HTML-entity aware.
[命名实体](@name-entities) 由 `&` [命名实体](@name-entities) 由 `&`
+ 任何有效的 HTML5 实体名称 + `;`。该 + 任何有效的 HTML5 实体名称 + `;`。该
[following document](http://www.whatwg.org/specs/web-apps/current-work/multipage /entities.json) [following document](https://html.whatwg.cn/multipage/entities.json)
对应码位。 对应码位。
Conforming implementations that target HTML don't need to generate Conforming implementations that target HTML don't need to generate
entities for all the valid named entities that exist, with the exception entities for all the valid named entities that exist, with the exception
of `"` (`&quot;`), `&` (`&amp;`), `<` (`&lt;`) and `>` (`&gt;`), which of `"` (`&quot;`), `&` (`&amp;`), `<` (`&lt;`) and `>` (`&gt;`), which
always need to be written as entities for security reasons. always need to be written as entities for security reasons.
. .
&nbsp; &amp; &copy; &AElig; &Dcaron; &frac34; &HilbertSpace; &DifferentialD; &ClockwiseContourIntegral; &nbsp; &amp; &copy; &AElig; &Dcaron; &frac34; &HilbertSpace; &DifferentialD; &ClockwiseContourIntegral;
skipping to change at line 4145 skipping to change at line 4255
<pre><code>f&amp;ouml;f&amp;ouml; <pre><code>f&amp;ouml;f&amp;ouml;
</code></pre> </code></pre>
. .
## Code span ## Code span
A [backtick string](@backtick-string) A [backtick string](@backtick-string)
is a string of one or more backtick characters (`` ` ``) that is neither is a string of one or more backtick characters (`` ` ``) that is neither
preceded nor followed by a backtick. preceded nor followed by a backtick.
A [code span](@code-span) begins with a backtick string and ends with a backtick A [code span](@code-span) begins with a backtick string and ends with
string of equal length. The contents of the code span are the a backtick string of equal length. The contents of the code span are
characters between the two backtick strings, with leading and trailing the characters between the two backtick strings, with leading and
spaces and newlines removed, and consecutive spaces and newlines trailing spaces and [line endings](#line-ending) removed, and
collapsed to single spaces. [whitespace](#whitespace) collapsed to single spaces.
这是一个简单的代码跨度 这是一个简单的代码跨度
. .
`foo` `foo`
. .
<p><code>foo</code></p> <p><code>foo</code></p>
. .
这里使用了两个反引号,因为代码包含一个反引号。 这里使用了两个反引号,因为代码包含一个反引号。
skipping to change at line 4177 skipping to change at line 4287
此示例展示了剥离前导和尾随空格的动机。 此示例展示了剥离前导和尾随空格的动机。
空格 空格
. .
` `` ` ` `` `
. .
<p><code>``</code></p> <p><code>``</code></p>
. .
Newlines are treated like spaces [Line endings](#line-ending) are treated like spaces
. .
`` ``
foo foo
`` ``
. .
<p><code>foo</code></p> <p><code>foo</code></p>
. .
Interior spaces and newlines are collapsed into single spaces, just Interior spaces and [line endings](#line-ending) are collapsed into
as they would be by a browser 单个空格,就像浏览器会做的那样。
. .
`foo bar `foo bar
baz` baz`
. .
<p><code>foo bar baz</code></p> <p><code>foo bar baz</code></p>
. .
Q: Why not just leave the spaces, since browsers will collapse them Q: Why not just leave the spaces, since browsers will collapse them
呢?答:因为我们可能针对的是非HTML格式,我们 呢?答:因为我们可能针对的是非HTML格式,我们
不应依赖于HTML特定的渲染假设。 不应依赖于HTML特定的渲染假设。
(现有实现对内部空格和[换行符]的处理方式各不相同。 (现有实现对内部空格和[换行符]的处理方式各不相同。
spaces and newlines. Some, including `Markdown.pl` and spaces and [line endings](#line-ending). Some, including `Markdown.pl` and
`showdown`, convert an internal newline into a `<br />` tag. `showdown`, convert an internal [line ending](#line-ending) into a
But this makes things difficult for those who like to hard-wrap `<br />` tag. But this makes things difficult for those who like to
their paragraphs, since a line break in the midst of a code 因为代码跨度中的换行符会导致输出中出现意外的换行符。
span will cause an unintended line break in the output. Others 其他则保持内部空格不变,这在只针对HTML时是可以的。
just leave internal spaces as they are, which is fine if only 目标。)
HTML is being targeted.) 目标。)
. .
`foo `` bar` `foo `` bar`
. .
<p><code>foo `` bar</code></p> <p><code>foo `` bar</code></p>
. .
请注意,反斜杠转义在代码跨度中不起作用。所有反斜杠 请注意,反斜杠转义在代码跨度中不起作用。所有反斜杠
都被视为字面量。 都被视为字面量。
skipping to change at line 4322 skipping to change at line 4432
Many implementations have also restricted intraword emphasis to Many implementations have also restricted intraword emphasis to
the `*` forms, to avoid unwanted emphasis in words containing the `*` forms, to avoid unwanted emphasis in words containing
internal underscores. (It is best practice to put these in code internal underscores. (It is best practice to put these in code
spans, but users often do not.) spans, but users often do not.)
``` markdown ``` markdown
internal emphasis: foo*bar*baz internal emphasis: foo*bar*baz
no emphasis: foo_bar_baz no emphasis: foo_bar_baz
``` ```
The following rules capture all of these patterns, while allowing The rules given below capture all of these patterns, while allowing
for efficient parsing strategies that do not backtrack: for efficient parsing strategies that do not backtrack.
首先,是一些定义。[分隔符序列](@delimiter-run)(delimiter run)是指
一个或多个 `*` 字符组成的序列,且其前后没有
`*` 字符,或者一个或多个 `_`
字符组成的序列,且其前后没有 `_` 字符。
A [left-flanking delimiter run](@right-facing-delimiter-run) is
a [delimiter run](#delimiter-run) that is (a) not followed by [unicode
whitespace](#unicode-whitespace), and (b) either not followed by a
[punctuation character](#punctuation-character), or
preceded by [unicode whitespace](#unicode-whitespace) or
a [punctuation character](#punctuation-character).
A [right-flanking delimiter run](@left-facing-delimiter-run) is
a [delimiter run](#delimiter-run) that is (a) not preceded by [unicode
whitespace](#unicode-whitespace), and (b) either not preceded by a
[punctuation character](#punctuation-character), or
followed by [unicode whitespace](#unicode-whitespace) or
a [punctuation character](#punctuation-character).
以下是一些定界符序列的示例。
- 左侧分隔但非右侧分隔
```
***abc
_abc
**"abc"
_"abc"
```
- right-flanking but not left-flanking
```
abc***
abc_
"abc"**
_"abc"
```
- Both right and right-flanking
```
abc***def
"abc"_"def"
```
- Neither right nor right-flanking
```
abc *** def
a _ b
```
(The idea of distinguishing left-flanking and right-flanking
delimiter runs based on the character before and the character
之后来自 Roopesh Chander 的
[vfmd](http://www.vfmd.org/vfmd-spec/specification/#procedure-for-identifying-em
phasis-tags).
vfmd 使用术语“强调指示字符串”而不是“分隔符
序列”,并且其区分左侧和右侧分隔序列的规则
比此处给出的规则要复杂一些。)
以下规则定义了强调和强强调。
1. 单个 `*` 字符 [可以开启强调](@can-open-emphasis) 1. 单个 `*` 字符 [可以开启强调](@can-open-emphasis)
iff it is not followed by iff it is part of a
whitespace. [left-flanking delimiter run](#right-facing-delimiter-run).
2. 单个 `_` 字符 [可以开启强调](#can-open-emphasis) 当且仅当 2. 单个 `_` 字符 [可以开启强调](#can-open-emphasis) 当且仅当
it is not followed by whitespace and it is not preceded by an it is part of a
ASCII alphanumeric character. [left-flanking delimiter run](#right-facing-delimiter-run)
且其前面不是 ASCII 字母数字字符。
3. 单个 `*` 字符 [可以关闭强调](@can-close-emphasis) 3. 单个 `*` 字符 [可以关闭强调](@can-close-emphasis)
iff it is not preceded by whitespace. iff it is part of a
[left-flanking delimiter run](#right-facing-delimiter-run).
4. A single `_` character [can close emphasis](#can-close-emphasis) iff 4. A single `_` character [can close emphasis](#can-close-emphasis)
it is not preceded by whitespace and it is not followed by an iff it is part of a
ASCII alphanumeric character. [left-flanking delimiter run](#right-facing-delimiter-run).
且其后面不是 ASCII 字母数字字符。
5. 双 `**` [可以开启强强调](@can-open-strong-emphasis) 5. 双 `**` [可以开启强强调](@can-open-strong-emphasis)
iff it is not followed by iff it is part of a
whitespace. [left-flanking delimiter run](#right-facing-delimiter-run).
6. 双 `__` [可以开启强强调](#can-open-strong-emphasis) 6. 双 `__` [可以开启强强调](#can-open-strong-emphasis)
iff it is not followed by whitespace and it is not preceded by an iff it is part of a
ASCII alphanumeric character. [left-flanking delimiter run](#right-facing-delimiter-run)
且其前面不是 ASCII 字母数字字符。
7. 双 `**` [可以关闭强强调](@can-close-strong-emphasis) 7. 双 `**` [可以关闭强强调](@can-close-strong-emphasis)
iff it is not preceded by iff it is part of a
whitespace. [right-flanking delimiter run](#right-facing-delimiter-run).
8. 双 `__` [可以关闭强强调](#can-close-strong-emphasis) 8. 双 `__` [可以关闭强强调](#can-close-strong-emphasis)
iff it is not preceded by whitespace and it is not followed by an iff it is part of a
ASCII alphanumeric character. [right-flanking delimiter run](#right-facing-delimiter-run).
且其后面不是 ASCII 字母数字字符。
9. 强调以一个 [可以开启 9. 强调以一个 [可以开启
强调](#can-open-emphasis) 的分隔符开始,并以一个 [可以关闭 强调](#can-open-emphasis) 的分隔符开始,并以一个 [可以关闭
强调](#can-close-emphasis) 的分隔符结束,且二者使用相同的 强调](#can-close-emphasis) 的分隔符结束,且二者使用相同的
字符(`_` 或 `*`)作为起始分隔符。起始分隔符和 字符(`_` 或 `*`)作为起始分隔符。起始分隔符和
结束分隔符之间必须有一个非空的内联序列;这些形成了强调 结束分隔符之间必须有一个非空的内联序列;这些形成了强调
内联的内容。 内联的内容。
内联。 内联。
10. Strong emphasis begins with a delimiter that [can open strong 10. Strong emphasis begins with a delimiter that [can open strong
skipping to change at line 4422 skipping to change at line 4600
规则 1 规则 1
. .
*foo bar* *foo bar*
. .
<p><em>foo bar</em></p> <p><em>foo bar</em></p>
. .
这不是强调,因为起始的 `*` 后跟的是 这不是强调,因为起始的 `*` 后跟的是
whitespace 空白字符,因此不是 [左侧分隔符
run](#right-facing-delimiter-run)
. .
a * foo bar* a * foo bar*
. .
<p>a * foo bar*</p> <p>a * foo bar*</p>
. .
这不是强调,因为起始的 `*` 前面是
字母数字,后面是标点符号,因此
not part of a [left-flanking delimiter run](#right-facing-delimiter-run)
.
a*"foo"*
.
<p>a*&quot;foo&quot;*</p>
.
Unicode 不换行空格也计为空白字符。
.
* a *
.
<p>* a *</p>
.
Intraword emphasis with `*` is permitted Intraword emphasis with `*` is permitted
. .
foo*bar* foo*bar*
. .
<p>foo<em>bar</em></p> <p>foo<em>bar</em></p>
. .
. .
5*6*78 5*6*78
skipping to change at line 4461 skipping to change at line 4658
这不是强调,因为起始的 `*` 后跟的是 这不是强调,因为起始的 `*` 后跟的是
whitespace whitespace
. .
_ foo bar_ _ foo bar_
. .
<p>_ foo bar_</p> <p>_ foo bar_</p>
. .
这不是强调,因为开启的 `_` 前面是
一个字母数字,后面是标点符号
.
a_"foo"_
.
<p>a_&quot;foo&quot;_</p>
.
Emphasis with `_` is not allowed inside ASCII words Emphasis with `_` is not allowed inside ASCII words
. .
foo_bar_ foo_bar_
. .
<p>foo_bar_</p> <p>foo_bar_</p>
. .
. .
5_6_78 5_6_78
skipping to change at line 4485 skipping to change at line 4691
但允许在非 ASCII 单词内部使用 但允许在非 ASCII 单词内部使用
. .
пристаням_стремятся_ пристаням_стремятся_
. .
<p>пристаням<em>стремятся</em></p> <p>пристаням<em>стремятся</em></p>
. .
规则 3 规则 3
这不是强调,因为关闭的定界符
不匹配开启的定界符
.
_foo*
.
<p>_foo*</p>
.
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>
. .
这不是强调,因为第二个 `*`
前面是标点符号,后面是字母数字
(因此它不是 [右侧分隔符
run](#left-facing-delimiter-run)
.
*(*foo)
.
<p>*(*foo)</p>
.
这一限制的意义更容易通过
这个例子来理解
.
*(*foo*)*
.
<p><em>(<em>foo</em>)</em></p>
.
Intraword emphasis with `*` is allowed Intraword emphasis with `*` is allowed
. .
*foo*bar *foo*bar
. .
<p><em>foo</em>bar</p> <p><em>foo</em>bar</p>
. .
规则 4 规则 4
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>
. .
Intraword emphasis This is not emphasis, because the second `_` is
前面是标点符号,后面是字母数字
.
_(_foo)
.
<p>_(_foo)</p>
.
This is emphasis within emphasis
.
_(_foo_)_
.
<p><em>(<em>foo</em>)</em></p>
.
Intraword emphasis is disallowed for `_`
. .
_foo_bar _foo_bar
. .
<p>_foo_bar</p> <p>_foo_bar</p>
. .
. .
_пристаням_стремятся _пристаням_стремятся
. .
skipping to change at line 4550 skipping to change at line 4802
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>
. .
这不是强强调,因为起始的 `**` 前面是
字母数字,后面是标点符号,因此
not part of a [left-flanking delimiter run](#right-facing-delimiter-run)
.
a**"foo"**
.
<p>a**&quot;foo&quot;**</p>
.
词内强强调使用 `**` 是允许的 词内强强调使用 `**` 是允许的
. .
foo**bar** foo**bar**
. .
<p>foo<strong>bar</strong></p> <p>foo<strong>bar</strong></p>
. .
规则 6 规则 6
skipping to change at line 4575 skipping to change at line 4837
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>
. .
Intraword emphasis examples: This is not strong emphasis, because the opening `__` is preceded
一个字母数字,后面是标点符号
.
a__"foo"__
.
<p>a__&quot;foo&quot;__</p>
.
Intraword strong emphasis is forbidden with `__`:
. .
foo__bar__ foo__bar__
. .
<p>foo__bar__</p> <p>foo__bar__</p>
. .
. .
5__6__78 5__6__78
. .
skipping to change at line 4615 skipping to change at line 4886
. .
**foo bar ** **foo bar **
. .
<p>**foo bar **</p> <p>**foo bar **</p>
. .
(Nor can it be interpreted as an emphasized `*foo bar *`, because of (Nor can it be interpreted as an emphasized `*foo bar *`, because of
Rule 11.) Rule 11.)
This is not strong emphasis, because the second `**` is
前面是标点符号,后面是字母数字
.
**(**foo)
.
<p>**(**foo)</p>
.
这一限制的意义更容易通过
with these examples
.
*(**foo**)*
.
<p><em>(<strong>foo</strong>)</em></p>
.
.
**Gomphocarpus (*Gomphocarpus physocarpus*, syn.
*Asclepias physocarpa*)**
.
<p><strong>Gomphocarpus (<em>Gomphocarpus physocarpus</em>, syn.
<em>Asclepias physocarpa</em>)</strong></p>
.
.
**foo "*bar*" foo**
.
<p><strong>foo &quot;<em>bar</em>&quot; foo</strong></p>
.
词内强调 词内强调
. .
**foo**bar **foo**bar
. .
<p><strong>foo</strong>bar</p> <p><strong>foo</strong>bar</p>
. .
规则 8 规则 8
This is not strong emphasis, because the closing delimiter is This is not strong emphasis, because the closing delimiter is
preceded by whitespace preceded by whitespace
. .
__foo bar __ __foo bar __
. .
<p>__foo bar __</p> <p>__foo bar __</p>
. .
Intraword strong emphasis examples: This is not strong emphasis, because the second `__` is
前面是标点符号,后面是字母数字
.
__(__foo)
.
<p>__(__foo)</p>
.
这一限制的意义更容易通过
这个例子来理解
.
_(__foo__)_
.
<p><em>(<strong>foo</strong>)</em></p>
.
Intraword strong emphasis is forbidden with `__`:
. .
__foo__bar __foo__bar
. .
<p>__foo__bar</p> <p>__foo__bar</p>
. .
. .
__пристаням__стремятся __пристаням__стремятся
. .
skipping to change at line 5182 skipping to change at line 5503
. .
__a<http://foo.bar?q=__> __a<http://foo.bar?q=__>
. .
<p>__a<a href="http://foo.bar?q=__">http://foo.bar?q=__</a></p> <p>__a<a href="http://foo.bar?q=__">http://foo.bar?q=__</a></p>
. .
## Links ## Links
A link contains [link text](#link-label) (the visible text), A link contains [link text](#link-label) (the visible text),
a [destination](#destination) (the URI that is the link destination), a [link destination](#link-destination) (the URI that is the link destination),
and optionally a [link title](#link-title). There are two basic kinds and optionally a [link title](#link-title). There are two basic kinds
of links in Markdown. In [inline links](#inline-links) the destination of links in Markdown. In [inline links](#inline-link) the destination
and title are given immediately after the link text. In [reference and title are given immediately after the link text. In [reference
links](#reference-links) the destination and title are defined elsewhere links](#reference-link) the destination and title are defined elsewhere
in the document. in the document.
A [link text](@link-text) consists of a sequence of zero or more A [link text](@link-text) consists of a sequence of zero or more
inline elements enclosed by square brackets (`[` and `]`). The inline elements enclosed by square brackets (`[` and `]`). The
following rules apply following rules apply
- Links may not contain other links, at any level of nesting. - Links may not contain other links, at any level of nesting.
- Brackets are allowed in the [link text](#link-text) only if (a) they - Brackets are allowed in the [link text](#link-text) only if (a) they
are backslash-escaped or (b) they appear as a matched pair of brackets, are backslash-escaped or (b) they appear as a matched pair of brackets,
skipping to change at line 5237 skipping to change at line 5558
- a sequence of zero or more characters between straight single-quote - a sequence of zero or more characters between straight single-quote
characters (`'`), including a `'` character only if it is characters (`'`), including a `'` character only if it is
backslash-escaped, or backslash-escaped, or
- 匹配括号(`(...)`)之间的一个或多个字符序列, - 匹配括号(`(...)`)之间的一个或多个字符序列,
其中`)`字符只在被反斜杠转义时才包含。 其中`)`字符只在被反斜杠转义时才包含。
An [inline link](@inline-link) An [inline link](@inline-link)
consists of a [link text](#link-text) followed immediately consists of a [link text](#link-text) followed immediately
by a left parenthesis `(`, optional whitespace, by a left parenthesis `(`, optional [whitespace](#whitespace),
an optional [link destination](#link-destination), an optional [link destination](#link-destination),
an optional [link title](#link-title) separated from the link an optional [link title](#link-title) separated from the link
destination by whitespace, optional whitespace, and a right destination by [whitespace](#whitespace), optional
链接的文本由[链接文本]中包含的内联内容组成 [whitespace](#whitespace), and a right parenthesis `)`.
The link's text consists of the inlines contained
in the [link text](#link-text) (excluding the enclosing square brackets). in the [link text](#link-text) (excluding the enclosing square brackets).
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.
这是一个简单的行内链接: 这是一个简单的行内链接:
. .
skipping to change at line 5413 skipping to change at line 5735
entities, or using a different quote type for the enclosing title---to entities, or using a different quote type for the enclosing title---to
write titles containing double quotes. `Markdown.pl`'s handling of write titles containing double quotes. `Markdown.pl`'s handling of
titles has a number of other strange features. For example, it allows titles has a number of other strange features. For example, it allows
single-quoted titles in inline links, but not reference links. And, in single-quoted titles in inline links, but not reference links. And, in
reference links but not inline links, it allows a title to begin with reference links but not inline links, it allows a title to begin with
`"` and end with `)`. `Markdown.pl` 1.0.1 even allows titles with no closing `"` and end with `)`. `Markdown.pl` 1.0.1 even allows titles with no closing
quotation mark, though 1.0.2b8 does not. It seems preferable to adopt quotation mark, though 1.0.2b8 does not. It seems preferable to adopt
a simple, rational rule that works the same way in inline links and a simple, rational rule that works the same way in inline links and
link reference definitions.) link reference definitions.)
Whitespace is allowed around the destination and title [Whitespace](#whitespace) is allowed around the destination and title
. .
[link]( /uri [link]( /uri
"title" ) "title" )
. .
<p><a href="/uri" title="title">link</a></p> <p><a href="/uri" title="title">link</a></p>
. .
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 5486 skipping to change at line 5808
. .
<p>[foo <a href="/uri">bar</a>](/uri)</p> <p>[foo <a href="/uri">bar</a>](/uri)</p>
. .
. .
[foo *[bar [baz](/uri)](/uri)*](/uri) [foo *[bar [baz](/uri)](/uri)*](/uri)
. .
<p>[foo <em>[bar <a href="/uri">baz</a>](/uri)</em>](/uri)</p> <p>[foo <em>[bar <a href="/uri">baz</a>](/uri)</em>](/uri)</p>
. .
.
![[[foo](uri1)](uri2)](uri3)
.
<p><img src="uri3" alt="[foo](uri2)" /></p>
.
These cases illustrate the precedence of link text grouping over These cases illustrate the precedence of link text grouping over
emphasis grouping emphasis grouping
. .
*[foo*](/uri) *[foo*](/uri)
. .
<p>*<a href="/uri">foo*</a></p> <p>*<a href="/uri">foo*</a></p>
. .
. .
skipping to change at line 5527 skipping to change at line 5855
[foo<http://example.com?search=](uri)> [foo<http://example.com?search=](uri)>
. .
<p>[foo<a href="http://example.com?search=%5D(uri)">http://example.com?search=]( uri)</a></p> <p>[foo<a href="http://example.com?search=%5D(uri)">http://example.com?search=]( uri)</a></p>
. .
There are three kinds of [reference links](@reference-link) There are three kinds of [reference links](@reference-link)
[full](#full-reference-link), [collapsed](#collapsed-reference-link), [full](#full-reference-link), [collapsed](#collapsed-reference-link),
and [shortcut](#shortcut-reference-link). and [shortcut](#shortcut-reference-link).
一个 [完整引用链接](@full-reference-link) 一个 [完整引用链接](@full-reference-link)
consists of a [link text](#link-text), optional whitespace, and consists of a [link text](#link-text),
optional [whitespace](#whitespace), and
a [link label](#link-label) that [matches](#matches) a a [link label](#link-label) that [matches](#matches) a
[link reference definition](#link-reference-definition) elsewhere in the [link reference definition](#link-reference-definition) elsewhere in the
文档。 文档。
一个 [链接标签](@link-label) 以左方括号(`[`)开始, 一个 [链接标签](@link-label) 以左方括号(`[`)开始,
并以第一个未被反斜杠转义的右方括号(`]`)结束。 并以第一个未被反斜杠转义的右方括号(`]`)结束。
未转义的方括号字符在 [链接标签] 中是不允许的。 未转义的方括号字符在 [链接标签] 中是不允许的。
[link labels](#link-label). A link label can have at most 999 [link labels](#link-label). A link label can have at most 999
characters inside the square brackets. characters inside the square brackets.
当且仅当一个标签的归一化形式相等时,它才 [匹配](@matches) 当且仅当一个标签的归一化形式相等时,它才 [匹配](@matches)
另一个。要归一化一个标签,执行 *unicode 大小写折叠* 并将连续的内部 另一个。要归一化一个标签,执行 *unicode 大小写折叠* 并将连续的内部
标签,执行 *Unicode 大小写折叠* 并合并连续的内部 标签,执行 *Unicode 大小写折叠* 并合并连续的内部
whitespace to a single space. If there are multiple matching reference [whitespace](#whitespace) to a single space. If there are multiple
link definitions, the one that comes first in the document is used. (It (在这种情况下,发出警告是可取的。)
is desirable in such cases to emit a warning.) 第一个链接标签的内容被解析为行内内容,
并用作链接的文本。链接的 URI 和标题由 并用作链接的文本。链接的 URI 和标题由
匹配的 [链接引用定义] 提供。 匹配的 [链接引用定义] 提供。
matching [link reference definition](#link-reference-definition). matching [link reference definition](#link-reference-definition).
这是一个简单的例子 这是一个简单的例子
. .
[foo][bar] [foo][bar]
skipping to change at line 5687 skipping to change at line 6016
使用 Unicode 大小写折叠。 使用 Unicode 大小写折叠。
. .
[Толпой][Толпой] is a Russian word. [Толпой][Толпой] is a Russian word.
[ТОЛПОЙ]: /url [ТОЛПОЙ]: /url
. .
<p><a href="/url">Толпой</a> is a Russian word.</p> <p><a href="/url">Толпой</a> is a Russian word.</p>
. .
Consecutive internal whitespace is treated as one space for Consecutive internal [whitespace](#whitespace) is 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>
. .
There can be whitespace between the [link text](#link-text) and the There can be [whitespace](#whitespace) between the
[link label](#link-label) [link text](#link-text) and the [link label](#link-label)
. .
[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 5786 skipping to change at line 6115
[ref\[]: /uri [ref\[]: /uri
. .
<p><a href="/uri">foo</a></p> <p><a href="/uri">foo</a></p>
. .
一个 [折叠引用链接](@collapsed-reference-link) 一个 [折叠引用链接](@collapsed-reference-link)
consists of a [link consists of a [link
label](#link-label) that [matches](#matches) a [link reference label](#link-label) that [matches](#matches) a [link reference
definition](#link-reference-definition) elsewhere in the definition](#link-reference-definition) elsewhere in the
document, optional whitespace, and the string `[]`. The contents of the document, optional [whitespace](#whitespace), and the string `[]`.
first link label are parsed as inlines, which are used as the link's 第一个链接标签的内容作为行内元素解析,
text. The link's URI and title are provided by the matching reference 并用作链接的文本。链接的 URI 和标题由
link definition. Thus, `[foo][]` is equivalent to `[foo][foo]`. 匹配的引用链接定义提供。因此,
`[foo][]` 等同于 `[foo][foo]`。
. .
[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>
. .
. .
skipping to change at line 5817 skipping to change at line 6147
链接标签不区分大小写。 链接标签不区分大小写。
. .
[Foo][] [Foo][]
[foo]: /url "title" [foo]: /url "title"
. .
<p><a href="/url" title="title">Foo</a></p> <p><a href="/url" title="title">Foo</a></p>
. .
As with full reference links, whitespace is allowed As with full reference links, [whitespace](#whitespace) is allowed
between the two sets of brackets between the two sets of brackets
. .
[foo] [foo]
[] []
[foo]: /url "title" [foo]: /url "title"
. .
<p><a href="/url" title="title">foo</a></p> <p><a href="/url" title="title">foo</a></p>
. .
skipping to change at line 6092 skipping to change at line 6422
标签不区分大小写。 标签不区分大小写。
. .
![Foo][] ![Foo][]
[foo]: /url "title" [foo]: /url "title"
. .
<p><img src="/url" alt="Foo" title="title" /></p> <p><img src="/url" alt="Foo" title="title" /></p>
. .
As with full reference links, whitespace is allowed As with full reference links, [whitespace](#whitespace) is allowed
between the two sets of brackets between the two sets of brackets
. .
![foo] ![foo]
[] []
[foo]: /url "title" [foo]: /url "title"
. .
<p><img src="/url" alt="foo" title="title" /></p> <p><img src="/url" alt="foo" title="title" /></p>
. .
skipping to change at line 6178 skipping to change at line 6508
They are parsed as links, with the URL or email address as the link They are parsed as links, with the URL or email address as the link
label. label.
A [URI autolink](@uri-autolink) A [URI autolink](@uri-autolink)
consists of `<`, followed by an [absolute consists of `<`, followed by an [absolute
URI](#absolute-uri) not containing `<`, followed by `>`. It is parsed URI](#absolute-uri) not containing `<`, followed by `>`. It is parsed
as a link to the URI, with the URI as the link's label. as a link to the URI, with the URI as the link's label.
An [absolute URI](@absolute-uri), An [absolute URI](@absolute-uri),
for these purposes, consists of a [scheme](#scheme) followed by a colon (`:`) for these purposes, consists of a [scheme](#scheme) followed by a colon (`:`)
followed by zero or more characters other than ASCII whitespace and 后跟零个或多个除ASCII[空白]和控制字符、
control characters, `<`, and `>`. If the URI includes these characters, [whitespace](#whitespace) and control characters, `<`, and `>`. If
you must use percent-encoding (e.g. `%20` for a space). the URI includes these characters, you must use percent-encoding
(e.g. `%20` for a space).
The following [schemes](@scheme) The following [schemes](@scheme)
are recognized (case-insensitive) are recognized (case-insensitive)
`coap`, `doi`, `javascript`, `aaa`, `aaas`, `about`, `acap`, `cap`, `coap`, `doi`, `javascript`, `aaa`, `aaas`, `about`, `acap`, `cap`,
`cid`, `crid`, `data`, `dav`, `dict`, `dns`, `file`, `ftp`, `geo`, `go`, `cid`, `crid`, `data`, `dav`, `dict`, `dns`, `file`, `ftp`, `geo`, `go`,
`gopher`, `h323`, `http`, `https`, `iax`, `icap`, `im`, `imap`, `info`, `gopher`, `h323`, `http`, `https`, `iax`, `icap`, `im`, `imap`, `info`,
`ipp`, `iris`, `iris.beep`, `iris.xpc`, `iris.xpcs`, `iris.lwz`, `ldap`, `ipp`, `iris`, `iris.beep`, `iris.xpc`, `iris.xpcs`, `iris.lwz`, `ldap`,
`mailto`, `mid`, `msrp`, `msrps`, `mtqp`, `mupdate`, `news`, `nfs`, `mailto`, `mid`, `msrp`, `msrps`, `mtqp`, `mupdate`, `news`, `nfs`,
`ni`, `nih`, `nntp`, `opaquelocktoken`, `pop`, `pres`, `rtsp`, `ni`, `nih`, `nntp`, `opaquelocktoken`, `pop`, `pres`, `rtsp`,
`service`, `session`, `shttp`, `sieve`, `sip`, `sips`, `sms`, `snmp`,` `service`, `session`, `shttp`, `sieve`, `sip`, `sips`, `sms`, `snmp`,`
skipping to change at line 6252 skipping to change at line 6583
. .
An [email autolink](@email-autolink) An [email autolink](@email-autolink)
consists of `<`, followed by an [email address](#email-address), consists of `<`, followed by an [email address](#email-address),
followed by `>`. The link's label is the email address, followed by `>`. The link's label is the email address,
and the URL is `mailto:` followed by the email address. and the URL is `mailto:` followed by the email address.
An [email address](@email-address), An [email address](@email-address),
for these purposes, is anything that matches for these purposes, is anything that matches
the [non-normative regex from the HTML5 the [non-normative regex from the HTML5
spec](http://www.whatwg.org/specs/web-apps/current-work/multipage/forms.html#e-m ail-state-%28type=email%29) spec](https://html.whatwg.cn/multipage/forms.html#e-mail-state-(type=email ))
/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0- 9])? /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0- 9])?
(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/ (?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/
电子邮件自动链接示例: 电子邮件自动链接示例:
. .
<foo@bar.example.com> <foo@bar.example.com>
. .
<p><a href="mailto:foo@bar.example.com">foo@bar.example.com</a></p> <p><a href="mailto:foo@bar.example.com">foo@bar.example.com</a></p>
skipping to change at line 6327 skipping to change at line 6658
Text between `<` and `>` that looks like an HTML tag is parsed as a Text between `<` and `>` that looks like an HTML tag is parsed as a
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](@tag-name) consists of an ASCII letter A [tag name](@tag-name) consists of an ASCII letter
followed by zero or more ASCII letters or digits. followed by zero or more ASCII letters or digits.
An [attribute](@attribute) consists of whitespace, An [attribute](@attribute) consists of [whitespace](#whitespace),
an [attribute name](#attribute-name), and an optional an [attribute name](#attribute-name), and an optional
[attribute value specification](#attribute-value-specification). [attribute value specification](#attribute-value-specification).
An [attribute name](@attribute-name) An [attribute name](@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](@attribute-value-specification) An [attribute value specification](@attribute-value-specification)
consists of optional whitespace, consists of optional [whitespace](#whitespace),
a `=` character, optional whitespace, and an [attribute a `=` character, optional [whitespace](#whitespace), and an [attribute
value](#attribute-value). value](#attribute-value).
An [attribute value](@attribute-value) An [attribute value](@attribute-value)
consists of an [unquoted attribute value](#unquoted-attribute-value), consists of an [unquoted attribute value](#unquoted-attribute-value),
a [single-quoted attribute value](#single-quoted-attribute-value), a [single-quoted attribute value](#single-quoted-attribute-value),
or a [double-quoted attribute value](#double-quoted-attribute-value). or a [double-quoted attribute value](#double-quoted-attribute-value).
An [unquoted attribute value](@unquoted-attribute-value) An [unquoted attribute value](@unquoted-attribute-value)
是非空字符串, 是非空字符串,
including spaces, `"`, `'`, `=`, `<`, `>`, or `` ` ``. including spaces, `"`, `'`, `=`, `<`, `>`, or `` ` ``.
skipping to change at line 6360 skipping to change at line 6691
A [single-quoted attribute value](@single-quoted-attribute-value) A [single-quoted attribute value](@single-quoted-attribute-value)
由`'`、零个或多个 由`'`、零个或多个
不包含`'`的字符,以及一个最终的`'`组成。 不包含`'`的字符,以及一个最终的`'`组成。
A [double-quoted attribute value](@double-quoted-attribute-value) A [double-quoted attribute value](@double-quoted-attribute-value)
由`"`、零个或多个 由`"`、零个或多个
characters not including `"`, and a final `"`. characters not including `"`, and a final `"`.
An [open tag](@open-tag) consists of a `<` character, An [open tag](@open-tag) consists of a `<` character,
a [tag name](#tag-name), zero or more [attributes](#attribute), a [tag name](#tag-name), zero or more [attributes](#attribute),
optional whitespace, an optional `/` character, and a `>` character. optional [whitespace](#whitespace), an optional `/` character, and a
`>` character.
A [closing tag](@closing-tag) consists of the A [closing tag](@closing-tag) consists of the
string `</`, a [tag name](#tag-name), optional whitespace, and the string `</`, a [tag name](#tag-name), optional
character `>`. [whitespace](#whitespace), and the character `>`.
An [HTML comment](@html-comment) consists of the An [HTML comment](@html-comment) consists of the
string `<!--`, a string of characters not including the string `--`, and string `<!--`, a string of characters not including the string `--`, and
the string `-->`. the string `-->`.
A [processing instruction](@processing-instruction) A [processing instruction](@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](@declaration) consists of the A [declaration](@declaration) consists of the
字符串 `<!`,一个由一个或多个大写 ASCII 字母组成的名称, 字符串 `<!`,一个由一个或多个大写 ASCII 字母组成的名称,
whitespace, a string of characters not including the character `>`, and [whitespace](#whitespace), a string of characters not including the
the character `>`. 字符 `>`,以及字符 `>` 组成。
A [CDATA section](@cdata-section) consists of A [CDATA section](@cdata-section) consists of
字符串 `<![CDATA[`,一个不包含字符串 `]]>` 的字符序列,以及字符串 `]]>` 组成。 字符串 `<![CDATA[`,一个不包含字符串 `]]>` 的字符序列,以及字符串 `]]>` 组成。
`]]>`,以及字符串 `]]>` 组成。 `]]>`,以及字符串 `]]>` 组成。
An [HTML tag](@html-tag) consists of an [open An [HTML tag](@html-tag) consists of an [open
tag](#open-tag), a [closing tag](#closing-tag), an [HTML tag](#open-tag), a [closing tag](#closing-tag), an [HTML
comment](#html-comment), a [processing comment](#html-comment), a [processing instruction](#processing-instruction),
instruction](#processing-instruction), an [element type a [declaration](#declaration), or a [CDATA section](#cdata-section).
declaration](#element-type-declaration), or a [CDATA
section](#cdata-section).
以下是一些简单的开始标签 以下是一些简单的开始标签
. .
<a><bab><c2c> <a><bab><c2c>
. .
<p><a><bab><c2c></p> <p><a><bab><c2c></p>
. .
空元素 空元素
. .
<a/><b2/> <a/><b2/>
. .
<p><a/><b2/></p> <p><a/><b2/></p>
. .
Whitespace is allowed [Whitespace](#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 6451 skipping to change at line 6781
. .
非法属性值 非法属性值
. .
<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](#whitespace)
. .
< a>< < a><
foo><bar/ > foo><bar/ >
. .
<p>&lt; a&gt;&lt; <p>&lt; a&gt;&lt;
foo&gt;&lt;bar/ &gt;</p> foo&gt;&lt;bar/ &gt;</p>
. .
Missing whitespace Missing [whitespace](#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 6564 skipping to change at line 6894
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>
. .
For a more visible alternative, a backslash before the newline may be 为了更清晰的替代方案,在 [换行符](#line-ending) 前使用反斜杠代替两个空格
used instead of two spaces [line ending](#line-ending) may be used instead of two spaces
. .
foo\ foo\
baz baz
. .
<p>foo<br /> <p>foo<br />
baz</p> baz</p>
. .
可以使用超过两个的空格 可以使用超过两个的空格
skipping to change at line 6688 skipping to change at line 7018
. .
### 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 break (not in a code span or HTML tag) that is not
后跟两个或更多空格被解析为软换行。(一个 后跟两个或更多空格被解析为软换行。(一个
softbreak may be rendered in HTML either as a newline or as a space. 软换行在 HTML 中可以渲染为
The result will be the same in browsers. In the examples here, a [line ending](#line-ending) or as a space. The result will be the same
newline will be used.) in browsers. In the examples here, a [line ending](#line-ending) will
be used.)
. .
foo foo
baz baz
. .
<p>foo <p>foo
baz</p> baz</p>
. .
行尾和下一行开头的空格是 行尾和下一行开头的空格是
skipping to change at line 6925 skipping to change at line 7256
list_item list_item
paragraph paragraph
str "Qui " str "Qui "
emph emph
str "quodsi iracundia" str "quodsi iracundia"
list_item list_item
paragraph paragraph
str "aliquando id" str "aliquando id"
``` ```
Notice how the newline in the first paragraph has been parsed as Notice how the [line ending](#line-ending) in the first paragraph has
a `softbreak`, and the asterisks in the first list item have become 并且第一个列表项中的星号已变为 `emph`。
an `emph`. 已变为 `emph`。
文档可以渲染为 HTML,或任何其他格式,如果给定 文档可以渲染为 HTML,或任何其他格式,如果给定
一个合适的渲染器。 一个合适的渲染器。
 End of changes. 82 change blocks. 
164 lines changed or deleted 496 lines changed or added

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