CINXE.COM
CommonMark Spec
<!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; } a.definition { 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: 0px; bottom: 7px; left: 1px; right: 1px; color: #AAA; } 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; background-color: #D3E1E4; } pre > code { background-color: transparent; } 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; } #watermark { position:fixed; bottom:0px; left:0px; padding: 1em; width: 100%; font-size: 120%; opacity:0.7; z-index:99; color: white; } #watermark a { color: white; } div.examplenum { font-size: 82%; text-align: left; } a.dingus { color: red; cursor: pointer; } a.footnoteRef > sup:before { content: "["; } a.footnoteRef > sup:after { content: "]"; } a.footnoteRef > sup { vertical-align: baseline; font-size: 100%; } </style> <script src="//code.jquery.com/jquery-1.11.0.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $("div.example").each(function(e) { var t = $(this).find('pre.markdown > code').text(); $(this).find('a.dingus').click(function(f) { window.open('/dingus/?text=' + encodeURIComponent(t.replace(/→/g,"\t"))); }); }); $("pre.markdown").dblclick(function(e) { window.open('/dingus/?text=' + encodeURIComponent($(this).find('code').text())); }); }); </script> </head> <body> <h1 class="title">CommonMark Spec</h1> <div class="version">Version 0.11 (2014-11-10)</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="#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> <div id="watermark" style="background-color:black">This is an older version of the spec. For the most recent version, see <a href="http://spec.commonmark.org">http://spec.commonmark.org</a>.</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><p></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>> Blockquote [foo]. > > [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 id="line" href="#line" class="definition">line</a> is a sequence of zero or more <a href="#character">characters</a> followed by a line ending (CR, LF, or CRLF) or by the end of file.</p> <p>A <a id="character" href="#character" class="definition">character</a> is a unicode code point. 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"> <a href="#example-1">Example 1</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>→foo→baz→→bim</code></pre> <pre class="html"><code><pre><code>foo<span class="space"> </span>baz<span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>bim </code></pre></code></pre> </div> <div id="example-2" class="example" data-section="Preprocessing"> <div class="examplenum"> <a href="#example-2">Example 2</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>a→a <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>ὐ→a</code></pre> <pre class="html"><code><pre><code>a<span class="space"> </span><span class="space"> </span><span class="space"> </span>a ὐ<span class="space"> </span><span class="space"> </span><span class="space"> </span>a </code></pre></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 id="blank-line" href="#blank-line" class="definition">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 id="block" href="#block" class="definition">blocks</a>—structural elements like paragraphs, block quotations, lists, headers, rules, and code blocks. Blocks can contain other blocks, or they can contain <a id="inline" href="#inline" class="definition">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"> <a href="#example-3">Example 3</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>-<span class="space"> </span>`one -<span class="space"> </span>two`</code></pre> <pre class="html"><code><ul> <li>`one</li> <li>two`</li> </ul></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 id="container-block" href="#container-block" class="definition">container blocks</a>, which can contain other blocks, and <a id="leaf-block" href="#leaf-block" class="definition">leaf blocks</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 id="horizontal-rule" href="#horizontal-rule" class="definition">horizontal rule</a>.</p> <div id="example-4" class="example" data-section="Horizontal rules"> <div class="examplenum"> <a href="#example-4">Example 4</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>*** --- ___</code></pre> <pre class="html"><code><hr<span class="space"> </span>/> <hr<span class="space"> </span>/> <hr<span class="space"> </span>/></code></pre> </div> <p>Wrong characters:</p> <div id="example-5" class="example" data-section="Horizontal rules"> <div class="examplenum"> <a href="#example-5">Example 5</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>+++</code></pre> <pre class="html"><code><p>+++</p></code></pre> </div> <div id="example-6" class="example" data-section="Horizontal rules"> <div class="examplenum"> <a href="#example-6">Example 6</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>===</code></pre> <pre class="html"><code><p>===</p></code></pre> </div> <p>Not enough characters:</p> <div id="example-7" class="example" data-section="Horizontal rules"> <div class="examplenum"> <a href="#example-7">Example 7</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>-- ** __</code></pre> <pre class="html"><code><p>-- ** __</p></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"> <a href="#example-8">Example 8</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span>*** <span class="space"> </span><span class="space"> </span>*** <span class="space"> </span><span class="space"> </span><span class="space"> </span>***</code></pre> <pre class="html"><code><hr<span class="space"> </span>/> <hr<span class="space"> </span>/> <hr<span class="space"> </span>/></code></pre> </div> <p>Four spaces is too many:</p> <div id="example-9" class="example" data-section="Horizontal rules"> <div class="examplenum"> <a href="#example-9">Example 9</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>***</code></pre> <pre class="html"><code><pre><code>*** </code></pre></code></pre> </div> <div id="example-10" class="example" data-section="Horizontal rules"> <div class="examplenum"> <a href="#example-10">Example 10</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>Foo <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>***</code></pre> <pre class="html"><code><p>Foo ***</p></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"> <a href="#example-11">Example 11</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>_____________________________________</code></pre> <pre class="html"><code><hr<span class="space"> </span>/></code></pre> </div> <p>Spaces are allowed between the characters:</p> <div id="example-12" class="example" data-section="Horizontal rules"> <div class="examplenum"> <a href="#example-12">Example 12</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span>-<span class="space"> </span>-<span class="space"> </span>-</code></pre> <pre class="html"><code><hr<span class="space"> </span>/></code></pre> </div> <div id="example-13" class="example" data-section="Horizontal rules"> <div class="examplenum"> <a href="#example-13">Example 13</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span>**<span class="space"> </span><span class="space"> </span>*<span class="space"> </span>**<span class="space"> </span>*<span class="space"> </span>**<span class="space"> </span>*<span class="space"> </span>**</code></pre> <pre class="html"><code><hr<span class="space"> </span>/></code></pre> </div> <div id="example-14" class="example" data-section="Horizontal rules"> <div class="examplenum"> <a href="#example-14">Example 14</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>-<span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>-<span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>-<span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>-</code></pre> <pre class="html"><code><hr<span class="space"> </span>/></code></pre> </div> <p>Spaces are allowed at the end:</p> <div id="example-15" class="example" data-section="Horizontal rules"> <div class="examplenum"> <a href="#example-15">Example 15</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>-<span class="space"> </span>-<span class="space"> </span>-<span class="space"> </span>-<span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span></code></pre> <pre class="html"><code><hr<span class="space"> </span>/></code></pre> </div> <p>However, no other characters may occur in the line:</p> <div id="example-16" class="example" data-section="Horizontal rules"> <div class="examplenum"> <a href="#example-16">Example 16</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>_<span class="space"> </span>_<span class="space"> </span>_<span class="space"> </span>_<span class="space"> </span>a a------ ---a---</code></pre> <pre class="html"><code><p>_<span class="space"> </span>_<span class="space"> </span>_<span class="space"> </span>_<span class="space"> </span>a</p> <p>a------</p> <p>---a---</p></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"> <a href="#example-17">Example 17</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span>*-*</code></pre> <pre class="html"><code><p><em>-</em></p></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"> <a href="#example-18">Example 18</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>-<span class="space"> </span>foo *** -<span class="space"> </span>bar</code></pre> <pre class="html"><code><ul> <li>foo</li> </ul> <hr<span class="space"> </span>/> <ul> <li>bar</li> </ul></code></pre> </div> <p>Horizontal rules can interrupt a paragraph:</p> <div id="example-19" class="example" data-section="Horizontal rules"> <div class="examplenum"> <a href="#example-19">Example 19</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>Foo *** bar</code></pre> <pre class="html"><code><p>Foo</p> <hr<span class="space"> </span>/> <p>bar</p></code></pre> </div> <p>If a line of dashes that meets the above conditions for being a horizontal rule could also be interpreted as the underline of a <a href="#setext-header">setext header</a>, the interpretation as a <a href="#setext-header">setext-header</a> takes precedence. Thus, for example, 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"> <a href="#example-20">Example 20</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>Foo --- bar</code></pre> <pre class="html"><code><h2>Foo</h2> <p>bar</p></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"> <a href="#example-21">Example 21</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>*<span class="space"> </span>Foo *<span class="space"> </span>*<span class="space"> </span>* *<span class="space"> </span>Bar</code></pre> <pre class="html"><code><ul> <li>Foo</li> </ul> <hr<span class="space"> </span>/> <ul> <li>Bar</li> </ul></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"> <a href="#example-22">Example 22</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>-<span class="space"> </span>Foo -<span class="space"> </span>*<span class="space"> </span>*<span class="space"> </span>*</code></pre> <pre class="html"><code><ul> <li>Foo</li> <li><hr<span class="space"> </span>/></li> </ul></code></pre> </div> <h2 id="atx-headers"><span class="header-section-number">4.2</span> ATX headers</h2> <p>An <a id="atx-header" href="#atx-header" class="definition">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 nonspace character. The optional closing sequence of <code>#</code>s must be preceded by a space and 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"> <a href="#example-23">Example 23</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>#<span class="space"> </span>foo ##<span class="space"> </span>foo ###<span class="space"> </span>foo ####<span class="space"> </span>foo #####<span class="space"> </span>foo ######<span class="space"> </span>foo</code></pre> <pre class="html"><code><h1>foo</h1> <h2>foo</h2> <h3>foo</h3> <h4>foo</h4> <h5>foo</h5> <h6>foo</h6></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"> <a href="#example-24">Example 24</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>#######<span class="space"> </span>foo</code></pre> <pre class="html"><code><p>#######<span class="space"> </span>foo</p></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"> <a href="#example-25">Example 25</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>#5<span class="space"> </span>bolt</code></pre> <pre class="html"><code><p>#5<span class="space"> </span>bolt</p></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"> <a href="#example-26">Example 26</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>\##<span class="space"> </span>foo</code></pre> <pre class="html"><code><p>##<span class="space"> </span>foo</p></code></pre> </div> <p>Contents are parsed as inlines:</p> <div id="example-27" class="example" data-section="ATX headers"> <div class="examplenum"> <a href="#example-27">Example 27</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>#<span class="space"> </span>foo<span class="space"> </span>*bar*<span class="space"> </span>\*baz\*</code></pre> <pre class="html"><code><h1>foo<span class="space"> </span><em>bar</em><span class="space"> </span>*baz*</h1></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"> <a href="#example-28">Example 28</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>#<span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>foo<span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span></code></pre> <pre class="html"><code><h1>foo</h1></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"> <a href="#example-29">Example 29</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span>###<span class="space"> </span>foo <span class="space"> </span><span class="space"> </span>##<span class="space"> </span>foo <span class="space"> </span><span class="space"> </span><span class="space"> </span>#<span class="space"> </span>foo</code></pre> <pre class="html"><code><h3>foo</h3> <h2>foo</h2> <h1>foo</h1></code></pre> </div> <p>Four spaces are too much:</p> <div id="example-30" class="example" data-section="ATX headers"> <div class="examplenum"> <a href="#example-30">Example 30</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>#<span class="space"> </span>foo</code></pre> <pre class="html"><code><pre><code>#<span class="space"> </span>foo </code></pre></code></pre> </div> <div id="example-31" class="example" data-section="ATX headers"> <div class="examplenum"> <a href="#example-31">Example 31</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>foo <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>#<span class="space"> </span>bar</code></pre> <pre class="html"><code><p>foo #<span class="space"> </span>bar</p></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"> <a href="#example-32">Example 32</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>##<span class="space"> </span>foo<span class="space"> </span>## <span class="space"> </span><span class="space"> </span>###<span class="space"> </span><span class="space"> </span><span class="space"> </span>bar<span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>###</code></pre> <pre class="html"><code><h2>foo</h2> <h3>bar</h3></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"> <a href="#example-33">Example 33</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>#<span class="space"> </span>foo<span class="space"> </span>################################## #####<span class="space"> </span>foo<span class="space"> </span>##</code></pre> <pre class="html"><code><h1>foo</h1> <h5>foo</h5></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"> <a href="#example-34">Example 34</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>###<span class="space"> </span>foo<span class="space"> </span>###<span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span></code></pre> <pre class="html"><code><h3>foo</h3></code></pre> </div> <p>A sequence of <code>#</code> characters with a nonspace 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"> <a href="#example-35">Example 35</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>###<span class="space"> </span>foo<span class="space"> </span>###<span class="space"> </span>b</code></pre> <pre class="html"><code><h3>foo<span class="space"> </span>###<span class="space"> </span>b</h3></code></pre> </div> <p>The closing sequence must be preceded by a space:</p> <div id="example-36" class="example" data-section="ATX headers"> <div class="examplenum"> <a href="#example-36">Example 36</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>#<span class="space"> </span>foo#</code></pre> <pre class="html"><code><h1>foo#</h1></code></pre> </div> <p>Backslash-escaped <code>#</code> characters do not count as part of the closing sequence:</p> <div id="example-37" class="example" data-section="ATX headers"> <div class="examplenum"> <a href="#example-37">Example 37</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>###<span class="space"> </span>foo<span class="space"> </span>\### ##<span class="space"> </span>foo<span class="space"> </span>#\## #<span class="space"> </span>foo<span class="space"> </span>\#</code></pre> <pre class="html"><code><h3>foo<span class="space"> </span>###</h3> <h2>foo<span class="space"> </span>###</h2> <h1>foo<span class="space"> </span>#</h1></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-38" class="example" data-section="ATX headers"> <div class="examplenum"> <a href="#example-38">Example 38</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>**** ##<span class="space"> </span>foo ****</code></pre> <pre class="html"><code><hr<span class="space"> </span>/> <h2>foo</h2> <hr<span class="space"> </span>/></code></pre> </div> <div id="example-39" class="example" data-section="ATX headers"> <div class="examplenum"> <a href="#example-39">Example 39</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>Foo<span class="space"> </span>bar #<span class="space"> </span>baz Bar<span class="space"> </span>foo</code></pre> <pre class="html"><code><p>Foo<span class="space"> </span>bar</p> <h1>baz</h1> <p>Bar<span class="space"> </span>foo</p></code></pre> </div> <p>ATX headers can be empty:</p> <div id="example-40" class="example" data-section="ATX headers"> <div class="examplenum"> <a href="#example-40">Example 40</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>##<span class="space"> </span> # ###<span class="space"> </span>###</code></pre> <pre class="html"><code><h2></h2> <h1></h1> <h3></h3></code></pre> </div> <h2 id="setext-headers"><span class="header-section-number">4.3</span> Setext headers</h2> <p>A <a id="setext-header" href="#setext-header" class="definition">setext header</a> consists of a line of text, containing at least one nonspace character, with no more than 3 spaces indentation, followed by a <a href="#setext-header-underline">setext header underline</a>. The line of text must be one that, were it not followed by the setext header underline, would be interpreted as part of a paragraph: it cannot be a code block, header, blockquote, horizontal rule, or list. A <a id="setext-header-underline" href="#setext-header-underline" class="definition">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-41" class="example" data-section="Setext headers"> <div class="examplenum"> <a href="#example-41">Example 41</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>Foo<span class="space"> </span>*bar* ========= Foo<span class="space"> </span>*bar* ---------</code></pre> <pre class="html"><code><h1>Foo<span class="space"> </span><em>bar</em></h1> <h2>Foo<span class="space"> </span><em>bar</em></h2></code></pre> </div> <p>The underlining can be any length:</p> <div id="example-42" class="example" data-section="Setext headers"> <div class="examplenum"> <a href="#example-42">Example 42</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>Foo ------------------------- Foo =</code></pre> <pre class="html"><code><h2>Foo</h2> <h1>Foo</h1></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-43" class="example" data-section="Setext headers"> <div class="examplenum"> <a href="#example-43">Example 43</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span><span class="space"> </span><span class="space"> </span>Foo --- <span class="space"> </span><span class="space"> </span>Foo ----- <span class="space"> </span><span class="space"> </span>Foo <span class="space"> </span><span class="space"> </span>===</code></pre> <pre class="html"><code><h2>Foo</h2> <h2>Foo</h2> <h1>Foo</h1></code></pre> </div> <p>Four spaces indent is too much:</p> <div id="example-44" class="example" data-section="Setext headers"> <div class="examplenum"> <a href="#example-44">Example 44</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>Foo <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>--- <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>Foo ---</code></pre> <pre class="html"><code><pre><code>Foo --- Foo </code></pre> <hr<span class="space"> </span>/></code></pre> </div> <p>The setext header underline can be indented up to three spaces, and may have trailing spaces:</p> <div id="example-45" class="example" data-section="Setext headers"> <div class="examplenum"> <a href="#example-45">Example 45</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>Foo <span class="space"> </span><span class="space"> </span><span class="space"> </span>----<span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span></code></pre> <pre class="html"><code><h2>Foo</h2></code></pre> </div> <p>Four spaces is too much:</p> <div id="example-46" class="example" data-section="Setext headers"> <div class="examplenum"> <a href="#example-46">Example 46</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>Foo <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>---</code></pre> <pre class="html"><code><p>Foo ---</p></code></pre> </div> <p>The setext header underline cannot contain internal spaces:</p> <div id="example-47" class="example" data-section="Setext headers"> <div class="examplenum"> <a href="#example-47">Example 47</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>Foo =<span class="space"> </span>= Foo ---<span class="space"> </span>-</code></pre> <pre class="html"><code><p>Foo =<span class="space"> </span>=</p> <p>Foo</p> <hr<span class="space"> </span>/></code></pre> </div> <p>Trailing spaces in the content line do not cause a line break:</p> <div id="example-48" class="example" data-section="Setext headers"> <div class="examplenum"> <a href="#example-48">Example 48</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>Foo<span class="space"> </span><span class="space"> </span> -----</code></pre> <pre class="html"><code><h2>Foo</h2></code></pre> </div> <p>Nor does a backslash at the end:</p> <div id="example-49" class="example" data-section="Setext headers"> <div class="examplenum"> <a href="#example-49">Example 49</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>Foo\ ----</code></pre> <pre class="html"><code><h2>Foo\</h2></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-50" class="example" data-section="Setext headers"> <div class="examplenum"> <a href="#example-50">Example 50</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>`Foo ---- ` <a<span class="space"> </span>title="a<span class="space"> </span>lot --- of<span class="space"> </span>dashes"/></code></pre> <pre class="html"><code><h2>`Foo</h2> <p>`</p> <h2>&lt;a<span class="space"> </span>title=&quot;a<span class="space"> </span>lot</h2> <p>of<span class="space"> </span>dashes&quot;/&gt;</p></code></pre> </div> <p>The setext header underline cannot be a <a href="#lazy-continuation-line">lazy continuation line</a> in a list item or block quote:</p> <div id="example-51" class="example" data-section="Setext headers"> <div class="examplenum"> <a href="#example-51">Example 51</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>><span class="space"> </span>Foo ---</code></pre> <pre class="html"><code><blockquote> <p>Foo</p> </blockquote> <hr<span class="space"> </span>/></code></pre> </div> <div id="example-52" class="example" data-section="Setext headers"> <div class="examplenum"> <a href="#example-52">Example 52</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>-<span class="space"> </span>Foo ---</code></pre> <pre class="html"><code><ul> <li>Foo</li> </ul> <hr<span class="space"> </span>/></code></pre> </div> <p>A setext header cannot interrupt a paragraph:</p> <div id="example-53" class="example" data-section="Setext headers"> <div class="examplenum"> <a href="#example-53">Example 53</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>Foo Bar --- Foo Bar ===</code></pre> <pre class="html"><code><p>Foo Bar</p> <hr<span class="space"> </span>/> <p>Foo Bar ===</p></code></pre> </div> <p>But in general a blank line is not required before or after:</p> <div id="example-54" class="example" data-section="Setext headers"> <div class="examplenum"> <a href="#example-54">Example 54</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>--- Foo --- Bar --- Baz</code></pre> <pre class="html"><code><hr<span class="space"> </span>/> <h2>Foo</h2> <h2>Bar</h2> <p>Baz</p></code></pre> </div> <p>Setext headers cannot be empty:</p> <div id="example-55" class="example" data-section="Setext headers"> <div class="examplenum"> <a href="#example-55">Example 55</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code> ====</code></pre> <pre class="html"><code><p>====</p></code></pre> </div> <p>Setext header text lines must not be interpretable as block constructs other than paragraphs. So, the line of dashes in these examples gets interpreted as a horizontal rule:</p> <div id="example-56" class="example" data-section="Setext headers"> <div class="examplenum"> <a href="#example-56">Example 56</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>--- ---</code></pre> <pre class="html"><code><hr<span class="space"> </span>/> <hr<span class="space"> </span>/></code></pre> </div> <div id="example-57" class="example" data-section="Setext headers"> <div class="examplenum"> <a href="#example-57">Example 57</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>-<span class="space"> </span>foo -----</code></pre> <pre class="html"><code><ul> <li>foo</li> </ul> <hr<span class="space"> </span>/></code></pre> </div> <div id="example-58" class="example" data-section="Setext headers"> <div class="examplenum"> <a href="#example-58">Example 58</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>foo ---</code></pre> <pre class="html"><code><pre><code>foo </code></pre> <hr<span class="space"> </span>/></code></pre> </div> <div id="example-59" class="example" data-section="Setext headers"> <div class="examplenum"> <a href="#example-59">Example 59</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>><span class="space"> </span>foo -----</code></pre> <pre class="html"><code><blockquote> <p>foo</p> </blockquote> <hr<span class="space"> </span>/></code></pre> </div> <p>If you want a header with <code>> foo</code> as its literal text, you can use backslash escapes:</p> <div id="example-60" class="example" data-section="Setext headers"> <div class="examplenum"> <a href="#example-60">Example 60</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>\><span class="space"> </span>foo ------</code></pre> <pre class="html"><code><h2>&gt;<span class="space"> </span>foo</h2></code></pre> </div> <h2 id="indented-code-blocks"><span class="header-section-number">4.4</span> Indented code blocks</h2> <p>An <a id="indented-code-block" href="#indented-code-block" class="definition">indented code block</a> is composed of one or more <a href="#indented-chunk">indented chunks</a> separated by blank lines. An <a id="indented-chunk" href="#indented-chunk" class="definition">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-61" class="example" data-section="Indented code blocks"> <div class="examplenum"> <a href="#example-61">Example 61</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>a<span class="space"> </span>simple <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>indented<span class="space"> </span>code<span class="space"> </span>block</code></pre> <pre class="html"><code><pre><code>a<span class="space"> </span>simple <span class="space"> </span><span class="space"> </span>indented<span class="space"> </span>code<span class="space"> </span>block </code></pre></code></pre> </div> <p>The contents are literal text, and do not get parsed as Markdown:</p> <div id="example-62" class="example" data-section="Indented code blocks"> <div class="examplenum"> <a href="#example-62">Example 62</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><a/> <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>*hi* <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>-<span class="space"> </span>one</code></pre> <pre class="html"><code><pre><code>&lt;a/&gt; *hi* -<span class="space"> </span>one </code></pre></code></pre> </div> <p>Here we have three chunks separated by blank lines:</p> <div id="example-63" class="example" data-section="Indented code blocks"> <div class="examplenum"> <a href="#example-63">Example 63</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>chunk1 <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>chunk2 <span class="space"> </span><span class="space"> </span> <span class="space"> </span> <span class="space"> </span> <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>chunk3</code></pre> <pre class="html"><code><pre><code>chunk1 chunk2 chunk3 </code></pre></code></pre> </div> <p>Any initial spaces beyond four will be included in the content, even in interior blank lines:</p> <div id="example-64" class="example" data-section="Indented code blocks"> <div class="examplenum"> <a href="#example-64">Example 64</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>chunk1 <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span> <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>chunk2</code></pre> <pre class="html"><code><pre><code>chunk1 <span class="space"> </span><span class="space"> </span> <span class="space"> </span><span class="space"> </span>chunk2 </code></pre></code></pre> </div> <p>An indented code block cannot interrupt a paragraph. (This allows hanging indents and the like.)</p> <div id="example-65" class="example" data-section="Indented code blocks"> <div class="examplenum"> <a href="#example-65">Example 65</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>Foo <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>bar </code></pre> <pre class="html"><code><p>Foo bar</p></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-66" class="example" data-section="Indented code blocks"> <div class="examplenum"> <a href="#example-66">Example 66</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>foo bar</code></pre> <pre class="html"><code><pre><code>foo </code></pre> <p>bar</p></code></pre> </div> <p>And indented code can occur immediately before and after other kinds of blocks:</p> <div id="example-67" class="example" data-section="Indented code blocks"> <div class="examplenum"> <a href="#example-67">Example 67</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>#<span class="space"> </span>Header <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>foo Header ------ <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>foo ----</code></pre> <pre class="html"><code><h1>Header</h1> <pre><code>foo </code></pre> <h2>Header</h2> <pre><code>foo </code></pre> <hr<span class="space"> </span>/></code></pre> </div> <p>The first line can be indented more than four spaces:</p> <div id="example-68" class="example" data-section="Indented code blocks"> <div class="examplenum"> <a href="#example-68">Example 68</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>foo <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>bar</code></pre> <pre class="html"><code><pre><code><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>foo bar </code></pre></code></pre> </div> <p>Blank lines preceding or following an indented code block are not included in it:</p> <div id="example-69" class="example" data-section="Indented code blocks"> <div class="examplenum"> <a href="#example-69">Example 69</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code> <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span> <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>foo <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span> </code></pre> <pre class="html"><code><pre><code>foo </code></pre></code></pre> </div> <p>Trailing spaces are included in the code block’s content:</p> <div id="example-70" class="example" data-section="Indented code blocks"> <div class="examplenum"> <a href="#example-70">Example 70</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>foo<span class="space"> </span><span class="space"> </span></code></pre> <pre class="html"><code><pre><code>foo<span class="space"> </span><span class="space"> </span> </code></pre></code></pre> </div> <h2 id="fenced-code-blocks"><span class="header-section-number">4.5</span> Fenced code blocks</h2> <p>A <a id="code-fence" href="#code-fence" class="definition">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 id="fenced-code-block" href="#fenced-code-block" class="definition">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 id="info-string" href="#info-string" class="definition">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-71" class="example" data-section="Fenced code blocks"> <div class="examplenum"> <a href="#example-71">Example 71</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>``` < <span class="space"> </span>> ```</code></pre> <pre class="html"><code><pre><code>&lt; <span class="space"> </span>&gt; </code></pre></code></pre> </div> <p>With tildes:</p> <div id="example-72" class="example" data-section="Fenced code blocks"> <div class="examplenum"> <a href="#example-72">Example 72</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>~~~ < <span class="space"> </span>> ~~~</code></pre> <pre class="html"><code><pre><code>&lt; <span class="space"> </span>&gt; </code></pre></code></pre> </div> <p>The closing code fence must use the same character as the opening fence:</p> <div id="example-73" class="example" data-section="Fenced code blocks"> <div class="examplenum"> <a href="#example-73">Example 73</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>``` aaa ~~~ ```</code></pre> <pre class="html"><code><pre><code>aaa ~~~ </code></pre></code></pre> </div> <div id="example-74" class="example" data-section="Fenced code blocks"> <div class="examplenum"> <a href="#example-74">Example 74</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>~~~ aaa ``` ~~~</code></pre> <pre class="html"><code><pre><code>aaa ``` </code></pre></code></pre> </div> <p>The closing code fence must be at least as long as the opening fence:</p> <div id="example-75" class="example" data-section="Fenced code blocks"> <div class="examplenum"> <a href="#example-75">Example 75</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>```` aaa ``` ``````</code></pre> <pre class="html"><code><pre><code>aaa ``` </code></pre></code></pre> </div> <div id="example-76" class="example" data-section="Fenced code blocks"> <div class="examplenum"> <a href="#example-76">Example 76</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>~~~~ aaa ~~~ ~~~~</code></pre> <pre class="html"><code><pre><code>aaa ~~~ </code></pre></code></pre> </div> <p>Unclosed code blocks are closed by the end of the document:</p> <div id="example-77" class="example" data-section="Fenced code blocks"> <div class="examplenum"> <a href="#example-77">Example 77</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>```</code></pre> <pre class="html"><code><pre><code></code></pre></code></pre> </div> <div id="example-78" class="example" data-section="Fenced code blocks"> <div class="examplenum"> <a href="#example-78">Example 78</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>````` ``` aaa</code></pre> <pre class="html"><code><pre><code> ``` aaa </code></pre></code></pre> </div> <p>A code block can have all empty lines as its content:</p> <div id="example-79" class="example" data-section="Fenced code blocks"> <div class="examplenum"> <a href="#example-79">Example 79</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>``` <span class="space"> </span><span class="space"> </span> ```</code></pre> <pre class="html"><code><pre><code> <span class="space"> </span><span class="space"> </span> </code></pre></code></pre> </div> <p>A code block can be empty:</p> <div id="example-80" class="example" data-section="Fenced code blocks"> <div class="examplenum"> <a href="#example-80">Example 80</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>``` ```</code></pre> <pre class="html"><code><pre><code></code></pre></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-81" class="example" data-section="Fenced code blocks"> <div class="examplenum"> <a href="#example-81">Example 81</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span>``` <span class="space"> </span>aaa aaa ```</code></pre> <pre class="html"><code><pre><code>aaa aaa </code></pre></code></pre> </div> <div id="example-82" class="example" data-section="Fenced code blocks"> <div class="examplenum"> <a href="#example-82">Example 82</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span><span class="space"> </span>``` aaa <span class="space"> </span><span class="space"> </span>aaa aaa <span class="space"> </span><span class="space"> </span>```</code></pre> <pre class="html"><code><pre><code>aaa aaa aaa </code></pre></code></pre> </div> <div id="example-83" class="example" data-section="Fenced code blocks"> <div class="examplenum"> <a href="#example-83">Example 83</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span><span class="space"> </span><span class="space"> </span>``` <span class="space"> </span><span class="space"> </span><span class="space"> </span>aaa <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>aaa <span class="space"> </span><span class="space"> </span>aaa <span class="space"> </span><span class="space"> </span><span class="space"> </span>```</code></pre> <pre class="html"><code><pre><code>aaa <span class="space"> </span>aaa aaa </code></pre></code></pre> </div> <p>Four spaces indentation produces an indented code block:</p> <div id="example-84" class="example" data-section="Fenced code blocks"> <div class="examplenum"> <a href="#example-84">Example 84</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>``` <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>aaa <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>```</code></pre> <pre class="html"><code><pre><code>``` aaa ``` </code></pre></code></pre> </div> <p>Closing fences may be indented by 0-3 spaces, and their indentation need not match that of the opening fence:</p> <div id="example-85" class="example" data-section="Fenced code blocks"> <div class="examplenum"> <a href="#example-85">Example 85</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>``` aaa <span class="space"> </span><span class="space"> </span>```</code></pre> <pre class="html"><code><pre><code>aaa </code></pre></code></pre> </div> <div id="example-86" class="example" data-section="Fenced code blocks"> <div class="examplenum"> <a href="#example-86">Example 86</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span><span class="space"> </span><span class="space"> </span>``` aaa <span class="space"> </span><span class="space"> </span>```</code></pre> <pre class="html"><code><pre><code>aaa </code></pre></code></pre> </div> <p>This is not a closing fence, because it is indented 4 spaces:</p> <div id="example-87" class="example" data-section="Fenced code blocks"> <div class="examplenum"> <a href="#example-87">Example 87</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>``` aaa <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>```</code></pre> <pre class="html"><code><pre><code>aaa <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>``` </code></pre></code></pre> </div> <p>Code fences (opening and closing) cannot contain internal spaces:</p> <div id="example-88" class="example" data-section="Fenced code blocks"> <div class="examplenum"> <a href="#example-88">Example 88</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>```<span class="space"> </span>``` aaa</code></pre> <pre class="html"><code><p><code></code> aaa</p></code></pre> </div> <div id="example-89" class="example" data-section="Fenced code blocks"> <div class="examplenum"> <a href="#example-89">Example 89</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>~~~~~~ aaa ~~~<span class="space"> </span>~~</code></pre> <pre class="html"><code><pre><code>aaa ~~~<span class="space"> </span>~~ </code></pre></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-90" class="example" data-section="Fenced code blocks"> <div class="examplenum"> <a href="#example-90">Example 90</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>foo ``` bar ``` baz</code></pre> <pre class="html"><code><p>foo</p> <pre><code>bar </code></pre> <p>baz</p></code></pre> </div> <p>Other blocks can also occur before and after fenced code blocks without an intervening blank line:</p> <div id="example-91" class="example" data-section="Fenced code blocks"> <div class="examplenum"> <a href="#example-91">Example 91</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>foo --- ~~~ bar ~~~ #<span class="space"> </span>baz</code></pre> <pre class="html"><code><h2>foo</h2> <pre><code>bar </code></pre> <h1>baz</h1></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-92" class="example" data-section="Fenced code blocks"> <div class="examplenum"> <a href="#example-92">Example 92</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>```ruby def<span class="space"> </span>foo(x) <span class="space"> </span><span class="space"> </span>return<span class="space"> </span>3 end ```</code></pre> <pre class="html"><code><pre><code<span class="space"> </span>class="language-ruby">def<span class="space"> </span>foo(x) <span class="space"> </span><span class="space"> </span>return<span class="space"> </span>3 end </code></pre></code></pre> </div> <div id="example-93" class="example" data-section="Fenced code blocks"> <div class="examplenum"> <a href="#example-93">Example 93</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>~~~~<span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>ruby<span class="space"> </span>startline=3<span class="space"> </span>$%@#$ def<span class="space"> </span>foo(x) <span class="space"> </span><span class="space"> </span>return<span class="space"> </span>3 end ~~~~~~~</code></pre> <pre class="html"><code><pre><code<span class="space"> </span>class="language-ruby">def<span class="space"> </span>foo(x) <span class="space"> </span><span class="space"> </span>return<span class="space"> </span>3 end </code></pre></code></pre> </div> <div id="example-94" class="example" data-section="Fenced code blocks"> <div class="examplenum"> <a href="#example-94">Example 94</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>````; ````</code></pre> <pre class="html"><code><pre><code<span class="space"> </span>class="language-;"></code></pre></code></pre> </div> <p>Info strings for backtick code blocks cannot contain backticks:</p> <div id="example-95" class="example" data-section="Fenced code blocks"> <div class="examplenum"> <a href="#example-95">Example 95</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>```<span class="space"> </span>aa<span class="space"> </span>``` foo</code></pre> <pre class="html"><code><p><code>aa</code> foo</p></code></pre> </div> <p>Closing code fences cannot have info strings:</p> <div id="example-96" class="example" data-section="Fenced code blocks"> <div class="examplenum"> <a href="#example-96">Example 96</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>``` ```<span class="space"> </span>aaa ```</code></pre> <pre class="html"><code><pre><code>```<span class="space"> </span>aaa </code></pre></code></pre> </div> <h2 id="html-blocks"><span class="header-section-number">4.6</span> HTML blocks</h2> <p>An <a id="html-block-tag" href="#html-block-tag" class="definition">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>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 id="html-block" href="#html-block" class="definition">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-97" class="example" data-section="HTML blocks"> <div class="examplenum"> <a href="#example-97">Example 97</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><table> <span class="space"> </span><span class="space"> </span><tr> <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><td> <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>hi <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span></td> <span class="space"> </span><span class="space"> </span></tr> </table> okay.</code></pre> <pre class="html"><code><table> <span class="space"> </span><span class="space"> </span><tr> <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><td> <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>hi <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span></td> <span class="space"> </span><span class="space"> </span></tr> </table> <p>okay.</p></code></pre> </div> <div id="example-98" class="example" data-section="HTML blocks"> <div class="examplenum"> <a href="#example-98">Example 98</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span><div> <span class="space"> </span><span class="space"> </span>*hello* <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><foo><a></code></pre> <pre class="html"><code><span class="space"> </span><div> <span class="space"> </span><span class="space"> </span>*hello* <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><foo><a></code></pre> </div> <p>Here we have two HTML blocks with a Markdown paragraph between them:</p> <div id="example-99" class="example" data-section="HTML blocks"> <div class="examplenum"> <a href="#example-99">Example 99</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><DIV<span class="space"> </span>CLASS="foo"> *Markdown* </DIV></code></pre> <pre class="html"><code><DIV<span class="space"> </span>CLASS="foo"> <p><em>Markdown</em></p> </DIV></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-100" class="example" data-section="HTML blocks"> <div class="examplenum"> <a href="#example-100">Example 100</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><div></div> ```<span class="space"> </span>c int<span class="space"> </span>x<span class="space"> </span>=<span class="space"> </span>33; ```</code></pre> <pre class="html"><code><div></div> ```<span class="space"> </span>c int<span class="space"> </span>x<span class="space"> </span>=<span class="space"> </span>33; ```</code></pre> </div> <p>A comment:</p> <div id="example-101" class="example" data-section="HTML blocks"> <div class="examplenum"> <a href="#example-101">Example 101</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><!--<span class="space"> </span>Foo bar <span class="space"> </span><span class="space"> </span><span class="space"> </span>baz<span class="space"> </span>--></code></pre> <pre class="html"><code><!--<span class="space"> </span>Foo bar <span class="space"> </span><span class="space"> </span><span class="space"> </span>baz<span class="space"> </span>--></code></pre> </div> <p>A processing instruction:</p> <div id="example-102" class="example" data-section="HTML blocks"> <div class="examplenum"> <a href="#example-102">Example 102</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><?php <span class="space"> </span><span class="space"> </span>echo<span class="space"> </span>'>'; ?></code></pre> <pre class="html"><code><?php <span class="space"> </span><span class="space"> </span>echo<span class="space"> </span>'>'; ?></code></pre> </div> <p>CDATA:</p> <div id="example-103" class="example" data-section="HTML blocks"> <div class="examplenum"> <a href="#example-103">Example 103</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><![CDATA[ function<span class="space"> </span>matchwo(a,b) { if<span class="space"> </span>(a<span class="space"> </span><<span class="space"> </span>b<span class="space"> </span>&&<span class="space"> </span>a<span class="space"> </span><<span class="space"> </span>0)<span class="space"> </span>then <span class="space"> </span><span class="space"> </span>{ <span class="space"> </span><span class="space"> </span>return<span class="space"> </span>1; <span class="space"> </span><span class="space"> </span>} else <span class="space"> </span><span class="space"> </span>{ <span class="space"> </span><span class="space"> </span>return<span class="space"> </span>0; <span class="space"> </span><span class="space"> </span>} } ]]></code></pre> <pre class="html"><code><![CDATA[ function<span class="space"> </span>matchwo(a,b) { if<span class="space"> </span>(a<span class="space"> </span><<span class="space"> </span>b<span class="space"> </span>&&<span class="space"> </span>a<span class="space"> </span><<span class="space"> </span>0)<span class="space"> </span>then <span class="space"> </span><span class="space"> </span>{ <span class="space"> </span><span class="space"> </span>return<span class="space"> </span>1; <span class="space"> </span><span class="space"> </span>} else <span class="space"> </span><span class="space"> </span>{ <span class="space"> </span><span class="space"> </span>return<span class="space"> </span>0; <span class="space"> </span><span class="space"> </span>} } ]]></code></pre> </div> <p>The opening tag can be indented 1-3 spaces, but not 4:</p> <div id="example-104" class="example" data-section="HTML blocks"> <div class="examplenum"> <a href="#example-104">Example 104</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span><span class="space"> </span><!--<span class="space"> </span>foo<span class="space"> </span>--> <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><!--<span class="space"> </span>foo<span class="space"> </span>--></code></pre> <pre class="html"><code><span class="space"> </span><span class="space"> </span><!--<span class="space"> </span>foo<span class="space"> </span>--> <pre><code>&lt;!--<span class="space"> </span>foo<span class="space"> </span>--&gt; </code></pre></code></pre> </div> <p>An HTML block can interrupt a paragraph, and need not be preceded by a blank line.</p> <div id="example-105" class="example" data-section="HTML blocks"> <div class="examplenum"> <a href="#example-105">Example 105</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>Foo <div> bar </div></code></pre> <pre class="html"><code><p>Foo</p> <div> bar </div></code></pre> </div> <p>However, a following blank line is always needed, except at the end of a document:</p> <div id="example-106" class="example" data-section="HTML blocks"> <div class="examplenum"> <a href="#example-106">Example 106</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><div> bar </div> *foo*</code></pre> <pre class="html"><code><div> bar </div> *foo*</code></pre> </div> <p>An incomplete HTML block tag may also start an HTML block:</p> <div id="example-107" class="example" data-section="HTML blocks"> <div class="examplenum"> <a href="#example-107">Example 107</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><div<span class="space"> </span>class foo</code></pre> <pre class="html"><code><div<span class="space"> </span>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><div></code>, <code><table></code>, <code><pre></code>, <code><p></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-108" class="example" data-section="HTML blocks"> <div class="examplenum"> <a href="#example-108">Example 108</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><div> *Emphasized*<span class="space"> </span>text. </div></code></pre> <pre class="html"><code><div> <p><em>Emphasized</em><span class="space"> </span>text.</p> </div></code></pre> </div> <p>Compare:</p> <div id="example-109" class="example" data-section="HTML blocks"> <div class="examplenum"> <a href="#example-109">Example 109</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><div> *Emphasized*<span class="space"> </span>text. </div></code></pre> <pre class="html"><code><div> *Emphasized*<span class="space"> </span>text. </div></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-110" class="example" data-section="HTML blocks"> <div class="examplenum"> <a href="#example-110">Example 110</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><table> <tr> <td> Hi </td> </tr> </table></code></pre> <pre class="html"><code><table> <tr> <td> Hi </td> </tr> </table></code></pre> </div> <p>Moreover, blank lines are usually not necessary and can be deleted. The exception is inside <code><pre></code> tags; here, one can replace the blank lines with <code>&#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 id="link-reference-definition" href="#link-reference-definition" class="definition">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-111" class="example" data-section="Link reference definitions"> <div class="examplenum"> <a href="#example-111">Example 111</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[foo]:<span class="space"> </span>/url<span class="space"> </span>"title" [foo]</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/url"<span class="space"> </span>title="title">foo</a></p></code></pre> </div> <div id="example-112" class="example" data-section="Link reference definitions"> <div class="examplenum"> <a href="#example-112">Example 112</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span><span class="space"> </span><span class="space"> </span>[foo]:<span class="space"> </span> <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>/url<span class="space"> </span><span class="space"> </span> <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>'the<span class="space"> </span>title'<span class="space"> </span><span class="space"> </span> [foo]</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/url"<span class="space"> </span>title="the<span class="space"> </span>title">foo</a></p></code></pre> </div> <div id="example-113" class="example" data-section="Link reference definitions"> <div class="examplenum"> <a href="#example-113">Example 113</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[Foo*bar\]]:my_(url)<span class="space"> </span>'title<span class="space"> </span>(with<span class="space"> </span>parens)' [Foo*bar\]]</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="my_(url)"<span class="space"> </span>title="title<span class="space"> </span>(with<span class="space"> </span>parens)">Foo*bar]</a></p></code></pre> </div> <div id="example-114" class="example" data-section="Link reference definitions"> <div class="examplenum"> <a href="#example-114">Example 114</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[Foo<span class="space"> </span>bar]: <my<span class="space"> </span>url> 'title' [Foo<span class="space"> </span>bar]</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="my%20url"<span class="space"> </span>title="title">Foo<span class="space"> </span>bar</a></p></code></pre> </div> <p>The title may be omitted:</p> <div id="example-115" class="example" data-section="Link reference definitions"> <div class="examplenum"> <a href="#example-115">Example 115</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[foo]: /url [foo]</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/url">foo</a></p></code></pre> </div> <p>The link destination may not be omitted:</p> <div id="example-116" class="example" data-section="Link reference definitions"> <div class="examplenum"> <a href="#example-116">Example 116</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[foo]: [foo]</code></pre> <pre class="html"><code><p>[foo]:</p> <p>[foo]</p></code></pre> </div> <p>A link can come before its corresponding definition:</p> <div id="example-117" class="example" data-section="Link reference definitions"> <div class="examplenum"> <a href="#example-117">Example 117</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[foo] [foo]:<span class="space"> </span>url</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="url">foo</a></p></code></pre> </div> <p>If there are several matching definitions, the first one takes precedence:</p> <div id="example-118" class="example" data-section="Link reference definitions"> <div class="examplenum"> <a href="#example-118">Example 118</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[foo] [foo]:<span class="space"> </span>first [foo]:<span class="space"> </span>second</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="first">foo</a></p></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-119" class="example" data-section="Link reference definitions"> <div class="examplenum"> <a href="#example-119">Example 119</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[FOO]:<span class="space"> </span>/url [Foo]</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/url">Foo</a></p></code></pre> </div> <div id="example-120" class="example" data-section="Link reference definitions"> <div class="examplenum"> <a href="#example-120">Example 120</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[ΑΓΩ]:<span class="space"> </span>/φου [αγω]</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/%CF%86%CE%BF%CF%85">αγω</a></p></code></pre> </div> <p>Here is a link reference definition with no corresponding link. It contributes nothing to the document.</p> <div id="example-121" class="example" data-section="Link reference definitions"> <div class="examplenum"> <a href="#example-121">Example 121</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[foo]:<span class="space"> </span>/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-122" class="example" data-section="Link reference definitions"> <div class="examplenum"> <a href="#example-122">Example 122</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[foo]:<span class="space"> </span>/url<span class="space"> </span>"title"<span class="space"> </span>ok</code></pre> <pre class="html"><code><p>[foo]:<span class="space"> </span>/url<span class="space"> </span>&quot;title&quot;<span class="space"> </span>ok</p></code></pre> </div> <p>This is not a link reference definition, because it is indented four spaces:</p> <div id="example-123" class="example" data-section="Link reference definitions"> <div class="examplenum"> <a href="#example-123">Example 123</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>[foo]:<span class="space"> </span>/url<span class="space"> </span>"title" [foo]</code></pre> <pre class="html"><code><pre><code>[foo]:<span class="space"> </span>/url<span class="space"> </span>&quot;title&quot; </code></pre> <p>[foo]</p></code></pre> </div> <p>This is not a link reference definition, because it occurs inside a code block:</p> <div id="example-124" class="example" data-section="Link reference definitions"> <div class="examplenum"> <a href="#example-124">Example 124</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>``` [foo]:<span class="space"> </span>/url ``` [foo]</code></pre> <pre class="html"><code><pre><code>[foo]:<span class="space"> </span>/url </code></pre> <p>[foo]</p></code></pre> </div> <p>A <a href="#link-reference-definition">link reference definition</a> cannot interrupt a paragraph.</p> <div id="example-125" class="example" data-section="Link reference definitions"> <div class="examplenum"> <a href="#example-125">Example 125</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>Foo [bar]:<span class="space"> </span>/baz [bar]</code></pre> <pre class="html"><code><p>Foo [bar]:<span class="space"> </span>/baz</p> <p>[bar]</p></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-126" class="example" data-section="Link reference definitions"> <div class="examplenum"> <a href="#example-126">Example 126</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>#<span class="space"> </span>[Foo] [foo]:<span class="space"> </span>/url ><span class="space"> </span>bar</code></pre> <pre class="html"><code><h1><a<span class="space"> </span>href="/url">Foo</a></h1> <blockquote> <p>bar</p> </blockquote></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-127" class="example" data-section="Link reference definitions"> <div class="examplenum"> <a href="#example-127">Example 127</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[foo]:<span class="space"> </span>/foo-url<span class="space"> </span>"foo" [bar]:<span class="space"> </span>/bar-url <span class="space"> </span><span class="space"> </span>"bar" [baz]:<span class="space"> </span>/baz-url [foo], [bar], [baz]</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/foo-url"<span class="space"> </span>title="foo">foo</a>, <a<span class="space"> </span>href="/bar-url"<span class="space"> </span>title="bar">bar</a>, <a<span class="space"> </span>href="/baz-url">baz</a></p></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-128" class="example" data-section="Link reference definitions"> <div class="examplenum"> <a href="#example-128">Example 128</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[foo] ><span class="space"> </span>[foo]:<span class="space"> </span>/url</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/url">foo</a></p> <blockquote> </blockquote></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 id="paragraph" href="#paragraph" class="definition">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-129" class="example" data-section="Paragraphs"> <div class="examplenum"> <a href="#example-129">Example 129</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>aaa bbb</code></pre> <pre class="html"><code><p>aaa</p> <p>bbb</p></code></pre> </div> <p>Paragraphs can contain multiple lines, but no blank lines:</p> <div id="example-130" class="example" data-section="Paragraphs"> <div class="examplenum"> <a href="#example-130">Example 130</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>aaa bbb ccc ddd</code></pre> <pre class="html"><code><p>aaa bbb</p> <p>ccc ddd</p></code></pre> </div> <p>Multiple blank lines between paragraph have no effect:</p> <div id="example-131" class="example" data-section="Paragraphs"> <div class="examplenum"> <a href="#example-131">Example 131</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>aaa bbb</code></pre> <pre class="html"><code><p>aaa</p> <p>bbb</p></code></pre> </div> <p>Leading spaces are skipped:</p> <div id="example-132" class="example" data-section="Paragraphs"> <div class="examplenum"> <a href="#example-132">Example 132</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span><span class="space"> </span>aaa <span class="space"> </span>bbb</code></pre> <pre class="html"><code><p>aaa bbb</p></code></pre> </div> <p>Lines after the first may be indented any amount, since indented code blocks cannot interrupt paragraphs.</p> <div id="example-133" class="example" data-section="Paragraphs"> <div class="examplenum"> <a href="#example-133">Example 133</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>aaa <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>bbb <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>ccc</code></pre> <pre class="html"><code><p>aaa bbb ccc</p></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-134" class="example" data-section="Paragraphs"> <div class="examplenum"> <a href="#example-134">Example 134</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span><span class="space"> </span><span class="space"> </span>aaa bbb</code></pre> <pre class="html"><code><p>aaa bbb</p></code></pre> </div> <div id="example-135" class="example" data-section="Paragraphs"> <div class="examplenum"> <a href="#example-135">Example 135</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>aaa bbb</code></pre> <pre class="html"><code><pre><code>aaa </code></pre> <p>bbb</p></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 <a href="#hard-line-break">hard line break</a>:</p> <div id="example-136" class="example" data-section="Paragraphs"> <div class="examplenum"> <a href="#example-136">Example 136</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>aaa<span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span> bbb<span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span></code></pre> <pre class="html"><code><p>aaa<br<span class="space"> </span>/> bbb</p></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-137" class="example" data-section="Blank lines"> <div class="examplenum"> <a href="#example-137">Example 137</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span><span class="space"> </span> aaa <span class="space"> </span><span class="space"> </span> #<span class="space"> </span>aaa <span class="space"> </span><span class="space"> </span></code></pre> <pre class="html"><code><p>aaa</p> <h1>aaa</h1></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 href="#appendix-a-a-parsing-strategy">A parsing strategy</a>.)</p> <h2 id="block-quotes"><span class="header-section-number">5.1</span> Block quotes</h2> <p>A <a id="block-quote-marker" href="#block-quote-marker" class="definition">block quote marker</a> consists of 0-3 spaces of initial indent, plus (a) the character <code>></code> together with a following space, or (b) a single character <code>></code> not followed by a space.</p> <p>The following rules define <a id="block-quote" href="#block-quote" class="definition">block quotes</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 prepending a <a href="#block-quote-marker">block quote marker</a> 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" href="#paragraph-continuation-text" class="definition">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-138" class="example" data-section="Block quotes"> <div class="examplenum"> <a href="#example-138">Example 138</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>><span class="space"> </span>#<span class="space"> </span>Foo ><span class="space"> </span>bar ><span class="space"> </span>baz</code></pre> <pre class="html"><code><blockquote> <h1>Foo</h1> <p>bar baz</p> </blockquote></code></pre> </div> <p>The spaces after the <code>></code> characters can be omitted:</p> <div id="example-139" class="example" data-section="Block quotes"> <div class="examplenum"> <a href="#example-139">Example 139</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>>#<span class="space"> </span>Foo >bar ><span class="space"> </span>baz</code></pre> <pre class="html"><code><blockquote> <h1>Foo</h1> <p>bar baz</p> </blockquote></code></pre> </div> <p>The <code>></code> characters can be indented 1-3 spaces:</p> <div id="example-140" class="example" data-section="Block quotes"> <div class="examplenum"> <a href="#example-140">Example 140</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span><span class="space"> </span><span class="space"> </span>><span class="space"> </span>#<span class="space"> </span>Foo <span class="space"> </span><span class="space"> </span><span class="space"> </span>><span class="space"> </span>bar <span class="space"> </span>><span class="space"> </span>baz</code></pre> <pre class="html"><code><blockquote> <h1>Foo</h1> <p>bar baz</p> </blockquote></code></pre> </div> <p>Four spaces gives us a code block:</p> <div id="example-141" class="example" data-section="Block quotes"> <div class="examplenum"> <a href="#example-141">Example 141</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>><span class="space"> </span>#<span class="space"> </span>Foo <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>><span class="space"> </span>bar <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>><span class="space"> </span>baz</code></pre> <pre class="html"><code><pre><code>&gt;<span class="space"> </span>#<span class="space"> </span>Foo &gt;<span class="space"> </span>bar &gt;<span class="space"> </span>baz </code></pre></code></pre> </div> <p>The Laziness clause allows us to omit the <code>></code> before a paragraph continuation line:</p> <div id="example-142" class="example" data-section="Block quotes"> <div class="examplenum"> <a href="#example-142">Example 142</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>><span class="space"> </span>#<span class="space"> </span>Foo ><span class="space"> </span>bar baz</code></pre> <pre class="html"><code><blockquote> <h1>Foo</h1> <p>bar baz</p> </blockquote></code></pre> </div> <p>A block quote can contain some lazy and some non-lazy continuation lines:</p> <div id="example-143" class="example" data-section="Block quotes"> <div class="examplenum"> <a href="#example-143">Example 143</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>><span class="space"> </span>bar baz ><span class="space"> </span>foo</code></pre> <pre class="html"><code><blockquote> <p>bar baz foo</p> </blockquote></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-144" class="example" data-section="Block quotes"> <div class="examplenum"> <a href="#example-144">Example 144</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>><span class="space"> </span>foo ---</code></pre> <pre class="html"><code><blockquote> <p>foo</p> </blockquote> <hr<span class="space"> </span>/></code></pre> </div> <div id="example-145" class="example" data-section="Block quotes"> <div class="examplenum"> <a href="#example-145">Example 145</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>><span class="space"> </span>-<span class="space"> </span>foo -<span class="space"> </span>bar</code></pre> <pre class="html"><code><blockquote> <ul> <li>foo</li> </ul> </blockquote> <ul> <li>bar</li> </ul></code></pre> </div> <div id="example-146" class="example" data-section="Block quotes"> <div class="examplenum"> <a href="#example-146">Example 146</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>foo <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>bar</code></pre> <pre class="html"><code><blockquote> <pre><code>foo </code></pre> </blockquote> <pre><code>bar </code></pre></code></pre> </div> <div id="example-147" class="example" data-section="Block quotes"> <div class="examplenum"> <a href="#example-147">Example 147</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>><span class="space"> </span>``` foo ```</code></pre> <pre class="html"><code><blockquote> <pre><code></code></pre> </blockquote> <p>foo</p> <pre><code></code></pre></code></pre> </div> <p>A block quote can be empty:</p> <div id="example-148" class="example" data-section="Block quotes"> <div class="examplenum"> <a href="#example-148">Example 148</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>></code></pre> <pre class="html"><code><blockquote> </blockquote></code></pre> </div> <div id="example-149" class="example" data-section="Block quotes"> <div class="examplenum"> <a href="#example-149">Example 149</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>> ><span class="space"> </span><span class="space"> </span> ><span class="space"> </span></code></pre> <pre class="html"><code><blockquote> </blockquote></code></pre> </div> <p>A block quote can have initial or final blank lines:</p> <div id="example-150" class="example" data-section="Block quotes"> <div class="examplenum"> <a href="#example-150">Example 150</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>> ><span class="space"> </span>foo ><span class="space"> </span><span class="space"> </span></code></pre> <pre class="html"><code><blockquote> <p>foo</p> </blockquote></code></pre> </div> <p>A blank line always separates block quotes:</p> <div id="example-151" class="example" data-section="Block quotes"> <div class="examplenum"> <a href="#example-151">Example 151</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>><span class="space"> </span>foo ><span class="space"> </span>bar</code></pre> <pre class="html"><code><blockquote> <p>foo</p> </blockquote> <blockquote> <p>bar</p> </blockquote></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-152" class="example" data-section="Block quotes"> <div class="examplenum"> <a href="#example-152">Example 152</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>><span class="space"> </span>foo ><span class="space"> </span>bar</code></pre> <pre class="html"><code><blockquote> <p>foo bar</p> </blockquote></code></pre> </div> <p>To get a block quote with two paragraphs, use:</p> <div id="example-153" class="example" data-section="Block quotes"> <div class="examplenum"> <a href="#example-153">Example 153</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>><span class="space"> </span>foo > ><span class="space"> </span>bar</code></pre> <pre class="html"><code><blockquote> <p>foo</p> <p>bar</p> </blockquote></code></pre> </div> <p>Block quotes can interrupt paragraphs:</p> <div id="example-154" class="example" data-section="Block quotes"> <div class="examplenum"> <a href="#example-154">Example 154</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>foo ><span class="space"> </span>bar</code></pre> <pre class="html"><code><p>foo</p> <blockquote> <p>bar</p> </blockquote></code></pre> </div> <p>In general, blank lines are not needed before or after block quotes:</p> <div id="example-155" class="example" data-section="Block quotes"> <div class="examplenum"> <a href="#example-155">Example 155</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>><span class="space"> </span>aaa *** ><span class="space"> </span>bbb</code></pre> <pre class="html"><code><blockquote> <p>aaa</p> </blockquote> <hr<span class="space"> </span>/> <blockquote> <p>bbb</p> </blockquote></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-156" class="example" data-section="Block quotes"> <div class="examplenum"> <a href="#example-156">Example 156</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>><span class="space"> </span>bar baz</code></pre> <pre class="html"><code><blockquote> <p>bar baz</p> </blockquote></code></pre> </div> <div id="example-157" class="example" data-section="Block quotes"> <div class="examplenum"> <a href="#example-157">Example 157</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>><span class="space"> </span>bar baz</code></pre> <pre class="html"><code><blockquote> <p>bar</p> </blockquote> <p>baz</p></code></pre> </div> <div id="example-158" class="example" data-section="Block quotes"> <div class="examplenum"> <a href="#example-158">Example 158</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>><span class="space"> </span>bar > baz</code></pre> <pre class="html"><code><blockquote> <p>bar</p> </blockquote> <p>baz</p></code></pre> </div> <p>It is a consequence of the Laziness rule that any number of initial <code>></code>s may be omitted on a continuation line of a nested block quote:</p> <div id="example-159" class="example" data-section="Block quotes"> <div class="examplenum"> <a href="#example-159">Example 159</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>><span class="space"> </span>><span class="space"> </span>><span class="space"> </span>foo bar</code></pre> <pre class="html"><code><blockquote> <blockquote> <blockquote> <p>foo bar</p> </blockquote> </blockquote> </blockquote></code></pre> </div> <div id="example-160" class="example" data-section="Block quotes"> <div class="examplenum"> <a href="#example-160">Example 160</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>>>><span class="space"> </span>foo ><span class="space"> </span>bar >>baz</code></pre> <pre class="html"><code><blockquote> <blockquote> <blockquote> <p>foo bar baz</p> </blockquote> </blockquote> </blockquote></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>></code> and a following space. So <em>five spaces</em> are needed after the <code>></code>:</p> <div id="example-161" class="example" data-section="Block quotes"> <div class="examplenum"> <a href="#example-161">Example 161</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>code ><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>not<span class="space"> </span>code</code></pre> <pre class="html"><code><blockquote> <pre><code>code </code></pre> </blockquote> <blockquote> <p>not<span class="space"> </span>code</p> </blockquote></code></pre> </div> <h2 id="list-items"><span class="header-section-number">5.2</span> List items</h2> <p>A <a id="list-marker" href="#list-marker" class="definition">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 id="bullet-list-marker" href="#bullet-list-marker" class="definition">bullet list marker</a> is a <code>-</code>, <code>+</code>, or <code>*</code> character.</p> <p>An <a id="ordered-list-marker" href="#ordered-list-marker" class="definition">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 id="list-item" href="#list-item" class="definition">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 < <em>N</em> < 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-162" class="example" data-section="List items"> <div class="examplenum"> <a href="#example-162">Example 162</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>A<span class="space"> </span>paragraph with<span class="space"> </span>two<span class="space"> </span>lines. <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>indented<span class="space"> </span>code ><span class="space"> </span>A<span class="space"> </span>block<span class="space"> </span>quote.</code></pre> <pre class="html"><code><p>A<span class="space"> </span>paragraph with<span class="space"> </span>two<span class="space"> </span>lines.</p> <pre><code>indented<span class="space"> </span>code </code></pre> <blockquote> <p>A<span class="space"> </span>block<span class="space"> </span>quote.</p> </blockquote></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-163" class="example" data-section="List items"> <div class="examplenum"> <a href="#example-163">Example 163</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>1.<span class="space"> </span><span class="space"> </span>A<span class="space"> </span>paragraph <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>with<span class="space"> </span>two<span class="space"> </span>lines. <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>indented<span class="space"> </span>code <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>><span class="space"> </span>A<span class="space"> </span>block<span class="space"> </span>quote.</code></pre> <pre class="html"><code><ol> <li><p>A<span class="space"> </span>paragraph with<span class="space"> </span>two<span class="space"> </span>lines.</p> <pre><code>indented<span class="space"> </span>code </code></pre> <blockquote> <p>A<span class="space"> </span>block<span class="space"> </span>quote.</p> </blockquote></li> </ol></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 nonspace 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-164" class="example" data-section="List items"> <div class="examplenum"> <a href="#example-164">Example 164</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>-<span class="space"> </span>one <span class="space"> </span>two</code></pre> <pre class="html"><code><ul> <li>one</li> </ul> <p>two</p></code></pre> </div> <div id="example-165" class="example" data-section="List items"> <div class="examplenum"> <a href="#example-165">Example 165</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>-<span class="space"> </span>one <span class="space"> </span><span class="space"> </span>two</code></pre> <pre class="html"><code><ul> <li><p>one</p> <p>two</p></li> </ul></code></pre> </div> <div id="example-166" class="example" data-section="List items"> <div class="examplenum"> <a href="#example-166">Example 166</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span>-<span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>one <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>two</code></pre> <pre class="html"><code><ul> <li>one</li> </ul> <pre><code><span class="space"> </span>two </code></pre></code></pre> </div> <div id="example-167" class="example" data-section="List items"> <div class="examplenum"> <a href="#example-167">Example 167</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span>-<span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>one <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>two</code></pre> <pre class="html"><code><ul> <li><p>one</p> <p>two</p></li> </ul></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 nonspace 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-168" class="example" data-section="List items"> <div class="examplenum"> <a href="#example-168">Example 168</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span><span class="space"> </span><span class="space"> </span>><span class="space"> </span>><span class="space"> </span>1.<span class="space"> </span><span class="space"> </span>one >> >><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>two</code></pre> <pre class="html"><code><blockquote> <blockquote> <ol> <li><p>one</p> <p>two</p></li> </ol> </blockquote> </blockquote></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 sufficent 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-169" class="example" data-section="List items"> <div class="examplenum"> <a href="#example-169">Example 169</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>>>-<span class="space"> </span>one >> <span class="space"> </span><span class="space"> </span>><span class="space"> </span><span class="space"> </span>><span class="space"> </span>two</code></pre> <pre class="html"><code><blockquote> <blockquote> <ul> <li>one</li> </ul> <p>two</p> </blockquote> </blockquote></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-170" class="example" data-section="List items"> <div class="examplenum"> <a href="#example-170">Example 170</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>-<span class="space"> </span>foo <span class="space"> </span><span class="space"> </span>bar -<span class="space"> </span>foo <span class="space"> </span><span class="space"> </span>bar -<span class="space"> </span>``` <span class="space"> </span><span class="space"> </span>foo <span class="space"> </span><span class="space"> </span>bar <span class="space"> </span><span class="space"> </span>```</code></pre> <pre class="html"><code><ul> <li><p>foo</p> <p>bar</p></li> <li><p>foo</p></li> </ul> <p>bar</p> <ul> <li><pre><code>foo bar </code></pre></li> </ul></code></pre> </div> <p>A list item may contain any kind of block:</p> <div id="example-171" class="example" data-section="List items"> <div class="examplenum"> <a href="#example-171">Example 171</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>1.<span class="space"> </span><span class="space"> </span>foo <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>``` <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>bar <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>``` <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>baz <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>><span class="space"> </span>bam</code></pre> <pre class="html"><code><ol> <li><p>foo</p> <pre><code>bar </code></pre> <p>baz</p> <blockquote> <p>bam</p> </blockquote></li> </ol></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-172" class="example" data-section="List items"> <div class="examplenum"> <a href="#example-172">Example 172</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>-<span class="space"> </span>foo <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>bar</code></pre> <pre class="html"><code><ul> <li><p>foo</p> <pre><code>bar </code></pre></li> </ul></code></pre> </div> <p>And in this case it is 11 spaces:</p> <div id="example-173" class="example" data-section="List items"> <div class="examplenum"> <a href="#example-173">Example 173</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span><span class="space"> </span>10.<span class="space"> </span><span class="space"> </span>foo <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>bar</code></pre> <pre class="html"><code><ol<span class="space"> </span>start="10"> <li><p>foo</p> <pre><code>bar </code></pre></li> </ol></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-174" class="example" data-section="List items"> <div class="examplenum"> <a href="#example-174">Example 174</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>indented<span class="space"> </span>code paragraph <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>more<span class="space"> </span>code</code></pre> <pre class="html"><code><pre><code>indented<span class="space"> </span>code </code></pre> <p>paragraph</p> <pre><code>more<span class="space"> </span>code </code></pre></code></pre> </div> <div id="example-175" class="example" data-section="List items"> <div class="examplenum"> <a href="#example-175">Example 175</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>1.<span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>indented<span class="space"> </span>code <span class="space"> </span><span class="space"> </span><span class="space"> </span>paragraph <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>more<span class="space"> </span>code</code></pre> <pre class="html"><code><ol> <li><pre><code>indented<span class="space"> </span>code </code></pre> <p>paragraph</p> <pre><code>more<span class="space"> </span>code </code></pre></li> </ol></code></pre> </div> <p>Note that an additional space indent is interpreted as space inside the code block:</p> <div id="example-176" class="example" data-section="List items"> <div class="examplenum"> <a href="#example-176">Example 176</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>1.<span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>indented<span class="space"> </span>code <span class="space"> </span><span class="space"> </span><span class="space"> </span>paragraph <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>more<span class="space"> </span>code</code></pre> <pre class="html"><code><ol> <li><pre><code><span class="space"> </span>indented<span class="space"> </span>code </code></pre> <p>paragraph</p> <pre><code>more<span class="space"> </span>code </code></pre></li> </ol></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 nonspace 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-177" class="example" data-section="List items"> <div class="examplenum"> <a href="#example-177">Example 177</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span><span class="space"> </span><span class="space"> </span>foo bar</code></pre> <pre class="html"><code><p>foo</p> <p>bar</p></code></pre> </div> <div id="example-178" class="example" data-section="List items"> <div class="examplenum"> <a href="#example-178">Example 178</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>-<span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>foo <span class="space"> </span><span class="space"> </span>bar</code></pre> <pre class="html"><code><ul> <li>foo</li> </ul> <p>bar</p></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-179" class="example" data-section="List items"> <div class="examplenum"> <a href="#example-179">Example 179</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>-<span class="space"> </span><span class="space"> </span>foo <span class="space"> </span><span class="space"> </span><span class="space"> </span>bar</code></pre> <pre class="html"><code><ul> <li><p>foo</p> <p>bar</p></li> </ul></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-180" class="example" data-section="List items"> <div class="examplenum"> <a href="#example-180">Example 180</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span>1.<span class="space"> </span><span class="space"> </span>A<span class="space"> </span>paragraph <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>with<span class="space"> </span>two<span class="space"> </span>lines. <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>indented<span class="space"> </span>code <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>><span class="space"> </span>A<span class="space"> </span>block<span class="space"> </span>quote.</code></pre> <pre class="html"><code><ol> <li><p>A<span class="space"> </span>paragraph with<span class="space"> </span>two<span class="space"> </span>lines.</p> <pre><code>indented<span class="space"> </span>code </code></pre> <blockquote> <p>A<span class="space"> </span>block<span class="space"> </span>quote.</p> </blockquote></li> </ol></code></pre> </div> <p>Indented two spaces:</p> <div id="example-181" class="example" data-section="List items"> <div class="examplenum"> <a href="#example-181">Example 181</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span><span class="space"> </span>1.<span class="space"> </span><span class="space"> </span>A<span class="space"> </span>paragraph <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>with<span class="space"> </span>two<span class="space"> </span>lines. <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>indented<span class="space"> </span>code <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>><span class="space"> </span>A<span class="space"> </span>block<span class="space"> </span>quote.</code></pre> <pre class="html"><code><ol> <li><p>A<span class="space"> </span>paragraph with<span class="space"> </span>two<span class="space"> </span>lines.</p> <pre><code>indented<span class="space"> </span>code </code></pre> <blockquote> <p>A<span class="space"> </span>block<span class="space"> </span>quote.</p> </blockquote></li> </ol></code></pre> </div> <p>Indented three spaces:</p> <div id="example-182" class="example" data-section="List items"> <div class="examplenum"> <a href="#example-182">Example 182</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span><span class="space"> </span><span class="space"> </span>1.<span class="space"> </span><span class="space"> </span>A<span class="space"> </span>paragraph <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>with<span class="space"> </span>two<span class="space"> </span>lines. <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>indented<span class="space"> </span>code <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>><span class="space"> </span>A<span class="space"> </span>block<span class="space"> </span>quote.</code></pre> <pre class="html"><code><ol> <li><p>A<span class="space"> </span>paragraph with<span class="space"> </span>two<span class="space"> </span>lines.</p> <pre><code>indented<span class="space"> </span>code </code></pre> <blockquote> <p>A<span class="space"> </span>block<span class="space"> </span>quote.</p> </blockquote></li> </ol></code></pre> </div> <p>Four spaces indent gives a code block:</p> <div id="example-183" class="example" data-section="List items"> <div class="examplenum"> <a href="#example-183">Example 183</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>1.<span class="space"> </span><span class="space"> </span>A<span class="space"> </span>paragraph <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>with<span class="space"> </span>two<span class="space"> </span>lines. <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>indented<span class="space"> </span>code <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>><span class="space"> </span>A<span class="space"> </span>block<span class="space"> </span>quote.</code></pre> <pre class="html"><code><pre><code>1.<span class="space"> </span><span class="space"> </span>A<span class="space"> </span>paragraph <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>with<span class="space"> </span>two<span class="space"> </span>lines. <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>indented<span class="space"> </span>code <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>&gt;<span class="space"> </span>A<span class="space"> </span>block<span class="space"> </span>quote. </code></pre></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. The unindented lines are called <a id="lazy-continuation-line" href="#lazy-continuation-line" class="definition">lazy continuation lines</a>.</li> </ol> <p>Here is an example with <a href="#lazy-continuation-line">lazy continuation lines</a>:</p> <div id="example-184" class="example" data-section="List items"> <div class="examplenum"> <a href="#example-184">Example 184</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span><span class="space"> </span>1.<span class="space"> </span><span class="space"> </span>A<span class="space"> </span>paragraph with<span class="space"> </span>two<span class="space"> </span>lines. <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>indented<span class="space"> </span>code <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>><span class="space"> </span>A<span class="space"> </span>block<span class="space"> </span>quote.</code></pre> <pre class="html"><code><ol> <li><p>A<span class="space"> </span>paragraph with<span class="space"> </span>two<span class="space"> </span>lines.</p> <pre><code>indented<span class="space"> </span>code </code></pre> <blockquote> <p>A<span class="space"> </span>block<span class="space"> </span>quote.</p> </blockquote></li> </ol></code></pre> </div> <p>Indentation can be partially deleted:</p> <div id="example-185" class="example" data-section="List items"> <div class="examplenum"> <a href="#example-185">Example 185</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span><span class="space"> </span>1.<span class="space"> </span><span class="space"> </span>A<span class="space"> </span>paragraph <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>with<span class="space"> </span>two<span class="space"> </span>lines.</code></pre> <pre class="html"><code><ol> <li>A<span class="space"> </span>paragraph with<span class="space"> </span>two<span class="space"> </span>lines.</li> </ol></code></pre> </div> <p>These examples show how laziness can work in nested structures:</p> <div id="example-186" class="example" data-section="List items"> <div class="examplenum"> <a href="#example-186">Example 186</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>><span class="space"> </span>1.<span class="space"> </span>><span class="space"> </span>Blockquote continued<span class="space"> </span>here.</code></pre> <pre class="html"><code><blockquote> <ol> <li><blockquote> <p>Blockquote continued<span class="space"> </span>here.</p> </blockquote></li> </ol> </blockquote></code></pre> </div> <div id="example-187" class="example" data-section="List items"> <div class="examplenum"> <a href="#example-187">Example 187</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>><span class="space"> </span>1.<span class="space"> </span>><span class="space"> </span>Blockquote ><span class="space"> </span>continued<span class="space"> </span>here.</code></pre> <pre class="html"><code><blockquote> <ol> <li><blockquote> <p>Blockquote continued<span class="space"> </span>here.</p> </blockquote></li> </ol> </blockquote></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-188" class="example" data-section="List items"> <div class="examplenum"> <a href="#example-188">Example 188</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>-<span class="space"> </span>foo <span class="space"> </span><span class="space"> </span>-<span class="space"> </span>bar <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>-<span class="space"> </span>baz</code></pre> <pre class="html"><code><ul> <li>foo <ul> <li>bar <ul> <li>baz</li> </ul></li> </ul></li> </ul></code></pre> </div> <p>One is not enough:</p> <div id="example-189" class="example" data-section="List items"> <div class="examplenum"> <a href="#example-189">Example 189</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>-<span class="space"> </span>foo <span class="space"> </span>-<span class="space"> </span>bar <span class="space"> </span><span class="space"> </span>-<span class="space"> </span>baz</code></pre> <pre class="html"><code><ul> <li>foo</li> <li>bar</li> <li>baz</li> </ul></code></pre> </div> <p>Here we need four, because the list marker is wider:</p> <div id="example-190" class="example" data-section="List items"> <div class="examplenum"> <a href="#example-190">Example 190</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>10)<span class="space"> </span>foo <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>-<span class="space"> </span>bar</code></pre> <pre class="html"><code><ol<span class="space"> </span>start="10"> <li>foo <ul> <li>bar</li> </ul></li> </ol></code></pre> </div> <p>Three is not enough:</p> <div id="example-191" class="example" data-section="List items"> <div class="examplenum"> <a href="#example-191">Example 191</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>10)<span class="space"> </span>foo <span class="space"> </span><span class="space"> </span><span class="space"> </span>-<span class="space"> </span>bar</code></pre> <pre class="html"><code><ol<span class="space"> </span>start="10"> <li>foo</li> </ol> <ul> <li>bar</li> </ul></code></pre> </div> <p>A list may be the first block in a list item:</p> <div id="example-192" class="example" data-section="List items"> <div class="examplenum"> <a href="#example-192">Example 192</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>-<span class="space"> </span>-<span class="space"> </span>foo</code></pre> <pre class="html"><code><ul> <li><ul> <li>foo</li> </ul></li> </ul></code></pre> </div> <div id="example-193" class="example" data-section="List items"> <div class="examplenum"> <a href="#example-193">Example 193</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>1.<span class="space"> </span>-<span class="space"> </span>2.<span class="space"> </span>foo</code></pre> <pre class="html"><code><ol> <li><ul> <li><ol<span class="space"> </span>start="2"> <li>foo</li> </ol></li> </ul></li> </ol></code></pre> </div> <p>A list item may be empty:</p> <div id="example-194" class="example" data-section="List items"> <div class="examplenum"> <a href="#example-194">Example 194</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>-<span class="space"> </span>foo - -<span class="space"> </span>bar</code></pre> <pre class="html"><code><ul> <li>foo</li> <li></li> <li>bar</li> </ul></code></pre> </div> <div id="example-195" class="example" data-section="List items"> <div class="examplenum"> <a href="#example-195">Example 195</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>-</code></pre> <pre class="html"><code><ul> <li></li> </ul></code></pre> </div> <p>A list item can contain a header:</p> <div id="example-196" class="example" data-section="List items"> <div class="examplenum"> <a href="#example-196">Example 196</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>-<span class="space"> </span>#<span class="space"> </span>Foo -<span class="space"> </span>Bar <span class="space"> </span><span class="space"> </span>--- <span class="space"> </span><span class="space"> </span>baz</code></pre> <pre class="html"><code><ul> <li><h1>Foo</h1></li> <li><h2>Bar</h2> <p>baz</p></li> </ul></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>></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><ul> <li>foo</li> </ul> <p>bar</p> <ul> <li>baz</li> </ul></code></pre> <p>as the four-space rule demands, rather than a single list,</p> <pre class="html"><code><ul> <li><p>foo</p> <p>bar</p> <ul> <li>baz</li> </ul></li> </ul></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><ul> <li><p>one</p> <p>two</p></li> </ul></code></pre> <p>and similarly</p> <pre class="markdown"><code>> - one > > two</code></pre> <p>as</p> <pre class="html"><code><blockquote> <ul> <li><p>one</p> <p>two</p></li> </ul> </blockquote></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 id="list" href="#list" class="definition">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 id="of-the-same-type" href="#of-the-same-type" class="definition">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 id="ordered-list" href="#ordered-list" class="definition">ordered list</a> if its constituent list items begin with <a href="#ordered-list-marker">ordered list markers</a>, and a <a id="bullet-list" href="#bullet-list" class="definition">bullet list</a> if its constituent list items begin with <a href="#bullet-list-marker">bullet list markers</a>.</p> <p>The <a id="start-number" href="#start-number" class="definition">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 id="loose" href="#loose" class="definition">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 id="tight" href="#tight" class="definition">tight</a>. (The difference in HTML output is that paragraphs in a loose list are wrapped in <code><p></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-197" class="example" data-section="Lists"> <div class="examplenum"> <a href="#example-197">Example 197</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>-<span class="space"> </span>foo -<span class="space"> </span>bar +<span class="space"> </span>baz</code></pre> <pre class="html"><code><ul> <li>foo</li> <li>bar</li> </ul> <ul> <li>baz</li> </ul></code></pre> </div> <div id="example-198" class="example" data-section="Lists"> <div class="examplenum"> <a href="#example-198">Example 198</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>1.<span class="space"> </span>foo 2.<span class="space"> </span>bar 3)<span class="space"> </span>baz</code></pre> <pre class="html"><code><ol> <li>foo</li> <li>bar</li> </ol> <ol<span class="space"> </span>start="3"> <li>baz</li> </ol></code></pre> </div> <p>In CommonMark, a list can interrupt a paragraph. That is, no blank line is needed to separate a paragraph from a following list:</p> <div id="example-199" class="example" data-section="Lists"> <div class="examplenum"> <a href="#example-199">Example 199</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>Foo -<span class="space"> </span>bar -<span class="space"> </span>baz</code></pre> <pre class="html"><code><p>Foo</p> <ul> <li>bar</li> <li>baz</li> </ul></code></pre> </div> <p><code>Markdown.pl</code> does not allow this, through fear of triggering a list via a numeral in a hard-wrapped line:</p> <div id="example-200" class="example" data-section="Lists"> <div class="examplenum"> <a href="#example-200">Example 200</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>The<span class="space"> </span>number<span class="space"> </span>of<span class="space"> </span>windows<span class="space"> </span>in<span class="space"> </span>my<span class="space"> </span>house<span class="space"> </span>is 14.<span class="space"> </span><span class="space"> </span>The<span class="space"> </span>number<span class="space"> </span>of<span class="space"> </span>doors<span class="space"> </span>is<span class="space"> </span>6.</code></pre> <pre class="html"><code><p>The<span class="space"> </span>number<span class="space"> </span>of<span class="space"> </span>windows<span class="space"> </span>in<span class="space"> </span>my<span class="space"> </span>house<span class="space"> </span>is</p> <ol<span class="space"> </span>start="14"> <li>The<span class="space"> </span>number<span class="space"> </span>of<span class="space"> </span>doors<span class="space"> </span>is<span class="space"> </span>6.</li> </ol></code></pre> </div> <p>Oddly, <code>Markdown.pl</code> <em>does</em> allow a blockquote to interrupt a paragraph, even though the same considerations might apply. We think that the two cases should be treated the same. Here are two reasons for allowing lists to interrupt paragraphs:</p> <p>First, it is natural and not uncommon for people to start lists without blank lines:</p> <pre><code>I need to buy - new shoes - a coat - a plane ticket</code></pre> <p>Second, we are attracted to a</p> <blockquote> <p><a id="principle-of-uniformity" href="#principle-of-uniformity" class="definition">principle of uniformity</a>: if a span of text has a certain meaning, it will continue to have the same meaning when put into a list item.</p> </blockquote> <p>(Indeed, the spec for <a href="#list-item">list items</a> presupposes this.) This principle implies that if</p> <pre><code> * I need to buy - new shoes - a coat - a plane ticket</code></pre> <p>is a list item containing a paragraph followed by a nested sublist, as all Markdown implementations agree it is (though the paragraph may be rendered without <code><p></code> tags, since the list is “tight”), then</p> <pre><code>I need to buy - new shoes - a coat - a plane ticket</code></pre> <p>by itself should be a paragraph followed by a nested sublist.</p> <p>Our adherence to the <a href="#principle-of-uniformity">principle of uniformity</a> thus inclines us to think that there are two coherent packages:</p> <ol style="list-style-type: decimal"> <li><p>Require blank lines before <em>all</em> lists and blockquotes, including lists that occur as sublists inside other list items.</p></li> <li><p>Require blank lines in none of these places.</p></li> </ol> <p><a href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> takes the first approach, for which there is much to be said. But the second seems more consistent with established practice with Markdown.</p> <p>There can be blank lines between items, but two blank lines end a list:</p> <div id="example-201" class="example" data-section="Lists"> <div class="examplenum"> <a href="#example-201">Example 201</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>-<span class="space"> </span>foo -<span class="space"> </span>bar -<span class="space"> </span>baz</code></pre> <pre class="html"><code><ul> <li><p>foo</p></li> <li><p>bar</p></li> </ul> <ul> <li>baz</li> </ul></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-202" class="example" data-section="Lists"> <div class="examplenum"> <a href="#example-202">Example 202</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>-<span class="space"> </span>foo <span class="space"> </span><span class="space"> </span>bar -<span class="space"> </span>baz</code></pre> <pre class="html"><code><ul> <li>foo</li> </ul> <p>bar</p> <ul> <li>baz</li> </ul></code></pre> </div> <p>Indeed, two blank lines will end <em>all</em> containing lists:</p> <div id="example-203" class="example" data-section="Lists"> <div class="examplenum"> <a href="#example-203">Example 203</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>-<span class="space"> </span>foo <span class="space"> </span><span class="space"> </span>-<span class="space"> </span>bar <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>-<span class="space"> </span>baz <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>bim</code></pre> <pre class="html"><code><ul> <li>foo <ul> <li>bar <ul> <li>baz</li> </ul></li> </ul></li> </ul> <pre><code><span class="space"> </span><span class="space"> </span>bim </code></pre></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-204" class="example" data-section="Lists"> <div class="examplenum"> <a href="#example-204">Example 204</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>-<span class="space"> </span>foo -<span class="space"> </span>bar -<span class="space"> </span>baz -<span class="space"> </span>bim</code></pre> <pre class="html"><code><ul> <li>foo</li> <li>bar</li> </ul> <ul> <li>baz</li> <li>bim</li> </ul></code></pre> </div> <div id="example-205" class="example" data-section="Lists"> <div class="examplenum"> <a href="#example-205">Example 205</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>-<span class="space"> </span><span class="space"> </span><span class="space"> </span>foo <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>notcode -<span class="space"> </span><span class="space"> </span><span class="space"> </span>foo <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>code</code></pre> <pre class="html"><code><ul> <li><p>foo</p> <p>notcode</p></li> <li><p>foo</p></li> </ul> <pre><code>code </code></pre></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-206" class="example" data-section="Lists"> <div class="examplenum"> <a href="#example-206">Example 206</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>-<span class="space"> </span>a <span class="space"> </span>-<span class="space"> </span>b <span class="space"> </span><span class="space"> </span>-<span class="space"> </span>c <span class="space"> </span><span class="space"> </span><span class="space"> </span>-<span class="space"> </span>d <span class="space"> </span><span class="space"> </span>-<span class="space"> </span>e <span class="space"> </span>-<span class="space"> </span>f -<span class="space"> </span>g</code></pre> <pre class="html"><code><ul> <li>a</li> <li>b</li> <li>c</li> <li>d</li> <li>e</li> <li>f</li> <li>g</li> </ul></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-207" class="example" data-section="Lists"> <div class="examplenum"> <a href="#example-207">Example 207</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>-<span class="space"> </span>a -<span class="space"> </span>b -<span class="space"> </span>c</code></pre> <pre class="html"><code><ul> <li><p>a</p></li> <li><p>b</p></li> <li><p>c</p></li> </ul></code></pre> </div> <p>So is this, with a empty second item:</p> <div id="example-208" class="example" data-section="Lists"> <div class="examplenum"> <a href="#example-208">Example 208</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>*<span class="space"> </span>a * *<span class="space"> </span>c</code></pre> <pre class="html"><code><ul> <li><p>a</p></li> <li></li> <li><p>c</p></li> </ul></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-209" class="example" data-section="Lists"> <div class="examplenum"> <a href="#example-209">Example 209</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>-<span class="space"> </span>a -<span class="space"> </span>b <span class="space"> </span><span class="space"> </span>c -<span class="space"> </span>d</code></pre> <pre class="html"><code><ul> <li><p>a</p></li> <li><p>b</p> <p>c</p></li> <li><p>d</p></li> </ul></code></pre> </div> <div id="example-210" class="example" data-section="Lists"> <div class="examplenum"> <a href="#example-210">Example 210</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>-<span class="space"> </span>a -<span class="space"> </span>b <span class="space"> </span><span class="space"> </span>[ref]:<span class="space"> </span>/url -<span class="space"> </span>d</code></pre> <pre class="html"><code><ul> <li><p>a</p></li> <li><p>b</p></li> <li><p>d</p></li> </ul></code></pre> </div> <p>This is a tight list, because the blank lines are in a code block:</p> <div id="example-211" class="example" data-section="Lists"> <div class="examplenum"> <a href="#example-211">Example 211</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>-<span class="space"> </span>a -<span class="space"> </span>``` <span class="space"> </span><span class="space"> </span>b <span class="space"> </span><span class="space"> </span>``` -<span class="space"> </span>c</code></pre> <pre class="html"><code><ul> <li>a</li> <li><pre><code>b </code></pre></li> <li>c</li> </ul></code></pre> </div> <p>This is a tight list, because the blank line is between two paragraphs of a sublist. So the sublist is loose while the outer list is tight:</p> <div id="example-212" class="example" data-section="Lists"> <div class="examplenum"> <a href="#example-212">Example 212</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>-<span class="space"> </span>a <span class="space"> </span><span class="space"> </span>-<span class="space"> </span>b <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>c -<span class="space"> </span>d</code></pre> <pre class="html"><code><ul> <li>a <ul> <li><p>b</p> <p>c</p></li> </ul></li> <li>d</li> </ul></code></pre> </div> <p>This is a tight list, because the blank line is inside the block quote:</p> <div id="example-213" class="example" data-section="Lists"> <div class="examplenum"> <a href="#example-213">Example 213</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>*<span class="space"> </span>a <span class="space"> </span><span class="space"> </span>><span class="space"> </span>b <span class="space"> </span><span class="space"> </span>> *<span class="space"> </span>c</code></pre> <pre class="html"><code><ul> <li>a <blockquote> <p>b</p> </blockquote></li> <li>c</li> </ul></code></pre> </div> <p>This list is tight, because the consecutive block elements are not separated by blank lines:</p> <div id="example-214" class="example" data-section="Lists"> <div class="examplenum"> <a href="#example-214">Example 214</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>-<span class="space"> </span>a <span class="space"> </span><span class="space"> </span>><span class="space"> </span>b <span class="space"> </span><span class="space"> </span>``` <span class="space"> </span><span class="space"> </span>c <span class="space"> </span><span class="space"> </span>``` -<span class="space"> </span>d</code></pre> <pre class="html"><code><ul> <li>a <blockquote> <p>b</p> </blockquote> <pre><code>c </code></pre></li> <li>d</li> </ul></code></pre> </div> <p>A single-paragraph list is tight:</p> <div id="example-215" class="example" data-section="Lists"> <div class="examplenum"> <a href="#example-215">Example 215</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>-<span class="space"> </span>a</code></pre> <pre class="html"><code><ul> <li>a</li> </ul></code></pre> </div> <div id="example-216" class="example" data-section="Lists"> <div class="examplenum"> <a href="#example-216">Example 216</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>-<span class="space"> </span>a <span class="space"> </span><span class="space"> </span>-<span class="space"> </span>b</code></pre> <pre class="html"><code><ul> <li>a <ul> <li>b</li> </ul></li> </ul></code></pre> </div> <p>Here the outer list is loose, the inner list tight:</p> <div id="example-217" class="example" data-section="Lists"> <div class="examplenum"> <a href="#example-217">Example 217</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>*<span class="space"> </span>foo <span class="space"> </span><span class="space"> </span>*<span class="space"> </span>bar <span class="space"> </span><span class="space"> </span>baz</code></pre> <pre class="html"><code><ul> <li><p>foo</p> <ul> <li>bar</li> </ul> <p>baz</p></li> </ul></code></pre> </div> <div id="example-218" class="example" data-section="Lists"> <div class="examplenum"> <a href="#example-218">Example 218</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>-<span class="space"> </span>a <span class="space"> </span><span class="space"> </span>-<span class="space"> </span>b <span class="space"> </span><span class="space"> </span>-<span class="space"> </span>c -<span class="space"> </span>d <span class="space"> </span><span class="space"> </span>-<span class="space"> </span>e <span class="space"> </span><span class="space"> </span>-<span class="space"> </span>f</code></pre> <pre class="html"><code><ul> <li><p>a</p> <ul> <li>b</li> <li>c</li> </ul></li> <li><p>d</p> <ul> <li>e</li> <li>f</li> </ul></li> </ul></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-219" class="example" data-section="Inlines"> <div class="examplenum"> <a href="#example-219">Example 219</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>`hi`lo`</code></pre> <pre class="html"><code><p><code>hi</code>lo`</p></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-220" class="example" data-section="Backslash escapes"> <div class="examplenum"> <a href="#example-220">Example 220</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>\!\"\#\$\%\&\'\(\)\*\+\,\-\.\/\:\;\<\=\>\?\@\[\\\]\^\_\`\{\|\}\~</code></pre> <pre class="html"><code><p>!&quot;#$%&amp;'()*+,-./:;&lt;=&gt;?@[\]^_`{|}~</p></code></pre> </div> <p>Backslashes before other characters are treated as literal backslashes:</p> <div id="example-221" class="example" data-section="Backslash escapes"> <div class="examplenum"> <a href="#example-221">Example 221</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>\→\A\a\<span class="space"> </span>\3\φ\«</code></pre> <pre class="html"><code><p>\<span class="space"> </span><span class="space"> </span><span class="space"> </span>\A\a\<span class="space"> </span>\3\φ\«</p></code></pre> </div> <p>Escaped characters are treated as regular characters and do not have their usual Markdown meanings:</p> <div id="example-222" class="example" data-section="Backslash escapes"> <div class="examplenum"> <a href="#example-222">Example 222</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>\*not<span class="space"> </span>emphasized* \<br/><span class="space"> </span>not<span class="space"> </span>a<span class="space"> </span>tag \[not<span class="space"> </span>a<span class="space"> </span>link](/foo) \`not<span class="space"> </span>code` 1\.<span class="space"> </span>not<span class="space"> </span>a<span class="space"> </span>list \*<span class="space"> </span>not<span class="space"> </span>a<span class="space"> </span>list \#<span class="space"> </span>not<span class="space"> </span>a<span class="space"> </span>header \[foo]:<span class="space"> </span>/url<span class="space"> </span>"not<span class="space"> </span>a<span class="space"> </span>reference"</code></pre> <pre class="html"><code><p>*not<span class="space"> </span>emphasized* &lt;br/&gt;<span class="space"> </span>not<span class="space"> </span>a<span class="space"> </span>tag [not<span class="space"> </span>a<span class="space"> </span>link](/foo) `not<span class="space"> </span>code` 1.<span class="space"> </span>not<span class="space"> </span>a<span class="space"> </span>list *<span class="space"> </span>not<span class="space"> </span>a<span class="space"> </span>list #<span class="space"> </span>not<span class="space"> </span>a<span class="space"> </span>header [foo]:<span class="space"> </span>/url<span class="space"> </span>&quot;not<span class="space"> </span>a<span class="space"> </span>reference&quot;</p></code></pre> </div> <p>If a backslash is itself escaped, the following character is not:</p> <div id="example-223" class="example" data-section="Backslash escapes"> <div class="examplenum"> <a href="#example-223">Example 223</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>\\*emphasis*</code></pre> <pre class="html"><code><p>\<em>emphasis</em></p></code></pre> </div> <p>A backslash at the end of the line is a <a href="#hard-line-break">hard line break</a>:</p> <div id="example-224" class="example" data-section="Backslash escapes"> <div class="examplenum"> <a href="#example-224">Example 224</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>foo\ bar</code></pre> <pre class="html"><code><p>foo<br<span class="space"> </span>/> bar</p></code></pre> </div> <p>Backslash escapes do not work in code blocks, code spans, autolinks, or raw HTML:</p> <div id="example-225" class="example" data-section="Backslash escapes"> <div class="examplenum"> <a href="#example-225">Example 225</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>``<span class="space"> </span>\[\`<span class="space"> </span>``</code></pre> <pre class="html"><code><p><code>\[\`</code></p></code></pre> </div> <div id="example-226" class="example" data-section="Backslash escapes"> <div class="examplenum"> <a href="#example-226">Example 226</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>\[\]</code></pre> <pre class="html"><code><pre><code>\[\] </code></pre></code></pre> </div> <div id="example-227" class="example" data-section="Backslash escapes"> <div class="examplenum"> <a href="#example-227">Example 227</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>~~~ \[\] ~~~</code></pre> <pre class="html"><code><pre><code>\[\] </code></pre></code></pre> </div> <div id="example-228" class="example" data-section="Backslash escapes"> <div class="examplenum"> <a href="#example-228">Example 228</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><http://example.com?find=\*></code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="http://example.com?find=%5C*">http://example.com?find=\*</a></p></code></pre> </div> <div id="example-229" class="example" data-section="Backslash escapes"> <div class="examplenum"> <a href="#example-229">Example 229</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><a<span class="space"> </span>href="/bar\/)"></code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/bar\/)"></p></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-230" class="example" data-section="Backslash escapes"> <div class="examplenum"> <a href="#example-230">Example 230</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[foo](/bar\*<span class="space"> </span>"ti\*tle")</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/bar*"<span class="space"> </span>title="ti*tle">foo</a></p></code></pre> </div> <div id="example-231" class="example" data-section="Backslash escapes"> <div class="examplenum"> <a href="#example-231">Example 231</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[foo] [foo]:<span class="space"> </span>/bar\*<span class="space"> </span>"ti\*tle"</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/bar*"<span class="space"> </span>title="ti*tle">foo</a></p></code></pre> </div> <div id="example-232" class="example" data-section="Backslash escapes"> <div class="examplenum"> <a href="#example-232">Example 232</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>```<span class="space"> </span>foo\+bar foo ```</code></pre> <pre class="html"><code><pre><code<span class="space"> </span>class="language-foo+bar">foo </code></pre></code></pre> </div> <h2 id="entities"><span class="header-section-number">6.2</span> Entities</h2> <p>With the goal of making this standard as HTML-agnostic as possible, all valid HTML entities in any context are recognized as such and converted into unicode characters before they are stored in the AST.</p> <p>This allows implementations that target HTML output to trivially escape the entities when generating HTML, and simplifies the job of implementations targetting other languages, as these will only need to handle the unicode chars and need not be HTML-entity aware.</p> <p><a id="name-entities" href="#name-entities" class="definition">Named entities</a> consist of <code>&</code> + any of the valid HTML5 entity names + <code>;</code>. The <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/entities.json">following document</a> is used as an authoritative source of the valid entity names and their corresponding codepoints.</p> <p>Conforming implementations that target HTML don’t need to generate entities for all the valid named entities that exist, with the exception of <code>"</code> (<code>&quot;</code>), <code>&</code> (<code>&amp;</code>), <code><</code> (<code>&lt;</code>) and <code>></code> (<code>&gt;</code>), which always need to be written as entities for security reasons.</p> <div id="example-233" class="example" data-section="Entities"> <div class="examplenum"> <a href="#example-233">Example 233</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>&nbsp;<span class="space"> </span>&amp;<span class="space"> </span>&copy;<span class="space"> </span>&AElig;<span class="space"> </span>&Dcaron;<span class="space"> </span>&frac34;<span class="space"> </span>&HilbertSpace;<span class="space"> </span>&DifferentialD;<span class="space"> </span>&ClockwiseContourIntegral;</code></pre> <pre class="html"><code><p> <span class="space"> </span>&amp;<span class="space"> </span>©<span class="space"> </span>Æ<span class="space"> </span>Ď<span class="space"> </span>¾<span class="space"> </span>ℋ<span class="space"> </span>ⅆ<span class="space"> </span>∲</p></code></pre> </div> <p><a id="decimal-entities" href="#decimal-entities" class="definition">Decimal entities</a> consist of <code>&#</code> + a string of 1–8 arabic digits + <code>;</code>. Again, these entities need to be recognised and tranformed into their corresponding UTF8 codepoints. Invalid Unicode codepoints will be written as the “unknown codepoint” character (<code>0xFFFD</code>)</p> <div id="example-234" class="example" data-section="Entities"> <div class="examplenum"> <a href="#example-234">Example 234</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>&#35;<span class="space"> </span>&#1234;<span class="space"> </span>&#992;<span class="space"> </span>&#98765432;</code></pre> <pre class="html"><code><p>#<span class="space"> </span>Ӓ<span class="space"> </span>Ϡ<span class="space"> </span>�</p></code></pre> </div> <p><a id="hexadecimal-entities" href="#hexadecimal-entities" class="definition">Hexadecimal entities</a> consist of <code>&#</code> + either <code>X</code> or <code>x</code> + a string of 1-8 hexadecimal digits + <code>;</code>. They will also be parsed and turned into their corresponding UTF8 values in the AST.</p> <div id="example-235" class="example" data-section="Entities"> <div class="examplenum"> <a href="#example-235">Example 235</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>&#X22;<span class="space"> </span>&#XD06;<span class="space"> </span>&#xcab;</code></pre> <pre class="html"><code><p>&quot;<span class="space"> </span>ആ<span class="space"> </span>ಫ</p></code></pre> </div> <p>Here are some nonentities:</p> <div id="example-236" class="example" data-section="Entities"> <div class="examplenum"> <a href="#example-236">Example 236</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>&nbsp<span class="space"> </span>&x;<span class="space"> </span>&#;<span class="space"> </span>&#x;<span class="space"> </span>&ThisIsWayTooLongToBeAnEntityIsntIt;<span class="space"> </span>&hi?;</code></pre> <pre class="html"><code><p>&amp;nbsp<span class="space"> </span>&amp;x;<span class="space"> </span>&amp;#;<span class="space"> </span>&amp;#x;<span class="space"> </span>&amp;ThisIsWayTooLongToBeAnEntityIsntIt;<span class="space"> </span>&amp;hi?;</p></code></pre> </div> <p>Although HTML5 does accept some entities without a trailing semicolon (such as <code>&copy</code>), these are not recognized as entities here, because it makes the grammar too ambiguous:</p> <div id="example-237" class="example" data-section="Entities"> <div class="examplenum"> <a href="#example-237">Example 237</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>&copy</code></pre> <pre class="html"><code><p>&amp;copy</p></code></pre> </div> <p>Strings that are not on the list of HTML5 named entities are not recognized as entities either:</p> <div id="example-238" class="example" data-section="Entities"> <div class="examplenum"> <a href="#example-238">Example 238</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>&MadeUpEntity;</code></pre> <pre class="html"><code><p>&amp;MadeUpEntity;</p></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-239" class="example" data-section="Entities"> <div class="examplenum"> <a href="#example-239">Example 239</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><a<span class="space"> </span>href="&ouml;&ouml;.html"></code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="&ouml;&ouml;.html"></p></code></pre> </div> <div id="example-240" class="example" data-section="Entities"> <div class="examplenum"> <a href="#example-240">Example 240</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[foo](/f&ouml;&ouml;<span class="space"> </span>"f&ouml;&ouml;")</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/f%C3%B6%C3%B6"<span class="space"> </span>title="föö">foo</a></p></code></pre> </div> <div id="example-241" class="example" data-section="Entities"> <div class="examplenum"> <a href="#example-241">Example 241</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[foo] [foo]:<span class="space"> </span>/f&ouml;&ouml;<span class="space"> </span>"f&ouml;&ouml;"</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/f%C3%B6%C3%B6"<span class="space"> </span>title="föö">foo</a></p></code></pre> </div> <div id="example-242" class="example" data-section="Entities"> <div class="examplenum"> <a href="#example-242">Example 242</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>```<span class="space"> </span>f&ouml;&ouml; foo ```</code></pre> <pre class="html"><code><pre><code<span class="space"> </span>class="language-föö">foo </code></pre></code></pre> </div> <p>Entities are treated as literal text in code spans and code blocks:</p> <div id="example-243" class="example" data-section="Entities"> <div class="examplenum"> <a href="#example-243">Example 243</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>`f&ouml;&ouml;`</code></pre> <pre class="html"><code><p><code>f&amp;ouml;&amp;ouml;</code></p></code></pre> </div> <div id="example-244" class="example" data-section="Entities"> <div class="examplenum"> <a href="#example-244">Example 244</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>f&ouml;f&ouml;</code></pre> <pre class="html"><code><pre><code>f&amp;ouml;f&amp;ouml; </code></pre></code></pre> </div> <h2 id="code-span"><span class="header-section-number">6.3</span> Code span</h2> <p>A <a id="backtick-string" href="#backtick-string" class="definition">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 <a id="code-span" href="#code-span" class="definition">code span</a> 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-245" class="example" data-section="Code span"> <div class="examplenum"> <a href="#example-245">Example 245</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>`foo`</code></pre> <pre class="html"><code><p><code>foo</code></p></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-246" class="example" data-section="Code span"> <div class="examplenum"> <a href="#example-246">Example 246</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>``<span class="space"> </span>foo<span class="space"> </span>`<span class="space"> </span>bar<span class="space"> </span><span class="space"> </span>``</code></pre> <pre class="html"><code><p><code>foo<span class="space"> </span>`<span class="space"> </span>bar</code></p></code></pre> </div> <p>This example shows the motivation for stripping leading and trailing spaces:</p> <div id="example-247" class="example" data-section="Code span"> <div class="examplenum"> <a href="#example-247">Example 247</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>`<span class="space"> </span>``<span class="space"> </span>`</code></pre> <pre class="html"><code><p><code>``</code></p></code></pre> </div> <p>Newlines are treated like spaces:</p> <div id="example-248" class="example" data-section="Code span"> <div class="examplenum"> <a href="#example-248">Example 248</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>`` foo ``</code></pre> <pre class="html"><code><p><code>foo</code></p></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-249" class="example" data-section="Code span"> <div class="examplenum"> <a href="#example-249">Example 249</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>`foo<span class="space"> </span><span class="space"> </span><span class="space"> </span>bar <span class="space"> </span><span class="space"> </span>baz`</code></pre> <pre class="html"><code><p><code>foo<span class="space"> </span>bar<span class="space"> </span>baz</code></p></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><br /></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-250" class="example" data-section="Code span"> <div class="examplenum"> <a href="#example-250">Example 250</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>`foo<span class="space"> </span>``<span class="space"> </span>bar`</code></pre> <pre class="html"><code><p><code>foo<span class="space"> </span>``<span class="space"> </span>bar</code></p></code></pre> </div> <p>Note that backslash escapes do not work in code spans. All backslashes are treated literally:</p> <div id="example-251" class="example" data-section="Code span"> <div class="examplenum"> <a href="#example-251">Example 251</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>`foo\`bar`</code></pre> <pre class="html"><code><p><code>foo\</code>bar`</p></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-252" class="example" data-section="Code span"> <div class="examplenum"> <a href="#example-252">Example 252</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>*foo`*`</code></pre> <pre class="html"><code><p>*foo<code>*</code></p></code></pre> </div> <p>And this is not parsed as a link:</p> <div id="example-253" class="example" data-section="Code span"> <div class="examplenum"> <a href="#example-253">Example 253</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[not<span class="space"> </span>a<span class="space"> </span>`link](/foo`)</code></pre> <pre class="html"><code><p>[not<span class="space"> </span>a<span class="space"> </span><code>link](/foo</code>)</p></code></pre> </div> <p>But this is a link:</p> <div id="example-254" class="example" data-section="Code span"> <div class="examplenum"> <a href="#example-254">Example 254</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><http://foo.bar.`baz>`</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="http://foo.bar.%60baz">http://foo.bar.`baz</a>`</p></code></pre> </div> <p>And this is an HTML tag:</p> <div id="example-255" class="example" data-section="Code span"> <div class="examplenum"> <a href="#example-255">Example 255</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><a<span class="space"> </span>href="`">`</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="`">`</p></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-256" class="example" data-section="Code span"> <div class="examplenum"> <a href="#example-256">Example 256</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>```foo``</code></pre> <pre class="html"><code><p>```foo``</p></code></pre> </div> <div id="example-257" class="example" data-section="Code span"> <div class="examplenum"> <a href="#example-257">Example 257</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>`foo</code></pre> <pre class="html"><code><p>`foo</p></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><em></code> tag; double <code>*</code>’s or <code>_</code>’s will be wrapped with an HTML <code><strong></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 id="can-open-emphasis" href="#can-open-emphasis" class="definition">can open emphasis</a> iff it is not followed by whitespace.</p></li> <li><p>A single <code>_</code> character <a href="#can-open-emphasis">can open emphasis</a> iff it is not followed by whitespace and it is not preceded by an ASCII alphanumeric character.</p></li> <li><p>A single <code>*</code> character <a id="can-close-emphasis" href="#can-close-emphasis" class="definition">can close emphasis</a> iff it is not preceded by whitespace.</p></li> <li><p>A single <code>_</code> character <a href="#can-close-emphasis">can close emphasis</a> iff it is not preceded by whitespace and it is not followed by an ASCII alphanumeric character.</p></li> <li><p>A double <code>**</code> <a id="can-open-strong-emphasis" href="#can-open-strong-emphasis" class="definition">can open strong emphasis</a> iff it is not followed by whitespace.</p></li> <li><p>A double <code>__</code> <a href="#can-open-strong-emphasis">can open strong emphasis</a> iff it is not followed by whitespace and it is not preceded by an ASCII alphanumeric character.</p></li> <li><p>A double <code>**</code> <a id="can-close-strong-emphasis" href="#can-close-strong-emphasis" class="definition">can close strong emphasis</a> iff it is not preceded by whitespace.</p></li> <li><p>A double <code>__</code> <a href="#can-close-strong-emphasis">can close strong emphasis</a> iff it is not preceded by whitespace and it is not followed by an ASCII alphanumeric character.</p></li> <li><p>Emphasis begins with a delimiter that <a href="#can-open-emphasis">can open emphasis</a> and ends with 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. There must be a nonempty sequence of inlines between the open delimiter and the closing delimiter; these form the contents of the emphasis inline.</p></li> <li><p>Strong emphasis begins with a delimiter that <a href="#can-open-strong-emphasis">can open strong emphasis</a> and ends with 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. There must be a nonempty sequence of inlines between the open delimiter and the closing delimiter; these form the contents of the strong emphasis inline.</p></li> <li><p>A literal <code>*</code> character cannot occur at the beginning or end of <code>*</code>-delimited emphasis or <code>**</code>-delimited strong emphasis, unless it is backslash-escaped.</p></li> <li><p>A literal <code>_</code> character cannot occur at the beginning or end of <code>_</code>-delimited emphasis or <code>__</code>-delimited strong emphasis, unless it is backslash-escaped.</p></li> </ol> <p>Where rules 1–12 above are compatible with multiple parsings, the following principles resolve ambiguity:</p> <ol start="13" style="list-style-type: decimal"> <li><p>The number of nestings should be minimized. Thus, for example, an interpretation <code><strong>...</strong></code> is always preferred to <code><em><em>...</em></em></code>.</p></li> <li><p>An interpretation <code><strong><em>...</em></strong></code> is always preferred to <code><em><strong>..</strong></em></code>.</p></li> <li><p>When two potential emphasis or strong emphasis spans overlap, so that the second begins before the first ends and ends after the first ends, the first is preferred. Thus, for example, <code>*foo _bar* baz_</code> is parsed as <code><em>foo _bar</em> baz_</code> rather than <code>*foo <em>bar* baz</em></code>. For the same reason, <code>**foo*bar**</code> is parsed as <code><em><em>foo</em>bar</em>*</code> rather than <code><strong>foo*bar</strong></code>.</p></li> <li><p>When there are two potential emphasis or strong emphasis spans with the same closing delimiter, the shorter one (the one that opens later) is preferred. Thus, for example, <code>**foo **bar baz**</code> is parsed as <code>**foo <strong>bar baz</strong></code> rather than <code><strong>foo **bar baz</strong></code>.</p></li> <li><p>Inline code spans, links, images, and HTML tags group more tightly than emphasis. So, when there is a choice between an interpretation that contains one of these elements and one that does not, the former always wins. Thus, for example, <code>*[foo*](bar)</code> is parsed as <code>*<a href="bar">foo*</a></code> rather than as <code><em>[foo</em>](bar)</code>.</p></li> </ol> <p>These rules can be illustrated through a series of examples.</p> <p>Rule 1:</p> <div id="example-258" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-258">Example 258</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>*foo<span class="space"> </span>bar*</code></pre> <pre class="html"><code><p><em>foo<span class="space"> </span>bar</em></p></code></pre> </div> <p>This is not emphasis, because the opening <code>*</code> is followed by whitespace:</p> <div id="example-259" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-259">Example 259</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>a<span class="space"> </span>*<span class="space"> </span>foo<span class="space"> </span>bar*</code></pre> <pre class="html"><code><p>a<span class="space"> </span>*<span class="space"> </span>foo<span class="space"> </span>bar*</p></code></pre> </div> <p>Intraword emphasis with <code>*</code> is permitted:</p> <div id="example-260" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-260">Example 260</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>foo*bar*</code></pre> <pre class="html"><code><p>foo<em>bar</em></p></code></pre> </div> <div id="example-261" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-261">Example 261</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>5*6*78</code></pre> <pre class="html"><code><p>5<em>6</em>78</p></code></pre> </div> <p>Rule 2:</p> <div id="example-262" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-262">Example 262</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>_foo<span class="space"> </span>bar_</code></pre> <pre class="html"><code><p><em>foo<span class="space"> </span>bar</em></p></code></pre> </div> <p>This is not emphasis, because the opening <code>*</code> is followed by whitespace:</p> <div id="example-263" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-263">Example 263</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>_<span class="space"> </span>foo<span class="space"> </span>bar_</code></pre> <pre class="html"><code><p>_<span class="space"> </span>foo<span class="space"> </span>bar_</p></code></pre> </div> <p>Emphasis with <code>_</code> is not allowed inside ASCII words:</p> <div id="example-264" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-264">Example 264</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>foo_bar_</code></pre> <pre class="html"><code><p>foo_bar_</p></code></pre> </div> <div id="example-265" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-265">Example 265</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>5_6_78</code></pre> <pre class="html"><code><p>5_6_78</p></code></pre> </div> <p>But it is permitted inside non-ASCII words:</p> <div id="example-266" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-266">Example 266</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>пристаням_стремятся_</code></pre> <pre class="html"><code><p>пристаням<em>стремятся</em></p></code></pre> </div> <p>Rule 3:</p> <p>This is not emphasis, because the closing <code>*</code> is preceded by whitespace:</p> <div id="example-267" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-267">Example 267</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>*foo<span class="space"> </span>bar<span class="space"> </span>*</code></pre> <pre class="html"><code><p>*foo<span class="space"> </span>bar<span class="space"> </span>*</p></code></pre> </div> <p>Intraword emphasis with <code>*</code> is allowed:</p> <div id="example-268" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-268">Example 268</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>*foo*bar</code></pre> <pre class="html"><code><p><em>foo</em>bar</p></code></pre> </div> <p>Rule 4:</p> <p>This is not emphasis, because the closing <code>_</code> is preceded by whitespace:</p> <div id="example-269" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-269">Example 269</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>_foo<span class="space"> </span>bar<span class="space"> </span>_</code></pre> <pre class="html"><code><p>_foo<span class="space"> </span>bar<span class="space"> </span>_</p></code></pre> </div> <p>Intraword emphasis:</p> <div id="example-270" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-270">Example 270</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>_foo_bar</code></pre> <pre class="html"><code><p>_foo_bar</p></code></pre> </div> <div id="example-271" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-271">Example 271</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>_пристаням_стремятся</code></pre> <pre class="html"><code><p><em>пристаням</em>стремятся</p></code></pre> </div> <div id="example-272" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-272">Example 272</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>_foo_bar_baz_</code></pre> <pre class="html"><code><p><em>foo_bar_baz</em></p></code></pre> </div> <p>Rule 5:</p> <div id="example-273" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-273">Example 273</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>**foo<span class="space"> </span>bar**</code></pre> <pre class="html"><code><p><strong>foo<span class="space"> </span>bar</strong></p></code></pre> </div> <p>This is not strong emphasis, because the opening delimiter is followed by whitespace:</p> <div id="example-274" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-274">Example 274</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>**<span class="space"> </span>foo<span class="space"> </span>bar**</code></pre> <pre class="html"><code><p>**<span class="space"> </span>foo<span class="space"> </span>bar**</p></code></pre> </div> <p>Intraword strong emphasis with <code>**</code> is permitted:</p> <div id="example-275" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-275">Example 275</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>foo**bar**</code></pre> <pre class="html"><code><p>foo<strong>bar</strong></p></code></pre> </div> <p>Rule 6:</p> <div id="example-276" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-276">Example 276</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>__foo<span class="space"> </span>bar__</code></pre> <pre class="html"><code><p><strong>foo<span class="space"> </span>bar</strong></p></code></pre> </div> <p>This is not strong emphasis, because the opening delimiter is followed by whitespace:</p> <div id="example-277" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-277">Example 277</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>__<span class="space"> </span>foo<span class="space"> </span>bar__</code></pre> <pre class="html"><code><p>__<span class="space"> </span>foo<span class="space"> </span>bar__</p></code></pre> </div> <p>Intraword emphasis examples:</p> <div id="example-278" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-278">Example 278</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>foo__bar__</code></pre> <pre class="html"><code><p>foo__bar__</p></code></pre> </div> <div id="example-279" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-279">Example 279</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>5__6__78</code></pre> <pre class="html"><code><p>5__6__78</p></code></pre> </div> <div id="example-280" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-280">Example 280</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>пристаням__стремятся__</code></pre> <pre class="html"><code><p>пристаням<strong>стремятся</strong></p></code></pre> </div> <div id="example-281" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-281">Example 281</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>__foo,<span class="space"> </span>__bar__,<span class="space"> </span>baz__</code></pre> <pre class="html"><code><p><strong>foo,<span class="space"> </span><strong>bar</strong>,<span class="space"> </span>baz</strong></p></code></pre> </div> <p>Rule 7:</p> <p>This is not strong emphasis, because the closing delimiter is preceded by whitespace:</p> <div id="example-282" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-282">Example 282</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>**foo<span class="space"> </span>bar<span class="space"> </span>**</code></pre> <pre class="html"><code><p>**foo<span class="space"> </span>bar<span class="space"> </span>**</p></code></pre> </div> <p>(Nor can it be interpreted as an emphasized <code>*foo bar *</code>, because of Rule 11.)</p> <p>Intraword emphasis:</p> <div id="example-283" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-283">Example 283</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>**foo**bar</code></pre> <pre class="html"><code><p><strong>foo</strong>bar</p></code></pre> </div> <p>Rule 8:</p> <p>This is not strong emphasis, because the closing delimiter is preceded by whitespace:</p> <div id="example-284" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-284">Example 284</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>__foo<span class="space"> </span>bar<span class="space"> </span>__</code></pre> <pre class="html"><code><p>__foo<span class="space"> </span>bar<span class="space"> </span>__</p></code></pre> </div> <p>Intraword strong emphasis examples:</p> <div id="example-285" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-285">Example 285</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>__foo__bar</code></pre> <pre class="html"><code><p>__foo__bar</p></code></pre> </div> <div id="example-286" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-286">Example 286</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>__пристаням__стремятся</code></pre> <pre class="html"><code><p><strong>пристаням</strong>стремятся</p></code></pre> </div> <div id="example-287" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-287">Example 287</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>__foo__bar__baz__</code></pre> <pre class="html"><code><p><strong>foo__bar__baz</strong></p></code></pre> </div> <p>Rule 9:</p> <p>Any nonempty sequence of inline elements can be the contents of an emphasized span.</p> <div id="example-288" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-288">Example 288</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>*foo<span class="space"> </span>[bar](/url)*</code></pre> <pre class="html"><code><p><em>foo<span class="space"> </span><a<span class="space"> </span>href="/url">bar</a></em></p></code></pre> </div> <div id="example-289" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-289">Example 289</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>*foo bar*</code></pre> <pre class="html"><code><p><em>foo bar</em></p></code></pre> </div> <p>In particular, emphasis and strong emphasis can be nested inside emphasis:</p> <div id="example-290" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-290">Example 290</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>_foo<span class="space"> </span>__bar__<span class="space"> </span>baz_</code></pre> <pre class="html"><code><p><em>foo<span class="space"> </span><strong>bar</strong><span class="space"> </span>baz</em></p></code></pre> </div> <div id="example-291" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-291">Example 291</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>_foo<span class="space"> </span>_bar_<span class="space"> </span>baz_</code></pre> <pre class="html"><code><p><em>foo<span class="space"> </span><em>bar</em><span class="space"> </span>baz</em></p></code></pre> </div> <div id="example-292" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-292">Example 292</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>__foo_<span class="space"> </span>bar_</code></pre> <pre class="html"><code><p><em><em>foo</em><span class="space"> </span>bar</em></p></code></pre> </div> <div id="example-293" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-293">Example 293</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>*foo<span class="space"> </span>*bar**</code></pre> <pre class="html"><code><p><em>foo<span class="space"> </span><em>bar</em></em></p></code></pre> </div> <div id="example-294" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-294">Example 294</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>*foo<span class="space"> </span>**bar**<span class="space"> </span>baz*</code></pre> <pre class="html"><code><p><em>foo<span class="space"> </span><strong>bar</strong><span class="space"> </span>baz</em></p></code></pre> </div> <p>But note:</p> <div id="example-295" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-295">Example 295</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>*foo**bar**baz*</code></pre> <pre class="html"><code><p><em>foo</em><em>bar</em><em>baz</em></p></code></pre> </div> <p>The difference is that in the preceding case, the internal delimiters <a href="#can-close-emphasis">can close emphasis</a>, while in the cases with spaces, they cannot.</p> <div id="example-296" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-296">Example 296</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>***foo**<span class="space"> </span>bar*</code></pre> <pre class="html"><code><p><em><strong>foo</strong><span class="space"> </span>bar</em></p></code></pre> </div> <div id="example-297" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-297">Example 297</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>*foo<span class="space"> </span>**bar***</code></pre> <pre class="html"><code><p><em>foo<span class="space"> </span><strong>bar</strong></em></p></code></pre> </div> <p>Note, however, that in the following case we get no strong emphasis, because the opening delimiter is closed by the first <code>*</code> before <code>bar</code>:</p> <div id="example-298" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-298">Example 298</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>*foo**bar***</code></pre> <pre class="html"><code><p><em>foo</em><em>bar</em>**</p></code></pre> </div> <p>Indefinite levels of nesting are possible:</p> <div id="example-299" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-299">Example 299</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>*foo<span class="space"> </span>**bar<span class="space"> </span>*baz*<span class="space"> </span>bim**<span class="space"> </span>bop*</code></pre> <pre class="html"><code><p><em>foo<span class="space"> </span><strong>bar<span class="space"> </span><em>baz</em><span class="space"> </span>bim</strong><span class="space"> </span>bop</em></p></code></pre> </div> <div id="example-300" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-300">Example 300</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>*foo<span class="space"> </span>[*bar*](/url)*</code></pre> <pre class="html"><code><p><em>foo<span class="space"> </span><a<span class="space"> </span>href="/url"><em>bar</em></a></em></p></code></pre> </div> <p>There can be no empty emphasis or strong emphasis:</p> <div id="example-301" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-301">Example 301</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>**<span class="space"> </span>is<span class="space"> </span>not<span class="space"> </span>an<span class="space"> </span>empty<span class="space"> </span>emphasis</code></pre> <pre class="html"><code><p>**<span class="space"> </span>is<span class="space"> </span>not<span class="space"> </span>an<span class="space"> </span>empty<span class="space"> </span>emphasis</p></code></pre> </div> <div id="example-302" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-302">Example 302</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>****<span class="space"> </span>is<span class="space"> </span>not<span class="space"> </span>an<span class="space"> </span>empty<span class="space"> </span>strong<span class="space"> </span>emphasis</code></pre> <pre class="html"><code><p>****<span class="space"> </span>is<span class="space"> </span>not<span class="space"> </span>an<span class="space"> </span>empty<span class="space"> </span>strong<span class="space"> </span>emphasis</p></code></pre> </div> <p>Rule 10:</p> <p>Any nonempty sequence of inline elements can be the contents of an strongly emphasized span.</p> <div id="example-303" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-303">Example 303</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>**foo<span class="space"> </span>[bar](/url)**</code></pre> <pre class="html"><code><p><strong>foo<span class="space"> </span><a<span class="space"> </span>href="/url">bar</a></strong></p></code></pre> </div> <div id="example-304" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-304">Example 304</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>**foo bar**</code></pre> <pre class="html"><code><p><strong>foo bar</strong></p></code></pre> </div> <p>In particular, emphasis and strong emphasis can be nested inside strong emphasis:</p> <div id="example-305" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-305">Example 305</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>__foo<span class="space"> </span>_bar_<span class="space"> </span>baz__</code></pre> <pre class="html"><code><p><strong>foo<span class="space"> </span><em>bar</em><span class="space"> </span>baz</strong></p></code></pre> </div> <div id="example-306" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-306">Example 306</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>__foo<span class="space"> </span>__bar__<span class="space"> </span>baz__</code></pre> <pre class="html"><code><p><strong>foo<span class="space"> </span><strong>bar</strong><span class="space"> </span>baz</strong></p></code></pre> </div> <div id="example-307" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-307">Example 307</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>____foo__<span class="space"> </span>bar__</code></pre> <pre class="html"><code><p><strong><strong>foo</strong><span class="space"> </span>bar</strong></p></code></pre> </div> <div id="example-308" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-308">Example 308</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>**foo<span class="space"> </span>**bar****</code></pre> <pre class="html"><code><p><strong>foo<span class="space"> </span><strong>bar</strong></strong></p></code></pre> </div> <div id="example-309" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-309">Example 309</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>**foo<span class="space"> </span>*bar*<span class="space"> </span>baz**</code></pre> <pre class="html"><code><p><strong>foo<span class="space"> </span><em>bar</em><span class="space"> </span>baz</strong></p></code></pre> </div> <p>But note:</p> <div id="example-310" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-310">Example 310</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>**foo*bar*baz**</code></pre> <pre class="html"><code><p><em><em>foo</em>bar</em>baz**</p></code></pre> </div> <p>The difference is that in the preceding case, the internal delimiters <a href="#can-close-emphasis">can close emphasis</a>, while in the cases with spaces, they cannot.</p> <div id="example-311" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-311">Example 311</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>***foo*<span class="space"> </span>bar**</code></pre> <pre class="html"><code><p><strong><em>foo</em><span class="space"> </span>bar</strong></p></code></pre> </div> <div id="example-312" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-312">Example 312</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>**foo<span class="space"> </span>*bar***</code></pre> <pre class="html"><code><p><strong>foo<span class="space"> </span><em>bar</em></strong></p></code></pre> </div> <p>Indefinite levels of nesting are possible:</p> <div id="example-313" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-313">Example 313</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>**foo<span class="space"> </span>*bar<span class="space"> </span>**baz** bim*<span class="space"> </span>bop**</code></pre> <pre class="html"><code><p><strong>foo<span class="space"> </span><em>bar<span class="space"> </span><strong>baz</strong> bim</em><span class="space"> </span>bop</strong></p></code></pre> </div> <div id="example-314" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-314">Example 314</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>**foo<span class="space"> </span>[*bar*](/url)**</code></pre> <pre class="html"><code><p><strong>foo<span class="space"> </span><a<span class="space"> </span>href="/url"><em>bar</em></a></strong></p></code></pre> </div> <p>There can be no empty emphasis or strong emphasis:</p> <div id="example-315" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-315">Example 315</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>__<span class="space"> </span>is<span class="space"> </span>not<span class="space"> </span>an<span class="space"> </span>empty<span class="space"> </span>emphasis</code></pre> <pre class="html"><code><p>__<span class="space"> </span>is<span class="space"> </span>not<span class="space"> </span>an<span class="space"> </span>empty<span class="space"> </span>emphasis</p></code></pre> </div> <div id="example-316" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-316">Example 316</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>____<span class="space"> </span>is<span class="space"> </span>not<span class="space"> </span>an<span class="space"> </span>empty<span class="space"> </span>strong<span class="space"> </span>emphasis</code></pre> <pre class="html"><code><p>____<span class="space"> </span>is<span class="space"> </span>not<span class="space"> </span>an<span class="space"> </span>empty<span class="space"> </span>strong<span class="space"> </span>emphasis</p></code></pre> </div> <p>Rule 11:</p> <div id="example-317" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-317">Example 317</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>foo<span class="space"> </span>***</code></pre> <pre class="html"><code><p>foo<span class="space"> </span>***</p></code></pre> </div> <div id="example-318" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-318">Example 318</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>foo<span class="space"> </span>*\**</code></pre> <pre class="html"><code><p>foo<span class="space"> </span><em>*</em></p></code></pre> </div> <div id="example-319" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-319">Example 319</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>foo<span class="space"> </span>*_*</code></pre> <pre class="html"><code><p>foo<span class="space"> </span><em>_</em></p></code></pre> </div> <div id="example-320" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-320">Example 320</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>foo<span class="space"> </span>*****</code></pre> <pre class="html"><code><p>foo<span class="space"> </span>*****</p></code></pre> </div> <div id="example-321" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-321">Example 321</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>foo<span class="space"> </span>**\***</code></pre> <pre class="html"><code><p>foo<span class="space"> </span><strong>*</strong></p></code></pre> </div> <div id="example-322" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-322">Example 322</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>foo<span class="space"> </span>**_**</code></pre> <pre class="html"><code><p>foo<span class="space"> </span><strong>_</strong></p></code></pre> </div> <p>Note that when delimiters do not match evenly, Rule 11 determines that the excess literal <code>*</code> characters will appear outside of the emphasis, rather than inside it:</p> <div id="example-323" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-323">Example 323</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>**foo*</code></pre> <pre class="html"><code><p>*<em>foo</em></p></code></pre> </div> <div id="example-324" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-324">Example 324</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>*foo**</code></pre> <pre class="html"><code><p><em>foo</em>*</p></code></pre> </div> <div id="example-325" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-325">Example 325</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>***foo**</code></pre> <pre class="html"><code><p>*<strong>foo</strong></p></code></pre> </div> <div id="example-326" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-326">Example 326</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>****foo*</code></pre> <pre class="html"><code><p>***<em>foo</em></p></code></pre> </div> <div id="example-327" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-327">Example 327</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>**foo***</code></pre> <pre class="html"><code><p><strong>foo</strong>*</p></code></pre> </div> <div id="example-328" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-328">Example 328</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>*foo****</code></pre> <pre class="html"><code><p><em>foo</em>***</p></code></pre> </div> <p>Rule 12:</p> <div id="example-329" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-329">Example 329</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>foo<span class="space"> </span>___</code></pre> <pre class="html"><code><p>foo<span class="space"> </span>___</p></code></pre> </div> <div id="example-330" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-330">Example 330</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>foo<span class="space"> </span>_\__</code></pre> <pre class="html"><code><p>foo<span class="space"> </span><em>_</em></p></code></pre> </div> <div id="example-331" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-331">Example 331</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>foo<span class="space"> </span>_*_</code></pre> <pre class="html"><code><p>foo<span class="space"> </span><em>*</em></p></code></pre> </div> <div id="example-332" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-332">Example 332</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>foo<span class="space"> </span>_____</code></pre> <pre class="html"><code><p>foo<span class="space"> </span>_____</p></code></pre> </div> <div id="example-333" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-333">Example 333</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>foo<span class="space"> </span>__\___</code></pre> <pre class="html"><code><p>foo<span class="space"> </span><strong>_</strong></p></code></pre> </div> <div id="example-334" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-334">Example 334</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>foo<span class="space"> </span>__*__</code></pre> <pre class="html"><code><p>foo<span class="space"> </span><strong>*</strong></p></code></pre> </div> <div id="example-335" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-335">Example 335</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>__foo_</code></pre> <pre class="html"><code><p>_<em>foo</em></p></code></pre> </div> <p>Note that when delimiters do not match evenly, Rule 12 determines that the excess literal <code>_</code> characters will appear outside of the emphasis, rather than inside it:</p> <div id="example-336" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-336">Example 336</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>_foo__</code></pre> <pre class="html"><code><p><em>foo</em>_</p></code></pre> </div> <div id="example-337" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-337">Example 337</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>___foo__</code></pre> <pre class="html"><code><p>_<strong>foo</strong></p></code></pre> </div> <div id="example-338" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-338">Example 338</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>____foo_</code></pre> <pre class="html"><code><p>___<em>foo</em></p></code></pre> </div> <div id="example-339" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-339">Example 339</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>__foo___</code></pre> <pre class="html"><code><p><strong>foo</strong>_</p></code></pre> </div> <div id="example-340" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-340">Example 340</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>_foo____</code></pre> <pre class="html"><code><p><em>foo</em>___</p></code></pre> </div> <p>Rule 13 implies that if you want emphasis nested directly inside emphasis, you must use different delimiters:</p> <div id="example-341" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-341">Example 341</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>**foo**</code></pre> <pre class="html"><code><p><strong>foo</strong></p></code></pre> </div> <div id="example-342" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-342">Example 342</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>*_foo_*</code></pre> <pre class="html"><code><p><em><em>foo</em></em></p></code></pre> </div> <div id="example-343" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-343">Example 343</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>__foo__</code></pre> <pre class="html"><code><p><strong>foo</strong></p></code></pre> </div> <div id="example-344" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-344">Example 344</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>_*foo*_</code></pre> <pre class="html"><code><p><em><em>foo</em></em></p></code></pre> </div> <p>However, strong emphasis within strong emphasisis possible without switching delimiters:</p> <div id="example-345" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-345">Example 345</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>****foo****</code></pre> <pre class="html"><code><p><strong><strong>foo</strong></strong></p></code></pre> </div> <div id="example-346" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-346">Example 346</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>____foo____</code></pre> <pre class="html"><code><p><strong><strong>foo</strong></strong></p></code></pre> </div> <p>Rule 13 can be applied to arbitrarily long sequences of delimiters:</p> <div id="example-347" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-347">Example 347</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>******foo******</code></pre> <pre class="html"><code><p><strong><strong><strong>foo</strong></strong></strong></p></code></pre> </div> <p>Rule 14:</p> <div id="example-348" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-348">Example 348</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>***foo***</code></pre> <pre class="html"><code><p><strong><em>foo</em></strong></p></code></pre> </div> <div id="example-349" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-349">Example 349</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>_____foo_____</code></pre> <pre class="html"><code><p><strong><strong><em>foo</em></strong></strong></p></code></pre> </div> <p>Rule 15:</p> <div id="example-350" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-350">Example 350</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>*foo<span class="space"> </span>_bar*<span class="space"> </span>baz_</code></pre> <pre class="html"><code><p><em>foo<span class="space"> </span>_bar</em><span class="space"> </span>baz_</p></code></pre> </div> <div id="example-351" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-351">Example 351</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>**foo*bar**</code></pre> <pre class="html"><code><p><em><em>foo</em>bar</em>*</p></code></pre> </div> <p>Rule 16:</p> <div id="example-352" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-352">Example 352</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>**foo<span class="space"> </span>**bar<span class="space"> </span>baz**</code></pre> <pre class="html"><code><p>**foo<span class="space"> </span><strong>bar<span class="space"> </span>baz</strong></p></code></pre> </div> <div id="example-353" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-353">Example 353</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>*foo<span class="space"> </span>*bar<span class="space"> </span>baz*</code></pre> <pre class="html"><code><p>*foo<span class="space"> </span><em>bar<span class="space"> </span>baz</em></p></code></pre> </div> <p>Rule 17:</p> <div id="example-354" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-354">Example 354</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>*[bar*](/url)</code></pre> <pre class="html"><code><p>*<a<span class="space"> </span>href="/url">bar*</a></p></code></pre> </div> <div id="example-355" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-355">Example 355</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>_foo<span class="space"> </span>[bar_](/url)</code></pre> <pre class="html"><code><p>_foo<span class="space"> </span><a<span class="space"> </span>href="/url">bar_</a></p></code></pre> </div> <div id="example-356" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-356">Example 356</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>*<img<span class="space"> </span>src="foo"<span class="space"> </span>title="*"/></code></pre> <pre class="html"><code><p>*<img<span class="space"> </span>src="foo"<span class="space"> </span>title="*"/></p></code></pre> </div> <div id="example-357" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-357">Example 357</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>**<a<span class="space"> </span>href="**"></code></pre> <pre class="html"><code><p>**<a<span class="space"> </span>href="**"></p></code></pre> </div> <div id="example-358" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-358">Example 358</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>__<a<span class="space"> </span>href="__"></code></pre> <pre class="html"><code><p>__<a<span class="space"> </span>href="__"></p></code></pre> </div> <div id="example-359" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-359">Example 359</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>*a<span class="space"> </span>`*`*</code></pre> <pre class="html"><code><p><em>a<span class="space"> </span><code>*</code></em></p></code></pre> </div> <div id="example-360" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-360">Example 360</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>_a<span class="space"> </span>`_`_</code></pre> <pre class="html"><code><p><em>a<span class="space"> </span><code>_</code></em></p></code></pre> </div> <div id="example-361" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-361">Example 361</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>**a<http://foo.bar?q=**></code></pre> <pre class="html"><code><p>**a<a<span class="space"> </span>href="http://foo.bar?q=**">http://foo.bar?q=**</a></p></code></pre> </div> <div id="example-362" class="example" data-section="Emphasis and strong emphasis"> <div class="examplenum"> <a href="#example-362">Example 362</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>__a<http://foo.bar?q=__></code></pre> <pre class="html"><code><p>__a<a<span class="space"> </span>href="http://foo.bar?q=__">http://foo.bar?q=__</a></p></code></pre> </div> <h2 id="links"><span class="header-section-number">6.5</span> Links</h2> <p>A link contains <a href="#link-label">link text</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 link text. In <a href="#reference-links">reference links</a> the destination and title are defined elsewhere in the document.</p> <p>A <a id="link-text" href="#link-text" class="definition">link text</a> consists of a sequence of zero or more inline elements enclosed by square brackets (<code>[</code> and <code>]</code>). The following rules apply:</p> <ul> <li><p>Links may not contain other links, at any level of nesting.</p></li> <li><p>Brackets are allowed in the link text only if (a) they are backslash-escaped or (b) they appear as a matched pair of brackets, with an open bracket <code>[</code>, a sequence of zero or more inlines, and a close bracket <code>]</code>.</p></li> <li><p>Backtick <a href="#code-span">code spans</a>, <a href="#autolink">autolinks</a>, and raw <a href="#html-tag">HTML tags</a> bind more tightly than the brackets in link text. Thus, for example, <code>[foo`]`</code> could not be a link text, since the second <code>]</code> is part of a code span.</p></li> <li><p>The brackets in link text bind more tightly than markers for <a href="#emphasis-and-strong-emphasis">emphasis and strong emphasis</a>. Thus, for example, <code>*[foo*](url)</code> is a link.</p></li> </ul> <p>A <a id="link-destination" href="#link-destination" class="definition">link destination</a> consists of either</p> <ul> <li><p>a sequence of zero or more characters between an opening <code><</code> and a closing <code>></code> that contains no line breaks or unescaped <code><</code> or <code>></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 paretheses.</p></li> </ul> <p>A <a id="link-title" href="#link-title" class="definition">link title</a> consists of either</p> <ul> <li><p>a sequence of zero or more characters between straight double-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 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 id="inline-link" href="#inline-link" class="definition">inline link</a> consists of a <a href="#link-text">link text</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 inlines contained in the <a href="#link-text">link text</a> (excluding the enclosing square brackets). The link’s URI consists of the link destination, excluding enclosing <code><...></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-363" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-363">Example 363</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[link](/uri<span class="space"> </span>"title")</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/uri"<span class="space"> </span>title="title">link</a></p></code></pre> </div> <p>The title may be omitted:</p> <div id="example-364" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-364">Example 364</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[link](/uri)</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/uri">link</a></p></code></pre> </div> <p>Both the title and the destination may be omitted:</p> <div id="example-365" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-365">Example 365</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[link]()</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="">link</a></p></code></pre> </div> <div id="example-366" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-366">Example 366</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[link](<>)</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="">link</a></p></code></pre> </div> <p>If the destination contains spaces, it must be enclosed in pointy braces:</p> <div id="example-367" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-367">Example 367</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[link](/my<span class="space"> </span>uri)</code></pre> <pre class="html"><code><p>[link](/my<span class="space"> </span>uri)</p></code></pre> </div> <div id="example-368" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-368">Example 368</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[link](</my<span class="space"> </span>uri>)</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/my%20uri">link</a></p></code></pre> </div> <p>The destination cannot contain line breaks, even with pointy braces:</p> <div id="example-369" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-369">Example 369</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[link](foo bar)</code></pre> <pre class="html"><code><p>[link](foo bar)</p></code></pre> </div> <p>One level of balanced parentheses is allowed without escaping:</p> <div id="example-370" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-370">Example 370</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[link]((foo)and(bar))</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="(foo)and(bar)">link</a></p></code></pre> </div> <p>However, if you have parentheses within parentheses, you need to escape or use the <code><...></code> form:</p> <div id="example-371" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-371">Example 371</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[link](foo(and(bar)))</code></pre> <pre class="html"><code><p>[link](foo(and(bar)))</p></code></pre> </div> <div id="example-372" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-372">Example 372</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[link](foo(and\(bar\)))</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="foo(and(bar))">link</a></p></code></pre> </div> <div id="example-373" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-373">Example 373</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[link](<foo(and(bar))>)</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="foo(and(bar))">link</a></p></code></pre> </div> <p>Parentheses and other symbols can also be escaped, as usual in Markdown:</p> <div id="example-374" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-374">Example 374</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[link](foo\)\:)</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="foo):">link</a></p></code></pre> </div> <p>URL-escaping should be left alone inside the destination, as all URL-escaped characters are also valid URL characters. HTML entities in the destination will be parsed into their UTF-8 codepoints, as usual, and optionally URL-escaped when written as HTML.</p> <div id="example-375" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-375">Example 375</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[link](foo%20b&auml;)</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="foo%20b%C3%A4">link</a></p></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-376" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-376">Example 376</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[link]("title")</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="%22title%22">link</a></p></code></pre> </div> <p>Titles may be in single quotes, double quotes, or parentheses:</p> <div id="example-377" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-377">Example 377</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[link](/url<span class="space"> </span>"title") [link](/url<span class="space"> </span>'title') [link](/url<span class="space"> </span>(title))</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/url"<span class="space"> </span>title="title">link</a> <a<span class="space"> </span>href="/url"<span class="space"> </span>title="title">link</a> <a<span class="space"> </span>href="/url"<span class="space"> </span>title="title">link</a></p></code></pre> </div> <p>Backslash escapes and entities may be used in titles:</p> <div id="example-378" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-378">Example 378</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[link](/url<span class="space"> </span>"title<span class="space"> </span>\"&quot;")</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/url"<span class="space"> </span>title="title<span class="space"> </span>&quot;&quot;">link</a></p></code></pre> </div> <p>Nested balanced quotes are not allowed without escaping:</p> <div id="example-379" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-379">Example 379</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[link](/url<span class="space"> </span>"title<span class="space"> </span>"and"<span class="space"> </span>title")</code></pre> <pre class="html"><code><p>[link](/url<span class="space"> </span>&quot;title<span class="space"> </span>&quot;and&quot;<span class="space"> </span>title&quot;)</p></code></pre> </div> <p>But it is easy to work around this by using a different quote type:</p> <div id="example-380" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-380">Example 380</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[link](/url<span class="space"> </span>'title<span class="space"> </span>"and"<span class="space"> </span>title')</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/url"<span class="space"> </span>title="title<span class="space"> </span>&quot;and&quot;<span class="space"> </span>title">link</a></p></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>"</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-381" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-381">Example 381</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[link](<span class="space"> </span><span class="space"> </span><span class="space"> </span>/uri <span class="space"> </span><span class="space"> </span>"title"<span class="space"> </span><span class="space"> </span>)</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/uri"<span class="space"> </span>title="title">link</a></p></code></pre> </div> <p>But it is not allowed between the link text and the following parenthesis:</p> <div id="example-382" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-382">Example 382</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[link]<span class="space"> </span>(/uri)</code></pre> <pre class="html"><code><p>[link]<span class="space"> </span>(/uri)</p></code></pre> </div> <p>The link text may contain balanced brackets, but not unbalanced ones, unless they are escaped:</p> <div id="example-383" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-383">Example 383</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[link<span class="space"> </span>[foo<span class="space"> </span>[bar]]](/uri)</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/uri">link<span class="space"> </span>[foo<span class="space"> </span>[bar]]</a></p></code></pre> </div> <div id="example-384" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-384">Example 384</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[link]<span class="space"> </span>bar](/uri)</code></pre> <pre class="html"><code><p>[link]<span class="space"> </span>bar](/uri)</p></code></pre> </div> <div id="example-385" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-385">Example 385</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[link<span class="space"> </span>[bar](/uri)</code></pre> <pre class="html"><code><p>[link<span class="space"> </span><a<span class="space"> </span>href="/uri">bar</a></p></code></pre> </div> <div id="example-386" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-386">Example 386</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[link<span class="space"> </span>\[bar](/uri)</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/uri">link<span class="space"> </span>[bar</a></p></code></pre> </div> <p>The link text may contain inline content:</p> <div id="example-387" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-387">Example 387</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[link<span class="space"> </span>*foo<span class="space"> </span>**bar**<span class="space"> </span>`#`*](/uri)</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/uri">link<span class="space"> </span><em>foo<span class="space"> </span><strong>bar</strong><span class="space"> </span><code>#</code></em></a></p></code></pre> </div> <div id="example-388" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-388">Example 388</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[![moon](moon.jpg)](/uri)</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/uri"><img<span class="space"> </span>src="moon.jpg"<span class="space"> </span>alt="moon"<span class="space"> </span>/></a></p></code></pre> </div> <p>However, links may not contain other links, at any level of nesting.</p> <div id="example-389" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-389">Example 389</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[foo<span class="space"> </span>[bar](/uri)](/uri)</code></pre> <pre class="html"><code><p>[foo<span class="space"> </span><a<span class="space"> </span>href="/uri">bar</a>](/uri)</p></code></pre> </div> <div id="example-390" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-390">Example 390</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[foo<span class="space"> </span>*[bar<span class="space"> </span>[baz](/uri)](/uri)*](/uri)</code></pre> <pre class="html"><code><p>[foo<span class="space"> </span><em>[bar<span class="space"> </span><a<span class="space"> </span>href="/uri">baz</a>](/uri)</em>](/uri)</p></code></pre> </div> <p>These cases illustrate the precedence of link text grouping over emphasis grouping:</p> <div id="example-391" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-391">Example 391</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>*[foo*](/uri)</code></pre> <pre class="html"><code><p>*<a<span class="space"> </span>href="/uri">foo*</a></p></code></pre> </div> <div id="example-392" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-392">Example 392</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[foo<span class="space"> </span>*bar](baz*)</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="baz*">foo<span class="space"> </span>*bar</a></p></code></pre> </div> <p>These cases illustrate the precedence of HTML tags, code spans, and autolinks over link grouping:</p> <div id="example-393" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-393">Example 393</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[foo<span class="space"> </span><bar<span class="space"> </span>attr="](baz)"></code></pre> <pre class="html"><code><p>[foo<span class="space"> </span><bar<span class="space"> </span>attr="](baz)"></p></code></pre> </div> <div id="example-394" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-394">Example 394</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[foo`](/uri)`</code></pre> <pre class="html"><code><p>[foo<code>](/uri)</code></p></code></pre> </div> <div id="example-395" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-395">Example 395</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[foo<http://example.com?search=](uri)></code></pre> <pre class="html"><code><p>[foo<a<span class="space"> </span>href="http://example.com?search=%5D(uri)">http://example.com?search=](uri)</a></p></code></pre> </div> <p>There are three kinds of <a id="reference-link" href="#reference-link" class="definition">reference links</a>: <a href="#full-reference-link">full</a>, <a href="#collapsed-reference-link">collapsed</a>, and <a href="#shortcut-reference-link">shortcut</a>.</p> <p>A <a id="full-reference-link" href="#full-reference-link" class="definition">full reference link</a> consists of a <a href="#link-text">link text</a>, optional whitespace, and 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.</p> <p>A <a id="link-label" href="#link-label" class="definition">link label</a> begins with a left bracket (<code>[</code>) and ends with the first right bracket (<code>]</code>) that is not backslash-escaped. Unescaped square bracket characters are not allowed in <a href="#link-label">link labels</a>. A link label can have at most 999 characters inside the square brackets.</p> <p>One label <a id="matches" href="#matches" class="definition">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-396" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-396">Example 396</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[foo][bar] [bar]:<span class="space"> </span>/url<span class="space"> </span>"title"</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/url"<span class="space"> </span>title="title">foo</a></p></code></pre> </div> <p>The rules for the <a href="#link-text">link text</a> are the same as with <a href="#inline-link">inline links</a>. Thus:</p> <p>The link text may contain balanced brackets, but not unbalanced ones, unless they are escaped:</p> <div id="example-397" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-397">Example 397</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[link<span class="space"> </span>[foo<span class="space"> </span>[bar]]][ref] [ref]:<span class="space"> </span>/uri</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/uri">link<span class="space"> </span>[foo<span class="space"> </span>[bar]]</a></p></code></pre> </div> <div id="example-398" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-398">Example 398</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[link<span class="space"> </span>\[bar][ref] [ref]:<span class="space"> </span>/uri</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/uri">link<span class="space"> </span>[bar</a></p></code></pre> </div> <p>The link text may contain inline content:</p> <div id="example-399" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-399">Example 399</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[link<span class="space"> </span>*foo<span class="space"> </span>**bar**<span class="space"> </span>`#`*][ref] [ref]:<span class="space"> </span>/uri</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/uri">link<span class="space"> </span><em>foo<span class="space"> </span><strong>bar</strong><span class="space"> </span><code>#</code></em></a></p></code></pre> </div> <div id="example-400" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-400">Example 400</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[![moon](moon.jpg)][ref] [ref]:<span class="space"> </span>/uri</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/uri"><img<span class="space"> </span>src="moon.jpg"<span class="space"> </span>alt="moon"<span class="space"> </span>/></a></p></code></pre> </div> <p>However, links may not contain other links, at any level of nesting.</p> <div id="example-401" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-401">Example 401</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[foo<span class="space"> </span>[bar](/uri)][ref] [ref]:<span class="space"> </span>/uri</code></pre> <pre class="html"><code><p>[foo<span class="space"> </span><a<span class="space"> </span>href="/uri">bar</a>]<a<span class="space"> </span>href="/uri">ref</a></p></code></pre> </div> <div id="example-402" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-402">Example 402</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[foo<span class="space"> </span>*bar<span class="space"> </span>[baz][ref]*][ref] [ref]:<span class="space"> </span>/uri</code></pre> <pre class="html"><code><p>[foo<span class="space"> </span><em>bar<span class="space"> </span><a<span class="space"> </span>href="/uri">baz</a></em>]<a<span class="space"> </span>href="/uri">ref</a></p></code></pre> </div> <p>(In the examples above, we have two <a href="#shortcut-reference-link">shortcut reference links</a> instead of one <a href="#full-reference-link">full reference link</a>.)</p> <p>The following cases illustrate the precedence of link text grouping over emphasis grouping:</p> <div id="example-403" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-403">Example 403</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>*[foo*][ref] [ref]:<span class="space"> </span>/uri</code></pre> <pre class="html"><code><p>*<a<span class="space"> </span>href="/uri">foo*</a></p></code></pre> </div> <div id="example-404" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-404">Example 404</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[foo<span class="space"> </span>*bar][ref] [ref]:<span class="space"> </span>/uri</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/uri">foo<span class="space"> </span>*bar</a></p></code></pre> </div> <p>These cases illustrate the precedence of HTML tags, code spans, and autolinks over link grouping:</p> <div id="example-405" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-405">Example 405</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[foo<span class="space"> </span><bar<span class="space"> </span>attr="][ref]"> [ref]:<span class="space"> </span>/uri</code></pre> <pre class="html"><code><p>[foo<span class="space"> </span><bar<span class="space"> </span>attr="][ref]"></p></code></pre> </div> <div id="example-406" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-406">Example 406</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[foo`][ref]` [ref]:<span class="space"> </span>/uri</code></pre> <pre class="html"><code><p>[foo<code>][ref]</code></p></code></pre> </div> <div id="example-407" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-407">Example 407</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[foo<http://example.com?search=][ref]> [ref]:<span class="space"> </span>/uri</code></pre> <pre class="html"><code><p>[foo<a<span class="space"> </span>href="http://example.com?search=%5D%5Bref%5D">http://example.com?search=][ref]</a></p></code></pre> </div> <p>Matching is case-insensitive:</p> <div id="example-408" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-408">Example 408</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[foo][BaR] [bar]:<span class="space"> </span>/url<span class="space"> </span>"title"</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/url"<span class="space"> </span>title="title">foo</a></p></code></pre> </div> <p>Unicode case fold is used:</p> <div id="example-409" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-409">Example 409</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[Толпой][Толпой]<span class="space"> </span>is<span class="space"> </span>a<span class="space"> </span>Russian<span class="space"> </span>word. [ТОЛПОЙ]:<span class="space"> </span>/url</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/url">Толпой</a><span class="space"> </span>is<span class="space"> </span>a<span class="space"> </span>Russian<span class="space"> </span>word.</p></code></pre> </div> <p>Consecutive internal whitespace is treated as one space for purposes of determining matching:</p> <div id="example-410" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-410">Example 410</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[Foo <span class="space"> </span><span class="space"> </span>bar]:<span class="space"> </span>/url [Baz][Foo<span class="space"> </span>bar]</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/url">Baz</a></p></code></pre> </div> <p>There can be whitespace between the <a href="#link-text">link text</a> and the <a href="#link-label">link label</a>:</p> <div id="example-411" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-411">Example 411</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[foo]<span class="space"> </span>[bar] [bar]:<span class="space"> </span>/url<span class="space"> </span>"title"</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/url"<span class="space"> </span>title="title">foo</a></p></code></pre> </div> <div id="example-412" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-412">Example 412</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[foo] [bar] [bar]:<span class="space"> </span>/url<span class="space"> </span>"title"</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/url"<span class="space"> </span>title="title">foo</a></p></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-413" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-413">Example 413</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[foo]:<span class="space"> </span>/url1 [foo]:<span class="space"> </span>/url2 [bar][foo]</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/url1">bar</a></p></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-414" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-414">Example 414</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[bar][foo\!] [foo!]:<span class="space"> </span>/url</code></pre> <pre class="html"><code><p>[bar][foo!]</p></code></pre> </div> <p><a href="#link-label">Link labels</a> cannot contain brackets, unless they are backslash-escaped:</p> <div id="example-415" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-415">Example 415</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[foo][ref[] [ref[]:<span class="space"> </span>/uri</code></pre> <pre class="html"><code><p>[foo][ref[]</p> <p>[ref[]:<span class="space"> </span>/uri</p></code></pre> </div> <div id="example-416" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-416">Example 416</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[foo][ref[bar]] [ref[bar]]:<span class="space"> </span>/uri</code></pre> <pre class="html"><code><p>[foo][ref[bar]]</p> <p>[ref[bar]]:<span class="space"> </span>/uri</p></code></pre> </div> <div id="example-417" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-417">Example 417</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[[[foo]]] [[[foo]]]:<span class="space"> </span>/url</code></pre> <pre class="html"><code><p>[[[foo]]]</p> <p>[[[foo]]]:<span class="space"> </span>/url</p></code></pre> </div> <div id="example-418" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-418">Example 418</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[foo][ref\[] [ref\[]:<span class="space"> </span>/uri</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/uri">foo</a></p></code></pre> </div> <p>A <a id="collapsed-reference-link" href="#collapsed-reference-link" class="definition">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-419" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-419">Example 419</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[foo][] [foo]:<span class="space"> </span>/url<span class="space"> </span>"title"</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/url"<span class="space"> </span>title="title">foo</a></p></code></pre> </div> <div id="example-420" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-420">Example 420</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[*foo*<span class="space"> </span>bar][] [*foo*<span class="space"> </span>bar]:<span class="space"> </span>/url<span class="space"> </span>"title"</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/url"<span class="space"> </span>title="title"><em>foo</em><span class="space"> </span>bar</a></p></code></pre> </div> <p>The link labels are case-insensitive:</p> <div id="example-421" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-421">Example 421</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[Foo][] [foo]:<span class="space"> </span>/url<span class="space"> </span>"title"</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/url"<span class="space"> </span>title="title">Foo</a></p></code></pre> </div> <p>As with full reference links, whitespace is allowed between the two sets of brackets:</p> <div id="example-422" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-422">Example 422</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[foo]<span class="space"> </span> [] [foo]:<span class="space"> </span>/url<span class="space"> </span>"title"</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/url"<span class="space"> </span>title="title">foo</a></p></code></pre> </div> <p>A <a id="shortcut-reference-link" href="#shortcut-reference-link" class="definition">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-423" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-423">Example 423</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[foo] [foo]:<span class="space"> </span>/url<span class="space"> </span>"title"</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/url"<span class="space"> </span>title="title">foo</a></p></code></pre> </div> <div id="example-424" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-424">Example 424</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[*foo*<span class="space"> </span>bar] [*foo*<span class="space"> </span>bar]:<span class="space"> </span>/url<span class="space"> </span>"title"</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/url"<span class="space"> </span>title="title"><em>foo</em><span class="space"> </span>bar</a></p></code></pre> </div> <div id="example-425" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-425">Example 425</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[[*foo*<span class="space"> </span>bar]] [*foo*<span class="space"> </span>bar]:<span class="space"> </span>/url<span class="space"> </span>"title"</code></pre> <pre class="html"><code><p>[<a<span class="space"> </span>href="/url"<span class="space"> </span>title="title"><em>foo</em><span class="space"> </span>bar</a>]</p></code></pre> </div> <p>The link labels are case-insensitive:</p> <div id="example-426" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-426">Example 426</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[Foo] [foo]:<span class="space"> </span>/url<span class="space"> </span>"title"</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/url"<span class="space"> </span>title="title">Foo</a></p></code></pre> </div> <p>If you just want bracketed text, you can backslash-escape the opening bracket to avoid links:</p> <div id="example-427" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-427">Example 427</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>\[foo] [foo]:<span class="space"> </span>/url<span class="space"> </span>"title"</code></pre> <pre class="html"><code><p>[foo]</p></code></pre> </div> <p>Note that this is a link, because a link label ends with the first following closing bracket:</p> <div id="example-428" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-428">Example 428</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[foo*]:<span class="space"> </span>/url *[foo*]</code></pre> <pre class="html"><code><p>*<a<span class="space"> </span>href="/url">foo*</a></p></code></pre> </div> <p>This is a link too, for the same reason:</p> <div id="example-429" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-429">Example 429</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[foo`]:<span class="space"> </span>/url [foo`]`</code></pre> <pre class="html"><code><p>[foo<code>]</code></p></code></pre> </div> <p>Full references take precedence over shortcut references:</p> <div id="example-430" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-430">Example 430</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[foo][bar] [foo]:<span class="space"> </span>/url1 [bar]:<span class="space"> </span>/url2</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/url2">foo</a></p></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-431" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-431">Example 431</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[foo][bar][baz] [baz]:<span class="space"> </span>/url</code></pre> <pre class="html"><code><p>[foo]<a<span class="space"> </span>href="/url">bar</a></p></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-432" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-432">Example 432</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[foo][bar][baz] [baz]:<span class="space"> </span>/url1 [bar]:<span class="space"> </span>/url2</code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="/url2">foo</a><a<span class="space"> </span>href="/url1">baz</a></p></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-433" class="example" data-section="Links"> <div class="examplenum"> <a href="#example-433">Example 433</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>[foo][bar][baz] [baz]:<span class="space"> </span>/url1 [foo]:<span class="space"> </span>/url2</code></pre> <pre class="html"><code><p>[foo]<a<span class="space"> </span>href="/url1">bar</a></p></code></pre> </div> <h2 id="images"><span class="header-section-number">6.6</span> Images</h2> <p>Syntax for images is like the syntax for links, with one difference. Instead of <a href="#link-text">link text</a>, we have an <a id="image-description" href="#image-description" class="definition">image description</a>. The rules for this are the same as for <a href="#link-text">link text</a>, except that (a) an image description starts with <code>![</code> rather than <code>[</code>, and (b) an image description may contain links, but not images (even deeply nested). An image description has inline elements as its contents. When an image is rendered to HTML, this is standardly used as the image’s <code>alt</code> attribute.</p> <div id="example-434" class="example" data-section="Images"> <div class="examplenum"> <a href="#example-434">Example 434</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>![foo](/url<span class="space"> </span>"title")</code></pre> <pre class="html"><code><p><img<span class="space"> </span>src="/url"<span class="space"> </span>alt="foo"<span class="space"> </span>title="title"<span class="space"> </span>/></p></code></pre> </div> <div id="example-435" class="example" data-section="Images"> <div class="examplenum"> <a href="#example-435">Example 435</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>![foo<span class="space"> </span>*bar*] [foo<span class="space"> </span>*bar*]:<span class="space"> </span>train.jpg<span class="space"> </span>"train<span class="space"> </span>&<span class="space"> </span>tracks"</code></pre> <pre class="html"><code><p><img<span class="space"> </span>src="train.jpg"<span class="space"> </span>alt="foo<span class="space"> </span>bar"<span class="space"> </span>title="train<span class="space"> </span>&amp;<span class="space"> </span>tracks"<span class="space"> </span>/></p></code></pre> </div> <div id="example-436" class="example" data-section="Images"> <div class="examplenum"> <a href="#example-436">Example 436</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>![foo<span class="space"> </span>![bar](/url)](/url2)</code></pre> <pre class="html"><code><p>![foo<span class="space"> </span><img<span class="space"> </span>src="/url"<span class="space"> </span>alt="bar"<span class="space"> </span>/>](/url2)</p></code></pre> </div> <div id="example-437" class="example" data-section="Images"> <div class="examplenum"> <a href="#example-437">Example 437</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>![foo<span class="space"> </span>[bar](/url)](/url2)</code></pre> <pre class="html"><code><p><img<span class="space"> </span>src="/url2"<span class="space"> </span>alt="foo<span class="space"> </span>bar"<span class="space"> </span>/></p></code></pre> </div> <p>Though this spec is concerned with parsing, not rendering, it is recommended that in rendering to HTML, only the plain string content of the <a href="#image-description">image description</a> be used. Note that in the above example, the alt attribute’s value is <code>foo bar</code>, not <code>foo [bar](/url)</code> or <code>foo <a href="/url">bar</a></code>. Only the plain string content is rendered, without formatting.</p> <div id="example-438" class="example" data-section="Images"> <div class="examplenum"> <a href="#example-438">Example 438</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>![foo<span class="space"> </span>*bar*][] [foo<span class="space"> </span>*bar*]:<span class="space"> </span>train.jpg<span class="space"> </span>"train<span class="space"> </span>&<span class="space"> </span>tracks"</code></pre> <pre class="html"><code><p><img<span class="space"> </span>src="train.jpg"<span class="space"> </span>alt="foo<span class="space"> </span>bar"<span class="space"> </span>title="train<span class="space"> </span>&amp;<span class="space"> </span>tracks"<span class="space"> </span>/></p></code></pre> </div> <div id="example-439" class="example" data-section="Images"> <div class="examplenum"> <a href="#example-439">Example 439</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>![foo<span class="space"> </span>*bar*][foobar] [FOOBAR]:<span class="space"> </span>train.jpg<span class="space"> </span>"train<span class="space"> </span>&<span class="space"> </span>tracks"</code></pre> <pre class="html"><code><p><img<span class="space"> </span>src="train.jpg"<span class="space"> </span>alt="foo<span class="space"> </span>bar"<span class="space"> </span>title="train<span class="space"> </span>&amp;<span class="space"> </span>tracks"<span class="space"> </span>/></p></code></pre> </div> <div id="example-440" class="example" data-section="Images"> <div class="examplenum"> <a href="#example-440">Example 440</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>![foo](train.jpg)</code></pre> <pre class="html"><code><p><img<span class="space"> </span>src="train.jpg"<span class="space"> </span>alt="foo"<span class="space"> </span>/></p></code></pre> </div> <div id="example-441" class="example" data-section="Images"> <div class="examplenum"> <a href="#example-441">Example 441</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>My<span class="space"> </span>![foo<span class="space"> </span>bar](/path/to/train.jpg<span class="space"> </span><span class="space"> </span>"title"<span class="space"> </span><span class="space"> </span><span class="space"> </span>)</code></pre> <pre class="html"><code><p>My<span class="space"> </span><img<span class="space"> </span>src="/path/to/train.jpg"<span class="space"> </span>alt="foo<span class="space"> </span>bar"<span class="space"> </span>title="title"<span class="space"> </span>/></p></code></pre> </div> <div id="example-442" class="example" data-section="Images"> <div class="examplenum"> <a href="#example-442">Example 442</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>![foo](<url>)</code></pre> <pre class="html"><code><p><img<span class="space"> </span>src="url"<span class="space"> </span>alt="foo"<span class="space"> </span>/></p></code></pre> </div> <div id="example-443" class="example" data-section="Images"> <div class="examplenum"> <a href="#example-443">Example 443</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>![](/url)</code></pre> <pre class="html"><code><p><img<span class="space"> </span>src="/url"<span class="space"> </span>alt=""<span class="space"> </span>/></p></code></pre> </div> <p>Reference-style:</p> <div id="example-444" class="example" data-section="Images"> <div class="examplenum"> <a href="#example-444">Example 444</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>![foo]<span class="space"> </span>[bar] [bar]:<span class="space"> </span>/url</code></pre> <pre class="html"><code><p><img<span class="space"> </span>src="/url"<span class="space"> </span>alt="foo"<span class="space"> </span>/></p></code></pre> </div> <div id="example-445" class="example" data-section="Images"> <div class="examplenum"> <a href="#example-445">Example 445</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>![foo]<span class="space"> </span>[bar] [BAR]:<span class="space"> </span>/url</code></pre> <pre class="html"><code><p><img<span class="space"> </span>src="/url"<span class="space"> </span>alt="foo"<span class="space"> </span>/></p></code></pre> </div> <p>Collapsed:</p> <div id="example-446" class="example" data-section="Images"> <div class="examplenum"> <a href="#example-446">Example 446</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>![foo][] [foo]:<span class="space"> </span>/url<span class="space"> </span>"title"</code></pre> <pre class="html"><code><p><img<span class="space"> </span>src="/url"<span class="space"> </span>alt="foo"<span class="space"> </span>title="title"<span class="space"> </span>/></p></code></pre> </div> <div id="example-447" class="example" data-section="Images"> <div class="examplenum"> <a href="#example-447">Example 447</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>![*foo*<span class="space"> </span>bar][] [*foo*<span class="space"> </span>bar]:<span class="space"> </span>/url<span class="space"> </span>"title"</code></pre> <pre class="html"><code><p><img<span class="space"> </span>src="/url"<span class="space"> </span>alt="foo<span class="space"> </span>bar"<span class="space"> </span>title="title"<span class="space"> </span>/></p></code></pre> </div> <p>The labels are case-insensitive:</p> <div id="example-448" class="example" data-section="Images"> <div class="examplenum"> <a href="#example-448">Example 448</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>![Foo][] [foo]:<span class="space"> </span>/url<span class="space"> </span>"title"</code></pre> <pre class="html"><code><p><img<span class="space"> </span>src="/url"<span class="space"> </span>alt="Foo"<span class="space"> </span>title="title"<span class="space"> </span>/></p></code></pre> </div> <p>As with full reference links, whitespace is allowed between the two sets of brackets:</p> <div id="example-449" class="example" data-section="Images"> <div class="examplenum"> <a href="#example-449">Example 449</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>![foo]<span class="space"> </span> [] [foo]:<span class="space"> </span>/url<span class="space"> </span>"title"</code></pre> <pre class="html"><code><p><img<span class="space"> </span>src="/url"<span class="space"> </span>alt="foo"<span class="space"> </span>title="title"<span class="space"> </span>/></p></code></pre> </div> <p>Shortcut:</p> <div id="example-450" class="example" data-section="Images"> <div class="examplenum"> <a href="#example-450">Example 450</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>![foo] [foo]:<span class="space"> </span>/url<span class="space"> </span>"title"</code></pre> <pre class="html"><code><p><img<span class="space"> </span>src="/url"<span class="space"> </span>alt="foo"<span class="space"> </span>title="title"<span class="space"> </span>/></p></code></pre> </div> <div id="example-451" class="example" data-section="Images"> <div class="examplenum"> <a href="#example-451">Example 451</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>![*foo*<span class="space"> </span>bar] [*foo*<span class="space"> </span>bar]:<span class="space"> </span>/url<span class="space"> </span>"title"</code></pre> <pre class="html"><code><p><img<span class="space"> </span>src="/url"<span class="space"> </span>alt="foo<span class="space"> </span>bar"<span class="space"> </span>title="title"<span class="space"> </span>/></p></code></pre> </div> <p>Note that link labels cannot contain unescaped brackets:</p> <div id="example-452" class="example" data-section="Images"> <div class="examplenum"> <a href="#example-452">Example 452</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>![[foo]] [[foo]]:<span class="space"> </span>/url<span class="space"> </span>"title"</code></pre> <pre class="html"><code><p>![[foo]]</p> <p>[[foo]]:<span class="space"> </span>/url<span class="space"> </span>&quot;title&quot;</p></code></pre> </div> <p>The link labels are case-insensitive:</p> <div id="example-453" class="example" data-section="Images"> <div class="examplenum"> <a href="#example-453">Example 453</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>![Foo] [foo]:<span class="space"> </span>/url<span class="space"> </span>"title"</code></pre> <pre class="html"><code><p><img<span class="space"> </span>src="/url"<span class="space"> </span>alt="Foo"<span class="space"> </span>title="title"<span class="space"> </span>/></p></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-454" class="example" data-section="Images"> <div class="examplenum"> <a href="#example-454">Example 454</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>\!\[foo] [foo]:<span class="space"> </span>/url<span class="space"> </span>"title"</code></pre> <pre class="html"><code><p>![foo]</p></code></pre> </div> <p>If you want a link after a literal <code>!</code>, backslash-escape the <code>!</code>:</p> <div id="example-455" class="example" data-section="Images"> <div class="examplenum"> <a href="#example-455">Example 455</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>\![foo] [foo]:<span class="space"> </span>/url<span class="space"> </span>"title"</code></pre> <pre class="html"><code><p>!<a<span class="space"> </span>href="/url"<span class="space"> </span>title="title">foo</a></p></code></pre> </div> <h2 id="autolinks"><span class="header-section-number">6.7</span> Autolinks</h2> <p><a id="autolink" href="#autolink" class="definition">Autolinks</a> are absolute URIs and email addresses inside <code><</code> and <code>></code>. They are parsed as links, with the URL or email address as the link label.</p> <p>A <a id="uri-autolink" href="#uri-autolink" class="definition">URI autolink</a> consists of <code><</code>, followed by an <a href="#absolute-uri">absolute URI</a> not containing <code><</code>, followed by <code>></code>. It is parsed as a link to the URI, with the URI as the link’s label.</p> <p>An <a id="absolute-uri" href="#absolute-uri" class="definition">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><</code>, and <code>></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 id="scheme" href="#scheme" class="definition">schemes</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-456" class="example" data-section="Autolinks"> <div class="examplenum"> <a href="#example-456">Example 456</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><http://foo.bar.baz></code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="http://foo.bar.baz">http://foo.bar.baz</a></p></code></pre> </div> <div id="example-457" class="example" data-section="Autolinks"> <div class="examplenum"> <a href="#example-457">Example 457</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><http://foo.bar.baz?q=hello&id=22&boolean></code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="http://foo.bar.baz?q=hello&amp;id=22&amp;boolean">http://foo.bar.baz?q=hello&amp;id=22&amp;boolean</a></p></code></pre> </div> <div id="example-458" class="example" data-section="Autolinks"> <div class="examplenum"> <a href="#example-458">Example 458</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><irc://foo.bar:2233/baz></code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="irc://foo.bar:2233/baz">irc://foo.bar:2233/baz</a></p></code></pre> </div> <p>Uppercase is also fine:</p> <div id="example-459" class="example" data-section="Autolinks"> <div class="examplenum"> <a href="#example-459">Example 459</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><MAILTO:FOO@BAR.BAZ></code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="MAILTO:FOO@BAR.BAZ">MAILTO:FOO@BAR.BAZ</a></p></code></pre> </div> <p>Spaces are not allowed in autolinks:</p> <div id="example-460" class="example" data-section="Autolinks"> <div class="examplenum"> <a href="#example-460">Example 460</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><http://foo.bar/baz<span class="space"> </span>bim></code></pre> <pre class="html"><code><p>&lt;http://foo.bar/baz<span class="space"> </span>bim&gt;</p></code></pre> </div> <p>An <a id="email-autolink" href="#email-autolink" class="definition">email autolink</a> consists of <code><</code>, followed by an <a href="#email-address">email address</a>, followed by <code>></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 id="email-address" href="#email-address" class="definition">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.!#$%&'*+/=?^_`{|}~-]+@[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-461" class="example" data-section="Autolinks"> <div class="examplenum"> <a href="#example-461">Example 461</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><foo@bar.example.com></code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="mailto:foo@bar.example.com">foo@bar.example.com</a></p></code></pre> </div> <div id="example-462" class="example" data-section="Autolinks"> <div class="examplenum"> <a href="#example-462">Example 462</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><foo+special@Bar.baz-bar0.com></code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="mailto:foo+special@Bar.baz-bar0.com">foo+special@Bar.baz-bar0.com</a></p></code></pre> </div> <p>These are not autolinks:</p> <div id="example-463" class="example" data-section="Autolinks"> <div class="examplenum"> <a href="#example-463">Example 463</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><></code></pre> <pre class="html"><code><p>&lt;&gt;</p></code></pre> </div> <div id="example-464" class="example" data-section="Autolinks"> <div class="examplenum"> <a href="#example-464">Example 464</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><heck://bing.bong></code></pre> <pre class="html"><code><p>&lt;heck://bing.bong&gt;</p></code></pre> </div> <div id="example-465" class="example" data-section="Autolinks"> <div class="examplenum"> <a href="#example-465">Example 465</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><<span class="space"> </span>http://foo.bar<span class="space"> </span>></code></pre> <pre class="html"><code><p>&lt;<span class="space"> </span>http://foo.bar<span class="space"> </span>&gt;</p></code></pre> </div> <div id="example-466" class="example" data-section="Autolinks"> <div class="examplenum"> <a href="#example-466">Example 466</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><foo.bar.baz></code></pre> <pre class="html"><code><p>&lt;foo.bar.baz&gt;</p></code></pre> </div> <div id="example-467" class="example" data-section="Autolinks"> <div class="examplenum"> <a href="#example-467">Example 467</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><localhost:5001/foo></code></pre> <pre class="html"><code><p>&lt;localhost:5001/foo&gt;</p></code></pre> </div> <div id="example-468" class="example" data-section="Autolinks"> <div class="examplenum"> <a href="#example-468">Example 468</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>http://example.com</code></pre> <pre class="html"><code><p>http://example.com</p></code></pre> </div> <div id="example-469" class="example" data-section="Autolinks"> <div class="examplenum"> <a href="#example-469">Example 469</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>foo@bar.example.com</code></pre> <pre class="html"><code><p>foo@bar.example.com</p></code></pre> </div> <h2 id="raw-html"><span class="header-section-number">6.8</span> Raw HTML</h2> <p>Text between <code><</code> and <code>></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 id="tag-name" href="#tag-name" class="definition">tag name</a> consists of an ASCII letter followed by zero or more ASCII letters or digits.</p> <p>An <a id="attribute" href="#attribute" class="definition">attribute</a> consists of whitespace, an <a href="#attribute-name">attribute name</a>, and an optional <a href="#attribute-value-specification">attribute value specification</a>.</p> <p>An <a id="attribute-name" href="#attribute-name" class="definition">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 id="attribute-value-specification" href="#attribute-value-specification" class="definition">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 id="attribute-value" href="#attribute-value" class="definition">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 id="unquoted-attribute-value" href="#unquoted-attribute-value" class="definition">unquoted attribute value</a> is a nonempty string of characters not including spaces, <code>"</code>, <code>'</code>, <code>=</code>, <code><</code>, <code>></code>, or <code>`</code>.</p> <p>A <a id="single-quoted-attribute-value" href="#single-quoted-attribute-value" class="definition">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 id="double-quoted-attribute-value" href="#double-quoted-attribute-value" class="definition">double-quoted attribute value</a> consists of <code>"</code>, zero or more characters not including <code>"</code>, and a final <code>"</code>.</p> <p>An <a id="open-tag" href="#open-tag" class="definition">open tag</a> consists of a <code><</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>></code> character.</p> <p>A <a id="closing-tag" href="#closing-tag" class="definition">closing tag</a> consists of the string <code></</code>, a <a href="#tag-name">tag name</a>, optional whitespace, and the character <code>></code>.</p> <p>An <a id="html-comment" href="#html-comment" class="definition">HTML comment</a> consists of the string <code><!--</code>, a string of characters not including the string <code>--</code>, and the string <code>--></code>.</p> <p>A <a id="processing-instruction" href="#processing-instruction" class="definition">processing instruction</a> consists of the string <code><?</code>, a string of characters not including the string <code>?></code>, and the string <code>?></code>.</p> <p>A <a id="declaration" href="#declaration" class="definition">declaration</a> consists of the string <code><!</code>, a name consisting of one or more uppercase ASCII letters, whitespace, a string of characters not including the character <code>></code>, and the character <code>></code>.</p> <p>A <a id="cdata-section" href="#cdata-section" class="definition">CDATA section</a> consists of the string <code><![CDATA[</code>, a string of characters not including the string <code>]]></code>, and the string <code>]]></code>.</p> <p>An <a id="html-tag" href="#html-tag" class="definition">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-470" class="example" data-section="Raw HTML"> <div class="examplenum"> <a href="#example-470">Example 470</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><a><bab><c2c></code></pre> <pre class="html"><code><p><a><bab><c2c></p></code></pre> </div> <p>Empty elements:</p> <div id="example-471" class="example" data-section="Raw HTML"> <div class="examplenum"> <a href="#example-471">Example 471</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><a/><b2/></code></pre> <pre class="html"><code><p><a/><b2/></p></code></pre> </div> <p>Whitespace is allowed:</p> <div id="example-472" class="example" data-section="Raw HTML"> <div class="examplenum"> <a href="#example-472">Example 472</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><a<span class="space"> </span><span class="space"> </span>/><b2 data="foo"<span class="space"> </span>></code></pre> <pre class="html"><code><p><a<span class="space"> </span><span class="space"> </span>/><b2 data="foo"<span class="space"> </span>></p></code></pre> </div> <p>With attributes:</p> <div id="example-473" class="example" data-section="Raw HTML"> <div class="examplenum"> <a href="#example-473">Example 473</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><a<span class="space"> </span>foo="bar"<span class="space"> </span>bam<span class="space"> </span>=<span class="space"> </span>'baz<span class="space"> </span><em>"</em>' _boolean<span class="space"> </span>zoop:33=zoop:33<span class="space"> </span>/></code></pre> <pre class="html"><code><p><a<span class="space"> </span>foo="bar"<span class="space"> </span>bam<span class="space"> </span>=<span class="space"> </span>'baz<span class="space"> </span><em>"</em>' _boolean<span class="space"> </span>zoop:33=zoop:33<span class="space"> </span>/></p></code></pre> </div> <p>Illegal tag names, not parsed as HTML:</p> <div id="example-474" class="example" data-section="Raw HTML"> <div class="examplenum"> <a href="#example-474">Example 474</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><33><span class="space"> </span><__></code></pre> <pre class="html"><code><p>&lt;33&gt;<span class="space"> </span>&lt;__&gt;</p></code></pre> </div> <p>Illegal attribute names:</p> <div id="example-475" class="example" data-section="Raw HTML"> <div class="examplenum"> <a href="#example-475">Example 475</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><a<span class="space"> </span>h*#ref="hi"></code></pre> <pre class="html"><code><p>&lt;a<span class="space"> </span>h*#ref=&quot;hi&quot;&gt;</p></code></pre> </div> <p>Illegal attribute values:</p> <div id="example-476" class="example" data-section="Raw HTML"> <div class="examplenum"> <a href="#example-476">Example 476</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><a<span class="space"> </span>href="hi'><span class="space"> </span><a<span class="space"> </span>href=hi'></code></pre> <pre class="html"><code><p>&lt;a<span class="space"> </span>href=&quot;hi'&gt;<span class="space"> </span>&lt;a<span class="space"> </span>href=hi'&gt;</p></code></pre> </div> <p>Illegal whitespace:</p> <div id="example-477" class="example" data-section="Raw HTML"> <div class="examplenum"> <a href="#example-477">Example 477</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><<span class="space"> </span>a>< foo><bar/<span class="space"> </span>></code></pre> <pre class="html"><code><p>&lt;<span class="space"> </span>a&gt;&lt; foo&gt;&lt;bar/<span class="space"> </span>&gt;</p></code></pre> </div> <p>Missing whitespace:</p> <div id="example-478" class="example" data-section="Raw HTML"> <div class="examplenum"> <a href="#example-478">Example 478</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><a<span class="space"> </span>href='bar'title=title></code></pre> <pre class="html"><code><p>&lt;a<span class="space"> </span>href='bar'title=title&gt;</p></code></pre> </div> <p>Closing tags:</p> <div id="example-479" class="example" data-section="Raw HTML"> <div class="examplenum"> <a href="#example-479">Example 479</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code></a> </foo<span class="space"> </span>></code></pre> <pre class="html"><code><p></a> </foo<span class="space"> </span>></p></code></pre> </div> <p>Illegal attributes in closing tag:</p> <div id="example-480" class="example" data-section="Raw HTML"> <div class="examplenum"> <a href="#example-480">Example 480</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code></a<span class="space"> </span>href="foo"></code></pre> <pre class="html"><code><p>&lt;/a<span class="space"> </span>href=&quot;foo&quot;&gt;</p></code></pre> </div> <p>Comments:</p> <div id="example-481" class="example" data-section="Raw HTML"> <div class="examplenum"> <a href="#example-481">Example 481</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>foo<span class="space"> </span><!--<span class="space"> </span>this<span class="space"> </span>is<span class="space"> </span>a comment<span class="space"> </span>-<span class="space"> </span>with<span class="space"> </span>hyphen<span class="space"> </span>--></code></pre> <pre class="html"><code><p>foo<span class="space"> </span><!--<span class="space"> </span>this<span class="space"> </span>is<span class="space"> </span>a comment<span class="space"> </span>-<span class="space"> </span>with<span class="space"> </span>hyphen<span class="space"> </span>--></p></code></pre> </div> <div id="example-482" class="example" data-section="Raw HTML"> <div class="examplenum"> <a href="#example-482">Example 482</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>foo<span class="space"> </span><!--<span class="space"> </span>not<span class="space"> </span>a<span class="space"> </span>comment<span class="space"> </span>--<span class="space"> </span>two<span class="space"> </span>hyphens<span class="space"> </span>--></code></pre> <pre class="html"><code><p>foo<span class="space"> </span>&lt;!--<span class="space"> </span>not<span class="space"> </span>a<span class="space"> </span>comment<span class="space"> </span>--<span class="space"> </span>two<span class="space"> </span>hyphens<span class="space"> </span>--&gt;</p></code></pre> </div> <p>Processing instructions:</p> <div id="example-483" class="example" data-section="Raw HTML"> <div class="examplenum"> <a href="#example-483">Example 483</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>foo<span class="space"> </span><?php<span class="space"> </span>echo<span class="space"> </span>$a;<span class="space"> </span>?></code></pre> <pre class="html"><code><p>foo<span class="space"> </span><?php<span class="space"> </span>echo<span class="space"> </span>$a;<span class="space"> </span>?></p></code></pre> </div> <p>Declarations:</p> <div id="example-484" class="example" data-section="Raw HTML"> <div class="examplenum"> <a href="#example-484">Example 484</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>foo<span class="space"> </span><!ELEMENT<span class="space"> </span>br<span class="space"> </span>EMPTY></code></pre> <pre class="html"><code><p>foo<span class="space"> </span><!ELEMENT<span class="space"> </span>br<span class="space"> </span>EMPTY></p></code></pre> </div> <p>CDATA sections:</p> <div id="example-485" class="example" data-section="Raw HTML"> <div class="examplenum"> <a href="#example-485">Example 485</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>foo<span class="space"> </span><![CDATA[>&<]]></code></pre> <pre class="html"><code><p>foo<span class="space"> </span><![CDATA[>&<]]></p></code></pre> </div> <p>Entities are preserved in HTML attributes:</p> <div id="example-486" class="example" data-section="Raw HTML"> <div class="examplenum"> <a href="#example-486">Example 486</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><a<span class="space"> </span>href="&ouml;"></code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="&ouml;"></p></code></pre> </div> <p>Backslash escapes do not work in HTML attributes:</p> <div id="example-487" class="example" data-section="Raw HTML"> <div class="examplenum"> <a href="#example-487">Example 487</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><a<span class="space"> </span>href="\*"></code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="\*"></p></code></pre> </div> <div id="example-488" class="example" data-section="Raw HTML"> <div class="examplenum"> <a href="#example-488">Example 488</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><a<span class="space"> </span>href="\""></code></pre> <pre class="html"><code><p>&lt;a<span class="space"> </span>href=&quot;&quot;&quot;&gt;</p></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 and does not occur at the end of a block is parsed as a <a id="hard-line-break" href="#hard-line-break" class="definition">hard line break</a> (rendered in HTML as a <code><br /></code> tag):</p> <div id="example-489" class="example" data-section="Hard line breaks"> <div class="examplenum"> <a href="#example-489">Example 489</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>foo<span class="space"> </span><span class="space"> </span> baz</code></pre> <pre class="html"><code><p>foo<br<span class="space"> </span>/> baz</p></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-490" class="example" data-section="Hard line breaks"> <div class="examplenum"> <a href="#example-490">Example 490</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>foo\ baz</code></pre> <pre class="html"><code><p>foo<br<span class="space"> </span>/> baz</p></code></pre> </div> <p>More than two spaces can be used:</p> <div id="example-491" class="example" data-section="Hard line breaks"> <div class="examplenum"> <a href="#example-491">Example 491</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>foo<span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span> baz</code></pre> <pre class="html"><code><p>foo<br<span class="space"> </span>/> baz</p></code></pre> </div> <p>Leading spaces at the beginning of the next line are ignored:</p> <div id="example-492" class="example" data-section="Hard line breaks"> <div class="examplenum"> <a href="#example-492">Example 492</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>foo<span class="space"> </span><span class="space"> </span> <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>bar</code></pre> <pre class="html"><code><p>foo<br<span class="space"> </span>/> bar</p></code></pre> </div> <div id="example-493" class="example" data-section="Hard line breaks"> <div class="examplenum"> <a href="#example-493">Example 493</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>foo\ <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>bar</code></pre> <pre class="html"><code><p>foo<br<span class="space"> </span>/> bar</p></code></pre> </div> <p>Line breaks can occur inside emphasis, links, and other constructs that allow inline content:</p> <div id="example-494" class="example" data-section="Hard line breaks"> <div class="examplenum"> <a href="#example-494">Example 494</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>*foo<span class="space"> </span><span class="space"> </span> bar*</code></pre> <pre class="html"><code><p><em>foo<br<span class="space"> </span>/> bar</em></p></code></pre> </div> <div id="example-495" class="example" data-section="Hard line breaks"> <div class="examplenum"> <a href="#example-495">Example 495</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>*foo\ bar*</code></pre> <pre class="html"><code><p><em>foo<br<span class="space"> </span>/> bar</em></p></code></pre> </div> <p>Line breaks do not occur inside code spans</p> <div id="example-496" class="example" data-section="Hard line breaks"> <div class="examplenum"> <a href="#example-496">Example 496</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>`code<span class="space"> </span><span class="space"> </span> span`</code></pre> <pre class="html"><code><p><code>code<span class="space"> </span>span</code></p></code></pre> </div> <div id="example-497" class="example" data-section="Hard line breaks"> <div class="examplenum"> <a href="#example-497">Example 497</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>`code\ span`</code></pre> <pre class="html"><code><p><code>code\<span class="space"> </span>span</code></p></code></pre> </div> <p>or HTML tags:</p> <div id="example-498" class="example" data-section="Hard line breaks"> <div class="examplenum"> <a href="#example-498">Example 498</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><a<span class="space"> </span>href="foo<span class="space"> </span><span class="space"> </span> bar"></code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="foo<span class="space"> </span><span class="space"> </span> bar"></p></code></pre> </div> <div id="example-499" class="example" data-section="Hard line breaks"> <div class="examplenum"> <a href="#example-499">Example 499</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code><a<span class="space"> </span>href="foo\ bar"></code></pre> <pre class="html"><code><p><a<span class="space"> </span>href="foo\ bar"></p></code></pre> </div> <p>Hard line breaks are for separating inline content within a block. Neither syntax for hard line breaks works at the end of a paragraph or other block element:</p> <div id="example-500" class="example" data-section="Hard line breaks"> <div class="examplenum"> <a href="#example-500">Example 500</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>foo\</code></pre> <pre class="html"><code><p>foo\</p></code></pre> </div> <div id="example-501" class="example" data-section="Hard line breaks"> <div class="examplenum"> <a href="#example-501">Example 501</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>foo</code></pre> <pre class="html"><code><p>foo</p></code></pre> </div> <div id="example-502" class="example" data-section="Hard line breaks"> <div class="examplenum"> <a href="#example-502">Example 502</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>###<span class="space"> </span>foo\</code></pre> <pre class="html"><code><h3>foo\</h3></code></pre> </div> <div id="example-503" class="example" data-section="Hard line breaks"> <div class="examplenum"> <a href="#example-503">Example 503</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>###<span class="space"> </span>foo</code></pre> <pre class="html"><code><h3>foo</h3></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-504" class="example" data-section="Soft line breaks"> <div class="examplenum"> <a href="#example-504">Example 504</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>foo baz</code></pre> <pre class="html"><code><p>foo baz</p></code></pre> </div> <p>Spaces at the end of the line and beginning of the next line are removed:</p> <div id="example-505" class="example" data-section="Soft line breaks"> <div class="examplenum"> <a href="#example-505">Example 505</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>foo<span class="space"> </span> <span class="space"> </span>baz</code></pre> <pre class="html"><code><p>foo baz</p></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-506" class="example" data-section="Strings"> <div class="examplenum"> <a href="#example-506">Example 506</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>hello<span class="space"> </span>$.;'there</code></pre> <pre class="html"><code><p>hello<span class="space"> </span>$.;'there</p></code></pre> </div> <div id="example-507" class="example" data-section="Strings"> <div class="examplenum"> <a href="#example-507">Example 507</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>Foo<span class="space"> </span>χρῆν</code></pre> <pre class="html"><code><p>Foo<span class="space"> </span>χρῆν</p></code></pre> </div> <p>Internal spaces are preserved verbatim:</p> <div id="example-508" class="example" data-section="Strings"> <div class="examplenum"> <a href="#example-508">Example 508</a> <a class="dingus" title="open in interactive dingus">(interact)</a> </div> <pre class="markdown"><code>Multiple<span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>spaces</code></pre> <pre class="html"><code><p>Multiple<span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>spaces</p></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>-> document -> block_quote paragraph "Lorem ipsum dolor\nsit amet." -> list (type=bullet tight=true bullet_char=-) list_item paragraph "Qui *quodsi iracundia*" -> list_item -> paragraph "aliquando id"</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>> Lorem ipsum dolor sit amet. > - Qui *quodsi iracundia* > - aliquando id</code></pre> <p>At the outset, our document model is just</p> <pre class="tree"><code>-> document</code></pre> <p>The first line of our text,</p> <pre class="markdown"><code>> 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>-> document -> block_quote -> paragraph "Lorem ipsum dolor"</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>-> document -> block_quote -> paragraph "Lorem ipsum dolor\nsit amet."</code></pre> <p>The third line,</p> <pre class="markdown"><code>> - 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>-> document -> block_quote paragraph "Lorem ipsum dolor\nsit amet." -> list (type=bullet tight=true bullet_char=-) -> list_item -> paragraph "Qui *quodsi iracundia*"</code></pre> <p>The fourth line,</p> <pre class="markdown"><code>> - 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>-> document -> block_quote paragraph "Lorem ipsum dolor\nsit amet." -> list (type=bullet tight=true bullet_char=-) list_item paragraph "Qui *quodsi iracundia*" -> list_item -> paragraph "aliquando id"</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 "Lorem ipsum dolor" softbreak str "sit amet." list (type=bullet tight=true bullet_char=-) list_item paragraph str "Qui " emph str "quodsi iracundia" list_item paragraph str "aliquando id"</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>