diff options
Diffstat (limited to 'spec.txt')
-rw-r--r-- | spec.txt | 690 |
1 files changed, 390 insertions, 300 deletions
@@ -4248,79 +4248,71 @@ The following rules capture all of these patterns, while allowing for efficient parsing strategies that do not backtrack: 1. A single `*` character [can open emphasis](#can-open-emphasis) - <a id="can-open-emphasis"></a> iff - - (a) it is not followed by whitespace, and - (b) either it is not followed by a `*` character or it is - followed immediately by emphasis or strong emphasis. + <a id="can-open-emphasis"></a> iff it is not followed by + whitespace. 2. A single `_` character [can open emphasis](#can-open-emphasis) iff - - (a) it is not followed by whitespace, - (b) it is not preceded by an ASCII alphanumeric character, and - (c) either it is not followed by a `_` character or it is - followed immediately by emphasis or strong emphasis. + it is not followed by whitespace and it is not preceded by an + ASCII alphanumeric character. 3. A single `*` character [can close emphasis](#can-close-emphasis) - <a id="can-close-emphasis"></a> iff - - (b) it is not preceded by whitespace. + <a id="can-close-emphasis"></a> iff it is not preceded by whitespace. 4. A single `_` character [can close emphasis](#can-close-emphasis) iff - - (a) it is not preceded by whitespace, and - (b) it is not followed by an ASCII alphanumeric character. + it is not preceded by whitespace and it is not followed by an + ASCII alphanumeric character. 5. A double `**` [can open strong emphasis](#can-open-strong-emphasis) - <a id="can-open-strong-emphasis" ></a> iff - - (a) it is not followed by whitespace, and - (b) either it is not followed by a `*` character or it is - followed immediately by emphasis. + <a id="can-open-strong-emphasis" ></a> iff it is not followed by + whitespace. 6. A double `__` [can open strong emphasis](#can-open-strong-emphasis) - iff - - (a) it is not followed by whitespace, and - (b) it is not preceded by an ASCII alphanumeric character, and - (c) either it is not followed by a `_` character or it is - followed immediately by emphasis. + iff it is not followed by whitespace and it is not preceded by an + ASCII alphanumeric character. 7. A double `**` [can close strong emphasis](#can-close-strong-emphasis) - <a id="can-close-strong-emphasis" ></a> iff - - (a) it is not preceded by whitespace. + <a id="can-close-strong-emphasis" ></a> iff it is not preceded by + whitespace. 8. A double `__` [can close strong emphasis](#can-close-strong-emphasis) - iff - - (a) it is not preceded by whitespace, and - (b) it is not followed by an ASCII alphanumeric character. + iff it is not preceded by whitespace and it is not followed by an + ASCII alphanumeric character. 9. Emphasis begins with a delimiter that [can open emphasis](#can-open-emphasis) and ends with a delimiter that [can close emphasis](#can-close-emphasis), and that uses the same - character (`_` or `*`) as the opening delimiter. The inlines - between the open delimiter and the closing delimiter are the - contents of the emphasis inline. + character (`_` or `*`) as the opening delimiter. There must + be a nonempty sequence of inlines between the open delimiter + and the closing delimiter; these form the contents of the emphasis + inline. 10. Strong emphasis begins with a delimiter that [can open strong emphasis](#can-open-strong-emphasis) and ends with a delimiter that - [can close strong emphasis](#can-close-strong-emphasis), and that uses the - same character (`_` or `*`) as the opening delimiter. The inlines - between the open delimiter and the closing delimiter are the - contents of the strong emphasis inline. + [can close strong emphasis](#can-close-strong-emphasis), and that + uses the same character (`_` or `*`) as the opening delimiter. + There must be a nonempty sequence of inlines between the open + delimiter and the closing delimiter; these form the contents of + the strong emphasis inline. + +11. A literal `*` character cannot occur at the beginning or end of + `*`-delimited emphasis or `**`-delimited strong emphasis, unless it + is backslash-escaped. + +12. A literal `_` character cannot occur at the beginning or end of + `_`-delimited emphasis or `__`-delimited strong emphasis, unless it + is backslash-escaped. -Where rules 1--10 above are compatible with multiple parsings, +Where rules 1--12 above are compatible with multiple parsings, the following principles resolve ambiguity: -11. An interpretation `<strong>...</strong>` is always preferred to +13. The number of nestings should be minimized. Thus, for example, + an interpretation `<strong>...</strong>` is always preferred to `<em><em>...</em></em>`. -12. An interpretation `<strong><em>...</em></strong>` is always +14. An interpretation `<strong><em>...</em></strong>` is always preferred to `<em><strong>..</strong></em>`. -13. When two potential emphasis or strong emphasis spans overlap, +15. When two potential emphasis or strong emphasis spans overlap, so that the second begins before the first ends and ends after the first ends, the first is preferred. Thus, for example, `*foo _bar* baz_` is parsed as `<em>foo _bar</em> baz_` rather @@ -4328,13 +4320,13 @@ the following principles resolve ambiguity: `**foo*bar**` is parsed as `<em><em>foo</em>bar</em>*` rather than `<strong>foo*bar</strong>`. -14. When there are two potential emphasis or strong emphasis spans +16. When there are two potential emphasis or strong emphasis spans with the same closing delimiter, the shorter one (the one that opens later) is preferred. Thus, for example, `**foo **bar baz**` is parsed as `**foo <strong>bar baz</strong>` rather than `<strong>foo **bar baz</strong>`. -15. Inline code spans, links, images, and HTML tags group more tightly +17. Inline code spans, links, images, and HTML tags group more tightly than emphasis. So, when there is a choice between an interpretation that contains one of these elements and one that does not, the former always wins. Thus, for example, `*[foo*](bar)` is @@ -4343,7 +4335,7 @@ the following principles resolve ambiguity: These rules can be illustrated through a series of examples. -Simple emphasis: +Rule 1: . *foo bar* @@ -4351,363 +4343,424 @@ Simple emphasis: <p><em>foo bar</em></p> . +This is not emphasis, because the opening `*` is followed by +whitespace: + . -_foo bar_ +a * foo bar* . -<p><em>foo bar</em></p> +<p>a * foo bar*</p> . -Simple strong emphasis: +Intraword emphasis with `*` is permitted: . -**foo bar** +foo*bar* . -<p><strong>foo bar</strong></p> +<p>foo<em>bar</em></p> . . -__foo bar__ +5*6*78 . -<p><strong>foo bar</strong></p> +<p>5<em>6</em>78</p> . -Emphasis can continue over line breaks: +Rule 2: . -*foo -bar* +_foo bar_ . -<p><em>foo -bar</em></p> +<p><em>foo bar</em></p> . +This is not emphasis, because the opening `*` is followed by +whitespace: + . -_foo -bar_ +_ foo bar_ . -<p><em>foo -bar</em></p> +<p>_ foo bar_</p> . +Emphasis with `_` is not allowed inside ASCII words: + . -**foo -bar** +foo_bar_ . -<p><strong>foo -bar</strong></p> +<p>foo_bar_</p> . . -__foo -bar__ +5_6_78 . -<p><strong>foo -bar</strong></p> +<p>5_6_78</p> . -Emphasis can contain other inline constructs: +But it is permitted inside non-ASCII words: . -*foo [bar](/url)* +пристаням_стремятся_ . -<p><em>foo <a href="/url">bar</a></em></p> +<p>пристаням<em>стремятся</em></p> . +Rule 3: + +This is not emphasis, because the closing `*` is preceded by +whitespace: + . -_foo [bar](/url)_ +*foo bar * . -<p><em>foo <a href="/url">bar</a></em></p> +<p>*foo bar *</p> . +Intraword emphasis with `*` is allowed: + . -**foo [bar](/url)** +*foo*bar . -<p><strong>foo <a href="/url">bar</a></strong></p> +<p><em>foo</em>bar</p> . + +Rule 4: + +This is not emphasis, because the closing `_` is preceded by +whitespace: + . -__foo [bar](/url)__ +_foo bar _ . -<p><strong>foo <a href="/url">bar</a></strong></p> +<p>_foo bar _</p> . -Symbols contained in other inline constructs will not -close emphasis: +Intraword emphasis: . -*foo [bar*](/url) +_foo_bar . -<p>*foo <a href="/url">bar*</a></p> +<p>_foo_bar</p> . . -_foo [bar_](/url) +_пристаням_стремятся . -<p>_foo <a href="/url">bar_</a></p> +<p><em>пристаням</em>стремятся</p> . . -**<a href="**"> +_foo_bar_baz_ . -<p>**<a href="**"></p> +<p><em>foo_bar_baz</em></p> . +Rule 5: + . -__<a href="__"> +**foo bar** . -<p>__<a href="__"></p> +<p><strong>foo bar</strong></p> . +This is not strong emphasis, because the opening delimiter is +followed by whitespace: + . -*a `*`* +** foo bar** . -<p><em>a <code>*</code></em></p> +<p>** foo bar**</p> . +Intraword strong emphasis with `**` is permitted: + . -_a `_`_ +foo**bar** . -<p><em>a <code>_</code></em></p> +<p>foo<strong>bar</strong></p> . +Rule 6: + . -**a<http://foo.bar?q=**> +__foo bar__ . -<p>**a<a href="http://foo.bar?q=**">http://foo.bar?q=**</a></p> +<p><strong>foo bar</strong></p> . +This is not strong emphasis, because the opening delimiter is +followed by whitespace: + . -__a<http://foo.bar?q=__> +__ foo bar__ . -<p>__a<a href="http://foo.bar?q=__">http://foo.bar?q=__</a></p> +<p>__ foo bar__</p> . -This is not emphasis, because the opening delimiter is -followed by white space: +Intraword emphasis examples: . -and * foo bar* +foo__bar__ . -<p>and * foo bar*</p> +<p>foo__bar__</p> . . -_ foo bar_ +5__6__78 . -<p>_ foo bar_</p> +<p>5__6__78</p> . . -and ** foo bar** +пристаням__стремятся__ . -<p>and ** foo bar**</p> +<p>пристаням<strong>стремятся</strong></p> . . -__ foo bar__ +__foo, __bar__, baz__ . -<p>__ foo bar__</p> +<p><strong>foo, <strong>bar</strong>, baz</strong></p> . -This is not emphasis, because the closing delimiter is -preceded by white space: +Rule 7: + +This is not strong emphasis, because the closing delimiter is preceded +by whitespace: . -and *foo bar * +**foo bar ** . -<p>and *foo bar *</p> +<p>**foo bar **</p> . +(Nor can it be interpreted as an emphasized `*foo bar *`, because of +Rule 11.) + +Intraword emphasis: + . -and _foo bar _ +**foo**bar . -<p>and _foo bar _</p> +<p><strong>foo</strong>bar</p> . +Rule 8: + +This is not strong emphasis, because the closing delimiter is +preceded by whitespace: + . -and **foo bar ** +__foo bar __ . -<p>and **foo bar **</p> +<p>__foo bar __</p> . +Intraword strong emphasis examples: + . -and __foo bar __ +__foo__bar . -<p>and __foo bar __</p> +<p>__foo__bar</p> . -The rules imply that a sequence of `*` or `_` characters -surrounded by whitespace will be parsed as a literal string: - . -foo ******** +__пристаням__стремятся . -<p>foo ********</p> +<p><strong>пристаням</strong>стремятся</p> . . -Sign here: _________ +__foo__bar__baz__ . -<p>Sign here: _________</p> +<p><strong>foo__bar__baz</strong></p> . -The rules also imply that there can be no empty emphasis or strong -emphasis: +Rule 9: + +Any nonempty sequence of inline elements can be the contents of an +emphasized span. . -** is not an empty emphasis +*foo [bar](/url)* . -<p>** is not an empty emphasis</p> +<p><em>foo <a href="/url">bar</a></em></p> . . -**** is not an empty strong emphasis +*foo +bar* . -<p>**** is not an empty strong emphasis</p> +<p><em>foo +bar</em></p> . -To include `*` or `_` in emphasized sections, use backslash escapes -or code spans: +In particular, emphasis and strong emphasis can be nested +inside emphasis: . -*here is a \** +_foo __bar__ baz_ . -<p><em>here is a *</em></p> +<p><em>foo <strong>bar</strong> baz</em></p> . . -__this is a double underscore (`__`)__ +_foo _bar_ baz_ . -<p><strong>this is a double underscore (<code>__</code>)</strong></p> +<p><em>foo <em>bar</em> baz</em></p> . -Or use the other emphasis character: - . -*_* +__foo_ bar_ . -<p><em>_</em></p> +<p><em><em>foo</em> bar</em></p> . . -_*_ +*foo *bar** . -<p><em>*</em></p> +<p><em>foo <em>bar</em></em></p> . . -*__* +*foo **bar** baz* . -<p><em>__</em></p> +<p><em>foo <strong>bar</strong> baz</em></p> . +But note: + . -_**_ +*foo**bar**baz* . -<p><em>**</em></p> +<p><em>foo</em><em>bar</em><em>baz</em></p> . -`*` delimiters allow intra-word emphasis; `_` delimiters do not: +The difference is that in the preceding case, +the internal delimiters [can close emphasis](#can-close-emphasis), +while in the cases with spaces, they cannot. . -foo*bar*baz +***foo** bar* . -<p>foo<em>bar</em>baz</p> +<p><em><strong>foo</strong> bar</em></p> . . -foo_bar_baz +*foo **bar*** . -<p>foo_bar_baz</p> +<p><em>foo <strong>bar</strong></em></p> . +Note, however, that in the following case we get no strong +emphasis, because the opening delimiter is closed by the first +`*` before `bar`: + . -foo__bar__baz +*foo**bar*** . -<p>foo__bar__baz</p> +<p><em>foo</em><em>bar</em>**</p> . + +Indefinite levels of nesting are possible: + . -_foo_bar_baz_ +*foo **bar *baz* bim** bop* . -<p><em>foo_bar_baz</em></p> +<p><em>foo <strong>bar <em>baz</em> bim</strong> bop</em></p> . . -11*15*32 +*foo [*bar*](/url)* . -<p>11<em>15</em>32</p> +<p><em>foo <a href="/url"><em>bar</em></a></em></p> . +There can be no empty emphasis or strong emphasis: + . -11_15_32 +** is not an empty emphasis . -<p>11_15_32</p> +<p>** is not an empty emphasis</p> . -Internal underscores will be ignored in underscore-delimited -emphasis: - . -_foo_bar_baz_ +**** is not an empty strong emphasis . -<p><em>foo_bar_baz</em></p> +<p>**** is not an empty strong emphasis</p> . + +Rule 10: + +Any nonempty sequence of inline elements can be the contents of an +strongly emphasized span. + . -__foo__bar__baz__ +**foo [bar](/url)** . -<p><strong>foo__bar__baz</strong></p> +<p><strong>foo <a href="/url">bar</a></strong></p> . -The rules are sufficient for the following nesting patterns: - . -***foo bar*** +**foo +bar** . -<p><strong><em>foo bar</em></strong></p> +<p><strong>foo +bar</strong></p> . +In particular, emphasis and strong emphasis can be nested +inside strong emphasis: + . -___foo bar___ +__foo _bar_ baz__ . -<p><strong><em>foo bar</em></strong></p> +<p><strong>foo <em>bar</em> baz</strong></p> . . -***foo** bar* +__foo __bar__ baz__ . -<p><em><strong>foo</strong> bar</em></p> +<p><strong>foo <strong>bar</strong> baz</strong></p> . . -___foo__ bar_ +____foo__ bar__ . -<p><em><strong>foo</strong> bar</em></p> +<p><strong><strong>foo</strong> bar</strong></p> . . -***foo* bar** +**foo **bar**** . -<p><strong><em>foo</em> bar</strong></p> +<p><strong>foo <strong>bar</strong></strong></p> . . -___foo_ bar__ +**foo *bar* baz** . -<p><strong><em>foo</em> bar</strong></p> +<p><strong>foo <em>bar</em> baz</strong></p> . +But note: + . -*foo **bar*** +**foo*bar*baz** . -<p><em>foo <strong>bar</strong></em></p> +<p><em><em>foo</em>bar</em>baz**</p> . +The difference is that in the preceding case, +the internal delimiters [can close emphasis](#can-close-emphasis), +while in the cases with spaces, they cannot. + . -_foo __bar___ +***foo* bar** . -<p><em>foo <strong>bar</strong></em></p> +<p><strong><em>foo</em> bar</strong></p> . . @@ -4716,256 +4769,261 @@ _foo __bar___ <p><strong>foo <em>bar</em></strong></p> . +Indefinite levels of nesting are possible: + . -__foo _bar___ +**foo *bar **baz** +bim* bop** . -<p><strong>foo <em>bar</em></strong></p> +<p><strong>foo <em>bar <strong>baz</strong> +bim</em> bop</strong></p> . . -*foo **bar*** +**foo [*bar*](/url)** . -<p><em>foo <strong>bar</strong></em></p> +<p><strong>foo <a href="/url"><em>bar</em></a></strong></p> . +There can be no empty emphasis or strong emphasis: + . -_foo __bar___ +__ is not an empty emphasis . -<p><em>foo <strong>bar</strong></em></p> +<p>__ is not an empty emphasis</p> . . -*foo *bar* baz* +____ is not an empty strong emphasis . -<p><em>foo <em>bar</em> baz</em></p> +<p>____ is not an empty strong emphasis</p> . + +Rule 11: + . -_foo _bar_ baz_ +foo *** . -<p><em>foo <em>bar</em> baz</em></p> +<p>foo ***</p> . . -**foo **bar** baz** +foo *\** . -<p><strong>foo <strong>bar</strong> baz</strong></p> +<p>foo <em>*</em></p> . . -__foo __bar__ baz__ +foo *_* . -<p><strong>foo <strong>bar</strong> baz</strong></p> +<p>foo <em>_</em></p> . . -*foo **bar** baz* +foo ***** . -<p><em>foo <strong>bar</strong> baz</em></p> +<p>foo *****</p> . . -_foo __bar__ baz_ +foo **\*** . -<p><em>foo <strong>bar</strong> baz</em></p> +<p>foo <strong>*</strong></p> . . -**foo *bar* baz** +foo **_** . -<p><strong>foo <em>bar</em> baz</strong></p> +<p>foo <strong>_</strong></p> . +Note that when delimiters do not match evenly, Rule 11 determines +that the excess literal `*` characters will appear outside of the +emphasis, rather than inside it: + . -__foo _bar_ baz__ +**foo* . -<p><strong>foo <em>bar</em> baz</strong></p> +<p>*<em>foo</em></p> . . -**foo, *bar*, baz** +*foo** . -<p><strong>foo, <em>bar</em>, baz</strong></p> +<p><em>foo</em>*</p> . . -__foo, _bar_, baz__ +***foo** . -<p><strong>foo, <em>bar</em>, baz</strong></p> +<p>*<strong>foo</strong></p> . -But note: +. +****foo* +. +<p>***<em>foo</em></p> +. . -*foo**bar**baz* +**foo*** . -<p><em>foo</em><em>bar</em><em>baz</em></p> +<p><strong>foo</strong>*</p> . . -**foo*bar*baz** +*foo**** . -<p><em><em>foo</em>bar</em>baz**</p> +<p><em>foo</em>***</p> . -The difference is that in the two preceding cases, -the internal delimiters [can close emphasis](#can-close-emphasis), -while in the cases with spaces, they cannot. -Note that you cannot nest emphasis directly inside emphasis -using the same delimeter: +Rule 12: . -**foo** +foo ___ . -<p><strong>foo</strong></p> +<p>foo ___</p> . -For this, you need to switch delimiters: - . -*_foo_* +foo _\__ . -<p><em><em>foo</em></em></p> +<p>foo <em>_</em></p> . -Strong within strong is possible without switching -delimiters: - . -****foo**** +foo _*_ . -<p><strong><strong>foo</strong></strong></p> +<p>foo <em>*</em></p> . . -____foo____ +foo _____ . -<p><strong><strong>foo</strong></strong></p> +<p>foo _____</p> . -Note that a `*` followed by a `*` can close emphasis, and -a `**` followed by a `*` can close strong emphasis (and -similarly for `_` and `__`): - . -*foo** +foo __\___ . -<p><em>foo</em>*</p> +<p>foo <strong>_</strong></p> . . -*foo *bar** +foo __*__ . -<p><em>foo <em>bar</em></em></p> +<p>foo <strong>*</strong></p> . . -**foo*** +__foo_ . -<p><strong>foo</strong>*</p> +<p>_<em>foo</em></p> . +Note that when delimiters do not match evenly, Rule 12 determines +that the excess literal `_` characters will appear outside of the +emphasis, rather than inside it: + . -***foo* bar*** +_foo__ . -<p><strong><em>foo</em> bar</strong>*</p> +<p><em>foo</em>_</p> . . -***foo** bar*** +___foo__ . -<p><em><strong>foo</strong> bar</em>**</p> +<p>_<strong>foo</strong></p> . . -*foo**** +____foo_ . -<p><em>foo</em>***</p> +<p>___<em>foo</em></p> . -The following contains no strong emphasis, because the opening -delimiter is closed by the first `*` before `bar`: +. +__foo___ +. +<p><strong>foo</strong>_</p> +. . -*foo**bar*** +_foo____ . -<p><em>foo</em><em>bar</em>**</p> +<p><em>foo</em>___</p> . -We retain symmetry in these cases: +Rule 13 implies that if you want emphasis nested directly inside +emphasis, you must use different delimiters: . -*foo** - -**foo* +**foo** . -<p><em>foo</em>*</p> -<p>*<em>foo</em></p> +<p><strong>foo</strong></p> . . -*foo *bar** - -**foo* bar* +*_foo_* . -<p><em>foo <em>bar</em></em></p> -<p><em><em>foo</em> bar</em></p> +<p><em><em>foo</em></em></p> . . -**foo*** - -***foo** +__foo__ . -<p><strong>foo</strong>*</p> -<p>*<strong>foo</strong></p> +<p><strong>foo</strong></p> . . -**foo **bar**** - -****foo** bar** +_*foo*_ . -<p><strong>foo <strong>bar</strong></strong></p> -<p><strong><strong>foo</strong> bar</strong></p> +<p><em><em>foo</em></em></p> . - - -More cases with mismatched delimiters: +However, strong emphasis within strong emphasisis possible without +switching delimiters: . -*bar*** +****foo**** . -<p><em>bar</em>**</p> +<p><strong><strong>foo</strong></strong></p> . . -***foo* +____foo____ . -<p>**<em>foo</em></p> +<p><strong><strong>foo</strong></strong></p> . + +Rule 13 can be applied to arbitrarily long sequences of +delimiters: + . -**bar*** +******foo****** . -<p><strong>bar</strong>*</p> +<p><strong><strong><strong>foo</strong></strong></strong></p> . +Rule 14: + . -***foo** +***foo*** . -<p>*<strong>foo</strong></p> +<p><strong><em>foo</em></strong></p> . . -***foo *bar* +_____foo_____ . -<p>***foo <em>bar</em></p> +<p><strong><strong><em>foo</em></strong></strong></p> . -The following cases illustrate rule 13: +Rule 15: . *foo _bar* baz_ @@ -4974,12 +5032,13 @@ The following cases illustrate rule 13: . . -**foo bar* baz** +**foo*bar** . -<p><em><em>foo bar</em> baz</em>*</p> +<p><em><em>foo</em>bar</em>*</p> . -The following cases illustrate rule 14: + +Rule 16: . **foo **bar baz** @@ -4993,18 +5052,18 @@ The following cases illustrate rule 14: <p>*foo <em>bar baz</em></p> . -The following cases illustrate rule 15: +Rule 17: . -*[foo*](bar) +*[bar*](/url) . -<p>*<a href="bar">foo*</a></p> +<p>*<a href="/url">bar*</a></p> . . -*![foo*](bar) +_foo [bar_](/url) . -<p>*<img src="bar" alt="foo*" /></p> +<p>_foo <a href="/url">bar_</a></p> . . @@ -5014,11 +5073,42 @@ The following cases illustrate rule 15: . . -*a`a*` +**<a href="**"> +. +<p>**<a href="**"></p> +. + +. +__<a href="__"> +. +<p>__<a href="__"></p> +. + +. +*a `*`* . -<p>*a<code>a*</code></p> +<p><em>a <code>*</code></em></p> . +. +_a `_`_ +. +<p><em>a <code>_</code></em></p> +. + +. +**a<http://foo.bar?q=**> +. +<p>**a<a href="http://foo.bar?q=**">http://foo.bar?q=**</a></p> +. + +. +__a<http://foo.bar?q=__> +. +<p>__a<a href="http://foo.bar?q=__">http://foo.bar?q=__</a></p> +. + + ## Links A link contains a [link label](#link-label) (the visible text), |