summaryrefslogtreecommitdiff
path: root/spec.txt
diff options
context:
space:
mode:
Diffstat (limited to 'spec.txt')
-rw-r--r--spec.txt712
1 files changed, 406 insertions, 306 deletions
diff --git a/spec.txt b/spec.txt
index 1bbd287..f6d90c0 100644
--- a/spec.txt
+++ b/spec.txt
@@ -2,8 +2,8 @@
title: CommonMark Spec
author:
- John MacFarlane
-version: 0.7
-date: 2014-10-28
+version: 0.10
+date: 2014-11-06
...
# Introduction
@@ -4248,87 +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 part of a sequence of four or more unescaped `*`s,
- (b) it is not followed by whitespace, and
- (c) 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 part of a sequence of four or more unescaped `_`s,
- (b) it is not followed by whitespace,
- (c) it is not preceded by an ASCII alphanumeric character, and
- (d) 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
-
- (a) it is not part of a sequence of four or more unescaped `*`s, and
- (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 part of a sequence of four or more unescaped `_`s,
- (b) it is not preceded by whitespace, and
- (c) 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 part of a sequence of four or more unescaped `*`s,
- (b) it is not followed by whitespace, and
- (c) 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 part of a sequence of four or more unescaped `_`s,
- (b) it is not followed by whitespace, and
- (c) it is not preceded by an ASCII alphanumeric character, and
- (d) 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 part of a sequence of four or more unescaped `*`s, and
- (b) 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 part of a sequence of four or more unescaped `_`s,
- (b) it is not preceded by whitespace, and
- (c) 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
@@ -4336,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
@@ -4351,7 +4335,7 @@ the following principles resolve ambiguity:
These rules can be illustrated through a series of examples.
-Simple emphasis:
+Rule 1:
.
*foo bar*
@@ -4359,347 +4343,420 @@ 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 four or more unescaped `*` or
-`_` characters will always be parsed as a literal string:
+.
+__пристаням__стремятся
+.
+<p><strong>пристаням</strong>стремятся</p>
+.
.
-****hi****
+__foo__bar__baz__
.
-<p>****hi****</p>
+<p><strong>foo__bar__baz</strong></p>
.
+Rule 9:
+
+Any nonempty sequence of inline elements can be the contents of an
+emphasized span.
+
.
-_____hi_____
+*foo [bar](/url)*
.
-<p>_____hi_____</p>
+<p><em>foo <a href="/url">bar</a></em></p>
.
.
-Sign here: _________
+*foo
+bar*
.
-<p>Sign here: _________</p>
+<p><em>foo
+bar</em></p>
.
-The rules also imply that there can be no empty emphasis or strong
-emphasis:
+In particular, emphasis and strong emphasis can be nested
+inside emphasis:
.
-** is not an empty emphasis
+_foo __bar__ baz_
.
-<p>** is not an empty emphasis</p>
+<p><em>foo <strong>bar</strong> baz</em></p>
.
.
-**** is not an empty strong emphasis
+_foo _bar_ baz_
.
-<p>**** is not an empty strong emphasis</p>
+<p><em>foo <em>bar</em> baz</em></p>
.
-To include `*` or `_` in emphasized sections, use backslash escapes
-or code spans:
+.
+__foo_ bar_
+.
+<p><em><em>foo</em> bar</em></p>
+.
.
-*here is a \**
+*foo *bar**
.
-<p><em>here is a *</em></p>
+<p><em>foo <em>bar</em></em></p>
.
.
-__this is a double underscore (`__`)__
+*foo **bar** baz*
.
-<p><strong>this is a double underscore (<code>__</code>)</strong></p>
+<p><em>foo <strong>bar</strong> baz</em></p>
.
-Or use the other emphasis character:
+But note:
.
-*_*
+*foo**bar**baz*
.
-<p><em>_</em></p>
+<p><em>foo</em><em>bar</em><em>baz</em></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*
.
-<p><em>*</em></p>
+<p><em><strong>foo</strong> bar</em></p>
.
.
-*__*
+*foo **bar***
.
-<p><em>__</em></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***
.
-<p><em>**</em></p>
+<p><em>foo</em><em>bar</em>**</p>
.
-`*` delimiters allow intra-word emphasis; `_` delimiters do not:
+
+Indefinite levels of nesting are possible:
.
-foo*bar*baz
+*foo **bar *baz* bim** bop*
.
-<p>foo<em>bar</em>baz</p>
+<p><em>foo <strong>bar <em>baz</em> bim</strong> bop</em></p>
.
.
-foo_bar_baz
+*foo [*bar*](/url)*
.
-<p>foo_bar_baz</p>
+<p><em>foo <a href="/url"><em>bar</em></a></em></p>
.
+There can be no empty emphasis or strong emphasis:
+
.
-foo__bar__baz
+** is not an empty emphasis
.
-<p>foo__bar__baz</p>
+<p>** is not an empty emphasis</p>
.
.
-_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.
+
.
-11*15*32
+**foo [bar](/url)**
.
-<p>11<em>15</em>32</p>
+<p><strong>foo <a href="/url">bar</a></strong></p>
.
.
-11_15_32
+**foo
+bar**
.
-<p>11_15_32</p>
+<p><strong>foo
+bar</strong></p>
.
-Internal underscores will be ignored in underscore-delimited
-emphasis:
+In particular, emphasis and strong emphasis can be nested
+inside strong emphasis:
.
-_foo_bar_baz_
+__foo _bar_ baz__
.
-<p><em>foo_bar_baz</em></p>
+<p><strong>foo <em>bar</em> baz</strong></p>
.
.
-__foo__bar__baz__
+__foo __bar__ baz__
.
-<p><strong>foo__bar__baz</strong></p>
+<p><strong>foo <strong>bar</strong> baz</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><strong>foo</strong> bar</strong></p>
.
.
-___foo bar___
+**foo **bar****
.
-<p><strong><em>foo bar</em></strong></p>
+<p><strong>foo <strong>bar</strong></strong></p>
.
.
-***foo** bar*
+**foo *bar* baz**
.
-<p><em><strong>foo</strong> bar</em></p>
+<p><strong>foo <em>bar</em> baz</strong></p>
.
+But note:
+
.
-___foo__ bar_
+**foo*bar*baz**
.
-<p><em><strong>foo</strong> bar</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**
.
@@ -4707,259 +4764,266 @@ ___foo__ bar_
.
.
-___foo_ bar__
+**foo *bar***
.
-<p><strong><em>foo</em> bar</strong></p>
+<p><strong>foo <em>bar</em></strong></p>
.
+Indefinite levels of nesting are possible:
+
.
-*foo **bar***
+**foo *bar **baz**
+bim* bop**
.
-<p><em>foo <strong>bar</strong></em></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><strong>foo <em>bar</em></strong></p>
+<p>__ is not an empty emphasis</p>
.
.
-__foo _bar___
+____ is not an empty strong emphasis
.
-<p><strong>foo <em>bar</em></strong></p>
+<p>____ is not an empty strong emphasis</p>
.
+
+Rule 11:
+
.
-*foo **bar***
+foo ***
.
-<p><em>foo <strong>bar</strong></em></p>
+<p>foo ***</p>
.
.
-_foo __bar___
+foo *\**
.
-<p><em>foo <strong>bar</strong></em></p>
+<p>foo <em>*</em></p>
.
.
-*foo *bar* baz*
+foo *_*
.
-<p><em>foo <em>bar</em> baz</em></p>
+<p>foo <em>_</em></p>
.
.
-_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 <strong>*</strong></p>
.
.
-__foo __bar__ baz__
+foo **_**
.
-<p><strong>foo <strong>bar</strong> 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><em>foo <strong>bar</strong> baz</em></p>
+<p>*<em>foo</em></p>
.
.
-_foo __bar__ baz_
+*foo**
.
-<p><em>foo <strong>bar</strong> baz</em></p>
+<p><em>foo</em>*</p>
.
.
-**foo *bar* baz**
+***foo**
.
-<p><strong>foo <em>bar</em> baz</strong></p>
+<p>*<strong>foo</strong></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>
.
.
-__foo, _bar_, baz__
+*foo****
.
-<p><strong>foo, <em>bar</em>, baz</strong></p>
+<p><em>foo</em>***</p>
.
-But note:
+
+Rule 12:
.
-*foo**bar**baz*
+foo ___
.
-<p><em>foo</em><em>bar</em><em>baz</em></p>
+<p>foo ___</p>
.
.
-**foo*bar*baz**
+foo _\__
.
-<p><em><em>foo</em>bar</em>baz**</p>
+<p>foo <em>_</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, or strong emphasis directly inside
-strong emphasis:
-
.
-**foo**
+foo _*_
.
-<p><strong>foo</strong></p>
+<p>foo <em>*</em></p>
.
.
-****foo****
+foo _____
.
-<p>****foo****</p>
+<p>foo _____</p>
.
-For these nestings, you need to switch delimiters:
+.
+foo __\___
+.
+<p>foo <strong>_</strong></p>
+.
.
-*_foo_*
+foo __*__
.
-<p><em><em>foo</em></em></p>
+<p>foo <strong>*</strong></p>
.
.
-**__foo__**
+__foo_
.
-<p><strong><strong>foo</strong></strong></p>
+<p>_<em>foo</em></p>
.
-Note that a `*` followed by a `*` can close emphasis, and
-a `**` followed by a `*` can close strong emphasis (and
-similarly for `_` and `__`):
+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**
+_foo__
.
-<p><em>foo</em>*</p>
+<p><em>foo</em>_</p>
.
.
-*foo *bar**
+___foo__
.
-<p><em>foo <em>bar</em></em></p>
+<p>_<strong>foo</strong></p>
.
.
-**foo***
+____foo_
.
-<p><strong>foo</strong>*</p>
+<p>___<em>foo</em></p>
.
.
-***foo* bar***
+__foo___
.
-<p><strong><em>foo</em> bar</strong>*</p>
+<p><strong>foo</strong>_</p>
.
.
-***foo** bar***
+_foo____
.
-<p><em><strong>foo</strong> bar</em>**</p>
+<p><em>foo</em>___</p>
.
-The following contains no strong emphasis, because the opening
-delimiter is closed by the first `*` before `bar`:
+Rule 13 implies that if you want emphasis nested directly inside
+emphasis, you must use different delimiters:
.
-*foo**bar***
+**foo**
.
-<p><em>foo</em><em>bar</em>**</p>
+<p><strong>foo</strong></p>
.
-However, a string of four or more `****` can never close emphasis:
-
.
-*foo****
+*_foo_*
.
-<p>*foo****</p>
+<p><em><em>foo</em></em></p>
.
-We retain symmetry in these cases:
-
.
-*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>
.
-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_
@@ -4968,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**
@@ -4987,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>
.
.
@@ -5008,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><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<code>a*</code></p>
+<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),
@@ -5590,9 +5686,9 @@ is followed by a link label (even though `[bar]` is not defined):
## Images
An (unescaped) exclamation mark (`!`) followed by a reference or
-inline link will be parsed as an image. The link label will be
-used as the image's alt text, and the link title, if any, will
-be used as the image's title.
+inline link will be parsed as an image. The plain string content
+of the link label will be used as the image's alt text, and the link
+title, if any, will be used as the image's title.
.
![foo](/url "title")
@@ -5605,15 +5701,19 @@ be used as the image's title.
[foo *bar*]: train.jpg "train & tracks"
.
-<p><img src="train.jpg" alt="foo &lt;em&gt;bar&lt;/em&gt;" title="train &amp; tracks" /></p>
+<p><img src="train.jpg" alt="foo bar" title="train &amp; tracks" /></p>
.
+Note that in the above example, the alt text is `foo bar`, not `foo
+*bar*` or `foo <em>bar</em>` or `foo &lt;em&gt;bar&lt;/em&gt;`. Only
+the plain string content is rendered, without formatting.
+
.
![foo *bar*][]
[foo *bar*]: train.jpg "train & tracks"
.
-<p><img src="train.jpg" alt="foo &lt;em&gt;bar&lt;/em&gt;" title="train &amp; tracks" /></p>
+<p><img src="train.jpg" alt="foo bar" title="train &amp; tracks" /></p>
.
.
@@ -5621,7 +5721,7 @@ be used as the image's title.
[FOOBAR]: train.jpg "train & tracks"
.
-<p><img src="train.jpg" alt="foo &lt;em&gt;bar&lt;/em&gt;" title="train &amp; tracks" /></p>
+<p><img src="train.jpg" alt="foo bar" title="train &amp; tracks" /></p>
.
.
@@ -5681,7 +5781,7 @@ Collapsed:
[*foo* bar]: /url "title"
.
-<p><img src="/url" alt="&lt;em&gt;foo&lt;/em&gt; bar" title="title" /></p>
+<p><img src="/url" alt="foo bar" title="title" /></p>
.
The labels are case-insensitive:
@@ -5721,7 +5821,7 @@ Shortcut:
[*foo* bar]: /url "title"
.
-<p><img src="/url" alt="&lt;em&gt;foo&lt;/em&gt; bar" title="title" /></p>
+<p><img src="/url" alt="foo bar" title="title" /></p>
.
.