spec.txt   spec.txt 
--- ---
title: CommonMark Spec title: CommonMark Spec
author: author:
- John MacFarlane - John MacFarlane
version: 0.14 version: 0.15
date: 2014-12-10 date: 2014-12-31
license: '[CC-BY-SA 4.0](http://creativecommons.org/licenses/by-sa/4.0/)' license: '[CC-BY-SA 4.0](http://creativecommons.org/licenses/by-sa/4.0/)'
... ...
# Introduction # Introduction
## What is Markdown? ## What is Markdown?
Markdown is a plain text format for writing structured documents, Markdown is a plain text format for writing structured documents,
based on conventions used for indicating formatting in email and based on conventions used for indicating formatting in email and
usenet posts. It was developed in 2004 by John Gruber, who wrote usenet posts. It was developed in 2004 by John Gruber, who wrote
skipping to change at line 4440 skipping to change at line 4440
``` ```
The rules given below capture all of these patterns, while allowing The rules given below capture all of these patterns, while allowing
for efficient parsing strategies that do not backtrack. for efficient parsing strategies that do not backtrack.
First, some definitions. A [delimiter run](@delimiter-run) is either First, some definitions. A [delimiter run](@delimiter-run) is either
a sequence of one or more `*` characters that is not preceded or a sequence of one or more `*` characters that is not preceded or
followed by a `*` character, or a sequence of one or more `_` followed by a `*` character, or a sequence of one or more `_`
characters that is not preceded or followed by a `_` character. characters that is not preceded or followed by a `_` character.
A [left-flanking delimiter run](@right-facing-delimiter-run) is A [left-flanking delimiter run](@left-flanking-delimiter-run) is
a [delimiter run](#delimiter-run) that is (a) not followed by [unicode a [delimiter run](#delimiter-run) that is (a) not followed by [unicode
whitespace](#unicode-whitespace), and (b) either not followed by a whitespace](#unicode-whitespace), and (b) either not followed by a
[punctuation character](#punctuation-character), or [punctuation character](#punctuation-character), or
preceded by [unicode whitespace](#unicode-whitespace) or preceded by [unicode whitespace](#unicode-whitespace) or
a [punctuation character](#punctuation-character). a [punctuation character](#punctuation-character).
A [right-flanking delimiter run](@left-facing-delimiter-run) is A [right-flanking delimiter run](@right-flanking-delimiter-run) is
a [delimiter run](#delimiter-run) that is (a) not preceded by [unicode a [delimiter run](#delimiter-run) that is (a) not preceded by [unicode
whitespace](#unicode-whitespace), and (b) either not preceded by a whitespace](#unicode-whitespace), and (b) either not preceded by a
[punctuation character](#punctuation-character), or [punctuation character](#punctuation-character), or
followed by [unicode whitespace](#unicode-whitespace) or followed by [unicode whitespace](#unicode-whitespace) or
a [punctuation character](#punctuation-character). a [punctuation character](#punctuation-character).
Here are some examples of delimiter runs. Here are some examples of delimiter runs.
- left-flanking but not right-flanking: - left-flanking but not right-flanking:
skipping to change at line 4500 skipping to change at line 4500
after comes from Roopesh Chander's after comes from Roopesh Chander's
[vfmd](http://www.vfmd.org/vfmd-spec/specification/#procedure-for-identifying-em phasis-tags). [vfmd](http://www.vfmd.org/vfmd-spec/specification/#procedure-for-identifying-em phasis-tags).
vfmd uses the terminology "emphasis indicator string" instead of "delimiter vfmd uses the terminology "emphasis indicator string" instead of "delimiter
run," and its rules for distinguishing left- and right-flanking runs run," and its rules for distinguishing left- and right-flanking runs
are a bit more complex than the ones given here.) are a bit more complex than the ones given here.)
The following rules define emphasis and strong emphasis: The following rules define emphasis and strong emphasis:
1. A single `*` character [can open emphasis](@can-open-emphasis) 1. A single `*` character [can open emphasis](@can-open-emphasis)
iff it is part of a iff it is part of a
[left-flanking delimiter run](#right-facing-delimiter-run). [left-flanking delimiter run](#left-flanking-delimiter-run).
2. A single `_` character [can open emphasis](#can-open-emphasis) iff 2. A single `_` character [can open emphasis](#can-open-emphasis) iff
it is part of a it is part of a
[left-flanking delimiter run](#right-facing-delimiter-run) [left-flanking delimiter run](#left-flanking-delimiter-run)
and is not preceded by an ASCII alphanumeric character. and is not preceded by an ASCII alphanumeric character.
3. A single `*` character [can close emphasis](@can-close-emphasis) 3. A single `*` character [can close emphasis](@can-close-emphasis)
iff it is part of a iff it is part of a
[left-flanking delimiter run](#right-facing-delimiter-run). [right-flanking delimiter run](#right-flanking-delimiter-run).
4. A single `_` character [can close emphasis](#can-close-emphasis) 4. A single `_` character [can close emphasis](#can-close-emphasis)
iff it is part of a iff it is part of a
[left-flanking delimiter run](#right-facing-delimiter-run). [right-flanking delimiter run](#right-flanking-delimiter-run).
and it is not followed by an ASCII alphanumeric character. and it is not followed by an ASCII alphanumeric character.
5. A double `**` [can open strong emphasis](@can-open-strong-emphasis) 5. A double `**` [can open strong emphasis](@can-open-strong-emphasis)
iff it is part of a iff it is part of a
[left-flanking delimiter run](#right-facing-delimiter-run). [left-flanking delimiter run](#left-flanking-delimiter-run).
6. A double `__` [can open strong emphasis](#can-open-strong-emphasis) 6. A double `__` [can open strong emphasis](#can-open-strong-emphasis)
iff it is part of a iff it is part of a
[left-flanking delimiter run](#right-facing-delimiter-run) [left-flanking delimiter run](#left-flanking-delimiter-run)
and is not preceded by an ASCII alphanumeric character. and is not preceded by an ASCII alphanumeric character.
7. A double `**` [can close strong emphasis](@can-close-strong-emphasis) 7. A double `**` [can close strong emphasis](@can-close-strong-emphasis)
iff it is part of a iff it is part of a
[right-flanking delimiter run](#right-facing-delimiter-run). [right-flanking delimiter run](#right-flanking-delimiter-run).
8. A double `__` [can close strong emphasis](#can-close-strong-emphasis) 8. A double `__` [can close strong emphasis](#can-close-strong-emphasis)
iff it is part of a iff it is part of a
[right-flanking delimiter run](#right-facing-delimiter-run). [right-flanking delimiter run](#right-flanking-delimiter-run).
and is not followed by an ASCII alphanumeric character. and is not followed by an ASCII alphanumeric character.
9. Emphasis begins with a delimiter that [can open 9. Emphasis begins with a delimiter that [can open
emphasis](#can-open-emphasis) and ends with a delimiter that [can close emphasis](#can-open-emphasis) and ends with a delimiter that [can close
emphasis](#can-close-emphasis), and that uses the same emphasis](#can-close-emphasis), and that uses the same
character (`_` or `*`) as the opening delimiter. There must character (`_` or `*`) as the opening delimiter. There must
be a nonempty sequence of inlines between the open delimiter be a nonempty sequence of inlines between the open delimiter
and the closing delimiter; these form the contents of the emphasis and the closing delimiter; these form the contents of the emphasis
inline. inline.
skipping to change at line 4601 skipping to change at line 4601
Rule 1: Rule 1:
. .
*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 This is not emphasis, because the opening `*` is followed by
whitespace, and hence not part of a [left-flanking delimiter whitespace, and hence not part of a [left-flanking delimiter
run](#right-facing-delimiter-run): run](#left-flanking-delimiter-run):
. .
a * foo bar* a * foo bar*
. .
<p>a * foo bar*</p> <p>a * foo bar*</p>
. .
This is not emphasis, because the opening `*` is preceded This is not emphasis, because the opening `*` is preceded
by an alphanumeric and followed by punctuation, and hence by an alphanumeric and followed by punctuation, and hence
not part of a [left-flanking delimiter run](#right-facing-delimiter-run): not part of a [left-flanking delimiter run](#left-flanking-delimiter-run):
. .
a*"foo"* a*"foo"*
. .
<p>a*&quot;foo&quot;*</p> <p>a*&quot;foo&quot;*</p>
. .
Unicode nonbreaking spaces count as whitespace, too: Unicode nonbreaking spaces count as whitespace, too:
. .
skipping to change at line 4712 skipping to change at line 4712
. .
*foo bar * *foo bar *
. .
<p>*foo bar *</p> <p>*foo bar *</p>
. .
This is not emphasis, because the second `*` is This is not emphasis, because the second `*` is
preceded by punctuation and followed by an alphanumeric preceded by punctuation and followed by an alphanumeric
(hence it is not part of a [right-flanking delimiter (hence it is not part of a [right-flanking delimiter
run](#left-facing-delimiter-run): run](#right-flanking-delimiter-run):
. .
*(*foo) *(*foo)
. .
<p>*(*foo)</p> <p>*(*foo)</p>
. .
The point of this restriction is more easily appreciated The point of this restriction is more easily appreciated
with this example: with this example:
skipping to change at line 4804 skipping to change at line 4804
followed by whitespace: followed by whitespace:
. .
** foo bar** ** foo bar**
. .
<p>** foo bar**</p> <p>** foo bar**</p>
. .
This is not strong emphasis, because the opening `**` is preceded This is not strong emphasis, because the opening `**` is preceded
by an alphanumeric and followed by punctuation, and hence by an alphanumeric and followed by punctuation, and hence
not part of a [left-flanking delimiter run](#right-facing-delimiter-run): not part of a [left-flanking delimiter run](#left-flanking-delimiter-run):
. .
a**"foo"** a**"foo"**
. .
<p>a**&quot;foo&quot;**</p> <p>a**&quot;foo&quot;**</p>
. .
Intraword strong emphasis with `**` is permitted: Intraword strong emphasis with `**` is permitted:
. .
 End of changes. 15 change blocks. 
16 lines changed or deleted 16 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/