Skip to content

Instantly share code, notes, and snippets.

@mb21
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mb21/2df5137d0eb5388a20af to your computer and use it in GitHub Desktop.
Save mb21/2df5137d0eb5388a20af to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>CommonMark Spec</title>
<style type="text/css">
body { font-family: Helvetica, arial, freesans, clean, sans-serif;
line-height: 1.4;
max-width: 48em;
margin: auto;
color: #333333;
background-color: #fff;
font-size: 13pt;
}
div#TOC ul { list-style: none; }
h1 { font-size: 140%; font-weight: bold; border-top: 1px solid gray; padding-top: 0.5em; }
h2 { font-size: 120%; font-weight: bold; }
h3 { font-size: 110%; font-weight: bold; }
h4 { font-size: 100%; font-weight: bold; }
span.space { position: relative; }
span.space:after {
content: "";
position: absolute;
/* create a mark that indicates a space (trick from D. Greenspan) */
top: 3px; bottom: 3px; left: 1px; right: 1px;
border: 1px solid #999;
}
div.example { overflow: hidden; }
p { text-align: justify; }
pre { padding: 0.5em; margin-left: 0; margin-right: 0; margin-top: 0.2em;
margin-bottom: 0.5em; font-size: 88%; }
pre {
white-space: pre-wrap; /* css-3 */
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
word-wrap: break-word; /* Internet Explorer 5.5+ */
}
code { font-family: monospace; }
div.example > pre { float:left; width: 48%; }
div.example > pre.markdown { clear:left; }
pre.tree { font-weight: bold; color: #777; }
pre.markdown { background-color: #D3E1E4; }
pre.html { background-color: #C9CaCE; }
pre.html span.space:after {
border: 1px solid #666;
}
div.examplenum { font-size: 82%; text-align: left; }
a.footnoteRef > sup:before {
content: "[";
}
a.footnoteRef > sup:after {
content: "]";
}
a.footnoteRef > sup {
vertical-align: baseline;
font-size: 100%;
}
</style>
</head>
<body>
<h1 class="title">CommonMark Spec</h1>
<div class="version">Version 1 (2014-09-06)</div>
<div class="authors">
<span class="author">John MacFarlane</span>
</div>
<div id="TOC">
<ul>
<li><a href="#introduction"><span class="toc-section-number">1</span> Introduction</a><ul>
<li><a href="#what-is-markdown"><span class="toc-section-number">1.1</span> What is Markdown?</a></li>
<li><a href="#why-is-a-spec-needed"><span class="toc-section-number">1.2</span> Why is a spec needed?</a></li>
<li><a href="#about-this-document"><span class="toc-section-number">1.3</span> About this document</a></li>
</ul></li>
<li><a href="#preprocessing"><span class="toc-section-number">2</span> Preprocessing</a></li>
<li><a href="#blocks-and-inlines"><span class="toc-section-number">3</span> Blocks and inlines</a><ul>
<li><a href="#precedence"><span class="toc-section-number">3.1</span> Precedence</a></li>
<li><a href="#container-blocks-and-leaf-blocks"><span class="toc-section-number">3.2</span> Container blocks and leaf blocks</a></li>
</ul></li>
<li><a href="#leaf-blocks"><span class="toc-section-number">4</span> Leaf blocks</a><ul>
<li><a href="#horizontal-rules"><span class="toc-section-number">4.1</span> Horizontal rules</a></li>
<li><a href="#atx-headers"><span class="toc-section-number">4.2</span> ATX headers</a></li>
<li><a href="#setext-headers"><span class="toc-section-number">4.3</span> Setext headers</a></li>
<li><a href="#indented-code-blocks"><span class="toc-section-number">4.4</span> Indented code blocks</a></li>
<li><a href="#fenced-code-blocks"><span class="toc-section-number">4.5</span> Fenced code blocks</a></li>
<li><a href="#html-blocks"><span class="toc-section-number">4.6</span> HTML blocks</a></li>
<li><a href="#link-reference-definitions"><span class="toc-section-number">4.7</span> Link reference definitions</a></li>
<li><a href="#paragraphs"><span class="toc-section-number">4.8</span> Paragraphs</a></li>
<li><a href="#blank-lines"><span class="toc-section-number">4.9</span> Blank lines</a></li>
</ul></li>
<li><a href="#container-blocks"><span class="toc-section-number">5</span> Container blocks</a><ul>
<li><a href="#block-quotes"><span class="toc-section-number">5.1</span> Block quotes</a></li>
<li><a href="#list-items"><span class="toc-section-number">5.2</span> List items</a><ul>
<li><a href="#motivation"><span class="toc-section-number">5.2.1</span> Motivation</a></li>
</ul></li>
<li><a href="#lists"><span class="toc-section-number">5.3</span> Lists</a></li>
</ul></li>
<li><a href="#inlines"><span class="toc-section-number">6</span> Inlines</a><ul>
<li><a href="#backslash-escapes"><span class="toc-section-number">6.1</span> Backslash escapes</a></li>
<li><a href="#entities"><span class="toc-section-number">6.2</span> Entities</a></li>
<li><a href="#code-span"><span class="toc-section-number">6.3</span> Code span</a></li>
<li><a href="#emphasis-and-strong-emphasis"><span class="toc-section-number">6.4</span> Emphasis and strong emphasis</a></li>
<li><a href="#links"><span class="toc-section-number">6.5</span> Links</a></li>
<li><a href="#images"><span class="toc-section-number">6.6</span> Images</a></li>
<li><a href="#autolinks"><span class="toc-section-number">6.7</span> Autolinks</a></li>
<li><a href="#raw-html"><span class="toc-section-number">6.8</span> Raw HTML</a></li>
<li><a href="#hard-line-breaks"><span class="toc-section-number">6.9</span> Hard line breaks</a></li>
<li><a href="#soft-line-breaks"><span class="toc-section-number">6.10</span> Soft line breaks</a></li>
<li><a href="#strings"><span class="toc-section-number">6.11</span> Strings</a></li>
</ul></li>
<li><a href="#extensions"><span class="toc-section-number">7</span> Extensions</a><ul>
<li><a href="#attributes"><span class="toc-section-number">7.1</span> Attributes</a><ul>
<li><a href="#horizontal-rules-1"><span class="toc-section-number">7.1.1</span> Horizontal rules</a></li>
<li><a href="#atx-headers-1"><span class="toc-section-number">7.1.2</span> ATX headers</a></li>
<li><a href="#setext-headers-1"><span class="toc-section-number">7.1.3</span> Setext headers</a></li>
<li><a href="#fenced-code-blocks-1"><span class="toc-section-number">7.1.4</span> Fenced code blocks</a></li>
<li><a href="#reference-links"><span class="toc-section-number">7.1.5</span> Reference Links</a></li>
<li><a href="#paragraphs-1"><span class="toc-section-number">7.1.6</span> Paragraphs</a></li>
<li><a href="#block-quotes-1"><span class="toc-section-number">7.1.7</span> Block quotes</a></li>
<li><a href="#lists-1"><span class="toc-section-number">7.1.8</span> Lists</a></li>
<li><a href="#code-span-1"><span class="toc-section-number">7.1.9</span> Code span</a></li>
<li><a href="#emphasis-and-strong-emphasis-1"><span class="toc-section-number">7.1.10</span> Emphasis and strong emphasis</a></li>
<li><a href="#inline-links"><span class="toc-section-number">7.1.11</span> Inline Links</a></li>
<li><a href="#images-1"><span class="toc-section-number">7.1.12</span> Images</a></li>
<li><a href="#spans"><span class="toc-section-number">7.1.13</span> Spans</a></li>
</ul></li>
</ul></li>
<li><a href="#appendix-a-a-parsing-strategy">Appendix A: A parsing strategy</a><ul>
<li><a href="#overview">Overview</a></li>
<li><a href="#the-document-tree">The document tree</a></li>
<li><a href="#how-source-lines-alter-the-document-tree">How source lines alter the document tree</a></li>
<li><a href="#from-block-structure-to-the-final-document">From block structure to the final document</a></li>
</ul></li>
</ul>
</div>
<h1 id="introduction"><span class="header-section-number">1</span> Introduction</h1>
<h2 id="what-is-markdown"><span class="header-section-number">1.1</span> What is Markdown?</h2>
<p>Markdown is a plain text format for writing structured documents, based on conventions used for indicating formatting in email and usenet posts. It was developed in 2004 by John Gruber, who wrote the first Markdown-to-HTML converter in perl, and it soon became widely used in websites. By 2014 there were dozens of implementations in many languages. Some of them extended basic Markdown syntax with conventions for footnotes, definition lists, tables, and other constructs, and some allowed output not just in HTML but in LaTeX and many other formats.</p>
<h2 id="why-is-a-spec-needed"><span class="header-section-number">1.2</span> Why is a spec needed?</h2>
<p>John Gruber’s <a href="http://daringfireball.net/projects/markdown/syntax">canonical description of Markdown’s syntax</a> does not specify the syntax unambiguously. Here are some examples of questions it does not answer:</p>
<ol style="list-style-type: decimal">
<li><p>How much indentation is needed for a sublist? The spec says that continuation paragraphs need to be indented four spaces, but is not fully explicit about sublists. It is natural to think that they, too, must be indented four spaces, but <code>Markdown.pl</code> does not require that. This is hardly a “corner case,” and divergences between implementations on this issue often lead to surprises for users in real documents. (See <a href="http://article.gmane.org/gmane.text.markdown.general/1997">this comment by John Gruber</a>.)</p></li>
<li><p>Is a blank line needed before a block quote or header? Most implementations do not require the blank line. However, this can lead to unexpected results in hard-wrapped text, and also to ambiguities in parsing (note that some implementations put the header inside the blockquote, while others do not). (John Gruber has also spoken <a href="http://article.gmane.org/gmane.text.markdown.general/2146">in favor of requiring the blank lines</a>.)</p></li>
<li><p>Is a blank line needed before an indented code block? (<code>Markdown.pl</code> requires it, but this is not mentioned in the documentation, and some implementations do not require it.)</p>
<pre class="markdown"><code>paragraph
code?</code></pre></li>
<li><p>What is the exact rule for determining when list items get wrapped in <code>&lt;p&gt;</code> tags? Can a list be partially “loose” and partially “tight”? What should we do with a list like this?</p>
<pre class="markdown"><code>1. one
2. two
3. three</code></pre>
<p>Or this?</p>
<pre class="markdown"><code>1. one
- a
- b
2. two</code></pre>
<p>(There are some relevant comments by John Gruber <a href="http://article.gmane.org/gmane.text.markdown.general/2554">here</a>.)</p></li>
<li><p>Can list markers be indented? Can ordered list markers be right-aligned?</p>
<pre class="markdown"><code> 8. item 1
9. item 2
10. item 2a</code></pre></li>
<li><p>Is this one list with a horizontal rule in its second item, or two lists separated by a horizontal rule?</p>
<pre class="markdown"><code>* a
* * * * *
* b</code></pre></li>
<li><p>When list markers change from numbers to bullets, do we have two lists or one? (The Markdown syntax description suggests two, but the perl scripts and many other implementations produce one.)</p>
<pre class="markdown"><code>1. fee
2. fie
- foe
- fum</code></pre></li>
<li><p>What are the precedence rules for the markers of inline structure? For example, is the following a valid link, or does the code span take precedence ?</p>
<pre class="markdown"><code>[a backtick (`)](/url) and [another backtick (`)](/url).</code></pre></li>
<li><p>What are the precedence rules for markers of emphasis and strong emphasis? For example, how should the following be parsed?</p>
<pre class="markdown"><code>*foo *bar* baz*</code></pre></li>
<li><p>What are the precedence rules between block-level and inline-level structure? For example, how should the following be parsed?</p>
<pre class="markdown"><code>- `a long code span can contain a hyphen like this
- and it can screw things up`</code></pre></li>
<li><p>Can list items include headers? (<code>Markdown.pl</code> does not allow this, but headers can occur in blockquotes.)</p>
<pre class="markdown"><code>- # Heading</code></pre></li>
<li><p>Can link references be defined inside block quotes or list items?</p>
<pre class="markdown"><code>&gt; Blockquote [foo].
&gt;
&gt; [foo]: /url</code></pre></li>
<li><p>If there are multiple definitions for the same reference, which takes precedence?</p>
<pre class="markdown"><code>[foo]: /url1
[foo]: /url2
[foo][]</code></pre></li>
</ol>
<p>In the absence of a spec, early implementers consulted <code>Markdown.pl</code> to resolve these ambiguities. But <code>Markdown.pl</code> was quite buggy, and gave manifestly bad results in many cases, so it was not a satisfactory replacement for a spec.</p>
<p>Because there is no unambiguous spec, implementations have diverged considerably. As a result, users are often surprised to find that a document that renders one way on one system (say, a github wiki) renders differently on another (say, converting to docbook using pandoc). To make matters worse, because nothing in Markdown counts as a “syntax error,” the divergence often isn’t discovered right away.</p>
<h2 id="about-this-document"><span class="header-section-number">1.3</span> About this document</h2>
<p>This document attempts to specify Markdown syntax unambiguously. It contains many examples with side-by-side Markdown and HTML. These are intended to double as conformance tests. An accompanying script <code>runtests.pl</code> can be used to run the tests against any Markdown program:</p>
<pre><code>perl runtests.pl spec.txt PROGRAM</code></pre>
<p>Since this document describes how Markdown is to be parsed into an abstract syntax tree, it would have made sense to use an abstract representation of the syntax tree instead of HTML. But HTML is capable of representing the structural distinctions we need to make, and the choice of HTML for the tests makes it possible to run the tests against an implementation without writing an abstract syntax tree renderer.</p>
<p>This document is generated from a text file, <code>spec.txt</code>, written in Markdown with a small extension for the side-by-side tests. The script <code>spec2md.pl</code> can be used to turn <code>spec.txt</code> into pandoc Markdown, which can then be converted into other formats.</p>
<p>In the examples, the <code></code> character is used to represent tabs.</p>
<h1 id="preprocessing"><span class="header-section-number">2</span> Preprocessing</h1>
<p>A <a href="#line">line</a> <a id="line"></a> is a sequence of zero or more characters followed by a line ending (CR, LF, or CRLF) or by the end of file.</p>
<p>This spec does not specify an encoding; it thinks of lines as composed of characters rather than bytes. A conforming parser may be limited to a certain encoding.</p>
<p>Tabs in lines are expanded to spaces, with a tab stop of 4 characters:</p>
<div id="example-1" class="example" data-section="Preprocessing">
<div class="examplenum">
Example 1
</div>
<pre class="markdown"><code>→foo→baz→→bim</code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code&gt;foo baz bim
&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<div id="example-2" class="example" data-section="Preprocessing">
<div class="examplenum">
Example 2
</div>
<pre class="markdown"><code> a→a
ὐ→a</code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code&gt;a a
ὐ a
&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<p>Line endings are replaced by newline characters (LF).</p>
<p>A line containing no characters, or a line containing only spaces (after tab expansion), is called a <a href="#blank-line">blank line</a>. <a id="blank-line"></a></p>
<h1 id="blocks-and-inlines"><span class="header-section-number">3</span> Blocks and inlines</h1>
<p>We can think of a document as a sequence of <a href="#block">blocks</a><a
id="block"></a>—structural elements like paragraphs, block quotations, lists, headers, rules, and code blocks. Blocks can contain other blocks, or they can contain <a href="#inline">inline</a><a id="inline"></a> content: words, spaces, links, emphasized text, images, and inline code.</p>
<h2 id="precedence"><span class="header-section-number">3.1</span> Precedence</h2>
<p>Indicators of block structure always take precedence over indicators of inline structure. So, for example, the following is a list with two items, not a list with one item containing a code span:</p>
<div id="example-3" class="example" data-section="Precedence">
<div class="examplenum">
Example 3
</div>
<pre class="markdown"><code>- `one
- two`</code></pre>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;`one&lt;/li&gt;
&lt;li&gt;two`&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
<p>This means that parsing can proceed in two steps: first, the block structure of the document can be discerned; second, text lines inside paragraphs, headers, and other block constructs can be parsed for inline structure. The second step requires information about link reference definitions that will be available only at the end of the first step. Note that the first step requires processing lines in sequence, but the second can be parallelized, since the inline parsing of one block element does not affect the inline parsing of any other.</p>
<h2 id="container-blocks-and-leaf-blocks"><span class="header-section-number">3.2</span> Container blocks and leaf blocks</h2>
<p>We can divide blocks into two types: <a href="#container-block">container blocks</a>, <a id="container-block"></a> which can contain other blocks, and <a href="#leaf-block">leaf blocks</a>, <a id="leaf-block"></a> which cannot.</p>
<h1 id="leaf-blocks"><span class="header-section-number">4</span> Leaf blocks</h1>
<p>This section describes the different kinds of leaf block that make up a Markdown document.</p>
<h2 id="horizontal-rules"><span class="header-section-number">4.1</span> Horizontal rules</h2>
<p>A line consisting of 0-3 spaces of indentation, followed by a sequence of three or more matching <code>-</code>, <code>_</code>, or <code>*</code> characters, each followed optionally by any number of spaces, forms a <a href="#horizontal-rule">horizontal rule</a>. <a id="horizontal-rule"></a></p>
<div id="example-4" class="example" data-section="Horizontal rules">
<div class="examplenum">
Example 4
</div>
<pre class="markdown"><code>***
---
___</code></pre>
<pre class="html"><code>&lt;hr /&gt;
&lt;hr /&gt;
&lt;hr /&gt;</code></pre>
</div>
<p>Wrong characters:</p>
<div id="example-5" class="example" data-section="Horizontal rules">
<div class="examplenum">
Example 5
</div>
<pre class="markdown"><code>+++</code></pre>
<pre class="html"><code>&lt;p&gt;+++&lt;/p&gt;</code></pre>
</div>
<div id="example-6" class="example" data-section="Horizontal rules">
<div class="examplenum">
Example 6
</div>
<pre class="markdown"><code>===</code></pre>
<pre class="html"><code>&lt;p&gt;===&lt;/p&gt;</code></pre>
</div>
<p>Not enough characters:</p>
<div id="example-7" class="example" data-section="Horizontal rules">
<div class="examplenum">
Example 7
</div>
<pre class="markdown"><code>--
**
__</code></pre>
<pre class="html"><code>&lt;p&gt;--
**
__&lt;/p&gt;</code></pre>
</div>
<p>One to three spaces indent are allowed:</p>
<div id="example-8" class="example" data-section="Horizontal rules">
<div class="examplenum">
Example 8
</div>
<pre class="markdown"><code> ***
***
***</code></pre>
<pre class="html"><code>&lt;hr /&gt;
&lt;hr /&gt;
&lt;hr /&gt;</code></pre>
</div>
<p>Four spaces is too many:</p>
<div id="example-9" class="example" data-section="Horizontal rules">
<div class="examplenum">
Example 9
</div>
<pre class="markdown"><code> ***</code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code&gt;***
&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<div id="example-10" class="example" data-section="Horizontal rules">
<div class="examplenum">
Example 10
</div>
<pre class="markdown"><code>Foo
***</code></pre>
<pre class="html"><code>&lt;p&gt;Foo
***&lt;/p&gt;</code></pre>
</div>
<p>More than three characters may be used:</p>
<div id="example-11" class="example" data-section="Horizontal rules">
<div class="examplenum">
Example 11
</div>
<pre class="markdown"><code>_____________________________________</code></pre>
<pre class="html"><code>&lt;hr /&gt;</code></pre>
</div>
<p>Spaces are allowed between the characters:</p>
<div id="example-12" class="example" data-section="Horizontal rules">
<div class="examplenum">
Example 12
</div>
<pre class="markdown"><code> - - -</code></pre>
<pre class="html"><code>&lt;hr /&gt;</code></pre>
</div>
<div id="example-13" class="example" data-section="Horizontal rules">
<div class="examplenum">
Example 13
</div>
<pre class="markdown"><code> ** * ** * ** * **</code></pre>
<pre class="html"><code>&lt;hr /&gt;</code></pre>
</div>
<div id="example-14" class="example" data-section="Horizontal rules">
<div class="examplenum">
Example 14
</div>
<pre class="markdown"><code>- - - -</code></pre>
<pre class="html"><code>&lt;hr /&gt;</code></pre>
</div>
<p>Spaces are allowed at the end:</p>
<div id="example-15" class="example" data-section="Horizontal rules">
<div class="examplenum">
Example 15
</div>
<pre class="markdown"><code>- - - - </code></pre>
<pre class="html"><code>&lt;hr /&gt;</code></pre>
</div>
<p>However, no other characters may occur at the end or the beginning:</p>
<div id="example-16" class="example" data-section="Horizontal rules">
<div class="examplenum">
Example 16
</div>
<pre class="markdown"><code>_ _ _ _ a
a------</code></pre>
<pre class="html"><code>&lt;p&gt;_ _ _ _ a&lt;/p&gt;
&lt;p&gt;a------&lt;/p&gt;</code></pre>
</div>
<p>It is required that all of the non-space characters be the same. So, this is not a horizontal rule:</p>
<div id="example-17" class="example" data-section="Horizontal rules">
<div class="examplenum">
Example 17
</div>
<pre class="markdown"><code> *-*</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;em&gt;-&lt;/em&gt;&lt;/p&gt;</code></pre>
</div>
<p>Horizontal rules do not need blank lines before or after:</p>
<div id="example-18" class="example" data-section="Horizontal rules">
<div class="examplenum">
Example 18
</div>
<pre class="markdown"><code>- foo
***
- bar</code></pre>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;foo&lt;/li&gt;
&lt;/ul&gt;
&lt;hr /&gt;
&lt;ul&gt;
&lt;li&gt;bar&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
<p>Horizontal rules can interrupt a paragraph:</p>
<div id="example-19" class="example" data-section="Horizontal rules">
<div class="examplenum">
Example 19
</div>
<pre class="markdown"><code>Foo
***
bar</code></pre>
<pre class="html"><code>&lt;p&gt;Foo&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;bar&lt;/p&gt;</code></pre>
</div>
<p>Note, however, that this is a setext header, not a paragraph followed by a horizontal rule:</p>
<div id="example-20" class="example" data-section="Horizontal rules">
<div class="examplenum">
Example 20
</div>
<pre class="markdown"><code>Foo
---
bar</code></pre>
<pre class="html"><code>&lt;h2&gt;Foo&lt;/h2&gt;
&lt;p&gt;bar&lt;/p&gt;</code></pre>
</div>
<p>When both a horizontal rule and a list item are possible interpretations of a line, the horizontal rule is preferred:</p>
<div id="example-21" class="example" data-section="Horizontal rules">
<div class="examplenum">
Example 21
</div>
<pre class="markdown"><code>* Foo
* * *
* Bar</code></pre>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;Foo&lt;/li&gt;
&lt;/ul&gt;
&lt;hr /&gt;
&lt;ul&gt;
&lt;li&gt;Bar&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
<p>If you want a horizontal rule in a list item, use a different bullet:</p>
<div id="example-22" class="example" data-section="Horizontal rules">
<div class="examplenum">
Example 22
</div>
<pre class="markdown"><code>- Foo
- * * *</code></pre>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;Foo&lt;/li&gt;
&lt;li&gt;&lt;hr /&gt;&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
<h2 id="atx-headers"><span class="header-section-number">4.2</span> ATX headers</h2>
<p>An <a href="#atx-header">ATX header</a> <a id="atx-header"></a> consists of a string of characters, parsed as inline content, between an opening sequence of 1–6 unescaped <code>#</code> characters and an optional closing sequence of any number of <code>#</code> characters. The opening sequence of <code>#</code> characters cannot be followed directly by a non-space character. The closing <code>#</code> characters may be followed by spaces only. The opening <code>#</code> character may be indented 0-3 spaces. The raw contents of the header are stripped of leading and trailing spaces before being parsed as inline content. The header level is equal to the number of <code>#</code> characters in the opening sequence.</p>
<p>Simple headers:</p>
<div id="example-23" class="example" data-section="ATX headers">
<div class="examplenum">
Example 23
</div>
<pre class="markdown"><code># foo
## foo
### foo
#### foo
##### foo
###### foo</code></pre>
<pre class="html"><code>&lt;h1&gt;foo&lt;/h1&gt;
&lt;h2&gt;foo&lt;/h2&gt;
&lt;h3&gt;foo&lt;/h3&gt;
&lt;h4&gt;foo&lt;/h4&gt;
&lt;h5&gt;foo&lt;/h5&gt;
&lt;h6&gt;foo&lt;/h6&gt;</code></pre>
</div>
<p>More than six <code>#</code> characters is not a header:</p>
<div id="example-24" class="example" data-section="ATX headers">
<div class="examplenum">
Example 24
</div>
<pre class="markdown"><code>####### foo</code></pre>
<pre class="html"><code>&lt;p&gt;####### foo&lt;/p&gt;</code></pre>
</div>
<p>A space is required between the <code>#</code> characters and the header’s contents. Note that many implementations currently do not require the space. However, the space was required by the <a href="http://www.aaronsw.com/2002/atx/atx.py">original ATX implementation</a>, and it helps prevent things like the following from being parsed as headers:</p>
<div id="example-25" class="example" data-section="ATX headers">
<div class="examplenum">
Example 25
</div>
<pre class="markdown"><code>#5 bolt</code></pre>
<pre class="html"><code>&lt;p&gt;#5 bolt&lt;/p&gt;</code></pre>
</div>
<p>This is not a header, because the first <code>#</code> is escaped:</p>
<div id="example-26" class="example" data-section="ATX headers">
<div class="examplenum">
Example 26
</div>
<pre class="markdown"><code>\## foo</code></pre>
<pre class="html"><code>&lt;p&gt;## foo&lt;/p&gt;</code></pre>
</div>
<p>Contents are parsed as inlines:</p>
<div id="example-27" class="example" data-section="ATX headers">
<div class="examplenum">
Example 27
</div>
<pre class="markdown"><code># foo *bar* \*baz\*</code></pre>
<pre class="html"><code>&lt;h1&gt;foo &lt;em&gt;bar&lt;/em&gt; *baz*&lt;/h1&gt;</code></pre>
</div>
<p>Leading and trailing blanks are ignored in parsing inline content:</p>
<div id="example-28" class="example" data-section="ATX headers">
<div class="examplenum">
Example 28
</div>
<pre class="markdown"><code># foo </code></pre>
<pre class="html"><code>&lt;h1&gt;foo&lt;/h1&gt;</code></pre>
</div>
<p>One to three spaces indentation are allowed:</p>
<div id="example-29" class="example" data-section="ATX headers">
<div class="examplenum">
Example 29
</div>
<pre class="markdown"><code> ### foo
## foo
# foo</code></pre>
<pre class="html"><code>&lt;h3&gt;foo&lt;/h3&gt;
&lt;h2&gt;foo&lt;/h2&gt;
&lt;h1&gt;foo&lt;/h1&gt;</code></pre>
</div>
<p>Four spaces are too much:</p>
<div id="example-30" class="example" data-section="ATX headers">
<div class="examplenum">
Example 30
</div>
<pre class="markdown"><code> # foo</code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code&gt;# foo
&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<div id="example-31" class="example" data-section="ATX headers">
<div class="examplenum">
Example 31
</div>
<pre class="markdown"><code>foo
# bar</code></pre>
<pre class="html"><code>&lt;p&gt;foo
# bar&lt;/p&gt;</code></pre>
</div>
<p>A closing sequence of <code>#</code> characters is optional:</p>
<div id="example-32" class="example" data-section="ATX headers">
<div class="examplenum">
Example 32
</div>
<pre class="markdown"><code>## foo ##
### bar ###</code></pre>
<pre class="html"><code>&lt;h2&gt;foo&lt;/h2&gt;
&lt;h3&gt;bar&lt;/h3&gt;</code></pre>
</div>
<p>It need not be the same length as the opening sequence:</p>
<div id="example-33" class="example" data-section="ATX headers">
<div class="examplenum">
Example 33
</div>
<pre class="markdown"><code># foo ##################################
##### foo ##</code></pre>
<pre class="html"><code>&lt;h1&gt;foo&lt;/h1&gt;
&lt;h5&gt;foo&lt;/h5&gt;</code></pre>
</div>
<p>Spaces are allowed after the closing sequence:</p>
<div id="example-34" class="example" data-section="ATX headers">
<div class="examplenum">
Example 34
</div>
<pre class="markdown"><code>### foo ### </code></pre>
<pre class="html"><code>&lt;h3&gt;foo&lt;/h3&gt;</code></pre>
</div>
<p>A sequence of <code>#</code> characters with a non-space character following it is not a closing sequence, but counts as part of the contents of the header:</p>
<div id="example-35" class="example" data-section="ATX headers">
<div class="examplenum">
Example 35
</div>
<pre class="markdown"><code>### foo ### b</code></pre>
<pre class="html"><code>&lt;h3&gt;foo ### b&lt;/h3&gt;</code></pre>
</div>
<p>Backslash-escaped <code>#</code> characters do not count as part of the closing sequence:</p>
<div id="example-36" class="example" data-section="ATX headers">
<div class="examplenum">
Example 36
</div>
<pre class="markdown"><code>### foo \###
## foo \#\##
# foo \#</code></pre>
<pre class="html"><code>&lt;h3&gt;foo #&lt;/h3&gt;
&lt;h2&gt;foo ##&lt;/h2&gt;
&lt;h1&gt;foo #&lt;/h1&gt;</code></pre>
</div>
<p>ATX headers need not be separated from surrounding content by blank lines, and they can interrupt paragraphs:</p>
<div id="example-37" class="example" data-section="ATX headers">
<div class="examplenum">
Example 37
</div>
<pre class="markdown"><code>****
## foo
****</code></pre>
<pre class="html"><code>&lt;hr /&gt;
&lt;h2&gt;foo&lt;/h2&gt;
&lt;hr /&gt;</code></pre>
</div>
<div id="example-38" class="example" data-section="ATX headers">
<div class="examplenum">
Example 38
</div>
<pre class="markdown"><code>Foo bar
# baz
Bar foo</code></pre>
<pre class="html"><code>&lt;p&gt;Foo bar&lt;/p&gt;
&lt;h1&gt;baz&lt;/h1&gt;
&lt;p&gt;Bar foo&lt;/p&gt;</code></pre>
</div>
<p>ATX headers can be empty:</p>
<div id="example-39" class="example" data-section="ATX headers">
<div class="examplenum">
Example 39
</div>
<pre class="markdown"><code>##
#
### ###</code></pre>
<pre class="html"><code>&lt;h2&gt;&lt;/h2&gt;
&lt;h1&gt;&lt;/h1&gt;
&lt;h3&gt;&lt;/h3&gt;</code></pre>
</div>
<h2 id="setext-headers"><span class="header-section-number">4.3</span> Setext headers</h2>
<p>A <a href="#setext-header">setext header</a> <a id="setext-header"></a> consists of a line of text, containing at least one non-space character, with no more than 3 spaces indentation, followed by a <a href="#setext-header-underline">setext header underline</a>. A <a href="#setext-header-underline">setext header underline</a> <a id="setext-header-underline"></a> is a sequence of <code>=</code> characters or a sequence of <code>-</code> characters, with no more than 3 spaces indentation and any number of trailing spaces. The header is a level 1 header if <code>=</code> characters are used, and a level 2 header if <code>-</code> characters are used. The contents of the header are the result of parsing the first line as Markdown inline content.</p>
<p>In general, a setext header need not be preceded or followed by a blank line. However, it cannot interrupt a paragraph, so when a setext header comes after a paragraph, a blank line is needed between them.</p>
<p>Simple examples:</p>
<div id="example-40" class="example" data-section="Setext headers">
<div class="examplenum">
Example 40
</div>
<pre class="markdown"><code>Foo *bar*
=========
Foo *bar*
---------</code></pre>
<pre class="html"><code>&lt;h1&gt;Foo &lt;em&gt;bar&lt;/em&gt;&lt;/h1&gt;
&lt;h2&gt;Foo &lt;em&gt;bar&lt;/em&gt;&lt;/h2&gt;</code></pre>
</div>
<p>The underlining can be any length:</p>
<div id="example-41" class="example" data-section="Setext headers">
<div class="examplenum">
Example 41
</div>
<pre class="markdown"><code>Foo
-------------------------
Foo
=</code></pre>
<pre class="html"><code>&lt;h2&gt;Foo&lt;/h2&gt;
&lt;h1&gt;Foo&lt;/h1&gt;</code></pre>
</div>
<p>The header content can be indented up to three spaces, and need not line up with the underlining:</p>
<div id="example-42" class="example" data-section="Setext headers">
<div class="examplenum">
Example 42
</div>
<pre class="markdown"><code> Foo
---
Foo
-----
Foo
===</code></pre>
<pre class="html"><code>&lt;h2&gt;Foo&lt;/h2&gt;
&lt;h2&gt;Foo&lt;/h2&gt;
&lt;h1&gt;Foo&lt;/h1&gt;</code></pre>
</div>
<p>Four spaces indent is too much:</p>
<div id="example-43" class="example" data-section="Setext headers">
<div class="examplenum">
Example 43
</div>
<pre class="markdown"><code> Foo
---
Foo
---</code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code&gt;Foo
---
Foo
&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;</code></pre>
</div>
<p>The setext header underline can be indented up to three spaces, and may have trailing spaces:</p>
<div id="example-44" class="example" data-section="Setext headers">
<div class="examplenum">
Example 44
</div>
<pre class="markdown"><code>Foo
---- </code></pre>
<pre class="html"><code>&lt;h2&gt;Foo&lt;/h2&gt;</code></pre>
</div>
<p>Four spaces is too much:</p>
<div id="example-45" class="example" data-section="Setext headers">
<div class="examplenum">
Example 45
</div>
<pre class="markdown"><code>Foo
---</code></pre>
<pre class="html"><code>&lt;p&gt;Foo
---&lt;/p&gt;</code></pre>
</div>
<p>The setext header underline cannot contain internal spaces:</p>
<div id="example-46" class="example" data-section="Setext headers">
<div class="examplenum">
Example 46
</div>
<pre class="markdown"><code>Foo
= =
Foo
--- -</code></pre>
<pre class="html"><code>&lt;p&gt;Foo
= =&lt;/p&gt;
&lt;p&gt;Foo&lt;/p&gt;
&lt;hr /&gt;</code></pre>
</div>
<p>Trailing spaces in the content line do not cause a line break:</p>
<div id="example-47" class="example" data-section="Setext headers">
<div class="examplenum">
Example 47
</div>
<pre class="markdown"><code>Foo
-----</code></pre>
<pre class="html"><code>&lt;h2&gt;Foo&lt;/h2&gt;</code></pre>
</div>
<p>Nor does a backslash at the end:</p>
<div id="example-48" class="example" data-section="Setext headers">
<div class="examplenum">
Example 48
</div>
<pre class="markdown"><code>Foo\
----</code></pre>
<pre class="html"><code>&lt;h2&gt;Foo\&lt;/h2&gt;</code></pre>
</div>
<p>Since indicators of block structure take precedence over indicators of inline structure, the following are setext headers:</p>
<div id="example-49" class="example" data-section="Setext headers">
<div class="examplenum">
Example 49
</div>
<pre class="markdown"><code>`Foo
----
`
&lt;a title=&quot;a lot
---
of dashes&quot;/&gt;</code></pre>
<pre class="html"><code>&lt;h2&gt;`Foo&lt;/h2&gt;
&lt;p&gt;`&lt;/p&gt;
&lt;h2&gt;&amp;lt;a title=&amp;quot;a lot&lt;/h2&gt;
&lt;p&gt;of dashes&amp;quot;/&amp;gt;&lt;/p&gt;</code></pre>
</div>
<p>The setext header underline cannot be a lazy line:</p>
<div id="example-50" class="example" data-section="Setext headers">
<div class="examplenum">
Example 50
</div>
<pre class="markdown"><code>&gt; Foo
---</code></pre>
<pre class="html"><code>&lt;blockquote&gt;
&lt;p&gt;Foo&lt;/p&gt;
&lt;/blockquote&gt;
&lt;hr /&gt;</code></pre>
</div>
<p>A setext header cannot interrupt a paragraph:</p>
<div id="example-51" class="example" data-section="Setext headers">
<div class="examplenum">
Example 51
</div>
<pre class="markdown"><code>Foo
Bar
---
Foo
Bar
===</code></pre>
<pre class="html"><code>&lt;p&gt;Foo
Bar&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;Foo
Bar
===&lt;/p&gt;</code></pre>
</div>
<p>But in general a blank line is not required before or after:</p>
<div id="example-52" class="example" data-section="Setext headers">
<div class="examplenum">
Example 52
</div>
<pre class="markdown"><code>---
Foo
---
Bar
---
Baz</code></pre>
<pre class="html"><code>&lt;hr /&gt;
&lt;h2&gt;Foo&lt;/h2&gt;
&lt;h2&gt;Bar&lt;/h2&gt;
&lt;p&gt;Baz&lt;/p&gt;</code></pre>
</div>
<p>Setext headers cannot be empty:</p>
<div id="example-53" class="example" data-section="Setext headers">
<div class="examplenum">
Example 53
</div>
<pre class="markdown"><code>
====</code></pre>
<pre class="html"><code>&lt;p&gt;====&lt;/p&gt;</code></pre>
</div>
<h2 id="indented-code-blocks"><span class="header-section-number">4.4</span> Indented code blocks</h2>
<p>An <a href="#indented-code-block">indented code block</a> <a id="indented-code-block"></a> is composed of one or more <a href="#indented-chunk">indented chunks</a> separated by blank lines. An <a href="#indented-chunk">indented chunk</a> <a id="indented-chunk"></a> is a sequence of non-blank lines, each indented four or more spaces. An indented code block cannot interrupt a paragraph, so if it occurs before or after a paragraph, there must be an intervening blank line. The contents of the code block are the literal contents of the lines, including trailing newlines, minus four spaces of indentation. An indented code block has no attributes.</p>
<div id="example-54" class="example" data-section="Indented code blocks">
<div class="examplenum">
Example 54
</div>
<pre class="markdown"><code> a simple
indented code block</code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code&gt;a simple
indented code block
&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<p>The contents are literal text, and do not get parsed as Markdown:</p>
<div id="example-55" class="example" data-section="Indented code blocks">
<div class="examplenum">
Example 55
</div>
<pre class="markdown"><code> &lt;a/&gt;
*hi*
- one</code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code&gt;&amp;lt;a/&amp;gt;
*hi*
- one
&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<p>Here we have three chunks separated by blank lines:</p>
<div id="example-56" class="example" data-section="Indented code blocks">
<div class="examplenum">
Example 56
</div>
<pre class="markdown"><code> chunk1
chunk2
chunk3</code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code&gt;chunk1
chunk2
chunk3
&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<p>Any initial spaces beyond four will be included in the content, even in interior blank lines:</p>
<div id="example-57" class="example" data-section="Indented code blocks">
<div class="examplenum">
Example 57
</div>
<pre class="markdown"><code> chunk1
chunk2</code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code&gt;chunk1
chunk2
&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<p>An indented code block cannot interrupt a paragraph. (This allows hanging indents and the like.)</p>
<div id="example-58" class="example" data-section="Indented code blocks">
<div class="examplenum">
Example 58
</div>
<pre class="markdown"><code>Foo
bar
</code></pre>
<pre class="html"><code>&lt;p&gt;Foo
bar&lt;/p&gt;</code></pre>
</div>
<p>However, any non-blank line with fewer than four leading spaces ends the code block immediately. So a paragraph may occur immediately after indented code:</p>
<div id="example-59" class="example" data-section="Indented code blocks">
<div class="examplenum">
Example 59
</div>
<pre class="markdown"><code> foo
bar</code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code&gt;foo
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;bar&lt;/p&gt;</code></pre>
</div>
<p>And indented code can occur immediately before and after other kinds of blocks:</p>
<div id="example-60" class="example" data-section="Indented code blocks">
<div class="examplenum">
Example 60
</div>
<pre class="markdown"><code># Header
foo
Header
------
foo
----</code></pre>
<pre class="html"><code>&lt;h1&gt;Header&lt;/h1&gt;
&lt;pre&gt;&lt;code&gt;foo
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Header&lt;/h2&gt;
&lt;pre&gt;&lt;code&gt;foo
&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;</code></pre>
</div>
<p>The first line can be indented more than four spaces:</p>
<div id="example-61" class="example" data-section="Indented code blocks">
<div class="examplenum">
Example 61
</div>
<pre class="markdown"><code> foo
bar</code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code&gt; foo
bar
&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<p>Blank lines preceding or following an indented code block are not included in it:</p>
<div id="example-62" class="example" data-section="Indented code blocks">
<div class="examplenum">
Example 62
</div>
<pre class="markdown"><code>
foo
</code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code&gt;foo
&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<p>Trailing spaces are included in the code block’s content:</p>
<div id="example-63" class="example" data-section="Indented code blocks">
<div class="examplenum">
Example 63
</div>
<pre class="markdown"><code> foo </code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code&gt;foo
&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<h2 id="fenced-code-blocks"><span class="header-section-number">4.5</span> Fenced code blocks</h2>
<p>A <a href="#code-fence">code fence</a> <a id="code-fence"></a> is a sequence of at least three consecutive backtick characters (<code>`</code>) or tildes (<code>~</code>). (Tildes and backticks cannot be mixed.) A <a href="#fenced-code-block">fenced code block</a> <a id="fenced-code-block"></a> begins with a code fence, indented no more than three spaces.</p>
<p>The line with the opening code fence may optionally contain some text following the code fence; this is trimmed of leading and trailing spaces and called the <a href="#info-string">info string</a>. <a id="info-string"></a> The info string may not contain any backtick characters. (The reason for this restriction is that otherwise some inline code would be incorrectly interpreted as the beginning of a fenced code block.)</p>
<p>The content of the code block consists of all subsequent lines, until a closing <a href="#code-fence">code fence</a> of the same type as the code block began with (backticks or tildes), and with at least as many backticks or tildes as the opening code fence. If the leading code fence is indented N spaces, then up to N spaces of indentation are removed from each line of the content (if present). (If a content line is not indented, it is preserved unchanged. If it is indented less than N spaces, all of the indentation is removed.)</p>
<p>The closing code fence may be indented up to three spaces, and may be followed only by spaces, which are ignored. If the end of the containing block (or document) is reached and no closing code fence has been found, the code block contains all of the lines after the opening code fence until the end of the containing block (or document). (An alternative spec would require backtracking in the event that a closing code fence is not found. But this makes parsing much less efficient, and there seems to be no real down side to the behavior described here.)</p>
<p>A fenced code block may interrupt a paragraph, and does not require a blank line either before or after.</p>
<p>The content of a code fence is treated as literal text, not parsed as inlines. The first word of the info string is typically used to specify the language of the code sample, and rendered in the <code>class</code> attribute of the <code>code</code> tag. However, this spec does not mandate any particular treatment of the info string.</p>
<p>Here is a simple example with backticks:</p>
<div id="example-64" class="example" data-section="Fenced code blocks">
<div class="examplenum">
Example 64
</div>
<pre class="markdown"><code>```
&lt;
&gt;
```</code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code&gt;&amp;lt;
&amp;gt;
&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<p>With tildes:</p>
<div id="example-65" class="example" data-section="Fenced code blocks">
<div class="examplenum">
Example 65
</div>
<pre class="markdown"><code>~~~
&lt;
&gt;
~~~</code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code&gt;&amp;lt;
&amp;gt;
&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<p>The closing code fence must use the same character as the opening fence:</p>
<div id="example-66" class="example" data-section="Fenced code blocks">
<div class="examplenum">
Example 66
</div>
<pre class="markdown"><code>```
aaa
~~~
```</code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code&gt;aaa
~~~
&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<div id="example-67" class="example" data-section="Fenced code blocks">
<div class="examplenum">
Example 67
</div>
<pre class="markdown"><code>~~~
aaa
```
~~~</code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code&gt;aaa
```
&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<p>The closing code fence must be at least as long as the opening fence:</p>
<div id="example-68" class="example" data-section="Fenced code blocks">
<div class="examplenum">
Example 68
</div>
<pre class="markdown"><code>````
aaa
```
``````</code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code&gt;aaa
```
&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<div id="example-69" class="example" data-section="Fenced code blocks">
<div class="examplenum">
Example 69
</div>
<pre class="markdown"><code>~~~~
aaa
~~~
~~~~</code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code&gt;aaa
~~~
&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<p>Unclosed code blocks are closed by the end of the document:</p>
<div id="example-70" class="example" data-section="Fenced code blocks">
<div class="examplenum">
Example 70
</div>
<pre class="markdown"><code>```</code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code&gt;&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<div id="example-71" class="example" data-section="Fenced code blocks">
<div class="examplenum">
Example 71
</div>
<pre class="markdown"><code>`````
```
aaa</code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code&gt;
```
aaa
&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<p>A code block can have all empty lines as its content:</p>
<div id="example-72" class="example" data-section="Fenced code blocks">
<div class="examplenum">
Example 72
</div>
<pre class="markdown"><code>```
```</code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code&gt;
&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<p>A code block can be empty:</p>
<div id="example-73" class="example" data-section="Fenced code blocks">
<div class="examplenum">
Example 73
</div>
<pre class="markdown"><code>```
```</code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code&gt;&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<p>Fences can be indented. If the opening fence is indented, content lines will have equivalent opening indentation removed, if present:</p>
<div id="example-74" class="example" data-section="Fenced code blocks">
<div class="examplenum">
Example 74
</div>
<pre class="markdown"><code> ```
aaa
aaa
```</code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code&gt;aaa
aaa
&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<div id="example-75" class="example" data-section="Fenced code blocks">
<div class="examplenum">
Example 75
</div>
<pre class="markdown"><code> ```
aaa
aaa
aaa
```</code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code&gt;aaa
aaa
aaa
&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<div id="example-76" class="example" data-section="Fenced code blocks">
<div class="examplenum">
Example 76
</div>
<pre class="markdown"><code> ```
aaa
aaa
aaa
```</code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code&gt;aaa
aaa
aaa
&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<p>Four spaces indentation produces an indented code block:</p>
<div id="example-77" class="example" data-section="Fenced code blocks">
<div class="examplenum">
Example 77
</div>
<pre class="markdown"><code> ```
aaa
```</code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code&gt;```
aaa
```
&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<p>Code fences (opening and closing) cannot contain internal spaces:</p>
<div id="example-78" class="example" data-section="Fenced code blocks">
<div class="examplenum">
Example 78
</div>
<pre class="markdown"><code>``` ```
aaa</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;code&gt;&lt;/code&gt;
aaa&lt;/p&gt;</code></pre>
</div>
<div id="example-79" class="example" data-section="Fenced code blocks">
<div class="examplenum">
Example 79
</div>
<pre class="markdown"><code>~~~~~~
aaa
~~~ ~~</code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code&gt;aaa
~~~ ~~
&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<p>Fenced code blocks can interrupt paragraphs, and can be followed directly by paragraphs, without a blank line between:</p>
<div id="example-80" class="example" data-section="Fenced code blocks">
<div class="examplenum">
Example 80
</div>
<pre class="markdown"><code>foo
```
bar
```
baz</code></pre>
<pre class="html"><code>&lt;p&gt;foo&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;bar
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;baz&lt;/p&gt;</code></pre>
</div>
<p>Other blocks can also occur before and after fenced code blocks without an intervening blank line:</p>
<div id="example-81" class="example" data-section="Fenced code blocks">
<div class="examplenum">
Example 81
</div>
<pre class="markdown"><code>foo
---
~~~
bar
~~~
# baz</code></pre>
<pre class="html"><code>&lt;h2&gt;foo&lt;/h2&gt;
&lt;pre&gt;&lt;code&gt;bar
&lt;/code&gt;&lt;/pre&gt;
&lt;h1&gt;baz&lt;/h1&gt;</code></pre>
</div>
<p>An <a href="#info-string">info string</a> can be provided after the opening code fence. Opening and closing spaces will be stripped, and the first word, prefixed with <code>language-</code>, is used as the value for the <code>class</code> attribute of the <code>code</code> element within the enclosing <code>pre</code> element.</p>
<div id="example-82" class="example" data-section="Fenced code blocks">
<div class="examplenum">
Example 82
</div>
<pre class="markdown"><code>```ruby
def foo(x)
return 3
end
```</code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code class=&quot;language-ruby&quot;&gt;def foo(x)
return 3
end
&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<div id="example-83" class="example" data-section="Fenced code blocks">
<div class="examplenum">
Example 83
</div>
<pre class="markdown"><code>~~~~ ruby startline=3 $%@#$
def foo(x)
return 3
end
~~~~~~~</code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code class=&quot;language-ruby&quot;&gt;def foo(x)
return 3
end
&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<div id="example-84" class="example" data-section="Fenced code blocks">
<div class="examplenum">
Example 84
</div>
<pre class="markdown"><code>````;
````</code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code class=&quot;language-;&quot;&gt;&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<p>Info strings for backtick code blocks cannot contain backticks:</p>
<div id="example-85" class="example" data-section="Fenced code blocks">
<div class="examplenum">
Example 85
</div>
<pre class="markdown"><code>``` aa ```
foo</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;code&gt;aa&lt;/code&gt;
foo&lt;/p&gt;</code></pre>
</div>
<p>Closing code fences cannot have info strings:</p>
<div id="example-86" class="example" data-section="Fenced code blocks">
<div class="examplenum">
Example 86
</div>
<pre class="markdown"><code>```
``` aaa
```</code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code&gt;``` aaa
&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<h2 id="html-blocks"><span class="header-section-number">4.6</span> HTML blocks</h2>
<p>An <a href="#html-block-tag">HTML block tag</a> <a id="html-block-tag"></a> is an <a href="#open-tag">open tag</a> or <a href="#closing-tag">closing tag</a> whose tag name is one of the following (case-insensitive): <code>article</code>, <code>header</code>, <code>aside</code>, <code>hgroup</code>, <code>blockquote</code>, <code>hr</code>, <code>iframe</code>, <code>body</code>, <code>li</code>, <code>map</code>, <code>button</code>, <code>object</code>, <code>canvas</code>, <code>ol</code>, <code>caption</code>, <code>output</code>, <code>col</code>, <code>p</code>, <code>colgroup</code>, <code>pre</code>, <code>dd</code>, <code>progress</code>, <code>div</code>, <code>section</code>, <code>dl</code>, <code>table</code>, <code>td</code>, <code>dt</code>, <code>tbody</code>, <code>embed</code>, <code>textarea</code>, <code>fieldset</code>, <code>tfoot</code>, <code>figcaption</code>, <code>th</code>, <code>figure</code>, <code>thead</code>, <code>footer</code>, <code>footer</code>, <code>tr</code>, <code>form</code>, <code>ul</code>, <code>h1</code>, <code>h2</code>, <code>h3</code>, <code>h4</code>, <code>h5</code>, <code>h6</code>, <code>video</code>, <code>script</code>, <code>style</code>.</p>
<p>An <a href="#html-block">HTML block</a> <a id="html-block"></a> begins with an <a href="#html-block-tag">HTML block tag</a>, <a href="#html-comment">HTML comment</a>, <a href="#processing-instruction">processing instruction</a>, <a href="#declaration">declaration</a>, or <a href="#cdata-section">CDATA section</a>. It ends when a <a href="#blank-line">blank line</a> or the end of the input is encountered. The initial line may be indented up to three spaces, and subsequent lines may have any indentation. The contents of the HTML block are interpreted as raw HTML, and will not be escaped in HTML output.</p>
<p>Some simple examples:</p>
<div id="example-87" class="example" data-section="HTML blocks">
<div class="examplenum">
Example 87
</div>
<pre class="markdown"><code>&lt;table&gt;
&lt;tr&gt;
&lt;td&gt;
hi
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
okay.</code></pre>
<pre class="html"><code>&lt;table&gt;
&lt;tr&gt;
&lt;td&gt;
hi
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;p&gt;okay.&lt;/p&gt;</code></pre>
</div>
<div id="example-88" class="example" data-section="HTML blocks">
<div class="examplenum">
Example 88
</div>
<pre class="markdown"><code> &lt;div&gt;
*hello*
&lt;foo&gt;&lt;a&gt;</code></pre>
<pre class="html"><code> &lt;div&gt;
*hello*
&lt;foo&gt;&lt;a&gt;</code></pre>
</div>
<p>Here we have two code blocks with a Markdown paragraph between them:</p>
<div id="example-89" class="example" data-section="HTML blocks">
<div class="examplenum">
Example 89
</div>
<pre class="markdown"><code>&lt;DIV CLASS=&quot;foo&quot;&gt;
*Markdown*
&lt;/DIV&gt;</code></pre>
<pre class="html"><code>&lt;DIV CLASS=&quot;foo&quot;&gt;
&lt;p&gt;&lt;em&gt;Markdown&lt;/em&gt;&lt;/p&gt;
&lt;/DIV&gt;</code></pre>
</div>
<p>In the following example, what looks like a Markdown code block is actually part of the HTML block, which continues until a blank line or the end of the document is reached:</p>
<div id="example-90" class="example" data-section="HTML blocks">
<div class="examplenum">
Example 90
</div>
<pre class="markdown"><code>&lt;div&gt;&lt;/div&gt;
``` c
int x = 33;
```</code></pre>
<pre class="html"><code>&lt;div&gt;&lt;/div&gt;
``` c
int x = 33;
```</code></pre>
</div>
<p>A comment:</p>
<div id="example-91" class="example" data-section="HTML blocks">
<div class="examplenum">
Example 91
</div>
<pre class="markdown"><code>&lt;!-- Foo
bar
baz --&gt;</code></pre>
<pre class="html"><code>&lt;!-- Foo
bar
baz --&gt;</code></pre>
</div>
<p>A processing instruction:</p>
<div id="example-92" class="example" data-section="HTML blocks">
<div class="examplenum">
Example 92
</div>
<pre class="markdown"><code>&lt;?php
echo &#39;foo&#39;
?&gt;</code></pre>
<pre class="html"><code>&lt;?php
echo &#39;foo&#39;
?&gt;</code></pre>
</div>
<p>CDATA:</p>
<div id="example-93" class="example" data-section="HTML blocks">
<div class="examplenum">
Example 93
</div>
<pre class="markdown"><code>&lt;![CDATA[
function matchwo(a,b)
{
if (a &lt; b &amp;&amp; a &lt; 0) then
{
return 1;
}
else
{
return 0;
}
}
]]&gt;</code></pre>
<pre class="html"><code>&lt;![CDATA[
function matchwo(a,b)
{
if (a &lt; b &amp;&amp; a &lt; 0) then
{
return 1;
}
else
{
return 0;
}
}
]]&gt;</code></pre>
</div>
<p>The opening tag can be indented 1-3 spaces, but not 4:</p>
<div id="example-94" class="example" data-section="HTML blocks">
<div class="examplenum">
Example 94
</div>
<pre class="markdown"><code> &lt;!-- foo --&gt;
&lt;!-- foo --&gt;</code></pre>
<pre class="html"><code> &lt;!-- foo --&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;!-- foo --&amp;gt;
&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<p>An HTML block can interrupt a paragraph, and need not be preceded by a blank line.</p>
<div id="example-95" class="example" data-section="HTML blocks">
<div class="examplenum">
Example 95
</div>
<pre class="markdown"><code>Foo
&lt;div&gt;
bar
&lt;/div&gt;</code></pre>
<pre class="html"><code>&lt;p&gt;Foo&lt;/p&gt;
&lt;div&gt;
bar
&lt;/div&gt;</code></pre>
</div>
<p>However, a following blank line is always needed, except at the end of a document:</p>
<div id="example-96" class="example" data-section="HTML blocks">
<div class="examplenum">
Example 96
</div>
<pre class="markdown"><code>&lt;div&gt;
bar
&lt;/div&gt;
*foo*</code></pre>
<pre class="html"><code>&lt;div&gt;
bar
&lt;/div&gt;
*foo*</code></pre>
</div>
<p>An incomplete HTML block tag may also start an HTML block:</p>
<div id="example-97" class="example" data-section="HTML blocks">
<div class="examplenum">
Example 97
</div>
<pre class="markdown"><code>&lt;div class
foo</code></pre>
<pre class="html"><code>&lt;div class
foo</code></pre>
</div>
<p>This rule differs from John Gruber’s original Markdown syntax specification, which says:</p>
<blockquote>
<p>The only restrictions are that block-level HTML elements — e.g. <code>&lt;div&gt;</code>, <code>&lt;table&gt;</code>, <code>&lt;pre&gt;</code>, <code>&lt;p&gt;</code>, etc. — must be separated from surrounding content by blank lines, and the start and end tags of the block should not be indented with tabs or spaces.</p>
</blockquote>
<p>In some ways Gruber’s rule is more restrictive than the one given here:</p>
<ul>
<li>It requires that an HTML block be preceded by a blank line.</li>
<li>It does not allow the start tag to be indented.</li>
<li>It requires a matching end tag, which it also does not allow to be indented.</li>
</ul>
<p>Indeed, most Markdown implementations, including some of Gruber’s own perl implementations, do not impose these restrictions.</p>
<p>There is one respect, however, in which Gruber’s rule is more liberal than the one given here, since it allows blank lines to occur inside an HTML block. There are two reasons for disallowing them here. First, it removes the need to parse balanced tags, which is expensive and can require backtracking from the end of the document if no matching end tag is found. Second, it provides a very simple and flexible way of including Markdown content inside HTML tags: simply separate the Markdown from the HTML using blank lines:</p>
<div id="example-98" class="example" data-section="HTML blocks">
<div class="examplenum">
Example 98
</div>
<pre class="markdown"><code>&lt;div&gt;
*Emphasized* text.
&lt;/div&gt;</code></pre>
<pre class="html"><code>&lt;div&gt;
&lt;p&gt;&lt;em&gt;Emphasized&lt;/em&gt; text.&lt;/p&gt;
&lt;/div&gt;</code></pre>
</div>
<p>Compare:</p>
<div id="example-99" class="example" data-section="HTML blocks">
<div class="examplenum">
Example 99
</div>
<pre class="markdown"><code>&lt;div&gt;
*Emphasized* text.
&lt;/div&gt;</code></pre>
<pre class="html"><code>&lt;div&gt;
*Emphasized* text.
&lt;/div&gt;</code></pre>
</div>
<p>Some Markdown implementations have adopted a convention of interpreting content inside tags as text if the open tag has the attribute <code>markdown=1</code>. The rule given above seems a simpler and more elegant way of achieving the same expressive power, which is also much simpler to parse.</p>
<p>The main potential drawback is that one can no longer paste HTML blocks into Markdown documents with 100% reliability. However, <em>in most cases</em> this will work fine, because the blank lines in HTML are usually followed by HTML block tags. For example:</p>
<div id="example-100" class="example" data-section="HTML blocks">
<div class="examplenum">
Example 100
</div>
<pre class="markdown"><code>&lt;table&gt;
&lt;tr&gt;
&lt;td&gt;
Hi
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;</code></pre>
<pre class="html"><code>&lt;table&gt;
&lt;tr&gt;
&lt;td&gt;
Hi
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;</code></pre>
</div>
<p>Moreover, blank lines are usually not necessary and can be deleted. The exception is inside <code>&lt;pre&gt;</code> tags; here, one can replace the blank lines with <code>&amp;#10;</code> entities.</p>
<p>So there is no important loss of expressive power with the new rule.</p>
<h2 id="link-reference-definitions"><span class="header-section-number">4.7</span> Link reference definitions</h2>
<p>A <a href="#link-reference-definition">link reference definition</a> <a id="link-reference-definition"></a> consists of a <a href="#link-label">link label</a>, indented up to three spaces, followed by a colon (<code>:</code>), optional blank space (including up to one newline), a <a href="#link-destination">link destination</a>, optional blank space (including up to one newline), and an optional <a href="#link-title">link title</a>, which if it is present must be separated from the <a href="#link-destination">link destination</a> by whitespace. No further non-space characters may occur on the line.</p>
<p>A <a href="#link-reference-definition">link reference-definition</a> does not correspond to a structural element of a document. Instead, it defines a label which can be used in <a href="#reference-link">reference links</a> and reference-style <a href="#image">images</a> elsewhere in the document. <a href="#link-reference-definitions">Link reference definitions</a> can come either before or after the links that use them.</p>
<div id="example-101" class="example" data-section="Link reference definitions">
<div class="examplenum">
Example 101
</div>
<pre class="markdown"><code>[foo]: /url &quot;title&quot;
[foo]</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;/url&quot; title=&quot;title&quot;&gt;foo&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-102" class="example" data-section="Link reference definitions">
<div class="examplenum">
Example 102
</div>
<pre class="markdown"><code> [foo]:
/url
&#39;the title&#39;
[foo]</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;/url&quot; title=&quot;the title&quot;&gt;foo&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-103" class="example" data-section="Link reference definitions">
<div class="examplenum">
Example 103
</div>
<pre class="markdown"><code>[Foo*bar\]]:my_(url) &#39;title (with parens)&#39;
[Foo*bar\]]</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;my_(url)&quot; title=&quot;title (with parens)&quot;&gt;Foo*bar]&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-104" class="example" data-section="Link reference definitions">
<div class="examplenum">
Example 104
</div>
<pre class="markdown"><code>[Foo bar]:
&lt;my url&gt;
&#39;title&#39;
[Foo bar]</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;my url&quot; title=&quot;title&quot;&gt;Foo bar&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<p>The title may be omitted:</p>
<div id="example-105" class="example" data-section="Link reference definitions">
<div class="examplenum">
Example 105
</div>
<pre class="markdown"><code>[foo]:
/url
[foo]</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;/url&quot;&gt;foo&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<p>The link destination may not be omitted:</p>
<div id="example-106" class="example" data-section="Link reference definitions">
<div class="examplenum">
Example 106
</div>
<pre class="markdown"><code>[foo]:
[foo]</code></pre>
<pre class="html"><code>&lt;p&gt;[foo]:&lt;/p&gt;
&lt;p&gt;[foo]&lt;/p&gt;</code></pre>
</div>
<p>A link can come before its corresponding definition:</p>
<div id="example-107" class="example" data-section="Link reference definitions">
<div class="examplenum">
Example 107
</div>
<pre class="markdown"><code>[foo]
[foo]: url</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;url&quot;&gt;foo&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<p>If there are several matching definitions, the first one takes precedence:</p>
<div id="example-108" class="example" data-section="Link reference definitions">
<div class="examplenum">
Example 108
</div>
<pre class="markdown"><code>[foo]
[foo]: first
[foo]: second</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;first&quot;&gt;foo&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<p>As noted in the section on <a href="#links">Links</a>, matching of labels is case-insensitive (see <a href="#matches">matches</a>).</p>
<div id="example-109" class="example" data-section="Link reference definitions">
<div class="examplenum">
Example 109
</div>
<pre class="markdown"><code>[FOO]: /url
[Foo]</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;/url&quot;&gt;Foo&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-110" class="example" data-section="Link reference definitions">
<div class="examplenum">
Example 110
</div>
<pre class="markdown"><code>[ΑΓΩ]: /φου
[αγω]</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;/φου&quot;&gt;αγω&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<p>Here is a link reference definition with no corresponding link. It contributes nothing to the document.</p>
<div id="example-111" class="example" data-section="Link reference definitions">
<div class="examplenum">
Example 111
</div>
<pre class="markdown"><code>[foo]: /url</code></pre>
<pre class="html"><code></code></pre>
</div>
<p>This is not a link reference definition, because there are non-space characters after the title:</p>
<div id="example-112" class="example" data-section="Link reference definitions">
<div class="examplenum">
Example 112
</div>
<pre class="markdown"><code>[foo]: /url &quot;title&quot; ok</code></pre>
<pre class="html"><code>&lt;p&gt;[foo]: /url &amp;quot;title&amp;quot; ok&lt;/p&gt;</code></pre>
</div>
<p>This is not a link reference definition, because it is indented four spaces:</p>
<div id="example-113" class="example" data-section="Link reference definitions">
<div class="examplenum">
Example 113
</div>
<pre class="markdown"><code> [foo]: /url &quot;title&quot;
[foo]</code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code&gt;[foo]: /url &amp;quot;title&amp;quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;[foo]&lt;/p&gt;</code></pre>
</div>
<p>This is not a link reference definition, because it occurs inside a code block:</p>
<div id="example-114" class="example" data-section="Link reference definitions">
<div class="examplenum">
Example 114
</div>
<pre class="markdown"><code>```
[foo]: /url
```
[foo]</code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code&gt;[foo]: /url
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;[foo]&lt;/p&gt;</code></pre>
</div>
<p>A <a href="#link-reference-definition">link reference definition</a> cannot interrupt a paragraph.</p>
<div id="example-115" class="example" data-section="Link reference definitions">
<div class="examplenum">
Example 115
</div>
<pre class="markdown"><code>Foo
[bar]: /baz
[bar]</code></pre>
<pre class="html"><code>&lt;p&gt;Foo
[bar]: /baz&lt;/p&gt;
&lt;p&gt;[bar]&lt;/p&gt;</code></pre>
</div>
<p>However, it can directly follow other block elements, such as headers and horizontal rules, and it need not be followed by a blank line.</p>
<div id="example-116" class="example" data-section="Link reference definitions">
<div class="examplenum">
Example 116
</div>
<pre class="markdown"><code># [Foo]
[foo]: /url
&gt; bar</code></pre>
<pre class="html"><code>&lt;h1&gt;&lt;a href=&quot;/url&quot;&gt;Foo&lt;/a&gt;&lt;/h1&gt;
&lt;blockquote&gt;
&lt;p&gt;bar&lt;/p&gt;
&lt;/blockquote&gt;</code></pre>
</div>
<p>Several <a href="#link-reference">link references</a> can occur one after another, without intervening blank lines.</p>
<div id="example-117" class="example" data-section="Link reference definitions">
<div class="examplenum">
Example 117
</div>
<pre class="markdown"><code>[foo]: /foo-url &quot;foo&quot;
[bar]: /bar-url
&quot;bar&quot;
[baz]: /baz-url
[foo],
[bar],
[baz]</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;/foo-url&quot; title=&quot;foo&quot;&gt;foo&lt;/a&gt;,
&lt;a href=&quot;/bar-url&quot; title=&quot;bar&quot;&gt;bar&lt;/a&gt;,
&lt;a href=&quot;/baz-url&quot;&gt;baz&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<p><a href="#link-reference-definition">Link reference definitions</a> can occur inside block containers, like lists and block quotations. They affect the entire document, not just the container in which they are defined:</p>
<div id="example-118" class="example" data-section="Link reference definitions">
<div class="examplenum">
Example 118
</div>
<pre class="markdown"><code>[foo]
&gt; [foo]: /url</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;/url&quot;&gt;foo&lt;/a&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;/blockquote&gt;</code></pre>
</div>
<h2 id="paragraphs"><span class="header-section-number">4.8</span> Paragraphs</h2>
<p>A sequence of non-blank lines that cannot be interpreted as other kinds of blocks forms a <a href="#paragraph">paragraph</a>.<a id="paragraph"></a> The contents of the paragraph are the result of parsing the paragraph’s raw content as inlines. The paragraph’s raw content is formed by concatenating the lines and removing initial and final spaces.</p>
<p>A simple example with two paragraphs:</p>
<div id="example-119" class="example" data-section="Paragraphs">
<div class="examplenum">
Example 119
</div>
<pre class="markdown"><code>aaa
bbb</code></pre>
<pre class="html"><code>&lt;p&gt;aaa&lt;/p&gt;
&lt;p&gt;bbb&lt;/p&gt;</code></pre>
</div>
<p>Paragraphs can contain multiple lines, but no blank lines:</p>
<div id="example-120" class="example" data-section="Paragraphs">
<div class="examplenum">
Example 120
</div>
<pre class="markdown"><code>aaa
bbb
ccc
ddd</code></pre>
<pre class="html"><code>&lt;p&gt;aaa
bbb&lt;/p&gt;
&lt;p&gt;ccc
ddd&lt;/p&gt;</code></pre>
</div>
<p>Multiple blank lines between paragraph have no effect:</p>
<div id="example-121" class="example" data-section="Paragraphs">
<div class="examplenum">
Example 121
</div>
<pre class="markdown"><code>aaa
bbb</code></pre>
<pre class="html"><code>&lt;p&gt;aaa&lt;/p&gt;
&lt;p&gt;bbb&lt;/p&gt;</code></pre>
</div>
<p>Leading spaces are skipped:</p>
<div id="example-122" class="example" data-section="Paragraphs">
<div class="examplenum">
Example 122
</div>
<pre class="markdown"><code> aaa
bbb</code></pre>
<pre class="html"><code>&lt;p&gt;aaa
bbb&lt;/p&gt;</code></pre>
</div>
<p>Lines after the first may be indented any amount, since indented code blocks cannot interrupt paragraphs.</p>
<div id="example-123" class="example" data-section="Paragraphs">
<div class="examplenum">
Example 123
</div>
<pre class="markdown"><code>aaa
bbb
ccc</code></pre>
<pre class="html"><code>&lt;p&gt;aaa
bbb
ccc&lt;/p&gt;</code></pre>
</div>
<p>However, the first line may be indented at most three spaces, or an indented code block will be triggered:</p>
<div id="example-124" class="example" data-section="Paragraphs">
<div class="examplenum">
Example 124
</div>
<pre class="markdown"><code> aaa
bbb</code></pre>
<pre class="html"><code>&lt;p&gt;aaa
bbb&lt;/p&gt;</code></pre>
</div>
<div id="example-125" class="example" data-section="Paragraphs">
<div class="examplenum">
Example 125
</div>
<pre class="markdown"><code> aaa
bbb</code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code&gt;aaa
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;bbb&lt;/p&gt;</code></pre>
</div>
<p>Final spaces are stripped before inline parsing, so a paragraph that ends with two or more spaces will not end with a hard line break:</p>
<div id="example-126" class="example" data-section="Paragraphs">
<div class="examplenum">
Example 126
</div>
<pre class="markdown"><code>aaa
bbb </code></pre>
<pre class="html"><code>&lt;p&gt;aaa&lt;br /&gt;
bbb&lt;/p&gt;</code></pre>
</div>
<h2 id="blank-lines"><span class="header-section-number">4.9</span> Blank lines</h2>
<p><a href="#blank-line">Blank lines</a> between block-level elements are ignored, except for the role they play in determining whether a <a href="#list">list</a> is <a href="#tight">tight</a> or <a href="#loose">loose</a>.</p>
<p>Blank lines at the beginning and end of the document are also ignored.</p>
<div id="example-127" class="example" data-section="Blank lines">
<div class="examplenum">
Example 127
</div>
<pre class="markdown"><code>
aaa
# aaa
</code></pre>
<pre class="html"><code>&lt;p&gt;aaa&lt;/p&gt;
&lt;h1&gt;aaa&lt;/h1&gt;</code></pre>
</div>
<h1 id="container-blocks"><span class="header-section-number">5</span> Container blocks</h1>
<p>A <a href="#container-block">container block</a> is a block that has other blocks as its contents. There are two basic kinds of container blocks: <a href="#block-quote">block quotes</a> and <a href="#list-item">list items</a>. <a href="#list">Lists</a> are meta-containers for <a href="#list-item">list items</a>.</p>
<p>We define the syntax for container blocks recursively. The general form of the definition is:</p>
<blockquote>
<p>If X is a sequence of blocks, then the result of transforming X in such-and-such a way is a container of type Y with these blocks as its content.</p>
</blockquote>
<p>So, we explain what counts as a block quote or list item by explaining how these can be <em>generated</em> from their contents. This should suffice to define the syntax, although it does not give a recipe for <em>parsing</em> these constructions. (A recipe is provided below in the section entitled [A parsing strategy].)</p>
<h2 id="block-quotes"><span class="header-section-number">5.1</span> Block quotes</h2>
<p>A <a href="#block-quote-marker">block quote marker</a> <a id="block-quote-marker"></a> consists of 0-3 spaces of initial indent, plus (a) the character <code>&gt;</code> together with a following space, or (b) a single character <code>&gt;</code> not followed by a space.</p>
<p>The following rules define <a href="#block-quote">block quotes</a>: <a id="block-quote"></a></p>
<ol style="list-style-type: decimal">
<li><p><strong>Basic case.</strong> If a string of lines <em>Ls</em> constitute a sequence of blocks <em>Bs</em>, then the result of appending a [block quote marker] to the beginning of each line in <em>Ls</em> is a <a href="#block-quote">block quote</a> containing <em>Bs</em>.</p></li>
<li><p><strong>Laziness.</strong> If a string of lines <em>Ls</em> constitute a <a href="#block-quote">block quote</a> with contents <em>Bs</em>, then the result of deleting the initial <a href="#block-quote-marker">block quote marker</a> from one or more lines in which the next non-space character after the <a href="#block-quote-marker">block quote marker</a> is <a href="#paragraph-continuation-text">paragraph continuation text</a> is a block quote with <em>Bs</em> as its content. <a id="paragraph-continuation-text"></a> <a href="#paragraph-continuation-text">Paragraph continuation text</a> is text that will be parsed as part of the content of a paragraph, but does not occur at the beginning of the paragraph.</p></li>
<li><p><strong>Consecutiveness.</strong> A document cannot contain two <a href="#block-quote">block quotes</a> in a row unless there is a <a href="#blank-line">blank line</a> between them.</p></li>
</ol>
<p>Nothing else counts as a <a href="#block-quote">block quote</a>.</p>
<p>Here is a simple example:</p>
<div id="example-128" class="example" data-section="Block quotes">
<div class="examplenum">
Example 128
</div>
<pre class="markdown"><code>&gt; # Foo
&gt; bar
&gt; baz</code></pre>
<pre class="html"><code>&lt;blockquote&gt;
&lt;h1&gt;Foo&lt;/h1&gt;
&lt;p&gt;bar
baz&lt;/p&gt;
&lt;/blockquote&gt;</code></pre>
</div>
<p>The spaces after the <code>&gt;</code> characters can be omitted:</p>
<div id="example-129" class="example" data-section="Block quotes">
<div class="examplenum">
Example 129
</div>
<pre class="markdown"><code>&gt;# Foo
&gt;bar
&gt; baz</code></pre>
<pre class="html"><code>&lt;blockquote&gt;
&lt;h1&gt;Foo&lt;/h1&gt;
&lt;p&gt;bar
baz&lt;/p&gt;
&lt;/blockquote&gt;</code></pre>
</div>
<p>The <code>&gt;</code> characters can be indented 1-3 spaces:</p>
<div id="example-130" class="example" data-section="Block quotes">
<div class="examplenum">
Example 130
</div>
<pre class="markdown"><code> &gt; # Foo
&gt; bar
&gt; baz</code></pre>
<pre class="html"><code>&lt;blockquote&gt;
&lt;h1&gt;Foo&lt;/h1&gt;
&lt;p&gt;bar
baz&lt;/p&gt;
&lt;/blockquote&gt;</code></pre>
</div>
<p>Four spaces gives us a code block:</p>
<div id="example-131" class="example" data-section="Block quotes">
<div class="examplenum">
Example 131
</div>
<pre class="markdown"><code> &gt; # Foo
&gt; bar
&gt; baz</code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code&gt;&amp;gt; # Foo
&amp;gt; bar
&amp;gt; baz
&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<p>The Laziness clause allows us to omit the <code>&gt;</code> before a paragraph continuation line:</p>
<div id="example-132" class="example" data-section="Block quotes">
<div class="examplenum">
Example 132
</div>
<pre class="markdown"><code>&gt; # Foo
&gt; bar
baz</code></pre>
<pre class="html"><code>&lt;blockquote&gt;
&lt;h1&gt;Foo&lt;/h1&gt;
&lt;p&gt;bar
baz&lt;/p&gt;
&lt;/blockquote&gt;</code></pre>
</div>
<p>A block quote can contain some lazy and some non-lazy continuation lines:</p>
<div id="example-133" class="example" data-section="Block quotes">
<div class="examplenum">
Example 133
</div>
<pre class="markdown"><code>&gt; bar
baz
&gt; foo</code></pre>
<pre class="html"><code>&lt;blockquote&gt;
&lt;p&gt;bar
baz
foo&lt;/p&gt;
&lt;/blockquote&gt;</code></pre>
</div>
<p>Laziness only applies to lines that are continuations of paragraphs. Lines containing characters or indentation that indicate block structure cannot be lazy.</p>
<div id="example-134" class="example" data-section="Block quotes">
<div class="examplenum">
Example 134
</div>
<pre class="markdown"><code>&gt; foo
---</code></pre>
<pre class="html"><code>&lt;blockquote&gt;
&lt;p&gt;foo&lt;/p&gt;
&lt;/blockquote&gt;
&lt;hr /&gt;</code></pre>
</div>
<div id="example-135" class="example" data-section="Block quotes">
<div class="examplenum">
Example 135
</div>
<pre class="markdown"><code>&gt; - foo
- bar</code></pre>
<pre class="html"><code>&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;foo&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;ul&gt;
&lt;li&gt;bar&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
<div id="example-136" class="example" data-section="Block quotes">
<div class="examplenum">
Example 136
</div>
<pre class="markdown"><code>&gt; foo
bar</code></pre>
<pre class="html"><code>&lt;blockquote&gt;
&lt;pre&gt;&lt;code&gt;foo
&lt;/code&gt;&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;pre&gt;&lt;code&gt;bar
&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<div id="example-137" class="example" data-section="Block quotes">
<div class="examplenum">
Example 137
</div>
<pre class="markdown"><code>&gt; ```
foo
```</code></pre>
<pre class="html"><code>&lt;blockquote&gt;
&lt;pre&gt;&lt;code&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;p&gt;foo&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<p>A block quote can be empty:</p>
<div id="example-138" class="example" data-section="Block quotes">
<div class="examplenum">
Example 138
</div>
<pre class="markdown"><code>&gt;</code></pre>
<pre class="html"><code>&lt;blockquote&gt;
&lt;/blockquote&gt;</code></pre>
</div>
<div id="example-139" class="example" data-section="Block quotes">
<div class="examplenum">
Example 139
</div>
<pre class="markdown"><code>&gt;
&gt;
&gt; </code></pre>
<pre class="html"><code>&lt;blockquote&gt;
&lt;/blockquote&gt;</code></pre>
</div>
<p>A block quote can have initial or final blank lines:</p>
<div id="example-140" class="example" data-section="Block quotes">
<div class="examplenum">
Example 140
</div>
<pre class="markdown"><code>&gt;
&gt; foo
&gt; </code></pre>
<pre class="html"><code>&lt;blockquote&gt;
&lt;p&gt;foo&lt;/p&gt;
&lt;/blockquote&gt;</code></pre>
</div>
<p>A blank line always separates block quotes:</p>
<div id="example-141" class="example" data-section="Block quotes">
<div class="examplenum">
Example 141
</div>
<pre class="markdown"><code>&gt; foo
&gt; bar</code></pre>
<pre class="html"><code>&lt;blockquote&gt;
&lt;p&gt;foo&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;bar&lt;/p&gt;
&lt;/blockquote&gt;</code></pre>
</div>
<p>(Most current Markdown implementations, including John Gruber’s original <code>Markdown.pl</code>, will parse this example as a single block quote with two paragraphs. But it seems better to allow the author to decide whether two block quotes or one are wanted.)</p>
<p>Consecutiveness means that if we put these block quotes together, we get a single block quote:</p>
<div id="example-142" class="example" data-section="Block quotes">
<div class="examplenum">
Example 142
</div>
<pre class="markdown"><code>&gt; foo
&gt; bar</code></pre>
<pre class="html"><code>&lt;blockquote&gt;
&lt;p&gt;foo
bar&lt;/p&gt;
&lt;/blockquote&gt;</code></pre>
</div>
<p>To get a block quote with two paragraphs, use:</p>
<div id="example-143" class="example" data-section="Block quotes">
<div class="examplenum">
Example 143
</div>
<pre class="markdown"><code>&gt; foo
&gt;
&gt; bar</code></pre>
<pre class="html"><code>&lt;blockquote&gt;
&lt;p&gt;foo&lt;/p&gt;
&lt;p&gt;bar&lt;/p&gt;
&lt;/blockquote&gt;</code></pre>
</div>
<p>Block quotes can interrupt paragraphs:</p>
<div id="example-144" class="example" data-section="Block quotes">
<div class="examplenum">
Example 144
</div>
<pre class="markdown"><code>foo
&gt; bar</code></pre>
<pre class="html"><code>&lt;p&gt;foo&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;bar&lt;/p&gt;
&lt;/blockquote&gt;</code></pre>
</div>
<p>In general, blank lines are not needed before or after block quotes:</p>
<div id="example-145" class="example" data-section="Block quotes">
<div class="examplenum">
Example 145
</div>
<pre class="markdown"><code>&gt; aaa
***
&gt; bbb</code></pre>
<pre class="html"><code>&lt;blockquote&gt;
&lt;p&gt;aaa&lt;/p&gt;
&lt;/blockquote&gt;
&lt;hr /&gt;
&lt;blockquote&gt;
&lt;p&gt;bbb&lt;/p&gt;
&lt;/blockquote&gt;</code></pre>
</div>
<p>However, because of laziness, a blank line is needed between a block quote and a following paragraph:</p>
<div id="example-146" class="example" data-section="Block quotes">
<div class="examplenum">
Example 146
</div>
<pre class="markdown"><code>&gt; bar
baz</code></pre>
<pre class="html"><code>&lt;blockquote&gt;
&lt;p&gt;bar
baz&lt;/p&gt;
&lt;/blockquote&gt;</code></pre>
</div>
<div id="example-147" class="example" data-section="Block quotes">
<div class="examplenum">
Example 147
</div>
<pre class="markdown"><code>&gt; bar
baz</code></pre>
<pre class="html"><code>&lt;blockquote&gt;
&lt;p&gt;bar&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;baz&lt;/p&gt;</code></pre>
</div>
<div id="example-148" class="example" data-section="Block quotes">
<div class="examplenum">
Example 148
</div>
<pre class="markdown"><code>&gt; bar
&gt;
baz</code></pre>
<pre class="html"><code>&lt;blockquote&gt;
&lt;p&gt;bar&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;baz&lt;/p&gt;</code></pre>
</div>
<p>It is a consequence of the Laziness rule that any number of initial <code>&gt;</code>s may be omitted on a continuation line of a nested block quote:</p>
<div id="example-149" class="example" data-section="Block quotes">
<div class="examplenum">
Example 149
</div>
<pre class="markdown"><code>&gt; &gt; &gt; foo
bar</code></pre>
<pre class="html"><code>&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;foo
bar&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/blockquote&gt;
&lt;/blockquote&gt;</code></pre>
</div>
<div id="example-150" class="example" data-section="Block quotes">
<div class="examplenum">
Example 150
</div>
<pre class="markdown"><code>&gt;&gt;&gt; foo
&gt; bar
&gt;&gt;baz</code></pre>
<pre class="html"><code>&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;foo
bar
baz&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/blockquote&gt;
&lt;/blockquote&gt;</code></pre>
</div>
<p>When including an indented code block in a block quote, remember that the <a href="#block-quote-marker">block quote marker</a> includes both the <code>&gt;</code> and a following space. So <em>five spaces</em> are needed after the <code>&gt;</code>:</p>
<div id="example-151" class="example" data-section="Block quotes">
<div class="examplenum">
Example 151
</div>
<pre class="markdown"><code>&gt; code
&gt; not code</code></pre>
<pre class="html"><code>&lt;blockquote&gt;
&lt;pre&gt;&lt;code&gt;code
&lt;/code&gt;&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;not code&lt;/p&gt;
&lt;/blockquote&gt;</code></pre>
</div>
<h2 id="list-items"><span class="header-section-number">5.2</span> List items</h2>
<p>A <a href="#list-marker">list marker</a> <a id="list-marker"></a> is a <a href="#bullet-list-marker">bullet list marker</a> or an <a href="#ordered-list-marker">ordered list marker</a>.</p>
<p>A <a href="#bullet-list-marker">bullet list marker</a> <a id="bullet-list-marker"></a> is a <code>-</code>, <code>+</code>, or <code>*</code> character.</p>
<p>An <a href="#ordered-list-marker">ordered list marker</a> <a id="ordered-list-marker"></a> is a sequence of one of more digits (<code>0-9</code>), followed by either a <code>.</code> character or a <code>)</code> character.</p>
<p>The following rules define <a href="#list-item">list items</a>:</p>
<ol style="list-style-type: decimal">
<li><strong>Basic case.</strong> If a sequence of lines <em>Ls</em> constitute a sequence of blocks <em>Bs</em> starting with a non-space character and not separated from each other by more than one blank line, and <em>M</em> is a list marker <em>M</em> of width <em>W</em> followed by 0 &lt; <em>N</em> &lt; 5 spaces, then the result of prepending <em>M</em> and the following spaces to the first line of <em>Ls</em>, and indenting subsequent lines of <em>Ls</em> by <em>W + N</em> spaces, is a list item with <em>Bs</em> as its contents. The type of the list item (bullet or ordered) is determined by the type of its list marker. If the list item is ordered, then it is also assigned a start number, based on the ordered list marker.</li>
</ol>
<p>For example, let <em>Ls</em> be the lines</p>
<div id="example-152" class="example" data-section="List items">
<div class="examplenum">
Example 152
</div>
<pre class="markdown"><code>A paragraph
with two lines.
indented code
&gt; A block quote.</code></pre>
<pre class="html"><code>&lt;p&gt;A paragraph
with two lines.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;indented code
&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;A block quote.&lt;/p&gt;
&lt;/blockquote&gt;</code></pre>
</div>
<p>And let <em>M</em> be the marker <code>1.</code>, and <em>N</em> = 2. Then rule #1 says that the following is an ordered list item with start number 1, and the same contents as <em>Ls</em>:</p>
<div id="example-153" class="example" data-section="List items">
<div class="examplenum">
Example 153
</div>
<pre class="markdown"><code>1. A paragraph
with two lines.
indented code
&gt; A block quote.</code></pre>
<pre class="html"><code>&lt;ol&gt;
&lt;li&gt;&lt;p&gt;A paragraph
with two lines.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;indented code
&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;A block quote.&lt;/p&gt;
&lt;/blockquote&gt;&lt;/li&gt;
&lt;/ol&gt;</code></pre>
</div>
<p>The most important thing to notice is that the position of the text after the list marker determines how much indentation is needed in subsequent blocks in the list item. If the list marker takes up two spaces, and there are three spaces between the list marker and the next non-space character, then blocks must be indented five spaces in order to fall under the list item.</p>
<p>Here are some examples showing how far content must be indented to be put under the list item:</p>
<div id="example-154" class="example" data-section="List items">
<div class="examplenum">
Example 154
</div>
<pre class="markdown"><code>- one
two</code></pre>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;one&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;two&lt;/p&gt;</code></pre>
</div>
<div id="example-155" class="example" data-section="List items">
<div class="examplenum">
Example 155
</div>
<pre class="markdown"><code>- one
two</code></pre>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;&lt;p&gt;one&lt;/p&gt;
&lt;p&gt;two&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
<div id="example-156" class="example" data-section="List items">
<div class="examplenum">
Example 156
</div>
<pre class="markdown"><code> - one
two</code></pre>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;one&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code&gt; two
&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<div id="example-157" class="example" data-section="List items">
<div class="examplenum">
Example 157
</div>
<pre class="markdown"><code> - one
two</code></pre>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;&lt;p&gt;one&lt;/p&gt;
&lt;p&gt;two&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
<p>It is tempting to think of this in terms of columns: the continuation blocks must be indented at least to the column of the first non-space character after the list marker. However, that is not quite right. The spaces after the list marker determine how much relative indentation is needed. Which column this indentation reaches will depend on how the list item is embedded in other constructions, as shown by this example:</p>
<div id="example-158" class="example" data-section="List items">
<div class="examplenum">
Example 158
</div>
<pre class="markdown"><code> &gt; &gt; 1. one
&gt;&gt;
&gt;&gt; two</code></pre>
<pre class="html"><code>&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;ol&gt;
&lt;li&gt;&lt;p&gt;one&lt;/p&gt;
&lt;p&gt;two&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;/blockquote&gt;</code></pre>
</div>
<p>Here <code>two</code> occurs in the same column as the list marker <code>1.</code>, but is actually contained in the list item, because there is sufficient indentation after the last containing blockquote marker.</p>
<p>The converse is also possible. In the following example, the word <code>two</code> occurs far to the right of the initial text of the list item, <code>one</code>, but it is not considered part of the list item, because it is not indented far enough past the blockquote marker:</p>
<div id="example-159" class="example" data-section="List items">
<div class="examplenum">
Example 159
</div>
<pre class="markdown"><code>&gt;&gt;- one
&gt;&gt;
&gt; &gt; two</code></pre>
<pre class="html"><code>&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;one&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;two&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/blockquote&gt;</code></pre>
</div>
<p>A list item may not contain blocks that are separated by more than one blank line. Thus, two blank lines will end a list, unless the two blanks are contained in a <a href="#fenced-code-block">fenced code block</a>.</p>
<div id="example-160" class="example" data-section="List items">
<div class="examplenum">
Example 160
</div>
<pre class="markdown"><code>- foo
bar
- foo
bar
- ```
foo
bar
```</code></pre>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;&lt;p&gt;foo&lt;/p&gt;
&lt;p&gt;bar&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;foo&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;bar&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;pre&gt;&lt;code&gt;foo
bar
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
<p>A list item may contain any kind of block:</p>
<div id="example-161" class="example" data-section="List items">
<div class="examplenum">
Example 161
</div>
<pre class="markdown"><code>1. foo
```
bar
```
baz
&gt; bam</code></pre>
<pre class="html"><code>&lt;ol&gt;
&lt;li&gt;&lt;p&gt;foo&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;bar
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;baz&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;bam&lt;/p&gt;
&lt;/blockquote&gt;&lt;/li&gt;
&lt;/ol&gt;</code></pre>
</div>
<ol start="2" style="list-style-type: decimal">
<li><strong>Item starting with indented code.</strong> If a sequence of lines <em>Ls</em> constitute a sequence of blocks <em>Bs</em> starting with an indented code block and not separated from each other by more than one blank line, and <em>M</em> is a list marker <em>M</em> of width <em>W</em> followed by one space, then the result of prepending <em>M</em> and the following space to the first line of <em>Ls</em>, and indenting subsequent lines of <em>Ls</em> by <em>W + 1</em> spaces, is a list item with <em>Bs</em> as its contents. If a line is empty, then it need not be indented. The type of the list item (bullet or ordered) is determined by the type of its list marker. If the list item is ordered, then it is also assigned a start number, based on the ordered list marker.</li>
</ol>
<p>An indented code block will have to be indented four spaces beyond the edge of the region where text will be included in the list item. In the following case that is 6 spaces:</p>
<div id="example-162" class="example" data-section="List items">
<div class="examplenum">
Example 162
</div>
<pre class="markdown"><code>- foo
bar</code></pre>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;&lt;p&gt;foo&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;bar
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
<p>And in this case it is 11 spaces:</p>
<div id="example-163" class="example" data-section="List items">
<div class="examplenum">
Example 163
</div>
<pre class="markdown"><code> 10. foo
bar</code></pre>
<pre class="html"><code>&lt;ol start=&quot;10&quot;&gt;
&lt;li&gt;&lt;p&gt;foo&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;bar
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;/ol&gt;</code></pre>
</div>
<p>If the <em>first</em> block in the list item is an indented code block, then by rule #2, the contents must be indented <em>one</em> space after the list marker:</p>
<div id="example-164" class="example" data-section="List items">
<div class="examplenum">
Example 164
</div>
<pre class="markdown"><code> indented code
paragraph
more code</code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code&gt;indented code
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;paragraph&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;more code
&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<div id="example-165" class="example" data-section="List items">
<div class="examplenum">
Example 165
</div>
<pre class="markdown"><code>1. indented code
paragraph
more code</code></pre>
<pre class="html"><code>&lt;ol&gt;
&lt;li&gt;&lt;pre&gt;&lt;code&gt;indented code
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;paragraph&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;more code
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;/ol&gt;</code></pre>
</div>
<p>Note that an additional space indent is interpreted as space inside the code block:</p>
<div id="example-166" class="example" data-section="List items">
<div class="examplenum">
Example 166
</div>
<pre class="markdown"><code>1. indented code
paragraph
more code</code></pre>
<pre class="html"><code>&lt;ol&gt;
&lt;li&gt;&lt;pre&gt;&lt;code&gt; indented code
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;paragraph&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;more code
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;/ol&gt;</code></pre>
</div>
<p>Note that rules #1 and #2 only apply to two cases: (a) cases in which the lines to be included in a list item begin with a non-space character, and (b) cases in which they begin with an indented code block. In a case like the following, where the first block begins with a three-space indent, the rules do not allow us to form a list item by indenting the whole thing and prepending a list marker:</p>
<div id="example-167" class="example" data-section="List items">
<div class="examplenum">
Example 167
</div>
<pre class="markdown"><code> foo
bar</code></pre>
<pre class="html"><code>&lt;p&gt;foo&lt;/p&gt;
&lt;p&gt;bar&lt;/p&gt;</code></pre>
</div>
<div id="example-168" class="example" data-section="List items">
<div class="examplenum">
Example 168
</div>
<pre class="markdown"><code>- foo
bar</code></pre>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;foo&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;bar&lt;/p&gt;</code></pre>
</div>
<p>This is not a significant restriction, because when a block begins with 1-3 spaces indent, the indentation can always be removed without a change in interpretation, allowing rule #1 to be applied. So, in the above case:</p>
<div id="example-169" class="example" data-section="List items">
<div class="examplenum">
Example 169
</div>
<pre class="markdown"><code>- foo
bar</code></pre>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;&lt;p&gt;foo&lt;/p&gt;
&lt;p&gt;bar&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
<ol start="3" style="list-style-type: decimal">
<li><strong>Indentation.</strong> If a sequence of lines <em>Ls</em> constitutes a list item according to rule #1 or #2, then the result of indenting each line of <em>L</em> by 1-3 spaces (the same for each line) also constitutes a list item with the same contents and attributes. If a line is empty, then it need not be indented.</li>
</ol>
<p>Indented one space:</p>
<div id="example-170" class="example" data-section="List items">
<div class="examplenum">
Example 170
</div>
<pre class="markdown"><code> 1. A paragraph
with two lines.
indented code
&gt; A block quote.</code></pre>
<pre class="html"><code>&lt;ol&gt;
&lt;li&gt;&lt;p&gt;A paragraph
with two lines.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;indented code
&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;A block quote.&lt;/p&gt;
&lt;/blockquote&gt;&lt;/li&gt;
&lt;/ol&gt;</code></pre>
</div>
<p>Indented two spaces:</p>
<div id="example-171" class="example" data-section="List items">
<div class="examplenum">
Example 171
</div>
<pre class="markdown"><code> 1. A paragraph
with two lines.
indented code
&gt; A block quote.</code></pre>
<pre class="html"><code>&lt;ol&gt;
&lt;li&gt;&lt;p&gt;A paragraph
with two lines.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;indented code
&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;A block quote.&lt;/p&gt;
&lt;/blockquote&gt;&lt;/li&gt;
&lt;/ol&gt;</code></pre>
</div>
<p>Indented three spaces:</p>
<div id="example-172" class="example" data-section="List items">
<div class="examplenum">
Example 172
</div>
<pre class="markdown"><code> 1. A paragraph
with two lines.
indented code
&gt; A block quote.</code></pre>
<pre class="html"><code>&lt;ol&gt;
&lt;li&gt;&lt;p&gt;A paragraph
with two lines.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;indented code
&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;A block quote.&lt;/p&gt;
&lt;/blockquote&gt;&lt;/li&gt;
&lt;/ol&gt;</code></pre>
</div>
<p>Four spaces indent gives a code block:</p>
<div id="example-173" class="example" data-section="List items">
<div class="examplenum">
Example 173
</div>
<pre class="markdown"><code> 1. A paragraph
with two lines.
indented code
&gt; A block quote.</code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code&gt;1. A paragraph
with two lines.
indented code
&amp;gt; A block quote.
&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<ol start="4" style="list-style-type: decimal">
<li><strong>Laziness.</strong> If a string of lines <em>Ls</em> constitute a <a href="#list-item">list item</a> with contents <em>Bs</em>, then the result of deleting some or all of the indentation from one or more lines in which the next non-space character after the indentation is <a href="#paragraph-continuation-text">paragraph continuation text</a> is a list item with the same contents and attributes.</li>
</ol>
<p>Here is an example with lazy continuation lines:</p>
<div id="example-174" class="example" data-section="List items">
<div class="examplenum">
Example 174
</div>
<pre class="markdown"><code> 1. A paragraph
with two lines.
indented code
&gt; A block quote.</code></pre>
<pre class="html"><code>&lt;ol&gt;
&lt;li&gt;&lt;p&gt;A paragraph
with two lines.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;indented code
&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;A block quote.&lt;/p&gt;
&lt;/blockquote&gt;&lt;/li&gt;
&lt;/ol&gt;</code></pre>
</div>
<p>Indentation can be partially deleted:</p>
<div id="example-175" class="example" data-section="List items">
<div class="examplenum">
Example 175
</div>
<pre class="markdown"><code> 1. A paragraph
with two lines.</code></pre>
<pre class="html"><code>&lt;ol&gt;
&lt;li&gt;A paragraph
with two lines.&lt;/li&gt;
&lt;/ol&gt;</code></pre>
</div>
<p>These examples show how laziness can work in nested structures:</p>
<div id="example-176" class="example" data-section="List items">
<div class="examplenum">
Example 176
</div>
<pre class="markdown"><code>&gt; 1. &gt; Blockquote
continued here.</code></pre>
<pre class="html"><code>&lt;blockquote&gt;
&lt;ol&gt;
&lt;li&gt;&lt;blockquote&gt;
&lt;p&gt;Blockquote
continued here.&lt;/p&gt;
&lt;/blockquote&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;</code></pre>
</div>
<div id="example-177" class="example" data-section="List items">
<div class="examplenum">
Example 177
</div>
<pre class="markdown"><code>&gt; 1. &gt; Blockquote
&gt; continued here.</code></pre>
<pre class="html"><code>&lt;blockquote&gt;
&lt;ol&gt;
&lt;li&gt;&lt;blockquote&gt;
&lt;p&gt;Blockquote
continued here.&lt;/p&gt;
&lt;/blockquote&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;</code></pre>
</div>
<ol start="5" style="list-style-type: decimal">
<li><strong>That’s all.</strong> Nothing that is not counted as a list item by rules #1–4 counts as a <a href="#list-item">list item</a>.</li>
</ol>
<p>The rules for sublists follow from the general rules above. A sublist must be indented the same number of spaces a paragraph would need to be in order to be included in the list item.</p>
<p>So, in this case we need two spaces indent:</p>
<div id="example-178" class="example" data-section="List items">
<div class="examplenum">
Example 178
</div>
<pre class="markdown"><code>- foo
- bar
- baz</code></pre>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;foo
&lt;ul&gt;
&lt;li&gt;bar
&lt;ul&gt;
&lt;li&gt;baz&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
<p>One is not enough:</p>
<div id="example-179" class="example" data-section="List items">
<div class="examplenum">
Example 179
</div>
<pre class="markdown"><code>- foo
- bar
- baz</code></pre>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;foo&lt;/li&gt;
&lt;li&gt;bar&lt;/li&gt;
&lt;li&gt;baz&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
<p>Here we need four, because the list marker is wider:</p>
<div id="example-180" class="example" data-section="List items">
<div class="examplenum">
Example 180
</div>
<pre class="markdown"><code>10) foo
- bar</code></pre>
<pre class="html"><code>&lt;ol start=&quot;10&quot;&gt;
&lt;li&gt;foo
&lt;ul&gt;
&lt;li&gt;bar&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ol&gt;</code></pre>
</div>
<p>Three is not enough:</p>
<div id="example-181" class="example" data-section="List items">
<div class="examplenum">
Example 181
</div>
<pre class="markdown"><code>10) foo
- bar</code></pre>
<pre class="html"><code>&lt;ol start=&quot;10&quot;&gt;
&lt;li&gt;foo&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li&gt;bar&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
<p>A list may be the first block in a list item:</p>
<div id="example-182" class="example" data-section="List items">
<div class="examplenum">
Example 182
</div>
<pre class="markdown"><code>- - foo</code></pre>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;&lt;ul&gt;
&lt;li&gt;foo&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
<div id="example-183" class="example" data-section="List items">
<div class="examplenum">
Example 183
</div>
<pre class="markdown"><code>1. - 2. foo</code></pre>
<pre class="html"><code>&lt;ol&gt;
&lt;li&gt;&lt;ul&gt;
&lt;li&gt;&lt;ol start=&quot;2&quot;&gt;
&lt;li&gt;foo&lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ol&gt;</code></pre>
</div>
<p>A list item may be empty:</p>
<div id="example-184" class="example" data-section="List items">
<div class="examplenum">
Example 184
</div>
<pre class="markdown"><code>- foo
-
- bar</code></pre>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;foo&lt;/li&gt;
&lt;li&gt;&lt;/li&gt;
&lt;li&gt;bar&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
<div id="example-185" class="example" data-section="List items">
<div class="examplenum">
Example 185
</div>
<pre class="markdown"><code>-</code></pre>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
<h3 id="motivation"><span class="header-section-number">5.2.1</span> Motivation</h3>
<p>John Gruber’s Markdown spec says the following about list items:</p>
<ol style="list-style-type: decimal">
<li><p>“List markers typically start at the left margin, but may be indented by up to three spaces. List markers must be followed by one or more spaces or a tab.”</p></li>
<li><p>“To make lists look nice, you can wrap items with hanging indents…. But if you don’t want to, you don’t have to.”</p></li>
<li><p>“List items may consist of multiple paragraphs. Each subsequent paragraph in a list item must be indented by either 4 spaces or one tab.”</p></li>
<li><p>“It looks nice if you indent every line of the subsequent paragraphs, but here again, Markdown will allow you to be lazy.”</p></li>
<li><p>“To put a blockquote within a list item, the blockquote’s <code>&gt;</code> delimiters need to be indented.”</p></li>
<li><p>“To put a code block within a list item, the code block needs to be indented twice — 8 spaces or two tabs.”</p></li>
</ol>
<p>These rules specify that a paragraph under a list item must be indented four spaces (presumably, from the left margin, rather than the start of the list marker, but this is not said), and that code under a list item must be indented eight spaces instead of the usual four. They also say that a block quote must be indented, but not by how much; however, the example given has four spaces indentation. Although nothing is said about other kinds of block-level content, it is certainly reasonable to infer that <em>all</em> block elements under a list item, including other lists, must be indented four spaces. This principle has been called the <em>four-space rule</em>.</p>
<p>The four-space rule is clear and principled, and if the reference implementation <code>Markdown.pl</code> had followed it, it probably would have become the standard. However, <code>Markdown.pl</code> allowed paragraphs and sublists to start with only two spaces indentation, at least on the outer level. Worse, its behavior was inconsistent: a sublist of an outer-level list needed two spaces indentation, but a sublist of this sublist needed three spaces. It is not surprising, then, that different implementations of Markdown have developed very different rules for determining what comes under a list item. (Pandoc and python-Markdown, for example, stuck with Gruber’s syntax description and the four-space rule, while discount, redcarpet, marked, PHP Markdown, and others followed <code>Markdown.pl</code>’s behavior more closely.)</p>
<p>Unfortunately, given the divergences between implementations, there is no way to give a spec for list items that will be guaranteed not to break any existing documents. However, the spec given here should correctly handle lists formatted with either the four-space rule or the more forgiving <code>Markdown.pl</code> behavior, provided they are laid out in a way that is natural for a human to read.</p>
<p>The strategy here is to let the width and indentation of the list marker determine the indentation necessary for blocks to fall under the list item, rather than having a fixed and arbitrary number. The writer can think of the body of the list item as a unit which gets indented to the right enough to fit the list marker (and any indentation on the list marker). (The laziness rule, #4, then allows continuation lines to be unindented if needed.)</p>
<p>This rule is superior, we claim, to any rule requiring a fixed level of indentation from the margin. The four-space rule is clear but unnatural. It is quite unintuitive that</p>
<pre class="markdown"><code>- foo
bar
- baz</code></pre>
<p>should be parsed as two lists with an intervening paragraph,</p>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;foo&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;bar&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;baz&lt;/li&gt;
&lt;/ul&gt;</code></pre>
<p>as the four-space rule demands, rather than a single list,</p>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;&lt;p&gt;foo&lt;/p&gt;
&lt;p&gt;bar&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;baz&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;</code></pre>
<p>The choice of four spaces is arbitrary. It can be learned, but it is not likely to be guessed, and it trips up beginners regularly.</p>
<p>Would it help to adopt a two-space rule? The problem is that such a rule, together with the rule allowing 1–3 spaces indentation of the initial list marker, allows text that is indented <em>less than</em> the original list marker to be included in the list item. For example, <code>Markdown.pl</code> parses</p>
<pre class="markdown"><code> - one
two</code></pre>
<p>as a single list item, with <code>two</code> a continuation paragraph:</p>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;&lt;p&gt;one&lt;/p&gt;
&lt;p&gt;two&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;</code></pre>
<p>and similarly</p>
<pre class="markdown"><code>&gt; - one
&gt;
&gt; two</code></pre>
<p>as</p>
<pre class="html"><code>&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;one&lt;/p&gt;
&lt;p&gt;two&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;</code></pre>
<p>This is extremely unintuitive.</p>
<p>Rather than requiring a fixed indent from the margin, we could require a fixed indent (say, two spaces, or even one space) from the list marker (which may itself be indented). This proposal would remove the last anomaly discussed. Unlike the spec presented above, it would count the following as a list item with a subparagraph, even though the paragraph <code>bar</code> is not indented as far as the first paragraph <code>foo</code>:</p>
<pre class="markdown"><code> 10. foo
bar </code></pre>
<p>Arguably this text does read like a list item with <code>bar</code> as a subparagraph, which may count in favor of the proposal. However, on this proposal indented code would have to be indented six spaces after the list marker. And this would break a lot of existing Markdown, which has the pattern:</p>
<pre class="markdown"><code>1. foo
indented code</code></pre>
<p>where the code is indented eight spaces. The spec above, by contrast, will parse this text as expected, since the code block’s indentation is measured from the beginning of <code>foo</code>.</p>
<p>The one case that needs special treatment is a list item that <em>starts</em> with indented code. How much indentation is required in that case, since we don’t have a “first paragraph” to measure from? Rule #2 simply stipulates that in such cases, we require one space indentation from the list marker (and then the normal four spaces for the indented code). This will match the four-space rule in cases where the list marker plus its initial indentation takes four spaces (a common case), but diverge in other cases.</p>
<h2 id="lists"><span class="header-section-number">5.3</span> Lists</h2>
<p>A <a href="#list">list</a> <a id="list"></a> is a sequence of one or more list items <a href="#of-the-same-type">of the same type</a>. The list items may be separated by single <a href="#blank-line">blank lines</a>, but two blank lines end all containing lists.</p>
<p>Two list items are <a href="#of-the-same-type">of the same type</a> <a id="of-the-same-type"></a> if they begin with a <a href="#list-marker">list marker</a> of the same type. Two list markers are of the same type if (a) they are bullet list markers using the same character (<code>-</code>, <code>+</code>, or <code>*</code>) or (b) they are ordered list numbers with the same delimiter (either <code>.</code> or <code>)</code>).</p>
<p>A list is an <a href="#ordered-list">ordered list</a> <a id="ordered-list"></a> if its constituent list items begin with <a href="#ordered-list-marker">ordered list markers</a>, and a <a href="#bullet-list">bullet list</a> <a id="bullet-list"></a> if its constituent list items begin with <a href="#bullet-list-marker">bullet list markers</a>.</p>
<p>The <a href="#start-number">start number</a> <a id="start-number"></a> of an <a href="#ordered-list">ordered list</a> is determined by the list number of its initial list item. The numbers of subsequent list items are disregarded.</p>
<p>A list is <a href="#loose">loose</a> if it any of its constituent list items are separated by blank lines, or if any of its constituent list items directly contain two block-level elements with a blank line between them. Otherwise a list is <a href="#tight">tight</a>. (The difference in HTML output is that paragraphs in a loose with are wrapped in <code>&lt;p&gt;</code> tags, while paragraphs in a tight list are not.)</p>
<p>Changing the bullet or ordered list delimiter starts a new list:</p>
<div id="example-186" class="example" data-section="Lists">
<div class="examplenum">
Example 186
</div>
<pre class="markdown"><code>- foo
- bar
+ baz</code></pre>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;foo&lt;/li&gt;
&lt;li&gt;bar&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;baz&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
<div id="example-187" class="example" data-section="Lists">
<div class="examplenum">
Example 187
</div>
<pre class="markdown"><code>1. foo
2. bar
3) baz</code></pre>
<pre class="html"><code>&lt;ol&gt;
&lt;li&gt;foo&lt;/li&gt;
&lt;li&gt;bar&lt;/li&gt;
&lt;/ol&gt;
&lt;ol start=&quot;3&quot;&gt;
&lt;li&gt;baz&lt;/li&gt;
&lt;/ol&gt;</code></pre>
</div>
<p>There can be blank lines between items, but two blank lines end a list:</p>
<div id="example-188" class="example" data-section="Lists">
<div class="examplenum">
Example 188
</div>
<pre class="markdown"><code>- foo
- bar
- baz</code></pre>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;&lt;p&gt;foo&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;bar&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;baz&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
<p>As illustrated above in the section on <a href="#list-item">list items</a>, two blank lines between blocks <em>within</em> a list item will also end a list:</p>
<div id="example-189" class="example" data-section="Lists">
<div class="examplenum">
Example 189
</div>
<pre class="markdown"><code>- foo
bar
- baz</code></pre>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;foo&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;bar&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;baz&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
<p>Indeed, two blank lines will end <em>all</em> containing lists:</p>
<div id="example-190" class="example" data-section="Lists">
<div class="examplenum">
Example 190
</div>
<pre class="markdown"><code>- foo
- bar
- baz
bim</code></pre>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;foo
&lt;ul&gt;
&lt;li&gt;bar
&lt;ul&gt;
&lt;li&gt;baz&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code&gt; bim
&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<p>Thus, two blank lines can be used to separate consecutive lists of the same type, or to separate a list from an indented code block that would otherwise be parsed as a subparagraph of the final list item:</p>
<div id="example-191" class="example" data-section="Lists">
<div class="examplenum">
Example 191
</div>
<pre class="markdown"><code>- foo
- bar
- baz
- bim</code></pre>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;foo&lt;/li&gt;
&lt;li&gt;bar&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;baz&lt;/li&gt;
&lt;li&gt;bim&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
<div id="example-192" class="example" data-section="Lists">
<div class="examplenum">
Example 192
</div>
<pre class="markdown"><code>- foo
notcode
- foo
code</code></pre>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;&lt;p&gt;foo&lt;/p&gt;
&lt;p&gt;notcode&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;foo&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code&gt;code
&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<p>List items need not be indented to the same level. The following list items will be treated as items at the same list level, since none is indented enough to belong to the previous list item:</p>
<div id="example-193" class="example" data-section="Lists">
<div class="examplenum">
Example 193
</div>
<pre class="markdown"><code>- a
- b
- c
- d
- e
- f
- g</code></pre>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;a&lt;/li&gt;
&lt;li&gt;b&lt;/li&gt;
&lt;li&gt;c&lt;/li&gt;
&lt;li&gt;d&lt;/li&gt;
&lt;li&gt;e&lt;/li&gt;
&lt;li&gt;f&lt;/li&gt;
&lt;li&gt;g&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
<p>This is a loose list, because there is a blank line between two of the list items:</p>
<div id="example-194" class="example" data-section="Lists">
<div class="examplenum">
Example 194
</div>
<pre class="markdown"><code>- a
- b
- c</code></pre>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;&lt;p&gt;a&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;b&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;c&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
<p>So is this, with a empty second item:</p>
<div id="example-195" class="example" data-section="Lists">
<div class="examplenum">
Example 195
</div>
<pre class="markdown"><code>* a
*
* c</code></pre>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;&lt;p&gt;a&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;c&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
<p>These are loose lists, even though there is no space between the items, because one of the items directly contains two block-level elements with a blank line between them:</p>
<div id="example-196" class="example" data-section="Lists">
<div class="examplenum">
Example 196
</div>
<pre class="markdown"><code>- a
- b
c
- d</code></pre>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;&lt;p&gt;a&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;b&lt;/p&gt;
&lt;p&gt;c&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;d&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
<div id="example-197" class="example" data-section="Lists">
<div class="examplenum">
Example 197
</div>
<pre class="markdown"><code>- a
- b
[ref]: /url
- d</code></pre>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;&lt;p&gt;a&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;b&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;d&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
<p>This is a tight list, because the blank lines are in a code block:</p>
<div id="example-198" class="example" data-section="Lists">
<div class="examplenum">
Example 198
</div>
<pre class="markdown"><code>- a
- ```
b
```
- c</code></pre>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;a&lt;/li&gt;
&lt;li&gt;&lt;pre&gt;&lt;code&gt;b
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;c&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
<p>This is a tight list, because the blank line is between two paragraphs of a sublist. So the inner list is loose while the other list is tight:</p>
<div id="example-199" class="example" data-section="Lists">
<div class="examplenum">
Example 199
</div>
<pre class="markdown"><code>- a
- b
c
- d</code></pre>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;a
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;b&lt;/p&gt;
&lt;p&gt;c&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;d&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
<p>This is a tight list, because the blank line is inside the block quote:</p>
<div id="example-200" class="example" data-section="Lists">
<div class="examplenum">
Example 200
</div>
<pre class="markdown"><code>* a
&gt; b
&gt;
* c</code></pre>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;a
&lt;blockquote&gt;
&lt;p&gt;b&lt;/p&gt;
&lt;/blockquote&gt;&lt;/li&gt;
&lt;li&gt;c&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
<p>This list is tight, because the consecutive block elements are not separated by blank lines:</p>
<div id="example-201" class="example" data-section="Lists">
<div class="examplenum">
Example 201
</div>
<pre class="markdown"><code>- a
&gt; b
```
c
```
- d</code></pre>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;a
&lt;blockquote&gt;
&lt;p&gt;b&lt;/p&gt;
&lt;/blockquote&gt;
&lt;pre&gt;&lt;code&gt;c
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;d&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
<p>A single-paragraph list is tight:</p>
<div id="example-202" class="example" data-section="Lists">
<div class="examplenum">
Example 202
</div>
<pre class="markdown"><code>- a</code></pre>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;a&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
<div id="example-203" class="example" data-section="Lists">
<div class="examplenum">
Example 203
</div>
<pre class="markdown"><code>- a
- b</code></pre>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;a
&lt;ul&gt;
&lt;li&gt;b&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
<p>Here the outer list is loose, the inner list tight:</p>
<div id="example-204" class="example" data-section="Lists">
<div class="examplenum">
Example 204
</div>
<pre class="markdown"><code>* foo
* bar
baz</code></pre>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;&lt;p&gt;foo&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;bar&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;baz&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
<div id="example-205" class="example" data-section="Lists">
<div class="examplenum">
Example 205
</div>
<pre class="markdown"><code>- a
- b
- c
- d
- e
- f</code></pre>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;&lt;p&gt;a&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;b&lt;/li&gt;
&lt;li&gt;c&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;d&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;e&lt;/li&gt;
&lt;li&gt;f&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
<h1 id="inlines"><span class="header-section-number">6</span> Inlines</h1>
<p>Inlines are parsed sequentially from the beginning of the character stream to the end (left to right, in left-to-right languages). Thus, for example, in</p>
<div id="example-206" class="example" data-section="Inlines">
<div class="examplenum">
Example 206
</div>
<pre class="markdown"><code>`hi`lo`</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;code&gt;hi&lt;/code&gt;lo`&lt;/p&gt;</code></pre>
</div>
<p><code>hi</code> is parsed as code, leaving the backtick at the end as a literal backtick.</p>
<h2 id="backslash-escapes"><span class="header-section-number">6.1</span> Backslash escapes</h2>
<p>Any ASCII punctuation character may be backslash-escaped:</p>
<div id="example-207" class="example" data-section="Backslash escapes">
<div class="examplenum">
Example 207
</div>
<pre class="markdown"><code>\!\&quot;\#\$\%\&amp;\&#39;\(\)\*\+\,\-\.\/\:\;\&lt;\=\&gt;\?\@\[\\\]\^\_\`\{\|\}\~</code></pre>
<pre class="html"><code>&lt;p&gt;!&amp;quot;#$%&amp;amp;&#39;()*+,-./:;&amp;lt;=&amp;gt;?@[\]^_`{|}~&lt;/p&gt;</code></pre>
</div>
<p>Backslashes before other characters are treated as literal backslashes:</p>
<div id="example-208" class="example" data-section="Backslash escapes">
<div class="examplenum">
Example 208
</div>
<pre class="markdown"><code>\→\A\a\ \3\φ\«</code></pre>
<pre class="html"><code>&lt;p&gt;\ \A\a\ \3\φ\«&lt;/p&gt;</code></pre>
</div>
<p>Escaped characters are treated as regular characters and do not have their usual Markdown meanings:</p>
<div id="example-209" class="example" data-section="Backslash escapes">
<div class="examplenum">
Example 209
</div>
<pre class="markdown"><code>\*not emphasized*
\&lt;br/&gt; not a tag
\[not a link](/foo)
\`not code`
1\. not a list
\* not a list
\# not a header
\[foo]: /url &quot;not a reference&quot;</code></pre>
<pre class="html"><code>&lt;p&gt;*not emphasized*
&amp;lt;br/&amp;gt; not a tag
[not a link](/foo)
`not code`
1. not a list
* not a list
# not a header
[foo]: /url &amp;quot;not a reference&amp;quot;&lt;/p&gt;</code></pre>
</div>
<p>If a backslash is itself escaped, the following character is not:</p>
<div id="example-210" class="example" data-section="Backslash escapes">
<div class="examplenum">
Example 210
</div>
<pre class="markdown"><code>\\*emphasis*</code></pre>
<pre class="html"><code>&lt;p&gt;\&lt;em&gt;emphasis&lt;/em&gt;&lt;/p&gt;</code></pre>
</div>
<p>A backslash at the end of the line is a hard line break:</p>
<div id="example-211" class="example" data-section="Backslash escapes">
<div class="examplenum">
Example 211
</div>
<pre class="markdown"><code>foo\
bar</code></pre>
<pre class="html"><code>&lt;p&gt;foo&lt;br /&gt;
bar&lt;/p&gt;</code></pre>
</div>
<p>Backslash escapes do not work in code blocks, code spans, autolinks, or raw HTML:</p>
<div id="example-212" class="example" data-section="Backslash escapes">
<div class="examplenum">
Example 212
</div>
<pre class="markdown"><code>`` \[\` ``</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;code&gt;\[\`&lt;/code&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-213" class="example" data-section="Backslash escapes">
<div class="examplenum">
Example 213
</div>
<pre class="markdown"><code> \[\]</code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code&gt;\[\]
&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<div id="example-214" class="example" data-section="Backslash escapes">
<div class="examplenum">
Example 214
</div>
<pre class="markdown"><code>~~~
\[\]
~~~</code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code&gt;\[\]
&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<div id="example-215" class="example" data-section="Backslash escapes">
<div class="examplenum">
Example 215
</div>
<pre class="markdown"><code>&lt;http://google.com?find=\*&gt;</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;http://google.com?find=\*&quot;&gt;http://google.com?find=\*&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-216" class="example" data-section="Backslash escapes">
<div class="examplenum">
Example 216
</div>
<pre class="markdown"><code>&lt;a href=&quot;/bar\/)&quot;&gt;</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;/bar\/)&quot;&gt;&lt;/p&gt;</code></pre>
</div>
<p>But they work in all other contexts, including URLs and link titles, link references, and info strings in <a href="#fenced-code-block">fenced code blocks</a>:</p>
<div id="example-217" class="example" data-section="Backslash escapes">
<div class="examplenum">
Example 217
</div>
<pre class="markdown"><code>[foo](/bar\* &quot;ti\*tle&quot;)</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;/bar*&quot; title=&quot;ti*tle&quot;&gt;foo&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-218" class="example" data-section="Backslash escapes">
<div class="examplenum">
Example 218
</div>
<pre class="markdown"><code>[foo]
[foo]: /bar\* &quot;ti\*tle&quot;</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;/bar*&quot; title=&quot;ti*tle&quot;&gt;foo&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-219" class="example" data-section="Backslash escapes">
<div class="examplenum">
Example 219
</div>
<pre class="markdown"><code>``` foo\+bar
foo
```</code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code class=&quot;language-foo+bar&quot;&gt;foo
&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<h2 id="entities"><span class="header-section-number">6.2</span> Entities</h2>
<p>Entities are parsed as entities, not as literal text, in all contexts except code spans and code blocks. Three kinds of entities are recognized.</p>
<p><a href="#name-entities">Named entities</a> <a id="named-entities"></a> consist of <code>&amp;</code> + a string of 2-32 alphanumerics beginning with a letter + <code>;</code>.</p>
<div id="example-220" class="example" data-section="Entities">
<div class="examplenum">
Example 220
</div>
<pre class="markdown"><code>&amp;nbsp; &amp;amp; &amp;copy; &amp;AElig; &amp;Dcaron; &amp;frac34; &amp;HilbertSpace; &amp;DifferentialD; &amp;ClockwiseContourIntegral;</code></pre>
<pre class="html"><code>&lt;p&gt;&amp;nbsp; &amp;amp; &amp;copy; &amp;AElig; &amp;Dcaron; &amp;frac34; &amp;HilbertSpace; &amp;DifferentialD; &amp;ClockwiseContourIntegral;&lt;/p&gt;</code></pre>
</div>
<p><a href="#decimal-entities">Decimal entities</a> <a id="decimal-entities"></a> consist of <code>&amp;#</code> + a string of 1–8 arabic digits + <code>;</code>.</p>
<div id="example-221" class="example" data-section="Entities">
<div class="examplenum">
Example 221
</div>
<pre class="markdown"><code>&amp;#1; &amp;#35; &amp;#1234; &amp;#992; &amp;#98765432;</code></pre>
<pre class="html"><code>&lt;p&gt;&amp;#1; &amp;#35; &amp;#1234; &amp;#992; &amp;#98765432;&lt;/p&gt;</code></pre>
</div>
<p><a href="#hexadecimal-entities">Hexadecimal entities</a> <a id="hexadecimal-entities"></a> consist of <code>&amp;#</code> + either <code>X</code> or <code>x</code> + a string of 1-8 hexadecimal digits + <code>;</code>.</p>
<div id="example-222" class="example" data-section="Entities">
<div class="examplenum">
Example 222
</div>
<pre class="markdown"><code>&amp;#x1; &amp;#X22; &amp;#XD06; &amp;#xcab;</code></pre>
<pre class="html"><code>&lt;p&gt;&amp;#x1; &amp;#X22; &amp;#XD06; &amp;#xcab;&lt;/p&gt;</code></pre>
</div>
<p>Here are some nonentities:</p>
<div id="example-223" class="example" data-section="Entities">
<div class="examplenum">
Example 223
</div>
<pre class="markdown"><code>&amp;nbsp &amp;x; &amp;#; &amp;#x; &amp;#123456789; &amp;ThisIsWayTooLongToBeAnEntityIsntIt; &amp;hi?;</code></pre>
<pre class="html"><code>&lt;p&gt;&amp;amp;nbsp &amp;amp;x; &amp;amp;#; &amp;amp;#x; &amp;amp;#123456789; &amp;amp;ThisIsWayTooLongToBeAnEntityIsntIt; &amp;amp;hi?;&lt;/p&gt;</code></pre>
</div>
<p>Although HTML5 does accept some entities without a trailing semicolon (such as <code>&amp;copy</code>), these are not recognized as entities here:</p>
<div id="example-224" class="example" data-section="Entities">
<div class="examplenum">
Example 224
</div>
<pre class="markdown"><code>&amp;copy</code></pre>
<pre class="html"><code>&lt;p&gt;&amp;amp;copy&lt;/p&gt;</code></pre>
</div>
<p>On the other hand, many strings that are not on the list of HTML5 named entities are recognized as entities here:</p>
<div id="example-225" class="example" data-section="Entities">
<div class="examplenum">
Example 225
</div>
<pre class="markdown"><code>&amp;MadeUpEntity;</code></pre>
<pre class="html"><code>&lt;p&gt;&amp;MadeUpEntity;&lt;/p&gt;</code></pre>
</div>
<p>Entities are recognized in any context besides code spans or code blocks, including raw HTML, URLs, <a href="#link-title">link titles</a>, and <a href="#fenced-code-block">fenced code block</a> info strings:</p>
<div id="example-226" class="example" data-section="Entities">
<div class="examplenum">
Example 226
</div>
<pre class="markdown"><code>&lt;a href=&quot;&amp;ouml;&amp;ouml;.html&quot;&gt;</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;&amp;ouml;&amp;ouml;.html&quot;&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-227" class="example" data-section="Entities">
<div class="examplenum">
Example 227
</div>
<pre class="markdown"><code>[foo](/f&amp;ouml;&amp;ouml; &quot;f&amp;ouml;&amp;ouml;&quot;)</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;/f&amp;ouml;&amp;ouml;&quot; title=&quot;f&amp;ouml;&amp;ouml;&quot;&gt;foo&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-228" class="example" data-section="Entities">
<div class="examplenum">
Example 228
</div>
<pre class="markdown"><code>[foo]
[foo]: /f&amp;ouml;&amp;ouml; &quot;f&amp;ouml;&amp;ouml;&quot;</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;/f&amp;ouml;&amp;ouml;&quot; title=&quot;f&amp;ouml;&amp;ouml;&quot;&gt;foo&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-229" class="example" data-section="Entities">
<div class="examplenum">
Example 229
</div>
<pre class="markdown"><code>``` f&amp;ouml;&amp;ouml;
foo
```</code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code class=&quot;language-f&amp;ouml;&amp;ouml;&quot;&gt;foo
&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<p>Entities are treated as literal text in code spans and code blocks:</p>
<div id="example-230" class="example" data-section="Entities">
<div class="examplenum">
Example 230
</div>
<pre class="markdown"><code>`f&amp;ouml;&amp;ouml;`</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;code&gt;f&amp;amp;ouml;&amp;amp;ouml;&lt;/code&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-231" class="example" data-section="Entities">
<div class="examplenum">
Example 231
</div>
<pre class="markdown"><code> f&amp;ouml;f&amp;ouml;</code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code&gt;f&amp;amp;ouml;f&amp;amp;ouml;
&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<h2 id="code-span"><span class="header-section-number">6.3</span> Code span</h2>
<p>A <a href="#backtick-string">backtick string</a> <a id="backtick-string"></a> is a string of one or more backtick characters (<code>`</code>) that is neither preceded nor followed by a backtick.</p>
<p>A code span begins with a backtick string and ends with a backtick string of equal length. The contents of the code span are the characters between the two backtick strings, with leading and trailing spaces and newlines removed, and consecutive spaces and newlines collapsed to single spaces.</p>
<p>This is a simple code span:</p>
<div id="example-232" class="example" data-section="Code span">
<div class="examplenum">
Example 232
</div>
<pre class="markdown"><code>`foo`</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;code&gt;foo&lt;/code&gt;&lt;/p&gt;</code></pre>
</div>
<p>Here two backticks are used, because the code contains a backtick. This example also illustrates stripping of leading and trailing spaces:</p>
<div id="example-233" class="example" data-section="Code span">
<div class="examplenum">
Example 233
</div>
<pre class="markdown"><code>`` foo ` bar ``</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;code&gt;foo ` bar&lt;/code&gt;&lt;/p&gt;</code></pre>
</div>
<p>This example shows the motivation for stripping leading and trailing spaces:</p>
<div id="example-234" class="example" data-section="Code span">
<div class="examplenum">
Example 234
</div>
<pre class="markdown"><code>` `` `</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;code&gt;``&lt;/code&gt;&lt;/p&gt;</code></pre>
</div>
<p>Newlines are treated like spaces:</p>
<div id="example-235" class="example" data-section="Code span">
<div class="examplenum">
Example 235
</div>
<pre class="markdown"><code>``
foo
``</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;code&gt;foo&lt;/code&gt;&lt;/p&gt;</code></pre>
</div>
<p>Interior spaces and newlines are collapsed into single spaces, just as they would be by a browser:</p>
<div id="example-236" class="example" data-section="Code span">
<div class="examplenum">
Example 236
</div>
<pre class="markdown"><code>`foo bar
baz`</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;code&gt;foo bar baz&lt;/code&gt;&lt;/p&gt;</code></pre>
</div>
<p>Q: Why not just leave the spaces, since browsers will collapse them anyway? A: Because we might be targeting a non-HTML format, and we shouldn’t rely on HTML-specific rendering assumptions.</p>
<p>(Existing implementations differ in their treatment of internal spaces and newlines. Some, including <code>Markdown.pl</code> and <code>showdown</code>, convert an internal newline into a <code>&lt;br /&gt;</code> tag. But this makes things difficult for those who like to hard-wrap their paragraphs, since a line break in the midst of a code span will cause an unintended line break in the output. Others just leave internal spaces as they are, which is fine if only HTML is being targeted.)</p>
<div id="example-237" class="example" data-section="Code span">
<div class="examplenum">
Example 237
</div>
<pre class="markdown"><code>`foo `` bar`</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;code&gt;foo `` bar&lt;/code&gt;&lt;/p&gt;</code></pre>
</div>
<p>Note that backslash escapes do not work in code spans. All backslashes are treated literally:</p>
<div id="example-238" class="example" data-section="Code span">
<div class="examplenum">
Example 238
</div>
<pre class="markdown"><code>`foo\`bar`</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;code&gt;foo\&lt;/code&gt;bar`&lt;/p&gt;</code></pre>
</div>
<p>Backslash escapes are never needed, because one can always choose a string of <em>n</em> backtick characters as delimiters, where the code does not contain any strings of exactly <em>n</em> backtick characters.</p>
<p>Code span backticks have higher precedence than any other inline constructs except HTML tags and autolinks. Thus, for example, this is not parsed as emphasized text, since the second <code>*</code> is part of a code span:</p>
<div id="example-239" class="example" data-section="Code span">
<div class="examplenum">
Example 239
</div>
<pre class="markdown"><code>*foo`*`</code></pre>
<pre class="html"><code>&lt;p&gt;*foo&lt;code&gt;*&lt;/code&gt;&lt;/p&gt;</code></pre>
</div>
<p>And this is not parsed as a link:</p>
<div id="example-240" class="example" data-section="Code span">
<div class="examplenum">
Example 240
</div>
<pre class="markdown"><code>[not a `link](/foo`)</code></pre>
<pre class="html"><code>&lt;p&gt;[not a &lt;code&gt;link](/foo&lt;/code&gt;)&lt;/p&gt;</code></pre>
</div>
<p>But this is a link:</p>
<div id="example-241" class="example" data-section="Code span">
<div class="examplenum">
Example 241
</div>
<pre class="markdown"><code>&lt;http://foo.bar.`baz&gt;`</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;http://foo.bar.`baz&quot;&gt;http://foo.bar.`baz&lt;/a&gt;`&lt;/p&gt;</code></pre>
</div>
<p>And this is an HTML tag:</p>
<div id="example-242" class="example" data-section="Code span">
<div class="examplenum">
Example 242
</div>
<pre class="markdown"><code>&lt;a href=&quot;`&quot;&gt;`</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;`&quot;&gt;`&lt;/p&gt;</code></pre>
</div>
<p>When a backtick string is not closed by a matching backtick string, we just have literal backticks:</p>
<div id="example-243" class="example" data-section="Code span">
<div class="examplenum">
Example 243
</div>
<pre class="markdown"><code>```foo``</code></pre>
<pre class="html"><code>&lt;p&gt;```foo``&lt;/p&gt;</code></pre>
</div>
<div id="example-244" class="example" data-section="Code span">
<div class="examplenum">
Example 244
</div>
<pre class="markdown"><code>`foo</code></pre>
<pre class="html"><code>&lt;p&gt;`foo&lt;/p&gt;</code></pre>
</div>
<h2 id="emphasis-and-strong-emphasis"><span class="header-section-number">6.4</span> Emphasis and strong emphasis</h2>
<p>John Gruber’s original <a href="http://daringfireball.net/projects/markdown/syntax#em">Markdown syntax description</a> says:</p>
<blockquote>
<p>Markdown treats asterisks (<code>*</code>) and underscores (<code>_</code>) as indicators of emphasis. Text wrapped with one <code>*</code> or <code>_</code> will be wrapped with an HTML <code>&lt;em&gt;</code> tag; double <code>*</code>’s or <code>_</code>’s will be wrapped with an HTML <code>&lt;strong&gt;</code> tag.</p>
</blockquote>
<p>This is enough for most users, but these rules leave much undecided, especially when it comes to nested emphasis. The original <code>Markdown.pl</code> test suite makes it clear that triple <code>***</code> and <code>___</code> delimiters can be used for strong emphasis, and most implementations have also allowed the following patterns:</p>
<pre class="markdown"><code>***strong emph***
***strong** in emph*
***emph* in strong**
**in strong *emph***
*in emph **strong***</code></pre>
<p>The following patterns are less widely supported, but the intent is clear and they are useful (especially in contexts like bibliography entries):</p>
<pre class="markdown"><code>*emph *with emph* in it*
**strong **with strong** in it**</code></pre>
<p>Many implementations have also restricted intraword emphasis to the <code>*</code> 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.)</p>
<pre class="markdown"><code>internal emphasis: foo*bar*baz
no emphasis: foo_bar_baz</code></pre>
<p>The following rules capture all of these patterns, while allowing for efficient parsing strategies that do not backtrack:</p>
<ol style="list-style-type: decimal">
<li><p>A single <code>*</code> character <a href="#can-open-emphasis">can open emphasis</a> <a id="can-open-emphasis"></a> iff</p>
<ol style="list-style-type: lower-alpha">
<li>it is not part of a sequence of four or more unescaped <code>*</code>s,</li>
<li>it is not followed by whitespace, and</li>
<li>either it is not followed by a <code>*</code> character or it is followed immediately by strong emphasis.</li>
</ol></li>
<li><p>A single <code>_</code> character <a href="#can-open-emphasis">can open emphasis</a> iff</p>
<ol style="list-style-type: lower-alpha">
<li>it is not part of a sequence of four or more unescaped <code>_</code>s,</li>
<li>it is not followed by whitespace,</li>
<li>is is not preceded by an ASCII alphanumeric character, and</li>
<li>either it is not followed by a <code>_</code> character or it is followed immediately by strong emphasis.</li>
</ol></li>
<li><p>A single <code>*</code> character <a href="#can-close-emphasis">can close emphasis</a> <a id="can-close-emphasis"></a> iff</p>
<ol style="list-style-type: lower-alpha">
<li>it is not part of a sequence of four or more unescaped <code>*</code>s, and</li>
<li>it is not preceded by whitespace.</li>
</ol></li>
<li><p>A single <code>_</code> character <a href="#can-close-emphasis">can close emphasis</a> iff</p>
<ol style="list-style-type: lower-alpha">
<li>it is not part of a sequence of four or more unescaped <code>_</code>s,</li>
<li>it is not preceded by whitespace, and</li>
<li>it is not followed by an ASCII alphanumeric character.</li>
</ol></li>
<li><p>A double <code>**</code> <a href="#can-open-strong-emphasis">can open strong emphasis</a> <a id="can-open-strong-emphasis" ></a> iff</p>
<ol style="list-style-type: lower-alpha">
<li>it is not part of a sequence of four or more unescaped <code>*</code>s,</li>
<li>it is not followed by whitespace, and</li>
<li>either it is not followed by a <code>*</code> character or it is followed immediately by emphasis.</li>
</ol></li>
<li><p>A double <code>__</code> <a href="#can-open-strong-emphasis">can open strong emphasis</a> iff</p>
<ol style="list-style-type: lower-alpha">
<li>it is not part of a sequence of four or more unescaped <code>_</code>s,</li>
<li>it is not followed by whitespace, and</li>
<li>it is not preceded by an ASCII alphanumeric character, and</li>
<li>either it is not followed by a <code>_</code> character or it is followed immediately by emphasis.</li>
</ol></li>
<li><p>A double <code>**</code> <a href="#can-close-strong-emphasis">can close strong emphasis</a> <a id="can-close-strong-emphasis" ></a> iff</p>
<ol style="list-style-type: lower-alpha">
<li>it is not part of a sequence of four or more unescaped <code>*</code>s, and</li>
<li>it is not preceded by whitespace.</li>
</ol></li>
<li><p>A double <code>__</code> <a href="#can-close-strong-emphasis">can close strong emphasis</a> iff</p>
<ol style="list-style-type: lower-alpha">
<li>it is not part of a sequence of four or more unescaped <code>_</code>s,</li>
<li>it is not preceded by whitespace, and</li>
<li>it is not followed by an ASCII alphanumeric character.</li>
</ol></li>
<li><p>Emphasis begins with a delimiter that <a href="#can-open-emphasis">can open emphasis</a> and includes inlines parsed sequentially until a delimiter that <a href="#can-close-emphasis">can close emphasis</a>, and that uses the same character (<code>_</code> or <code>*</code>) as the opening delimiter, is reached.</p></li>
<li><p>Strong emphasis begins with a delimiter that <a href="#can-open-strong-emphasis">can open strong emphasis</a> and includes inlines parsed sequentially until a delimiter that <a href="#can-close-strong-emphasis">can close strong emphasis</a>, and that uses the same character (<code>_</code> or <code>*</code>) as the opening delimiter, is reached.</p></li>
</ol>
<p>These rules can be illustrated through a series of examples.</p>
<p>Simple emphasis:</p>
<div id="example-245" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 245
</div>
<pre class="markdown"><code>*foo bar*</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;em&gt;foo bar&lt;/em&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-246" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 246
</div>
<pre class="markdown"><code>_foo bar_</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;em&gt;foo bar&lt;/em&gt;&lt;/p&gt;</code></pre>
</div>
<p>Simple strong emphasis:</p>
<div id="example-247" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 247
</div>
<pre class="markdown"><code>**foo bar**</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;strong&gt;foo bar&lt;/strong&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-248" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 248
</div>
<pre class="markdown"><code>__foo bar__</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;strong&gt;foo bar&lt;/strong&gt;&lt;/p&gt;</code></pre>
</div>
<p>Emphasis can continue over line breaks:</p>
<div id="example-249" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 249
</div>
<pre class="markdown"><code>*foo
bar*</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;em&gt;foo
bar&lt;/em&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-250" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 250
</div>
<pre class="markdown"><code>_foo
bar_</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;em&gt;foo
bar&lt;/em&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-251" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 251
</div>
<pre class="markdown"><code>**foo
bar**</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;strong&gt;foo
bar&lt;/strong&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-252" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 252
</div>
<pre class="markdown"><code>__foo
bar__</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;strong&gt;foo
bar&lt;/strong&gt;&lt;/p&gt;</code></pre>
</div>
<p>Emphasis can contain other inline constructs:</p>
<div id="example-253" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 253
</div>
<pre class="markdown"><code>*foo [bar](/url)*</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;em&gt;foo &lt;a href=&quot;/url&quot;&gt;bar&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-254" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 254
</div>
<pre class="markdown"><code>_foo [bar](/url)_</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;em&gt;foo &lt;a href=&quot;/url&quot;&gt;bar&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-255" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 255
</div>
<pre class="markdown"><code>**foo [bar](/url)**</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;strong&gt;foo &lt;a href=&quot;/url&quot;&gt;bar&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-256" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 256
</div>
<pre class="markdown"><code>__foo [bar](/url)__</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;strong&gt;foo &lt;a href=&quot;/url&quot;&gt;bar&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;</code></pre>
</div>
<p>Symbols contained in other inline constructs will not close emphasis:</p>
<div id="example-257" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 257
</div>
<pre class="markdown"><code>*foo [bar*](/url)</code></pre>
<pre class="html"><code>&lt;p&gt;*foo &lt;a href=&quot;/url&quot;&gt;bar*&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-258" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 258
</div>
<pre class="markdown"><code>_foo [bar_](/url)</code></pre>
<pre class="html"><code>&lt;p&gt;_foo &lt;a href=&quot;/url&quot;&gt;bar_&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-259" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 259
</div>
<pre class="markdown"><code>**&lt;a href=&quot;**&quot;&gt;</code></pre>
<pre class="html"><code>&lt;p&gt;**&lt;a href=&quot;**&quot;&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-260" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 260
</div>
<pre class="markdown"><code>__&lt;a href=&quot;__&quot;&gt;</code></pre>
<pre class="html"><code>&lt;p&gt;__&lt;a href=&quot;__&quot;&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-261" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 261
</div>
<pre class="markdown"><code>*a `*`*</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;em&gt;a &lt;code&gt;*&lt;/code&gt;&lt;/em&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-262" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 262
</div>
<pre class="markdown"><code>_a `_`_</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;em&gt;a &lt;code&gt;_&lt;/code&gt;&lt;/em&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-263" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 263
</div>
<pre class="markdown"><code>**a&lt;http://foo.bar?q=**&gt;</code></pre>
<pre class="html"><code>&lt;p&gt;**a&lt;a href=&quot;http://foo.bar?q=**&quot;&gt;http://foo.bar?q=**&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-264" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 264
</div>
<pre class="markdown"><code>__a&lt;http://foo.bar?q=__&gt;</code></pre>
<pre class="html"><code>&lt;p&gt;__a&lt;a href=&quot;http://foo.bar?q=__&quot;&gt;http://foo.bar?q=__&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<p>This is not emphasis, because the opening delimiter is followed by white space:</p>
<div id="example-265" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 265
</div>
<pre class="markdown"><code>and * foo bar*</code></pre>
<pre class="html"><code>&lt;p&gt;and * foo bar*&lt;/p&gt;</code></pre>
</div>
<div id="example-266" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 266
</div>
<pre class="markdown"><code>_ foo bar_</code></pre>
<pre class="html"><code>&lt;p&gt;_ foo bar_&lt;/p&gt;</code></pre>
</div>
<div id="example-267" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 267
</div>
<pre class="markdown"><code>and ** foo bar**</code></pre>
<pre class="html"><code>&lt;p&gt;and ** foo bar**&lt;/p&gt;</code></pre>
</div>
<div id="example-268" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 268
</div>
<pre class="markdown"><code>__ foo bar__</code></pre>
<pre class="html"><code>&lt;p&gt;__ foo bar__&lt;/p&gt;</code></pre>
</div>
<p>This is not emphasis, because the closing delimiter is preceded by white space:</p>
<div id="example-269" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 269
</div>
<pre class="markdown"><code>and *foo bar *</code></pre>
<pre class="html"><code>&lt;p&gt;and *foo bar *&lt;/p&gt;</code></pre>
</div>
<div id="example-270" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 270
</div>
<pre class="markdown"><code>and _foo bar _</code></pre>
<pre class="html"><code>&lt;p&gt;and _foo bar _&lt;/p&gt;</code></pre>
</div>
<div id="example-271" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 271
</div>
<pre class="markdown"><code>and **foo bar **</code></pre>
<pre class="html"><code>&lt;p&gt;and **foo bar **&lt;/p&gt;</code></pre>
</div>
<div id="example-272" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 272
</div>
<pre class="markdown"><code>and __foo bar __</code></pre>
<pre class="html"><code>&lt;p&gt;and __foo bar __&lt;/p&gt;</code></pre>
</div>
<p>The rules imply that a sequence of four or more unescaped <code>*</code> or <code>_</code> characters will always be parsed as a literal string:</p>
<div id="example-273" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 273
</div>
<pre class="markdown"><code>****hi****</code></pre>
<pre class="html"><code>&lt;p&gt;****hi****&lt;/p&gt;</code></pre>
</div>
<div id="example-274" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 274
</div>
<pre class="markdown"><code>_____hi_____</code></pre>
<pre class="html"><code>&lt;p&gt;_____hi_____&lt;/p&gt;</code></pre>
</div>
<div id="example-275" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 275
</div>
<pre class="markdown"><code>Sign here: _________</code></pre>
<pre class="html"><code>&lt;p&gt;Sign here: _________&lt;/p&gt;</code></pre>
</div>
<p>The rules also imply that there can be no empty emphasis or strong emphasis:</p>
<div id="example-276" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 276
</div>
<pre class="markdown"><code>** is not an empty emphasis</code></pre>
<pre class="html"><code>&lt;p&gt;** is not an empty emphasis&lt;/p&gt;</code></pre>
</div>
<div id="example-277" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 277
</div>
<pre class="markdown"><code>**** is not an empty strong emphasis</code></pre>
<pre class="html"><code>&lt;p&gt;**** is not an empty strong emphasis&lt;/p&gt;</code></pre>
</div>
<p>To include <code>*</code> or <code>_</code> in emphasized sections, use backslash escapes or code spans:</p>
<div id="example-278" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 278
</div>
<pre class="markdown"><code>*here is a \**</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;em&gt;here is a *&lt;/em&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-279" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 279
</div>
<pre class="markdown"><code>__this is a double underscore (`__`)__</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;strong&gt;this is a double underscore (&lt;code&gt;__&lt;/code&gt;)&lt;/strong&gt;&lt;/p&gt;</code></pre>
</div>
<p><code>*</code> delimiters allow intra-word emphasis; <code>_</code> delimiters do not:</p>
<div id="example-280" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 280
</div>
<pre class="markdown"><code>foo*bar*baz</code></pre>
<pre class="html"><code>&lt;p&gt;foo&lt;em&gt;bar&lt;/em&gt;baz&lt;/p&gt;</code></pre>
</div>
<div id="example-281" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 281
</div>
<pre class="markdown"><code>foo_bar_baz</code></pre>
<pre class="html"><code>&lt;p&gt;foo_bar_baz&lt;/p&gt;</code></pre>
</div>
<div id="example-282" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 282
</div>
<pre class="markdown"><code>foo__bar__baz</code></pre>
<pre class="html"><code>&lt;p&gt;foo__bar__baz&lt;/p&gt;</code></pre>
</div>
<div id="example-283" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 283
</div>
<pre class="markdown"><code>_foo_bar_baz_</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;em&gt;foo_bar_baz&lt;/em&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-284" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 284
</div>
<pre class="markdown"><code>11*15*32</code></pre>
<pre class="html"><code>&lt;p&gt;11&lt;em&gt;15&lt;/em&gt;32&lt;/p&gt;</code></pre>
</div>
<div id="example-285" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 285
</div>
<pre class="markdown"><code>11_15_32</code></pre>
<pre class="html"><code>&lt;p&gt;11_15_32&lt;/p&gt;</code></pre>
</div>
<p>Internal underscores will be ignored in underscore-delimited emphasis:</p>
<div id="example-286" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 286
</div>
<pre class="markdown"><code>_foo_bar_baz_</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;em&gt;foo_bar_baz&lt;/em&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-287" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 287
</div>
<pre class="markdown"><code>__foo__bar__baz__</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;strong&gt;foo__bar__baz&lt;/strong&gt;&lt;/p&gt;</code></pre>
</div>
<p>The rules are sufficient for the following nesting patterns:</p>
<div id="example-288" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 288
</div>
<pre class="markdown"><code>***foo bar***</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;strong&gt;&lt;em&gt;foo bar&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-289" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 289
</div>
<pre class="markdown"><code>___foo bar___</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;strong&gt;&lt;em&gt;foo bar&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-290" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 290
</div>
<pre class="markdown"><code>***foo** bar*</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;em&gt;&lt;strong&gt;foo&lt;/strong&gt; bar&lt;/em&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-291" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 291
</div>
<pre class="markdown"><code>___foo__ bar_</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;em&gt;&lt;strong&gt;foo&lt;/strong&gt; bar&lt;/em&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-292" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 292
</div>
<pre class="markdown"><code>***foo* bar**</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;strong&gt;&lt;em&gt;foo&lt;/em&gt; bar&lt;/strong&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-293" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 293
</div>
<pre class="markdown"><code>___foo_ bar__</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;strong&gt;&lt;em&gt;foo&lt;/em&gt; bar&lt;/strong&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-294" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 294
</div>
<pre class="markdown"><code>*foo **bar***</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;em&gt;foo &lt;strong&gt;bar&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-295" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 295
</div>
<pre class="markdown"><code>_foo __bar___</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;em&gt;foo &lt;strong&gt;bar&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-296" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 296
</div>
<pre class="markdown"><code>**foo *bar***</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;strong&gt;foo &lt;em&gt;bar&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-297" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 297
</div>
<pre class="markdown"><code>__foo _bar___</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;strong&gt;foo &lt;em&gt;bar&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-298" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 298
</div>
<pre class="markdown"><code>*foo **bar***</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;em&gt;foo &lt;strong&gt;bar&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-299" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 299
</div>
<pre class="markdown"><code>_foo __bar___</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;em&gt;foo &lt;strong&gt;bar&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-300" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 300
</div>
<pre class="markdown"><code>*foo *bar* baz*</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;em&gt;foo &lt;em&gt;bar&lt;/em&gt; baz&lt;/em&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-301" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 301
</div>
<pre class="markdown"><code>_foo _bar_ baz_</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;em&gt;foo &lt;em&gt;bar&lt;/em&gt; baz&lt;/em&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-302" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 302
</div>
<pre class="markdown"><code>**foo **bar** baz**</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;strong&gt;foo &lt;strong&gt;bar&lt;/strong&gt; baz&lt;/strong&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-303" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 303
</div>
<pre class="markdown"><code>__foo __bar__ baz__</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;strong&gt;foo &lt;strong&gt;bar&lt;/strong&gt; baz&lt;/strong&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-304" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 304
</div>
<pre class="markdown"><code>*foo **bar** baz*</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;em&gt;foo &lt;strong&gt;bar&lt;/strong&gt; baz&lt;/em&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-305" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 305
</div>
<pre class="markdown"><code>_foo __bar__ baz_</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;em&gt;foo &lt;strong&gt;bar&lt;/strong&gt; baz&lt;/em&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-306" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 306
</div>
<pre class="markdown"><code>**foo *bar* baz**</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;strong&gt;foo &lt;em&gt;bar&lt;/em&gt; baz&lt;/strong&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-307" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 307
</div>
<pre class="markdown"><code>__foo _bar_ baz__</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;strong&gt;foo &lt;em&gt;bar&lt;/em&gt; baz&lt;/strong&gt;&lt;/p&gt;</code></pre>
</div>
<p>Note that you cannot nest emphasis directly inside emphasis using the same delimiter, or strong emphasis directly inside strong emphasis:</p>
<div id="example-308" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 308
</div>
<pre class="markdown"><code>**foo**</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;strong&gt;foo&lt;/strong&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-309" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 309
</div>
<pre class="markdown"><code>****foo****</code></pre>
<pre class="html"><code>&lt;p&gt;****foo****&lt;/p&gt;</code></pre>
</div>
<p>For these nestings, you need to switch delimiters:</p>
<div id="example-310" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 310
</div>
<pre class="markdown"><code>*_foo_*</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;em&gt;&lt;em&gt;foo&lt;/em&gt;&lt;/em&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-311" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 311
</div>
<pre class="markdown"><code>**__foo__**</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;strong&gt;&lt;strong&gt;foo&lt;/strong&gt;&lt;/strong&gt;&lt;/p&gt;</code></pre>
</div>
<p>Note that a <code>*</code> followed by a <code>*</code> can close emphasis, and a <code>**</code> followed by a <code>*</code> can close strong emphasis (and similarly for <code>_</code> and <code>__</code>):</p>
<div id="example-312" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 312
</div>
<pre class="markdown"><code>*foo**</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;em&gt;foo&lt;/em&gt;*&lt;/p&gt;</code></pre>
</div>
<div id="example-313" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 313
</div>
<pre class="markdown"><code>*foo *bar**</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;em&gt;foo &lt;em&gt;bar&lt;/em&gt;&lt;/em&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-314" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 314
</div>
<pre class="markdown"><code>**foo***</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;strong&gt;foo&lt;/strong&gt;*&lt;/p&gt;</code></pre>
</div>
<div id="example-315" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 315
</div>
<pre class="markdown"><code>***foo* bar***</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;strong&gt;&lt;em&gt;foo&lt;/em&gt; bar&lt;/strong&gt;*&lt;/p&gt;</code></pre>
</div>
<div id="example-316" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 316
</div>
<pre class="markdown"><code>***foo** bar***</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;em&gt;&lt;strong&gt;foo&lt;/strong&gt; bar&lt;/em&gt;**&lt;/p&gt;</code></pre>
</div>
<p>The following contains no strong emphasis, because the opening delimiter is closed by the first <code>*</code> before <code>bar</code>:</p>
<div id="example-317" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 317
</div>
<pre class="markdown"><code>*foo**bar***</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;em&gt;foo&lt;/em&gt;&lt;em&gt;bar&lt;/em&gt;**&lt;/p&gt;</code></pre>
</div>
<p>However, a string of four or more <code>****</code> can never close emphasis:</p>
<div id="example-318" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 318
</div>
<pre class="markdown"><code>*foo****</code></pre>
<pre class="html"><code>&lt;p&gt;*foo****&lt;/p&gt;</code></pre>
</div>
<p>Note that there are some asymmetries here:</p>
<div id="example-319" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 319
</div>
<pre class="markdown"><code>*foo**
**foo*</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;em&gt;foo&lt;/em&gt;*&lt;/p&gt;
&lt;p&gt;**foo*&lt;/p&gt;</code></pre>
</div>
<div id="example-320" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 320
</div>
<pre class="markdown"><code>*foo *bar**
**foo* bar*</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;em&gt;foo &lt;em&gt;bar&lt;/em&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;**foo* bar*&lt;/p&gt;</code></pre>
</div>
<p>More cases with mismatched delimiters:</p>
<div id="example-321" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 321
</div>
<pre class="markdown"><code>**foo* bar*</code></pre>
<pre class="html"><code>&lt;p&gt;**foo* bar*&lt;/p&gt;</code></pre>
</div>
<div id="example-322" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 322
</div>
<pre class="markdown"><code>*bar***</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;em&gt;bar&lt;/em&gt;**&lt;/p&gt;</code></pre>
</div>
<div id="example-323" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 323
</div>
<pre class="markdown"><code>***foo*</code></pre>
<pre class="html"><code>&lt;p&gt;***foo*&lt;/p&gt;</code></pre>
</div>
<div id="example-324" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 324
</div>
<pre class="markdown"><code>**bar***</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;strong&gt;bar&lt;/strong&gt;*&lt;/p&gt;</code></pre>
</div>
<div id="example-325" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 325
</div>
<pre class="markdown"><code>***foo**</code></pre>
<pre class="html"><code>&lt;p&gt;***foo**&lt;/p&gt;</code></pre>
</div>
<div id="example-326" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 326
</div>
<pre class="markdown"><code>***foo *bar*</code></pre>
<pre class="html"><code>&lt;p&gt;***foo &lt;em&gt;bar&lt;/em&gt;&lt;/p&gt;</code></pre>
</div>
<h2 id="links"><span class="header-section-number">6.5</span> Links</h2>
<p>A link contains a <a href="#link-label">link label</a> (the visible text), a <a href="#destination">destination</a> (the URI that is the link destination), and optionally a <a href="#link-title">link title</a>. There are two basic kinds of links in Markdown. In <a href="#inline-links">inline links</a> the destination and title are given immediately after the label. In <a href="#reference-links">reference links</a> the destination and title are defined elsewhere in the document.</p>
<p>A <a href="#link-label">link label</a> <a id="link-label"></a> consists of</p>
<ul>
<li>an opening <code>[</code>, followed by</li>
<li>zero or more backtick code spans, autolinks, HTML tags, link labels, backslash-escaped ASCII punctuation characters, or non-<code>]</code> characters, followed by</li>
<li>a closing <code>]</code>.</li>
</ul>
<p>These rules are motivated by the following intuitive ideas:</p>
<ul>
<li>A link label is a container for inline elements.</li>
<li>The square brackets bind more tightly than emphasis markers, but less tightly than <code>&lt;&gt;</code> or <code>`</code>.</li>
<li>Link labels may contain material in matching square brackets.</li>
</ul>
<p>A <a href="#link-destination">link destination</a> <a id="link-destination"></a> consists of either</p>
<ul>
<li><p>a sequence of zero or more characters between an opening <code>&lt;</code> and a closing <code>&gt;</code> that contains no line breaks or unescaped <code>&lt;</code> or <code>&gt;</code> characters, or</p></li>
<li><p>a nonempty sequence of characters that does not include ASCII space or control characters, and includes parentheses only if (a) they are backslash-escaped or (b) they are part of a balanced pair of unescaped parentheses that is not itself inside a balanced pair of unescaped parentheses.</p></li>
</ul>
<p>A <a href="#link-title">link title</a> <a id="link-title"></a> consists of either</p>
<ul>
<li><p>a sequence of zero or more characters between straight double-quote characters (<code>&quot;</code>), including a <code>&quot;</code> character only if it is backslash-escaped, or</p></li>
<li><p>a sequence of zero or more characters between straight single-quote characters (<code>'</code>), including a <code>'</code> character only if it is backslash-escaped, or</p></li>
<li><p>a sequence of zero or more characters between matching parentheses (<code>(...)</code>), including a <code>)</code> character only if it is backslash-escaped.</p></li>
</ul>
<p>An <a href="#inline-link">inline link</a> <a id="inline-link"></a> consists of a <a href="#link-label">link label</a> followed immediately by a left parenthesis <code>(</code>, optional whitespace, an optional <a href="#link-destination">link destination</a>, an optional <a href="#link-title">link title</a> separated from the link destination by whitespace, optional whitespace, and a right parenthesis <code>)</code>. The link’s text consists of the label (excluding the enclosing square brackets) parsed as inlines. The link’s URI consists of the link destination, excluding enclosing <code>&lt;...&gt;</code> 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.</p>
<p>Here is a simple inline link:</p>
<div id="example-327" class="example" data-section="Links">
<div class="examplenum">
Example 327
</div>
<pre class="markdown"><code>[link](/uri &quot;title&quot;)</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;/uri&quot; title=&quot;title&quot;&gt;link&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<p>The title may be omitted:</p>
<div id="example-328" class="example" data-section="Links">
<div class="examplenum">
Example 328
</div>
<pre class="markdown"><code>[link](/uri)</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;/uri&quot;&gt;link&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<p>Both the title and the destination may be omitted:</p>
<div id="example-329" class="example" data-section="Links">
<div class="examplenum">
Example 329
</div>
<pre class="markdown"><code>[link]()</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;&quot;&gt;link&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-330" class="example" data-section="Links">
<div class="examplenum">
Example 330
</div>
<pre class="markdown"><code>[link](&lt;&gt;)</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;&quot;&gt;link&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<p>If the destination contains spaces, it must be enclosed in pointy braces:</p>
<div id="example-331" class="example" data-section="Links">
<div class="examplenum">
Example 331
</div>
<pre class="markdown"><code>[link](/my uri)</code></pre>
<pre class="html"><code>&lt;p&gt;[link](/my uri)&lt;/p&gt;</code></pre>
</div>
<div id="example-332" class="example" data-section="Links">
<div class="examplenum">
Example 332
</div>
<pre class="markdown"><code>[link](&lt;/my uri&gt;)</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;/my uri&quot;&gt;link&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<p>The destination cannot contain line breaks, even with pointy braces:</p>
<div id="example-333" class="example" data-section="Links">
<div class="examplenum">
Example 333
</div>
<pre class="markdown"><code>[link](foo
bar)</code></pre>
<pre class="html"><code>&lt;p&gt;[link](foo
bar)&lt;/p&gt;</code></pre>
</div>
<p>One level of balanced parentheses is allowed without escaping:</p>
<div id="example-334" class="example" data-section="Links">
<div class="examplenum">
Example 334
</div>
<pre class="markdown"><code>[link]((foo)and(bar))</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;(foo)and(bar)&quot;&gt;link&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<p>However, if you have parentheses within parentheses, you need to escape or use the <code>&lt;...&gt;</code> form:</p>
<div id="example-335" class="example" data-section="Links">
<div class="examplenum">
Example 335
</div>
<pre class="markdown"><code>[link](foo(and(bar)))</code></pre>
<pre class="html"><code>&lt;p&gt;[link](foo(and(bar)))&lt;/p&gt;</code></pre>
</div>
<div id="example-336" class="example" data-section="Links">
<div class="examplenum">
Example 336
</div>
<pre class="markdown"><code>[link](foo(and\(bar\)))</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;foo(and(bar))&quot;&gt;link&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-337" class="example" data-section="Links">
<div class="examplenum">
Example 337
</div>
<pre class="markdown"><code>[link](&lt;foo(and(bar))&gt;)</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;foo(and(bar))&quot;&gt;link&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<p>Parentheses and other symbols can also be escaped, as usual in Markdown:</p>
<div id="example-338" class="example" data-section="Links">
<div class="examplenum">
Example 338
</div>
<pre class="markdown"><code>[link](foo\)\:)</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;foo):&quot;&gt;link&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<p>URL-escaping and entities should be left alone inside the destination:</p>
<div id="example-339" class="example" data-section="Links">
<div class="examplenum">
Example 339
</div>
<pre class="markdown"><code>[link](foo%20b&amp;auml;)</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;foo%20b&amp;auml;&quot;&gt;link&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<p>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:</p>
<div id="example-340" class="example" data-section="Links">
<div class="examplenum">
Example 340
</div>
<pre class="markdown"><code>[link](&quot;title&quot;)</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;&amp;quot;title&amp;quot;&quot;&gt;link&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<p>Titles may be in single quotes, double quotes, or parentheses:</p>
<div id="example-341" class="example" data-section="Links">
<div class="examplenum">
Example 341
</div>
<pre class="markdown"><code>[link](/url &quot;title&quot;)
[link](/url &#39;title&#39;)
[link](/url (title))</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;/url&quot; title=&quot;title&quot;&gt;link&lt;/a&gt;
&lt;a href=&quot;/url&quot; title=&quot;title&quot;&gt;link&lt;/a&gt;
&lt;a href=&quot;/url&quot; title=&quot;title&quot;&gt;link&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<p>Backslash escapes and entities may be used in titles:</p>
<div id="example-342" class="example" data-section="Links">
<div class="examplenum">
Example 342
</div>
<pre class="markdown"><code>[link](/url &quot;title \&quot;&amp;quot;&quot;)</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;/url&quot; title=&quot;title &amp;quot;&amp;quot;&quot;&gt;link&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<p>Nested balanced quotes are not allowed without escaping:</p>
<div id="example-343" class="example" data-section="Links">
<div class="examplenum">
Example 343
</div>
<pre class="markdown"><code>[link](/url &quot;title &quot;and&quot; title&quot;)</code></pre>
<pre class="html"><code>&lt;p&gt;[link](/url &amp;quot;title &amp;quot;and&amp;quot; title&amp;quot;)&lt;/p&gt;</code></pre>
</div>
<p>But it is easy to work around this by using a different quote type:</p>
<div id="example-344" class="example" data-section="Links">
<div class="examplenum">
Example 344
</div>
<pre class="markdown"><code>[link](/url &#39;title &quot;and&quot; title&#39;)</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;/url&quot; title=&quot;title &amp;quot;and&amp;quot; title&quot;&gt;link&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<p>(Note: <code>Markdown.pl</code> 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, entities, or using a different quote type for the enclosing title—to write titles containing double quotes. <code>Markdown.pl</code>’s handling of titles has a number of other strange features. For example, 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 <code>&quot;</code> and end with <code>)</code>. <code>Markdown.pl</code> 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.)</p>
<p>Whitespace is allowed around the destination and title:</p>
<div id="example-345" class="example" data-section="Links">
<div class="examplenum">
Example 345
</div>
<pre class="markdown"><code>[link]( /uri
&quot;title&quot; )</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;/uri&quot; title=&quot;title&quot;&gt;link&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<p>But it is not allowed between the link label and the following parenthesis:</p>
<div id="example-346" class="example" data-section="Links">
<div class="examplenum">
Example 346
</div>
<pre class="markdown"><code>[link] (/uri)</code></pre>
<pre class="html"><code>&lt;p&gt;[link] (/uri)&lt;/p&gt;</code></pre>
</div>
<p>Note that this is not a link, because the closing <code>]</code> occurs in an HTML tag:</p>
<div id="example-347" class="example" data-section="Links">
<div class="examplenum">
Example 347
</div>
<pre class="markdown"><code>[foo &lt;bar attr=&quot;](baz)&quot;&gt;</code></pre>
<pre class="html"><code>&lt;p&gt;[foo &lt;bar attr=&quot;](baz)&quot;&gt;&lt;/p&gt;</code></pre>
</div>
<p>There are three kinds of <a href="#reference-link">reference links</a>: <a id="reference-link"></a></p>
<p>A <a href="#full-reference-link">full reference link</a> <a id="full-reference-link"></a> consists of a <a href="#link-label">link label</a>, optional whitespace, and another <a href="#link-label">link label</a> that <a href="#matches">matches</a> a <a href="#link-reference-definition">link reference definition</a> elsewhere in the document.</p>
<p>One label <a href="#matches">matches</a> <a id="matches"></a> another just in case their normalized forms are equal. To normalize a label, perform the <em>unicode case fold</em> and collapse consecutive internal whitespace 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.)</p>
<p>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 <a href="#link-reference-definition">link reference definition</a>.</p>
<p>Here is a simple example:</p>
<div id="example-348" class="example" data-section="Links">
<div class="examplenum">
Example 348
</div>
<pre class="markdown"><code>[foo][bar]
[bar]: /url &quot;title&quot;</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;/url&quot; title=&quot;title&quot;&gt;foo&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<p>The first label can contain inline content:</p>
<div id="example-349" class="example" data-section="Links">
<div class="examplenum">
Example 349
</div>
<pre class="markdown"><code>[*foo\!*][bar]
[bar]: /url &quot;title&quot;</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;/url&quot; title=&quot;title&quot;&gt;&lt;em&gt;foo!&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<p>Matching is case-insensitive:</p>
<div id="example-350" class="example" data-section="Links">
<div class="examplenum">
Example 350
</div>
<pre class="markdown"><code>[foo][BaR]
[bar]: /url &quot;title&quot;</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;/url&quot; title=&quot;title&quot;&gt;foo&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<p>Unicode case fold is used:</p>
<div id="example-351" class="example" data-section="Links">
<div class="examplenum">
Example 351
</div>
<pre class="markdown"><code>[Толпой][Толпой] is a Russian word.
[ТОЛПОЙ]: /url</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;/url&quot;&gt;Толпой&lt;/a&gt; is a Russian word.&lt;/p&gt;</code></pre>
</div>
<p>Consecutive internal whitespace is treated as one space for purposes of determining matching:</p>
<div id="example-352" class="example" data-section="Links">
<div class="examplenum">
Example 352
</div>
<pre class="markdown"><code>[Foo
bar]: /url
[Baz][Foo bar]</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;/url&quot;&gt;Baz&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<p>There can be whitespace between the two labels:</p>
<div id="example-353" class="example" data-section="Links">
<div class="examplenum">
Example 353
</div>
<pre class="markdown"><code>[foo] [bar]
[bar]: /url &quot;title&quot;</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;/url&quot; title=&quot;title&quot;&gt;foo&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-354" class="example" data-section="Links">
<div class="examplenum">
Example 354
</div>
<pre class="markdown"><code>[foo]
[bar]
[bar]: /url &quot;title&quot;</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;/url&quot; title=&quot;title&quot;&gt;foo&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<p>When there are multiple matching <a href="#link-reference-definition">link reference definitions</a>, the first is used:</p>
<div id="example-355" class="example" data-section="Links">
<div class="examplenum">
Example 355
</div>
<pre class="markdown"><code>[foo]: /url1
[foo]: /url2
[bar][foo]</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;/url1&quot;&gt;bar&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<p>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:</p>
<div id="example-356" class="example" data-section="Links">
<div class="examplenum">
Example 356
</div>
<pre class="markdown"><code>[bar][foo\!]
[foo!]: /url</code></pre>
<pre class="html"><code>&lt;p&gt;[bar][foo!]&lt;/p&gt;</code></pre>
</div>
<p>A <a href="#collapsed-reference-link">collapsed reference link</a> <a id="collapsed-reference-link"></a> consists of a <a href="#link-label">link label</a> that <a href="#matches">matches</a> a <a href="#link-reference-definition">link reference definition</a> elsewhere in the document, optional whitespace, and the string <code>[]</code>. 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, <code>[foo][]</code> is equivalent to <code>[foo][foo]</code>.</p>
<div id="example-357" class="example" data-section="Links">
<div class="examplenum">
Example 357
</div>
<pre class="markdown"><code>[foo][]
[foo]: /url &quot;title&quot;</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;/url&quot; title=&quot;title&quot;&gt;foo&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-358" class="example" data-section="Links">
<div class="examplenum">
Example 358
</div>
<pre class="markdown"><code>[*foo* bar][]
[*foo* bar]: /url &quot;title&quot;</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;/url&quot; title=&quot;title&quot;&gt;&lt;em&gt;foo&lt;/em&gt; bar&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<p>The link labels are case-insensitive:</p>
<div id="example-359" class="example" data-section="Links">
<div class="examplenum">
Example 359
</div>
<pre class="markdown"><code>[Foo][]
[foo]: /url &quot;title&quot;</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;/url&quot; title=&quot;title&quot;&gt;Foo&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<p>As with full reference links, whitespace is allowed between the two sets of brackets:</p>
<div id="example-360" class="example" data-section="Links">
<div class="examplenum">
Example 360
</div>
<pre class="markdown"><code>[foo]
[]
[foo]: /url &quot;title&quot;</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;/url&quot; title=&quot;title&quot;&gt;foo&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<p>A <a href="#shortcut-reference-link">shortcut reference link</a> <a id="shortcut-reference-link"></a> consists of a <a href="#link-label">link label</a> that <a href="#matches">matches</a> a <a href="#link-reference-definition">link reference definition</a> elsewhere in the document and is not followed by <code>[]</code> 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, <code>[foo]</code> is equivalent to <code>[foo][]</code>.</p>
<div id="example-361" class="example" data-section="Links">
<div class="examplenum">
Example 361
</div>
<pre class="markdown"><code>[foo]
[foo]: /url &quot;title&quot;</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;/url&quot; title=&quot;title&quot;&gt;foo&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-362" class="example" data-section="Links">
<div class="examplenum">
Example 362
</div>
<pre class="markdown"><code>[*foo* bar]
[*foo* bar]: /url &quot;title&quot;</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;/url&quot; title=&quot;title&quot;&gt;&lt;em&gt;foo&lt;/em&gt; bar&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-363" class="example" data-section="Links">
<div class="examplenum">
Example 363
</div>
<pre class="markdown"><code>[[*foo* bar]]
[*foo* bar]: /url &quot;title&quot;</code></pre>
<pre class="html"><code>&lt;p&gt;[&lt;a href=&quot;/url&quot; title=&quot;title&quot;&gt;&lt;em&gt;foo&lt;/em&gt; bar&lt;/a&gt;]&lt;/p&gt;</code></pre>
</div>
<p>The link labels are case-insensitive:</p>
<div id="example-364" class="example" data-section="Links">
<div class="examplenum">
Example 364
</div>
<pre class="markdown"><code>[Foo]
[foo]: /url &quot;title&quot;</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;/url&quot; title=&quot;title&quot;&gt;Foo&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<p>If you just want bracketed text, you can backslash-escape the opening bracket to avoid links:</p>
<div id="example-365" class="example" data-section="Links">
<div class="examplenum">
Example 365
</div>
<pre class="markdown"><code>\[foo]
[foo]: /url &quot;title&quot;</code></pre>
<pre class="html"><code>&lt;p&gt;[foo]&lt;/p&gt;</code></pre>
</div>
<p>Note that this is a link, because link labels bind more tightly than emphasis:</p>
<div id="example-366" class="example" data-section="Links">
<div class="examplenum">
Example 366
</div>
<pre class="markdown"><code>[foo*]: /url
*[foo*]</code></pre>
<pre class="html"><code>&lt;p&gt;*&lt;a href=&quot;/url&quot;&gt;foo*&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<p>However, this is not, because link labels bind less tightly than code backticks:</p>
<div id="example-367" class="example" data-section="Links">
<div class="examplenum">
Example 367
</div>
<pre class="markdown"><code>[foo`]: /url
[foo`]`</code></pre>
<pre class="html"><code>&lt;p&gt;[foo&lt;code&gt;]&lt;/code&gt;&lt;/p&gt;</code></pre>
</div>
<p>Link labels can contain matched square brackets:</p>
<div id="example-368" class="example" data-section="Links">
<div class="examplenum">
Example 368
</div>
<pre class="markdown"><code>[[[foo]]]
[[[foo]]]: /url</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;/url&quot;&gt;[[foo]]&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-369" class="example" data-section="Links">
<div class="examplenum">
Example 369
</div>
<pre class="markdown"><code>[[[foo]]]
[[[foo]]]: /url1
[foo]: /url2</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;/url1&quot;&gt;[[foo]]&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<p>For non-matching brackets, use backslash escapes:</p>
<div id="example-370" class="example" data-section="Links">
<div class="examplenum">
Example 370
</div>
<pre class="markdown"><code>[\[foo]
[\[foo]: /url</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;/url&quot;&gt;[foo&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<p>Full references take precedence over shortcut references:</p>
<div id="example-371" class="example" data-section="Links">
<div class="examplenum">
Example 371
</div>
<pre class="markdown"><code>[foo][bar]
[foo]: /url1
[bar]: /url2</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;/url2&quot;&gt;foo&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<p>In the following case <code>[bar][baz]</code> is parsed as a reference, <code>[foo]</code> as normal text:</p>
<div id="example-372" class="example" data-section="Links">
<div class="examplenum">
Example 372
</div>
<pre class="markdown"><code>[foo][bar][baz]
[baz]: /url</code></pre>
<pre class="html"><code>&lt;p&gt;[foo]&lt;a href=&quot;/url&quot;&gt;bar&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<p>Here, though, <code>[foo][bar]</code> is parsed as a reference, since <code>[bar]</code> is defined:</p>
<div id="example-373" class="example" data-section="Links">
<div class="examplenum">
Example 373
</div>
<pre class="markdown"><code>[foo][bar][baz]
[baz]: /url1
[bar]: /url2</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;/url2&quot;&gt;foo&lt;/a&gt;&lt;a href=&quot;/url1&quot;&gt;baz&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<p>Here <code>[foo]</code> is not parsed as a shortcut reference, because it is followed by a link label (even though <code>[bar]</code> is not defined):</p>
<div id="example-374" class="example" data-section="Links">
<div class="examplenum">
Example 374
</div>
<pre class="markdown"><code>[foo][bar][baz]
[baz]: /url1
[foo]: /url2</code></pre>
<pre class="html"><code>&lt;p&gt;[foo]&lt;a href=&quot;/url1&quot;&gt;bar&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<h2 id="images"><span class="header-section-number">6.6</span> Images</h2>
<p>An (unescaped) exclamation mark (<code>!</code>) 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.</p>
<div id="example-375" class="example" data-section="Images">
<div class="examplenum">
Example 375
</div>
<pre class="markdown"><code>![foo](/url &quot;title&quot;)</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;img src=&quot;/url&quot; alt=&quot;foo&quot; title=&quot;title&quot; /&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-376" class="example" data-section="Images">
<div class="examplenum">
Example 376
</div>
<pre class="markdown"><code>![foo *bar*]
[foo *bar*]: train.jpg &quot;train &amp; tracks&quot;</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;img src=&quot;train.jpg&quot; alt=&quot;foo &amp;lt;em&amp;gt;bar&amp;lt;/em&amp;gt;&quot; title=&quot;train &amp;amp; tracks&quot; /&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-377" class="example" data-section="Images">
<div class="examplenum">
Example 377
</div>
<pre class="markdown"><code>![foo *bar*][]
[foo *bar*]: train.jpg &quot;train &amp; tracks&quot;</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;img src=&quot;train.jpg&quot; alt=&quot;foo &amp;lt;em&amp;gt;bar&amp;lt;/em&amp;gt;&quot; title=&quot;train &amp;amp; tracks&quot; /&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-378" class="example" data-section="Images">
<div class="examplenum">
Example 378
</div>
<pre class="markdown"><code>![foo *bar*][foobar]
[FOOBAR]: train.jpg &quot;train &amp; tracks&quot;</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;img src=&quot;train.jpg&quot; alt=&quot;foo &amp;lt;em&amp;gt;bar&amp;lt;/em&amp;gt;&quot; title=&quot;train &amp;amp; tracks&quot; /&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-379" class="example" data-section="Images">
<div class="examplenum">
Example 379
</div>
<pre class="markdown"><code>![foo](train.jpg)</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;img src=&quot;train.jpg&quot; alt=&quot;foo&quot; /&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-380" class="example" data-section="Images">
<div class="examplenum">
Example 380
</div>
<pre class="markdown"><code>My ![foo bar](/path/to/train.jpg &quot;title&quot; )</code></pre>
<pre class="html"><code>&lt;p&gt;My &lt;img src=&quot;/path/to/train.jpg&quot; alt=&quot;foo bar&quot; title=&quot;title&quot; /&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-381" class="example" data-section="Images">
<div class="examplenum">
Example 381
</div>
<pre class="markdown"><code>![foo](&lt;url&gt;)</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;img src=&quot;url&quot; alt=&quot;foo&quot; /&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-382" class="example" data-section="Images">
<div class="examplenum">
Example 382
</div>
<pre class="markdown"><code>![](/url)</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;img src=&quot;/url&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;</code></pre>
</div>
<p>Reference-style:</p>
<div id="example-383" class="example" data-section="Images">
<div class="examplenum">
Example 383
</div>
<pre class="markdown"><code>![foo] [bar]
[bar]: /url</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;img src=&quot;/url&quot; alt=&quot;foo&quot; /&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-384" class="example" data-section="Images">
<div class="examplenum">
Example 384
</div>
<pre class="markdown"><code>![foo] [bar]
[BAR]: /url</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;img src=&quot;/url&quot; alt=&quot;foo&quot; /&gt;&lt;/p&gt;</code></pre>
</div>
<p>Collapsed:</p>
<div id="example-385" class="example" data-section="Images">
<div class="examplenum">
Example 385
</div>
<pre class="markdown"><code>![foo][]
[foo]: /url &quot;title&quot;</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;img src=&quot;/url&quot; alt=&quot;foo&quot; title=&quot;title&quot; /&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-386" class="example" data-section="Images">
<div class="examplenum">
Example 386
</div>
<pre class="markdown"><code>![*foo* bar][]
[*foo* bar]: /url &quot;title&quot;</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;img src=&quot;/url&quot; alt=&quot;&amp;lt;em&amp;gt;foo&amp;lt;/em&amp;gt; bar&quot; title=&quot;title&quot; /&gt;&lt;/p&gt;</code></pre>
</div>
<p>The labels are case-insensitive:</p>
<div id="example-387" class="example" data-section="Images">
<div class="examplenum">
Example 387
</div>
<pre class="markdown"><code>![Foo][]
[foo]: /url &quot;title&quot;</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;img src=&quot;/url&quot; alt=&quot;Foo&quot; title=&quot;title&quot; /&gt;&lt;/p&gt;</code></pre>
</div>
<p>As with full reference links, whitespace is allowed between the two sets of brackets:</p>
<div id="example-388" class="example" data-section="Images">
<div class="examplenum">
Example 388
</div>
<pre class="markdown"><code>![foo]
[]
[foo]: /url &quot;title&quot;</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;img src=&quot;/url&quot; alt=&quot;foo&quot; title=&quot;title&quot; /&gt;&lt;/p&gt;</code></pre>
</div>
<p>Shortcut:</p>
<div id="example-389" class="example" data-section="Images">
<div class="examplenum">
Example 389
</div>
<pre class="markdown"><code>![foo]
[foo]: /url &quot;title&quot;</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;img src=&quot;/url&quot; alt=&quot;foo&quot; title=&quot;title&quot; /&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-390" class="example" data-section="Images">
<div class="examplenum">
Example 390
</div>
<pre class="markdown"><code>![*foo* bar]
[*foo* bar]: /url &quot;title&quot;</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;img src=&quot;/url&quot; alt=&quot;&amp;lt;em&amp;gt;foo&amp;lt;/em&amp;gt; bar&quot; title=&quot;title&quot; /&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-391" class="example" data-section="Images">
<div class="examplenum">
Example 391
</div>
<pre class="markdown"><code>![[foo]]
[[foo]]: /url &quot;title&quot;</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;img src=&quot;/url&quot; alt=&quot;[foo]&quot; title=&quot;title&quot; /&gt;&lt;/p&gt;</code></pre>
</div>
<p>The link labels are case-insensitive:</p>
<div id="example-392" class="example" data-section="Images">
<div class="examplenum">
Example 392
</div>
<pre class="markdown"><code>![Foo]
[foo]: /url &quot;title&quot;</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;img src=&quot;/url&quot; alt=&quot;Foo&quot; title=&quot;title&quot; /&gt;&lt;/p&gt;</code></pre>
</div>
<p>If you just want bracketed text, you can backslash-escape the opening <code>!</code> and <code>[</code>:</p>
<div id="example-393" class="example" data-section="Images">
<div class="examplenum">
Example 393
</div>
<pre class="markdown"><code>\!\[foo]
[foo]: /url &quot;title&quot;</code></pre>
<pre class="html"><code>&lt;p&gt;![foo]&lt;/p&gt;</code></pre>
</div>
<p>If you want a link after a literal <code>!</code>, backslash-escape the <code>!</code>:</p>
<div id="example-394" class="example" data-section="Images">
<div class="examplenum">
Example 394
</div>
<pre class="markdown"><code>\![foo]
[foo]: /url &quot;title&quot;</code></pre>
<pre class="html"><code>&lt;p&gt;!&lt;a href=&quot;/url&quot; title=&quot;title&quot;&gt;foo&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<h2 id="autolinks"><span class="header-section-number">6.7</span> Autolinks</h2>
<p>Autolinks are absolute URIs and email addresses inside <code>&lt;</code> and <code>&gt;</code>. They are parsed as links, with the URL or email address as the link label.</p>
<p>A <a href="#uri-autolink">URI autolink</a> <a id="uri-autolink"></a> consists of <code>&lt;</code>, followed by an <a href="#absolute-uri">absolute URI</a> not containing <code>&lt;</code>, followed by <code>&gt;</code>. It is parsed as a link to the URI, with the URI as the link’s label.</p>
<p>An <a href="#absolute-uri">absolute URI</a>, <a id="absolute-uri"></a> for these purposes, consists of a <a href="#scheme">scheme</a> followed by a colon (<code>:</code>) followed by zero or more characters other than ASCII whitespace and control characters, <code>&lt;</code>, and <code>&gt;</code>. If the URI includes these characters, you must use percent-encoding (e.g. <code>%20</code> for a space).</p>
<p>The following <a href="#scheme">schemes</a> <a id="scheme"></a> are recognized (case-insensitive): <code>coap</code>, <code>doi</code>, <code>javascript</code>, <code>aaa</code>, <code>aaas</code>, <code>about</code>, <code>acap</code>, <code>cap</code>, <code>cid</code>, <code>crid</code>, <code>data</code>, <code>dav</code>, <code>dict</code>, <code>dns</code>, <code>file</code>, <code>ftp</code>, <code>geo</code>, <code>go</code>, <code>gopher</code>, <code>h323</code>, <code>http</code>, <code>https</code>, <code>iax</code>, <code>icap</code>, <code>im</code>, <code>imap</code>, <code>info</code>, <code>ipp</code>, <code>iris</code>, <code>iris.beep</code>, <code>iris.xpc</code>, <code>iris.xpcs</code>, <code>iris.lwz</code>, <code>ldap</code>, <code>mailto</code>, <code>mid</code>, <code>msrp</code>, <code>msrps</code>, <code>mtqp</code>, <code>mupdate</code>, <code>news</code>, <code>nfs</code>, <code>ni</code>, <code>nih</code>, <code>nntp</code>, <code>opaquelocktoken</code>, <code>pop</code>, <code>pres</code>, <code>rtsp</code>, <code>service</code>, <code>session</code>, <code>shttp</code>, <code>sieve</code>, <code>sip</code>, <code>sips</code>, <code>sms</code>, <code>snmp</code>,<code>soap.beep</code>, <code>soap.beeps</code>, <code>tag</code>, <code>tel</code>, <code>telnet</code>, <code>tftp</code>, <code>thismessage</code>, <code>tn3270</code>, <code>tip</code>, <code>tv</code>, <code>urn</code>, <code>vemmi</code>, <code>ws</code>, <code>wss</code>, <code>xcon</code>, <code>xcon-userid</code>, <code>xmlrpc.beep</code>, <code>xmlrpc.beeps</code>, <code>xmpp</code>, <code>z39.50r</code>, <code>z39.50s</code>, <code>adiumxtra</code>, <code>afp</code>, <code>afs</code>, <code>aim</code>, <code>apt</code>,<code>attachment</code>, <code>aw</code>, <code>beshare</code>, <code>bitcoin</code>, <code>bolo</code>, <code>callto</code>, <code>chrome</code>,<code>chrome-extension</code>, <code>com-eventbrite-attendee</code>, <code>content</code>, <code>cvs</code>,<code>dlna-playsingle</code>, <code>dlna-playcontainer</code>, <code>dtn</code>, <code>dvb</code>, <code>ed2k</code>, <code>facetime</code>, <code>feed</code>, <code>finger</code>, <code>fish</code>, <code>gg</code>, <code>git</code>, <code>gizmoproject</code>, <code>gtalk</code>, <code>hcp</code>, <code>icon</code>, <code>ipn</code>, <code>irc</code>, <code>irc6</code>, <code>ircs</code>, <code>itms</code>, <code>jar</code>, <code>jms</code>, <code>keyparc</code>, <code>lastfm</code>, <code>ldaps</code>, <code>magnet</code>, <code>maps</code>, <code>market</code>,<code>message</code>, <code>mms</code>, <code>ms-help</code>, <code>msnim</code>, <code>mumble</code>, <code>mvn</code>, <code>notes</code>, <code>oid</code>, <code>palm</code>, <code>paparazzi</code>, <code>platform</code>, <code>proxy</code>, <code>psyc</code>, <code>query</code>, <code>res</code>, <code>resource</code>, <code>rmi</code>, <code>rsync</code>, <code>rtmp</code>, <code>secondlife</code>, <code>sftp</code>, <code>sgn</code>, <code>skype</code>, <code>smb</code>, <code>soldat</code>, <code>spotify</code>, <code>ssh</code>, <code>steam</code>, <code>svn</code>, <code>teamspeak</code>, <code>things</code>, <code>udp</code>, <code>unreal</code>, <code>ut2004</code>, <code>ventrilo</code>, <code>view-source</code>, <code>webcal</code>, <code>wtai</code>, <code>wyciwyg</code>, <code>xfire</code>, <code>xri</code>, <code>ymsgr</code>.</p>
<p>Here are some valid autolinks:</p>
<div id="example-395" class="example" data-section="Autolinks">
<div class="examplenum">
Example 395
</div>
<pre class="markdown"><code>&lt;http://foo.bar.baz&gt;</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;http://foo.bar.baz&quot;&gt;http://foo.bar.baz&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-396" class="example" data-section="Autolinks">
<div class="examplenum">
Example 396
</div>
<pre class="markdown"><code>&lt;http://foo.bar.baz?q=hello&amp;id=22&amp;boolean&gt;</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;http://foo.bar.baz?q=hello&amp;amp;id=22&amp;amp;boolean&quot;&gt;http://foo.bar.baz?q=hello&amp;amp;id=22&amp;amp;boolean&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-397" class="example" data-section="Autolinks">
<div class="examplenum">
Example 397
</div>
<pre class="markdown"><code>&lt;irc://foo.bar:2233/baz&gt;</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;irc://foo.bar:2233/baz&quot;&gt;irc://foo.bar:2233/baz&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<p>Uppercase is also fine:</p>
<div id="example-398" class="example" data-section="Autolinks">
<div class="examplenum">
Example 398
</div>
<pre class="markdown"><code>&lt;MAILTO:FOO@BAR.BAZ&gt;</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;MAILTO:FOO@BAR.BAZ&quot;&gt;MAILTO:FOO@BAR.BAZ&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<p>Spaces are not allowed in autolinks:</p>
<div id="example-399" class="example" data-section="Autolinks">
<div class="examplenum">
Example 399
</div>
<pre class="markdown"><code>&lt;http://foo.bar/baz bim&gt;</code></pre>
<pre class="html"><code>&lt;p&gt;&amp;lt;http://foo.bar/baz bim&amp;gt;&lt;/p&gt;</code></pre>
</div>
<p>An <a href="#email-autolink">email autolink</a> <a id="email-autolink"></a> consists of <code>&lt;</code>, followed by an <a href="#email-address">email address</a>, followed by <code>&gt;</code>. The link’s label is the email address, and the URL is <code>mailto:</code> followed by the email address.</p>
<p>An <a href="#email-address">email address</a>, <a id="email-address"></a> for these purposes, is anything that matches the <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/forms.html#e-mail-state-%28type=email%29">non-normative regex from the HTML5 spec</a>:</p>
<pre><code>/^[a-zA-Z0-9.!#$%&amp;&#39;*+/=?^_`{|}~-]+@[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])?)*$/</code></pre>
<p>Examples of email autolinks:</p>
<div id="example-400" class="example" data-section="Autolinks">
<div class="examplenum">
Example 400
</div>
<pre class="markdown"><code>&lt;foo@bar.baz.com&gt;</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;mailto:foo@bar.baz.com&quot;&gt;foo@bar.baz.com&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-401" class="example" data-section="Autolinks">
<div class="examplenum">
Example 401
</div>
<pre class="markdown"><code>&lt;foo+special@Bar.baz-bar0.com&gt;</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;mailto:foo+special@Bar.baz-bar0.com&quot;&gt;foo+special@Bar.baz-bar0.com&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<p>These are not autolinks:</p>
<div id="example-402" class="example" data-section="Autolinks">
<div class="examplenum">
Example 402
</div>
<pre class="markdown"><code>&lt;&gt;</code></pre>
<pre class="html"><code>&lt;p&gt;&amp;lt;&amp;gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-403" class="example" data-section="Autolinks">
<div class="examplenum">
Example 403
</div>
<pre class="markdown"><code>&lt;heck://bing.bong&gt;</code></pre>
<pre class="html"><code>&lt;p&gt;&amp;lt;heck://bing.bong&amp;gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-404" class="example" data-section="Autolinks">
<div class="examplenum">
Example 404
</div>
<pre class="markdown"><code>&lt; http://foo.bar &gt;</code></pre>
<pre class="html"><code>&lt;p&gt;&amp;lt; http://foo.bar &amp;gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-405" class="example" data-section="Autolinks">
<div class="examplenum">
Example 405
</div>
<pre class="markdown"><code>&lt;foo.bar.baz&gt;</code></pre>
<pre class="html"><code>&lt;p&gt;&amp;lt;foo.bar.baz&amp;gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-406" class="example" data-section="Autolinks">
<div class="examplenum">
Example 406
</div>
<pre class="markdown"><code>&lt;localhost:5001/foo&gt;</code></pre>
<pre class="html"><code>&lt;p&gt;&amp;lt;localhost:5001/foo&amp;gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-407" class="example" data-section="Autolinks">
<div class="examplenum">
Example 407
</div>
<pre class="markdown"><code>http://google.com</code></pre>
<pre class="html"><code>&lt;p&gt;http://google.com&lt;/p&gt;</code></pre>
</div>
<div id="example-408" class="example" data-section="Autolinks">
<div class="examplenum">
Example 408
</div>
<pre class="markdown"><code>foo@bar.baz.com</code></pre>
<pre class="html"><code>&lt;p&gt;foo@bar.baz.com&lt;/p&gt;</code></pre>
</div>
<h2 id="raw-html"><span class="header-section-number">6.8</span> Raw HTML</h2>
<p>Text between <code>&lt;</code> and <code>&gt;</code> 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.</p>
<p>Here is the grammar for tags:</p>
<p>A <a href="#tag-name">tag name</a> <a id="tag-name"></a> consists of an ASCII letter followed by zero or more ASCII letters or digits.</p>
<p>An <a href="#attribute">attribute</a> <a id="attribute"></a> consists of whitespace, an <strong>attribute name</strong>, and an optional <strong>attribute value specification</strong>.</p>
<p>An <a href="#attribute-name">attribute name</a> <a id="attribute-name"></a> consists of an ASCII letter, <code>_</code>, or <code>:</code>, followed by zero or more ASCII letters, digits, <code>_</code>, <code>.</code>, <code>:</code>, or <code>-</code>. (Note: This is the XML specification restricted to ASCII. HTML5 is laxer.)</p>
<p>An <a href="#attribute-value-specification">attribute value specification</a> <a id="attribute-value-specification"></a> consists of optional whitespace, a <code>=</code> character, optional whitespace, and an <a href="#attribute-value">attribute value</a>.</p>
<p>An <a href="#attribute-value">attribute value</a> <a id="attribute-value"></a> consists of an <a href="#unquoted-attribute-value">unquoted attribute value</a>, a <a href="#single-quoted-attribute-value">single-quoted attribute value</a>, or a <a href="#double-quoted-attribute-value">double-quoted attribute value</a>.</p>
<p>An <a href="#unquoted-attribute-value">unquoted attribute value</a> <a id="unquoted-attribute-value"></a> is a nonempty string of characters not including spaces, <code>&quot;</code>, <code>'</code>, <code>=</code>, <code>&lt;</code>, <code>&gt;</code>, or <code>`</code>.</p>
<p>A <a href="#single-quoted-attribute-value">single-quoted attribute value</a> <a id="single-quoted-attribute-value"></a> consists of <code>'</code>, zero or more characters not including <code>'</code>, and a final <code>'</code>.</p>
<p>A <a href="#double-quoted-attribute-value">double-quoted attribute value</a> <a id="double-quoted-attribute-value"></a> consists of <code>&quot;</code>, zero or more characters not including <code>&quot;</code>, and a final <code>&quot;</code>.</p>
<p>An <a href="#open-tag">open tag</a> <a id="open-tag"></a> consists of a <code>&lt;</code> character, a <a href="#tag-name">tag name</a>, zero or more <a href="#attribute">attributes</a>, optional whitespace, an optional <code>/</code> character, and a <code>&gt;</code> character.</p>
<p>A <a href="#closing-tag">closing tag</a> <a id="closing-tag"></a> consists of the string <code>&lt;/</code>, a <a href="#tag-name">tag name</a>, optional whitespace, and the character <code>&gt;</code>.</p>
<p>An <a href="#html-comment">HTML comment</a> <a id="html-comment"></a> consists of the string <code>&lt;!--</code>, a string of characters not including the string <code>--</code>, and the string <code>--&gt;</code>.</p>
<p>A <a href="#processing-instruction">processing instruction</a> <a id="processing-instruction"></a> consists of the string <code>&lt;?</code>, a string of characters not including the string <code>?&gt;</code>, and the string <code>?&gt;</code>.</p>
<p>A <a href="#declaration">declaration</a> <a id="declaration"></a> consists of the string <code>&lt;!</code>, a name consisting of one or more uppercase ASCII letters, whitespace, a string of characters not including the character <code>&gt;</code>, and the character <code>&gt;</code>.</p>
<p>A <a href="#cdata-section">CDATA section</a> <a id="cdata-section"></a> consists of the string <code>&lt;![CDATA[</code>, a string of characters not including the string <code>]]&gt;</code>, and the string <code>]]&gt;</code>.</p>
<p>An <a href="#html-tag">HTML tag</a> <a id="html-tag"></a> consists of an <a href="#open-tag">open tag</a>, a <a href="#closing-tag">closing tag</a>, an <a href="#html-comment">HTML comment</a>, a <a href="#processing-instruction">processing instruction</a>, an <a href="#element-type-declaration">element type declaration</a>, or a <a href="#cdata-section">CDATA section</a>.</p>
<p>Here are some simple open tags:</p>
<div id="example-409" class="example" data-section="Raw HTML">
<div class="examplenum">
Example 409
</div>
<pre class="markdown"><code>&lt;a&gt;&lt;bab&gt;&lt;c2c&gt;</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a&gt;&lt;bab&gt;&lt;c2c&gt;&lt;/p&gt;</code></pre>
</div>
<p>Empty elements:</p>
<div id="example-410" class="example" data-section="Raw HTML">
<div class="examplenum">
Example 410
</div>
<pre class="markdown"><code>&lt;a/&gt;&lt;b2/&gt;</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a/&gt;&lt;b2/&gt;&lt;/p&gt;</code></pre>
</div>
<p>Whitespace is allowed:</p>
<div id="example-411" class="example" data-section="Raw HTML">
<div class="examplenum">
Example 411
</div>
<pre class="markdown"><code>&lt;a /&gt;&lt;b2
data=&quot;foo&quot; &gt;</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a /&gt;&lt;b2
data=&quot;foo&quot; &gt;&lt;/p&gt;</code></pre>
</div>
<p>With attributes:</p>
<div id="example-412" class="example" data-section="Raw HTML">
<div class="examplenum">
Example 412
</div>
<pre class="markdown"><code>&lt;a foo=&quot;bar&quot; bam = &#39;baz &lt;em&gt;&quot;&lt;/em&gt;&#39;
_boolean zoop:33=zoop:33 /&gt;</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a foo=&quot;bar&quot; bam = &#39;baz &lt;em&gt;&quot;&lt;/em&gt;&#39;
_boolean zoop:33=zoop:33 /&gt;&lt;/p&gt;</code></pre>
</div>
<p>Illegal tag names, not parsed as HTML:</p>
<div id="example-413" class="example" data-section="Raw HTML">
<div class="examplenum">
Example 413
</div>
<pre class="markdown"><code>&lt;33&gt; &lt;__&gt;</code></pre>
<pre class="html"><code>&lt;p&gt;&amp;lt;33&amp;gt; &amp;lt;__&amp;gt;&lt;/p&gt;</code></pre>
</div>
<p>Illegal attribute names:</p>
<div id="example-414" class="example" data-section="Raw HTML">
<div class="examplenum">
Example 414
</div>
<pre class="markdown"><code>&lt;a h*#ref=&quot;hi&quot;&gt;</code></pre>
<pre class="html"><code>&lt;p&gt;&amp;lt;a h*#ref=&amp;quot;hi&amp;quot;&amp;gt;&lt;/p&gt;</code></pre>
</div>
<p>Illegal attribute values:</p>
<div id="example-415" class="example" data-section="Raw HTML">
<div class="examplenum">
Example 415
</div>
<pre class="markdown"><code>&lt;a href=&quot;hi&#39;&gt; &lt;a href=hi&#39;&gt;</code></pre>
<pre class="html"><code>&lt;p&gt;&amp;lt;a href=&amp;quot;hi&#39;&amp;gt; &amp;lt;a href=hi&#39;&amp;gt;&lt;/p&gt;</code></pre>
</div>
<p>Illegal whitespace:</p>
<div id="example-416" class="example" data-section="Raw HTML">
<div class="examplenum">
Example 416
</div>
<pre class="markdown"><code>&lt; a&gt;&lt;
foo&gt;&lt;bar/ &gt;</code></pre>
<pre class="html"><code>&lt;p&gt;&amp;lt; a&amp;gt;&amp;lt;
foo&amp;gt;&amp;lt;bar/ &amp;gt;&lt;/p&gt;</code></pre>
</div>
<p>Missing whitespace:</p>
<div id="example-417" class="example" data-section="Raw HTML">
<div class="examplenum">
Example 417
</div>
<pre class="markdown"><code>&lt;a href=&#39;bar&#39;title=title&gt;</code></pre>
<pre class="html"><code>&lt;p&gt;&amp;lt;a href=&#39;bar&#39;title=title&amp;gt;&lt;/p&gt;</code></pre>
</div>
<p>Closing tags:</p>
<div id="example-418" class="example" data-section="Raw HTML">
<div class="examplenum">
Example 418
</div>
<pre class="markdown"><code>&lt;/a&gt;
&lt;/foo &gt;</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;/a&gt;
&lt;/foo &gt;&lt;/p&gt;</code></pre>
</div>
<p>Illegal attributes in closing tag:</p>
<div id="example-419" class="example" data-section="Raw HTML">
<div class="examplenum">
Example 419
</div>
<pre class="markdown"><code>&lt;/a href=&quot;foo&quot;&gt;</code></pre>
<pre class="html"><code>&lt;p&gt;&amp;lt;/a href=&amp;quot;foo&amp;quot;&amp;gt;&lt;/p&gt;</code></pre>
</div>
<p>Comments:</p>
<div id="example-420" class="example" data-section="Raw HTML">
<div class="examplenum">
Example 420
</div>
<pre class="markdown"><code>foo &lt;!-- this is a
comment - with hyphen --&gt;</code></pre>
<pre class="html"><code>&lt;p&gt;foo &lt;!-- this is a
comment - with hyphen --&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-421" class="example" data-section="Raw HTML">
<div class="examplenum">
Example 421
</div>
<pre class="markdown"><code>foo &lt;!-- not a comment -- two hyphens --&gt;</code></pre>
<pre class="html"><code>&lt;p&gt;foo &amp;lt;!-- not a comment -- two hyphens --&amp;gt;&lt;/p&gt;</code></pre>
</div>
<p>Processing instructions:</p>
<div id="example-422" class="example" data-section="Raw HTML">
<div class="examplenum">
Example 422
</div>
<pre class="markdown"><code>foo &lt;?php echo $a; ?&gt;</code></pre>
<pre class="html"><code>&lt;p&gt;foo &lt;?php echo $a; ?&gt;&lt;/p&gt;</code></pre>
</div>
<p>Declarations:</p>
<div id="example-423" class="example" data-section="Raw HTML">
<div class="examplenum">
Example 423
</div>
<pre class="markdown"><code>foo &lt;!ELEMENT br EMPTY&gt;</code></pre>
<pre class="html"><code>&lt;p&gt;foo &lt;!ELEMENT br EMPTY&gt;&lt;/p&gt;</code></pre>
</div>
<p>CDATA sections:</p>
<div id="example-424" class="example" data-section="Raw HTML">
<div class="examplenum">
Example 424
</div>
<pre class="markdown"><code>foo &lt;![CDATA[&gt;&amp;&lt;]]&gt;</code></pre>
<pre class="html"><code>&lt;p&gt;foo &lt;![CDATA[&gt;&amp;&lt;]]&gt;&lt;/p&gt;</code></pre>
</div>
<p>Entities are preserved in HTML attributes:</p>
<div id="example-425" class="example" data-section="Raw HTML">
<div class="examplenum">
Example 425
</div>
<pre class="markdown"><code>&lt;a href=&quot;&amp;ouml;&quot;&gt;</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;&amp;ouml;&quot;&gt;&lt;/p&gt;</code></pre>
</div>
<p>Backslash escapes do not work in HTML attributes:</p>
<div id="example-426" class="example" data-section="Raw HTML">
<div class="examplenum">
Example 426
</div>
<pre class="markdown"><code>&lt;a href=&quot;\*&quot;&gt;</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;\*&quot;&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-427" class="example" data-section="Raw HTML">
<div class="examplenum">
Example 427
</div>
<pre class="markdown"><code>&lt;a href=&quot;\&quot;&quot;&gt;</code></pre>
<pre class="html"><code>&lt;p&gt;&amp;lt;a href=&amp;quot;&amp;quot;&amp;quot;&amp;gt;&lt;/p&gt;</code></pre>
</div>
<h2 id="hard-line-breaks"><span class="header-section-number">6.9</span> Hard line breaks</h2>
<p>A line break (not in a code span or HTML tag) that is preceded by two or more spaces is parsed as a linebreak (rendered in HTML as a <code>&lt;br /&gt;</code> tag):</p>
<div id="example-428" class="example" data-section="Hard line breaks">
<div class="examplenum">
Example 428
</div>
<pre class="markdown"><code>foo
baz</code></pre>
<pre class="html"><code>&lt;p&gt;foo&lt;br /&gt;
baz&lt;/p&gt;</code></pre>
</div>
<p>For a more visible alternative, a backslash before the newline may be used instead of two spaces:</p>
<div id="example-429" class="example" data-section="Hard line breaks">
<div class="examplenum">
Example 429
</div>
<pre class="markdown"><code>foo\
baz</code></pre>
<pre class="html"><code>&lt;p&gt;foo&lt;br /&gt;
baz&lt;/p&gt;</code></pre>
</div>
<p>More than two spaces can be used:</p>
<div id="example-430" class="example" data-section="Hard line breaks">
<div class="examplenum">
Example 430
</div>
<pre class="markdown"><code>foo
baz</code></pre>
<pre class="html"><code>&lt;p&gt;foo&lt;br /&gt;
baz&lt;/p&gt;</code></pre>
</div>
<p>Leading spaces at the beginning of the next line are ignored:</p>
<div id="example-431" class="example" data-section="Hard line breaks">
<div class="examplenum">
Example 431
</div>
<pre class="markdown"><code>foo
bar</code></pre>
<pre class="html"><code>&lt;p&gt;foo&lt;br /&gt;
bar&lt;/p&gt;</code></pre>
</div>
<div id="example-432" class="example" data-section="Hard line breaks">
<div class="examplenum">
Example 432
</div>
<pre class="markdown"><code>foo\
bar</code></pre>
<pre class="html"><code>&lt;p&gt;foo&lt;br /&gt;
bar&lt;/p&gt;</code></pre>
</div>
<p>Line breaks can occur inside emphasis, links, and other constructs that allow inline content:</p>
<div id="example-433" class="example" data-section="Hard line breaks">
<div class="examplenum">
Example 433
</div>
<pre class="markdown"><code>*foo
bar*</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;em&gt;foo&lt;br /&gt;
bar&lt;/em&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-434" class="example" data-section="Hard line breaks">
<div class="examplenum">
Example 434
</div>
<pre class="markdown"><code>*foo\
bar*</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;em&gt;foo&lt;br /&gt;
bar&lt;/em&gt;&lt;/p&gt;</code></pre>
</div>
<p>Line breaks do not occur inside code spans</p>
<div id="example-435" class="example" data-section="Hard line breaks">
<div class="examplenum">
Example 435
</div>
<pre class="markdown"><code>`code
span`</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;code&gt;code span&lt;/code&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-436" class="example" data-section="Hard line breaks">
<div class="examplenum">
Example 436
</div>
<pre class="markdown"><code>`code\
span`</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;code&gt;code\ span&lt;/code&gt;&lt;/p&gt;</code></pre>
</div>
<p>or HTML tags:</p>
<div id="example-437" class="example" data-section="Hard line breaks">
<div class="examplenum">
Example 437
</div>
<pre class="markdown"><code>&lt;a href=&quot;foo
bar&quot;&gt;</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;foo
bar&quot;&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-438" class="example" data-section="Hard line breaks">
<div class="examplenum">
Example 438
</div>
<pre class="markdown"><code>&lt;a href=&quot;foo\
bar&quot;&gt;</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;foo\
bar&quot;&gt;&lt;/p&gt;</code></pre>
</div>
<h2 id="soft-line-breaks"><span class="header-section-number">6.10</span> Soft line breaks</h2>
<p>A regular line break (not in a code span or HTML tag) that is not preceded by two or more spaces is parsed as a softbreak. (A softbreak may be rendered in HTML either as a newline or as a space. The result will be the same in browsers. In the examples here, a newline will be used.)</p>
<div id="example-439" class="example" data-section="Soft line breaks">
<div class="examplenum">
Example 439
</div>
<pre class="markdown"><code>foo
baz</code></pre>
<pre class="html"><code>&lt;p&gt;foo
baz&lt;/p&gt;</code></pre>
</div>
<p>Spaces at the end of the line and beginning of the next line are removed:</p>
<div id="example-440" class="example" data-section="Soft line breaks">
<div class="examplenum">
Example 440
</div>
<pre class="markdown"><code>foo
baz</code></pre>
<pre class="html"><code>&lt;p&gt;foo
baz&lt;/p&gt;</code></pre>
</div>
<p>A conforming parser may render a soft line break in HTML either as a line break or as a space.</p>
<p>A renderer may also provide an option to render soft line breaks as hard line breaks.</p>
<h2 id="strings"><span class="header-section-number">6.11</span> Strings</h2>
<p>Any characters not given an interpretation by the above rules will be parsed as string content.</p>
<div id="example-441" class="example" data-section="Strings">
<div class="examplenum">
Example 441
</div>
<pre class="markdown"><code>hello $.;&#39;there</code></pre>
<pre class="html"><code>&lt;p&gt;hello $.;&#39;there&lt;/p&gt;</code></pre>
</div>
<div id="example-442" class="example" data-section="Strings">
<div class="examplenum">
Example 442
</div>
<pre class="markdown"><code>Foo χρῆν</code></pre>
<pre class="html"><code>&lt;p&gt;Foo χρῆν&lt;/p&gt;</code></pre>
</div>
<p>Internal spaces are preserved verbatim:</p>
<div id="example-443" class="example" data-section="Strings">
<div class="examplenum">
Example 443
</div>
<pre class="markdown"><code>Multiple spaces</code></pre>
<pre class="html"><code>&lt;p&gt;Multiple spaces&lt;/p&gt;</code></pre>
</div>
<h1 id="extensions"><span class="header-section-number">7</span> Extensions</h1>
<p>This section contains extensions to the Core Markdown syntax described above. They don’t need to be implemented to conform to this spec. However, if an implementation includes an extension with the same purpose as one of the extensions described here, this spec strongly recommends to implement the syntax described here.</p>
<h2 id="attributes"><span class="header-section-number">7.1</span> Attributes</h2>
<p>Certain elements may carry an attribute block. The following subsections list all elements that may contain attributes, see those for examples.</p>
<ul>
<li>For inlines, the attribute block must immediately follow the element without any characters between the end of the inline and the start of the attribute block.</li>
<li>For horizontal rules, headers, fenced code blocks and reference links, there must be one or more space characters preceding the attribute block and any trailing whitespace is non-significant.</li>
<li>For paragraphs, block quotes and tight lists, the attribute block must start on a line that immediately follows the corresponding block. (Attributes on list items are not supported.)</li>
<li>For loose lists, the attribute block must start on a line that either immediately follows the list or is separated from it by only one blank line.</li>
</ul>
<p>For the last two points in the above list the following must hold: the line(s) on which the attribute block resides must not contain any other characters except for leading spaces (i.e. indentation), which may be significant in determining to which element the attribute block belongs, but the start of the attribute block must be indented by exactly the same amount as the corresonding block itself. Trailing whitespace which is non-significant.</p>
<p>An attribute block consists of a sequence of zero or more characters, between an unescaped opening LEFT CURLY BRACKET (<code>{</code>) and an unescaped closing RIGHT CURLY BRACKET (<code>}</code>), that includes curly brackets only if they are part of a balanced pair of unescaped double-quote or single-quote characters. The characters between the opening and closing brackets form zero or more attributes which are separated by one or more whitespace characters (and may contain non-significant leading and trailing whitespace). The order of the attributes is not significant. An attribute consists of (a) a key-value pair, (b) an id-identifier or (c) a class-identifier.</p>
<ul>
<li><ol style="list-style-type: lower-alpha">
<li>A key-value pair consists of a key, immediately followed by an EQUALS SIGN (<code>=</code>) which is immediately followed by the value. The key follows the syntax of <a href="#attribute-name">raw HTML attribute names</a>. The value consists of either</li>
</ol>
<ul>
<li>a sequence of zero or more characters that does not include ASCII space or control characters, or</li>
<li>a sequence of zero or more characters between straight double-quote characters (<code>&quot;</code>), including a <code>&quot;</code> character only if it is backslash-escaped, or</li>
<li>a sequence of zero or more characters between straight single-quote characters (<code>'</code>), including a <code>'</code> character only if it is backslash-escaped.</li>
</ul></li>
<li><ol start="2" style="list-style-type: lower-alpha">
<li>An id-identifier consists of a NUMBER SIGN — also known as a hash — (<code>#</code>) immediately followed by one or more characters that does neither include ASCII space or control characters nor curly brackets. <code>{#myId}</code> is syntactic sugar for <code>{id=myId}</code>.</li>
</ol></li>
<li><ol start="3" style="list-style-type: lower-alpha">
<li>A class-identifier consists of a FULL STOP (<code>.</code>) immediately followed by one or more characters that does neither include ASCII space or control characters nor curly brackets. <code>{.myClass}</code> is syntactic sugar for <code>{class=myClass}</code>.</li>
</ol></li>
</ul>
<p>Markdown authors shouldn’t write multiple key-value pairs with the same key in an attribute block. However, to ease the burden of implementation, the behaviour in such cases is left undefined—although most implementations will probably parse the attributes sequentially and insert them into a map, which would result in a last-one-wins semantic.</p>
<p>If there are curly brackets that contain characters which don’t follow the rules outlined above and below, the curly brackets and the containing characters are not considered an attribute block but regular text and are to be interpreted accordingly.</p>
<h3 id="horizontal-rules-1"><span class="header-section-number">7.1.1</span> Horizontal rules</h3>
<div id="example-444" class="example" data-section="Horizontal rules">
<div class="examplenum">
Example 444
</div>
<pre class="markdown"><code>--- {#myId .myClass key=val key2=&quot;val 2&quot;}</code></pre>
<pre class="html"><code>&lt;hr id=&quot;myId&quot; class=&quot;myClass&quot; key=&quot;val&quot; key2=&quot;val 2&quot; /&gt;</code></pre>
</div>
<p>There must be one or more space characters in front of the attribute block:</p>
<div id="example-445" class="example" data-section="Horizontal rules">
<div class="examplenum">
Example 445
</div>
<pre class="markdown"><code>---{.myClass}</code></pre>
<pre class="html"><code>&lt;p&gt;---{.myClass}&lt;/p&gt;</code></pre>
</div>
<div id="example-446" class="example" data-section="Horizontal rules">
<div class="examplenum">
Example 446
</div>
<pre class="markdown"><code>--- {#myId .myClass key=val key2=&quot;val 2&quot;}</code></pre>
<pre class="html"><code>&lt;hr id=&quot;myId&quot; class=&quot;myClass&quot; key=&quot;val&quot; key2=&quot;val 2&quot; /&gt;</code></pre>
</div>
<p>Any whitespace (not only spaces) separate the attributes:</p>
<div id="example-447" class="example" data-section="Horizontal rules">
<div class="examplenum">
Example 447
</div>
<pre class="markdown"><code>--- {#myId .myClass
key=val}</code></pre>
<pre class="html"><code>&lt;hr id=&quot;myId&quot; class=&quot;myClass&quot; key=&quot;val&quot; /&gt;</code></pre>
</div>
<p>Any characters (except unescaped quotes of the same kind) are allowed in quoted attributes:</p>
<div id="example-448" class="example" data-section="Horizontal rules">
<div class="examplenum">
Example 448
</div>
<pre class="markdown"><code>--- {key=&quot;Hello \&quot;World\&quot;!&quot; key2=&#39;Hello &quot;World&quot;!&#39; key3=&quot;even new
lines and special chars like &#39;=&#39; or &#39;`&#39; are allowed&quot;}</code></pre>
<pre class="html"><code>&lt;hr key=&quot;Hello &amp;quot;World&amp;quot;!&quot; key2=&quot;Hello &amp;quot;World&amp;quot;!&quot; key3=&quot;even new lines and special chars like &#39;=&#39; or &#39;`&#39; are allowed&quot;/&gt;</code></pre>
</div>
<h3 id="atx-headers-1"><span class="header-section-number">7.1.2</span> ATX headers</h3>
<div id="example-449" class="example" data-section="ATX headers">
<div class="examplenum">
Example 449
</div>
<pre class="markdown"><code>### foo {#myId .myClass key=val key2=&quot;val 2&quot;}</code></pre>
<pre class="html"><code>&lt;h3 id=&quot;myId&quot; class=&quot;myClass&quot; key=&quot;val&quot; key2=&quot;val 2&quot;&gt;foo&lt;/h3&gt;</code></pre>
</div>
<p>Or with a closing header sequence:</p>
<div id="example-450" class="example" data-section="ATX headers">
<div class="examplenum">
Example 450
</div>
<pre class="markdown"><code>### foo ### {#myId}</code></pre>
<pre class="html"><code>&lt;h3 id=&quot;myId&quot;&gt;foo&lt;/h3&gt;</code></pre>
</div>
<h3 id="setext-headers-1"><span class="header-section-number">7.1.3</span> Setext headers</h3>
<div id="example-451" class="example" data-section="Setext headers">
<div class="examplenum">
Example 451
</div>
<pre class="markdown"><code>Foo {#myId}
===========</code></pre>
<pre class="html"><code>&lt;h1 id=&quot;myId&quot;&gt;Foo&lt;/h1&gt;</code></pre>
</div>
<h3 id="fenced-code-blocks-1"><span class="header-section-number">7.1.4</span> Fenced code blocks</h3>
<div id="example-452" class="example" data-section="Fenced code blocks">
<div class="examplenum">
Example 452
</div>
<pre class="markdown"><code>``` {.language-ruby #code1}
x = 1
```</code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code class=&quot;language-ruby&quot;&gt;x = 1
&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<p><a href="#info-string">Info strings</a> are syntactic sugar for classes, i.e. the following two fenced code blocks are identical:</p>
<pre><code>```ruby
x = 1
```
``` {.language-ruby}
x = 1
```</code></pre>
<p>As the attribute block must be preceded by a space, this may be surprising:</p>
<div id="example-453" class="example" data-section="Fenced code blocks">
<div class="examplenum">
Example 453
</div>
<pre class="markdown"><code>```{.foo}
x = 1
```</code></pre>
<pre class="html"><code>&lt;pre&gt;&lt;code class=&quot;language-{.foo}&quot;&gt;x = 1
&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<h3 id="reference-links"><span class="header-section-number">7.1.5</span> Reference Links</h3>
<p>There must be one or more space characters preceding the attribute block in a reference link as well:</p>
<div id="example-454" class="example" data-section="Reference Links">
<div class="examplenum">
Example 454
</div>
<pre class="markdown"><code>[foo][bar]
[bar]: /url &quot;title&quot; {.myClass}</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;/url&quot; title=&quot;title&quot; class=&quot;myClass&quot;&gt;foo&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-455" class="example" data-section="Reference Links">
<div class="examplenum">
Example 455
</div>
<pre class="markdown"><code>[foo][bar]
[bar]: /url &quot;title&quot;{.no-attribute}</code></pre>
<pre class="html"><code>&lt;p&gt;[foo][bar]&lt;/p&gt;
&lt;p&gt;[bar]: /url &quot;title&quot;{.no-attribute}&lt;/p&gt;</code></pre>
</div>
<div id="example-456" class="example" data-section="Reference Links">
<div class="examplenum">
Example 456
</div>
<pre class="markdown"><code>[foo][bar]
[bar]: /url{.no-attribute}</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;/url{.no-attribute}&quot;&gt;foo&lt;/a&gt;
&lt;/p&gt;</code></pre>
</div>
<h3 id="paragraphs-1"><span class="header-section-number">7.1.6</span> Paragraphs</h3>
<p>Attribute blocks must start on a line following the paragraph.</p>
<div id="example-457" class="example" data-section="Paragraphs">
<div class="examplenum">
Example 457
</div>
<pre class="markdown"><code>Paragraph with attributes.
{.myPar}</code></pre>
<pre class="html"><code>&lt;p class=&quot;myPar&quot;&gt;Paragraph with attributes.&lt;/p&gt;</code></pre>
</div>
<div id="example-458" class="example" data-section="Paragraphs">
<div class="examplenum">
Example 458
</div>
<pre class="markdown"><code>Paragraph with attributes.
{.myPar
#myId}</code></pre>
<pre class="html"><code>&lt;p class=&quot;myPar&quot; id=&quot;myId&quot;&gt;Paragraph with attributes.&lt;/p&gt;</code></pre>
</div>
<div id="example-459" class="example" data-section="Paragraphs">
<div class="examplenum">
Example 459
</div>
<pre class="markdown"><code>Paragraph {.nope}</code></pre>
<pre class="html"><code>&lt;p&gt;Paragraph {.nope}&lt;/p&gt;</code></pre>
</div>
<div id="example-460" class="example" data-section="Paragraphs">
<div class="examplenum">
Example 460
</div>
<pre class="markdown"><code>Paragraph
{.nope}</code></pre>
<pre class="html"><code>&lt;p&gt;Paragraph&lt;/p&gt;
&lt;p&gt;{.nope}&lt;/p&gt;</code></pre>
</div>
<p>Attribute blocks for paragraphs must be indented exactly as much as the first line of the paragraph itself:</p>
<div id="example-461" class="example" data-section="Paragraphs">
<div class="examplenum">
Example 461
</div>
<pre class="markdown"><code>Paragraph
{.nope}</code></pre>
<pre class="html"><code>&lt;p&gt;Paragraph {.nope}&lt;/p&gt;</code></pre>
</div>
<h3 id="block-quotes-1"><span class="header-section-number">7.1.7</span> Block quotes</h3>
<div id="example-462" class="example" data-section="Block quotes">
<div class="examplenum">
Example 462
</div>
<pre class="markdown"><code>&gt; Blockquote with attributes.
{.myBlockquote}</code></pre>
<pre class="html"><code>&lt;blockquote class=&quot;myBlockquote&quot;&gt;
&lt;p&gt;Blockquote with attributes.&lt;/p&gt;
&lt;/blockquote&gt;</code></pre>
</div>
<div id="example-463" class="example" data-section="Block quotes">
<div class="examplenum">
Example 463
</div>
<pre class="markdown"><code>&gt; Paragraph with attributes
&gt; inside a block quote.
&gt; {.myPar}</code></pre>
<pre class="html"><code>&lt;blockquote&gt;
&lt;p class=&quot;myPar&quot;&gt;Paragraph with attributes inside a block quote.&lt;/p&gt;
&lt;/blockquote&gt;</code></pre>
</div>
<p>Attribute blocks for block quotes must be indented exactly as much as the <code>&gt;</code> which is part of the <a href="#block-quote-marker">block quote marker</a>:</p>
<div id="example-464" class="example" data-section="Block quotes">
<div class="examplenum">
Example 464
</div>
<pre class="markdown"><code> &gt; Blockquote with attributes.
{.myBlockquote}</code></pre>
<pre class="html"><code>&lt;blockquote class=&quot;myBlockquote&quot;&gt;
&lt;p&gt;Blockquote with attributes.&lt;/p&gt;
&lt;/blockquote&gt;</code></pre>
</div>
<div id="example-465" class="example" data-section="Block quotes">
<div class="examplenum">
Example 465
</div>
<pre class="markdown"><code>&gt; Blockquote without attributes.
{.nope}</code></pre>
<pre class="html"><code>&lt;blockquote&gt;
&lt;p&gt;Blockquote without attributes. {.nope}&lt;/p&gt;
&lt;/blockquote&gt;</code></pre>
</div>
<div id="example-466" class="example" data-section="Block quotes">
<div class="examplenum">
Example 466
</div>
<pre class="markdown"><code>&gt; Blockquote with
lazy continuation
{.myBlockquote}</code></pre>
<pre class="html"><code>&lt;blockquote class=&quot;myBlockquote&quot;&gt;
&lt;p&gt;Blockquote with lazy continuation.&lt;/p&gt;
&lt;/blockquote&gt;</code></pre>
</div>
<div id="example-467" class="example" data-section="Block quotes">
<div class="examplenum">
Example 467
</div>
<pre class="markdown"><code>&gt; Blockquote with
lazy continuation
{.nope}</code></pre>
<pre class="html"><code>&lt;blockquote&gt;
&lt;p&gt;Blockquote with lazy continuation {.nope}&lt;/p&gt;
&lt;/blockquote&gt;</code></pre>
</div>
<h3 id="lists-1"><span class="header-section-number">7.1.8</span> Lists</h3>
<div id="example-468" class="example" data-section="Lists">
<div class="examplenum">
Example 468
</div>
<pre class="markdown"><code>- list with
- attributes
{.myList}</code></pre>
<pre class="html"><code>&lt;ul class=&quot;myList&quot;&gt;
&lt;li&gt;list with&lt;/li&gt;
&lt;li&gt;attributes&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
<div id="example-469" class="example" data-section="Lists">
<div class="examplenum">
Example 469
</div>
<pre class="markdown"><code>- tight list without
- attributes
{.nope}</code></pre>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;tight list without&lt;/li&gt;
&lt;li&gt;attributes&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;{.nope}&lt;/p&gt;</code></pre>
</div>
<p>Attribute blocks for lists must be indented exactly as much as the <a href="#list-marker">list markers</a>:</p>
<div id="example-470" class="example" data-section="Lists">
<div class="examplenum">
Example 470
</div>
<pre class="markdown"><code>- a tight list
- without attributes
{.nope}</code></pre>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;a tight list&lt;/li&gt;
&lt;li&gt;without attributes {.nope}&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
<div id="example-471" class="example" data-section="Lists">
<div class="examplenum">
Example 471
</div>
<pre class="markdown"><code>- a tight list
- without attributes
{.nope}</code></pre>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;a tight list&lt;/li&gt;
&lt;li&gt;without attributes {.nope}&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
<div id="example-472" class="example" data-section="Lists">
<div class="examplenum">
Example 472
</div>
<pre class="markdown"><code>- one 1
- two 2
- 2.1
{.myList}</code></pre>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;one 1&lt;/li&gt;
&lt;li&gt;two 2
&lt;ul class=&quot;myList&quot;&gt;
&lt;li&gt;2.1&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
<div id="example-473" class="example" data-section="Lists">
<div class="examplenum">
Example 473
</div>
<pre class="markdown"><code>- a loose list
- with attributes
{.myList}</code></pre>
<pre class="html"><code>&lt;ul class=&quot;myList&quot;&gt;
&lt;li&gt;&lt;p&gt;a loose list&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;with attributes&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
<div id="example-474" class="example" data-section="Lists">
<div class="examplenum">
Example 474
</div>
<pre class="markdown"><code>- loose list
- with attributes
{.myList}</code></pre>
<pre class="html"><code>&lt;ul class=&quot;myList&quot;&gt;
&lt;li&gt;&lt;p&gt;loose list&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;with attributes&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
<div id="example-475" class="example" data-section="Lists">
<div class="examplenum">
Example 475
</div>
<pre class="markdown"><code>- a loose list
- without attributes
{.nope}</code></pre>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;&lt;p&gt;a loose list&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;without attributes&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;{.nope}&lt;/p&gt;</code></pre>
</div>
<div id="example-476" class="example" data-section="Lists">
<div class="examplenum">
Example 476
</div>
<pre class="markdown"><code>- a loose list where
- the last paragraph has attributes.
Note that the indentation of the
attribute block is significant.
{.myPar}</code></pre>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;&lt;p&gt;a loose list where&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p class=&quot;myPar&quot;&gt;the last paragraph has attributes&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
<p>Attribute blocks themselves do not obey the lazy continuation rules. They can be used with lazy continuation paragraphs, however it is not recommended since it gets quickly confusing.</p>
<div id="example-477" class="example" data-section="Lists">
<div class="examplenum">
Example 477
</div>
<pre class="markdown"><code>- a loose list
- with lazy
continuation
{.myList}</code></pre>
<pre class="html"><code>&lt;ul class=&quot;myList&quot;&gt;
&lt;li&gt;&lt;p&gt;a loose list&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;with lazy continuation&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
<div id="example-478" class="example" data-section="Lists">
<div class="examplenum">
Example 478
</div>
<pre class="markdown"><code>- a tight list
{.nope}
- with lazy
continuation
{.nope}</code></pre>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;a tight list {.nope}&lt;/li&gt;
&lt;li&gt;with lazy continuation {.nope}&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
<div id="example-479" class="example" data-section="Lists">
<div class="examplenum">
Example 479
</div>
<pre class="markdown"><code>- a loose list
- with lazy
continuation
{.myPar}</code></pre>
<pre class="html"><code>&lt;ul&gt;
&lt;li&gt;&lt;p&gt;a loose list&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p class=&quot;myPar&quot;&gt;with lazy continuation&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
<p>A list of blockquotes:</p>
<div id="example-480" class="example" data-section="Lists">
<div class="examplenum">
Example 480
</div>
<pre class="markdown"><code>- &gt; a list where each
&gt; item is a blockquote
&gt; {.myPar}
- &gt; to see what is possible
&gt; {.myPar}
{.myBlockquote}
{.myList}</code></pre>
<pre class="html"><code>&lt;ul class=&quot;myList&quot;&gt;
&lt;li&gt;
&lt;blockquote&gt;
&lt;p class=&quot;myPar&quot;&gt;a list where each item is a blockquote&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;blockquote class=&quot;myBlockquote&quot;&gt;
&lt;p class=&quot;myPar&quot;&gt;to see what is possible&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
<p>Note that list items themselves cannot have attributes.</p>
<h3 id="code-span-1"><span class="header-section-number">7.1.9</span> Code span</h3>
<p>An attribute block follows the closing code span backtick immediately:</p>
<div id="example-481" class="example" data-section="Code span">
<div class="examplenum">
Example 481
</div>
<pre class="markdown"><code>`foo`{.myClass}</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;code class=&quot;myClass&quot;&gt;foo&lt;/code&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-482" class="example" data-section="Code span">
<div class="examplenum">
Example 482
</div>
<pre class="markdown"><code>`foo` {.no-attribute}</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;code&gt;foo&lt;/code&gt; {.no-attribute}&lt;/p&gt;</code></pre>
</div>
<h3 id="emphasis-and-strong-emphasis-1"><span class="header-section-number">7.1.10</span> Emphasis and strong emphasis</h3>
<p>An attribute block follows any closing emphasis character immediately:</p>
<div id="example-483" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 483
</div>
<pre class="markdown"><code>_foo_{.myClass}</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;em class=&quot;myClass&quot;&gt;foo&lt;/em&gt;&lt;/p&gt;</code></pre>
</div>
<div id="example-484" class="example" data-section="Emphasis and strong emphasis">
<div class="examplenum">
Example 484
</div>
<pre class="markdown"><code>**foo**{.myClass}</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;strong class=&quot;myClass&quot;&gt;foo&lt;/strong&gt;&lt;/p&gt;</code></pre>
</div>
<h3 id="inline-links"><span class="header-section-number">7.1.11</span> Inline Links</h3>
<p>An attribute block follows a link’s right parenthesis (<code>)</code>) immediately:</p>
<div id="example-485" class="example" data-section="Inline Links">
<div class="examplenum">
Example 485
</div>
<pre class="markdown"><code>[link](/uri){.myClass}</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;a href=&quot;/uri&quot; class=&quot;myClass&quot;&gt;link&lt;/a&gt;&lt;/p&gt;</code></pre>
</div>
<h3 id="images-1"><span class="header-section-number">7.1.12</span> Images</h3>
<p>As images are defined as links preceded by an exclamation mark (<code>!</code>), the behaviour is already well-defined.</p>
<div id="example-486" class="example" data-section="Images">
<div class="examplenum">
Example 486
</div>
<pre class="markdown"><code>![foo](/url){.myClass}</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;img src=&quot;/url&quot; alt=&quot;foo&quot; class=&quot;myClass&quot; /&gt;&lt;/p&gt;</code></pre>
</div>
<h3 id="spans"><span class="header-section-number">7.1.13</span> Spans</h3>
<p>A span consists of</p>
<ul>
<li>an opening <code>[</code>, followed by</li>
<li>zero or more characters parsed as inline (where neither the first nor the last character is an ASCII space or control character), followed by</li>
<li>a closing <code>]</code>, immediately followed by</li>
<li>a mandatory attribute block.</li>
</ul>
<div id="example-487" class="example" data-section="Spans">
<div class="examplenum">
Example 487
</div>
<pre class="markdown"><code>[foo _bar_]{#myId}</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;span id=&quot;myId&quot;&gt;foo &lt;em&gt;bar&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;</code></pre>
</div>
<p>Spaces before or after the span are not required:</p>
<div id="example-488" class="example" data-section="Spans">
<div class="examplenum">
Example 488
</div>
<pre class="markdown"><code>this[foo]{#myId}works</code></pre>
<pre class="html"><code>&lt;p&gt;this&lt;span id=&quot;myId&quot;&gt;foo&lt;/span&gt;works&lt;/p&gt;</code></pre>
</div>
<p>But the span content mustn’t start or end with whitespace:</p>
<div id="example-489" class="example" data-section="Spans">
<div class="examplenum">
Example 489
</div>
<pre class="markdown"><code>[ does not]{} work</code></pre>
<pre class="html"><code>&lt;p&gt;[ does not]{} work&lt;/p&gt;</code></pre>
</div>
<div id="example-490" class="example" data-section="Spans">
<div class="examplenum">
Example 490
</div>
<pre class="markdown"><code>[does not ]{} work</code></pre>
<pre class="html"><code>&lt;p&gt;[does not ]{} work&lt;/p&gt;</code></pre>
</div>
<p>Empty attribute blocks are generally allowed:</p>
<div id="example-491" class="example" data-section="Spans">
<div class="examplenum">
Example 491
</div>
<pre class="markdown"><code>[foo]{}</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;span&gt;foo&lt;/span&gt;&lt;/p&gt;</code></pre>
</div>
<p>As are empty spans:</p>
<div id="example-492" class="example" data-section="Spans">
<div class="examplenum">
Example 492
</div>
<pre class="markdown"><code>[]{.glyphicon}</code></pre>
<pre class="html"><code>&lt;p&gt;&lt;span class=&quot;glyphicon&quot;&gt;&lt;/span&gt;&lt;/p&gt;</code></pre>
</div>
<!-- END TESTS -->
<h1 id="appendix-a-a-parsing-strategy" class="unnumbered">Appendix A: A parsing strategy</h1>
<h2 id="overview" class="unnumbered">Overview</h2>
<p>Parsing has two phases:</p>
<ol style="list-style-type: decimal">
<li><p>In the first phase, lines of input are consumed and the block structure of the document—its division into paragraphs, block quotes, list items, and so on—is constructed. Text is assigned to these blocks but not parsed. Link reference definitions are parsed and a map of links is constructed.</p></li>
<li><p>In the second phase, the raw text contents of paragraphs and headers are parsed into sequences of Markdown inline elements (strings, code spans, links, emphasis, and so on), using the map of link references constructed in phase 1.</p></li>
</ol>
<h2 id="the-document-tree" class="unnumbered">The document tree</h2>
<p>At each point in processing, the document is represented as a tree of <strong>blocks</strong>. The root of the tree is a <code>document</code> block. The <code>document</code> may have any number of other blocks as <strong>children</strong>. These children may, in turn, have other blocks as children. The last child of a block is normally considered <strong>open</strong>, meaning that subsequent lines of input can alter its contents. (Blocks that are not open are <strong>closed</strong>.) Here, for example, is a possible document tree, with the open blocks marked by arrows:</p>
<pre class="tree"><code>-&gt; document
-&gt; block_quote
paragraph
&quot;Lorem ipsum dolor\nsit amet.&quot;
-&gt; list (type=bullet tight=true bullet_char=-)
list_item
paragraph
&quot;Qui *quodsi iracundia*&quot;
-&gt; list_item
-&gt; paragraph
&quot;aliquando id&quot;</code></pre>
<h2 id="how-source-lines-alter-the-document-tree" class="unnumbered">How source lines alter the document tree</h2>
<p>Each line that is processed has an effect on this tree. The line is analyzed and, depending on its contents, the document may be altered in one or more of the following ways:</p>
<ol style="list-style-type: decimal">
<li>One or more open blocks may be closed.</li>
<li>One or more new blocks may be created as children of the last open block.</li>
<li>Text may be added to the last (deepest) open block remaining on the tree.</li>
</ol>
<p>Once a line has been incorporated into the tree in this way, it can be discarded, so input can be read in a stream.</p>
<p>We can see how this works by considering how the tree above is generated by four lines of Markdown:</p>
<pre class="markdown"><code>&gt; Lorem ipsum dolor
sit amet.
&gt; - Qui *quodsi iracundia*
&gt; - aliquando id</code></pre>
<p>At the outset, our document model is just</p>
<pre class="tree"><code>-&gt; document</code></pre>
<p>The first line of our text,</p>
<pre class="markdown"><code>&gt; Lorem ipsum dolor</code></pre>
<p>causes a <code>block_quote</code> block to be created as a child of our open <code>document</code> block, and a <code>paragraph</code> block as a child of the <code>block_quote</code>. Then the text is added to the last open block, the <code>paragraph</code>:</p>
<pre class="tree"><code>-&gt; document
-&gt; block_quote
-&gt; paragraph
&quot;Lorem ipsum dolor&quot;</code></pre>
<p>The next line,</p>
<pre class="markdown"><code>sit amet.</code></pre>
<p>is a “lazy continuation” of the open <code>paragraph</code>, so it gets added to the paragraph’s text:</p>
<pre class="tree"><code>-&gt; document
-&gt; block_quote
-&gt; paragraph
&quot;Lorem ipsum dolor\nsit amet.&quot;</code></pre>
<p>The third line,</p>
<pre class="markdown"><code>&gt; - Qui *quodsi iracundia*</code></pre>
<p>causes the <code>paragraph</code> block to be closed, and a new <code>list</code> block opened as a child of the <code>block_quote</code>. A <code>list_item</code> is also added as a child of the <code>list</code>, and a <code>paragraph</code> as a child of the <code>list_item</code>. The text is then added to the new <code>paragraph</code>:</p>
<pre class="tree"><code>-&gt; document
-&gt; block_quote
paragraph
&quot;Lorem ipsum dolor\nsit amet.&quot;
-&gt; list (type=bullet tight=true bullet_char=-)
-&gt; list_item
-&gt; paragraph
&quot;Qui *quodsi iracundia*&quot;</code></pre>
<p>The fourth line,</p>
<pre class="markdown"><code>&gt; - aliquando id</code></pre>
<p>causes the <code>list_item</code> (and its child the <code>paragraph</code>) to be closed, and a new <code>list_item</code> opened up as child of the <code>list</code>. A <code>paragraph</code> is added as a child of the new <code>list_item</code>, to contain the text. We thus obtain the final tree:</p>
<pre class="tree"><code>-&gt; document
-&gt; block_quote
paragraph
&quot;Lorem ipsum dolor\nsit amet.&quot;
-&gt; list (type=bullet tight=true bullet_char=-)
list_item
paragraph
&quot;Qui *quodsi iracundia*&quot;
-&gt; list_item
-&gt; paragraph
&quot;aliquando id&quot;</code></pre>
<h2 id="from-block-structure-to-the-final-document" class="unnumbered">From block structure to the final document</h2>
<p>Once all of the input has been parsed, all open blocks are closed.</p>
<p>We then “walk the tree,” visiting every node, and parse raw string contents of paragraphs and headers as inlines. At this point we have seen all the link reference definitions, so we can resolve reference links as we go.</p>
<pre class="tree"><code>document
block_quote
paragraph
str &quot;Lorem ipsum dolor&quot;
softbreak
str &quot;sit amet.&quot;
list (type=bullet tight=true bullet_char=-)
list_item
paragraph
str &quot;Qui &quot;
emph
str &quot;quodsi iracundia&quot;
list_item
paragraph
str &quot;aliquando id&quot;</code></pre>
<p>Notice how the newline in the first paragraph has been parsed as a <code>softbreak</code>, and the asterisks in the first list item have become an <code>emph</code>.</p>
<p>The document can be rendered as HTML, or in any other format, given an appropriate renderer.</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment