| spec.txt | spec.txt | |||
|---|---|---|---|---|
| --- | --- | |||
| 标题: CommonMark 规范 | 标题: CommonMark 规范 | |||
| 作者 | 作者 | |||
| - John MacFarlane | - John MacFarlane | |||
| version: 0.12 | version: 0.13 | |||
| date: 2014-11-10 | date: 2014-12-10 | |||
| ... | ... | |||
| # 引言 | # 引言 | |||
| ## 什么是 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 173 | skipping to change at line 173 | |||
| a document that renders one way on one system (say, a github wiki) | a document that renders one way on one system (say, a github wiki) | |||
| renders differently on another (say, converting to docbook using | renders differently on another (say, converting to docbook using | |||
| pandoc). To make matters worse, because nothing in Markdown counts | pandoc). To make matters worse, because nothing in Markdown counts | |||
| as a "syntax error," the divergence often isn't discovered right away. | as a "syntax error," the divergence often isn't discovered right away. | |||
| ## About this document | ## About this document | |||
| This document attempts to specify Markdown syntax unambiguously. | This document attempts to specify Markdown syntax unambiguously. | |||
| It contains many examples with side-by-side Markdown and | It contains many examples with side-by-side Markdown and | |||
| HTML. These are intended to double as conformance tests. An | HTML. These are intended to double as conformance tests. An | |||
| accompanying script `runtests.pl` can be used to run the tests | accompanying script `spec_tests.py` can be used to run the tests | |||
| against any Markdown program | against any Markdown program | |||
| perl runtests.pl spec.txt 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. | |||
| 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. | |||
| skipping to change at line 226 | skipping to change at line 226 | |||
| <pre><code>a a | <pre><code>a a | |||
| ὐ a | ὐ a | |||
| </code></pre> | </code></pre> | |||
| . | . | |||
| 行结束符会被替换为换行符 (LF)。 | 行结束符会被替换为换行符 (LF)。 | |||
| A line containing no characters, or a line containing only spaces (after | A line containing no characters, or a line containing only spaces (after | |||
| tab expansion), is called a [blank line](@blank-line). | 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 471 | skipping to change at line 474 | |||
| . | . | |||
| 如果你想在列表项中使用水平分割线,请使用不同的项目符号 | 如果你想在列表项中使用水平分割线,请使用不同的项目符号 | |||
| . | . | |||
| - Foo | - Foo | |||
| - * * * | - * * * | |||
| . | . | |||
| <ul> | <ul> | |||
| <li>Foo</li> | <li>Foo</li> | |||
| <li><hr /></li> | <li> | |||
| <hr /> | ||||
| </li> | ||||
| </ul> | </ul> | |||
| . | . | |||
| ## ATX 标题 | ## ATX 标题 | |||
| 一个 [ATX 标题](@atx-header) | 一个 [ATX 标题](@atx-header) | |||
| 由一串字符组成,被解析为行内内容,位于 | 由一串字符组成,被解析为行内内容,位于 | |||
| 起始的 1--6 个未转义的 `#` 字符和一个可选的 | 起始的 1--6 个未转义的 `#` 字符和一个可选的 | |||
| 结尾的任意数量的 `#` 字符之间。起始序列 | 结尾的任意数量的 `#` 字符之间。起始序列 | |||
| of `#` characters cannot be followed directly by a nonspace character. | of `#` characters cannot be followed directly by a nonspace character. | |||
| skipping to change at line 2516 | skipping to change at line 2521 | |||
| . | . | |||
| 1. A paragraph | 1. A paragraph | |||
| with two lines. | with two lines. | |||
| indented code | indented code | |||
| > A block quote. | > A block quote. | |||
| . | . | |||
| <ol> | <ol> | |||
| <li><p>A paragraph | <li> | |||
| <p>A paragraph | ||||
| with two lines.</p> | with two lines.</p> | |||
| <pre><code>indented code | <pre><code>indented code | |||
| </code></pre> | </code></pre> | |||
| <blockquote> | <blockquote> | |||
| <p>A block quote.</p> | <p>A block quote.</p> | |||
| </blockquote></li> | </blockquote> | |||
| </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, and there are three spaces between | |||
| the list marker and the next nonspace character, then blocks | the list marker and the next nonspace character, 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. | |||
| skipping to change at line 2554 | skipping to change at line 2561 | |||
| </ul> | </ul> | |||
| <p>two</p> | <p>two</p> | |||
| . | . | |||
| . | . | |||
| - one | - one | |||
| two | two | |||
| . | . | |||
| <ul> | <ul> | |||
| <li><p>one</p> | <li> | |||
| <p>two</p></li> | <p>one</p> | |||
| <p>two</p> | ||||
| </li> | ||||
| </ul> | </ul> | |||
| . | . | |||
| . | . | |||
| - one | - one | |||
| two | two | |||
| . | . | |||
| <ul> | <ul> | |||
| <li>one</li> | <li>one</li> | |||
| skipping to change at line 2577 | skipping to change at line 2586 | |||
| <pre><code> two | <pre><code> two | |||
| </code></pre> | </code></pre> | |||
| . | . | |||
| . | . | |||
| - one | - one | |||
| two | two | |||
| . | . | |||
| <ul> | <ul> | |||
| <li><p>one</p> | <li> | |||
| <p>two</p></li> | <p>one</p> | |||
| <p>two</p> | ||||
| </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 nonspace | blocks must be indented at least to the column of the first nonspace | |||
| character after the list marker. However, that is not quite right. | character after the list marker. However, that is not quite right. | |||
| The spaces after the list marker determine how much relative indentation | The spaces after the list marker determine how much relative indentation | |||
| is needed. Which column this indentation reaches will depend on | 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> | |||
| <ol> | <ol> | |||
| <li><p>one</p> | <li> | |||
| <p>two</p></li> | <p>one</p> | |||
| <p>two</p> | ||||
| </li> | ||||
| </ol> | </ol> | |||
| </blockquote> | </blockquote> | |||
| </blockquote> | </blockquote> | |||
| . | . | |||
| Here `two` occurs in the same column as the list marker `1.`, | Here `two` occurs in the same column as the list marker `1.`, | |||
| but is actually contained in the list item, because there is | but is actually contained in the list item, because there is | |||
| sufficent indentation after the last containing blockquote marker. | sufficent indentation after the last containing blockquote marker. | |||
| The converse is also possible. In the following example, the word `two` | The converse is also possible. In the following example, the word `two` | |||
| skipping to change at line 2649 | skipping to change at line 2662 | |||
| bar | bar | |||
| - ``` | - ``` | |||
| foo | foo | |||
| bar | bar | |||
| ``` | ``` | |||
| . | . | |||
| <ul> | <ul> | |||
| <li><p>foo</p> | <li> | |||
| <p>bar</p></li> | <p>foo</p> | |||
| <li><p>foo</p></li> | <p>bar</p> | |||
| </li> | ||||
| <li> | ||||
| <p>foo</p> | ||||
| </li> | ||||
| </ul> | </ul> | |||
| <p>bar</p> | <p>bar</p> | |||
| <ul> | <ul> | |||
| <li><pre><code>foo | <li> | |||
| <pre><code>foo | ||||
| bar | bar | |||
| </code></pre></li> | </code></pre> | |||
| </li> | ||||
| </ul> | </ul> | |||
| . | . | |||
| 列表项可以包含任何类型的块 | 列表项可以包含任何类型的块 | |||
| . | . | |||
| 1. foo | 1. foo | |||
| ``` | ``` | |||
| bar | bar | |||
| ``` | ``` | |||
| baz | baz | |||
| > bam | > bam | |||
| . | . | |||
| <ol> | <ol> | |||
| <li><p>foo</p> | <li> | |||
| <p>foo</p> | ||||
| <pre><code>bar | <pre><code>bar | |||
| </code></pre> | </code></pre> | |||
| <p>baz</p> | <p>baz</p> | |||
| <blockquote> | <blockquote> | |||
| <p>bam</p> | <p>bam</p> | |||
| </blockquote></li> | </blockquote> | |||
| </li> | ||||
| </ol> | </ol> | |||
| . | . | |||
| 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 | |||
| 块,且彼此之间没有被超过一个空行隔开, | 块,且彼此之间没有被超过一个空行隔开, | |||
| and *M* is a list marker *M* of width *W* followed by | and *M* is a list marker *M* of width *W* followed by | |||
| 一个空格,则预置*M*和其后的 | 一个空格,则预置*M*和其后的 | |||
| space to the first line of *Ls*, and indenting subsequent lines of | space to the first line of *Ls*, and indenting subsequent lines of | |||
| *Ls* by *W + 1* spaces, is a list item with *Bs* as its contents. | *Ls* by *W + 1* spaces, is a list item with *Bs* as its contents. | |||
| skipping to change at line 2708 | skipping to change at line 2729 | |||
| 一个缩进的代码块需要比段落多缩进四个空格。 | 一个缩进的代码块需要比段落多缩进四个空格。 | |||
| the edge of the region where text will be included in the list item. | the edge of the region where text will be included in the list item. | |||
| In the following case that is 6 spaces | In the following case that is 6 spaces | |||
| . | . | |||
| - foo | - foo | |||
| bar | bar | |||
| . | . | |||
| <ul> | <ul> | |||
| <li><p>foo</p> | <li> | |||
| <p>foo</p> | ||||
| <pre><code>bar | <pre><code>bar | |||
| </code></pre></li> | </code></pre> | |||
| </li> | ||||
| </ul> | </ul> | |||
| . | . | |||
| 在这种情况下为 11 个空格 | 在这种情况下为 11 个空格 | |||
| . | . | |||
| 10. foo | 10. foo | |||
| bar | bar | |||
| . | . | |||
| <ol start="10"> | <ol start="10"> | |||
| <li><p>foo</p> | <li> | |||
| <p>foo</p> | ||||
| <pre><code>bar | <pre><code>bar | |||
| </code></pre></li> | </code></pre> | |||
| </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 indented *one* space after the | |||
| list marker | list marker | |||
| . | . | |||
| indented code | indented code | |||
| skipping to change at line 2754 | skipping to change at line 2779 | |||
| . | . | |||
| . | . | |||
| 1. indented code | 1. indented code | |||
| paragraph | paragraph | |||
| more code | more code | |||
| . | . | |||
| <ol> | <ol> | |||
| <li><pre><code>indented code | <li> | |||
| <pre><code>indented code | ||||
| </code></pre> | </code></pre> | |||
| <p>paragraph</p> | <p>paragraph</p> | |||
| <pre><code>more code | <pre><code>more code | |||
| </code></pre></li> | </code></pre> | |||
| </li> | ||||
| </ol> | </ol> | |||
| . | . | |||
| Note that an additional space indent is interpreted as space | Note that an additional space indent 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> | |||
| <li><pre><code> indented code | <li> | |||
| <pre><code> indented code | ||||
| </code></pre> | </code></pre> | |||
| <p>paragraph</p> | <p>paragraph</p> | |||
| <pre><code>more code | <pre><code>more code | |||
| </code></pre></li> | </code></pre> | |||
| </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 nonspace | in which the lines to be included in a list item begin with a nonspace | |||
| character, and (b) cases in which they begin with an indented code | character, and (b) cases in which 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 | a three-space indent, 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 | |||
| skipping to change at line 2819 | skipping to change at line 2848 | |||
| with 1-3 spaces indent, the indentation can always be removed without | with 1-3 spaces indent, 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><p>foo</p> | <li> | |||
| <p>bar</p></li> | <p>foo</p> | |||
| <p>bar</p> | ||||
| </li> | ||||
| </ul> | </ul> | |||
| . | . | |||
| 3. **Indentation.** If a sequence of lines *Ls* constitutes a list item | 3. **Indentation.** If a sequence of lines *Ls* constitutes a list item | |||
| according to rule #1 or #2, then the result of indenting each line | according to rule #1 or #2, 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. | |||
| indented code | indented code | |||
| > A block quote. | > A block quote. | |||
| . | . | |||
| <ol> | <ol> | |||
| <li><p>A paragraph | <li> | |||
| <p>A paragraph | ||||
| with two lines.</p> | with two lines.</p> | |||
| <pre><code>indented code | <pre><code>indented code | |||
| </code></pre> | </code></pre> | |||
| <blockquote> | <blockquote> | |||
| <p>A block quote.</p> | <p>A block quote.</p> | |||
| </blockquote></li> | </blockquote> | |||
| </li> | ||||
| </ol> | </ol> | |||
| . | . | |||
| 缩进两个空格 | 缩进两个空格 | |||
| . | . | |||
| 1. A paragraph | 1. A paragraph | |||
| with two lines. | with two lines. | |||
| indented code | indented code | |||
| > A block quote. | > A block quote. | |||
| . | . | |||
| <ol> | <ol> | |||
| <li><p>A paragraph | <li> | |||
| <p>A paragraph | ||||
| with two lines.</p> | with two lines.</p> | |||
| <pre><code>indented code | <pre><code>indented code | |||
| </code></pre> | </code></pre> | |||
| <blockquote> | <blockquote> | |||
| <p>A block quote.</p> | <p>A block quote.</p> | |||
| </blockquote></li> | </blockquote> | |||
| </li> | ||||
| </ol> | </ol> | |||
| . | . | |||
| 缩进三个空格 | 缩进三个空格 | |||
| . | . | |||
| 1. A paragraph | 1. A paragraph | |||
| with two lines. | with two lines. | |||
| indented code | indented code | |||
| > A block quote. | > A block quote. | |||
| . | . | |||
| <ol> | <ol> | |||
| <li><p>A paragraph | <li> | |||
| <p>A paragraph | ||||
| with two lines.</p> | with two lines.</p> | |||
| <pre><code>indented code | <pre><code>indented code | |||
| </code></pre> | </code></pre> | |||
| <blockquote> | <blockquote> | |||
| <p>A block quote.</p> | <p>A block quote.</p> | |||
| </blockquote></li> | </blockquote> | |||
| </li> | ||||
| </ol> | </ol> | |||
| . | . | |||
| 四个空格缩进产生一个代码块 | 四个空格缩进产生一个代码块 | |||
| . | . | |||
| 1. A paragraph | 1. A paragraph | |||
| with two lines. | with two lines. | |||
| indented code | indented code | |||
| skipping to change at line 2933 | skipping to change at line 2970 | |||
| . | . | |||
| 1. A paragraph | 1. A paragraph | |||
| with two lines. | with two lines. | |||
| indented code | indented code | |||
| > A block quote. | > A block quote. | |||
| . | . | |||
| <ol> | <ol> | |||
| <li><p>A paragraph | <li> | |||
| <p>A paragraph | ||||
| with two lines.</p> | with two lines.</p> | |||
| <pre><code>indented code | <pre><code>indented code | |||
| </code></pre> | </code></pre> | |||
| <blockquote> | <blockquote> | |||
| <p>A block quote.</p> | <p>A block quote.</p> | |||
| </blockquote></li> | </blockquote> | |||
| </li> | ||||
| </ol> | </ol> | |||
| . | . | |||
| 缩进可以被部分删除 | 缩进可以被部分删除 | |||
| . | . | |||
| 1. A paragraph | 1. A paragraph | |||
| with two lines. | with two lines. | |||
| . | . | |||
| <ol> | <ol> | |||
| skipping to change at line 2963 | skipping to change at line 3002 | |||
| . | . | |||
| 这些示例显示了惰性匹配如何在嵌套结构中工作 | 这些示例显示了惰性匹配如何在嵌套结构中工作 | |||
| . | . | |||
| > 1. > Blockquote | > 1. > Blockquote | |||
| continued here. | continued here. | |||
| . | . | |||
| <blockquote> | <blockquote> | |||
| <ol> | <ol> | |||
| <li><blockquote> | <li> | |||
| <blockquote> | ||||
| <p>Blockquote | <p>Blockquote | |||
| 在此处继续。</p> | 在此处继续。</p> | |||
| </blockquote></li> | </blockquote> | |||
| </li> | ||||
| </ol> | </ol> | |||
| </blockquote> | </blockquote> | |||
| . | . | |||
| . | . | |||
| > 1. > Blockquote | > 1. > Blockquote | |||
| > continued here. | > continued here. | |||
| . | . | |||
| <blockquote> | <blockquote> | |||
| <ol> | <ol> | |||
| <li><blockquote> | <li> | |||
| <blockquote> | ||||
| <p>Blockquote | <p>Blockquote | |||
| 在此处继续。</p> | 在此处继续。</p> | |||
| </blockquote></li> | </blockquote> | |||
| </li> | ||||
| </ol> | </ol> | |||
| </blockquote> | </blockquote> | |||
| . | . | |||
| 5. **That's all.** Nothing that is not counted as a list item by rules | 5. **That's all.** Nothing that is not counted as a list item by rules | |||
| #1--4 counts as a [list item](#list-item). | #1--4 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. | |||
| skipping to change at line 3005 | skipping to change at line 3048 | |||
| - foo | - foo | |||
| - bar | - bar | |||
| - baz | - baz | |||
| . | . | |||
| <ul> | <ul> | |||
| <li>foo | <li>foo | |||
| <ul> | <ul> | |||
| <li>bar | <li>bar | |||
| <ul> | <ul> | |||
| <li>baz</li> | <li>baz</li> | |||
| </ul></li> | </ul> | |||
| </ul></li> | </li> | |||
| </ul> | ||||
| </li> | ||||
| </ul> | </ul> | |||
| . | . | |||
| 一个空格是不够的 | 一个空格是不够的 | |||
| . | . | |||
| - foo | - foo | |||
| - bar | - bar | |||
| - baz | - baz | |||
| . | . | |||
| skipping to change at line 3034 | skipping to change at line 3079 | |||
| 这里我们需要四个,因为列表标记更宽 | 这里我们需要四个,因为列表标记更宽 | |||
| . | . | |||
| 10) foo | 10) foo | |||
| - bar | - bar | |||
| . | . | |||
| <ol start="10"> | <ol start="10"> | |||
| <li>foo | <li>foo | |||
| <ul> | <ul> | |||
| <li>bar</li> | <li>bar</li> | |||
| </ul></li> | </ul> | |||
| </li> | ||||
| </ol> | </ol> | |||
| . | . | |||
| 三个空格是不够的 | 三个空格是不够的 | |||
| . | . | |||
| 10) foo | 10) foo | |||
| - bar | - bar | |||
| . | . | |||
| <ol start="10"> | <ol start="10"> | |||
| skipping to change at line 3058 | skipping to change at line 3104 | |||
| <li>bar</li> | <li>bar</li> | |||
| </ul> | </ul> | |||
| . | . | |||
| 列表可以是列表项中的第一个块 | 列表可以是列表项中的第一个块 | |||
| . | . | |||
| - - foo | - - foo | |||
| . | . | |||
| <ul> | <ul> | |||
| <li><ul> | <li> | |||
| <ul> | ||||
| <li>foo</li> | <li>foo</li> | |||
| </ul></li> | </ul> | |||
| </li> | ||||
| </ul> | </ul> | |||
| . | . | |||
| . | . | |||
| 1. - 2. foo | 1. - 2. foo | |||
| . | . | |||
| <ol> | <ol> | |||
| <li><ul> | <li> | |||
| <li><ol start="2"> | <ul> | |||
| <li> | ||||
| <ol start="2"> | ||||
| <li>foo</li> | <li>foo</li> | |||
| </ol></li> | </ol> | |||
| </ul></li> | </li> | |||
| </ul> | ||||
| </li> | ||||
| </ol> | </ol> | |||
| . | . | |||
| 列表项可以为空 | 列表项可以为空 | |||
| . | . | |||
| - foo | - foo | |||
| - | - | |||
| - bar | - bar | |||
| . | . | |||
| skipping to change at line 3107 | skipping to change at line 3159 | |||
| 列表项可以包含标题 | 列表项可以包含标题 | |||
| . | . | |||
| - # Foo | - # Foo | |||
| - Bar | - Bar | |||
| --- | --- | |||
| baz | baz | |||
| . | . | |||
| <ul> | <ul> | |||
| <li><h1>Foo</h1></li> | <li> | |||
| <li><h2>Bar</h2> | <h1>Foo</h1> | |||
| <p>baz</p></li> | </li> | |||
| <li> | ||||
| <h2>Bar</h2> | ||||
| baz</li> | ||||
| </ul> | </ul> | |||
| . | . | |||
| ### Motivation | ### Motivation | |||
| John Gruber 的 Markdown 规范中关于列表项的描述如下: | John Gruber 的 Markdown 规范中关于列表项的描述如下: | |||
| 1. "List markers typically start at the left margin, but may be indented | 1. "List markers typically start at the left margin, but may be indented | |||
| by up to three spaces. List markers must be followed by one or more | by up to three spaces. List markers must be followed by one or more | |||
| spaces or a tab." | spaces or a tab." | |||
| skipping to change at line 3204 | skipping to change at line 3259 | |||
| <p>bar</p> | <p>bar</p> | |||
| <ul> | <ul> | |||
| <li>baz</li> | <li>baz</li> | |||
| </ul> | </ul> | |||
| ``` | ``` | |||
| 如四空格规则所要求的那样,而不是一个单一的列表,这非常不直观。 | 如四空格规则所要求的那样,而不是一个单一的列表,这非常不直观。 | |||
| ``` html | ``` html | |||
| <ul> | <ul> | |||
| <li><p>foo</p> | <li> | |||
| <p>foo</p> | ||||
| <p>bar</p> | <p>bar</p> | |||
| <ul> | <ul> | |||
| <li>baz</li> | <li>baz</li> | |||
| </ul></li> | </ul> | |||
| </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 1--3 spaces indentation of the | |||
| initial list marker, allows text that is indented *less than* 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, | |||
| skipping to change at line 3231 | skipping to change at line 3288 | |||
| ``` 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 | |||
| ``` html | ``` html | |||
| <ul> | <ul> | |||
| <li><p>one</p> | <li> | |||
| <p>two</p></li> | <p>one</p> | |||
| <p>two</p> | ||||
| </li> | ||||
| </ul> | </ul> | |||
| ``` | ``` | |||
| 同样 | 同样 | |||
| ``` markdown | ``` markdown | |||
| > - one | > - one | |||
| > | > | |||
| > two | > two | |||
| ``` | ``` | |||
| 作为 | 作为 | |||
| ``` html | ``` html | |||
| <blockquote> | <blockquote> | |||
| <ul> | <ul> | |||
| <li><p>one</p> | <li> | |||
| <p>two</p></li> | <p>one</p> | |||
| <p>two</p> | ||||
| </li> | ||||
| </ul> | </ul> | |||
| </blockquote> | </blockquote> | |||
| ``` | ``` | |||
| 这是极其不直观的。 | 这是极其不直观的。 | |||
| Rather than requiring a fixed indent from the margin, we could require | Rather than requiring a fixed indent from the margin, we could require | |||
| a fixed indent (say, two spaces, or even one space) from the list marker (which | a fixed indent (say, two spaces, or even one space) from the list marker (which | |||
| may itself be indented). This proposal would remove the last anomaly | may itself be indented). This proposal would remove the last anomaly | |||
| discussed. Unlike the spec presented above, it would count the following | discussed. Unlike the spec presented above, it would count the following | |||
| skipping to change at line 3447 | skipping to change at line 3508 | |||
| a list | a list | |||
| . | . | |||
| - foo | - foo | |||
| - bar | - bar | |||
| - baz | - baz | |||
| . | . | |||
| <ul> | <ul> | |||
| <li><p>foo</p></li> | <li> | |||
| <li><p>bar</p></li> | <p>foo</p> | |||
| </li> | ||||
| <li> | ||||
| <p>bar</p> | ||||
| </li> | ||||
| </ul> | </ul> | |||
| <ul> | <ul> | |||
| <li>baz</li> | <li>baz</li> | |||
| </ul> | </ul> | |||
| . | . | |||
| As illustrated above in the section on [list items](#list-item), | As illustrated above in the section on [list items](#list-item), | |||
| two blank lines between blocks *within* a list item will also end a | two blank lines between blocks *within* a list item will also end a | |||
| list | list | |||
| skipping to change at line 3489 | skipping to change at line 3554 | |||
| - baz | - baz | |||
| bim | bim | |||
| . | . | |||
| <ul> | <ul> | |||
| <li>foo | <li>foo | |||
| <ul> | <ul> | |||
| <li>bar | <li>bar | |||
| <ul> | <ul> | |||
| <li>baz</li> | <li>baz</li> | |||
| </ul></li> | </ul> | |||
| </ul></li> | </li> | |||
| </ul> | ||||
| </li> | ||||
| </ul> | </ul> | |||
| <pre><code> bim | <pre><code> bim | |||
| </code></pre> | </code></pre> | |||
| . | . | |||
| Thus, two blank lines can be used to separate consecutive lists of | Thus, two blank lines can be used to separate consecutive lists of | |||
| the same type, or to separate a list from an indented code block | the same type, or to separate a list from an indented code block | |||
| that would otherwise be parsed as a subparagraph of the final list | that would otherwise be parsed as a subparagraph of the final list | |||
| item | item | |||
| skipping to change at line 3528 | skipping to change at line 3595 | |||
| . | . | |||
| - foo | - foo | |||
| notcode | notcode | |||
| - foo | - foo | |||
| code | code | |||
| . | . | |||
| <ul> | <ul> | |||
| <li><p>foo</p> | <li> | |||
| <p>notcode</p></li> | <p>foo</p> | |||
| <li><p>foo</p></li> | <p>notcode</p> | |||
| </li> | ||||
| <li> | ||||
| <p>foo</p> | ||||
| </li> | ||||
| </ul> | </ul> | |||
| <pre><code>code | <pre><code>code | |||
| </code></pre> | </code></pre> | |||
| . | . | |||
| 列表项不需要缩进到相同的级别。以下 | 列表项不需要缩进到相同的级别。以下 | |||
| 列表项将被视为同一列表级别的项目, | 列表项将被视为同一列表级别的项目, | |||
| 因为没有一个缩进足够深以属于前一个列表 | 因为没有一个缩进足够深以属于前一个列表 | |||
| item | item | |||
| skipping to change at line 3571 | skipping to change at line 3642 | |||
| 这是一个松散的列表,因为在两个列表项之间有一个空行 | 这是一个松散的列表,因为在两个列表项之间有一个空行 | |||
| 两个列表项 | 两个列表项 | |||
| . | . | |||
| - a | - a | |||
| - b | - b | |||
| - c | - c | |||
| . | . | |||
| <ul> | <ul> | |||
| <li><p>a</p></li> | <li> | |||
| <li><p>b</p></li> | <p>a</p> | |||
| <li><p>c</p></li> | </li> | |||
| <li> | ||||
| <p>b</p> | ||||
| </li> | ||||
| <li> | ||||
| <p>c</p> | ||||
| </li> | ||||
| </ul> | </ul> | |||
| . | . | |||
| 这也是,第二个项为空 | 这也是,第二个项为空 | |||
| . | . | |||
| * a | * a | |||
| * | * | |||
| * c | * c | |||
| . | . | |||
| <ul> | <ul> | |||
| <li><p>a</p></li> | <li> | |||
| <p>a</p> | ||||
| </li> | ||||
| <li></li> | <li></li> | |||
| <li><p>c</p></li> | <li> | |||
| <p>c</p> | ||||
| </li> | ||||
| </ul> | </ul> | |||
| . | . | |||
| These are loose lists, even though there is no space between the items, | These are loose lists, even though there is no space 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 | |||
| . | . | |||
| <ul> | <ul> | |||
| <li><p>a</p></li> | <li> | |||
| <li><p>b</p> | <p>a</p> | |||
| <p>c</p></li> | </li> | |||
| <li><p>d</p></li> | <li> | |||
| <p>b</p> | ||||
| <p>c</p> | ||||
| </li> | ||||
| <li> | ||||
| <p>d</p> | ||||
| </li> | ||||
| </ul> | </ul> | |||
| . | . | |||
| . | . | |||
| - a | - a | |||
| - b | - b | |||
| [ref]: /url | [ref]: /url | |||
| - d | - d | |||
| . | . | |||
| <ul> | <ul> | |||
| <li><p>a</p></li> | <li> | |||
| <li><p>b</p></li> | <p>a</p> | |||
| <li><p>d</p></li> | </li> | |||
| <li> | ||||
| <p>b</p> | ||||
| </li> | ||||
| <li> | ||||
| <p>d</p> | ||||
| </li> | ||||
| </ul> | </ul> | |||
| . | . | |||
| 这是一个紧凑列表,因为空行在代码块中 | 这是一个紧凑列表,因为空行在代码块中 | |||
| . | . | |||
| - a | - a | |||
| - ``` | - ``` | |||
| b | b | |||
| ``` | ``` | |||
| - c | - c | |||
| . | . | |||
| <ul> | <ul> | |||
| <li>a</li> | <li>a</li> | |||
| <li><pre><code>b | <li> | |||
| <pre><code>b | ||||
| </code></pre></li> | </code></pre> | |||
| </li> | ||||
| <li>c</li> | <li>c</li> | |||
| </ul> | </ul> | |||
| . | . | |||
| This is a tight list, because the blank line is between two | This is a tight list, because the blank line is between two | |||
| paragraphs of a sublist. So the sublist is loose while | paragraphs of a sublist. So the sublist is loose while | |||
| the outer list is tight | the outer list is tight | |||
| . | . | |||
| - a | - a | |||
| - b | - b | |||
| c | c | |||
| - d | - d | |||
| . | . | |||
| <ul> | <ul> | |||
| <li>a | <li>a | |||
| <ul> | <ul> | |||
| <li><p>b</p> | <li> | |||
| <p>c</p></li> | <p>b</p> | |||
| </ul></li> | <p>c</p> | |||
| </li> | ||||
| </ul> | ||||
| </li> | ||||
| <li>d</li> | <li>d</li> | |||
| </ul> | </ul> | |||
| . | . | |||
| This is a tight list, because the blank line is inside the | This is a tight list, because the blank line is inside the | |||
| block quote | block quote | |||
| . | . | |||
| * a | * a | |||
| > b | > b | |||
| > | > | |||
| * c | * c | |||
| . | . | |||
| <ul> | <ul> | |||
| <li>a | <li>a | |||
| <blockquote> | <blockquote> | |||
| <p>b</p> | <p>b</p> | |||
| </blockquote></li> | </blockquote> | |||
| </li> | ||||
| <li>c</li> | <li>c</li> | |||
| </ul> | </ul> | |||
| . | . | |||
| This list is tight, because the consecutive block elements | This list is tight, because the consecutive block elements | |||
| are not separated by blank lines | are not separated by blank lines | |||
| . | . | |||
| - a | - a | |||
| > b | > b | |||
| skipping to change at line 3700 | skipping to change at line 3799 | |||
| c | c | |||
| ``` | ``` | |||
| - d | - d | |||
| . | . | |||
| <ul> | <ul> | |||
| <li>a | <li>a | |||
| <blockquote> | <blockquote> | |||
| <p>b</p> | <p>b</p> | |||
| </blockquote> | </blockquote> | |||
| <pre><code>c | <pre><code>c | |||
| </code></pre></li> | </code></pre> | |||
| </li> | ||||
| <li>d</li> | <li>d</li> | |||
| </ul> | </ul> | |||
| . | . | |||
| 单段落列表是紧凑的 | 单段落列表是紧凑的 | |||
| . | . | |||
| - a | - a | |||
| . | . | |||
| <ul> | <ul> | |||
| skipping to change at line 3723 | skipping to change at line 3823 | |||
| . | . | |||
| . | . | |||
| - a | - a | |||
| - b | - b | |||
| . | . | |||
| <ul> | <ul> | |||
| <li>a | <li>a | |||
| <ul> | <ul> | |||
| <li>b</li> | <li>b</li> | |||
| </ul></li> | </ul> | |||
| </li> | ||||
| </ul> | </ul> | |||
| . | . | |||
| 这里外部列表是松散的,内部列表是紧凑的 | 这里外部列表是松散的,内部列表是紧凑的 | |||
| . | . | |||
| * foo | * foo | |||
| * bar | * bar | |||
| baz | baz | |||
| . | . | |||
| <ul> | <ul> | |||
| <li><p>foo</p> | <li> | |||
| <p>foo</p> | ||||
| <ul> | <ul> | |||
| <li>bar</li> | <li>bar</li> | |||
| </ul> | </ul> | |||
| <p>baz</p></li> | <p>baz</p> | |||
| </li> | ||||
| </ul> | </ul> | |||
| . | . | |||
| . | . | |||
| - a | - a | |||
| - b | - b | |||
| - c | - c | |||
| - d | - d | |||
| - e | - e | |||
| - f | - f | |||
| . | . | |||
| <ul> | <ul> | |||
| <li><p>a</p> | <li> | |||
| <p>a</p> | ||||
| <ul> | <ul> | |||
| <li>b</li> | <li>b</li> | |||
| <li>c</li> | <li>c</li> | |||
| </ul></li> | </ul> | |||
| <li><p>d</p> | </li> | |||
| <li> | ||||
| <p>d</p> | ||||
| <ul> | <ul> | |||
| <li>e</li> | <li>e</li> | |||
| <li>f</li> | <li>f</li> | |||
| </ul></li> | </ul> | |||
| </li> | ||||
| </ul> | </ul> | |||
| . | . | |||
| # Inlines | # Inlines | |||
| Inlines are parsed sequentially from the beginning of the character | Inlines are parsed sequentially from the beginning of the character | |||
| stream to the end (left to right, in left-to-right languages). | stream to the end (left to right, in left-to-right languages). | |||
| Thus, for example, in | Thus, for example, in | |||
| . | . | |||
| skipping to change at line 5766 | skipping to change at line 5873 | |||
| 链接标签不区分大小写。 | 链接标签不区分大小写。 | |||
| . | . | |||
| [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> | |||
| . | . | |||
| 链接文本后的空格应予以保留。 | ||||
| . | ||||
| [foo] bar | ||||
| [foo]: /url | ||||
| . | ||||
| <p><a href="/url">foo</a> bar</p> | ||||
| . | ||||
| If you just want bracketed text, you can backslash-escape the | If you just want bracketed text, you can backslash-escape the | |||
| opening bracket to avoid links | opening bracket to avoid links | |||
| . | . | |||
| \[foo] | \[foo] | |||
| [foo]: /url "title" | [foo]: /url "title" | |||
| . | . | |||
| <p>[foo]</p> | <p>[foo]</p> | |||
| . | . | |||
| skipping to change at line 6600 | skipping to change at line 6717 | |||
| <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 break 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. | |||
| ## Strings | ## 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 string content. | be parsed as plain textual content. | |||
| . | . | |||
| hello $.;'there | hello $.;'there | |||
| . | . | |||
| <p>hello $.;'there</p> | <p>hello $.;'there</p> | |||
| . | . | |||
| . | . | |||
| Foo χρῆν | Foo χρῆν | |||
| . | . | |||
| End of changes. 69 change blocks. | ||||
| 95 lines changed or deleted | 212 lines changed or added | |||
此 HTML 差异由 rfcdiff 1.41 生成。最新版本可从 http://tools.ietf.org/tools/rfcdiff/ 获取 | ||||