# Inlines Inlines are parsed sequentially from the beginning of the character stream to the end (left to right, in left-to-right languages). Thus, for{panels}, in ````````````````````````````````{panels} `hi`lo` .
hi
lo`
foo
foo ` bar
``
``
a
b
foo bar baz
foo
foo bar baz
` elements, so it is recommended that
the following CSS be used:
code{white-space: pre-wrap;}
Note that backslash escapes do not work in code spans. All backslashes
are treated literally:
````````````````````````````````{panels}
`foo\`bar`
.
foo\
bar`
````````````````````````````````
Backslash escapes are never needed, because one can always choose a
string of *n* backtick characters as delimiters, where the code does
not contain any strings of exactly *n* backtick characters.
````````````````````````````````{panels}
``foo`bar``
.
foo`bar
````````````````````````````````
````````````````````````````````{panels}
` foo `` bar `
.
foo `` bar
````````````````````````````````
Code span backticks have higher precedence than any other inline
constructs except HTML tags and autolinks. Thus, for{panels}, this is
not parsed as emphasized text, since the second `*` is part of a code
span:
````````````````````````````````{panels}
*foo`*`
.
*foo*
````````````````````````````````
And this is not parsed as a link:
````````````````````````````````{panels}
[not a `link](/foo`)
.
[not a link](/foo
)
````````````````````````````````
Code spans, HTML tags, and autolinks have the same precedence.
Thus, this is code:
````````````````````````````````{panels}
``
.
<a href="
">`
````````````````````````````````
But this is an HTML tag:
````````````````````````````````{panels}
`
.
````````````````````````````````
And this is code:
````````````````````````````````{panels}
``
.
<http://foo.bar.
baz>`
````````````````````````````````
But this is an autolink:
````````````````````````````````{panels}
`
.
````````````````````````````````
When a backtick string is not closed by a matching backtick string,
we just have literal backticks:
````````````````````````````````{panels}
```foo``
.
```foo``
````````````````````````````````
````````````````````````````````{panels}
`foo
.
`foo
````````````````````````````````
The following case also illustrates the need for opening and
closing backtick strings to be equal in length:
````````````````````````````````{panels}
`foo``bar``
.
`foobar
````````````````````````````````
## Emphasis and strong emphasis
John Gruber's original [Markdown syntax
description](http://daringfireball.net/projects/markdown/syntax#em) says:
> Markdown treats asterisks (`*`) and underscores (`_`) as indicators of
> emphasis. Text wrapped with one `*` or `_` will be wrapped with an HTML
> `` tag; double `*`'s or `_`'s will be wrapped with an HTML ``
> tag.
This is enough for most users, but these rules leave much undecided,
especially when it comes to nested emphasis. The original
`Markdown.pl` test suite makes it clear that triple `***` and
`___` delimiters can be used for strong emphasis, and most
implementations have also allowed the following patterns:
``` markdown
***strong emph***
***strong** in emph*
***emph* in strong**
**in strong *emph***
*in emph **strong***
```
The following patterns are less widely supported, but the intent
is clear and they are useful (especially in contexts like bibliography
entries):
``` markdown
*emph *with emph* in it*
**strong **with strong** in it**
```
Many implementations have also restricted intraword emphasis to
the `*` forms, to avoid unwanted emphasis in words containing
internal underscores. (It is best practice to put these in code
spans, but users often do not.)
``` markdown
internal emphasis: foo*bar*baz
no emphasis: foo_bar_baz
```
The rules given below capture all of these patterns, while allowing
for efficient parsing strategies that do not backtrack.
First, some definitions. A [delimiter run](#@) is either
a sequence of one or more `*` characters that is not preceded or
followed by a non-backslash-escaped `*` character, or a sequence
of one or more `_` characters that is not preceded or followed by
a non-backslash-escaped `_` character.
A [left-flanking delimiter run](#@) is
a [delimiter run] that is (1) not followed by [Unicode whitespace],
and either (2a) not followed by a [Unicode punctuation character], or
(2b) followed by a [Unicode punctuation character] and
preceded by [Unicode whitespace] or a [Unicode punctuation character].
For purposes of this definition, the beginning and the end of
the line count as Unicode whitespace.
A [right-flanking delimiter run](#@) is
a [delimiter run] that is (1) not preceded by [Unicode whitespace],
and either (2a) not preceded by a [Unicode punctuation character], or
(2b) preceded by a [Unicode punctuation character] and
followed by [Unicode whitespace] or a [Unicode punctuation character].
For purposes of this definition, the beginning and the end of
the line count as Unicode whitespace.
Here are some{panels}s of delimiter runs.
- left-flanking but not right-flanking:
```
***abc
_abc
**"abc"
_"abc"
```
- right-flanking but not left-flanking:
```
abc***
abc_
"abc"**
"abc"_
```
- Both left and right-flanking:
```
abc***def
"abc"_"def"
```
- Neither left 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
after comes from Roopesh Chander's
[vfmd](http://www.vfmd.org/vfmd-spec/specification/#procedure-for-identifying-emphasis-tags).
vfmd uses the terminology "emphasis indicator string" instead of "delimiter
run," and its rules for distinguishing left- and right-flanking runs
are a bit more complex than the ones given here.)
The following rules define emphasis and strong emphasis:
1. A single `*` character [can open emphasis](#@)
iff (if and only if) it is part of a [left-flanking delimiter run].
2. A single `_` character [can open emphasis] iff
it is part of a [left-flanking delimiter run]
and either (a) not part of a [right-flanking delimiter run]
or (b) part of a [right-flanking delimiter run]
preceded by a [Unicode punctuation character].
3. A single `*` character [can close emphasis](#@)
iff it is part of a [right-flanking delimiter run].
4. A single `_` character [can close emphasis] iff
it is part of a [right-flanking delimiter run]
and either (a) not part of a [left-flanking delimiter run]
or (b) part of a [left-flanking delimiter run]
followed by a [Unicode punctuation character].
5. A double `**` [can open strong emphasis](#@)
iff it is part of a [left-flanking delimiter run].
6. A double `__` [can open strong emphasis] iff
it is part of a [left-flanking delimiter run]
and either (a) not part of a [right-flanking delimiter run]
or (b) part of a [right-flanking delimiter run]
preceded by a [Unicode punctuation character].
7. A double `**` [can close strong emphasis](#@)
iff it is part of a [right-flanking delimiter run].
8. A double `__` [can close strong emphasis] iff
it is part of a [right-flanking delimiter run]
and either (a) not part of a [left-flanking delimiter run]
or (b) part of a [left-flanking delimiter run]
followed by a [Unicode punctuation character].
9. Emphasis begins with a delimiter that [can open emphasis] and ends
with a delimiter that [can close emphasis], and that uses the same
character (`_` or `*`) as the opening delimiter. The
opening and closing delimiters must belong to separate
[delimiter runs]. If one of the delimiters can both
open and close emphasis, then the sum of the lengths of the
delimiter runs containing the opening and closing delimiters
must not be a multiple of 3 unless both lengths are
multiples of 3.
10. Strong emphasis begins with a delimiter that
[can open strong emphasis] and ends with a delimiter that
[can close strong emphasis], and that uses the same character
(`_` or `*`) as the opening delimiter. The
opening and closing delimiters must belong to separate
[delimiter runs]. If one of the delimiters can both open
and close strong emphasis, then the sum of the lengths of
the delimiter runs containing the opening and closing
delimiters must not be a multiple of 3 unless both lengths
are multiples of 3.
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--12 above are compatible with multiple parsings,
the following principles resolve ambiguity:
13. The number of nestings should be minimized. Thus, for{panels},
an interpretation `...` is always preferred to
`...`.
14. An interpretation `...` is always
preferred to `...`.
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 takes precedence. Thus, for{panels},
`*foo _bar* baz_` is parsed as `foo _bar baz_` rather
than `*foo bar* baz`.
16. When there are two potential emphasis or strong emphasis spans
with the same closing delimiter, the shorter one (the one that
opens later) takes precedence. Thus, for{panels},
`**foo **bar baz**` is parsed as `**foo bar baz`
rather than `foo **bar baz`.
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{panels}, `*[foo*](bar)` is
parsed as `*foo*` rather than as
`[foo](bar)`.
These rules can be illustrated through a series of{panels}s.
Rule 1:
````````````````````````````````{panels}
*foo bar*
.
foo bar
````````````````````````````````
This is not emphasis, because the opening `*` is followed by
whitespace, and hence not part of a [left-flanking delimiter run]:
````````````````````````````````{panels}
a * foo bar*
.
a * foo bar*
````````````````````````````````
This is not emphasis, because the opening `*` is preceded
by an alphanumeric and followed by punctuation, and hence
not part of a [left-flanking delimiter run]:
````````````````````````````````{panels}
a*"foo"*
.
a*"foo"*
````````````````````````````````
Unicode nonbreaking spaces count as whitespace, too:
````````````````````````````````{panels}
* a *
.
* a *
````````````````````````````````
Intraword emphasis with `*` is permitted:
````````````````````````````````{panels}
foo*bar*
.
foobar
````````````````````````````````
````````````````````````````````{panels}
5*6*78
.
5678
````````````````````````````````
Rule 2:
````````````````````````````````{panels}
_foo bar_
.
foo bar
````````````````````````````````
This is not emphasis, because the opening `_` is followed by
whitespace:
````````````````````````````````{panels}
_ foo bar_
.
_ foo bar_
````````````````````````````````
This is not emphasis, because the opening `_` is preceded
by an alphanumeric and followed by punctuation:
````````````````````````````````{panels}
a_"foo"_
.
a_"foo"_
````````````````````````````````
Emphasis with `_` is not allowed inside words:
````````````````````````````````{panels}
foo_bar_
.
foo_bar_
````````````````````````````````
````````````````````````````````{panels}
5_6_78
.
5_6_78
````````````````````````````````
````````````````````````````````{panels}
пристаням_стремятся_
.
пристаням_стремятся_
````````````````````````````````
Here `_` does not generate emphasis, because the first delimiter run
is right-flanking and the second left-flanking:
````````````````````````````````{panels}
aa_"bb"_cc
.
aa_"bb"_cc
````````````````````````````````
This is emphasis, even though the opening delimiter is
both left- and right-flanking, because it is preceded by
punctuation:
````````````````````````````````{panels}
foo-_(bar)_
.
foo-(bar)
````````````````````````````````
Rule 3:
This is not emphasis, because the closing delimiter does
not match the opening delimiter:
````````````````````````````````{panels}
_foo*
.
_foo*
````````````````````````````````
This is not emphasis, because the closing `*` is preceded by
whitespace:
````````````````````````````````{panels}
*foo bar *
.
*foo bar *
````````````````````````````````
A line ending also counts as whitespace:
````````````````````````````````{panels}
*foo bar
*
.
*foo bar
*
````````````````````````````````
This is not emphasis, because the second `*` is
preceded by punctuation and followed by an alphanumeric
(hence it is not part of a [right-flanking delimiter run]:
````````````````````````````````{panels}
*(*foo)
.
*(*foo)
````````````````````````````````
The point of this restriction is more easily appreciated
with this{panels}:
````````````````````````````````{panels}
*(*foo*)*
.
(foo)
````````````````````````````````
Intraword emphasis with `*` is allowed:
````````````````````````````````{panels}
*foo*bar
.
foobar
````````````````````````````````
Rule 4:
This is not emphasis, because the closing `_` is preceded by
whitespace:
````````````````````````````````{panels}
_foo bar _
.
_foo bar _
````````````````````````````````
This is not emphasis, because the second `_` is
preceded by punctuation and followed by an alphanumeric:
````````````````````````````````{panels}
_(_foo)
.
_(_foo)
````````````````````````````````
This is emphasis within emphasis:
````````````````````````````````{panels}
_(_foo_)_
.
(foo)
````````````````````````````````
Intraword emphasis is disallowed for `_`:
````````````````````````````````{panels}
_foo_bar
.
_foo_bar
````````````````````````````````
````````````````````````````````{panels}
_пристаням_стремятся
.
_пристаням_стремятся
````````````````````````````````
````````````````````````````````{panels}
_foo_bar_baz_
.
foo_bar_baz
````````````````````````````````
This is emphasis, even though the closing delimiter is
both left- and right-flanking, because it is followed by
punctuation:
````````````````````````````````{panels}
_(bar)_.
.
(bar).
````````````````````````````````
Rule 5:
````````````````````````````````{panels}
**foo bar**
.
foo bar
````````````````````````````````
This is not strong emphasis, because the opening delimiter is
followed by whitespace:
````````````````````````````````{panels}
** foo bar**
.
** foo bar**
````````````````````````````````
This is not strong emphasis, because the opening `**` is preceded
by an alphanumeric and followed by punctuation, and hence
not part of a [left-flanking delimiter run]:
````````````````````````````````{panels}
a**"foo"**
.
a**"foo"**
````````````````````````````````
Intraword strong emphasis with `**` is permitted:
````````````````````````````````{panels}
foo**bar**
.
foobar
````````````````````````````````
Rule 6:
````````````````````````````````{panels}
__foo bar__
.
foo bar
````````````````````````````````
This is not strong emphasis, because the opening delimiter is
followed by whitespace:
````````````````````````````````{panels}
__ foo bar__
.
__ foo bar__
````````````````````````````````
A line ending counts as whitespace:
````````````````````````````````{panels}
__
foo bar__
.
__
foo bar__
````````````````````````````````
This is not strong emphasis, because the opening `__` is preceded
by an alphanumeric and followed by punctuation:
````````````````````````````````{panels}
a__"foo"__
.
a__"foo"__
````````````````````````````````
Intraword strong emphasis is forbidden with `__`:
````````````````````````````````{panels}
foo__bar__
.
foo__bar__
````````````````````````````````
````````````````````````````````{panels}
5__6__78
.
5__6__78
````````````````````````````````
````````````````````````````````{panels}
пристаням__стремятся__
.
пристаням__стремятся__
````````````````````````````````
````````````````````````````````{panels}
__foo, __bar__, baz__
.
foo, bar, baz
````````````````````````````````
This is strong emphasis, even though the opening delimiter is
both left- and right-flanking, because it is preceded by
punctuation:
````````````````````````````````{panels}
foo-__(bar)__
.
foo-(bar)
````````````````````````````````
Rule 7:
This is not strong emphasis, because the closing delimiter is preceded
by whitespace:
````````````````````````````````{panels}
**foo bar **
.
**foo bar **
````````````````````````````````
(Nor can it be interpreted as an emphasized `*foo bar *`, because of
Rule 11.)
This is not strong emphasis, because the second `**` is
preceded by punctuation and followed by an alphanumeric:
````````````````````````````````{panels}
**(**foo)
.
**(**foo)
````````````````````````````````
The point of this restriction is more easily appreciated
with these{panels}s:
````````````````````````````````{panels}
*(**foo**)*
.
(foo)
````````````````````````````````
````````````````````````````````{panels}
**Gomphocarpus (*Gomphocarpus physocarpus*, syn.
*Asclepias physocarpa*)**
.
Gomphocarpus (Gomphocarpus physocarpus, syn.
Asclepias physocarpa)
````````````````````````````````
````````````````````````````````{panels}
**foo "*bar*" foo**
.
foo "bar" foo
````````````````````````````````
Intraword emphasis:
````````````````````````````````{panels}
**foo**bar
.
foobar
````````````````````````````````
Rule 8:
This is not strong emphasis, because the closing delimiter is
preceded by whitespace:
````````````````````````````````{panels}
__foo bar __
.
__foo bar __
````````````````````````````````
This is not strong emphasis, because the second `__` is
preceded by punctuation and followed by an alphanumeric:
````````````````````````````````{panels}
__(__foo)
.
__(__foo)
````````````````````````````````
The point of this restriction is more easily appreciated
with this{panels}:
````````````````````````````````{panels}
_(__foo__)_
.
(foo)
````````````````````````````````
Intraword strong emphasis is forbidden with `__`:
````````````````````````````````{panels}
__foo__bar
.
__foo__bar
````````````````````````````````
````````````````````````````````{panels}
__пристаням__стремятся
.
__пристаням__стремятся
````````````````````````````````
````````````````````````````````{panels}
__foo__bar__baz__
.
foo__bar__baz
````````````````````````````````
This is strong emphasis, even though the closing delimiter is
both left- and right-flanking, because it is followed by
punctuation:
````````````````````````````````{panels}
__(bar)__.
.
(bar).
````````````````````````````````
Rule 9:
Any nonempty sequence of inline elements can be the contents of an
emphasized span.
````````````````````````````````{panels}
*foo [bar](/url)*
.
foo bar
````````````````````````````````
````````````````````````````````{panels}
*foo
bar*
.
foo
bar
````````````````````````````````
In particular, emphasis and strong emphasis can be nested
inside emphasis:
````````````````````````````````{panels}
_foo __bar__ baz_
.
foo bar baz
````````````````````````````````
````````````````````````````````{panels}
_foo _bar_ baz_
.
foo bar baz
````````````````````````````````
````````````````````````````````{panels}
__foo_ bar_
.
foo bar
````````````````````````````````
````````````````````````````````{panels}
*foo *bar**
.
foo bar
````````````````````````````````
````````````````````````````````{panels}
*foo **bar** baz*
.
foo bar baz
````````````````````````````````
````````````````````````````````{panels}
*foo**bar**baz*
.
foobarbaz
````````````````````````````````
Note that in the preceding case, the interpretation
``` markdown
foobarbaz
```
is precluded by the condition that a delimiter that
can both open and close (like the `*` after `foo`)
cannot form emphasis if the sum of the lengths of
the delimiter runs containing the opening and
closing delimiters is a multiple of 3 unless
both lengths are multiples of 3.
For the same reason, we don't get two consecutive
emphasis sections in this{panels}:
````````````````````````````````{panels}
*foo**bar*
.
foo**bar
````````````````````````````````
The same condition ensures that the following
cases are all strong emphasis nested inside
emphasis, even when the interior whitespace is
omitted:
````````````````````````````````{panels}
***foo** bar*
.
foo bar
````````````````````````````````
````````````````````````````````{panels}
*foo **bar***
.
foo bar
````````````````````````````````
````````````````````````````````{panels}
*foo**bar***
.
foobar
````````````````````````````````
When the lengths of the interior closing and opening
delimiter runs are *both* multiples of 3, though,
they can match to create emphasis:
````````````````````````````````{panels}
foo***bar***baz
.
foobarbaz
````````````````````````````````
````````````````````````````````{panels}
foo******bar*********baz
.
foobar***baz
````````````````````````````````
Indefinite levels of nesting are possible:
````````````````````````````````{panels}
*foo **bar *baz* bim** bop*
.
foo bar baz bim bop
````````````````````````````````
````````````````````````````````{panels}
*foo [*bar*](/url)*
.
foo bar
````````````````````````````````
There can be no empty emphasis or strong emphasis:
````````````````````````````````{panels}
** is not an empty emphasis
.
** is not an empty emphasis
````````````````````````````````
````````````````````````````````{panels}
**** is not an empty strong emphasis
.
**** is not an empty strong emphasis
````````````````````````````````
Rule 10:
Any nonempty sequence of inline elements can be the contents of an
strongly emphasized span.
````````````````````````````````{panels}
**foo [bar](/url)**
.
foo bar
````````````````````````````````
````````````````````````````````{panels}
**foo
bar**
.
foo
bar
````````````````````````````````
In particular, emphasis and strong emphasis can be nested
inside strong emphasis:
````````````````````````````````{panels}
__foo _bar_ baz__
.
foo bar baz
````````````````````````````````
````````````````````````````````{panels}
__foo __bar__ baz__
.
foo bar baz
````````````````````````````````
````````````````````````````````{panels}
____foo__ bar__
.
foo bar
````````````````````````````````
````````````````````````````````{panels}
**foo **bar****
.
foo bar
````````````````````````````````
````````````````````````````````{panels}
**foo *bar* baz**
.
foo bar baz
````````````````````````````````
````````````````````````````````{panels}
**foo*bar*baz**
.
foobarbaz
````````````````````````````````
````````````````````````````````{panels}
***foo* bar**
.
foo bar
````````````````````````````````
````````````````````````````````{panels}
**foo *bar***
.
foo bar
````````````````````````````````
Indefinite levels of nesting are possible:
````````````````````````````````{panels}
**foo *bar **baz**
bim* bop**
.
foo bar baz
bim bop
````````````````````````````````
````````````````````````````````{panels}
**foo [*bar*](/url)**
.
foo bar
````````````````````````````````
There can be no empty emphasis or strong emphasis:
````````````````````````````````{panels}
__ is not an empty emphasis
.
__ is not an empty emphasis
````````````````````````````````
````````````````````````````````{panels}
____ is not an empty strong emphasis
.
____ is not an empty strong emphasis
````````````````````````````````
Rule 11:
````````````````````````````````{panels}
foo ***
.
foo ***
````````````````````````````````
````````````````````````````````{panels}
foo *\**
.
foo *
````````````````````````````````
````````````````````````````````{panels}
foo *_*
.
foo _
````````````````````````````````
````````````````````````````````{panels}
foo *****
.
foo *****
````````````````````````````````
````````````````````````````````{panels}
foo **\***
.
foo *
````````````````````````````````
````````````````````````````````{panels}
foo **_**
.
foo _
````````````````````````````````
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:
````````````````````````````````{panels}
**foo*
.
*foo
````````````````````````````````
````````````````````````````````{panels}
*foo**
.
foo*
````````````````````````````````
````````````````````````````````{panels}
***foo**
.
*foo
````````````````````````````````
````````````````````````````````{panels}
****foo*
.
***foo
````````````````````````````````
````````````````````````````````{panels}
**foo***
.
foo*
````````````````````````````````
````````````````````````````````{panels}
*foo****
.
foo***
````````````````````````````````
Rule 12:
````````````````````````````````{panels}
foo ___
.
foo ___
````````````````````````````````
````````````````````````````````{panels}
foo _\__
.
foo _
````````````````````````````````
````````````````````````````````{panels}
foo _*_
.
foo *
````````````````````````````````
````````````````````````````````{panels}
foo _____
.
foo _____
````````````````````````````````
````````````````````````````````{panels}
foo __\___
.
foo _
````````````````````````````````
````````````````````````````````{panels}
foo __*__
.
foo *
````````````````````````````````
````````````````````````````````{panels}
__foo_
.
_foo
````````````````````````````````
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:
````````````````````````````````{panels}
_foo__
.
foo_
````````````````````````````````
````````````````````````````````{panels}
___foo__
.
_foo
````````````````````````````````
````````````````````````````````{panels}
____foo_
.
___foo
````````````````````````````````
````````````````````````````````{panels}
__foo___
.
foo_
````````````````````````````````
````````````````````````````````{panels}
_foo____
.
foo___
````````````````````````````````
Rule 13 implies that if you want emphasis nested directly inside
emphasis, you must use different delimiters:
````````````````````````````````{panels}
**foo**
.
foo
````````````````````````````````
````````````````````````````````{panels}
*_foo_*
.
foo
````````````````````````````````
````````````````````````````````{panels}
__foo__
.
foo
````````````````````````````````
````````````````````````````````{panels}
_*foo*_
.
foo
````````````````````````````````
However, strong emphasis within strong emphasis is possible without
switching delimiters:
````````````````````````````````{panels}
****foo****
.
foo
````````````````````````````````
````````````````````````````````{panels}
____foo____
.
foo
````````````````````````````````
Rule 13 can be applied to arbitrarily long sequences of
delimiters:
````````````````````````````````{panels}
******foo******
.
foo
````````````````````````````````
Rule 14:
````````````````````````````````{panels}
***foo***
.
foo
````````````````````````````````
````````````````````````````````{panels}
_____foo_____
.
foo
````````````````````````````````
Rule 15:
````````````````````````````````{panels}
*foo _bar* baz_
.
foo _bar baz_
````````````````````````````````
````````````````````````````````{panels}
*foo __bar *baz bim__ bam*
.
foo bar *baz bim bam
````````````````````````````````
Rule 16:
````````````````````````````````{panels}
**foo **bar baz**
.
**foo bar baz
````````````````````````````````
````````````````````````````````{panels}
*foo *bar baz*
.
*foo bar baz
````````````````````````````````
Rule 17:
````````````````````````````````{panels}
*[bar*](/url)
.
*bar*
````````````````````````````````
````````````````````````````````{panels}
_foo [bar_](/url)
.
_foo bar_
````````````````````````````````
````````````````````````````````{panels}
*
.
*
````````````````````````````````
````````````````````````````````{panels}
**
.
````````````````````````````````
````````````````````````````````{panels}
__
.
````````````````````````````````
````````````````````````````````{panels}
*a `*`*
.
a *
````````````````````````````````
````````````````````````````````{panels}
_a `_`_
.
a _
````````````````````````````````
````````````````````````````````{panels}
**a
.
````````````````````````````````
````````````````````````````````{panels}
__a
.
````````````````````````````````
## Links
A link contains [link text] (the visible text), a [link destination]
(the URI that is the link destination), and optionally a [link title].
There are two basic kinds of links in Markdown. In [inline links] the
destination and title are given immediately after the link text. In
[reference links] the destination and title are defined elsewhere in
the document.
A [link text](#@) consists of a sequence of zero or more
inline elements enclosed by square brackets (`[` and `]`). The
following rules apply:
- Links may not contain other links, at any level of nesting. If
multiple otherwise valid link definitions appear nested inside each
other, the inner-most definition is used.
- Brackets are allowed in the [link text] only if (a) they
are backslash-escaped or (b) they appear as a matched pair of brackets,
with an open bracket `[`, a sequence of zero or more inlines, and
a close bracket `]`.
- Backtick [code spans], [autolinks], and raw [HTML tags] bind more tightly
than the brackets in link text. Thus, for{panels},
`` [foo`]` `` could not be a link text, since the second `]`
is part of a code span.
- The brackets in link text bind more tightly than markers for
[emphasis and strong emphasis]. Thus, for{panels}, `*[foo*](url)` is a link.
A [link destination](#@) consists of either
- a sequence of zero or more characters between an opening `<` and a
closing `>` that contains no line endings or unescaped
`<` or `>` characters, or
- a nonempty sequence of characters that does not start with `<`,
does not include [ASCII control characters][ASCII control character]
or [space] character, and includes parentheses only if (a) they are
backslash-escaped or (b) they are part of a balanced pair of
unescaped parentheses.
(Implementations may impose limits on parentheses nesting to
avoid performance issues, but at least three levels of nesting
should be supported.)
A [link title](#@) consists of either
- a sequence of zero or more characters between straight double-quote
characters (`"`), including a `"` character only if it is
backslash-escaped, or
- a sequence of zero or more characters between straight single-quote
characters (`'`), including a `'` character only if it is
backslash-escaped, or
- a sequence of zero or more characters between matching parentheses
(`(...)`), including a `(` or `)` character only if it is
backslash-escaped.
Although [link titles] may span multiple lines, they may not contain
a [blank line].
An [inline link](#@) consists of a [link text] followed immediately
by a left parenthesis `(`, an optional [link destination], an optional
[link title], and a right parenthesis `)`.
These four components may be separated by spaces, tabs, and up to one line
ending.
If both [link destination] and [link title] are present, they *must* be
separated by spaces, tabs, and up to one line ending.
The link's text consists of the inlines contained
in the [link text] (excluding the enclosing square brackets).
The link's URI consists of the link destination, excluding enclosing
`<...>` if present, with backslash-escapes in effect as described
above. The link's title consists of the link title, excluding its
enclosing delimiters, with backslash-escapes in effect as described
above.
Here is a simple inline link:
````````````````````````````````{panels}
[link](/uri "title")
.
````````````````````````````````
The title, the link text and even
the destination may be omitted:
````````````````````````````````{panels}
[link](/uri)
.
````````````````````````````````
````````````````````````````````{panels}
[](./target.md)
.
````````````````````````````````
````````````````````````````````{panels}
[link]()
.
````````````````````````````````
````````````````````````````````{panels}
[link](<>)
.
````````````````````````````````
````````````````````````````````{panels}
[]()
.
````````````````````````````````
The destination can only contain spaces if it is
enclosed in pointy brackets:
````````````````````````````````{panels}
[link](/my uri)
.
[link](/my uri)
````````````````````````````````
````````````````````````````````{panels}
[link]()
.
````````````````````````````````
The destination cannot contain line endings,
even if enclosed in pointy brackets:
````````````````````````````````{panels}
[link](foo
bar)
.
[link](foo
bar)
````````````````````````````````
````````````````````````````````{panels}
[link]()
.
[link]()
````````````````````````````````
The destination can contain `)` if it is enclosed
in pointy brackets:
````````````````````````````````{panels}
[a]()
.
````````````````````````````````
Pointy brackets that enclose links must be unescaped:
````````````````````````````````{panels}
[link]()
.
[link](<foo>)
````````````````````````````````
These are not links, because the opening pointy bracket
is not matched properly:
````````````````````````````````{panels}
[a](
[a](c)
.
[a](<b)c
[a](<b)c>
[a](c)
````````````````````````````````
Parentheses inside the link destination may be escaped:
````````````````````````````````{panels}
[link](\(foo\))
.
````````````````````````````````
Any number of parentheses are allowed without escaping, as long as they are
balanced:
````````````````````````````````{panels}
[link](foo(and(bar)))
.
````````````````````````````````
However, if you have unbalanced parentheses, you need to escape or use the
`<...>` form:
````````````````````````````````{panels}
[link](foo(and(bar))
.
[link](foo(and(bar))
````````````````````````````````
````````````````````````````````{panels}
[link](foo\(and\(bar\))
.
````````````````````````````````
````````````````````````````````{panels}
[link]()
.
````````````````````````````````
Parentheses and other symbols can also be escaped, as usual
in Markdown:
````````````````````````````````{panels}
[link](foo\)\:)
.
````````````````````````````````
A link can contain fragment identifiers and queries:
````````````````````````````````{panels}
[link](#fragment)
[link](http://example.com#fragment)
[link](http://example.com?foo=3#frag)
.
````````````````````````````````
Note that a backslash before a non-escapable character is
just a backslash:
````````````````````````````````{panels}
[link](foo\bar)
.
````````````````````````````````
URL-escaping should be left alone inside the destination, as all
URL-escaped characters are also valid URL characters. Entity and
numerical character references in the destination will be parsed
into the corresponding Unicode code points, as usual. These may
be optionally URL-escaped when written as HTML, but this spec
does not enforce any particular policy for rendering URLs in
HTML or other formats. Renderers may make different decisions
about how to escape or normalize URLs in the output.
````````````````````````````````{panels}
[link](foo%20bä)
.
````````````````````````````````
Note that, because titles can often be parsed as destinations,
if you try to omit the destination and keep the title, you'll
get unexpected results:
````````````````````````````````{panels}
[link]("title")
.
````````````````````````````````
Titles may be in single quotes, double quotes, or parentheses:
````````````````````````````````{panels}
[link](/url "title")
[link](/url 'title')
[link](/url (title))
.
````````````````````````````````
Backslash escapes and entity and numeric character references
may be used in titles:
````````````````````````````````{panels}
[link](/url "title \""")
.
````````````````````````````````
Titles must be separated from the link using spaces, tabs, and up to one line
ending.
Other [Unicode whitespace] like non-breaking space doesn't work.
````````````````````````````````{panels}
[link](/url "title")
.
````````````````````````````````
Nested balanced quotes are not allowed without escaping:
````````````````````````````````{panels}
[link](/url "title "and" title")
.
[link](/url "title "and" title")
````````````````````````````````
But it is easy to work around this by using a different quote type:
````````````````````````````````{panels}
[link](/url 'title "and" title')
.
````````````````````````````````
(Note: `Markdown.pl` did allow double quotes inside a double-quoted
title, and its test suite included a test demonstrating this.
But it is hard to see a good rationale for the extra complexity this
brings, since there are already many ways---backslash escaping,
entity and numeric character references, or using a different
quote type for the enclosing title---to write titles containing
double quotes. `Markdown.pl`'s handling of titles has a number
of other strange features. For{panels}, it allows 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 `"` 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 a simple, rational rule that works
the same way in inline links and link reference definitions.)
Spaces, tabs, and up to one line ending is allowed around the destination and
title:
````````````````````````````````{panels}
[link]( /uri
"title" )
.
````````````````````````````````
But it is not allowed between the link text and the
following parenthesis:
````````````````````````````````{panels}
[link] (/uri)
.
[link] (/uri)
````````````````````````````````
The link text may contain balanced brackets, but not unbalanced ones,
unless they are escaped:
````````````````````````````````{panels}
[link [foo [bar]]](/uri)
.
````````````````````````````````
````````````````````````````````{panels}
[link] bar](/uri)
.
[link] bar](/uri)
````````````````````````````````
````````````````````````````````{panels}
[link [bar](/uri)
.
[link bar
````````````````````````````````
````````````````````````````````{panels}
[link \[bar](/uri)
.
````````````````````````````````
The link text may contain inline content:
````````````````````````````````{panels}
[link *foo **bar** `#`*](/uri)
.
````````````````````````````````
````````````````````````````````{panels}
[![moon](moon.jpg)](/uri)
.
````````````````````````````````
However, links may not contain other links, at any level of nesting.
````````````````````````````````{panels}
[foo [bar](/uri)](/uri)
.
[foo bar](/uri)
````````````````````````````````
````````````````````````````````{panels}
[foo *[bar [baz](/uri)](/uri)*](/uri)
.
[foo [bar baz](/uri)](/uri)
````````````````````````````````
````````````````````````````````{panels}
![[[foo](uri1)](uri2)](uri3)
.
````````````````````````````````
These cases illustrate the precedence of link text grouping over
emphasis grouping:
````````````````````````````````{panels}
*[foo*](/uri)
.
*foo*
````````````````````````````````
````````````````````````````````{panels}
[foo *bar](baz*)
.
````````````````````````````````
Note that brackets that *aren't* part of links do not take
precedence:
````````````````````````````````{panels}
*foo [bar* baz]
.
foo [bar baz]
````````````````````````````````
These cases illustrate the precedence of HTML tags, code spans,
and autolinks over link grouping:
````````````````````````````````{panels}
[foo
.
[foo
````````````````````````````````
````````````````````````````````{panels}
[foo`](/uri)`
.
[foo](/uri)
````````````````````````````````
````````````````````````````````{panels}
[foo
.
[foohttp://example.com/?search=](uri)
````````````````````````````````
There are three kinds of [reference link](#@)s:
[full](#full-reference-link), [collapsed](#collapsed-reference-link),
and [shortcut](#shortcut-reference-link).
A [full reference link](#@)
consists of a [link text] immediately followed by a [link label]
that [matches] a [link reference definition] elsewhere in the document.
A [link label](#@) begins with a left bracket (`[`) and ends
with the first right bracket (`]`) that is not backslash-escaped.
Between these brackets there must be at least one character that is not a space,
tab, or line ending.
Unescaped square bracket characters are not allowed inside the
opening and closing square brackets of [link labels]. A link
label can have at most 999 characters inside the square
brackets.
One label [matches](#@)
another just in case their normalized forms are equal. To normalize a
label, strip off the opening and closing brackets,
perform the *Unicode case fold*, strip leading and trailing
spaces, tabs, and line endings, and collapse consecutive internal
spaces, tabs, and line endings to a single space. If there are multiple
matching reference link definitions, the one that comes first in the
document is used. (It is desirable in such cases to emit a warning.)
The link's URI and title are provided by the matching [link
reference definition].
Here is a simple{panels}:
````````````````````````````````{panels}
[foo][bar]
[bar]: /url "title"
.
````````````````````````````````
The rules for the [link text] are the same as with
[inline links]. Thus:
The link text may contain balanced brackets, but not unbalanced ones,
unless they are escaped:
````````````````````````````````{panels}
[link [foo [bar]]][ref]
[ref]: /uri
.
````````````````````````````````
````````````````````````````````{panels}
[link \[bar][ref]
[ref]: /uri
.
````````````````````````````````
The link text may contain inline content:
````````````````````````````````{panels}
[link *foo **bar** `#`*][ref]
[ref]: /uri
.
````````````````````````````````
````````````````````````````````{panels}
[![moon](moon.jpg)][ref]
[ref]: /uri
.
````````````````````````````````
However, links may not contain other links, at any level of nesting.
````````````````````````````````{panels}
[foo [bar](/uri)][ref]
[ref]: /uri
.
````````````````````````````````
````````````````````````````````{panels}
[foo *bar [baz][ref]*][ref]
[ref]: /uri
.
````````````````````````````````
(In the{panels}s above, we have two [shortcut reference links]
instead of one [full reference link].)
The following cases illustrate the precedence of link text grouping over
emphasis grouping:
````````````````````````````````{panels}
*[foo*][ref]
[ref]: /uri
.
*foo*
````````````````````````````````
````````````````````````````````{panels}
[foo *bar][ref]*
[ref]: /uri
.
````````````````````````````````
These cases illustrate the precedence of HTML tags, code spans,
and autolinks over link grouping:
````````````````````````````````{panels}
[foo
[ref]: /uri
.
[foo
````````````````````````````````
````````````````````````````````{panels}
[foo`][ref]`
[ref]: /uri
.
[foo][ref]
````````````````````````````````
````````````````````````````````{panels}
[foo
[ref]: /uri
.
[foohttp://example.com/?search=][ref]
````````````````````````````````
Matching is case-insensitive:
````````````````````````````````{panels}
[foo][BaR]
[bar]: /url "title"
.
````````````````````````````````
Unicode case fold is used:
````````````````````````````````{panels}
[ẞ]
[SS]: /url
.
````````````````````````````````
Consecutive internal spaces, tabs, and line endings are treated as one space for
purposes of determining matching:
````````````````````````````````{panels}
[Foo
bar]: /url
[Baz][Foo bar]
.
````````````````````````````````
No spaces, tabs, or line endings are allowed between the [link text] and the
[link label]:
````````````````````````````````{panels}
[foo] [bar]
[bar]: /url "title"
.
[foo] bar
````````````````````````````````
````````````````````````````````{panels}
[foo]
[bar]
[bar]: /url "title"
.
[foo]
bar
````````````````````````````````
This is a departure from John Gruber's original Markdown syntax
description, which explicitly allows whitespace between the link
text and the link label. It brings reference links in line with
[inline links], which (according to both original Markdown and
this spec) cannot have whitespace after the link text. More
importantly, it prevents inadvertent capture of consecutive
[shortcut reference links]. If whitespace is allowed between the
link text and the link label, then in the following we will have
a single reference link, not two shortcut reference links, as
intended:
``` markdown
[foo]
[bar]
[foo]: /url1
[bar]: /url2
```
(Note that [shortcut reference links] were introduced by Gruber
himself in a beta version of `Markdown.pl`, but never included
in the official syntax description. Without shortcut reference
links, it is harmless to allow space between the link text and
link label; but once shortcut references are introduced, it is
too dangerous to allow this, as it frequently leads to
unintended results.)
When there are multiple matching [link reference definitions],
the first is used:
````````````````````````````````{panels}
[foo]: /url1
[foo]: /url2
[bar][foo]
.
````````````````````````````````
Note that matching is performed on normalized strings, not parsed
inline content. So the following does not match, even though the
labels define equivalent inline content:
````````````````````````````````{panels}
[bar][foo\!]
[foo!]: /url
.
[bar][foo!]
````````````````````````````````
[Link labels] cannot contain brackets, unless they are
backslash-escaped:
````````````````````````````````{panels}
[foo][ref[]
[ref[]: /uri
.
[foo][ref[]
[ref[]: /uri
````````````````````````````````
````````````````````````````````{panels}
[foo][ref[bar]]
[ref[bar]]: /uri
.
[foo][ref[bar]]
[ref[bar]]: /uri
````````````````````````````````
````````````````````````````````{panels}
[[[foo]]]
[[[foo]]]: /url
.
[[[foo]]]
[[[foo]]]: /url
````````````````````````````````
````````````````````````````````{panels}
[foo][ref\[]
[ref\[]: /uri
.
````````````````````````````````
Note that in this{panels} `]` is not backslash-escaped:
````````````````````````````````{panels}
[bar\\]: /uri
[bar\\]
.
````````````````````````````````
A [link label] must contain at least one character that is not a space, tab, or
line ending:
````````````````````````````````{panels}
[]
[]: /uri
.
[]
[]: /uri
````````````````````````````````
````````````````````````````````{panels}
[
]
[
]: /uri
.
[
]
[
]: /uri
````````````````````````````````
A [collapsed reference link](#@)
consists of a [link label] that [matches] a
[link reference definition] elsewhere in the
document, followed by the string `[]`.
The contents of the 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 link definition. Thus,
`[foo][]` is equivalent to `[foo][foo]`.
````````````````````````````````{panels}
[foo][]
[foo]: /url "title"
.
````````````````````````````````
````````````````````````````````{panels}
[*foo* bar][]
[*foo* bar]: /url "title"
.
````````````````````````````````
The link labels are case-insensitive:
````````````````````````````````{panels}
[Foo][]
[foo]: /url "title"
.
````````````````````````````````
As with full reference links, spaces, tabs, or line endings are not
allowed between the two sets of brackets:
````````````````````````````````{panels}
[foo]
[]
[foo]: /url "title"
.
foo
[]
````````````````````````````````
A [shortcut reference link](#@)
consists of a [link label] that [matches] a
[link reference definition] elsewhere in the
document and is not followed by `[]` or a link label.
The contents of the 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 link reference definition.
Thus, `[foo]` is equivalent to `[foo][]`.
````````````````````````````````{panels}
[foo]
[foo]: /url "title"
.
````````````````````````````````
````````````````````````````````{panels}
[*foo* bar]
[*foo* bar]: /url "title"
.
````````````````````````````````
````````````````````````````````{panels}
[[*foo* bar]]
[*foo* bar]: /url "title"
.
[foo bar]
````````````````````````````````
````````````````````````````````{panels}
[[bar [foo]
[foo]: /url
.
[[bar foo
````````````````````````````````
The link labels are case-insensitive:
````````````````````````````````{panels}
[Foo]
[foo]: /url "title"
.
````````````````````````````````
A space after the link text should be preserved:
````````````````````````````````{panels}
[foo] bar
[foo]: /url
.
foo bar
````````````````````````````````
If you just want bracketed text, you can backslash-escape the
opening bracket to avoid links:
````````````````````````````````{panels}
\[foo]
[foo]: /url "title"
.
[foo]
````````````````````````````````
Note that this is a link, because a link label ends with the first
following closing bracket:
````````````````````````````````{panels}
[foo*]: /url
*[foo*]
.
*foo*
````````````````````````````````
Full and compact references take precedence over shortcut
references:
````````````````````````````````{panels}
[foo][bar]
[foo]: /url1
[bar]: /url2
.
````````````````````````````````
````````````````````````````````{panels}
[foo][]
[foo]: /url1
.
````````````````````````````````
Inline links also take precedence:
````````````````````````````````{panels}
[foo]()
[foo]: /url1
.
````````````````````````````````
````````````````````````````````{panels}
[foo](not a link)
[foo]: /url1
.
foo(not a link)
````````````````````````````````
In the following case `[bar][baz]` is parsed as a reference,
`[foo]` as normal text:
````````````````````````````````{panels}
[foo][bar][baz]
[baz]: /url
.
[foo]bar
````````````````````````````````
Here, though, `[foo][bar]` is parsed as a reference, since
`[bar]` is defined:
````````````````````````````````{panels}
[foo][bar][baz]
[baz]: /url1
[bar]: /url2
.
````````````````````````````````
Here `[foo]` is not parsed as a shortcut reference, because it
is followed by a link label (even though `[bar]` is not defined):
````````````````````````````````{panels}
[foo][bar][baz]
[baz]: /url1
[foo]: /url2
.
[foo]bar
````````````````````````````````
## Images
Syntax for images is like the syntax for links, with one
difference. Instead of [link text], we have an
[image description](#@). The rules for this are the
same as for [link text], except that (a) an
image description starts with `![` rather than `[`, and
(b) an image description may contain links.
An image description has inline elements
as its contents. When an image is rendered to HTML,
this is standardly used as the image's `alt` attribute.
````````````````````````````````{panels}
```
![foo](/url "title")
```
---
```
```
````````````````````````````````
````````````````````````````````{panels}
```
![foo *bar*]
[foo *bar*]: train.jpg "train & tracks"
```
---
```
```
````````````````````````````````
````````````````````````````````{panels}
```
![foo ![bar](/url)](/url2)
```
---
```
```
````````````````````````````````
````````````````````````````````{panels}
```
![foo [bar](/url)](/url2)
```
---
```
```
````````````````````````````````
Though this spec is concerned with parsing, not rendering, it is
recommended that in rendering to HTML, only the plain string content
of the [image description] be used. Note that in
the above{panels}, the alt attribute's value is `foo bar`, not `foo
[bar](/url)` or `foo bar`. Only the plain string
content is rendered, without formatting.
````````````````````````````````{panels}
```
![foo *bar*][]
[foo *bar*]: train.jpg "train & tracks"
```
---
```
```
````````````````````````````````
````````````````````````````````{panels}
```
![foo *bar*][foobar]
[FOOBAR]: train.jpg "train & tracks"
```
---
```
```
````````````````````````````````
````````````````````````````````{panels}
```
![foo](train.jpg)
```
---
```
```
````````````````````````````````
````````````````````````````````{panels}
```
My ![foo bar](/path/to/train.jpg "title" )
```
---
```
My
```
````````````````````````````````
````````````````````````````````{panels}
```
![foo]()
```
---
```
```
````````````````````````````````
````````````````````````````````{panels}
```
![](/url)
```
---
```
```
````````````````````````````````
Reference-style:
````````````````````````````````{panels}
```````
![foo][bar]
[bar]: /url
```````
---
```````
```````
````````````````````````````````
````````````````````````````````{panels}
```````
![foo][bar]
[BAR]: /url
```````
---
```````
```````
````````````````````````````````
Collapsed:
````````````````````````````````{panels}
```````
![foo][]
[foo]: /url "title"
```````
---
```````
```````
````````````````````````````````
````````````````````````````````{panels}
```````
![*foo* bar][]
[*foo* bar]: /url "title"
```````
---
```````
```````
````````````````````````````````
The labels are case-insensitive:
````````````````````````````````{panels}
```````
![Foo][]
[foo]: /url "title"
```````
---
```````
```````
````````````````````````````````
As with reference links, spaces, tabs, and line endings, are not allowed
between the two sets of brackets:
````````````````````````````````{panels}
```````
![foo]
[]
[foo]: /url "title"
```````
---
```````
[]
```````
````````````````````````````````
Shortcut:
````````````````````````````````{panels}
```````
![foo]
[foo]: /url "title"
```````
---
```````
```````
````````````````````````````````
````````````````````````````````{panels}
```````
![*foo* bar]
[*foo* bar]: /url "title"
```````
---
```````
```````
````````````````````````````````
Note that link labels cannot contain unescaped brackets:
````````````````````````````````{panels}
```````
![[foo]]
[[foo]]: /url "title"
```````
---
```````
![[foo]]
[[foo]]: /url "title"
```````
````````````````````````````````
The link labels are case-insensitive:
````````````````````````````````{panels}
```````
![Foo]
[foo]: /url "title"
```````
---
```````
```````
````````````````````````````````
If you just want a literal `!` followed by bracketed text, you can
backslash-escape the opening `[`:
````````````````````````````````{panels}
```````
!\[foo]
[foo]: /url "title"
```````
---
```````
![foo]
```````
````````````````````````````````
If you want a link after a literal `!`, backslash-escape the
`!`:
````````````````````````````````{panels}
```````
\![foo]
[foo]: /url "title"
```````
---
```````
!foo
```````
````````````````````````````````
## Autolinks
[Autolink](#@)s are absolute URIs and email addresses inside
`<` and `>`. They are parsed as links, with the URL or email address
as the link label.
A [URI autolink](#@) consists of `<`, followed by an
[absolute URI] followed by `>`. It is parsed as
a link to the URI, with the URI as the link's label.
An [absolute URI](#@),
for these purposes, consists of a [scheme] followed by a colon (`:`)
followed by zero or more characters other than [ASCII control
characters][ASCII control character], [space], `<`, and `>`.
If the URI includes these characters, they must be percent-encoded
(e.g. `%20` for a space).
For purposes of this spec, a [scheme](#@) is any sequence
of 2--32 characters beginning with an ASCII letter and followed
by any combination of ASCII letters, digits, or the symbols plus
("+"), period ("."), or hyphen ("-").
Here are some valid autolinks:
````````````````````````````````{panels}
```````
```````
---
```````
```````
````````````````````````````````
````````````````````````````````{panels}
```````
```````
---
```````
http://foo.bar.baz/test?q=hello&id=22&boolean
```````
````````````````````````````````
````````````````````````````````{panels}
```````
```````
---
```````
```````
````````````````````````````````
Uppercase is also fine:
````````````````````````````````{panels}
```````
```````
---
```````
```````
````````````````````````````````
Note that many strings that count as [absolute URIs] for
purposes of this spec are not valid URIs, because their
schemes are not registered or because of other problems
with their syntax:
````````````````````````````````{panels}
```````
```````
---
```````
```````
````````````````````````````````
````````````````````````````````{panels}
```````
```````
---
```````
```````
````````````````````````````````
````````````````````````````````{panels}
```````
```````
---
```````
```````
````````````````````````````````
````````````````````````````````{panels}
```````
```````
---
```````
```````
````````````````````````````````
Spaces are not allowed in autolinks:
````````````````````````````````{panels}
```````
```````
---
```````
<http://foo.bar/baz bim>
```````
````````````````````````````````
Backslash-escapes do not work inside autolinks:
````````````````````````````````{panels}
```````
```````
---
```````
```````
````````````````````````````````
An [email autolink](#@)
consists of `<`, followed by an [email address],
followed by `>`. The link's label is the email address,
and the URL is `mailto:` followed by the email address.
An [email address](#@),
for these purposes, is anything that matches
the [non-normative regex from the HTML5
spec](https://html.spec.whatwg.org/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-]{0,61}[a-zA-Z0-9])?)*$/
Examples of email autolinks:
````````````````````````````````{panels}
```````
```````
---
```````
```````
````````````````````````````````
````````````````````````````````{panels}
```````
```````
---
```````
```````
````````````````````````````````
Backslash-escapes do not work inside email autolinks:
````````````````````````````````{panels}
```````
```````
---
```````
<foo+@bar.example.com>
```````
````````````````````````````````
These are not autolinks:
````````````````````````````````{panels}
```````
<>
```````
---
```````
<>
```````
````````````````````````````````
````````````````````````````````{panels}
```````
< http://foo.bar >
```````
---
```````
< http://foo.bar >
```````
````````````````````````````````
````````````````````````````````{panels}
```````
```````
---
```````
<m:abc>
```````
````````````````````````````````
````````````````````````````````{panels}
```````
```````
---
```````
<foo.bar.baz>
```````
````````````````````````````````
````````````````````````````````{panels}
```````
http://example.com
```````
---
```````
http://example.com
```````
````````````````````````````````
````````````````````````````````{panels}
```````
foo@bar.example.com
```````
---
```````
foo@bar.example.com
```````
````````````````````````````````
## Raw HTML
Text between `<` and `>` that looks like an HTML tag is parsed as a
raw HTML tag and will be rendered in HTML without escaping.
Tag and attribute names are not limited to current HTML tags,
so custom tags (and even, say, DocBook tags) may be used.
Here is the grammar for tags:
A [tag name](#@) consists of an ASCII letter
followed by zero or more ASCII letters, digits, or
hyphens (`-`).
An [attribute](#@) consists of spaces, tabs, and up to one line ending,
an [attribute name], and an optional
[attribute value specification].
An [attribute name](#@)
consists of an ASCII letter, `_`, or `:`, followed by zero or more ASCII
letters, digits, `_`, `.`, `:`, or `-`. (Note: This is the XML
specification restricted to ASCII. HTML5 is laxer.)
An [attribute value specification](#@)
consists of optional spaces, tabs, and up to one line ending,
a `=` character, optional spaces, tabs, and up to one line ending,
and an [attribute value].
An [attribute value](#@)
consists of an [unquoted attribute value],
a [single-quoted attribute value], or a [double-quoted attribute value].
An [unquoted attribute value](#@)
is a nonempty string of characters not
including spaces, tabs, line endings, `"`, `'`, `=`, `<`, `>`, or `` ` ``.
A [single-quoted attribute value](#@)
consists of `'`, zero or more
characters not including `'`, and a final `'`.
A [double-quoted attribute value](#@)
consists of `"`, zero or more
characters not including `"`, and a final `"`.
An [open tag](#@) consists of a `<` character, a [tag name],
zero or more [attributes], optional spaces, tabs, and up to one line ending,
an optional `/` character, and a `>` character.
A [closing tag](#@) consists of the string ``, a
[tag name], optional spaces, tabs, and up to one line ending, and the character
`>`.
An [HTML comment](#@) consists of ``,
where *text* does not start with `>` or `->`, does not end with `-`,
and does not contain `--`. (See the
[HTML5 spec](http://www.w3.org/TR/html5/syntax.html#comments).)
A [processing instruction](#@)
consists of the string ``, a string
of characters not including the string `?>`, and the string
`?>`.
A [declaration](#@) consists of the string ``, and the character `>`.
A [CDATA section](#@) consists of
the string ``, and the string `]]>`.
An [HTML tag](#@) consists of an [open tag], a [closing tag],
an [HTML comment], a [processing instruction], a [declaration],
or a [CDATA section].
Here are some simple open tags:
````````````````````````````````{panels}
```````
```````
---
```````
```````
````````````````````````````````
Empty elements:
````````````````````````````````{panels}
```````
```````
---
```````
```````
````````````````````````````````
Whitespace is allowed:
````````````````````````````````{panels}
```````
```````
---
```````
```````
````````````````````````````````
With attributes:
````````````````````````````````{panels}
```````
```````
---
```````
```````
````````````````````````````````
Custom tag names can be used:
````````````````````````````````{panels}
```````
Foo
```````
---
```````
Foo
```````
````````````````````````````````
Illegal tag names, not parsed as HTML:
````````````````````````````````{panels}
```````
<33> <__>
```````
---
```````
<33> <__>
```````
````````````````````````````````
Illegal attribute names:
````````````````````````````````{panels}
```````
```````
---
```````
<a h*#ref="hi">
```````
````````````````````````````````
Illegal attribute values:
````````````````````````````````{panels}
```````
---
```````
</a href="foo">
```````
````````````````````````````````
Comments:
````````````````````````````````{panels}
```````
foo
```````
---
```````
foo
```````
````````````````````````````````
````````````````````````````````{panels}
```````
foo
```````
---
```````
foo <!-- not a comment -- two hyphens -->
````````````````````````````````
Not comments:
````````````````````````````````{panels}
```````
foo foo -->
foo
```````
---
```````
foo <!--> foo -->
foo <!-- foo--->
```````
````````````````````````````````
Processing instructions:
````````````````````````````````{panels}
```````
foo
```````
---
```````
foo
```````
````````````````````````````````
Declarations:
````````````````````````````````{panels}
```````
foo
```````
---
```````
foo
```````
````````````````````````````````
CDATA sections:
````````````````````````````````{panels}
```````
foo &<]]>
```````
---
```````
foo &<]]>
```````
````````````````````````````````
Entity and numeric character references are preserved in HTML
attributes:
````````````````````````````````{panels}
```````
foo
```````
---
```````
```````
````````````````````````````````
Backslash escapes do not work in HTML attributes:
````````````````````````````````{panels}
```````
foo
```````
---
```````
```````
````````````````````````````````
````````````````````````````````{panels}
```````
```````
---
```````
<a href=""">
```````
````````````````````````````````
## Hard line breaks
A line ending (not in a code span or HTML tag) that is preceded
by two or more spaces and does not occur at the end of a block
is parsed as a [hard line break](#@) (rendered
in HTML as a `
` tag):
````````````````````````````````{panels}
```````
foo
baz
```````
---
```````
foo
baz
```````
````````````````````````````````
For a more visible alternative, a backslash before the
[line ending] may be used instead of two or more spaces:
````````````````````````````````{panels}
```````
foo\
baz
```````
---
```````
foo
baz
```````
````````````````````````````````
More than two spaces can be used:
````````````````````````````````{panels}
```````
foo
baz
```````
---
```````
foo
baz
```````
````````````````````````````````
Leading spaces at the beginning of the next line are ignored:
````````````````````````````````{panels}
```````
foo
bar
```````
---
```````
foo
bar
```````
````````````````````````````````
````````````````````````````````{panels}
```````
foo\
bar
```````
---
```````
foo
bar
```````
````````````````````````````````
Hard line breaks can occur inside emphasis, links, and other constructs
that allow inline content:
````````````````````````````````{panels}
```````
*foo
bar*
```````
---
```````
foo
bar
```````
````````````````````````````````
````````````````````````````````{panels}
```````
*foo\
bar*
```````
---
```````
foo
bar
```````
````````````````````````````````
Hard line breaks do not occur inside code spans
````````````````````````````````{panels}
```````
`code
span`
```````
---
```````
code span
````````````````````````````````
````````````````````````````````{panels}
```````
`code\
span`
```````
---
```````
code\ span
```````
````````````````````````````````
or HTML tags:
````````````````````````````````{panels}
```````
```````
---
```````
```````
````````````````````````````````
````````````````````````````````{panels}
```````
```````
---
```````
```````
````````````````````````````````
Hard line breaks are for separating inline content within a block.
Neither syntax for hard line breaks works at the end of a paragraph or
other block element:
````````````````````````````````{panels}
```````
foo\
```````
---
```````
foo\
```````
````````````````````````````````
````````````````````````````````{panels}
```````
foo
```````
---
```````
foo
```````
````````````````````````````````
````````````````````````````````{panels}
```````
### foo\
```````
---
```````
foo\
```````
````````````````````````````````
````````````````````````````````{panels}
```````
### foo
```````
---
```````
foo
```````
````````````````````````````````
## Soft line breaks
A regular line ending (not in a code span or HTML tag) that is not
preceded by two or more spaces or a backslash is parsed as a
[softbreak](#@). (A soft line break may be rendered in HTML either as a
[line ending] or as a space. The result will be the same in
browsers. In the{panels}s here, a [line ending] will be used.)
````````````````````````````````{panels}
```````
foo
baz
```````
---
```````
foo
baz
```````
````````````````````````````````
Spaces at the end of the line and beginning of the next line are
removed:
````````````````````````````````{panels}
```````
foo
baz
```````
---
```````
foo
baz
```````
````````````````````````````````
A conforming parser may render a soft line break in HTML either as a
line ending or as a space.
A renderer may also provide an option to render soft line breaks
as hard line breaks.
## Textual content
Any characters not given an interpretation by the above rules will
be parsed as plain textual content.
````````````````````````````````{panels}
```````
hello $.;'there
```````
---
```````
hello $.;'there
```````
````````````````````````````````
````````````````````````````````{panels}
```````
Foo χρῆν
```````
---
```````
Foo χρῆν
```````
````````````````````````````````
Internal spaces are preserved verbatim:
````````````````````````````````{panels}
```````
Multiple spaces
```````
---
```````
Multiple spaces
```````
````````````````````````````````