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:nth-child(2) { clear:left; background-color: #D3E1E4; } div.example > pre:nth-child(3) { clear:right; 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('code.language-markdown').text(); $(this).find('a.dingus').click(function(f) { window.open('/dingus/?text=' + encodeURIComponent(t.replace(/→/g,"\t"))); }); }); $("code.language-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.22 (2015-08-23)</div> <div class="authors"> <span class="author">John MacFarlane</span> </div> <div class="license"> <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="Creative Commons BY-SA" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/80x15.png" /></a><br/><span style="display:none"><span xmlns:dct="http://purl.org/dc/terms/" href="http://purl.org/dc/dcmitype/Text" property="dct:title" rel="dct:type">CommonMark Spec</span> by <a xmlns:cc="http://creativecommons.org/ns#" href="http://spec.commonmark.org" property="cc:attributionName" rel="cc:attributionURL">John MacFarlane</a> is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/">Creative Commons Attribution-ShareAlike 4.0 International License</a>.</span> </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> <div id="TOC"> <ul> <li><a href="#introduction">1 Introduction</a> <ul> <li><a href="#what-is-markdown-">1.1 What is Markdown?</a></li> <li><a href="#why-is-a-spec-needed-">1.2 Why is a spec needed?</a></li> <li><a href="#about-this-document">1.3 About this document</a></li> </ul> </li> <li><a href="#preliminaries">2 Preliminaries</a> <ul> <li><a href="#characters-and-lines">2.1 Characters and lines</a></li> <li><a href="#tabs">2.2 Tabs</a></li> <li><a href="#insecure-characters">2.3 Insecure characters</a></li> </ul> </li> <li><a href="#blocks-and-inlines">3 Blocks and inlines</a> <ul> <li><a href="#precedence">3.1 Precedence</a></li> <li><a href="#container-blocks-and-leaf-blocks">3.2 Container blocks and leaf blocks</a></li> </ul> </li> <li><a href="#leaf-blocks">4 Leaf blocks</a> <ul> <li><a href="#horizontal-rules">4.1 Horizontal rules</a></li> <li><a href="#atx-headers">4.2 ATX headers</a></li> <li><a href="#setext-headers">4.3 Setext headers</a></li> <li><a href="#indented-code-blocks">4.4 Indented code blocks</a></li> <li><a href="#fenced-code-blocks">4.5 Fenced code blocks</a></li> <li><a href="#html-blocks">4.6 HTML blocks</a></li> <li><a href="#link-reference-definitions">4.7 Link reference definitions</a></li> <li><a href="#paragraphs">4.8 Paragraphs</a></li> <li><a href="#blank-lines">4.9 Blank lines</a></li> </ul> </li> <li><a href="#container-blocks">5 Container blocks</a> <ul> <li><a href="#block-quotes">5.1 Block quotes</a></li> <li><a href="#list-items">5.2 List items</a> <ul> <li><a href="#motivation">5.2.1 Motivation</a></li> </ul> </li> <li><a href="#lists">5.3 Lists</a></li> </ul> </li> <li><a href="#inlines">6 Inlines</a> <ul> <li><a href="#backslash-escapes">6.1 Backslash escapes</a></li> <li><a href="#entities">6.2 Entities</a></li> <li><a href="#code-spans">6.3 Code spans</a></li> <li><a href="#emphasis-and-strong-emphasis">6.4 Emphasis and strong emphasis</a></li> <li><a href="#links">6.5 Links</a></li> <li><a href="#images">6.6 Images</a></li> <li><a href="#autolinks">6.7 Autolinks</a></li> <li><a href="#raw-html">6.8 Raw HTML</a></li> <li><a href="#hard-line-breaks">6.9 Hard line breaks</a></li> <li><a href="#soft-line-breaks">6.10 Soft line breaks</a></li> <li><a href="#textual-content">6.11 Textual content</a></li> </ul> </li> <li><a href="#appendix-a-parsing-strategy"> Appendix: A parsing strategy</a> <ul> <li><a href="#overview"> Overview</a></li> <li><a href="#phase-1-block-structure"> Phase 1: block structure</a></li> <li><a href="#phase-2-inline-structure"> Phase 2: inline structure</a> <ul> <li><a href="#an-algorithm-for-parsing-nested-emphasis-and-links"> An algorithm for parsing nested emphasis and links</a> <ul> <li><a href="#-look-for-link-or-image-"> <em>look for link or image</em></a></li> <li><a href="#-process-emphasis-"> <em>process emphasis</em></a></li> </ul> </li> </ul> </li> </ul> </li> </ul> </div> <h1><a id="introduction"></a><span class="number">1</span> Introduction</h1> <h2><a id="what-is-markdown-"></a><span class="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><a id="why-is-a-spec-needed-"></a><span class="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> <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><code class="language-markdown">paragraph code? </code></pre> </li> <li> <p>What is the exact rule for determining when list items get wrapped in <code>&lt;p&gt;</code> tags? Can a list be partially “loose” and partially “tight”? What should we do with a list like this?</p> <pre><code class="language-markdown">1. one 2. two 3. three </code></pre> <p>Or this?</p> <pre><code class="language-markdown">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><code class="language-markdown"> 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><code class="language-markdown">* 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><code class="language-markdown">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><code class="language-markdown">[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><code class="language-markdown">*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><code class="language-markdown">- `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 section headers? (<code>Markdown.pl</code> does not allow this, but does allow blockquotes to include headers.)</p> <pre><code class="language-markdown">- # Heading </code></pre> </li> <li> <p>Can list items be empty?</p> <pre><code class="language-markdown">* a * * b </code></pre> </li> <li> <p>Can link references be defined inside block quotes or list items?</p> <pre><code class="language-markdown">&gt; Blockquote [foo]. &gt; &gt; [foo]: /url </code></pre> </li> <li> <p>If there are multiple definitions for the same reference, which takes precedence?</p> <pre><code class="language-markdown">[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><a id="about-this-document"></a><span class="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>spec_tests.py</code> can be used to run the tests against any Markdown program:</p> <pre><code>python test/spec_tests.py --spec spec.txt --program 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>tools/makespec.py</code> can be used to convert <code>spec.txt</code> into HTML or CommonMark (which can then be converted into other formats).</p> <p>In the examples, the <code>→</code> character is used to represent tabs.</p> <h1><a id="preliminaries"></a><span class="number">2</span> Preliminaries</h1> <h2><a id="characters-and-lines"></a><span class="number">2.1</span> Characters and lines</h2> <p>Any sequence of <a href="#character">characters</a> is a valid CommonMark document.</p> <p>A <a id="character" href="#character" class="definition">character</a> is a Unicode code point. Although some code points (for example, combining accents) do not correspond to characters in an intuitive sense, all code points count as characters for purposes of this spec.</p> <p>This spec does not specify an encoding; it thinks of lines as composed of <a href="#character">characters</a> rather than bytes. A conforming parser may be limited to a certain encoding.</p> <p>A <a id="line" href="#line" class="definition">line</a> is a sequence of zero or more <a href="#character">characters</a> other than newline (<code>U+000A</code>) or carriage return (<code>U+000D</code>), followed by a <a href="#line-ending">line ending</a> or by the end of file.</p> <p>A <a id="line-ending" href="#line-ending" class="definition">line ending</a> is a newline (<code>U+000A</code>), a carriage return (<code>U+000D</code>) not followed by a newline, or a carriage return and a following newline.</p> <p>A line containing no characters, or a line containing only spaces (<code>U+0020</code>) or tabs (<code>U+0009</code>), is called a <a id="blank-line" href="#blank-line" class="definition">blank line</a>.</p> <p>The following definitions of character classes will be used in this spec:</p> <p>A <a id="whitespace-character" href="#whitespace-character" class="definition">whitespace character</a> is a space (<code>U+0020</code>), tab (<code>U+0009</code>), newline (<code>U+000A</code>), line tabulation (<code>U+000B</code>), form feed (<code>U+000C</code>), or carriage return (<code>U+000D</code>).</p> <p><a id="whitespace" href="#whitespace" class="definition">Whitespace</a> is a sequence of one or more <a href="#whitespace-character">whitespace characters</a>.</p> <p>A <a id="unicode-whitespace-character" href="#unicode-whitespace-character" class="definition">Unicode whitespace character</a> is any code point in the Unicode <code>Zs</code> class, or a tab (<code>U+0009</code>), carriage return (<code>U+000D</code>), newline (<code>U+000A</code>), or form feed (<code>U+000C</code>).</p> <p><a id="unicode-whitespace" href="#unicode-whitespace" class="definition">Unicode whitespace</a> is a sequence of one or more <a href="#unicode-whitespace-character">Unicode whitespace characters</a>.</p> <p>A <a id="space" href="#space" class="definition">space</a> is <code>U+0020</code>.</p> <p>A <a id="non-whitespace-character" href="#non-whitespace-character" class="definition">non-whitespace character</a> is any character that is not a <a href="#whitespace-character">whitespace character</a>.</p> <p>An <a id="ascii-punctuation-character" href="#ascii-punctuation-character" class="definition">ASCII punctuation character</a> is <code>!</code>, <code>&quot;</code>, <code>#</code>, <code>$</code>, <code>%</code>, <code>&amp;</code>, <code>'</code>, <code>(</code>, <code>)</code>, <code>*</code>, <code>+</code>, <code>,</code>, <code>-</code>, <code>.</code>, <code>/</code>, <code>:</code>, <code>;</code>, <code>&lt;</code>, <code>=</code>, <code>&gt;</code>, <code>?</code>, <code>@</code>, <code>[</code>, <code>\</code>, <code>]</code>, <code>^</code>, <code>_</code>, <code>`</code>, <code>{</code>, <code>|</code>, <code>}</code>, or <code>~</code>.</p> <p>A <a id="punctuation-character" href="#punctuation-character" class="definition">punctuation character</a> is an <a href="#ascii-punctuation-character">ASCII punctuation character</a> or anything in the Unicode classes <code>Pc</code>, <code>Pd</code>, <code>Pe</code>, <code>Pf</code>, <code>Pi</code>, <code>Po</code>, or <code>Ps</code>.</p> <h2><a id="tabs"></a><span class="number">2.2</span> Tabs</h2> <p>Tabs in lines are not expanded to <a href="#space">spaces</a>. However, in contexts where indentation is significant for the document’s structure, tabs behave as if they were replaced by spaces with a tab stop of 4 characters.</p> <div class="example" id="example-1" data-section="Tabs"> <div class="examplenum"><a href="#example-1">Example 1</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">→foo→baz→→bim </code></pre> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;foo→baz→→bim &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <div class="example" id="example-2" data-section="Tabs"> <div class="examplenum"><a href="#example-2">Example 2</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><span class="space"> </span><span class="space"> </span>→foo→baz→→bim </code></pre> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;foo→baz→→bim &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <div class="example" id="example-3" data-section="Tabs"> <div class="examplenum"><a href="#example-3">Example 3</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><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><code class="language-html">&lt;pre&gt;&lt;code&gt;a→a ὐ→a &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <div class="example" id="example-4" data-section="Tabs"> <div class="examplenum"><a href="#example-4">Example 4</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><span class="space"> </span><span class="space"> </span>-<span class="space"> </span>foo →bar </code></pre> <pre><code class="language-html">&lt;ul&gt; &lt;li&gt; &lt;p&gt;foo&lt;/p&gt; &lt;p&gt;bar&lt;/p&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> </div> <div class="example" id="example-5" data-section="Tabs"> <div class="examplenum"><a href="#example-5">Example 5</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&gt;→foo→bar </code></pre> <pre><code class="language-html">&lt;blockquote&gt; &lt;p&gt;foo→bar&lt;/p&gt; &lt;/blockquote&gt; </code></pre> </div> <div class="example" id="example-6" data-section="Tabs"> <div class="examplenum"><a href="#example-6">Example 6</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>foo →bar </code></pre> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;foo bar &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <h2><a id="insecure-characters"></a><span class="number">2.3</span> Insecure characters</h2> <p>For security reasons, the Unicode character <code>U+0000</code> must be replaced with the replacement character (<code>U+FFFD</code>).</p> <h1><a id="blocks-and-inlines"></a><span class="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. Some blocks (like block quotes and list items) contain other blocks; others (like headers and paragraphs) contain <a id="inline" href="#inline" class="definition">inline</a> content—text, links, emphasized text, images, code, and so on.</p> <h2><a id="precedence"></a><span class="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 class="example" id="example-7" data-section="Precedence"> <div class="examplenum"><a href="#example-7">Example 7</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">-<span class="space"> </span>`one -<span class="space"> </span>two` </code></pre> <pre><code class="language-html">&lt;ul&gt; &lt;li&gt;`one&lt;/li&gt; &lt;li&gt;two`&lt;/li&gt; &lt;/ul&gt; </code></pre> </div> <p>This means that parsing can proceed in two steps: first, the block structure of the document can be discerned; second, text lines inside paragraphs, headers, and other block constructs can be parsed for inline structure. The second step requires information about link reference definitions that will be available only at the end of the first step. Note that the first step requires processing lines in sequence, but the second can be parallelized, since the inline parsing of one block element does not affect the inline parsing of any other.</p> <h2><a id="container-blocks-and-leaf-blocks"></a><span class="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><a id="leaf-blocks"></a><span class="number">4</span> Leaf blocks</h1> <p>This section describes the different kinds of leaf block that make up a Markdown document.</p> <h2><a id="horizontal-rules"></a><span class="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 class="example" id="example-8" data-section="Horizontal rules"> <div class="examplenum"><a href="#example-8">Example 8</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">*** --- ___ </code></pre> <pre><code class="language-html">&lt;hr<span class="space"> </span>/&gt; &lt;hr<span class="space"> </span>/&gt; &lt;hr<span class="space"> </span>/&gt; </code></pre> </div> <p>Wrong characters:</p> <div class="example" id="example-9" data-section="Horizontal rules"> <div class="examplenum"><a href="#example-9">Example 9</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">+++ </code></pre> <pre><code class="language-html">&lt;p&gt;+++&lt;/p&gt; </code></pre> </div> <div class="example" id="example-10" data-section="Horizontal rules"> <div class="examplenum"><a href="#example-10">Example 10</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">=== </code></pre> <pre><code class="language-html">&lt;p&gt;===&lt;/p&gt; </code></pre> </div> <p>Not enough characters:</p> <div class="example" id="example-11" data-section="Horizontal rules"> <div class="examplenum"><a href="#example-11">Example 11</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">-- ** __ </code></pre> <pre><code class="language-html">&lt;p&gt;-- ** __&lt;/p&gt; </code></pre> </div> <p>One to three spaces indent are allowed:</p> <div class="example" id="example-12" data-section="Horizontal rules"> <div class="examplenum"><a href="#example-12">Example 12</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><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><code class="language-html">&lt;hr<span class="space"> </span>/&gt; &lt;hr<span class="space"> </span>/&gt; &lt;hr<span class="space"> </span>/&gt; </code></pre> </div> <p>Four spaces is too many:</p> <div class="example" id="example-13" data-section="Horizontal rules"> <div class="examplenum"><a href="#example-13">Example 13</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>*** </code></pre> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;*** &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <div class="example" id="example-14" data-section="Horizontal rules"> <div class="examplenum"><a href="#example-14">Example 14</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">Foo <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>*** </code></pre> <pre><code class="language-html">&lt;p&gt;Foo ***&lt;/p&gt; </code></pre> </div> <p>More than three characters may be used:</p> <div class="example" id="example-15" data-section="Horizontal rules"> <div class="examplenum"><a href="#example-15">Example 15</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">_____________________________________ </code></pre> <pre><code class="language-html">&lt;hr<span class="space"> </span>/&gt; </code></pre> </div> <p>Spaces are allowed between the characters:</p> <div class="example" id="example-16" data-section="Horizontal rules"> <div class="examplenum"><a href="#example-16">Example 16</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><span class="space"> </span>-<span class="space"> </span>-<span class="space"> </span>- </code></pre> <pre><code class="language-html">&lt;hr<span class="space"> </span>/&gt; </code></pre> </div> <div class="example" id="example-17" data-section="Horizontal rules"> <div class="examplenum"><a href="#example-17">Example 17</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><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><code class="language-html">&lt;hr<span class="space"> </span>/&gt; </code></pre> </div> <div class="example" id="example-18" data-section="Horizontal rules"> <div class="examplenum"><a href="#example-18">Example 18</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">-<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><code class="language-html">&lt;hr<span class="space"> </span>/&gt; </code></pre> </div> <p>Spaces are allowed at the end:</p> <div class="example" id="example-19" data-section="Horizontal rules"> <div class="examplenum"><a href="#example-19">Example 19</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">-<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><code class="language-html">&lt;hr<span class="space"> </span>/&gt; </code></pre> </div> <p>However, no other characters may occur in the line:</p> <div class="example" id="example-20" data-section="Horizontal rules"> <div class="examplenum"><a href="#example-20">Example 20</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">_<span class="space"> </span>_<span class="space"> </span>_<span class="space"> </span>_<span class="space"> </span>a a------ ---a--- </code></pre> <pre><code class="language-html">&lt;p&gt;_<span class="space"> </span>_<span class="space"> </span>_<span class="space"> </span>_<span class="space"> </span>a&lt;/p&gt; &lt;p&gt;a------&lt;/p&gt; &lt;p&gt;---a---&lt;/p&gt; </code></pre> </div> <p>It is required that all of the <a href="#non-whitespace-character">non-whitespace characters</a> be the same. So, this is not a horizontal rule:</p> <div class="example" id="example-21" data-section="Horizontal rules"> <div class="examplenum"><a href="#example-21">Example 21</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><span class="space"> </span>*-* </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;-&lt;/em&gt;&lt;/p&gt; </code></pre> </div> <p>Horizontal rules do not need blank lines before or after:</p> <div class="example" id="example-22" data-section="Horizontal rules"> <div class="examplenum"><a href="#example-22">Example 22</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">-<span class="space"> </span>foo *** -<span class="space"> </span>bar </code></pre> <pre><code class="language-html">&lt;ul&gt; &lt;li&gt;foo&lt;/li&gt; &lt;/ul&gt; &lt;hr<span class="space"> </span>/&gt; &lt;ul&gt; &lt;li&gt;bar&lt;/li&gt; &lt;/ul&gt; </code></pre> </div> <p>Horizontal rules can interrupt a paragraph:</p> <div class="example" id="example-23" data-section="Horizontal rules"> <div class="examplenum"><a href="#example-23">Example 23</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">Foo *** bar </code></pre> <pre><code class="language-html">&lt;p&gt;Foo&lt;/p&gt; &lt;hr<span class="space"> </span>/&gt; &lt;p&gt;bar&lt;/p&gt; </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 class="example" id="example-24" data-section="Horizontal rules"> <div class="examplenum"><a href="#example-24">Example 24</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">Foo --- bar </code></pre> <pre><code class="language-html">&lt;h2&gt;Foo&lt;/h2&gt; &lt;p&gt;bar&lt;/p&gt; </code></pre> </div> <p>When both a horizontal rule and a list item are possible interpretations of a line, the horizontal rule takes precedence:</p> <div class="example" id="example-25" data-section="Horizontal rules"> <div class="examplenum"><a href="#example-25">Example 25</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">*<span class="space"> </span>Foo *<span class="space"> </span>*<span class="space"> </span>* *<span class="space"> </span>Bar </code></pre> <pre><code class="language-html">&lt;ul&gt; &lt;li&gt;Foo&lt;/li&gt; &lt;/ul&gt; &lt;hr<span class="space"> </span>/&gt; &lt;ul&gt; &lt;li&gt;Bar&lt;/li&gt; &lt;/ul&gt; </code></pre> </div> <p>If you want a horizontal rule in a list item, use a different bullet:</p> <div class="example" id="example-26" data-section="Horizontal rules"> <div class="examplenum"><a href="#example-26">Example 26</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">-<span class="space"> </span>Foo -<span class="space"> </span>*<span class="space"> </span>*<span class="space"> </span>* </code></pre> <pre><code class="language-html">&lt;ul&gt; &lt;li&gt;Foo&lt;/li&gt; &lt;li&gt; &lt;hr<span class="space"> </span>/&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> </div> <h2><a id="atx-headers"></a><span class="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 unescaped <code>#</code> characters. The opening sequence of <code>#</code> characters cannot be followed directly by a <a href="#non-whitespace-character">non-whitespace character</a>. The optional closing sequence of <code>#</code>s must be preceded by a <a href="#space">space</a> 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 class="example" id="example-27" data-section="ATX headers"> <div class="examplenum"><a href="#example-27">Example 27</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">#<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><code class="language-html">&lt;h1&gt;foo&lt;/h1&gt; &lt;h2&gt;foo&lt;/h2&gt; &lt;h3&gt;foo&lt;/h3&gt; &lt;h4&gt;foo&lt;/h4&gt; &lt;h5&gt;foo&lt;/h5&gt; &lt;h6&gt;foo&lt;/h6&gt; </code></pre> </div> <p>More than six <code>#</code> characters is not a header:</p> <div class="example" id="example-28" data-section="ATX headers"> <div class="examplenum"><a href="#example-28">Example 28</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">#######<span class="space"> </span>foo </code></pre> <pre><code class="language-html">&lt;p&gt;#######<span class="space"> </span>foo&lt;/p&gt; </code></pre> </div> <p>At least one space is required between the <code>#</code> characters and the header’s contents, unless the header is empty. 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 class="example" id="example-29" data-section="ATX headers"> <div class="examplenum"><a href="#example-29">Example 29</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">#5<span class="space"> </span>bolt #foobar </code></pre> <pre><code class="language-html">&lt;p&gt;#5<span class="space"> </span>bolt&lt;/p&gt; &lt;p&gt;#foobar&lt;/p&gt; </code></pre> </div> <p>This is not a header, because the first <code>#</code> is escaped:</p> <div class="example" id="example-30" data-section="ATX headers"> <div class="examplenum"><a href="#example-30">Example 30</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">\##<span class="space"> </span>foo </code></pre> <pre><code class="language-html">&lt;p&gt;##<span class="space"> </span>foo&lt;/p&gt; </code></pre> </div> <p>Contents are parsed as inlines:</p> <div class="example" id="example-31" data-section="ATX headers"> <div class="examplenum"><a href="#example-31">Example 31</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">#<span class="space"> </span>foo<span class="space"> </span>*bar*<span class="space"> </span>\*baz\* </code></pre> <pre><code class="language-html">&lt;h1&gt;foo<span class="space"> </span>&lt;em&gt;bar&lt;/em&gt;<span class="space"> </span>*baz*&lt;/h1&gt; </code></pre> </div> <p>Leading and trailing blanks are ignored in parsing inline content:</p> <div class="example" id="example-32" data-section="ATX headers"> <div class="examplenum"><a href="#example-32">Example 32</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">#<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><code class="language-html">&lt;h1&gt;foo&lt;/h1&gt; </code></pre> </div> <p>One to three spaces indentation are allowed:</p> <div class="example" id="example-33" data-section="ATX headers"> <div class="examplenum"><a href="#example-33">Example 33</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><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><code class="language-html">&lt;h3&gt;foo&lt;/h3&gt; &lt;h2&gt;foo&lt;/h2&gt; &lt;h1&gt;foo&lt;/h1&gt; </code></pre> </div> <p>Four spaces are too much:</p> <div class="example" id="example-34" data-section="ATX headers"> <div class="examplenum"><a href="#example-34">Example 34</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>#<span class="space"> </span>foo </code></pre> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;#<span class="space"> </span>foo &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <div class="example" id="example-35" data-section="ATX headers"> <div class="examplenum"><a href="#example-35">Example 35</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">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><code class="language-html">&lt;p&gt;foo #<span class="space"> </span>bar&lt;/p&gt; </code></pre> </div> <p>A closing sequence of <code>#</code> characters is optional:</p> <div class="example" id="example-36" data-section="ATX headers"> <div class="examplenum"><a href="#example-36">Example 36</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">##<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><code class="language-html">&lt;h2&gt;foo&lt;/h2&gt; &lt;h3&gt;bar&lt;/h3&gt; </code></pre> </div> <p>It need not be the same length as the opening sequence:</p> <div class="example" id="example-37" data-section="ATX headers"> <div class="examplenum"><a href="#example-37">Example 37</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">#<span class="space"> </span>foo<span class="space"> </span>################################## #####<span class="space"> </span>foo<span class="space"> </span>## </code></pre> <pre><code class="language-html">&lt;h1&gt;foo&lt;/h1&gt; &lt;h5&gt;foo&lt;/h5&gt; </code></pre> </div> <p>Spaces are allowed after the closing sequence:</p> <div class="example" id="example-38" data-section="ATX headers"> <div class="examplenum"><a href="#example-38">Example 38</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">###<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><code class="language-html">&lt;h3&gt;foo&lt;/h3&gt; </code></pre> </div> <p>A sequence of <code>#</code> characters with anything but <a href="#space">spaces</a> following it is not a closing sequence, but counts as part of the contents of the header:</p> <div class="example" id="example-39" data-section="ATX headers"> <div class="examplenum"><a href="#example-39">Example 39</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">###<span class="space"> </span>foo<span class="space"> </span>###<span class="space"> </span>b </code></pre> <pre><code class="language-html">&lt;h3&gt;foo<span class="space"> </span>###<span class="space"> </span>b&lt;/h3&gt; </code></pre> </div> <p>The closing sequence must be preceded by a space:</p> <div class="example" id="example-40" data-section="ATX headers"> <div class="examplenum"><a href="#example-40">Example 40</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">#<span class="space"> </span>foo# </code></pre> <pre><code class="language-html">&lt;h1&gt;foo#&lt;/h1&gt; </code></pre> </div> <p>Backslash-escaped <code>#</code> characters do not count as part of the closing sequence:</p> <div class="example" id="example-41" data-section="ATX headers"> <div class="examplenum"><a href="#example-41">Example 41</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">###<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><code class="language-html">&lt;h3&gt;foo<span class="space"> </span>###&lt;/h3&gt; &lt;h2&gt;foo<span class="space"> </span>###&lt;/h2&gt; &lt;h1&gt;foo<span class="space"> </span>#&lt;/h1&gt; </code></pre> </div> <p>ATX headers need not be separated from surrounding content by blank lines, and they can interrupt paragraphs:</p> <div class="example" id="example-42" data-section="ATX headers"> <div class="examplenum"><a href="#example-42">Example 42</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">**** ##<span class="space"> </span>foo **** </code></pre> <pre><code class="language-html">&lt;hr<span class="space"> </span>/&gt; &lt;h2&gt;foo&lt;/h2&gt; &lt;hr<span class="space"> </span>/&gt; </code></pre> </div> <div class="example" id="example-43" data-section="ATX headers"> <div class="examplenum"><a href="#example-43">Example 43</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">Foo<span class="space"> </span>bar #<span class="space"> </span>baz Bar<span class="space"> </span>foo </code></pre> <pre><code class="language-html">&lt;p&gt;Foo<span class="space"> </span>bar&lt;/p&gt; &lt;h1&gt;baz&lt;/h1&gt; &lt;p&gt;Bar<span class="space"> </span>foo&lt;/p&gt; </code></pre> </div> <p>ATX headers can be empty:</p> <div class="example" id="example-44" data-section="ATX headers"> <div class="examplenum"><a href="#example-44">Example 44</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">##<span class="space"> </span> # ###<span class="space"> </span>### </code></pre> <pre><code class="language-html">&lt;h2&gt;&lt;/h2&gt; &lt;h1&gt;&lt;/h1&gt; &lt;h3&gt;&lt;/h3&gt; </code></pre> </div> <h2><a id="setext-headers"></a><span class="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 <a href="#non-whitespace-character">non-whitespace character</a>, 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 interpretable as a <a href="#code-fence">code fence</a>, <a href="#atx-headers">ATX header</a>, <a href="#block-quotes">block quote</a>, <a href="#horizontal-rules">horizontal rule</a>, <a href="#list-items">list item</a>, or <a href="#html-blocks">HTML block</a>.</p> <p>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. If a line containing a single <code>-</code> can be interpreted as an empty <a href="#list-items">list items</a>, it should be interpreted this way and not as a <a href="#setext-header-underline">setext header underline</a>.</p> <p>The header is a level 1 header if <code>=</code> characters are used in the <a href="#setext-header-underline">setext header underline</a>, 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 class="example" id="example-45" data-section="Setext headers"> <div class="examplenum"><a href="#example-45">Example 45</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">Foo<span class="space"> </span>*bar* ========= Foo<span class="space"> </span>*bar* --------- </code></pre> <pre><code class="language-html">&lt;h1&gt;Foo<span class="space"> </span>&lt;em&gt;bar&lt;/em&gt;&lt;/h1&gt; &lt;h2&gt;Foo<span class="space"> </span>&lt;em&gt;bar&lt;/em&gt;&lt;/h2&gt; </code></pre> </div> <p>The underlining can be any length:</p> <div class="example" id="example-46" data-section="Setext headers"> <div class="examplenum"><a href="#example-46">Example 46</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">Foo ------------------------- Foo = </code></pre> <pre><code class="language-html">&lt;h2&gt;Foo&lt;/h2&gt; &lt;h1&gt;Foo&lt;/h1&gt; </code></pre> </div> <p>The header content can be indented up to three spaces, and need not line up with the underlining:</p> <div class="example" id="example-47" data-section="Setext headers"> <div class="examplenum"><a href="#example-47">Example 47</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><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><code class="language-html">&lt;h2&gt;Foo&lt;/h2&gt; &lt;h2&gt;Foo&lt;/h2&gt; &lt;h1&gt;Foo&lt;/h1&gt; </code></pre> </div> <p>Four spaces indent is too much:</p> <div class="example" id="example-48" data-section="Setext headers"> <div class="examplenum"><a href="#example-48">Example 48</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><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><code class="language-html">&lt;pre&gt;&lt;code&gt;Foo --- Foo &lt;/code&gt;&lt;/pre&gt; &lt;hr<span class="space"> </span>/&gt; </code></pre> </div> <p>The setext header underline can be indented up to three spaces, and may have trailing spaces:</p> <div class="example" id="example-49" data-section="Setext headers"> <div class="examplenum"><a href="#example-49">Example 49</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">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><code class="language-html">&lt;h2&gt;Foo&lt;/h2&gt; </code></pre> </div> <p>Four spaces is too much:</p> <div class="example" id="example-50" data-section="Setext headers"> <div class="examplenum"><a href="#example-50">Example 50</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">Foo <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>--- </code></pre> <pre><code class="language-html">&lt;p&gt;Foo ---&lt;/p&gt; </code></pre> </div> <p>The setext header underline cannot contain internal spaces:</p> <div class="example" id="example-51" data-section="Setext headers"> <div class="examplenum"><a href="#example-51">Example 51</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">Foo =<span class="space"> </span>= Foo ---<span class="space"> </span>- </code></pre> <pre><code class="language-html">&lt;p&gt;Foo =<span class="space"> </span>=&lt;/p&gt; &lt;p&gt;Foo&lt;/p&gt; &lt;hr<span class="space"> </span>/&gt; </code></pre> </div> <p>Trailing spaces in the content line do not cause a line break:</p> <div class="example" id="example-52" data-section="Setext headers"> <div class="examplenum"><a href="#example-52">Example 52</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">Foo<span class="space"> </span><span class="space"> </span> ----- </code></pre> <pre><code class="language-html">&lt;h2&gt;Foo&lt;/h2&gt; </code></pre> </div> <p>Nor does a backslash at the end:</p> <div class="example" id="example-53" data-section="Setext headers"> <div class="examplenum"><a href="#example-53">Example 53</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">Foo\ ---- </code></pre> <pre><code class="language-html">&lt;h2&gt;Foo\&lt;/h2&gt; </code></pre> </div> <p>Since indicators of block structure take precedence over indicators of inline structure, the following are setext headers:</p> <div class="example" id="example-54" data-section="Setext headers"> <div class="examplenum"><a href="#example-54">Example 54</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">`Foo ---- ` &lt;a<span class="space"> </span>title=&quot;a<span class="space"> </span>lot --- of<span class="space"> </span>dashes&quot;/&gt; </code></pre> <pre><code class="language-html">&lt;h2&gt;`Foo&lt;/h2&gt; &lt;p&gt;`&lt;/p&gt; &lt;h2&gt;&amp;lt;a<span class="space"> </span>title=&amp;quot;a<span class="space"> </span>lot&lt;/h2&gt; &lt;p&gt;of<span class="space"> </span>dashes&amp;quot;/&amp;gt;&lt;/p&gt; </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 class="example" id="example-55" data-section="Setext headers"> <div class="examplenum"><a href="#example-55">Example 55</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&gt;<span class="space"> </span>Foo --- </code></pre> <pre><code class="language-html">&lt;blockquote&gt; &lt;p&gt;Foo&lt;/p&gt; &lt;/blockquote&gt; &lt;hr<span class="space"> </span>/&gt; </code></pre> </div> <div class="example" id="example-56" data-section="Setext headers"> <div class="examplenum"><a href="#example-56">Example 56</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">-<span class="space"> </span>Foo --- </code></pre> <pre><code class="language-html">&lt;ul&gt; &lt;li&gt;Foo&lt;/li&gt; &lt;/ul&gt; &lt;hr<span class="space"> </span>/&gt; </code></pre> </div> <p>A setext header cannot interrupt a paragraph:</p> <div class="example" id="example-57" data-section="Setext headers"> <div class="examplenum"><a href="#example-57">Example 57</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">Foo Bar --- Foo Bar === </code></pre> <pre><code class="language-html">&lt;p&gt;Foo Bar&lt;/p&gt; &lt;hr<span class="space"> </span>/&gt; &lt;p&gt;Foo Bar ===&lt;/p&gt; </code></pre> </div> <p>But in general a blank line is not required before or after:</p> <div class="example" id="example-58" data-section="Setext headers"> <div class="examplenum"><a href="#example-58">Example 58</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">--- Foo --- Bar --- Baz </code></pre> <pre><code class="language-html">&lt;hr<span class="space"> </span>/&gt; &lt;h2&gt;Foo&lt;/h2&gt; &lt;h2&gt;Bar&lt;/h2&gt; &lt;p&gt;Baz&lt;/p&gt; </code></pre> </div> <p>Setext headers cannot be empty:</p> <div class="example" id="example-59" data-section="Setext headers"> <div class="examplenum"><a href="#example-59">Example 59</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"> ==== </code></pre> <pre><code class="language-html">&lt;p&gt;====&lt;/p&gt; </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 class="example" id="example-60" data-section="Setext headers"> <div class="examplenum"><a href="#example-60">Example 60</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">--- --- </code></pre> <pre><code class="language-html">&lt;hr<span class="space"> </span>/&gt; &lt;hr<span class="space"> </span>/&gt; </code></pre> </div> <div class="example" id="example-61" data-section="Setext headers"> <div class="examplenum"><a href="#example-61">Example 61</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">-<span class="space"> </span>foo ----- </code></pre> <pre><code class="language-html">&lt;ul&gt; &lt;li&gt;foo&lt;/li&gt; &lt;/ul&gt; &lt;hr<span class="space"> </span>/&gt; </code></pre> </div> <div class="example" id="example-62" data-section="Setext headers"> <div class="examplenum"><a href="#example-62">Example 62</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>foo --- </code></pre> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;foo &lt;/code&gt;&lt;/pre&gt; &lt;hr<span class="space"> </span>/&gt; </code></pre> </div> <div class="example" id="example-63" data-section="Setext headers"> <div class="examplenum"><a href="#example-63">Example 63</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&gt;<span class="space"> </span>foo ----- </code></pre> <pre><code class="language-html">&lt;blockquote&gt; &lt;p&gt;foo&lt;/p&gt; &lt;/blockquote&gt; &lt;hr<span class="space"> </span>/&gt; </code></pre> </div> <p>If you want a header with <code>&gt; foo</code> as its literal text, you can use backslash escapes:</p> <div class="example" id="example-64" data-section="Setext headers"> <div class="examplenum"><a href="#example-64">Example 64</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">\&gt;<span class="space"> </span>foo ------ </code></pre> <pre><code class="language-html">&lt;h2&gt;&amp;gt;<span class="space"> </span>foo&lt;/h2&gt; </code></pre> </div> <h2><a id="indented-code-blocks"></a><span class="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. The contents of the code block are the literal contents of the lines, including trailing <a href="#line-ending">line endings</a>, minus four spaces of indentation. An indented code block has no <a href="#info-string">info string</a>.</p> <p>An indented code block cannot interrupt a paragraph, so there must be a blank line between a paragraph and a following indented code block. (A blank line is not needed, however, between a code block and a following paragraph.)</p> <div class="example" id="example-65" data-section="Indented code blocks"> <div class="examplenum"><a href="#example-65">Example 65</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><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><code class="language-html">&lt;pre&gt;&lt;code&gt;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 &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <p>If there is any ambiguity between an interpretation of indentation as a code block and as indicating that material belongs to a <a href="#list-items">list item</a>, the list item interpretation takes precedence:</p> <div class="example" id="example-66" data-section="Indented code blocks"> <div class="examplenum"><a href="#example-66">Example 66</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><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><code class="language-html">&lt;ul&gt; &lt;li&gt; &lt;p&gt;foo&lt;/p&gt; &lt;p&gt;bar&lt;/p&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> </div> <div class="example" id="example-67" data-section="Indented code blocks"> <div class="examplenum"><a href="#example-67">Example 67</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">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>bar </code></pre> <pre><code class="language-html">&lt;ol&gt; &lt;li&gt; &lt;p&gt;foo&lt;/p&gt; &lt;ul&gt; &lt;li&gt;bar&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ol&gt; </code></pre> </div> <p>The contents of a code block are literal text, and do not get parsed as Markdown:</p> <div class="example" id="example-68" data-section="Indented code blocks"> <div class="examplenum"><a href="#example-68">Example 68</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>&lt;a/&gt; <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><code class="language-html">&lt;pre&gt;&lt;code&gt;&amp;lt;a/&amp;gt; *hi* -<span class="space"> </span>one &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <p>Here we have three chunks separated by blank lines:</p> <div class="example" id="example-69" data-section="Indented code blocks"> <div class="examplenum"><a href="#example-69">Example 69</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><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><code class="language-html">&lt;pre&gt;&lt;code&gt;chunk1 chunk2 chunk3 &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <p>Any initial spaces beyond four will be included in the content, even in interior blank lines:</p> <div class="example" id="example-70" data-section="Indented code blocks"> <div class="examplenum"><a href="#example-70">Example 70</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><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><code class="language-html">&lt;pre&gt;&lt;code&gt;chunk1 <span class="space"> </span><span class="space"> </span> <span class="space"> </span><span class="space"> </span>chunk2 &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <p>An indented code block cannot interrupt a paragraph. (This allows hanging indents and the like.)</p> <div class="example" id="example-71" data-section="Indented code blocks"> <div class="examplenum"><a href="#example-71">Example 71</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">Foo <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>bar </code></pre> <pre><code class="language-html">&lt;p&gt;Foo bar&lt;/p&gt; </code></pre> </div> <p>However, any non-blank line with fewer than four leading spaces ends the code block immediately. So a paragraph may occur immediately after indented code:</p> <div class="example" id="example-72" data-section="Indented code blocks"> <div class="examplenum"><a href="#example-72">Example 72</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>foo bar </code></pre> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;foo &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;bar&lt;/p&gt; </code></pre> </div> <p>And indented code can occur immediately before and after other kinds of blocks:</p> <div class="example" id="example-73" data-section="Indented code blocks"> <div class="examplenum"><a href="#example-73">Example 73</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">#<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><code class="language-html">&lt;h1&gt;Header&lt;/h1&gt; &lt;pre&gt;&lt;code&gt;foo &lt;/code&gt;&lt;/pre&gt; &lt;h2&gt;Header&lt;/h2&gt; &lt;pre&gt;&lt;code&gt;foo &lt;/code&gt;&lt;/pre&gt; &lt;hr<span class="space"> </span>/&gt; </code></pre> </div> <p>The first line can be indented more than four spaces:</p> <div class="example" id="example-74" data-section="Indented code blocks"> <div class="examplenum"><a href="#example-74">Example 74</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><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><code class="language-html">&lt;pre&gt;&lt;code&gt;<span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>foo bar &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <p>Blank lines preceding or following an indented code block are not included in it:</p> <div class="example" id="example-75" data-section="Indented code blocks"> <div class="examplenum"><a href="#example-75">Example 75</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"> <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><code class="language-html">&lt;pre&gt;&lt;code&gt;foo &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <p>Trailing spaces are included in the code block’s content:</p> <div class="example" id="example-76" data-section="Indented code blocks"> <div class="examplenum"><a href="#example-76">Example 76</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><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><code class="language-html">&lt;pre&gt;&lt;code&gt;foo<span class="space"> </span><span class="space"> </span> &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <h2><a id="fenced-code-blocks"></a><span class="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 <a href="#info-string">info string</a> 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 <a href="#info-string">info string</a> 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 <a href="#info-string">info string</a>.</p> <p>Here is a simple example with backticks:</p> <div class="example" id="example-77" data-section="Fenced code blocks"> <div class="examplenum"><a href="#example-77">Example 77</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">``` &lt; <span class="space"> </span>&gt; ``` </code></pre> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;&amp;lt; <span class="space"> </span>&amp;gt; &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <p>With tildes:</p> <div class="example" id="example-78" data-section="Fenced code blocks"> <div class="examplenum"><a href="#example-78">Example 78</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">~~~ &lt; <span class="space"> </span>&gt; ~~~ </code></pre> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;&amp;lt; <span class="space"> </span>&amp;gt; &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <p>The closing code fence must use the same character as the opening fence:</p> <div class="example" id="example-79" data-section="Fenced code blocks"> <div class="examplenum"><a href="#example-79">Example 79</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">``` aaa ~~~ ``` </code></pre> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;aaa ~~~ &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <div class="example" id="example-80" data-section="Fenced code blocks"> <div class="examplenum"><a href="#example-80">Example 80</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">~~~ aaa ``` ~~~ </code></pre> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;aaa ``` &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <p>The closing code fence must be at least as long as the opening fence:</p> <div class="example" id="example-81" data-section="Fenced code blocks"> <div class="examplenum"><a href="#example-81">Example 81</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">```` aaa ``` `````` </code></pre> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;aaa ``` &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <div class="example" id="example-82" data-section="Fenced code blocks"> <div class="examplenum"><a href="#example-82">Example 82</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">~~~~ aaa ~~~ ~~~~ </code></pre> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;aaa ~~~ &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <p>Unclosed code blocks are closed by the end of the document (or the enclosing [block quote] or [list item]):</p> <div class="example" id="example-83" data-section="Fenced code blocks"> <div class="examplenum"><a href="#example-83">Example 83</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">``` </code></pre> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;&lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <div class="example" id="example-84" data-section="Fenced code blocks"> <div class="examplenum"><a href="#example-84">Example 84</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">````` ``` aaa </code></pre> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt; ``` aaa &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <div class="example" id="example-85" data-section="Fenced code blocks"> <div class="examplenum"><a href="#example-85">Example 85</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&gt;<span class="space"> </span>``` &gt;<span class="space"> </span>aaa bbb </code></pre> <pre><code class="language-html">&lt;blockquote&gt; &lt;pre&gt;&lt;code&gt;aaa &lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;p&gt;bbb&lt;/p&gt; </code></pre> </div> <p>A code block can have all empty lines as its content:</p> <div class="example" id="example-86" data-section="Fenced code blocks"> <div class="examplenum"><a href="#example-86">Example 86</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">``` <span class="space"> </span><span class="space"> </span> ``` </code></pre> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt; <span class="space"> </span><span class="space"> </span> &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <p>A code block can be empty:</p> <div class="example" id="example-87" data-section="Fenced code blocks"> <div class="examplenum"><a href="#example-87">Example 87</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">``` ``` </code></pre> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;&lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <p>Fences can be indented. If the opening fence is indented, content lines will have equivalent opening indentation removed, if present:</p> <div class="example" id="example-88" data-section="Fenced code blocks"> <div class="examplenum"><a href="#example-88">Example 88</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><span class="space"> </span>``` <span class="space"> </span>aaa aaa ``` </code></pre> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;aaa aaa &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <div class="example" id="example-89" data-section="Fenced code blocks"> <div class="examplenum"><a href="#example-89">Example 89</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><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><code class="language-html">&lt;pre&gt;&lt;code&gt;aaa aaa aaa &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <div class="example" id="example-90" data-section="Fenced code blocks"> <div class="examplenum"><a href="#example-90">Example 90</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><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><code class="language-html">&lt;pre&gt;&lt;code&gt;aaa <span class="space"> </span>aaa aaa &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <p>Four spaces indentation produces an indented code block:</p> <div class="example" id="example-91" data-section="Fenced code blocks"> <div class="examplenum"><a href="#example-91">Example 91</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><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><code class="language-html">&lt;pre&gt;&lt;code&gt;``` aaa ``` &lt;/code&gt;&lt;/pre&gt; </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 class="example" id="example-92" data-section="Fenced code blocks"> <div class="examplenum"><a href="#example-92">Example 92</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">``` aaa <span class="space"> </span><span class="space"> </span>``` </code></pre> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;aaa &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <div class="example" id="example-93" data-section="Fenced code blocks"> <div class="examplenum"><a href="#example-93">Example 93</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><span class="space"> </span><span class="space"> </span><span class="space"> </span>``` aaa <span class="space"> </span><span class="space"> </span>``` </code></pre> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;aaa &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <p>This is not a closing fence, because it is indented 4 spaces:</p> <div class="example" id="example-94" data-section="Fenced code blocks"> <div class="examplenum"><a href="#example-94">Example 94</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">``` aaa <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>``` </code></pre> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;aaa <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>``` &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <p>Code fences (opening and closing) cannot contain internal spaces:</p> <div class="example" id="example-95" data-section="Fenced code blocks"> <div class="examplenum"><a href="#example-95">Example 95</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">```<span class="space"> </span>``` aaa </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;code&gt;&lt;/code&gt; aaa&lt;/p&gt; </code></pre> </div> <div class="example" id="example-96" data-section="Fenced code blocks"> <div class="examplenum"><a href="#example-96">Example 96</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">~~~~~~ aaa ~~~<span class="space"> </span>~~ </code></pre> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;aaa ~~~<span class="space"> </span>~~ &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <p>Fenced code blocks can interrupt paragraphs, and can be followed directly by paragraphs, without a blank line between:</p> <div class="example" id="example-97" data-section="Fenced code blocks"> <div class="examplenum"><a href="#example-97">Example 97</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">foo ``` bar ``` baz </code></pre> <pre><code class="language-html">&lt;p&gt;foo&lt;/p&gt; &lt;pre&gt;&lt;code&gt;bar &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;baz&lt;/p&gt; </code></pre> </div> <p>Other blocks can also occur before and after fenced code blocks without an intervening blank line:</p> <div class="example" id="example-98" data-section="Fenced code blocks"> <div class="examplenum"><a href="#example-98">Example 98</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">foo --- ~~~ bar ~~~ #<span class="space"> </span>baz </code></pre> <pre><code class="language-html">&lt;h2&gt;foo&lt;/h2&gt; &lt;pre&gt;&lt;code&gt;bar &lt;/code&gt;&lt;/pre&gt; &lt;h1&gt;baz&lt;/h1&gt; </code></pre> </div> <p>An <a href="#info-string">info string</a> can be provided after the opening code fence. Opening and closing spaces will be stripped, and the first word, prefixed with <code>language-</code>, is used as the value for the <code>class</code> attribute of the <code>code</code> element within the enclosing <code>pre</code> element.</p> <div class="example" id="example-99" data-section="Fenced code blocks"> <div class="examplenum"><a href="#example-99">Example 99</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">```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><code class="language-html">&lt;pre&gt;&lt;code<span class="space"> </span>class=&quot;language-ruby&quot;&gt;def<span class="space"> </span>foo(x) <span class="space"> </span><span class="space"> </span>return<span class="space"> </span>3 end &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <div class="example" id="example-100" data-section="Fenced code blocks"> <div class="examplenum"><a href="#example-100">Example 100</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">~~~~<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><code class="language-html">&lt;pre&gt;&lt;code<span class="space"> </span>class=&quot;language-ruby&quot;&gt;def<span class="space"> </span>foo(x) <span class="space"> </span><span class="space"> </span>return<span class="space"> </span>3 end &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <div class="example" id="example-101" data-section="Fenced code blocks"> <div class="examplenum"><a href="#example-101">Example 101</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">````; ```` </code></pre> <pre><code class="language-html">&lt;pre&gt;&lt;code<span class="space"> </span>class=&quot;language-;&quot;&gt;&lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <p><a href="#info-string">Info strings</a> for backtick code blocks cannot contain backticks:</p> <div class="example" id="example-102" data-section="Fenced code blocks"> <div class="examplenum"><a href="#example-102">Example 102</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">```<span class="space"> </span>aa<span class="space"> </span>``` foo </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;code&gt;aa&lt;/code&gt; foo&lt;/p&gt; </code></pre> </div> <p>Closing code fences cannot have <a href="#info-string">info strings</a>:</p> <div class="example" id="example-103" data-section="Fenced code blocks"> <div class="examplenum"><a href="#example-103">Example 103</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">``` ```<span class="space"> </span>aaa ``` </code></pre> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;```<span class="space"> </span>aaa &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <h2><a id="html-blocks"></a><span class="number">4.6</span> HTML blocks</h2> <p>An <a id="html-block" href="#html-block" class="definition">HTML block</a> is a group of lines that is treated as raw HTML (and will not be escaped in HTML output).</p> <p>There are seven kinds of <a href="#html-block">HTML block</a>, which can be defined by their start and end conditions. The block begins with a line that meets a <a id="start-condition" href="#start-condition" class="definition">start condition</a> (after up to three spaces optional indentation). It ends with the first subsequent line that meets a matching <a id="end-condition" href="#end-condition" class="definition">end condition</a>, or the last line of the document, if no line is encountered that meets the <a href="#end-condition">end condition</a>. If the first line meets both the <a href="#start-condition">start condition</a> and the <a href="#end-condition">end condition</a>, the block will contain just that line.</p> <ol> <li> <p><strong>Start condition:</strong> line begins with the string <code>&lt;script</code>, <code>&lt;pre</code>, or <code>&lt;style</code> (case-insensitive), followed by whitespace, the string <code>&gt;</code>, or the end of the line.<br /> <strong>End condition:</strong> line contains an end tag <code>&lt;/script&gt;</code>, <code>&lt;/pre&gt;</code>, or <code>&lt;/style&gt;</code> (case-insensitive; it need not match the start tag).</p> </li> <li> <p><strong>Start condition:</strong> line begins with the string <code>&lt;!--</code>.<br /> <strong>End condition:</strong> line contains the string <code>--&gt;</code>.</p> </li> <li> <p><strong>Start condition:</strong> line begins with the string <code>&lt;?</code>.<br /> <strong>End condition:</strong> line contains the string <code>?&gt;</code>.</p> </li> <li> <p><strong>Start condition:</strong> line begins with the string <code>&lt;!</code> followed by an uppercase ASCII letter.<br /> <strong>End condition:</strong> line contains the character <code>&gt;</code>.</p> </li> <li> <p><strong>Start condition:</strong> line begins with the string <code>&lt;![CDATA[</code>.<br /> <strong>End condition:</strong> line contains the string <code>]]&gt;</code>.</p> </li> <li> <p><strong>Start condition:</strong> line begins the string <code>&lt;</code> or <code>&lt;/</code> followed by one of the strings (case-insensitive) <code>address</code>, <code>article</code>, <code>aside</code>, <code>base</code>, <code>basefont</code>, <code>blockquote</code>, <code>body</code>, <code>caption</code>, <code>center</code>, <code>col</code>, <code>colgroup</code>, <code>dd</code>, <code>details</code>, <code>dialog</code>, <code>dir</code>, <code>div</code>, <code>dl</code>, <code>dt</code>, <code>fieldset</code>, <code>figcaption</code>, <code>figure</code>, <code>footer</code>, <code>form</code>, <code>frame</code>, <code>frameset</code>, <code>h1</code>, <code>head</code>, <code>header</code>, <code>hr</code>, <code>html</code>, <code>iframe</code>, <code>legend</code>, <code>li</code>, <code>link</code>, <code>main</code>, <code>menu</code>, <code>menuitem</code>, <code>meta</code>, <code>nav</code>, <code>noframes</code>, <code>ol</code>, <code>optgroup</code>, <code>option</code>, <code>p</code>, <code>param</code>, <code>section</code>, <code>source</code>, <code>summary</code>, <code>table</code>, <code>tbody</code>, <code>td</code>, <code>tfoot</code>, <code>th</code>, <code>thead</code>, <code>title</code>, <code>tr</code>, <code>track</code>, <code>ul</code>, followed by <a href="#whitespace">whitespace</a>, the end of the line, the string <code>&gt;</code>, or the string <code>/&gt;</code>.<br /> <strong>End condition:</strong> line is followed by a <a href="#blank-line">blank line</a>.</p> </li> <li> <p><strong>Start condition:</strong> line begins with a complete <a href="#open-tag">open tag</a> or <a href="#closing-tag">closing tag</a> (with any <a href="#tag-name">tag name</a> other than <code>script</code>, <code>style</code>, or <code>pre</code>) followed only by <a href="#whitespace">whitespace</a> or the end of the line.<br /> <strong>End condition:</strong> line is followed by a <a href="#blank-line">blank line</a>.</p> </li> </ol> <p>All types of <a href="#html-blocks">HTML blocks</a> except type 7 may interrupt a paragraph. Blocks of type 7 may not interrupt a paragraph. (This restriction is intended to prevent unwanted interpretation of long tags inside a wrapped paragraph as starting HTML blocks.)</p> <p>Some simple examples follow. Here are some basic HTML blocks of type 6:</p> <div class="example" id="example-104" data-section="HTML blocks"> <div class="examplenum"><a href="#example-104">Example 104</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;table&gt; <span class="space"> </span><span class="space"> </span>&lt;tr&gt; <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>&lt;td&gt; <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>&lt;/td&gt; <span class="space"> </span><span class="space"> </span>&lt;/tr&gt; &lt;/table&gt; okay. </code></pre> <pre><code class="language-html">&lt;table&gt; <span class="space"> </span><span class="space"> </span>&lt;tr&gt; <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>&lt;td&gt; <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>&lt;/td&gt; <span class="space"> </span><span class="space"> </span>&lt;/tr&gt; &lt;/table&gt; &lt;p&gt;okay.&lt;/p&gt; </code></pre> </div> <div class="example" id="example-105" data-section="HTML blocks"> <div class="examplenum"><a href="#example-105">Example 105</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><span class="space"> </span>&lt;div&gt; <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>&lt;foo&gt;&lt;a&gt; </code></pre> <pre><code class="language-html"><span class="space"> </span>&lt;div&gt; <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>&lt;foo&gt;&lt;a&gt; </code></pre> </div> <p>A block can also start with a closing tag:</p> <div class="example" id="example-106" data-section="HTML blocks"> <div class="examplenum"><a href="#example-106">Example 106</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;/div&gt; *foo* </code></pre> <pre><code class="language-html">&lt;/div&gt; *foo* </code></pre> </div> <p>Here we have two HTML blocks with a Markdown paragraph between them:</p> <div class="example" id="example-107" data-section="HTML blocks"> <div class="examplenum"><a href="#example-107">Example 107</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;DIV<span class="space"> </span>CLASS=&quot;foo&quot;&gt; *Markdown* &lt;/DIV&gt; </code></pre> <pre><code class="language-html">&lt;DIV<span class="space"> </span>CLASS=&quot;foo&quot;&gt; &lt;p&gt;&lt;em&gt;Markdown&lt;/em&gt;&lt;/p&gt; &lt;/DIV&gt; </code></pre> </div> <p>The tag on the first line can be partial, as long as it is split where there would be whitespace:</p> <div class="example" id="example-108" data-section="HTML blocks"> <div class="examplenum"><a href="#example-108">Example 108</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;div<span class="space"> </span>id=&quot;foo&quot; <span class="space"> </span><span class="space"> </span>class=&quot;bar&quot;&gt; &lt;/div&gt; </code></pre> <pre><code class="language-html">&lt;div<span class="space"> </span>id=&quot;foo&quot; <span class="space"> </span><span class="space"> </span>class=&quot;bar&quot;&gt; &lt;/div&gt; </code></pre> </div> <div class="example" id="example-109" data-section="HTML blocks"> <div class="examplenum"><a href="#example-109">Example 109</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;div<span class="space"> </span>id=&quot;foo&quot;<span class="space"> </span>class=&quot;bar <span class="space"> </span><span class="space"> </span>baz&quot;&gt; &lt;/div&gt; </code></pre> <pre><code class="language-html">&lt;div<span class="space"> </span>id=&quot;foo&quot;<span class="space"> </span>class=&quot;bar <span class="space"> </span><span class="space"> </span>baz&quot;&gt; &lt;/div&gt; </code></pre> </div> <p>An open tag need not be closed:</p> <div class="example" id="example-110" data-section="HTML blocks"> <div class="examplenum"><a href="#example-110">Example 110</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;div&gt; *foo* *bar* </code></pre> <pre><code class="language-html">&lt;div&gt; *foo* &lt;p&gt;&lt;em&gt;bar&lt;/em&gt;&lt;/p&gt; </code></pre> </div> <p>A partial tag need not even be completed (garbage in, garbage out):</p> <div class="example" id="example-111" data-section="HTML blocks"> <div class="examplenum"><a href="#example-111">Example 111</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;div<span class="space"> </span>id=&quot;foo&quot; *hi* </code></pre> <pre><code class="language-html">&lt;div<span class="space"> </span>id=&quot;foo&quot; *hi* </code></pre> </div> <div class="example" id="example-112" data-section="HTML blocks"> <div class="examplenum"><a href="#example-112">Example 112</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;div<span class="space"> </span>class foo </code></pre> <pre><code class="language-html">&lt;div<span class="space"> </span>class foo </code></pre> </div> <p>The initial tag doesn’t even need to be a valid tag, as long as it starts like one:</p> <div class="example" id="example-113" data-section="HTML blocks"> <div class="examplenum"><a href="#example-113">Example 113</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;div<span class="space"> </span>*???-&amp;&amp;&amp;-&lt;--- *foo* </code></pre> <pre><code class="language-html">&lt;div<span class="space"> </span>*???-&amp;&amp;&amp;-&lt;--- *foo* </code></pre> </div> <p>In type 6 blocks, the initial tag need not be on a line by itself:</p> <div class="example" id="example-114" data-section="HTML blocks"> <div class="examplenum"><a href="#example-114">Example 114</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;div&gt;&lt;a<span class="space"> </span>href=&quot;bar&quot;&gt;*foo*&lt;/a&gt;&lt;/div&gt; </code></pre> <pre><code class="language-html">&lt;div&gt;&lt;a<span class="space"> </span>href=&quot;bar&quot;&gt;*foo*&lt;/a&gt;&lt;/div&gt; </code></pre> </div> <div class="example" id="example-115" data-section="HTML blocks"> <div class="examplenum"><a href="#example-115">Example 115</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;table&gt;&lt;tr&gt;&lt;td&gt; foo &lt;/td&gt;&lt;/tr&gt;&lt;/table&gt; </code></pre> <pre><code class="language-html">&lt;table&gt;&lt;tr&gt;&lt;td&gt; foo &lt;/td&gt;&lt;/tr&gt;&lt;/table&gt; </code></pre> </div> <p>Everything until the next blank line or end of document gets included in the HTML block. So, 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 class="example" id="example-116" data-section="HTML blocks"> <div class="examplenum"><a href="#example-116">Example 116</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;div&gt;&lt;/div&gt; ```<span class="space"> </span>c int<span class="space"> </span>x<span class="space"> </span>=<span class="space"> </span>33; ``` </code></pre> <pre><code class="language-html">&lt;div&gt;&lt;/div&gt; ```<span class="space"> </span>c int<span class="space"> </span>x<span class="space"> </span>=<span class="space"> </span>33; ``` </code></pre> </div> <p>To start an <a href="#html-block">HTML block</a> with a tag that is <em>not</em> in the list of block-level tags in (6), you must put the tag by itself on the first line (and it must be complete):</p> <div class="example" id="example-117" data-section="HTML blocks"> <div class="examplenum"><a href="#example-117">Example 117</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;a<span class="space"> </span>href=&quot;foo&quot;&gt; *bar* &lt;/a&gt; </code></pre> <pre><code class="language-html">&lt;a<span class="space"> </span>href=&quot;foo&quot;&gt; *bar* &lt;/a&gt; </code></pre> </div> <p>In type 7 blocks, the <a href="#tag-name">tag name</a> can be anything:</p> <div class="example" id="example-118" data-section="HTML blocks"> <div class="examplenum"><a href="#example-118">Example 118</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;Warning&gt; *bar* &lt;/Warning&gt; </code></pre> <pre><code class="language-html">&lt;Warning&gt; *bar* &lt;/Warning&gt; </code></pre> </div> <div class="example" id="example-119" data-section="HTML blocks"> <div class="examplenum"><a href="#example-119">Example 119</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;i<span class="space"> </span>class=&quot;foo&quot;&gt; *bar* &lt;/i&gt; </code></pre> <pre><code class="language-html">&lt;i<span class="space"> </span>class=&quot;foo&quot;&gt; *bar* &lt;/i&gt; </code></pre> </div> <div class="example" id="example-120" data-section="HTML blocks"> <div class="examplenum"><a href="#example-120">Example 120</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;/ins&gt; *bar* </code></pre> <pre><code class="language-html">&lt;/ins&gt; *bar* </code></pre> </div> <p>These rules are designed to allow us to work with tags that can function as either block-level or inline-level tags. The <code>&lt;del&gt;</code> tag is a nice example. We can surround content with <code>&lt;del&gt;</code> tags in three different ways. In this case, we get a raw HTML block, because the <code>&lt;del&gt;</code> tag is on a line by itself:</p> <div class="example" id="example-121" data-section="HTML blocks"> <div class="examplenum"><a href="#example-121">Example 121</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;del&gt; *foo* &lt;/del&gt; </code></pre> <pre><code class="language-html">&lt;del&gt; *foo* &lt;/del&gt; </code></pre> </div> <p>In this case, we get a raw HTML block that just includes the <code>&lt;del&gt;</code> tag (because it ends with the following blank line). So the contents get interpreted as CommonMark:</p> <div class="example" id="example-122" data-section="HTML blocks"> <div class="examplenum"><a href="#example-122">Example 122</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;del&gt; *foo* &lt;/del&gt; </code></pre> <pre><code class="language-html">&lt;del&gt; &lt;p&gt;&lt;em&gt;foo&lt;/em&gt;&lt;/p&gt; &lt;/del&gt; </code></pre> </div> <p>Finally, in this case, the <code>&lt;del&gt;</code> tags are interpreted as <a href="#raw-html">raw HTML</a> <em>inside</em> the CommonMark paragraph. (Because the tag is not on a line by itself, we get inline HTML rather than an <a href="#html-block">HTML block</a>.)</p> <div class="example" id="example-123" data-section="HTML blocks"> <div class="examplenum"><a href="#example-123">Example 123</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;del&gt;*foo*&lt;/del&gt; </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;del&gt;&lt;em&gt;foo&lt;/em&gt;&lt;/del&gt;&lt;/p&gt; </code></pre> </div> <p>HTML tags designed to contain literal content (<code>script</code>, <code>style</code>, <code>pre</code>), comments, processing instructions, and declarations are treated somewhat differently. Instead of ending at the first blank line, these blocks end at the first line containing a corresponding end tag. As a result, these blocks can contain blank lines:</p> <p>A pre tag (type 1):</p> <div class="example" id="example-124" data-section="HTML blocks"> <div class="examplenum"><a href="#example-124">Example 124</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;pre<span class="space"> </span>language=&quot;haskell&quot;&gt;&lt;code&gt; import<span class="space"> </span>Text.HTML.TagSoup main<span class="space"> </span>::<span class="space"> </span>IO<span class="space"> </span>() main<span class="space"> </span>=<span class="space"> </span>print<span class="space"> </span>$<span class="space"> </span>parseTags<span class="space"> </span>tags &lt;/code&gt;&lt;/pre&gt; </code></pre> <pre><code class="language-html">&lt;pre<span class="space"> </span>language=&quot;haskell&quot;&gt;&lt;code&gt; import<span class="space"> </span>Text.HTML.TagSoup main<span class="space"> </span>::<span class="space"> </span>IO<span class="space"> </span>() main<span class="space"> </span>=<span class="space"> </span>print<span class="space"> </span>$<span class="space"> </span>parseTags<span class="space"> </span>tags &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <p>A script tag (type 1):</p> <div class="example" id="example-125" data-section="HTML blocks"> <div class="examplenum"><a href="#example-125">Example 125</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;script<span class="space"> </span>type=&quot;text/javascript&quot;&gt; //<span class="space"> </span>JavaScript<span class="space"> </span>example document.getElementById(&quot;demo&quot;).innerHTML<span class="space"> </span>=<span class="space"> </span>&quot;Hello<span class="space"> </span>JavaScript!&quot;; &lt;/script&gt; </code></pre> <pre><code class="language-html">&lt;script<span class="space"> </span>type=&quot;text/javascript&quot;&gt; //<span class="space"> </span>JavaScript<span class="space"> </span>example document.getElementById(&quot;demo&quot;).innerHTML<span class="space"> </span>=<span class="space"> </span>&quot;Hello<span class="space"> </span>JavaScript!&quot;; &lt;/script&gt; </code></pre> </div> <p>A style tag (type 1):</p> <div class="example" id="example-126" data-section="HTML blocks"> <div class="examplenum"><a href="#example-126">Example 126</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;style <span class="space"> </span><span class="space"> </span>type=&quot;text/css&quot;&gt; h1<span class="space"> </span>{color:red;} p<span class="space"> </span>{color:blue;} &lt;/style&gt; </code></pre> <pre><code class="language-html">&lt;style <span class="space"> </span><span class="space"> </span>type=&quot;text/css&quot;&gt; h1<span class="space"> </span>{color:red;} p<span class="space"> </span>{color:blue;} &lt;/style&gt; </code></pre> </div> <p>If there is no matching end tag, the block will end at the end of the document (or the enclosing [block quote] or [list item]):</p> <div class="example" id="example-127" data-section="HTML blocks"> <div class="examplenum"><a href="#example-127">Example 127</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;style <span class="space"> </span><span class="space"> </span>type=&quot;text/css&quot;&gt; foo </code></pre> <pre><code class="language-html">&lt;style <span class="space"> </span><span class="space"> </span>type=&quot;text/css&quot;&gt; foo </code></pre> </div> <div class="example" id="example-128" data-section="HTML blocks"> <div class="examplenum"><a href="#example-128">Example 128</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&gt;<span class="space"> </span>&lt;div&gt; &gt;<span class="space"> </span>foo bar </code></pre> <pre><code class="language-html">&lt;blockquote&gt; &lt;div&gt; foo &lt;/blockquote&gt; &lt;p&gt;bar&lt;/p&gt; </code></pre> </div> <div class="example" id="example-129" data-section="HTML blocks"> <div class="examplenum"><a href="#example-129">Example 129</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">-<span class="space"> </span>&lt;div&gt; -<span class="space"> </span>foo </code></pre> <pre><code class="language-html">&lt;ul&gt; &lt;li&gt; &lt;div&gt; &lt;/li&gt; &lt;li&gt;foo&lt;/li&gt; &lt;/ul&gt; </code></pre> </div> <p>The end tag can occur on the same line as the start tag:</p> <div class="example" id="example-130" data-section="HTML blocks"> <div class="examplenum"><a href="#example-130">Example 130</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;style&gt;p{color:red;}&lt;/style&gt; *foo* </code></pre> <pre><code class="language-html">&lt;style&gt;p{color:red;}&lt;/style&gt; &lt;p&gt;&lt;em&gt;foo&lt;/em&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-131" data-section="HTML blocks"> <div class="examplenum"><a href="#example-131">Example 131</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;!--<span class="space"> </span>foo<span class="space"> </span>--&gt;*bar* *baz* </code></pre> <pre><code class="language-html">&lt;!--<span class="space"> </span>foo<span class="space"> </span>--&gt;*bar* &lt;p&gt;&lt;em&gt;baz&lt;/em&gt;&lt;/p&gt; </code></pre> </div> <p>Note that anything on the last line after the end tag will be included in the <a href="#html-block">HTML block</a>:</p> <div class="example" id="example-132" data-section="HTML blocks"> <div class="examplenum"><a href="#example-132">Example 132</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;script&gt; foo &lt;/script&gt;1.<span class="space"> </span>*bar* </code></pre> <pre><code class="language-html">&lt;script&gt; foo &lt;/script&gt;1.<span class="space"> </span>*bar* </code></pre> </div> <p>A comment (type 2):</p> <div class="example" id="example-133" data-section="HTML blocks"> <div class="examplenum"><a href="#example-133">Example 133</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;!--<span class="space"> </span>Foo bar <span class="space"> </span><span class="space"> </span><span class="space"> </span>baz<span class="space"> </span>--&gt; </code></pre> <pre><code class="language-html">&lt;!--<span class="space"> </span>Foo bar <span class="space"> </span><span class="space"> </span><span class="space"> </span>baz<span class="space"> </span>--&gt; </code></pre> </div> <p>A processing instruction (type 3):</p> <div class="example" id="example-134" data-section="HTML blocks"> <div class="examplenum"><a href="#example-134">Example 134</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;?php <span class="space"> </span><span class="space"> </span>echo<span class="space"> </span>'&gt;'; ?&gt; </code></pre> <pre><code class="language-html">&lt;?php <span class="space"> </span><span class="space"> </span>echo<span class="space"> </span>'&gt;'; ?&gt; </code></pre> </div> <p>A declaration (type 4):</p> <div class="example" id="example-135" data-section="HTML blocks"> <div class="examplenum"><a href="#example-135">Example 135</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;!DOCTYPE<span class="space"> </span>html&gt; </code></pre> <pre><code class="language-html">&lt;!DOCTYPE<span class="space"> </span>html&gt; </code></pre> </div> <p>CDATA (type 5):</p> <div class="example" id="example-136" data-section="HTML blocks"> <div class="examplenum"><a href="#example-136">Example 136</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;![CDATA[ function<span class="space"> </span>matchwo(a,b) { <span class="space"> </span><span class="space"> </span>if<span class="space"> </span>(a<span class="space"> </span>&lt;<span class="space"> </span>b<span class="space"> </span>&amp;&amp;<span class="space"> </span>a<span class="space"> </span>&lt;<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><span class="space"> </span>return<span class="space"> </span>1; <span class="space"> </span><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><span class="space"> </span>return<span class="space"> </span>0; <span class="space"> </span><span class="space"> </span>} } ]]&gt; </code></pre> <pre><code class="language-html">&lt;![CDATA[ function<span class="space"> </span>matchwo(a,b) { <span class="space"> </span><span class="space"> </span>if<span class="space"> </span>(a<span class="space"> </span>&lt;<span class="space"> </span>b<span class="space"> </span>&amp;&amp;<span class="space"> </span>a<span class="space"> </span>&lt;<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><span class="space"> </span>return<span class="space"> </span>1; <span class="space"> </span><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><span class="space"> </span>return<span class="space"> </span>0; <span class="space"> </span><span class="space"> </span>} } ]]&gt; </code></pre> </div> <p>The opening tag can be indented 1-3 spaces, but not 4:</p> <div class="example" id="example-137" data-section="HTML blocks"> <div class="examplenum"><a href="#example-137">Example 137</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><span class="space"> </span><span class="space"> </span>&lt;!--<span class="space"> </span>foo<span class="space"> </span>--&gt; <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>&lt;!--<span class="space"> </span>foo<span class="space"> </span>--&gt; </code></pre> <pre><code class="language-html"><span class="space"> </span><span class="space"> </span>&lt;!--<span class="space"> </span>foo<span class="space"> </span>--&gt; &lt;pre&gt;&lt;code&gt;&amp;lt;!--<span class="space"> </span>foo<span class="space"> </span>--&amp;gt; &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <div class="example" id="example-138" data-section="HTML blocks"> <div class="examplenum"><a href="#example-138">Example 138</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><span class="space"> </span><span class="space"> </span>&lt;div&gt; <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>&lt;div&gt; </code></pre> <pre><code class="language-html"><span class="space"> </span><span class="space"> </span>&lt;div&gt; &lt;pre&gt;&lt;code&gt;&amp;lt;div&amp;gt; &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <p>An HTML block of types 1–6 can interrupt a paragraph, and need not be preceded by a blank line.</p> <div class="example" id="example-139" data-section="HTML blocks"> <div class="examplenum"><a href="#example-139">Example 139</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">Foo &lt;div&gt; bar &lt;/div&gt; </code></pre> <pre><code class="language-html">&lt;p&gt;Foo&lt;/p&gt; &lt;div&gt; bar &lt;/div&gt; </code></pre> </div> <p>However, a following blank line is needed, except at the end of a document, and except for blocks of types 1–5, above:</p> <div class="example" id="example-140" data-section="HTML blocks"> <div class="examplenum"><a href="#example-140">Example 140</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;div&gt; bar &lt;/div&gt; *foo* </code></pre> <pre><code class="language-html">&lt;div&gt; bar &lt;/div&gt; *foo* </code></pre> </div> <p>HTML blocks of type 7 cannot interrupt a paragraph:</p> <div class="example" id="example-141" data-section="HTML blocks"> <div class="examplenum"><a href="#example-141">Example 141</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">Foo &lt;a<span class="space"> </span>href=&quot;bar&quot;&gt; baz </code></pre> <pre><code class="language-html">&lt;p&gt;Foo &lt;a<span class="space"> </span>href=&quot;bar&quot;&gt; baz&lt;/p&gt; </code></pre> </div> <p>This rule differs from John Gruber’s original Markdown syntax specification, which says:</p> <blockquote> <p>The only restrictions are that block-level HTML elements — e.g. <code>&lt;div&gt;</code>, <code>&lt;table&gt;</code>, <code>&lt;pre&gt;</code>, <code>&lt;p&gt;</code>, etc. — must be separated from surrounding content by blank lines, and the start and end tags of the block should not be indented with tabs or spaces.</p> </blockquote> <p>In some ways Gruber’s rule is more restrictive than the one given here:</p> <ul> <li>It requires that an HTML block be preceded by a blank line.</li> <li>It does not allow the start tag to be indented.</li> <li>It requires a matching end tag, which it also does not allow to be indented.</li> </ul> <p>Most Markdown implementations (including some of Gruber’s own) do not respect all of 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> <p>Compare:</p> <div class="example" id="example-142" data-section="HTML blocks"> <div class="examplenum"><a href="#example-142">Example 142</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;div&gt; *Emphasized*<span class="space"> </span>text. &lt;/div&gt; </code></pre> <pre><code class="language-html">&lt;div&gt; &lt;p&gt;&lt;em&gt;Emphasized&lt;/em&gt;<span class="space"> </span>text.&lt;/p&gt; &lt;/div&gt; </code></pre> </div> <div class="example" id="example-143" data-section="HTML blocks"> <div class="examplenum"><a href="#example-143">Example 143</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;div&gt; *Emphasized*<span class="space"> </span>text. &lt;/div&gt; </code></pre> <pre><code class="language-html">&lt;div&gt; *Emphasized*<span class="space"> </span>text. &lt;/div&gt; </code></pre> </div> <p>Some Markdown implementations have adopted a convention of interpreting content inside tags as text if the open tag has the attribute <code>markdown=1</code>. The rule given above seems a simpler and more elegant way of achieving the same expressive power, which is also much simpler to parse.</p> <p>The main potential drawback is that one can no longer paste HTML blocks into Markdown documents with 100% reliability. However, <em>in most cases</em> this will work fine, because the blank lines in HTML are usually followed by HTML block tags. For example:</p> <div class="example" id="example-144" data-section="HTML blocks"> <div class="examplenum"><a href="#example-144">Example 144</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;table&gt; &lt;tr&gt; &lt;td&gt; Hi &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre> <pre><code class="language-html">&lt;table&gt; &lt;tr&gt; &lt;td&gt; Hi &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre> </div> <p>There are problems, however, if the inner tags are indented <em>and</em> separated by spaces, as then they will be interpreted as an indented code block:</p> <div class="example" id="example-145" data-section="HTML blocks"> <div class="examplenum"><a href="#example-145">Example 145</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;table&gt; <span class="space"> </span><span class="space"> </span>&lt;tr&gt; <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>&lt;td&gt; <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>&lt;/td&gt; <span class="space"> </span><span class="space"> </span>&lt;/tr&gt; &lt;/table&gt; </code></pre> <pre><code class="language-html">&lt;table&gt; <span class="space"> </span><span class="space"> </span>&lt;tr&gt; &lt;pre&gt;&lt;code&gt;&amp;lt;td&amp;gt; <span class="space"> </span><span class="space"> </span>Hi &amp;lt;/td&amp;gt; &lt;/code&gt;&lt;/pre&gt; <span class="space"> </span><span class="space"> </span>&lt;/tr&gt; &lt;/table&gt; </code></pre> </div> <p>Fortunately, blank lines are usually not necessary and can be deleted. The exception is inside <code>&lt;pre&gt;</code> tags, but as described above, raw HTML blocks starting with <code>&lt;pre&gt;</code> <em>can</em> contain blank lines.</p> <h2><a id="link-reference-definitions"></a><span class="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 <a href="#whitespace">whitespace</a> (including up to one <a href="#line-ending">line ending</a>), a <a href="#link-destination">link destination</a>, optional <a href="#whitespace">whitespace</a> (including up to one <a href="#line-ending">line ending</a>), 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 <a href="#whitespace">whitespace</a>. No further <a href="#non-whitespace-character">non-whitespace characters</a> 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="#images">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 class="example" id="example-146" data-section="Link reference definitions"> <div class="examplenum"><a href="#example-146">Example 146</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo]:<span class="space"> </span>/url<span class="space"> </span>&quot;title&quot; [foo] </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/url&quot;<span class="space"> </span>title=&quot;title&quot;&gt;foo&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-147" data-section="Link reference definitions"> <div class="examplenum"><a href="#example-147">Example 147</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><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><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/url&quot;<span class="space"> </span>title=&quot;the<span class="space"> </span>title&quot;&gt;foo&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-148" data-section="Link reference definitions"> <div class="examplenum"><a href="#example-148">Example 148</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[Foo*bar\]]:my_(url)<span class="space"> </span>'title<span class="space"> </span>(with<span class="space"> </span>parens)' [Foo*bar\]] </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;my_(url)&quot;<span class="space"> </span>title=&quot;title<span class="space"> </span>(with<span class="space"> </span>parens)&quot;&gt;Foo*bar]&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-149" data-section="Link reference definitions"> <div class="examplenum"><a href="#example-149">Example 149</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[Foo<span class="space"> </span>bar]: &lt;my<span class="space"> </span>url&gt; 'title' [Foo<span class="space"> </span>bar] </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;my%20url&quot;<span class="space"> </span>title=&quot;title&quot;&gt;Foo<span class="space"> </span>bar&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>The title may extend over multiple lines:</p> <div class="example" id="example-150" data-section="Link reference definitions"> <div class="examplenum"><a href="#example-150">Example 150</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo]:<span class="space"> </span>/url<span class="space"> </span>' title line1 line2 ' [foo] </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/url&quot;<span class="space"> </span>title=&quot; title line1 line2 &quot;&gt;foo&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>However, it may not contain a <a href="#blank-line">blank line</a>:</p> <div class="example" id="example-151" data-section="Link reference definitions"> <div class="examplenum"><a href="#example-151">Example 151</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo]:<span class="space"> </span>/url<span class="space"> </span>'title with<span class="space"> </span>blank<span class="space"> </span>line' [foo] </code></pre> <pre><code class="language-html">&lt;p&gt;[foo]:<span class="space"> </span>/url<span class="space"> </span>'title&lt;/p&gt; &lt;p&gt;with<span class="space"> </span>blank<span class="space"> </span>line'&lt;/p&gt; &lt;p&gt;[foo]&lt;/p&gt; </code></pre> </div> <p>The title may be omitted:</p> <div class="example" id="example-152" data-section="Link reference definitions"> <div class="examplenum"><a href="#example-152">Example 152</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo]: /url [foo] </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/url&quot;&gt;foo&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>The link destination may not be omitted:</p> <div class="example" id="example-153" data-section="Link reference definitions"> <div class="examplenum"><a href="#example-153">Example 153</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo]: [foo] </code></pre> <pre><code class="language-html">&lt;p&gt;[foo]:&lt;/p&gt; &lt;p&gt;[foo]&lt;/p&gt; </code></pre> </div> <p>Both title and destination can contain backslash escapes and literal backslashes:</p> <div class="example" id="example-154" data-section="Link reference definitions"> <div class="examplenum"><a href="#example-154">Example 154</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo]:<span class="space"> </span>/url\bar\*baz<span class="space"> </span>&quot;foo\&quot;bar\baz&quot; [foo] </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/url%5Cbar*baz&quot;<span class="space"> </span>title=&quot;foo&amp;quot;bar\baz&quot;&gt;foo&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>A link can come before its corresponding definition:</p> <div class="example" id="example-155" data-section="Link reference definitions"> <div class="examplenum"><a href="#example-155">Example 155</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo] [foo]:<span class="space"> </span>url </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;url&quot;&gt;foo&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>If there are several matching definitions, the first one takes precedence:</p> <div class="example" id="example-156" data-section="Link reference definitions"> <div class="examplenum"><a href="#example-156">Example 156</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo] [foo]:<span class="space"> </span>first [foo]:<span class="space"> </span>second </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;first&quot;&gt;foo&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>As noted in the section on <a href="#links">Links</a>, matching of labels is case-insensitive (see <a href="#matches">matches</a>).</p> <div class="example" id="example-157" data-section="Link reference definitions"> <div class="examplenum"><a href="#example-157">Example 157</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[FOO]:<span class="space"> </span>/url [Foo] </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/url&quot;&gt;Foo&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-158" data-section="Link reference definitions"> <div class="examplenum"><a href="#example-158">Example 158</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[ΑΓΩ]:<span class="space"> </span>/φου [αγω] </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/%CF%86%CE%BF%CF%85&quot;&gt;αγω&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>Here is a link reference definition with no corresponding link. It contributes nothing to the document.</p> <div class="example" id="example-159" data-section="Link reference definitions"> <div class="examplenum"><a href="#example-159">Example 159</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo]:<span class="space"> </span>/url </code></pre> <pre><code class="language-html"></code></pre> </div> <p>Here is another one:</p> <div class="example" id="example-160" data-section="Link reference definitions"> <div class="examplenum"><a href="#example-160">Example 160</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[ foo ]:<span class="space"> </span>/url bar </code></pre> <pre><code class="language-html">&lt;p&gt;bar&lt;/p&gt; </code></pre> </div> <p>This is not a link reference definition, because there are <a href="#non-whitespace-character">non-whitespace characters</a> after the title:</p> <div class="example" id="example-161" data-section="Link reference definitions"> <div class="examplenum"><a href="#example-161">Example 161</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo]:<span class="space"> </span>/url<span class="space"> </span>&quot;title&quot;<span class="space"> </span>ok </code></pre> <pre><code class="language-html">&lt;p&gt;[foo]:<span class="space"> </span>/url<span class="space"> </span>&amp;quot;title&amp;quot;<span class="space"> </span>ok&lt;/p&gt; </code></pre> </div> <p>This is a link reference definition, but it has no title:</p> <div class="example" id="example-162" data-section="Link reference definitions"> <div class="examplenum"><a href="#example-162">Example 162</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo]:<span class="space"> </span>/url &quot;title&quot;<span class="space"> </span>ok </code></pre> <pre><code class="language-html">&lt;p&gt;&amp;quot;title&amp;quot;<span class="space"> </span>ok&lt;/p&gt; </code></pre> </div> <p>This is not a link reference definition, because it is indented four spaces:</p> <div class="example" id="example-163" data-section="Link reference definitions"> <div class="examplenum"><a href="#example-163">Example 163</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><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>&quot;title&quot; [foo] </code></pre> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;[foo]:<span class="space"> </span>/url<span class="space"> </span>&amp;quot;title&amp;quot; &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;[foo]&lt;/p&gt; </code></pre> </div> <p>This is not a link reference definition, because it occurs inside a code block:</p> <div class="example" id="example-164" data-section="Link reference definitions"> <div class="examplenum"><a href="#example-164">Example 164</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">``` [foo]:<span class="space"> </span>/url ``` [foo] </code></pre> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;[foo]:<span class="space"> </span>/url &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;[foo]&lt;/p&gt; </code></pre> </div> <p>A <a href="#link-reference-definition">link reference definition</a> cannot interrupt a paragraph.</p> <div class="example" id="example-165" data-section="Link reference definitions"> <div class="examplenum"><a href="#example-165">Example 165</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">Foo [bar]:<span class="space"> </span>/baz [bar] </code></pre> <pre><code class="language-html">&lt;p&gt;Foo [bar]:<span class="space"> </span>/baz&lt;/p&gt; &lt;p&gt;[bar]&lt;/p&gt; </code></pre> </div> <p>However, it can directly follow other block elements, such as headers and horizontal rules, and it need not be followed by a blank line.</p> <div class="example" id="example-166" data-section="Link reference definitions"> <div class="examplenum"><a href="#example-166">Example 166</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">#<span class="space"> </span>[Foo] [foo]:<span class="space"> </span>/url &gt;<span class="space"> </span>bar </code></pre> <pre><code class="language-html">&lt;h1&gt;&lt;a<span class="space"> </span>href=&quot;/url&quot;&gt;Foo&lt;/a&gt;&lt;/h1&gt; &lt;blockquote&gt; &lt;p&gt;bar&lt;/p&gt; &lt;/blockquote&gt; </code></pre> </div> <p>Several <a href="#link-reference-definition">link reference definitions</a> can occur one after another, without intervening blank lines.</p> <div class="example" id="example-167" data-section="Link reference definitions"> <div class="examplenum"><a href="#example-167">Example 167</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo]:<span class="space"> </span>/foo-url<span class="space"> </span>&quot;foo&quot; [bar]:<span class="space"> </span>/bar-url <span class="space"> </span><span class="space"> </span>&quot;bar&quot; [baz]:<span class="space"> </span>/baz-url [foo], [bar], [baz] </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/foo-url&quot;<span class="space"> </span>title=&quot;foo&quot;&gt;foo&lt;/a&gt;, &lt;a<span class="space"> </span>href=&quot;/bar-url&quot;<span class="space"> </span>title=&quot;bar&quot;&gt;bar&lt;/a&gt;, &lt;a<span class="space"> </span>href=&quot;/baz-url&quot;&gt;baz&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p><a href="#link-reference-definition">Link reference definitions</a> can occur inside block containers, like lists and block quotations. They affect the entire document, not just the container in which they are defined:</p> <div class="example" id="example-168" data-section="Link reference definitions"> <div class="examplenum"><a href="#example-168">Example 168</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo] &gt;<span class="space"> </span>[foo]:<span class="space"> </span>/url </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/url&quot;&gt;foo&lt;/a&gt;&lt;/p&gt; &lt;blockquote&gt; &lt;/blockquote&gt; </code></pre> </div> <h2><a id="paragraphs"></a><span class="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 <a href="#whitespace">whitespace</a>.</p> <p>A simple example with two paragraphs:</p> <div class="example" id="example-169" data-section="Paragraphs"> <div class="examplenum"><a href="#example-169">Example 169</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">aaa bbb </code></pre> <pre><code class="language-html">&lt;p&gt;aaa&lt;/p&gt; &lt;p&gt;bbb&lt;/p&gt; </code></pre> </div> <p>Paragraphs can contain multiple lines, but no blank lines:</p> <div class="example" id="example-170" data-section="Paragraphs"> <div class="examplenum"><a href="#example-170">Example 170</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">aaa bbb ccc ddd </code></pre> <pre><code class="language-html">&lt;p&gt;aaa bbb&lt;/p&gt; &lt;p&gt;ccc ddd&lt;/p&gt; </code></pre> </div> <p>Multiple blank lines between paragraph have no effect:</p> <div class="example" id="example-171" data-section="Paragraphs"> <div class="examplenum"><a href="#example-171">Example 171</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">aaa bbb </code></pre> <pre><code class="language-html">&lt;p&gt;aaa&lt;/p&gt; &lt;p&gt;bbb&lt;/p&gt; </code></pre> </div> <p>Leading spaces are skipped:</p> <div class="example" id="example-172" data-section="Paragraphs"> <div class="examplenum"><a href="#example-172">Example 172</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><span class="space"> </span><span class="space"> </span>aaa <span class="space"> </span>bbb </code></pre> <pre><code class="language-html">&lt;p&gt;aaa bbb&lt;/p&gt; </code></pre> </div> <p>Lines after the first may be indented any amount, since indented code blocks cannot interrupt paragraphs.</p> <div class="example" id="example-173" data-section="Paragraphs"> <div class="examplenum"><a href="#example-173">Example 173</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">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><code class="language-html">&lt;p&gt;aaa bbb ccc&lt;/p&gt; </code></pre> </div> <p>However, the first line may be indented at most three spaces, or an indented code block will be triggered:</p> <div class="example" id="example-174" data-section="Paragraphs"> <div class="examplenum"><a href="#example-174">Example 174</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><span class="space"> </span><span class="space"> </span><span class="space"> </span>aaa bbb </code></pre> <pre><code class="language-html">&lt;p&gt;aaa bbb&lt;/p&gt; </code></pre> </div> <div class="example" id="example-175" data-section="Paragraphs"> <div class="examplenum"><a href="#example-175">Example 175</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>aaa bbb </code></pre> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;aaa &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;bbb&lt;/p&gt; </code></pre> </div> <p>Final spaces are stripped before inline parsing, so a paragraph that ends with two or more spaces will not end with a <a href="#hard-line-break">hard line break</a>:</p> <div class="example" id="example-176" data-section="Paragraphs"> <div class="examplenum"><a href="#example-176">Example 176</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">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><code class="language-html">&lt;p&gt;aaa&lt;br<span class="space"> </span>/&gt; bbb&lt;/p&gt; </code></pre> </div> <h2><a id="blank-lines"></a><span class="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 class="example" id="example-177" data-section="Blank lines"> <div class="examplenum"><a href="#example-177">Example 177</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><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><code class="language-html">&lt;p&gt;aaa&lt;/p&gt; &lt;h1&gt;aaa&lt;/h1&gt; </code></pre> </div> <h1><a id="container-blocks"></a><span class="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-quotes">block quotes</a> and <a href="#list-items">list items</a>. <a href="#lists">Lists</a> are meta-containers for <a href="#list-items">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-parsing-strategy">A parsing strategy</a>.)</p> <h2><a id="block-quotes"></a><span class="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>&gt;</code> together with a following space, or (b) a single character <code>&gt;</code> not followed by a space.</p> <p>The following rules define <a href="#block-quotes">block quotes</a>:</p> <ol> <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-quotes">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-quotes">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 <a href="#non-whitespace-character">non-whitespace character</a> 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-quotes">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-quotes">block quote</a>.</p> <p>Here is a simple example:</p> <div class="example" id="example-178" data-section="Block quotes"> <div class="examplenum"><a href="#example-178">Example 178</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&gt;<span class="space"> </span>#<span class="space"> </span>Foo &gt;<span class="space"> </span>bar &gt;<span class="space"> </span>baz </code></pre> <pre><code class="language-html">&lt;blockquote&gt; &lt;h1&gt;Foo&lt;/h1&gt; &lt;p&gt;bar baz&lt;/p&gt; &lt;/blockquote&gt; </code></pre> </div> <p>The spaces after the <code>&gt;</code> characters can be omitted:</p> <div class="example" id="example-179" data-section="Block quotes"> <div class="examplenum"><a href="#example-179">Example 179</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&gt;#<span class="space"> </span>Foo &gt;bar &gt;<span class="space"> </span>baz </code></pre> <pre><code class="language-html">&lt;blockquote&gt; &lt;h1&gt;Foo&lt;/h1&gt; &lt;p&gt;bar baz&lt;/p&gt; &lt;/blockquote&gt; </code></pre> </div> <p>The <code>&gt;</code> characters can be indented 1-3 spaces:</p> <div class="example" id="example-180" data-section="Block quotes"> <div class="examplenum"><a href="#example-180">Example 180</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><span class="space"> </span><span class="space"> </span><span class="space"> </span>&gt;<span class="space"> </span>#<span class="space"> </span>Foo <span class="space"> </span><span class="space"> </span><span class="space"> </span>&gt;<span class="space"> </span>bar <span class="space"> </span>&gt;<span class="space"> </span>baz </code></pre> <pre><code class="language-html">&lt;blockquote&gt; &lt;h1&gt;Foo&lt;/h1&gt; &lt;p&gt;bar baz&lt;/p&gt; &lt;/blockquote&gt; </code></pre> </div> <p>Four spaces gives us a code block:</p> <div class="example" id="example-181" data-section="Block quotes"> <div class="examplenum"><a href="#example-181">Example 181</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>&gt;<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>&gt;<span class="space"> </span>bar <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>&gt;<span class="space"> </span>baz </code></pre> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;&amp;gt;<span class="space"> </span>#<span class="space"> </span>Foo &amp;gt;<span class="space"> </span>bar &amp;gt;<span class="space"> </span>baz &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <p>The Laziness clause allows us to omit the <code>&gt;</code> before a paragraph continuation line:</p> <div class="example" id="example-182" data-section="Block quotes"> <div class="examplenum"><a href="#example-182">Example 182</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&gt;<span class="space"> </span>#<span class="space"> </span>Foo &gt;<span class="space"> </span>bar baz </code></pre> <pre><code class="language-html">&lt;blockquote&gt; &lt;h1&gt;Foo&lt;/h1&gt; &lt;p&gt;bar baz&lt;/p&gt; &lt;/blockquote&gt; </code></pre> </div> <p>A block quote can contain some lazy and some non-lazy continuation lines:</p> <div class="example" id="example-183" data-section="Block quotes"> <div class="examplenum"><a href="#example-183">Example 183</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&gt;<span class="space"> </span>bar baz &gt;<span class="space"> </span>foo </code></pre> <pre><code class="language-html">&lt;blockquote&gt; &lt;p&gt;bar baz foo&lt;/p&gt; &lt;/blockquote&gt; </code></pre> </div> <p>Laziness only applies to lines that would have been continuations of paragraphs had they been prepended with <a href="#block-quote-marker">block quote markers</a>. For example, the <code>&gt;</code> cannot be omitted in the second line of</p> <pre><code class="language-markdown">&gt; foo &gt; --- </code></pre> <p>without changing the meaning:</p> <div class="example" id="example-184" data-section="Block quotes"> <div class="examplenum"><a href="#example-184">Example 184</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&gt;<span class="space"> </span>foo --- </code></pre> <pre><code class="language-html">&lt;blockquote&gt; &lt;p&gt;foo&lt;/p&gt; &lt;/blockquote&gt; &lt;hr<span class="space"> </span>/&gt; </code></pre> </div> <p>Similarly, if we omit the <code>&gt;</code> in the second line of</p> <pre><code class="language-markdown">&gt; - foo &gt; - bar </code></pre> <p>then the block quote ends after the first line:</p> <div class="example" id="example-185" data-section="Block quotes"> <div class="examplenum"><a href="#example-185">Example 185</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&gt;<span class="space"> </span>-<span class="space"> </span>foo -<span class="space"> </span>bar </code></pre> <pre><code class="language-html">&lt;blockquote&gt; &lt;ul&gt; &lt;li&gt;foo&lt;/li&gt; &lt;/ul&gt; &lt;/blockquote&gt; &lt;ul&gt; &lt;li&gt;bar&lt;/li&gt; &lt;/ul&gt; </code></pre> </div> <p>For the same reason, we can’t omit the <code>&gt;</code> in front of subsequent lines of an indented or fenced code block:</p> <div class="example" id="example-186" data-section="Block quotes"> <div class="examplenum"><a href="#example-186">Example 186</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&gt;<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><code class="language-html">&lt;blockquote&gt; &lt;pre&gt;&lt;code&gt;foo &lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;pre&gt;&lt;code&gt;bar &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <div class="example" id="example-187" data-section="Block quotes"> <div class="examplenum"><a href="#example-187">Example 187</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&gt;<span class="space"> </span>``` foo ``` </code></pre> <pre><code class="language-html">&lt;blockquote&gt; &lt;pre&gt;&lt;code&gt;&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;p&gt;foo&lt;/p&gt; &lt;pre&gt;&lt;code&gt;&lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <p>Note that in the following case, we have a paragraph continuation line:</p> <div class="example" id="example-188" data-section="Block quotes"> <div class="examplenum"><a href="#example-188">Example 188</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&gt;<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><code class="language-html">&lt;blockquote&gt; &lt;p&gt;foo -<span class="space"> </span>bar&lt;/p&gt; &lt;/blockquote&gt; </code></pre> </div> <p>To see why, note that in</p> <pre><code class="language-markdown">&gt; foo &gt; - bar </code></pre> <p>the <code>- bar</code> is indented too far to start a list, and can’t be an indented code block because indented code blocks cannot interrupt paragraphs, so it is a [paragraph continuation line].</p> <p>A block quote can be empty:</p> <div class="example" id="example-189" data-section="Block quotes"> <div class="examplenum"><a href="#example-189">Example 189</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&gt; </code></pre> <pre><code class="language-html">&lt;blockquote&gt; &lt;/blockquote&gt; </code></pre> </div> <div class="example" id="example-190" data-section="Block quotes"> <div class="examplenum"><a href="#example-190">Example 190</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&gt; &gt;<span class="space"> </span><span class="space"> </span> &gt;<span class="space"> </span> </code></pre> <pre><code class="language-html">&lt;blockquote&gt; &lt;/blockquote&gt; </code></pre> </div> <p>A block quote can have initial or final blank lines:</p> <div class="example" id="example-191" data-section="Block quotes"> <div class="examplenum"><a href="#example-191">Example 191</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&gt; &gt;<span class="space"> </span>foo &gt;<span class="space"> </span><span class="space"> </span> </code></pre> <pre><code class="language-html">&lt;blockquote&gt; &lt;p&gt;foo&lt;/p&gt; &lt;/blockquote&gt; </code></pre> </div> <p>A blank line always separates block quotes:</p> <div class="example" id="example-192" data-section="Block quotes"> <div class="examplenum"><a href="#example-192">Example 192</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&gt;<span class="space"> </span>foo &gt;<span class="space"> </span>bar </code></pre> <pre><code class="language-html">&lt;blockquote&gt; &lt;p&gt;foo&lt;/p&gt; &lt;/blockquote&gt; &lt;blockquote&gt; &lt;p&gt;bar&lt;/p&gt; &lt;/blockquote&gt; </code></pre> </div> <p>(Most current Markdown implementations, including John Gruber’s original <code>Markdown.pl</code>, will parse this example as a single block quote with two paragraphs. But it seems better to allow the author to decide whether two block quotes or one are wanted.)</p> <p>Consecutiveness means that if we put these block quotes together, we get a single block quote:</p> <div class="example" id="example-193" data-section="Block quotes"> <div class="examplenum"><a href="#example-193">Example 193</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&gt;<span class="space"> </span>foo &gt;<span class="space"> </span>bar </code></pre> <pre><code class="language-html">&lt;blockquote&gt; &lt;p&gt;foo bar&lt;/p&gt; &lt;/blockquote&gt; </code></pre> </div> <p>To get a block quote with two paragraphs, use:</p> <div class="example" id="example-194" data-section="Block quotes"> <div class="examplenum"><a href="#example-194">Example 194</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&gt;<span class="space"> </span>foo &gt; &gt;<span class="space"> </span>bar </code></pre> <pre><code class="language-html">&lt;blockquote&gt; &lt;p&gt;foo&lt;/p&gt; &lt;p&gt;bar&lt;/p&gt; &lt;/blockquote&gt; </code></pre> </div> <p>Block quotes can interrupt paragraphs:</p> <div class="example" id="example-195" data-section="Block quotes"> <div class="examplenum"><a href="#example-195">Example 195</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">foo &gt;<span class="space"> </span>bar </code></pre> <pre><code class="language-html">&lt;p&gt;foo&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;bar&lt;/p&gt; &lt;/blockquote&gt; </code></pre> </div> <p>In general, blank lines are not needed before or after block quotes:</p> <div class="example" id="example-196" data-section="Block quotes"> <div class="examplenum"><a href="#example-196">Example 196</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&gt;<span class="space"> </span>aaa *** &gt;<span class="space"> </span>bbb </code></pre> <pre><code class="language-html">&lt;blockquote&gt; &lt;p&gt;aaa&lt;/p&gt; &lt;/blockquote&gt; &lt;hr<span class="space"> </span>/&gt; &lt;blockquote&gt; &lt;p&gt;bbb&lt;/p&gt; &lt;/blockquote&gt; </code></pre> </div> <p>However, because of laziness, a blank line is needed between a block quote and a following paragraph:</p> <div class="example" id="example-197" data-section="Block quotes"> <div class="examplenum"><a href="#example-197">Example 197</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&gt;<span class="space"> </span>bar baz </code></pre> <pre><code class="language-html">&lt;blockquote&gt; &lt;p&gt;bar baz&lt;/p&gt; &lt;/blockquote&gt; </code></pre> </div> <div class="example" id="example-198" data-section="Block quotes"> <div class="examplenum"><a href="#example-198">Example 198</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&gt;<span class="space"> </span>bar baz </code></pre> <pre><code class="language-html">&lt;blockquote&gt; &lt;p&gt;bar&lt;/p&gt; &lt;/blockquote&gt; &lt;p&gt;baz&lt;/p&gt; </code></pre> </div> <div class="example" id="example-199" data-section="Block quotes"> <div class="examplenum"><a href="#example-199">Example 199</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&gt;<span class="space"> </span>bar &gt; baz </code></pre> <pre><code class="language-html">&lt;blockquote&gt; &lt;p&gt;bar&lt;/p&gt; &lt;/blockquote&gt; &lt;p&gt;baz&lt;/p&gt; </code></pre> </div> <p>It is a consequence of the Laziness rule that any number of initial <code>&gt;</code>s may be omitted on a continuation line of a nested block quote:</p> <div class="example" id="example-200" data-section="Block quotes"> <div class="examplenum"><a href="#example-200">Example 200</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&gt;<span class="space"> </span>&gt;<span class="space"> </span>&gt;<span class="space"> </span>foo bar </code></pre> <pre><code class="language-html">&lt;blockquote&gt; &lt;blockquote&gt; &lt;blockquote&gt; &lt;p&gt;foo bar&lt;/p&gt; &lt;/blockquote&gt; &lt;/blockquote&gt; &lt;/blockquote&gt; </code></pre> </div> <div class="example" id="example-201" data-section="Block quotes"> <div class="examplenum"><a href="#example-201">Example 201</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&gt;&gt;&gt;<span class="space"> </span>foo &gt;<span class="space"> </span>bar &gt;&gt;baz </code></pre> <pre><code class="language-html">&lt;blockquote&gt; &lt;blockquote&gt; &lt;blockquote&gt; &lt;p&gt;foo bar baz&lt;/p&gt; &lt;/blockquote&gt; &lt;/blockquote&gt; &lt;/blockquote&gt; </code></pre> </div> <p>When including an indented code block in a block quote, remember that the <a href="#block-quote-marker">block quote marker</a> includes both the <code>&gt;</code> and a following space. So <em>five spaces</em> are needed after the <code>&gt;</code>:</p> <div class="example" id="example-202" data-section="Block quotes"> <div class="examplenum"><a href="#example-202">Example 202</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&gt;<span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>code &gt;<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><code class="language-html">&lt;blockquote&gt; &lt;pre&gt;&lt;code&gt;code &lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;blockquote&gt; &lt;p&gt;not<span class="space"> </span>code&lt;/p&gt; &lt;/blockquote&gt; </code></pre> </div> <h2><a id="list-items"></a><span class="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 1–9 arabic digits (<code>0-9</code>), followed by either a <code>.</code> character or a <code>)</code> character. (The reason for the length limit is that with 10 digits we start seeing integer overflows in some browsers.)</p> <p>The following rules define <a href="#list-items">list items</a>:</p> <ol> <li><strong>Basic case.</strong> If a sequence of lines <em>Ls</em> constitute a sequence of blocks <em>Bs</em> starting with a <a href="#non-whitespace-character">non-whitespace character</a> and not separated from each other by more than one blank line, and <em>M</em> is a list marker of width <em>W</em> followed by 0 &lt; <em>N</em> &lt; 5 spaces, then the result of prepending <em>M</em> and the following spaces to the first line of <em>Ls</em>, and indenting subsequent lines of <em>Ls</em> by <em>W + N</em> spaces, is a list item with <em>Bs</em> as its contents. The type of the list item (bullet or ordered) is determined by the type of its list marker. If the list item is ordered, then it is also assigned a start number, based on the ordered list marker.</li> </ol> <p>For example, let <em>Ls</em> be the lines</p> <div class="example" id="example-203" data-section="List items"> <div class="examplenum"><a href="#example-203">Example 203</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">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 &gt;<span class="space"> </span>A<span class="space"> </span>block<span class="space"> </span>quote. </code></pre> <pre><code class="language-html">&lt;p&gt;A<span class="space"> </span>paragraph with<span class="space"> </span>two<span class="space"> </span>lines.&lt;/p&gt; &lt;pre&gt;&lt;code&gt;indented<span class="space"> </span>code &lt;/code&gt;&lt;/pre&gt; &lt;blockquote&gt; &lt;p&gt;A<span class="space"> </span>block<span class="space"> </span>quote.&lt;/p&gt; &lt;/blockquote&gt; </code></pre> </div> <p>And let <em>M</em> be the marker <code>1.</code>, and <em>N</em> = 2. Then rule #1 says that the following is an ordered list item with start number 1, and the same contents as <em>Ls</em>:</p> <div class="example" id="example-204" data-section="List items"> <div class="examplenum"><a href="#example-204">Example 204</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">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> <pre><code class="language-html">&lt;ol&gt; &lt;li&gt; &lt;p&gt;A<span class="space"> </span>paragraph with<span class="space"> </span>two<span class="space"> </span>lines.&lt;/p&gt; &lt;pre&gt;&lt;code&gt;indented<span class="space"> </span>code &lt;/code&gt;&lt;/pre&gt; &lt;blockquote&gt; &lt;p&gt;A<span class="space"> </span>block<span class="space"> </span>quote.&lt;/p&gt; &lt;/blockquote&gt; &lt;/li&gt; &lt;/ol&gt; </code></pre> </div> <p>The most important thing to notice is that the position of the text after the list marker determines how much indentation is needed in subsequent blocks in the list item. If the list marker takes up two spaces, and there are three spaces between the list marker and the next <a href="#non-whitespace-character">non-whitespace character</a>, 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 class="example" id="example-205" data-section="List items"> <div class="examplenum"><a href="#example-205">Example 205</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">-<span class="space"> </span>one <span class="space"> </span>two </code></pre> <pre><code class="language-html">&lt;ul&gt; &lt;li&gt;one&lt;/li&gt; &lt;/ul&gt; &lt;p&gt;two&lt;/p&gt; </code></pre> </div> <div class="example" id="example-206" data-section="List items"> <div class="examplenum"><a href="#example-206">Example 206</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">-<span class="space"> </span>one <span class="space"> </span><span class="space"> </span>two </code></pre> <pre><code class="language-html">&lt;ul&gt; &lt;li&gt; &lt;p&gt;one&lt;/p&gt; &lt;p&gt;two&lt;/p&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> </div> <div class="example" id="example-207" data-section="List items"> <div class="examplenum"><a href="#example-207">Example 207</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><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><code class="language-html">&lt;ul&gt; &lt;li&gt;one&lt;/li&gt; &lt;/ul&gt; &lt;pre&gt;&lt;code&gt;<span class="space"> </span>two &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <div class="example" id="example-208" data-section="List items"> <div class="examplenum"><a href="#example-208">Example 208</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><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><code class="language-html">&lt;ul&gt; &lt;li&gt; &lt;p&gt;one&lt;/p&gt; &lt;p&gt;two&lt;/p&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> </div> <p>It is tempting to think of this in terms of columns: the continuation blocks must be indented at least to the column of the first <a href="#non-whitespace-character">non-whitespace character</a> 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 class="example" id="example-209" data-section="List items"> <div class="examplenum"><a href="#example-209">Example 209</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><span class="space"> </span><span class="space"> </span><span class="space"> </span>&gt;<span class="space"> </span>&gt;<span class="space"> </span>1.<span class="space"> </span><span class="space"> </span>one &gt;&gt; &gt;&gt;<span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>two </code></pre> <pre><code class="language-html">&lt;blockquote&gt; &lt;blockquote&gt; &lt;ol&gt; &lt;li&gt; &lt;p&gt;one&lt;/p&gt; &lt;p&gt;two&lt;/p&gt; &lt;/li&gt; &lt;/ol&gt; &lt;/blockquote&gt; &lt;/blockquote&gt; </code></pre> </div> <p>Here <code>two</code> occurs in the same column as the list marker <code>1.</code>, but is actually contained in the list item, because there is sufficient indentation after the last containing blockquote marker.</p> <p>The converse is also possible. In the following example, the word <code>two</code> occurs far to the right of the initial text of the list item, <code>one</code>, but it is not considered part of the list item, because it is not indented far enough past the blockquote marker:</p> <div class="example" id="example-210" data-section="List items"> <div class="examplenum"><a href="#example-210">Example 210</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&gt;&gt;-<span class="space"> </span>one &gt;&gt; <span class="space"> </span><span class="space"> </span>&gt;<span class="space"> </span><span class="space"> </span>&gt;<span class="space"> </span>two </code></pre> <pre><code class="language-html">&lt;blockquote&gt; &lt;blockquote&gt; &lt;ul&gt; &lt;li&gt;one&lt;/li&gt; &lt;/ul&gt; &lt;p&gt;two&lt;/p&gt; &lt;/blockquote&gt; &lt;/blockquote&gt; </code></pre> </div> <p>Note that at least one space is needed between the list marker and any following content, so these are not list items:</p> <div class="example" id="example-211" data-section="List items"> <div class="examplenum"><a href="#example-211">Example 211</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">-one 2.two </code></pre> <pre><code class="language-html">&lt;p&gt;-one&lt;/p&gt; &lt;p&gt;2.two&lt;/p&gt; </code></pre> </div> <p>A list item may not contain blocks that are separated by more than one blank line. Thus, two blank lines will end a list, unless the two blanks are contained in a <a href="#fenced-code-block">fenced code block</a>.</p> <div class="example" id="example-212" data-section="List items"> <div class="examplenum"><a href="#example-212">Example 212</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">-<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>``` -<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><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><span class="space"> </span><span class="space"> </span>``` </code></pre> <pre><code class="language-html">&lt;ul&gt; &lt;li&gt; &lt;p&gt;foo&lt;/p&gt; &lt;p&gt;bar&lt;/p&gt; &lt;/li&gt; &lt;li&gt; &lt;p&gt;foo&lt;/p&gt; &lt;/li&gt; &lt;/ul&gt; &lt;p&gt;bar&lt;/p&gt; &lt;ul&gt; &lt;li&gt; &lt;pre&gt;&lt;code&gt;foo bar &lt;/code&gt;&lt;/pre&gt; &lt;/li&gt; &lt;li&gt; &lt;p&gt;baz&lt;/p&gt; &lt;ul&gt; &lt;li&gt; &lt;pre&gt;&lt;code&gt;foo bar &lt;/code&gt;&lt;/pre&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> </div> <p>A list item may contain any kind of block:</p> <div class="example" id="example-213" data-section="List items"> <div class="examplenum"><a href="#example-213">Example 213</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">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>&gt;<span class="space"> </span>bam </code></pre> <pre><code class="language-html">&lt;ol&gt; &lt;li&gt; &lt;p&gt;foo&lt;/p&gt; &lt;pre&gt;&lt;code&gt;bar &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;baz&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;bam&lt;/p&gt; &lt;/blockquote&gt; &lt;/li&gt; &lt;/ol&gt; </code></pre> </div> <p>Note that ordered list start numbers must be nine digits or less:</p> <div class="example" id="example-214" data-section="List items"> <div class="examplenum"><a href="#example-214">Example 214</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">123456789.<span class="space"> </span>ok </code></pre> <pre><code class="language-html">&lt;ol<span class="space"> </span>start=&quot;123456789&quot;&gt; &lt;li&gt;ok&lt;/li&gt; &lt;/ol&gt; </code></pre> </div> <div class="example" id="example-215" data-section="List items"> <div class="examplenum"><a href="#example-215">Example 215</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">1234567890.<span class="space"> </span>not<span class="space"> </span>ok </code></pre> <pre><code class="language-html">&lt;p&gt;1234567890.<span class="space"> </span>not<span class="space"> </span>ok&lt;/p&gt; </code></pre> </div> <p>A start number may begin with 0s:</p> <div class="example" id="example-216" data-section="List items"> <div class="examplenum"><a href="#example-216">Example 216</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">0.<span class="space"> </span>ok </code></pre> <pre><code class="language-html">&lt;ol<span class="space"> </span>start=&quot;0&quot;&gt; &lt;li&gt;ok&lt;/li&gt; &lt;/ol&gt; </code></pre> </div> <div class="example" id="example-217" data-section="List items"> <div class="examplenum"><a href="#example-217">Example 217</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">003.<span class="space"> </span>ok </code></pre> <pre><code class="language-html">&lt;ol<span class="space"> </span>start=&quot;3&quot;&gt; &lt;li&gt;ok&lt;/li&gt; &lt;/ol&gt; </code></pre> </div> <p>A start number may not be negative:</p> <div class="example" id="example-218" data-section="List items"> <div class="examplenum"><a href="#example-218">Example 218</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">-1.<span class="space"> </span>not<span class="space"> </span>ok </code></pre> <pre><code class="language-html">&lt;p&gt;-1.<span class="space"> </span>not<span class="space"> </span>ok&lt;/p&gt; </code></pre> </div> <ol start="2"> <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 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 class="example" id="example-219" data-section="List items"> <div class="examplenum"><a href="#example-219">Example 219</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">-<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><code class="language-html">&lt;ul&gt; &lt;li&gt; &lt;p&gt;foo&lt;/p&gt; &lt;pre&gt;&lt;code&gt;bar &lt;/code&gt;&lt;/pre&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> </div> <p>And in this case it is 11 spaces:</p> <div class="example" id="example-220" data-section="List items"> <div class="examplenum"><a href="#example-220">Example 220</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><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><code class="language-html">&lt;ol<span class="space"> </span>start=&quot;10&quot;&gt; &lt;li&gt; &lt;p&gt;foo&lt;/p&gt; &lt;pre&gt;&lt;code&gt;bar &lt;/code&gt;&lt;/pre&gt; &lt;/li&gt; &lt;/ol&gt; </code></pre> </div> <p>If the <em>first</em> block in the list item is an indented code block, then by rule #2, the contents must be indented <em>one</em> space after the list marker:</p> <div class="example" id="example-221" data-section="List items"> <div class="examplenum"><a href="#example-221">Example 221</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><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><code class="language-html">&lt;pre&gt;&lt;code&gt;indented<span class="space"> </span>code &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;paragraph&lt;/p&gt; &lt;pre&gt;&lt;code&gt;more<span class="space"> </span>code &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <div class="example" id="example-222" data-section="List items"> <div class="examplenum"><a href="#example-222">Example 222</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">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><code class="language-html">&lt;ol&gt; &lt;li&gt; &lt;pre&gt;&lt;code&gt;indented<span class="space"> </span>code &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;paragraph&lt;/p&gt; &lt;pre&gt;&lt;code&gt;more<span class="space"> </span>code &lt;/code&gt;&lt;/pre&gt; &lt;/li&gt; &lt;/ol&gt; </code></pre> </div> <p>Note that an additional space indent is interpreted as space inside the code block:</p> <div class="example" id="example-223" data-section="List items"> <div class="examplenum"><a href="#example-223">Example 223</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">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><code class="language-html">&lt;ol&gt; &lt;li&gt; &lt;pre&gt;&lt;code&gt;<span class="space"> </span>indented<span class="space"> </span>code &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;paragraph&lt;/p&gt; &lt;pre&gt;&lt;code&gt;more<span class="space"> </span>code &lt;/code&gt;&lt;/pre&gt; &lt;/li&gt; &lt;/ol&gt; </code></pre> </div> <p>Note that rules #1 and #2 only apply to two cases: (a) cases in which the lines to be included in a list item begin with a <a href="#non-whitespace-character">non-whitespace character</a>, 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 class="example" id="example-224" data-section="List items"> <div class="examplenum"><a href="#example-224">Example 224</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><span class="space"> </span><span class="space"> </span><span class="space"> </span>foo bar </code></pre> <pre><code class="language-html">&lt;p&gt;foo&lt;/p&gt; &lt;p&gt;bar&lt;/p&gt; </code></pre> </div> <div class="example" id="example-225" data-section="List items"> <div class="examplenum"><a href="#example-225">Example 225</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">-<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><code class="language-html">&lt;ul&gt; &lt;li&gt;foo&lt;/li&gt; &lt;/ul&gt; &lt;p&gt;bar&lt;/p&gt; </code></pre> </div> <p>This is not a significant restriction, because when a block begins with 1-3 spaces indent, the indentation can always be removed without a change in interpretation, allowing rule #1 to be applied. So, in the above case:</p> <div class="example" id="example-226" data-section="List items"> <div class="examplenum"><a href="#example-226">Example 226</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">-<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><code class="language-html">&lt;ul&gt; &lt;li&gt; &lt;p&gt;foo&lt;/p&gt; &lt;p&gt;bar&lt;/p&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> </div> <ol start="3"> <li><strong>Item starting with a blank line.</strong> If a sequence of lines <em>Ls</em> starting with a single <a href="#blank-line">blank line</a> constitute a (possibly empty) sequence of blocks <em>Bs</em>, not separated from each other by more than one blank line, and <em>M</em> is a list marker of width <em>W</em>, then the result of prepending <em>M</em> 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>Here are some list items that start with a blank line but are not empty:</p> <div class="example" id="example-227" data-section="List items"> <div class="examplenum"><a href="#example-227">Example 227</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">- <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>``` - <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><code class="language-html">&lt;ul&gt; &lt;li&gt;foo&lt;/li&gt; &lt;li&gt; &lt;pre&gt;&lt;code&gt;bar &lt;/code&gt;&lt;/pre&gt; &lt;/li&gt; &lt;li&gt; &lt;pre&gt;&lt;code&gt;baz &lt;/code&gt;&lt;/pre&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> </div> <p>A list item can begin with at most one blank line. In the following example, <code>foo</code> is not part of the list item:</p> <div class="example" id="example-228" data-section="List items"> <div class="examplenum"><a href="#example-228">Example 228</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">- <span class="space"> </span><span class="space"> </span>foo </code></pre> <pre><code class="language-html">&lt;ul&gt; &lt;li&gt;&lt;/li&gt; &lt;/ul&gt; &lt;p&gt;foo&lt;/p&gt; </code></pre> </div> <p>Here is an empty bullet list item:</p> <div class="example" id="example-229" data-section="List items"> <div class="examplenum"><a href="#example-229">Example 229</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">-<span class="space"> </span>foo - -<span class="space"> </span>bar </code></pre> <pre><code class="language-html">&lt;ul&gt; &lt;li&gt;foo&lt;/li&gt; &lt;li&gt;&lt;/li&gt; &lt;li&gt;bar&lt;/li&gt; &lt;/ul&gt; </code></pre> </div> <p>It does not matter whether there are spaces following the <a href="#list-marker">list marker</a>:</p> <div class="example" id="example-230" data-section="List items"> <div class="examplenum"><a href="#example-230">Example 230</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">-<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><code class="language-html">&lt;ul&gt; &lt;li&gt;foo&lt;/li&gt; &lt;li&gt;&lt;/li&gt; &lt;li&gt;bar&lt;/li&gt; &lt;/ul&gt; </code></pre> </div> <p>Here is an empty ordered list item:</p> <div class="example" id="example-231" data-section="List items"> <div class="examplenum"><a href="#example-231">Example 231</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">1.<span class="space"> </span>foo 2. 3.<span class="space"> </span>bar </code></pre> <pre><code class="language-html">&lt;ol&gt; &lt;li&gt;foo&lt;/li&gt; &lt;li&gt;&lt;/li&gt; &lt;li&gt;bar&lt;/li&gt; &lt;/ol&gt; </code></pre> </div> <p>A list may start or end with an empty list item:</p> <div class="example" id="example-232" data-section="List items"> <div class="examplenum"><a href="#example-232">Example 232</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">* </code></pre> <pre><code class="language-html">&lt;ul&gt; &lt;li&gt;&lt;/li&gt; &lt;/ul&gt; </code></pre> </div> <ol start="4"> <li><strong>Indentation.</strong> If a sequence of lines <em>Ls</em> constitutes a list item according to rule #1, #2, or #3, then the result of indenting each line of <em>Ls</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 class="example" id="example-233" data-section="List items"> <div class="examplenum"><a href="#example-233">Example 233</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><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>&gt;<span class="space"> </span>A<span class="space"> </span>block<span class="space"> </span>quote. </code></pre> <pre><code class="language-html">&lt;ol&gt; &lt;li&gt; &lt;p&gt;A<span class="space"> </span>paragraph with<span class="space"> </span>two<span class="space"> </span>lines.&lt;/p&gt; &lt;pre&gt;&lt;code&gt;indented<span class="space"> </span>code &lt;/code&gt;&lt;/pre&gt; &lt;blockquote&gt; &lt;p&gt;A<span class="space"> </span>block<span class="space"> </span>quote.&lt;/p&gt; &lt;/blockquote&gt; &lt;/li&gt; &lt;/ol&gt; </code></pre> </div> <p>Indented two spaces:</p> <div class="example" id="example-234" data-section="List items"> <div class="examplenum"><a href="#example-234">Example 234</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><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>&gt;<span class="space"> </span>A<span class="space"> </span>block<span class="space"> </span>quote. </code></pre> <pre><code class="language-html">&lt;ol&gt; &lt;li&gt; &lt;p&gt;A<span class="space"> </span>paragraph with<span class="space"> </span>two<span class="space"> </span>lines.&lt;/p&gt; &lt;pre&gt;&lt;code&gt;indented<span class="space"> </span>code &lt;/code&gt;&lt;/pre&gt; &lt;blockquote&gt; &lt;p&gt;A<span class="space"> </span>block<span class="space"> </span>quote.&lt;/p&gt; &lt;/blockquote&gt; &lt;/li&gt; &lt;/ol&gt; </code></pre> </div> <p>Indented three spaces:</p> <div class="example" id="example-235" data-section="List items"> <div class="examplenum"><a href="#example-235">Example 235</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><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>&gt;<span class="space"> </span>A<span class="space"> </span>block<span class="space"> </span>quote. </code></pre> <pre><code class="language-html">&lt;ol&gt; &lt;li&gt; &lt;p&gt;A<span class="space"> </span>paragraph with<span class="space"> </span>two<span class="space"> </span>lines.&lt;/p&gt; &lt;pre&gt;&lt;code&gt;indented<span class="space"> </span>code &lt;/code&gt;&lt;/pre&gt; &lt;blockquote&gt; &lt;p&gt;A<span class="space"> </span>block<span class="space"> </span>quote.&lt;/p&gt; &lt;/blockquote&gt; &lt;/li&gt; &lt;/ol&gt; </code></pre> </div> <p>Four spaces indent gives a code block:</p> <div class="example" id="example-236" data-section="List items"> <div class="examplenum"><a href="#example-236">Example 236</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><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>&gt;<span class="space"> </span>A<span class="space"> </span>block<span class="space"> </span>quote. </code></pre> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;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>&amp;gt;<span class="space"> </span>A<span class="space"> </span>block<span class="space"> </span>quote. &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <ol start="5"> <li><strong>Laziness.</strong> If a string of lines <em>Ls</em> constitute a <a href="#list-items">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 <a href="#non-whitespace-character">non-whitespace character</a> 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 class="example" id="example-237" data-section="List items"> <div class="examplenum"><a href="#example-237">Example 237</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><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>&gt;<span class="space"> </span>A<span class="space"> </span>block<span class="space"> </span>quote. </code></pre> <pre><code class="language-html">&lt;ol&gt; &lt;li&gt; &lt;p&gt;A<span class="space"> </span>paragraph with<span class="space"> </span>two<span class="space"> </span>lines.&lt;/p&gt; &lt;pre&gt;&lt;code&gt;indented<span class="space"> </span>code &lt;/code&gt;&lt;/pre&gt; &lt;blockquote&gt; &lt;p&gt;A<span class="space"> </span>block<span class="space"> </span>quote.&lt;/p&gt; &lt;/blockquote&gt; &lt;/li&gt; &lt;/ol&gt; </code></pre> </div> <p>Indentation can be partially deleted:</p> <div class="example" id="example-238" data-section="List items"> <div class="examplenum"><a href="#example-238">Example 238</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><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><code class="language-html">&lt;ol&gt; &lt;li&gt;A<span class="space"> </span>paragraph with<span class="space"> </span>two<span class="space"> </span>lines.&lt;/li&gt; &lt;/ol&gt; </code></pre> </div> <p>These examples show how laziness can work in nested structures:</p> <div class="example" id="example-239" data-section="List items"> <div class="examplenum"><a href="#example-239">Example 239</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&gt;<span class="space"> </span>1.<span class="space"> </span>&gt;<span class="space"> </span>Blockquote continued<span class="space"> </span>here. </code></pre> <pre><code class="language-html">&lt;blockquote&gt; &lt;ol&gt; &lt;li&gt; &lt;blockquote&gt; &lt;p&gt;Blockquote continued<span class="space"> </span>here.&lt;/p&gt; &lt;/blockquote&gt; &lt;/li&gt; &lt;/ol&gt; &lt;/blockquote&gt; </code></pre> </div> <div class="example" id="example-240" data-section="List items"> <div class="examplenum"><a href="#example-240">Example 240</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&gt;<span class="space"> </span>1.<span class="space"> </span>&gt;<span class="space"> </span>Blockquote &gt;<span class="space"> </span>continued<span class="space"> </span>here. </code></pre> <pre><code class="language-html">&lt;blockquote&gt; &lt;ol&gt; &lt;li&gt; &lt;blockquote&gt; &lt;p&gt;Blockquote continued<span class="space"> </span>here.&lt;/p&gt; &lt;/blockquote&gt; &lt;/li&gt; &lt;/ol&gt; &lt;/blockquote&gt; </code></pre> </div> <ol start="6"> <li><strong>That’s all.</strong> Nothing that is not counted as a list item by rules #1–5 counts as a <a href="#list-items">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 class="example" id="example-241" data-section="List items"> <div class="examplenum"><a href="#example-241">Example 241</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">-<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><code class="language-html">&lt;ul&gt; &lt;li&gt;foo &lt;ul&gt; &lt;li&gt;bar &lt;ul&gt; &lt;li&gt;baz&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> </div> <p>One is not enough:</p> <div class="example" id="example-242" data-section="List items"> <div class="examplenum"><a href="#example-242">Example 242</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">-<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><code class="language-html">&lt;ul&gt; &lt;li&gt;foo&lt;/li&gt; &lt;li&gt;bar&lt;/li&gt; &lt;li&gt;baz&lt;/li&gt; &lt;/ul&gt; </code></pre> </div> <p>Here we need four, because the list marker is wider:</p> <div class="example" id="example-243" data-section="List items"> <div class="examplenum"><a href="#example-243">Example 243</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">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><code class="language-html">&lt;ol<span class="space"> </span>start=&quot;10&quot;&gt; &lt;li&gt;foo &lt;ul&gt; &lt;li&gt;bar&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ol&gt; </code></pre> </div> <p>Three is not enough:</p> <div class="example" id="example-244" data-section="List items"> <div class="examplenum"><a href="#example-244">Example 244</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">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><code class="language-html">&lt;ol<span class="space"> </span>start=&quot;10&quot;&gt; &lt;li&gt;foo&lt;/li&gt; &lt;/ol&gt; &lt;ul&gt; &lt;li&gt;bar&lt;/li&gt; &lt;/ul&gt; </code></pre> </div> <p>A list may be the first block in a list item:</p> <div class="example" id="example-245" data-section="List items"> <div class="examplenum"><a href="#example-245">Example 245</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">-<span class="space"> </span>-<span class="space"> </span>foo </code></pre> <pre><code class="language-html">&lt;ul&gt; &lt;li&gt; &lt;ul&gt; &lt;li&gt;foo&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> </div> <div class="example" id="example-246" data-section="List items"> <div class="examplenum"><a href="#example-246">Example 246</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">1.<span class="space"> </span>-<span class="space"> </span>2.<span class="space"> </span>foo </code></pre> <pre><code class="language-html">&lt;ol&gt; &lt;li&gt; &lt;ul&gt; &lt;li&gt; &lt;ol<span class="space"> </span>start=&quot;2&quot;&gt; &lt;li&gt;foo&lt;/li&gt; &lt;/ol&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ol&gt; </code></pre> </div> <p>A list item can contain a header:</p> <div class="example" id="example-247" data-section="List items"> <div class="examplenum"><a href="#example-247">Example 247</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">-<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><code class="language-html">&lt;ul&gt; &lt;li&gt; &lt;h1&gt;Foo&lt;/h1&gt; &lt;/li&gt; &lt;li&gt; &lt;h2&gt;Bar&lt;/h2&gt; baz&lt;/li&gt; &lt;/ul&gt; </code></pre> </div> <h3><a id="motivation"></a><span class="number">5.2.1</span> Motivation</h3> <p>John Gruber’s Markdown spec says the following about list items:</p> <ol> <li> <p>“List markers typically start at the left margin, but may be indented by up to three spaces. List markers must be followed by one or more spaces or a tab.”</p> </li> <li> <p>“To make lists look nice, you can wrap items with hanging indents…. But if you don’t want to, you don’t have to.”</p> </li> <li> <p>“List items may consist of multiple paragraphs. Each subsequent paragraph in a list item must be indented by either 4 spaces or one tab.”</p> </li> <li> <p>“It looks nice if you indent every line of the subsequent paragraphs, but here again, Markdown will allow you to be lazy.”</p> </li> <li> <p>“To put a blockquote within a list item, the blockquote’s <code>&gt;</code> delimiters need to be indented.”</p> </li> <li> <p>“To put a code block within a list item, the code block needs to be indented twice — 8 spaces or two tabs.”</p> </li> </ol> <p>These rules specify that a paragraph under a list item must be indented four spaces (presumably, from the left margin, rather than the start of the list marker, but this is not said), and that code under a list item must be indented eight spaces instead of the usual four. They also say that a block quote must be indented, but not by how much; however, the example given has four spaces indentation. Although nothing is said about other kinds of block-level content, it is certainly reasonable to infer that <em>all</em> block elements under a list item, including other lists, must be indented four spaces. This principle has been called the <em>four-space rule</em>.</p> <p>The four-space rule is clear and principled, and if the reference implementation <code>Markdown.pl</code> had followed it, it probably would have become the standard. However, <code>Markdown.pl</code> allowed paragraphs and sublists to start with only two spaces indentation, at least on the outer level. Worse, its behavior was inconsistent: a sublist of an outer-level list needed two spaces indentation, but a sublist of this sublist needed three spaces. It is not surprising, then, that different implementations of Markdown have developed very different rules for determining what comes under a list item. (Pandoc and python-Markdown, for example, stuck with Gruber’s syntax description and the four-space rule, while discount, redcarpet, marked, PHP Markdown, and others followed <code>Markdown.pl</code>’s behavior more closely.)</p> <p>Unfortunately, given the divergences between implementations, there is no way to give a spec for list items that will be guaranteed not to break any existing documents. However, the spec given here should correctly handle lists formatted with either the four-space rule or the more forgiving <code>Markdown.pl</code> behavior, provided they are laid out in a way that is natural for a human to read.</p> <p>The strategy here is to let the width and indentation of the list marker determine the indentation necessary for blocks to fall under the list item, rather than having a fixed and arbitrary number. The writer can think of the body of the list item as a unit which gets indented to the right enough to fit the list marker (and any indentation on the list marker). (The laziness rule, #5, 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><code class="language-markdown">- foo bar - baz </code></pre> <p>should be parsed as two lists with an intervening paragraph,</p> <pre><code class="language-html">&lt;ul&gt; &lt;li&gt;foo&lt;/li&gt; &lt;/ul&gt; &lt;p&gt;bar&lt;/p&gt; &lt;ul&gt; &lt;li&gt;baz&lt;/li&gt; &lt;/ul&gt; </code></pre> <p>as the four-space rule demands, rather than a single list,</p> <pre><code class="language-html">&lt;ul&gt; &lt;li&gt; &lt;p&gt;foo&lt;/p&gt; &lt;p&gt;bar&lt;/p&gt; &lt;ul&gt; &lt;li&gt;baz&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> <p>The choice of four spaces is arbitrary. It can be learned, but it is not likely to be guessed, and it trips up beginners regularly.</p> <p>Would it help to adopt a two-space rule? The problem is that such a rule, together with the rule allowing 1–3 spaces indentation of the initial list marker, allows text that is indented <em>less than</em> the original list marker to be included in the list item. For example, <code>Markdown.pl</code> parses</p> <pre><code class="language-markdown"> - one two </code></pre> <p>as a single list item, with <code>two</code> a continuation paragraph:</p> <pre><code class="language-html">&lt;ul&gt; &lt;li&gt; &lt;p&gt;one&lt;/p&gt; &lt;p&gt;two&lt;/p&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> <p>and similarly</p> <pre><code class="language-markdown">&gt; - one &gt; &gt; two </code></pre> <p>as</p> <pre><code class="language-html">&lt;blockquote&gt; &lt;ul&gt; &lt;li&gt; &lt;p&gt;one&lt;/p&gt; &lt;p&gt;two&lt;/p&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/blockquote&gt; </code></pre> <p>This is extremely unintuitive.</p> <p>Rather than requiring a fixed indent from the margin, we could require a fixed indent (say, two spaces, or even one space) from the list marker (which may itself be indented). This proposal would remove the last anomaly discussed. Unlike the spec presented above, it would count the following as a list item with a subparagraph, even though the paragraph <code>bar</code> is not indented as far as the first paragraph <code>foo</code>:</p> <pre><code class="language-markdown"> 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><code class="language-markdown">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><a id="lists"></a><span class="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-lines">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 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>&lt;p&gt;</code> tags, while paragraphs in a tight list are not.)</p> <p>Changing the bullet or ordered list delimiter starts a new list:</p> <div class="example" id="example-248" data-section="Lists"> <div class="examplenum"><a href="#example-248">Example 248</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">-<span class="space"> </span>foo -<span class="space"> </span>bar +<span class="space"> </span>baz </code></pre> <pre><code class="language-html">&lt;ul&gt; &lt;li&gt;foo&lt;/li&gt; &lt;li&gt;bar&lt;/li&gt; &lt;/ul&gt; &lt;ul&gt; &lt;li&gt;baz&lt;/li&gt; &lt;/ul&gt; </code></pre> </div> <div class="example" id="example-249" data-section="Lists"> <div class="examplenum"><a href="#example-249">Example 249</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">1.<span class="space"> </span>foo 2.<span class="space"> </span>bar 3)<span class="space"> </span>baz </code></pre> <pre><code class="language-html">&lt;ol&gt; &lt;li&gt;foo&lt;/li&gt; &lt;li&gt;bar&lt;/li&gt; &lt;/ol&gt; &lt;ol<span class="space"> </span>start=&quot;3&quot;&gt; &lt;li&gt;baz&lt;/li&gt; &lt;/ol&gt; </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 class="example" id="example-250" data-section="Lists"> <div class="examplenum"><a href="#example-250">Example 250</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">Foo -<span class="space"> </span>bar -<span class="space"> </span>baz </code></pre> <pre><code class="language-html">&lt;p&gt;Foo&lt;/p&gt; &lt;ul&gt; &lt;li&gt;bar&lt;/li&gt; &lt;li&gt;baz&lt;/li&gt; &lt;/ul&gt; </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 class="example" id="example-251" data-section="Lists"> <div class="examplenum"><a href="#example-251">Example 251</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">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><code class="language-html">&lt;p&gt;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&lt;/p&gt; &lt;ol<span class="space"> </span>start=&quot;14&quot;&gt; &lt;li&gt;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.&lt;/li&gt; &lt;/ol&gt; </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 chunk of text has a certain meaning, it will continue to have the same meaning when put into a container block (such as a list item or blockquote).</p> </blockquote> <p>(Indeed, the spec for <a href="#list-items">list items</a> and <a href="#block-quotes">block quotes</a> presupposes this principle.) 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>&lt;p&gt;</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> <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 class="example" id="example-252" data-section="Lists"> <div class="examplenum"><a href="#example-252">Example 252</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">-<span class="space"> </span>foo -<span class="space"> </span>bar -<span class="space"> </span>baz </code></pre> <pre><code class="language-html">&lt;ul&gt; &lt;li&gt; &lt;p&gt;foo&lt;/p&gt; &lt;/li&gt; &lt;li&gt; &lt;p&gt;bar&lt;/p&gt; &lt;/li&gt; &lt;/ul&gt; &lt;ul&gt; &lt;li&gt;baz&lt;/li&gt; &lt;/ul&gt; </code></pre> </div> <p>As illustrated above in the section on <a href="#list-items">list items</a>, two blank lines between blocks <em>within</em> a list item will also end a list:</p> <div class="example" id="example-253" data-section="Lists"> <div class="examplenum"><a href="#example-253">Example 253</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">-<span class="space"> </span>foo <span class="space"> </span><span class="space"> </span>bar -<span class="space"> </span>baz </code></pre> <pre><code class="language-html">&lt;ul&gt; &lt;li&gt;foo&lt;/li&gt; &lt;/ul&gt; &lt;p&gt;bar&lt;/p&gt; &lt;ul&gt; &lt;li&gt;baz&lt;/li&gt; &lt;/ul&gt; </code></pre> </div> <p>Indeed, two blank lines will end <em>all</em> containing lists:</p> <div class="example" id="example-254" data-section="Lists"> <div class="examplenum"><a href="#example-254">Example 254</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">-<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><code class="language-html">&lt;ul&gt; &lt;li&gt;foo &lt;ul&gt; &lt;li&gt;bar &lt;ul&gt; &lt;li&gt;baz&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; &lt;pre&gt;&lt;code&gt;<span class="space"> </span><span class="space"> </span>bim &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <p>Thus, two blank lines can be used to separate consecutive lists of the same type, or to separate a list from an indented code block that would otherwise be parsed as a subparagraph of the final list item:</p> <div class="example" id="example-255" data-section="Lists"> <div class="examplenum"><a href="#example-255">Example 255</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">-<span class="space"> </span>foo -<span class="space"> </span>bar -<span class="space"> </span>baz -<span class="space"> </span>bim </code></pre> <pre><code class="language-html">&lt;ul&gt; &lt;li&gt;foo&lt;/li&gt; &lt;li&gt;bar&lt;/li&gt; &lt;/ul&gt; &lt;ul&gt; &lt;li&gt;baz&lt;/li&gt; &lt;li&gt;bim&lt;/li&gt; &lt;/ul&gt; </code></pre> </div> <div class="example" id="example-256" data-section="Lists"> <div class="examplenum"><a href="#example-256">Example 256</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">-<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><code class="language-html">&lt;ul&gt; &lt;li&gt; &lt;p&gt;foo&lt;/p&gt; &lt;p&gt;notcode&lt;/p&gt; &lt;/li&gt; &lt;li&gt; &lt;p&gt;foo&lt;/p&gt; &lt;/li&gt; &lt;/ul&gt; &lt;pre&gt;&lt;code&gt;code &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <p>List items need not be indented to the same level. The following list items will be treated as items at the same list level, since none is indented enough to belong to the previous list item:</p> <div class="example" id="example-257" data-section="Lists"> <div class="examplenum"><a href="#example-257">Example 257</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">-<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><span class="space"> </span>-<span class="space"> </span>e <span class="space"> </span><span class="space"> </span><span class="space"> </span>-<span class="space"> </span>f <span class="space"> </span><span class="space"> </span>-<span class="space"> </span>g <span class="space"> </span>-<span class="space"> </span>h -<span class="space"> </span>i </code></pre> <pre><code class="language-html">&lt;ul&gt; &lt;li&gt;a&lt;/li&gt; &lt;li&gt;b&lt;/li&gt; &lt;li&gt;c&lt;/li&gt; &lt;li&gt;d&lt;/li&gt; &lt;li&gt;e&lt;/li&gt; &lt;li&gt;f&lt;/li&gt; &lt;li&gt;g&lt;/li&gt; &lt;li&gt;h&lt;/li&gt; &lt;li&gt;i&lt;/li&gt; &lt;/ul&gt; </code></pre> </div> <div class="example" id="example-258" data-section="Lists"> <div class="examplenum"><a href="#example-258">Example 258</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">1.<span class="space"> </span>a <span class="space"> </span><span class="space"> </span>2.<span class="space"> </span>b <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>3.<span class="space"> </span>c </code></pre> <pre><code class="language-html">&lt;ol&gt; &lt;li&gt; &lt;p&gt;a&lt;/p&gt; &lt;/li&gt; &lt;li&gt; &lt;p&gt;b&lt;/p&gt; &lt;/li&gt; &lt;li&gt; &lt;p&gt;c&lt;/p&gt; &lt;/li&gt; &lt;/ol&gt; </code></pre> </div> <p>This is a loose list, because there is a blank line between two of the list items:</p> <div class="example" id="example-259" data-section="Lists"> <div class="examplenum"><a href="#example-259">Example 259</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">-<span class="space"> </span>a -<span class="space"> </span>b -<span class="space"> </span>c </code></pre> <pre><code class="language-html">&lt;ul&gt; &lt;li&gt; &lt;p&gt;a&lt;/p&gt; &lt;/li&gt; &lt;li&gt; &lt;p&gt;b&lt;/p&gt; &lt;/li&gt; &lt;li&gt; &lt;p&gt;c&lt;/p&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> </div> <p>So is this, with a empty second item:</p> <div class="example" id="example-260" data-section="Lists"> <div class="examplenum"><a href="#example-260">Example 260</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">*<span class="space"> </span>a * *<span class="space"> </span>c </code></pre> <pre><code class="language-html">&lt;ul&gt; &lt;li&gt; &lt;p&gt;a&lt;/p&gt; &lt;/li&gt; &lt;li&gt;&lt;/li&gt; &lt;li&gt; &lt;p&gt;c&lt;/p&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> </div> <p>These are loose lists, even though there is no space between the items, because one of the items directly contains two block-level elements with a blank line between them:</p> <div class="example" id="example-261" data-section="Lists"> <div class="examplenum"><a href="#example-261">Example 261</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">-<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><code class="language-html">&lt;ul&gt; &lt;li&gt; &lt;p&gt;a&lt;/p&gt; &lt;/li&gt; &lt;li&gt; &lt;p&gt;b&lt;/p&gt; &lt;p&gt;c&lt;/p&gt; &lt;/li&gt; &lt;li&gt; &lt;p&gt;d&lt;/p&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> </div> <div class="example" id="example-262" data-section="Lists"> <div class="examplenum"><a href="#example-262">Example 262</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">-<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><code class="language-html">&lt;ul&gt; &lt;li&gt; &lt;p&gt;a&lt;/p&gt; &lt;/li&gt; &lt;li&gt; &lt;p&gt;b&lt;/p&gt; &lt;/li&gt; &lt;li&gt; &lt;p&gt;d&lt;/p&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> </div> <p>This is a tight list, because the blank lines are in a code block:</p> <div class="example" id="example-263" data-section="Lists"> <div class="examplenum"><a href="#example-263">Example 263</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">-<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><code class="language-html">&lt;ul&gt; &lt;li&gt;a&lt;/li&gt; &lt;li&gt; &lt;pre&gt;&lt;code&gt;b &lt;/code&gt;&lt;/pre&gt; &lt;/li&gt; &lt;li&gt;c&lt;/li&gt; &lt;/ul&gt; </code></pre> </div> <p>This is a tight list, because the blank line is between two paragraphs of a sublist. So the sublist is loose while the outer list is tight:</p> <div class="example" id="example-264" data-section="Lists"> <div class="examplenum"><a href="#example-264">Example 264</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">-<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><code class="language-html">&lt;ul&gt; &lt;li&gt;a &lt;ul&gt; &lt;li&gt; &lt;p&gt;b&lt;/p&gt; &lt;p&gt;c&lt;/p&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li&gt;d&lt;/li&gt; &lt;/ul&gt; </code></pre> </div> <p>This is a tight list, because the blank line is inside the block quote:</p> <div class="example" id="example-265" data-section="Lists"> <div class="examplenum"><a href="#example-265">Example 265</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">*<span class="space"> </span>a <span class="space"> </span><span class="space"> </span>&gt;<span class="space"> </span>b <span class="space"> </span><span class="space"> </span>&gt; *<span class="space"> </span>c </code></pre> <pre><code class="language-html">&lt;ul&gt; &lt;li&gt;a &lt;blockquote&gt; &lt;p&gt;b&lt;/p&gt; &lt;/blockquote&gt; &lt;/li&gt; &lt;li&gt;c&lt;/li&gt; &lt;/ul&gt; </code></pre> </div> <p>This list is tight, because the consecutive block elements are not separated by blank lines:</p> <div class="example" id="example-266" data-section="Lists"> <div class="examplenum"><a href="#example-266">Example 266</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">-<span class="space"> </span>a <span class="space"> </span><span class="space"> </span>&gt;<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><code class="language-html">&lt;ul&gt; &lt;li&gt;a &lt;blockquote&gt; &lt;p&gt;b&lt;/p&gt; &lt;/blockquote&gt; &lt;pre&gt;&lt;code&gt;c &lt;/code&gt;&lt;/pre&gt; &lt;/li&gt; &lt;li&gt;d&lt;/li&gt; &lt;/ul&gt; </code></pre> </div> <p>A single-paragraph list is tight:</p> <div class="example" id="example-267" data-section="Lists"> <div class="examplenum"><a href="#example-267">Example 267</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">-<span class="space"> </span>a </code></pre> <pre><code class="language-html">&lt;ul&gt; &lt;li&gt;a&lt;/li&gt; &lt;/ul&gt; </code></pre> </div> <div class="example" id="example-268" data-section="Lists"> <div class="examplenum"><a href="#example-268">Example 268</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">-<span class="space"> </span>a <span class="space"> </span><span class="space"> </span>-<span class="space"> </span>b </code></pre> <pre><code class="language-html">&lt;ul&gt; &lt;li&gt;a &lt;ul&gt; &lt;li&gt;b&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> </div> <p>This list is loose, because of the blank line between the two block elements in the list item:</p> <div class="example" id="example-269" data-section="Lists"> <div class="examplenum"><a href="#example-269">Example 269</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">1.<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>bar </code></pre> <pre><code class="language-html">&lt;ol&gt; &lt;li&gt; &lt;pre&gt;&lt;code&gt;foo &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;bar&lt;/p&gt; &lt;/li&gt; &lt;/ol&gt; </code></pre> </div> <p>Here the outer list is loose, the inner list tight:</p> <div class="example" id="example-270" data-section="Lists"> <div class="examplenum"><a href="#example-270">Example 270</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">*<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><code class="language-html">&lt;ul&gt; &lt;li&gt; &lt;p&gt;foo&lt;/p&gt; &lt;ul&gt; &lt;li&gt;bar&lt;/li&gt; &lt;/ul&gt; &lt;p&gt;baz&lt;/p&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> </div> <div class="example" id="example-271" data-section="Lists"> <div class="examplenum"><a href="#example-271">Example 271</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">-<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><code class="language-html">&lt;ul&gt; &lt;li&gt; &lt;p&gt;a&lt;/p&gt; &lt;ul&gt; &lt;li&gt;b&lt;/li&gt; &lt;li&gt;c&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li&gt; &lt;p&gt;d&lt;/p&gt; &lt;ul&gt; &lt;li&gt;e&lt;/li&gt; &lt;li&gt;f&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> </div> <h1><a id="inlines"></a><span class="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 class="example" id="example-272" data-section="Inlines"> <div class="examplenum"><a href="#example-272">Example 272</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">`hi`lo` </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;code&gt;hi&lt;/code&gt;lo`&lt;/p&gt; </code></pre> </div> <p><code>hi</code> is parsed as code, leaving the backtick at the end as a literal backtick.</p> <h2><a id="backslash-escapes"></a><span class="number">6.1</span> Backslash escapes</h2> <p>Any ASCII punctuation character may be backslash-escaped:</p> <div class="example" id="example-273" data-section="Backslash escapes"> <div class="examplenum"><a href="#example-273">Example 273</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">\!\&quot;\#\$\%\&amp;\'\(\)\*\+\,\-\.\/\:\;\&lt;\=\&gt;\?\@\[\\\]\^\_\`\{\|\}\~ </code></pre> <pre><code class="language-html">&lt;p&gt;!&amp;quot;#$%&amp;amp;'()*+,-./:;&amp;lt;=&amp;gt;?@[\]^_`{|}~&lt;/p&gt; </code></pre> </div> <p>Backslashes before other characters are treated as literal backslashes:</p> <div class="example" id="example-274" data-section="Backslash escapes"> <div class="examplenum"><a href="#example-274">Example 274</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">\→\A\a\<span class="space"> </span>\3\φ\« </code></pre> <pre><code class="language-html">&lt;p&gt;\→\A\a\<span class="space"> </span>\3\φ\«&lt;/p&gt; </code></pre> </div> <p>Escaped characters are treated as regular characters and do not have their usual Markdown meanings:</p> <div class="example" id="example-275" data-section="Backslash escapes"> <div class="examplenum"><a href="#example-275">Example 275</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">\*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; </code></pre> <pre><code class="language-html">&lt;p&gt;*not<span class="space"> </span>emphasized* &amp;lt;br/&amp;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>&amp;quot;not<span class="space"> </span>a<span class="space"> </span>reference&amp;quot;&lt;/p&gt; </code></pre> </div> <p>If a backslash is itself escaped, the following character is not:</p> <div class="example" id="example-276" data-section="Backslash escapes"> <div class="examplenum"><a href="#example-276">Example 276</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">\\*emphasis* </code></pre> <pre><code class="language-html">&lt;p&gt;\&lt;em&gt;emphasis&lt;/em&gt;&lt;/p&gt; </code></pre> </div> <p>A backslash at the end of the line is a <a href="#hard-line-break">hard line break</a>:</p> <div class="example" id="example-277" data-section="Backslash escapes"> <div class="examplenum"><a href="#example-277">Example 277</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">foo\ bar </code></pre> <pre><code class="language-html">&lt;p&gt;foo&lt;br<span class="space"> </span>/&gt; bar&lt;/p&gt; </code></pre> </div> <p>Backslash escapes do not work in code blocks, code spans, autolinks, or raw HTML:</p> <div class="example" id="example-278" data-section="Backslash escapes"> <div class="examplenum"><a href="#example-278">Example 278</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">``<span class="space"> </span>\[\`<span class="space"> </span>`` </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;code&gt;\[\`&lt;/code&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-279" data-section="Backslash escapes"> <div class="examplenum"><a href="#example-279">Example 279</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>\[\] </code></pre> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;\[\] &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <div class="example" id="example-280" data-section="Backslash escapes"> <div class="examplenum"><a href="#example-280">Example 280</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">~~~ \[\] ~~~ </code></pre> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;\[\] &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <div class="example" id="example-281" data-section="Backslash escapes"> <div class="examplenum"><a href="#example-281">Example 281</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;http://example.com?find=\*&gt; </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;http://example.com?find=%5C*&quot;&gt;http://example.com?find=\*&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-282" data-section="Backslash escapes"> <div class="examplenum"><a href="#example-282">Example 282</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;a<span class="space"> </span>href=&quot;/bar\/)&quot;&gt; </code></pre> <pre><code class="language-html">&lt;a<span class="space"> </span>href=&quot;/bar\/)&quot;&gt; </code></pre> </div> <p>But they work in all other contexts, including URLs and link titles, link references, and <a href="#info-string">info strings</a> in <a href="#fenced-code-block">fenced code blocks</a>:</p> <div class="example" id="example-283" data-section="Backslash escapes"> <div class="examplenum"><a href="#example-283">Example 283</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo](/bar\*<span class="space"> </span>&quot;ti\*tle&quot;) </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/bar*&quot;<span class="space"> </span>title=&quot;ti*tle&quot;&gt;foo&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-284" data-section="Backslash escapes"> <div class="examplenum"><a href="#example-284">Example 284</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo] [foo]:<span class="space"> </span>/bar\*<span class="space"> </span>&quot;ti\*tle&quot; </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/bar*&quot;<span class="space"> </span>title=&quot;ti*tle&quot;&gt;foo&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-285" data-section="Backslash escapes"> <div class="examplenum"><a href="#example-285">Example 285</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">```<span class="space"> </span>foo\+bar foo ``` </code></pre> <pre><code class="language-html">&lt;pre&gt;&lt;code<span class="space"> </span>class=&quot;language-foo+bar&quot;&gt;foo &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <h2><a id="entities"></a><span class="number">6.2</span> Entities</h2> <p>With the goal of making this standard as HTML-agnostic as possible, all valid HTML entities (except in code blocks and code spans) are recognized as such and converted into Unicode characters before they are stored in the AST. This means that renderers to formats other than HTML need not be HTML-entity aware. HTML renderers may either escape Unicode characters as entities or leave them as they are. (However, <code>&quot;</code>, <code>&amp;</code>, <code>&lt;</code>, and <code>&gt;</code> must always be rendered as entities.)</p> <p><a id="name-entities" href="#name-entities" class="definition">Named entities</a> consist of <code>&amp;</code> + any of the valid HTML5 entity names + <code>;</code>. The <a href="https://html.spec.whatwg.org/multipage/entities.json">following document</a> is used as an authoritative source of the valid entity names and their corresponding code points.</p> <div class="example" id="example-286" data-section="Entities"> <div class="examplenum"><a href="#example-286">Example 286</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&amp;nbsp;<span class="space"> </span>&amp;amp;<span class="space"> </span>&amp;copy;<span class="space"> </span>&amp;AElig;<span class="space"> </span>&amp;Dcaron; &amp;frac34;<span class="space"> </span>&amp;HilbertSpace;<span class="space"> </span>&amp;DifferentialD; &amp;ClockwiseContourIntegral;<span class="space"> </span>&amp;ngE; </code></pre> <pre><code class="language-html">&lt;p&gt; <span class="space"> </span>&amp;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>≧̸&lt;/p&gt; </code></pre> </div> <p><a id="decimal-entities" href="#decimal-entities" class="definition">Decimal entities</a> consist of <code>&amp;#</code> + a string of 1–8 arabic digits + <code>;</code>. Again, these entities need to be recognised and transformed into their corresponding Unicode code points. Invalid Unicode code points will be replaced by the “unknown code point” character (<code>U+FFFD</code>). For security reasons, the code point <code>U+0000</code> will also be replaced by <code>U+FFFD</code>.</p> <div class="example" id="example-287" data-section="Entities"> <div class="examplenum"><a href="#example-287">Example 287</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&amp;#35;<span class="space"> </span>&amp;#1234;<span class="space"> </span>&amp;#992;<span class="space"> </span>&amp;#98765432;<span class="space"> </span>&amp;#0; </code></pre> <pre><code class="language-html">&lt;p&gt;#<span class="space"> </span>Ӓ<span class="space"> </span>Ϡ<span class="space"> </span>�<span class="space"> </span>�&lt;/p&gt; </code></pre> </div> <p><a id="hexadecimal-entities" href="#hexadecimal-entities" class="definition">Hexadecimal entities</a> consist of <code>&amp;#</code> + either <code>X</code> or <code>x</code> + a string of 1-8 hexadecimal digits + <code>;</code>. They will also be parsed and turned into the corresponding Unicode code points in the AST.</p> <div class="example" id="example-288" data-section="Entities"> <div class="examplenum"><a href="#example-288">Example 288</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&amp;#X22;<span class="space"> </span>&amp;#XD06;<span class="space"> </span>&amp;#xcab; </code></pre> <pre><code class="language-html">&lt;p&gt;&amp;quot;<span class="space"> </span>ആ<span class="space"> </span>ಫ&lt;/p&gt; </code></pre> </div> <p>Here are some nonentities:</p> <div class="example" id="example-289" data-section="Entities"> <div class="examplenum"><a href="#example-289">Example 289</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&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?; </code></pre> <pre><code class="language-html">&lt;p&gt;&amp;amp;nbsp<span class="space"> </span>&amp;amp;x;<span class="space"> </span>&amp;amp;#;<span class="space"> </span>&amp;amp;#x;<span class="space"> </span>&amp;amp;ThisIsWayTooLongToBeAnEntityIsntIt;<span class="space"> </span>&amp;amp;hi?;&lt;/p&gt; </code></pre> </div> <p>Although HTML5 does accept some entities without a trailing semicolon (such as <code>&amp;copy</code>), these are not recognized as entities here, because it makes the grammar too ambiguous:</p> <div class="example" id="example-290" data-section="Entities"> <div class="examplenum"><a href="#example-290">Example 290</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&amp;copy </code></pre> <pre><code class="language-html">&lt;p&gt;&amp;amp;copy&lt;/p&gt; </code></pre> </div> <p>Strings that are not on the list of HTML5 named entities are not recognized as entities either:</p> <div class="example" id="example-291" data-section="Entities"> <div class="examplenum"><a href="#example-291">Example 291</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&amp;MadeUpEntity; </code></pre> <pre><code class="language-html">&lt;p&gt;&amp;amp;MadeUpEntity;&lt;/p&gt; </code></pre> </div> <p>Entities are recognized in any context besides code spans or code blocks, including raw HTML, URLs, <a href="#link-title">link titles</a>, and <a href="#info-string">fenced code blocks</a>:</p> <div class="example" id="example-292" data-section="Entities"> <div class="examplenum"><a href="#example-292">Example 292</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;a<span class="space"> </span>href=&quot;&amp;ouml;&amp;ouml;.html&quot;&gt; </code></pre> <pre><code class="language-html">&lt;a<span class="space"> </span>href=&quot;&amp;ouml;&amp;ouml;.html&quot;&gt; </code></pre> </div> <div class="example" id="example-293" data-section="Entities"> <div class="examplenum"><a href="#example-293">Example 293</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo](/f&amp;ouml;&amp;ouml;<span class="space"> </span>&quot;f&amp;ouml;&amp;ouml;&quot;) </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/f%C3%B6%C3%B6&quot;<span class="space"> </span>title=&quot;föö&quot;&gt;foo&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-294" data-section="Entities"> <div class="examplenum"><a href="#example-294">Example 294</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo] [foo]:<span class="space"> </span>/f&amp;ouml;&amp;ouml;<span class="space"> </span>&quot;f&amp;ouml;&amp;ouml;&quot; </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/f%C3%B6%C3%B6&quot;<span class="space"> </span>title=&quot;föö&quot;&gt;foo&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-295" data-section="Entities"> <div class="examplenum"><a href="#example-295">Example 295</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">```<span class="space"> </span>f&amp;ouml;&amp;ouml; foo ``` </code></pre> <pre><code class="language-html">&lt;pre&gt;&lt;code<span class="space"> </span>class=&quot;language-föö&quot;&gt;foo &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <p>Entities are treated as literal text in code spans and code blocks:</p> <div class="example" id="example-296" data-section="Entities"> <div class="examplenum"><a href="#example-296">Example 296</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">`f&amp;ouml;&amp;ouml;` </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;code&gt;f&amp;amp;ouml;&amp;amp;ouml;&lt;/code&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-297" data-section="Entities"> <div class="examplenum"><a href="#example-297">Example 297</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown"><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>f&amp;ouml;f&amp;ouml; </code></pre> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;f&amp;amp;ouml;f&amp;amp;ouml; &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> <h2><a id="code-spans"></a><span class="number">6.3</span> Code spans</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 <a href="#line-ending">line endings</a> removed, and <a href="#whitespace">whitespace</a> collapsed to single spaces.</p> <p>This is a simple code span:</p> <div class="example" id="example-298" data-section="Code spans"> <div class="examplenum"><a href="#example-298">Example 298</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">`foo` </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;code&gt;foo&lt;/code&gt;&lt;/p&gt; </code></pre> </div> <p>Here two backticks are used, because the code contains a backtick. This example also illustrates stripping of leading and trailing spaces:</p> <div class="example" id="example-299" data-section="Code spans"> <div class="examplenum"><a href="#example-299">Example 299</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">``<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><code class="language-html">&lt;p&gt;&lt;code&gt;foo<span class="space"> </span>`<span class="space"> </span>bar&lt;/code&gt;&lt;/p&gt; </code></pre> </div> <p>This example shows the motivation for stripping leading and trailing spaces:</p> <div class="example" id="example-300" data-section="Code spans"> <div class="examplenum"><a href="#example-300">Example 300</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">`<span class="space"> </span>``<span class="space"> </span>` </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;code&gt;``&lt;/code&gt;&lt;/p&gt; </code></pre> </div> <p><a href="#line-ending">Line endings</a> are treated like spaces:</p> <div class="example" id="example-301" data-section="Code spans"> <div class="examplenum"><a href="#example-301">Example 301</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">`` foo `` </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;code&gt;foo&lt;/code&gt;&lt;/p&gt; </code></pre> </div> <p>Interior spaces and <a href="#line-ending">line endings</a> are collapsed into single spaces, just as they would be by a browser:</p> <div class="example" id="example-302" data-section="Code spans"> <div class="examplenum"><a href="#example-302">Example 302</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">`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><code class="language-html">&lt;p&gt;&lt;code&gt;foo<span class="space"> </span>bar<span class="space"> </span>baz&lt;/code&gt;&lt;/p&gt; </code></pre> </div> <p>Q: Why not just leave the spaces, since browsers will collapse them anyway? A: Because we might be targeting a non-HTML format, and we shouldn’t rely on HTML-specific rendering assumptions.</p> <p>(Existing implementations differ in their treatment of internal spaces and <a href="#line-ending">line endings</a>. Some, including <code>Markdown.pl</code> and <code>showdown</code>, convert an internal <a href="#line-ending">line ending</a> into a <code>&lt;br /&gt;</code> tag. But this makes things difficult for those who like to hard-wrap their paragraphs, since a line break in the midst of a code span will cause an unintended line break in the output. Others just leave internal spaces as they are, which is fine if only HTML is being targeted.)</p> <div class="example" id="example-303" data-section="Code spans"> <div class="examplenum"><a href="#example-303">Example 303</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">`foo<span class="space"> </span>``<span class="space"> </span>bar` </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;code&gt;foo<span class="space"> </span>``<span class="space"> </span>bar&lt;/code&gt;&lt;/p&gt; </code></pre> </div> <p>Note that backslash escapes do not work in code spans. All backslashes are treated literally:</p> <div class="example" id="example-304" data-section="Code spans"> <div class="examplenum"><a href="#example-304">Example 304</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">`foo\`bar` </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;code&gt;foo\&lt;/code&gt;bar`&lt;/p&gt; </code></pre> </div> <p>Backslash escapes are never needed, because one can always choose a string of <em>n</em> backtick characters as delimiters, where the code does not contain any strings of exactly <em>n</em> backtick characters.</p> <p>Code span backticks have higher precedence than any other inline constructs except HTML tags and autolinks. Thus, for example, this is not parsed as emphasized text, since the second <code>*</code> is part of a code span:</p> <div class="example" id="example-305" data-section="Code spans"> <div class="examplenum"><a href="#example-305">Example 305</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">*foo`*` </code></pre> <pre><code class="language-html">&lt;p&gt;*foo&lt;code&gt;*&lt;/code&gt;&lt;/p&gt; </code></pre> </div> <p>And this is not parsed as a link:</p> <div class="example" id="example-306" data-section="Code spans"> <div class="examplenum"><a href="#example-306">Example 306</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[not<span class="space"> </span>a<span class="space"> </span>`link](/foo`) </code></pre> <pre><code class="language-html">&lt;p&gt;[not<span class="space"> </span>a<span class="space"> </span>&lt;code&gt;link](/foo&lt;/code&gt;)&lt;/p&gt; </code></pre> </div> <p>Code spans, HTML tags, and autolinks have the same precedence. Thus, this is code:</p> <div class="example" id="example-307" data-section="Code spans"> <div class="examplenum"><a href="#example-307">Example 307</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">`&lt;a<span class="space"> </span>href=&quot;`&quot;&gt;` </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;code&gt;&amp;lt;a<span class="space"> </span>href=&amp;quot;&lt;/code&gt;&amp;quot;&amp;gt;`&lt;/p&gt; </code></pre> </div> <p>But this is an HTML tag:</p> <div class="example" id="example-308" data-section="Code spans"> <div class="examplenum"><a href="#example-308">Example 308</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;a<span class="space"> </span>href=&quot;`&quot;&gt;` </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;`&quot;&gt;`&lt;/p&gt; </code></pre> </div> <p>And this is code:</p> <div class="example" id="example-309" data-section="Code spans"> <div class="examplenum"><a href="#example-309">Example 309</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">`&lt;http://foo.bar.`baz&gt;` </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;code&gt;&amp;lt;http://foo.bar.&lt;/code&gt;baz&amp;gt;`&lt;/p&gt; </code></pre> </div> <p>But this is an autolink:</p> <div class="example" id="example-310" data-section="Code spans"> <div class="examplenum"><a href="#example-310">Example 310</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;http://foo.bar.`baz&gt;` </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;http://foo.bar.%60baz&quot;&gt;http://foo.bar.`baz&lt;/a&gt;`&lt;/p&gt; </code></pre> </div> <p>When a backtick string is not closed by a matching backtick string, we just have literal backticks:</p> <div class="example" id="example-311" data-section="Code spans"> <div class="examplenum"><a href="#example-311">Example 311</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">```foo`` </code></pre> <pre><code class="language-html">&lt;p&gt;```foo``&lt;/p&gt; </code></pre> </div> <div class="example" id="example-312" data-section="Code spans"> <div class="examplenum"><a href="#example-312">Example 312</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">`foo </code></pre> <pre><code class="language-html">&lt;p&gt;`foo&lt;/p&gt; </code></pre> </div> <h2><a id="emphasis-and-strong-emphasis"></a><span class="number">6.4</span> Emphasis and strong emphasis</h2> <p>John Gruber’s original <a href="http://daringfireball.net/projects/markdown/syntax#em">Markdown syntax description</a> says:</p> <blockquote> <p>Markdown treats asterisks (<code>*</code>) and underscores (<code>_</code>) as indicators of emphasis. Text wrapped with one <code>*</code> or <code>_</code> will be wrapped with an HTML <code>&lt;em&gt;</code> tag; double <code>*</code>’s or <code>_</code>’s will be wrapped with an HTML <code>&lt;strong&gt;</code> tag.</p> </blockquote> <p>This is enough for most users, but these rules leave much undecided, especially when it comes to nested emphasis. The original <code>Markdown.pl</code> test suite makes it clear that triple <code>***</code> and <code>___</code> delimiters can be used for strong emphasis, and most implementations have also allowed the following patterns:</p> <pre><code class="language-markdown">***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><code class="language-markdown">*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><code class="language-markdown">internal emphasis: foo*bar*baz no emphasis: foo_bar_baz </code></pre> <p>The rules given below capture all of these patterns, while allowing for efficient parsing strategies that do not backtrack.</p> <p>First, some definitions. A <a id="delimiter-run" href="#delimiter-run" class="definition">delimiter run</a> is either a sequence of one or more <code>*</code> characters that is not preceded or followed by a <code>*</code> character, or a sequence of one or more <code>_</code> characters that is not preceded or followed by a <code>_</code> character.</p> <p>A <a id="left-flanking-delimiter-run" href="#left-flanking-delimiter-run" class="definition">left-flanking delimiter run</a> is a <a href="#delimiter-run">delimiter run</a> that is (a) not followed by <a href="#unicode-whitespace">Unicode whitespace</a>, and (b) either not followed by a <a href="#punctuation-character">punctuation character</a>, or preceded by <a href="#unicode-whitespace">Unicode whitespace</a> or a <a href="#punctuation-character">punctuation character</a>. For purposes of this definition, the beginning and the end of the line count as Unicode whitespace.</p> <p>A <a id="right-flanking-delimiter-run" href="#right-flanking-delimiter-run" class="definition">right-flanking delimiter run</a> is a <a href="#delimiter-run">delimiter run</a> that is (a) not preceded by <a href="#unicode-whitespace">Unicode whitespace</a>, and (b) either not preceded by a <a href="#punctuation-character">punctuation character</a>, or followed by <a href="#unicode-whitespace">Unicode whitespace</a> or a <a href="#punctuation-character">punctuation character</a>. For purposes of this definition, the beginning and the end of the line count as Unicode whitespace.</p> <p>Here are some examples of delimiter runs.</p> <ul> <li> <p>left-flanking but not right-flanking:</p> <pre><code>***abc _abc **&quot;abc&quot; _&quot;abc&quot; </code></pre> </li> <li> <p>right-flanking but not left-flanking:</p> <pre><code> abc*** abc_ &quot;abc&quot;** &quot;abc&quot;_ </code></pre> </li> <li> <p>Both left and right-flanking:</p> <pre><code> abc***def &quot;abc&quot;_&quot;def&quot; </code></pre> </li> <li> <p>Neither left nor right-flanking:</p> <pre><code>abc *** def a _ b </code></pre> </li> </ul> <p>(The idea of distinguishing left-flanking and right-flanking delimiter runs based on the character before and the character after comes from Roopesh Chander’s <a href="http://www.vfmd.org/vfmd-spec/specification/#procedure-for-identifying-emphasis-tags">vfmd</a>. vfmd uses the terminology “emphasis indicator string” instead of “delimiter run,” and its rules for distinguishing left- and right-flanking runs are a bit more complex than the ones given here.)</p> <p>The following rules define emphasis and strong emphasis:</p> <ol> <li> <p>A single <code>*</code> character <a id="can-open-emphasis" href="#can-open-emphasis" class="definition">can open emphasis</a> iff (if and only if) it is part of a <a href="#left-flanking-delimiter-run">left-flanking delimiter run</a>.</p> </li> <li> <p>A single <code>_</code> character <a href="#can-open-emphasis">can open emphasis</a> iff it is part of a <a href="#left-flanking-delimiter-run">left-flanking delimiter run</a> and either (a) not part of a <a href="#right-flanking-delimiter-run">right-flanking delimiter run</a> or (b) part of a [right-flanking delimeter run] preceded by punctuation.</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 part of a <a href="#right-flanking-delimiter-run">right-flanking delimiter run</a>.</p> </li> <li> <p>A single <code>_</code> character <a href="#can-close-emphasis">can close emphasis</a> iff it is part of a <a href="#right-flanking-delimiter-run">right-flanking delimiter run</a> and either (a) not part of a <a href="#left-flanking-delimiter-run">left-flanking delimiter run</a> or (b) part of a [left-flanking delimeter run] followed by punctuation.</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 part of a <a href="#left-flanking-delimiter-run">left-flanking delimiter run</a>.</p> </li> <li> <p>A double <code>__</code> <a href="#can-open-strong-emphasis">can open strong emphasis</a> iff it is part of a <a href="#left-flanking-delimiter-run">left-flanking delimiter run</a> and either (a) not part of a <a href="#right-flanking-delimiter-run">right-flanking delimiter run</a> or (b) part of a [right-flanking delimeter run] preceded by punctuation.</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 part of a <a href="#right-flanking-delimiter-run">right-flanking delimiter run</a>.</p> </li> <li> <p>A double <code>__</code> <a href="#can-close-strong-emphasis">can close strong emphasis</a> it is part of a <a href="#right-flanking-delimiter-run">right-flanking delimiter run</a> and either (a) not part of a <a href="#left-flanking-delimiter-run">left-flanking delimiter run</a> or (b) part of a [left-flanking delimeter run] followed by punctuation.</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"> <li> <p>The number of nestings should be minimized. Thus, for example, an interpretation <code>&lt;strong&gt;...&lt;/strong&gt;</code> is always preferred to <code>&lt;em&gt;&lt;em&gt;...&lt;/em&gt;&lt;/em&gt;</code>.</p> </li> <li> <p>An interpretation <code>&lt;strong&gt;&lt;em&gt;...&lt;/em&gt;&lt;/strong&gt;</code> is always preferred to <code>&lt;em&gt;&lt;strong&gt;..&lt;/strong&gt;&lt;/em&gt;</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 takes precedence. Thus, for example, <code>*foo _bar* baz_</code> is parsed as <code>&lt;em&gt;foo _bar&lt;/em&gt; baz_</code> rather than <code>*foo &lt;em&gt;bar* baz&lt;/em&gt;</code>. For the same reason, <code>**foo*bar**</code> is parsed as <code>&lt;em&gt;&lt;em&gt;foo&lt;/em&gt;bar&lt;/em&gt;*</code> rather than <code>&lt;strong&gt;foo*bar&lt;/strong&gt;</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) takes precedence. Thus, for example, <code>**foo **bar baz**</code> is parsed as <code>**foo &lt;strong&gt;bar baz&lt;/strong&gt;</code> rather than <code>&lt;strong&gt;foo **bar baz&lt;/strong&gt;</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>*&lt;a href=&quot;bar&quot;&gt;foo*&lt;/a&gt;</code> rather than as <code>&lt;em&gt;[foo&lt;/em&gt;](bar)</code>.</p> </li> </ol> <p>These rules can be illustrated through a series of examples.</p> <p>Rule 1:</p> <div class="example" id="example-313" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-313">Example 313</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">*foo<span class="space"> </span>bar* </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;foo<span class="space"> </span>bar&lt;/em&gt;&lt;/p&gt; </code></pre> </div> <p>This is not emphasis, because the opening <code>*</code> is followed by whitespace, and hence not part of a <a href="#left-flanking-delimiter-run">left-flanking delimiter run</a>:</p> <div class="example" id="example-314" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-314">Example 314</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">a<span class="space"> </span>*<span class="space"> </span>foo<span class="space"> </span>bar* </code></pre> <pre><code class="language-html">&lt;p&gt;a<span class="space"> </span>*<span class="space"> </span>foo<span class="space"> </span>bar*&lt;/p&gt; </code></pre> </div> <p>This is not emphasis, because the opening <code>*</code> is preceded by an alphanumeric and followed by punctuation, and hence not part of a <a href="#left-flanking-delimiter-run">left-flanking delimiter run</a>:</p> <div class="example" id="example-315" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-315">Example 315</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">a*&quot;foo&quot;* </code></pre> <pre><code class="language-html">&lt;p&gt;a*&amp;quot;foo&amp;quot;*&lt;/p&gt; </code></pre> </div> <p>Unicode nonbreaking spaces count as whitespace, too:</p> <div class="example" id="example-316" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-316">Example 316</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">* a * </code></pre> <pre><code class="language-html">&lt;p&gt;* a *&lt;/p&gt; </code></pre> </div> <p>Intraword emphasis with <code>*</code> is permitted:</p> <div class="example" id="example-317" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-317">Example 317</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">foo*bar* </code></pre> <pre><code class="language-html">&lt;p&gt;foo&lt;em&gt;bar&lt;/em&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-318" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-318">Example 318</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">5*6*78 </code></pre> <pre><code class="language-html">&lt;p&gt;5&lt;em&gt;6&lt;/em&gt;78&lt;/p&gt; </code></pre> </div> <p>Rule 2:</p> <div class="example" id="example-319" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-319">Example 319</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">_foo<span class="space"> </span>bar_ </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;foo<span class="space"> </span>bar&lt;/em&gt;&lt;/p&gt; </code></pre> </div> <p>This is not emphasis, because the opening <code>_</code> is followed by whitespace:</p> <div class="example" id="example-320" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-320">Example 320</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">_<span class="space"> </span>foo<span class="space"> </span>bar_ </code></pre> <pre><code class="language-html">&lt;p&gt;_<span class="space"> </span>foo<span class="space"> </span>bar_&lt;/p&gt; </code></pre> </div> <p>This is not emphasis, because the opening <code>_</code> is preceded by an alphanumeric and followed by punctuation:</p> <div class="example" id="example-321" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-321">Example 321</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">a_&quot;foo&quot;_ </code></pre> <pre><code class="language-html">&lt;p&gt;a_&amp;quot;foo&amp;quot;_&lt;/p&gt; </code></pre> </div> <p>Emphasis with <code>_</code> is not allowed inside words:</p> <div class="example" id="example-322" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-322">Example 322</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">foo_bar_ </code></pre> <pre><code class="language-html">&lt;p&gt;foo_bar_&lt;/p&gt; </code></pre> </div> <div class="example" id="example-323" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-323">Example 323</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">5_6_78 </code></pre> <pre><code class="language-html">&lt;p&gt;5_6_78&lt;/p&gt; </code></pre> </div> <div class="example" id="example-324" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-324">Example 324</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">пристаням_стремятся_ </code></pre> <pre><code class="language-html">&lt;p&gt;пристаням_стремятся_&lt;/p&gt; </code></pre> </div> <p>Here <code>_</code> does not generate emphasis, because the first delimiter run is right-flanking and the second left-flanking:</p> <div class="example" id="example-325" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-325">Example 325</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">aa_&quot;bb&quot;_cc </code></pre> <pre><code class="language-html">&lt;p&gt;aa_&amp;quot;bb&amp;quot;_cc&lt;/p&gt; </code></pre> </div> <p>This is emphasis, even though the opening delimiter is both left- and right-flanking, because it is preceded by punctuation:</p> <div class="example" id="example-326" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-326">Example 326</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">foo-_(bar)_ </code></pre> <pre><code class="language-html">&lt;p&gt;foo-&lt;em&gt;(bar)&lt;/em&gt;&lt;/p&gt; </code></pre> </div> <p>Rule 3:</p> <p>This is not emphasis, because the closing delimiter does not match the opening delimiter:</p> <div class="example" id="example-327" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-327">Example 327</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">_foo* </code></pre> <pre><code class="language-html">&lt;p&gt;_foo*&lt;/p&gt; </code></pre> </div> <p>This is not emphasis, because the closing <code>*</code> is preceded by whitespace:</p> <div class="example" id="example-328" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-328">Example 328</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">*foo<span class="space"> </span>bar<span class="space"> </span>* </code></pre> <pre><code class="language-html">&lt;p&gt;*foo<span class="space"> </span>bar<span class="space"> </span>*&lt;/p&gt; </code></pre> </div> <p>A newline also counts as whitespace:</p> <div class="example" id="example-329" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-329">Example 329</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">*foo<span class="space"> </span>bar * </code></pre> <pre><code class="language-html">&lt;p&gt;*foo<span class="space"> </span>bar&lt;/p&gt; &lt;ul&gt; &lt;li&gt;&lt;/li&gt; &lt;/ul&gt; </code></pre> </div> <p>This is not emphasis, because the second <code>*</code> is preceded by punctuation and followed by an alphanumeric (hence it is not part of a <a href="#right-flanking-delimiter-run">right-flanking delimiter run</a>:</p> <div class="example" id="example-330" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-330">Example 330</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">*(*foo) </code></pre> <pre><code class="language-html">&lt;p&gt;*(*foo)&lt;/p&gt; </code></pre> </div> <p>The point of this restriction is more easily appreciated with this example:</p> <div class="example" id="example-331" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-331">Example 331</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">*(*foo*)* </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;(&lt;em&gt;foo&lt;/em&gt;)&lt;/em&gt;&lt;/p&gt; </code></pre> </div> <p>Intraword emphasis with <code>*</code> is allowed:</p> <div class="example" id="example-332" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-332">Example 332</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">*foo*bar </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;foo&lt;/em&gt;bar&lt;/p&gt; </code></pre> </div> <p>Rule 4:</p> <p>This is not emphasis, because the closing <code>_</code> is preceded by whitespace:</p> <div class="example" id="example-333" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-333">Example 333</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">_foo<span class="space"> </span>bar<span class="space"> </span>_ </code></pre> <pre><code class="language-html">&lt;p&gt;_foo<span class="space"> </span>bar<span class="space"> </span>_&lt;/p&gt; </code></pre> </div> <p>This is not emphasis, because the second <code>_</code> is preceded by punctuation and followed by an alphanumeric:</p> <div class="example" id="example-334" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-334">Example 334</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">_(_foo) </code></pre> <pre><code class="language-html">&lt;p&gt;_(_foo)&lt;/p&gt; </code></pre> </div> <p>This is emphasis within emphasis:</p> <div class="example" id="example-335" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-335">Example 335</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">_(_foo_)_ </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;(&lt;em&gt;foo&lt;/em&gt;)&lt;/em&gt;&lt;/p&gt; </code></pre> </div> <p>Intraword emphasis is disallowed for <code>_</code>:</p> <div class="example" id="example-336" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-336">Example 336</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">_foo_bar </code></pre> <pre><code class="language-html">&lt;p&gt;_foo_bar&lt;/p&gt; </code></pre> </div> <div class="example" id="example-337" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-337">Example 337</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">_пристаням_стремятся </code></pre> <pre><code class="language-html">&lt;p&gt;_пристаням_стремятся&lt;/p&gt; </code></pre> </div> <div class="example" id="example-338" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-338">Example 338</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">_foo_bar_baz_ </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;foo_bar_baz&lt;/em&gt;&lt;/p&gt; </code></pre> </div> <p>This is emphasis, even though the closing delimiter is both left- and right-flanking, because it is followed by punctuation:</p> <div class="example" id="example-339" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-339">Example 339</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">_(bar)_. </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;(bar)&lt;/em&gt;.&lt;/p&gt; </code></pre> </div> <p>Rule 5:</p> <div class="example" id="example-340" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-340">Example 340</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">**foo<span class="space"> </span>bar** </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;strong&gt;foo<span class="space"> </span>bar&lt;/strong&gt;&lt;/p&gt; </code></pre> </div> <p>This is not strong emphasis, because the opening delimiter is followed by whitespace:</p> <div class="example" id="example-341" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-341">Example 341</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">**<span class="space"> </span>foo<span class="space"> </span>bar** </code></pre> <pre><code class="language-html">&lt;p&gt;**<span class="space"> </span>foo<span class="space"> </span>bar**&lt;/p&gt; </code></pre> </div> <p>This is not strong emphasis, because the opening <code>**</code> is preceded by an alphanumeric and followed by punctuation, and hence not part of a <a href="#left-flanking-delimiter-run">left-flanking delimiter run</a>:</p> <div class="example" id="example-342" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-342">Example 342</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">a**&quot;foo&quot;** </code></pre> <pre><code class="language-html">&lt;p&gt;a**&amp;quot;foo&amp;quot;**&lt;/p&gt; </code></pre> </div> <p>Intraword strong emphasis with <code>**</code> is permitted:</p> <div class="example" id="example-343" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-343">Example 343</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">foo**bar** </code></pre> <pre><code class="language-html">&lt;p&gt;foo&lt;strong&gt;bar&lt;/strong&gt;&lt;/p&gt; </code></pre> </div> <p>Rule 6:</p> <div class="example" id="example-344" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-344">Example 344</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">__foo<span class="space"> </span>bar__ </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;strong&gt;foo<span class="space"> </span>bar&lt;/strong&gt;&lt;/p&gt; </code></pre> </div> <p>This is not strong emphasis, because the opening delimiter is followed by whitespace:</p> <div class="example" id="example-345" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-345">Example 345</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">__<span class="space"> </span>foo<span class="space"> </span>bar__ </code></pre> <pre><code class="language-html">&lt;p&gt;__<span class="space"> </span>foo<span class="space"> </span>bar__&lt;/p&gt; </code></pre> </div> <p>A newline counts as whitespace:</p> <div class="example" id="example-346" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-346">Example 346</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">__ foo<span class="space"> </span>bar__ </code></pre> <pre><code class="language-html">&lt;p&gt;__ foo<span class="space"> </span>bar__&lt;/p&gt; </code></pre> </div> <p>This is not strong emphasis, because the opening <code>__</code> is preceded by an alphanumeric and followed by punctuation:</p> <div class="example" id="example-347" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-347">Example 347</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">a__&quot;foo&quot;__ </code></pre> <pre><code class="language-html">&lt;p&gt;a__&amp;quot;foo&amp;quot;__&lt;/p&gt; </code></pre> </div> <p>Intraword strong emphasis is forbidden with <code>__</code>:</p> <div class="example" id="example-348" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-348">Example 348</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">foo__bar__ </code></pre> <pre><code class="language-html">&lt;p&gt;foo__bar__&lt;/p&gt; </code></pre> </div> <div class="example" id="example-349" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-349">Example 349</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">5__6__78 </code></pre> <pre><code class="language-html">&lt;p&gt;5__6__78&lt;/p&gt; </code></pre> </div> <div class="example" id="example-350" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-350">Example 350</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">пристаням__стремятся__ </code></pre> <pre><code class="language-html">&lt;p&gt;пристаням__стремятся__&lt;/p&gt; </code></pre> </div> <div class="example" id="example-351" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-351">Example 351</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">__foo,<span class="space"> </span>__bar__,<span class="space"> </span>baz__ </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;strong&gt;foo,<span class="space"> </span>&lt;strong&gt;bar&lt;/strong&gt;,<span class="space"> </span>baz&lt;/strong&gt;&lt;/p&gt; </code></pre> </div> <p>This is strong emphasis, even though the opening delimiter is both left- and right-flanking, because it is preceded by punctuation:</p> <div class="example" id="example-352" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-352">Example 352</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">foo-__(bar)__ </code></pre> <pre><code class="language-html">&lt;p&gt;foo-&lt;strong&gt;(bar)&lt;/strong&gt;&lt;/p&gt; </code></pre> </div> <p>Rule 7:</p> <p>This is not strong emphasis, because the closing delimiter is preceded by whitespace:</p> <div class="example" id="example-353" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-353">Example 353</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">**foo<span class="space"> </span>bar<span class="space"> </span>** </code></pre> <pre><code class="language-html">&lt;p&gt;**foo<span class="space"> </span>bar<span class="space"> </span>**&lt;/p&gt; </code></pre> </div> <p>(Nor can it be interpreted as an emphasized <code>*foo bar *</code>, because of Rule 11.)</p> <p>This is not strong emphasis, because the second <code>**</code> is preceded by punctuation and followed by an alphanumeric:</p> <div class="example" id="example-354" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-354">Example 354</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">**(**foo) </code></pre> <pre><code class="language-html">&lt;p&gt;**(**foo)&lt;/p&gt; </code></pre> </div> <p>The point of this restriction is more easily appreciated with these examples:</p> <div class="example" id="example-355" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-355">Example 355</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">*(**foo**)* </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;(&lt;strong&gt;foo&lt;/strong&gt;)&lt;/em&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-356" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-356">Example 356</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">**Gomphocarpus<span class="space"> </span>(*Gomphocarpus<span class="space"> </span>physocarpus*,<span class="space"> </span>syn. *Asclepias<span class="space"> </span>physocarpa*)** </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;strong&gt;Gomphocarpus<span class="space"> </span>(&lt;em&gt;Gomphocarpus<span class="space"> </span>physocarpus&lt;/em&gt;,<span class="space"> </span>syn. &lt;em&gt;Asclepias<span class="space"> </span>physocarpa&lt;/em&gt;)&lt;/strong&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-357" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-357">Example 357</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">**foo<span class="space"> </span>&quot;*bar*&quot;<span class="space"> </span>foo** </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;strong&gt;foo<span class="space"> </span>&amp;quot;&lt;em&gt;bar&lt;/em&gt;&amp;quot;<span class="space"> </span>foo&lt;/strong&gt;&lt;/p&gt; </code></pre> </div> <p>Intraword emphasis:</p> <div class="example" id="example-358" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-358">Example 358</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">**foo**bar </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;strong&gt;foo&lt;/strong&gt;bar&lt;/p&gt; </code></pre> </div> <p>Rule 8:</p> <p>This is not strong emphasis, because the closing delimiter is preceded by whitespace:</p> <div class="example" id="example-359" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-359">Example 359</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">__foo<span class="space"> </span>bar<span class="space"> </span>__ </code></pre> <pre><code class="language-html">&lt;p&gt;__foo<span class="space"> </span>bar<span class="space"> </span>__&lt;/p&gt; </code></pre> </div> <p>This is not strong emphasis, because the second <code>__</code> is preceded by punctuation and followed by an alphanumeric:</p> <div class="example" id="example-360" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-360">Example 360</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">__(__foo) </code></pre> <pre><code class="language-html">&lt;p&gt;__(__foo)&lt;/p&gt; </code></pre> </div> <p>The point of this restriction is more easily appreciated with this example:</p> <div class="example" id="example-361" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-361">Example 361</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">_(__foo__)_ </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;(&lt;strong&gt;foo&lt;/strong&gt;)&lt;/em&gt;&lt;/p&gt; </code></pre> </div> <p>Intraword strong emphasis is forbidden with <code>__</code>:</p> <div class="example" id="example-362" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-362">Example 362</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">__foo__bar </code></pre> <pre><code class="language-html">&lt;p&gt;__foo__bar&lt;/p&gt; </code></pre> </div> <div class="example" id="example-363" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-363">Example 363</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">__пристаням__стремятся </code></pre> <pre><code class="language-html">&lt;p&gt;__пристаням__стремятся&lt;/p&gt; </code></pre> </div> <div class="example" id="example-364" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-364">Example 364</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">__foo__bar__baz__ </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;strong&gt;foo__bar__baz&lt;/strong&gt;&lt;/p&gt; </code></pre> </div> <p>This is strong emphasis, even though the closing delimiter is both left- and right-flanking, because it is followed by punctuation:</p> <div class="example" id="example-365" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-365">Example 365</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">__(bar)__. </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;strong&gt;(bar)&lt;/strong&gt;.&lt;/p&gt; </code></pre> </div> <p>Rule 9:</p> <p>Any nonempty sequence of inline elements can be the contents of an emphasized span.</p> <div class="example" id="example-366" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-366">Example 366</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">*foo<span class="space"> </span>[bar](/url)* </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;foo<span class="space"> </span>&lt;a<span class="space"> </span>href=&quot;/url&quot;&gt;bar&lt;/a&gt;&lt;/em&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-367" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-367">Example 367</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">*foo bar* </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;foo bar&lt;/em&gt;&lt;/p&gt; </code></pre> </div> <p>In particular, emphasis and strong emphasis can be nested inside emphasis:</p> <div class="example" id="example-368" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-368">Example 368</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">_foo<span class="space"> </span>__bar__<span class="space"> </span>baz_ </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;foo<span class="space"> </span>&lt;strong&gt;bar&lt;/strong&gt;<span class="space"> </span>baz&lt;/em&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-369" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-369">Example 369</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">_foo<span class="space"> </span>_bar_<span class="space"> </span>baz_ </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;foo<span class="space"> </span>&lt;em&gt;bar&lt;/em&gt;<span class="space"> </span>baz&lt;/em&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-370" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-370">Example 370</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">__foo_<span class="space"> </span>bar_ </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;&lt;em&gt;foo&lt;/em&gt;<span class="space"> </span>bar&lt;/em&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-371" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-371">Example 371</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">*foo<span class="space"> </span>*bar** </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;foo<span class="space"> </span>&lt;em&gt;bar&lt;/em&gt;&lt;/em&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-372" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-372">Example 372</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">*foo<span class="space"> </span>**bar**<span class="space"> </span>baz* </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;foo<span class="space"> </span>&lt;strong&gt;bar&lt;/strong&gt;<span class="space"> </span>baz&lt;/em&gt;&lt;/p&gt; </code></pre> </div> <p>But note:</p> <div class="example" id="example-373" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-373">Example 373</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">*foo**bar**baz* </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;foo&lt;/em&gt;&lt;em&gt;bar&lt;/em&gt;&lt;em&gt;baz&lt;/em&gt;&lt;/p&gt; </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 class="example" id="example-374" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-374">Example 374</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">***foo**<span class="space"> </span>bar* </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;&lt;strong&gt;foo&lt;/strong&gt;<span class="space"> </span>bar&lt;/em&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-375" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-375">Example 375</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">*foo<span class="space"> </span>**bar*** </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;foo<span class="space"> </span>&lt;strong&gt;bar&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt; </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 class="example" id="example-376" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-376">Example 376</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">*foo**bar*** </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;foo&lt;/em&gt;&lt;em&gt;bar&lt;/em&gt;**&lt;/p&gt; </code></pre> </div> <p>Indefinite levels of nesting are possible:</p> <div class="example" id="example-377" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-377">Example 377</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">*foo<span class="space"> </span>**bar<span class="space"> </span>*baz*<span class="space"> </span>bim**<span class="space"> </span>bop* </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;foo<span class="space"> </span>&lt;strong&gt;bar<span class="space"> </span>&lt;em&gt;baz&lt;/em&gt;<span class="space"> </span>bim&lt;/strong&gt;<span class="space"> </span>bop&lt;/em&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-378" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-378">Example 378</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">*foo<span class="space"> </span>[*bar*](/url)* </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;foo<span class="space"> </span>&lt;a<span class="space"> </span>href=&quot;/url&quot;&gt;&lt;em&gt;bar&lt;/em&gt;&lt;/a&gt;&lt;/em&gt;&lt;/p&gt; </code></pre> </div> <p>There can be no empty emphasis or strong emphasis:</p> <div class="example" id="example-379" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-379">Example 379</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">**<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><code class="language-html">&lt;p&gt;**<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&lt;/p&gt; </code></pre> </div> <div class="example" id="example-380" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-380">Example 380</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">****<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><code class="language-html">&lt;p&gt;****<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&lt;/p&gt; </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 class="example" id="example-381" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-381">Example 381</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">**foo<span class="space"> </span>[bar](/url)** </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;strong&gt;foo<span class="space"> </span>&lt;a<span class="space"> </span>href=&quot;/url&quot;&gt;bar&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-382" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-382">Example 382</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">**foo bar** </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;strong&gt;foo bar&lt;/strong&gt;&lt;/p&gt; </code></pre> </div> <p>In particular, emphasis and strong emphasis can be nested inside strong emphasis:</p> <div class="example" id="example-383" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-383">Example 383</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">__foo<span class="space"> </span>_bar_<span class="space"> </span>baz__ </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;strong&gt;foo<span class="space"> </span>&lt;em&gt;bar&lt;/em&gt;<span class="space"> </span>baz&lt;/strong&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-384" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-384">Example 384</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">__foo<span class="space"> </span>__bar__<span class="space"> </span>baz__ </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;strong&gt;foo<span class="space"> </span>&lt;strong&gt;bar&lt;/strong&gt;<span class="space"> </span>baz&lt;/strong&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-385" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-385">Example 385</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">____foo__<span class="space"> </span>bar__ </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;strong&gt;&lt;strong&gt;foo&lt;/strong&gt;<span class="space"> </span>bar&lt;/strong&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-386" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-386">Example 386</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">**foo<span class="space"> </span>**bar**** </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;strong&gt;foo<span class="space"> </span>&lt;strong&gt;bar&lt;/strong&gt;&lt;/strong&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-387" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-387">Example 387</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">**foo<span class="space"> </span>*bar*<span class="space"> </span>baz** </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;strong&gt;foo<span class="space"> </span>&lt;em&gt;bar&lt;/em&gt;<span class="space"> </span>baz&lt;/strong&gt;&lt;/p&gt; </code></pre> </div> <p>But note:</p> <div class="example" id="example-388" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-388">Example 388</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">**foo*bar*baz** </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;&lt;em&gt;foo&lt;/em&gt;bar&lt;/em&gt;baz**&lt;/p&gt; </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 class="example" id="example-389" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-389">Example 389</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">***foo*<span class="space"> </span>bar** </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;strong&gt;&lt;em&gt;foo&lt;/em&gt;<span class="space"> </span>bar&lt;/strong&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-390" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-390">Example 390</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">**foo<span class="space"> </span>*bar*** </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;strong&gt;foo<span class="space"> </span>&lt;em&gt;bar&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt; </code></pre> </div> <p>Indefinite levels of nesting are possible:</p> <div class="example" id="example-391" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-391">Example 391</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">**foo<span class="space"> </span>*bar<span class="space"> </span>**baz** bim*<span class="space"> </span>bop** </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;strong&gt;foo<span class="space"> </span>&lt;em&gt;bar<span class="space"> </span>&lt;strong&gt;baz&lt;/strong&gt; bim&lt;/em&gt;<span class="space"> </span>bop&lt;/strong&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-392" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-392">Example 392</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">**foo<span class="space"> </span>[*bar*](/url)** </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;strong&gt;foo<span class="space"> </span>&lt;a<span class="space"> </span>href=&quot;/url&quot;&gt;&lt;em&gt;bar&lt;/em&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt; </code></pre> </div> <p>There can be no empty emphasis or strong emphasis:</p> <div class="example" id="example-393" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-393">Example 393</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">__<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><code class="language-html">&lt;p&gt;__<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&lt;/p&gt; </code></pre> </div> <div class="example" id="example-394" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-394">Example 394</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">____<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><code class="language-html">&lt;p&gt;____<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&lt;/p&gt; </code></pre> </div> <p>Rule 11:</p> <div class="example" id="example-395" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-395">Example 395</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">foo<span class="space"> </span>*** </code></pre> <pre><code class="language-html">&lt;p&gt;foo<span class="space"> </span>***&lt;/p&gt; </code></pre> </div> <div class="example" id="example-396" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-396">Example 396</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">foo<span class="space"> </span>*\** </code></pre> <pre><code class="language-html">&lt;p&gt;foo<span class="space"> </span>&lt;em&gt;*&lt;/em&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-397" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-397">Example 397</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">foo<span class="space"> </span>*_* </code></pre> <pre><code class="language-html">&lt;p&gt;foo<span class="space"> </span>&lt;em&gt;_&lt;/em&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-398" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-398">Example 398</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">foo<span class="space"> </span>***** </code></pre> <pre><code class="language-html">&lt;p&gt;foo<span class="space"> </span>*****&lt;/p&gt; </code></pre> </div> <div class="example" id="example-399" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-399">Example 399</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">foo<span class="space"> </span>**\*** </code></pre> <pre><code class="language-html">&lt;p&gt;foo<span class="space"> </span>&lt;strong&gt;*&lt;/strong&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-400" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-400">Example 400</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">foo<span class="space"> </span>**_** </code></pre> <pre><code class="language-html">&lt;p&gt;foo<span class="space"> </span>&lt;strong&gt;_&lt;/strong&gt;&lt;/p&gt; </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 class="example" id="example-401" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-401">Example 401</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">**foo* </code></pre> <pre><code class="language-html">&lt;p&gt;*&lt;em&gt;foo&lt;/em&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-402" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-402">Example 402</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">*foo** </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;foo&lt;/em&gt;*&lt;/p&gt; </code></pre> </div> <div class="example" id="example-403" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-403">Example 403</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">***foo** </code></pre> <pre><code class="language-html">&lt;p&gt;*&lt;strong&gt;foo&lt;/strong&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-404" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-404">Example 404</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">****foo* </code></pre> <pre><code class="language-html">&lt;p&gt;***&lt;em&gt;foo&lt;/em&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-405" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-405">Example 405</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">**foo*** </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;strong&gt;foo&lt;/strong&gt;*&lt;/p&gt; </code></pre> </div> <div class="example" id="example-406" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-406">Example 406</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">*foo**** </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;foo&lt;/em&gt;***&lt;/p&gt; </code></pre> </div> <p>Rule 12:</p> <div class="example" id="example-407" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-407">Example 407</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">foo<span class="space"> </span>___ </code></pre> <pre><code class="language-html">&lt;p&gt;foo<span class="space"> </span>___&lt;/p&gt; </code></pre> </div> <div class="example" id="example-408" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-408">Example 408</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">foo<span class="space"> </span>_\__ </code></pre> <pre><code class="language-html">&lt;p&gt;foo<span class="space"> </span>&lt;em&gt;_&lt;/em&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-409" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-409">Example 409</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">foo<span class="space"> </span>_*_ </code></pre> <pre><code class="language-html">&lt;p&gt;foo<span class="space"> </span>&lt;em&gt;*&lt;/em&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-410" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-410">Example 410</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">foo<span class="space"> </span>_____ </code></pre> <pre><code class="language-html">&lt;p&gt;foo<span class="space"> </span>_____&lt;/p&gt; </code></pre> </div> <div class="example" id="example-411" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-411">Example 411</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">foo<span class="space"> </span>__\___ </code></pre> <pre><code class="language-html">&lt;p&gt;foo<span class="space"> </span>&lt;strong&gt;_&lt;/strong&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-412" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-412">Example 412</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">foo<span class="space"> </span>__*__ </code></pre> <pre><code class="language-html">&lt;p&gt;foo<span class="space"> </span>&lt;strong&gt;*&lt;/strong&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-413" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-413">Example 413</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">__foo_ </code></pre> <pre><code class="language-html">&lt;p&gt;_&lt;em&gt;foo&lt;/em&gt;&lt;/p&gt; </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 class="example" id="example-414" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-414">Example 414</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">_foo__ </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;foo&lt;/em&gt;_&lt;/p&gt; </code></pre> </div> <div class="example" id="example-415" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-415">Example 415</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">___foo__ </code></pre> <pre><code class="language-html">&lt;p&gt;_&lt;strong&gt;foo&lt;/strong&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-416" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-416">Example 416</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">____foo_ </code></pre> <pre><code class="language-html">&lt;p&gt;___&lt;em&gt;foo&lt;/em&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-417" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-417">Example 417</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">__foo___ </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;strong&gt;foo&lt;/strong&gt;_&lt;/p&gt; </code></pre> </div> <div class="example" id="example-418" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-418">Example 418</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">_foo____ </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;foo&lt;/em&gt;___&lt;/p&gt; </code></pre> </div> <p>Rule 13 implies that if you want emphasis nested directly inside emphasis, you must use different delimiters:</p> <div class="example" id="example-419" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-419">Example 419</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">**foo** </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;strong&gt;foo&lt;/strong&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-420" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-420">Example 420</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">*_foo_* </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;&lt;em&gt;foo&lt;/em&gt;&lt;/em&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-421" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-421">Example 421</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">__foo__ </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;strong&gt;foo&lt;/strong&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-422" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-422">Example 422</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">_*foo*_ </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;&lt;em&gt;foo&lt;/em&gt;&lt;/em&gt;&lt;/p&gt; </code></pre> </div> <p>However, strong emphasis within strong emphasis is possible without switching delimiters:</p> <div class="example" id="example-423" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-423">Example 423</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">****foo**** </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;strong&gt;&lt;strong&gt;foo&lt;/strong&gt;&lt;/strong&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-424" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-424">Example 424</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">____foo____ </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;strong&gt;&lt;strong&gt;foo&lt;/strong&gt;&lt;/strong&gt;&lt;/p&gt; </code></pre> </div> <p>Rule 13 can be applied to arbitrarily long sequences of delimiters:</p> <div class="example" id="example-425" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-425">Example 425</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">******foo****** </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;strong&gt;&lt;strong&gt;&lt;strong&gt;foo&lt;/strong&gt;&lt;/strong&gt;&lt;/strong&gt;&lt;/p&gt; </code></pre> </div> <p>Rule 14:</p> <div class="example" id="example-426" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-426">Example 426</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">***foo*** </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;strong&gt;&lt;em&gt;foo&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-427" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-427">Example 427</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">_____foo_____ </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;strong&gt;&lt;strong&gt;&lt;em&gt;foo&lt;/em&gt;&lt;/strong&gt;&lt;/strong&gt;&lt;/p&gt; </code></pre> </div> <p>Rule 15:</p> <div class="example" id="example-428" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-428">Example 428</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">*foo<span class="space"> </span>_bar*<span class="space"> </span>baz_ </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;foo<span class="space"> </span>_bar&lt;/em&gt;<span class="space"> </span>baz_&lt;/p&gt; </code></pre> </div> <div class="example" id="example-429" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-429">Example 429</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">**foo*bar** </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;&lt;em&gt;foo&lt;/em&gt;bar&lt;/em&gt;*&lt;/p&gt; </code></pre> </div> <div class="example" id="example-430" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-430">Example 430</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">*foo<span class="space"> </span>__bar<span class="space"> </span>*baz<span class="space"> </span>bim__<span class="space"> </span>bam* </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;foo<span class="space"> </span>&lt;strong&gt;bar<span class="space"> </span>*baz<span class="space"> </span>bim&lt;/strong&gt;<span class="space"> </span>bam&lt;/em&gt;&lt;/p&gt; </code></pre> </div> <p>Rule 16:</p> <div class="example" id="example-431" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-431">Example 431</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">**foo<span class="space"> </span>**bar<span class="space"> </span>baz** </code></pre> <pre><code class="language-html">&lt;p&gt;**foo<span class="space"> </span>&lt;strong&gt;bar<span class="space"> </span>baz&lt;/strong&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-432" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-432">Example 432</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">*foo<span class="space"> </span>*bar<span class="space"> </span>baz* </code></pre> <pre><code class="language-html">&lt;p&gt;*foo<span class="space"> </span>&lt;em&gt;bar<span class="space"> </span>baz&lt;/em&gt;&lt;/p&gt; </code></pre> </div> <p>Rule 17:</p> <div class="example" id="example-433" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-433">Example 433</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">*[bar*](/url) </code></pre> <pre><code class="language-html">&lt;p&gt;*&lt;a<span class="space"> </span>href=&quot;/url&quot;&gt;bar*&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-434" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-434">Example 434</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">_foo<span class="space"> </span>[bar_](/url) </code></pre> <pre><code class="language-html">&lt;p&gt;_foo<span class="space"> </span>&lt;a<span class="space"> </span>href=&quot;/url&quot;&gt;bar_&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-435" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-435">Example 435</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">*&lt;img<span class="space"> </span>src=&quot;foo&quot;<span class="space"> </span>title=&quot;*&quot;/&gt; </code></pre> <pre><code class="language-html">&lt;p&gt;*&lt;img<span class="space"> </span>src=&quot;foo&quot;<span class="space"> </span>title=&quot;*&quot;/&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-436" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-436">Example 436</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">**&lt;a<span class="space"> </span>href=&quot;**&quot;&gt; </code></pre> <pre><code class="language-html">&lt;p&gt;**&lt;a<span class="space"> </span>href=&quot;**&quot;&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-437" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-437">Example 437</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">__&lt;a<span class="space"> </span>href=&quot;__&quot;&gt; </code></pre> <pre><code class="language-html">&lt;p&gt;__&lt;a<span class="space"> </span>href=&quot;__&quot;&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-438" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-438">Example 438</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">*a<span class="space"> </span>`*`* </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;a<span class="space"> </span>&lt;code&gt;*&lt;/code&gt;&lt;/em&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-439" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-439">Example 439</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">_a<span class="space"> </span>`_`_ </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;a<span class="space"> </span>&lt;code&gt;_&lt;/code&gt;&lt;/em&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-440" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-440">Example 440</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">**a&lt;http://foo.bar/?q=**&gt; </code></pre> <pre><code class="language-html">&lt;p&gt;**a&lt;a<span class="space"> </span>href=&quot;http://foo.bar/?q=**&quot;&gt;http://foo.bar/?q=**&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-441" data-section="Emphasis and strong emphasis"> <div class="examplenum"><a href="#example-441">Example 441</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">__a&lt;http://foo.bar/?q=__&gt; </code></pre> <pre><code class="language-html">&lt;p&gt;__a&lt;a<span class="space"> </span>href=&quot;http://foo.bar/?q=__&quot;&gt;http://foo.bar/?q=__&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <h2><a id="links"></a><span class="number">6.5</span> Links</h2> <p>A link contains <a href="#link-text">link text</a> (the visible text), a <a href="#link-destination">link 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-link">inline links</a> the destination and title are given immediately after the link text. In <a href="#reference-link">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. If multiple otherwise valid link definitions appear nested inside each other, the inner-most definition is used.</p> </li> <li> <p>Brackets are allowed in the <a href="#link-text">link text</a> 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>&lt;</code> and a closing <code>&gt;</code> that contains no line breaks or unescaped <code>&lt;</code> or <code>&gt;</code> characters, or</p> </li> <li> <p>a nonempty sequence of characters that does not include ASCII space or control characters, and includes parentheses only if (a) they are backslash-escaped or (b) they are part of a balanced pair of unescaped parentheses that is not itself inside a balanced pair of unescaped parentheses.</p> </li> </ul> <p>A <a 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>&quot;</code>), including a <code>&quot;</code> character only if it is backslash-escaped, or</p> </li> <li> <p>a sequence of zero or more characters between straight single-quote characters (<code>'</code>), including a <code>'</code> character only if it is backslash-escaped, or</p> </li> <li> <p>a sequence of zero or more characters between matching parentheses (<code>(...)</code>), including a <code>)</code> character only if it is backslash-escaped.</p> </li> </ul> <p>Although <a href="#link-title">link titles</a> may span multiple lines, they may not contain a <a href="#blank-line">blank line</a>.</p> <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 <a href="#whitespace">whitespace</a>, an optional <a href="#link-destination">link destination</a>, an optional <a href="#link-title">link title</a> separated from the link destination by <a href="#whitespace">whitespace</a>, optional <a href="#whitespace">whitespace</a>, 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>&lt;...&gt;</code> if present, with backslash-escapes in effect as described above. The link’s title consists of the link title, excluding its enclosing delimiters, with backslash-escapes in effect as described above.</p> <p>Here is a simple inline link:</p> <div class="example" id="example-442" data-section="Links"> <div class="examplenum"><a href="#example-442">Example 442</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[link](/uri<span class="space"> </span>&quot;title&quot;) </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/uri&quot;<span class="space"> </span>title=&quot;title&quot;&gt;link&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>The title may be omitted:</p> <div class="example" id="example-443" data-section="Links"> <div class="examplenum"><a href="#example-443">Example 443</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[link](/uri) </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/uri&quot;&gt;link&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>Both the title and the destination may be omitted:</p> <div class="example" id="example-444" data-section="Links"> <div class="examplenum"><a href="#example-444">Example 444</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[link]() </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;&quot;&gt;link&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-445" data-section="Links"> <div class="examplenum"><a href="#example-445">Example 445</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[link](&lt;&gt;) </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;&quot;&gt;link&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>If the destination contains spaces, it must be enclosed in pointy braces:</p> <div class="example" id="example-446" data-section="Links"> <div class="examplenum"><a href="#example-446">Example 446</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[link](/my<span class="space"> </span>uri) </code></pre> <pre><code class="language-html">&lt;p&gt;[link](/my<span class="space"> </span>uri)&lt;/p&gt; </code></pre> </div> <div class="example" id="example-447" data-section="Links"> <div class="examplenum"><a href="#example-447">Example 447</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[link](&lt;/my<span class="space"> </span>uri&gt;) </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/my%20uri&quot;&gt;link&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>The destination cannot contain line breaks, even with pointy braces:</p> <div class="example" id="example-448" data-section="Links"> <div class="examplenum"><a href="#example-448">Example 448</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[link](foo bar) </code></pre> <pre><code class="language-html">&lt;p&gt;[link](foo bar)&lt;/p&gt; </code></pre> </div> <div class="example" id="example-449" data-section="Links"> <div class="examplenum"><a href="#example-449">Example 449</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[link](&lt;foo bar&gt;) </code></pre> <pre><code class="language-html">&lt;p&gt;[link](&lt;foo bar&gt;)&lt;/p&gt; </code></pre> </div> <p>One level of balanced parentheses is allowed without escaping:</p> <div class="example" id="example-450" data-section="Links"> <div class="examplenum"><a href="#example-450">Example 450</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[link]((foo)and(bar)) </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;(foo)and(bar)&quot;&gt;link&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>However, if you have parentheses within parentheses, you need to escape or use the <code>&lt;...&gt;</code> form:</p> <div class="example" id="example-451" data-section="Links"> <div class="examplenum"><a href="#example-451">Example 451</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[link](foo(and(bar))) </code></pre> <pre><code class="language-html">&lt;p&gt;[link](foo(and(bar)))&lt;/p&gt; </code></pre> </div> <div class="example" id="example-452" data-section="Links"> <div class="examplenum"><a href="#example-452">Example 452</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[link](foo(and\(bar\))) </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;foo(and(bar))&quot;&gt;link&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-453" data-section="Links"> <div class="examplenum"><a href="#example-453">Example 453</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[link](&lt;foo(and(bar))&gt;) </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;foo(and(bar))&quot;&gt;link&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>Parentheses and other symbols can also be escaped, as usual in Markdown:</p> <div class="example" id="example-454" data-section="Links"> <div class="examplenum"><a href="#example-454">Example 454</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[link](foo\)\:) </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;foo):&quot;&gt;link&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>A link can contain fragment identifiers and queries:</p> <div class="example" id="example-455" data-section="Links"> <div class="examplenum"><a href="#example-455">Example 455</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[link](#fragment) [link](http://example.com#fragment) [link](http://example.com?foo=bar&amp;baz#fragment) </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;#fragment&quot;&gt;link&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a<span class="space"> </span>href=&quot;http://example.com#fragment&quot;&gt;link&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a<span class="space"> </span>href=&quot;http://example.com?foo=bar&amp;amp;baz#fragment&quot;&gt;link&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>Note that a backslash before a non-escapable character is just a backslash:</p> <div class="example" id="example-456" data-section="Links"> <div class="examplenum"><a href="#example-456">Example 456</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[link](foo\bar) </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;foo%5Cbar&quot;&gt;link&lt;/a&gt;&lt;/p&gt; </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 the corresponding Unicode code points, as usual, and optionally URL-escaped when written as HTML.</p> <div class="example" id="example-457" data-section="Links"> <div class="examplenum"><a href="#example-457">Example 457</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[link](foo%20b&amp;auml;) </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;foo%20b%C3%A4&quot;&gt;link&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>Note that, because titles can often be parsed as destinations, if you try to omit the destination and keep the title, you’ll get unexpected results:</p> <div class="example" id="example-458" data-section="Links"> <div class="examplenum"><a href="#example-458">Example 458</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[link](&quot;title&quot;) </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;%22title%22&quot;&gt;link&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>Titles may be in single quotes, double quotes, or parentheses:</p> <div class="example" id="example-459" data-section="Links"> <div class="examplenum"><a href="#example-459">Example 459</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[link](/url<span class="space"> </span>&quot;title&quot;) [link](/url<span class="space"> </span>'title') [link](/url<span class="space"> </span>(title)) </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/url&quot;<span class="space"> </span>title=&quot;title&quot;&gt;link&lt;/a&gt; &lt;a<span class="space"> </span>href=&quot;/url&quot;<span class="space"> </span>title=&quot;title&quot;&gt;link&lt;/a&gt; &lt;a<span class="space"> </span>href=&quot;/url&quot;<span class="space"> </span>title=&quot;title&quot;&gt;link&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>Backslash escapes and entities may be used in titles:</p> <div class="example" id="example-460" data-section="Links"> <div class="examplenum"><a href="#example-460">Example 460</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[link](/url<span class="space"> </span>&quot;title<span class="space"> </span>\&quot;&amp;quot;&quot;) </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/url&quot;<span class="space"> </span>title=&quot;title<span class="space"> </span>&amp;quot;&amp;quot;&quot;&gt;link&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>Nested balanced quotes are not allowed without escaping:</p> <div class="example" id="example-461" data-section="Links"> <div class="examplenum"><a href="#example-461">Example 461</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[link](/url<span class="space"> </span>&quot;title<span class="space"> </span>&quot;and&quot;<span class="space"> </span>title&quot;) </code></pre> <pre><code class="language-html">&lt;p&gt;[link](/url<span class="space"> </span>&amp;quot;title<span class="space"> </span>&amp;quot;and&amp;quot;<span class="space"> </span>title&amp;quot;)&lt;/p&gt; </code></pre> </div> <p>But it is easy to work around this by using a different quote type:</p> <div class="example" id="example-462" data-section="Links"> <div class="examplenum"><a href="#example-462">Example 462</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[link](/url<span class="space"> </span>'title<span class="space"> </span>&quot;and&quot;<span class="space"> </span>title') </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/url&quot;<span class="space"> </span>title=&quot;title<span class="space"> </span>&amp;quot;and&amp;quot;<span class="space"> </span>title&quot;&gt;link&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>(Note: <code>Markdown.pl</code> did allow double quotes inside a double-quoted title, and its test suite included a test demonstrating this. But it is hard to see a good rationale for the extra complexity this brings, since there are already many ways—backslash escaping, entities, or using a different quote type for the enclosing title—to write titles containing double quotes. <code>Markdown.pl</code>’s handling of titles has a number of other strange features. For example, it allows single-quoted titles in inline links, but not reference links. And, in reference links but not inline links, it allows a title to begin with <code>&quot;</code> and end with <code>)</code>. <code>Markdown.pl</code> 1.0.1 even allows titles with no closing quotation mark, though 1.0.2b8 does not. It seems preferable to adopt a simple, rational rule that works the same way in inline links and link reference definitions.)</p> <p><a href="#whitespace">Whitespace</a> is allowed around the destination and title:</p> <div class="example" id="example-463" data-section="Links"> <div class="examplenum"><a href="#example-463">Example 463</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[link](<span class="space"> </span><span class="space"> </span><span class="space"> </span>/uri <span class="space"> </span><span class="space"> </span>&quot;title&quot;<span class="space"> </span><span class="space"> </span>) </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/uri&quot;<span class="space"> </span>title=&quot;title&quot;&gt;link&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>But it is not allowed between the link text and the following parenthesis:</p> <div class="example" id="example-464" data-section="Links"> <div class="examplenum"><a href="#example-464">Example 464</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[link]<span class="space"> </span>(/uri) </code></pre> <pre><code class="language-html">&lt;p&gt;[link]<span class="space"> </span>(/uri)&lt;/p&gt; </code></pre> </div> <p>The link text may contain balanced brackets, but not unbalanced ones, unless they are escaped:</p> <div class="example" id="example-465" data-section="Links"> <div class="examplenum"><a href="#example-465">Example 465</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[link<span class="space"> </span>[foo<span class="space"> </span>[bar]]](/uri) </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/uri&quot;&gt;link<span class="space"> </span>[foo<span class="space"> </span>[bar]]&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-466" data-section="Links"> <div class="examplenum"><a href="#example-466">Example 466</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[link]<span class="space"> </span>bar](/uri) </code></pre> <pre><code class="language-html">&lt;p&gt;[link]<span class="space"> </span>bar](/uri)&lt;/p&gt; </code></pre> </div> <div class="example" id="example-467" data-section="Links"> <div class="examplenum"><a href="#example-467">Example 467</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[link<span class="space"> </span>[bar](/uri) </code></pre> <pre><code class="language-html">&lt;p&gt;[link<span class="space"> </span>&lt;a<span class="space"> </span>href=&quot;/uri&quot;&gt;bar&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-468" data-section="Links"> <div class="examplenum"><a href="#example-468">Example 468</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[link<span class="space"> </span>\[bar](/uri) </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/uri&quot;&gt;link<span class="space"> </span>[bar&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>The link text may contain inline content:</p> <div class="example" id="example-469" data-section="Links"> <div class="examplenum"><a href="#example-469">Example 469</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[link<span class="space"> </span>*foo<span class="space"> </span>**bar**<span class="space"> </span>`#`*](/uri) </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/uri&quot;&gt;link<span class="space"> </span>&lt;em&gt;foo<span class="space"> </span>&lt;strong&gt;bar&lt;/strong&gt;<span class="space"> </span>&lt;code&gt;#&lt;/code&gt;&lt;/em&gt;&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-470" data-section="Links"> <div class="examplenum"><a href="#example-470">Example 470</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[![moon](moon.jpg)](/uri) </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/uri&quot;&gt;&lt;img<span class="space"> </span>src=&quot;moon.jpg&quot;<span class="space"> </span>alt=&quot;moon&quot;<span class="space"> </span>/&gt;&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>However, links may not contain other links, at any level of nesting.</p> <div class="example" id="example-471" data-section="Links"> <div class="examplenum"><a href="#example-471">Example 471</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo<span class="space"> </span>[bar](/uri)](/uri) </code></pre> <pre><code class="language-html">&lt;p&gt;[foo<span class="space"> </span>&lt;a<span class="space"> </span>href=&quot;/uri&quot;&gt;bar&lt;/a&gt;](/uri)&lt;/p&gt; </code></pre> </div> <div class="example" id="example-472" data-section="Links"> <div class="examplenum"><a href="#example-472">Example 472</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo<span class="space"> </span>*[bar<span class="space"> </span>[baz](/uri)](/uri)*](/uri) </code></pre> <pre><code class="language-html">&lt;p&gt;[foo<span class="space"> </span>&lt;em&gt;[bar<span class="space"> </span>&lt;a<span class="space"> </span>href=&quot;/uri&quot;&gt;baz&lt;/a&gt;](/uri)&lt;/em&gt;](/uri)&lt;/p&gt; </code></pre> </div> <div class="example" id="example-473" data-section="Links"> <div class="examplenum"><a href="#example-473">Example 473</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">![[[foo](uri1)](uri2)](uri3) </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;img<span class="space"> </span>src=&quot;uri3&quot;<span class="space"> </span>alt=&quot;[foo](uri2)&quot;<span class="space"> </span>/&gt;&lt;/p&gt; </code></pre> </div> <p>These cases illustrate the precedence of link text grouping over emphasis grouping:</p> <div class="example" id="example-474" data-section="Links"> <div class="examplenum"><a href="#example-474">Example 474</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">*[foo*](/uri) </code></pre> <pre><code class="language-html">&lt;p&gt;*&lt;a<span class="space"> </span>href=&quot;/uri&quot;&gt;foo*&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-475" data-section="Links"> <div class="examplenum"><a href="#example-475">Example 475</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo<span class="space"> </span>*bar](baz*) </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;baz*&quot;&gt;foo<span class="space"> </span>*bar&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>Note that brackets that <em>aren’t</em> part of links do not take precedence:</p> <div class="example" id="example-476" data-section="Links"> <div class="examplenum"><a href="#example-476">Example 476</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">*foo<span class="space"> </span>[bar*<span class="space"> </span>baz] </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;foo<span class="space"> </span>[bar&lt;/em&gt;<span class="space"> </span>baz]&lt;/p&gt; </code></pre> </div> <p>These cases illustrate the precedence of HTML tags, code spans, and autolinks over link grouping:</p> <div class="example" id="example-477" data-section="Links"> <div class="examplenum"><a href="#example-477">Example 477</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo<span class="space"> </span>&lt;bar<span class="space"> </span>attr=&quot;](baz)&quot;&gt; </code></pre> <pre><code class="language-html">&lt;p&gt;[foo<span class="space"> </span>&lt;bar<span class="space"> </span>attr=&quot;](baz)&quot;&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-478" data-section="Links"> <div class="examplenum"><a href="#example-478">Example 478</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo`](/uri)` </code></pre> <pre><code class="language-html">&lt;p&gt;[foo&lt;code&gt;](/uri)&lt;/code&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-479" data-section="Links"> <div class="examplenum"><a href="#example-479">Example 479</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo&lt;http://example.com/?search=](uri)&gt; </code></pre> <pre><code class="language-html">&lt;p&gt;[foo&lt;a<span class="space"> </span>href=&quot;http://example.com/?search=%5D(uri)&quot;&gt;http://example.com/?search=](uri)&lt;/a&gt;&lt;/p&gt; </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 <a href="#whitespace">whitespace</a>, 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. Between these brackets there must be at least one <a href="#non-whitespace-character">non-whitespace character</a>. 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 <a href="#whitespace">whitespace</a> 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 class="example" id="example-480" data-section="Links"> <div class="examplenum"><a href="#example-480">Example 480</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo][bar] [bar]:<span class="space"> </span>/url<span class="space"> </span>&quot;title&quot; </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/url&quot;<span class="space"> </span>title=&quot;title&quot;&gt;foo&lt;/a&gt;&lt;/p&gt; </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 class="example" id="example-481" data-section="Links"> <div class="examplenum"><a href="#example-481">Example 481</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[link<span class="space"> </span>[foo<span class="space"> </span>[bar]]][ref] [ref]:<span class="space"> </span>/uri </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/uri&quot;&gt;link<span class="space"> </span>[foo<span class="space"> </span>[bar]]&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-482" data-section="Links"> <div class="examplenum"><a href="#example-482">Example 482</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[link<span class="space"> </span>\[bar][ref] [ref]:<span class="space"> </span>/uri </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/uri&quot;&gt;link<span class="space"> </span>[bar&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>The link text may contain inline content:</p> <div class="example" id="example-483" data-section="Links"> <div class="examplenum"><a href="#example-483">Example 483</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[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><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/uri&quot;&gt;link<span class="space"> </span>&lt;em&gt;foo<span class="space"> </span>&lt;strong&gt;bar&lt;/strong&gt;<span class="space"> </span>&lt;code&gt;#&lt;/code&gt;&lt;/em&gt;&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-484" data-section="Links"> <div class="examplenum"><a href="#example-484">Example 484</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[![moon](moon.jpg)][ref] [ref]:<span class="space"> </span>/uri </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/uri&quot;&gt;&lt;img<span class="space"> </span>src=&quot;moon.jpg&quot;<span class="space"> </span>alt=&quot;moon&quot;<span class="space"> </span>/&gt;&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>However, links may not contain other links, at any level of nesting.</p> <div class="example" id="example-485" data-section="Links"> <div class="examplenum"><a href="#example-485">Example 485</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo<span class="space"> </span>[bar](/uri)][ref] [ref]:<span class="space"> </span>/uri </code></pre> <pre><code class="language-html">&lt;p&gt;[foo<span class="space"> </span>&lt;a<span class="space"> </span>href=&quot;/uri&quot;&gt;bar&lt;/a&gt;]&lt;a<span class="space"> </span>href=&quot;/uri&quot;&gt;ref&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-486" data-section="Links"> <div class="examplenum"><a href="#example-486">Example 486</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo<span class="space"> </span>*bar<span class="space"> </span>[baz][ref]*][ref] [ref]:<span class="space"> </span>/uri </code></pre> <pre><code class="language-html">&lt;p&gt;[foo<span class="space"> </span>&lt;em&gt;bar<span class="space"> </span>&lt;a<span class="space"> </span>href=&quot;/uri&quot;&gt;baz&lt;/a&gt;&lt;/em&gt;]&lt;a<span class="space"> </span>href=&quot;/uri&quot;&gt;ref&lt;/a&gt;&lt;/p&gt; </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 class="example" id="example-487" data-section="Links"> <div class="examplenum"><a href="#example-487">Example 487</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">*[foo*][ref] [ref]:<span class="space"> </span>/uri </code></pre> <pre><code class="language-html">&lt;p&gt;*&lt;a<span class="space"> </span>href=&quot;/uri&quot;&gt;foo*&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-488" data-section="Links"> <div class="examplenum"><a href="#example-488">Example 488</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo<span class="space"> </span>*bar][ref] [ref]:<span class="space"> </span>/uri </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/uri&quot;&gt;foo<span class="space"> </span>*bar&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>These cases illustrate the precedence of HTML tags, code spans, and autolinks over link grouping:</p> <div class="example" id="example-489" data-section="Links"> <div class="examplenum"><a href="#example-489">Example 489</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo<span class="space"> </span>&lt;bar<span class="space"> </span>attr=&quot;][ref]&quot;&gt; [ref]:<span class="space"> </span>/uri </code></pre> <pre><code class="language-html">&lt;p&gt;[foo<span class="space"> </span>&lt;bar<span class="space"> </span>attr=&quot;][ref]&quot;&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-490" data-section="Links"> <div class="examplenum"><a href="#example-490">Example 490</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo`][ref]` [ref]:<span class="space"> </span>/uri </code></pre> <pre><code class="language-html">&lt;p&gt;[foo&lt;code&gt;][ref]&lt;/code&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-491" data-section="Links"> <div class="examplenum"><a href="#example-491">Example 491</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo&lt;http://example.com/?search=][ref]&gt; [ref]:<span class="space"> </span>/uri </code></pre> <pre><code class="language-html">&lt;p&gt;[foo&lt;a<span class="space"> </span>href=&quot;http://example.com/?search=%5D%5Bref%5D&quot;&gt;http://example.com/?search=][ref]&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>Matching is case-insensitive:</p> <div class="example" id="example-492" data-section="Links"> <div class="examplenum"><a href="#example-492">Example 492</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo][BaR] [bar]:<span class="space"> </span>/url<span class="space"> </span>&quot;title&quot; </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/url&quot;<span class="space"> </span>title=&quot;title&quot;&gt;foo&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>Unicode case fold is used:</p> <div class="example" id="example-493" data-section="Links"> <div class="examplenum"><a href="#example-493">Example 493</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[Толпой][Толпой]<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><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/url&quot;&gt;Толпой&lt;/a&gt;<span class="space"> </span>is<span class="space"> </span>a<span class="space"> </span>Russian<span class="space"> </span>word.&lt;/p&gt; </code></pre> </div> <p>Consecutive internal <a href="#whitespace">whitespace</a> is treated as one space for purposes of determining matching:</p> <div class="example" id="example-494" data-section="Links"> <div class="examplenum"><a href="#example-494">Example 494</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[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><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/url&quot;&gt;Baz&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>There can be <a href="#whitespace">whitespace</a> between the <a href="#link-text">link text</a> and the <a href="#link-label">link label</a>:</p> <div class="example" id="example-495" data-section="Links"> <div class="examplenum"><a href="#example-495">Example 495</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo]<span class="space"> </span>[bar] [bar]:<span class="space"> </span>/url<span class="space"> </span>&quot;title&quot; </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/url&quot;<span class="space"> </span>title=&quot;title&quot;&gt;foo&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-496" data-section="Links"> <div class="examplenum"><a href="#example-496">Example 496</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo] [bar] [bar]:<span class="space"> </span>/url<span class="space"> </span>&quot;title&quot; </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/url&quot;<span class="space"> </span>title=&quot;title&quot;&gt;foo&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>When there are multiple matching <a href="#link-reference-definition">link reference definitions</a>, the first is used:</p> <div class="example" id="example-497" data-section="Links"> <div class="examplenum"><a href="#example-497">Example 497</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo]:<span class="space"> </span>/url1 [foo]:<span class="space"> </span>/url2 [bar][foo] </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/url1&quot;&gt;bar&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>Note that matching is performed on normalized strings, not parsed inline content. So the following does not match, even though the labels define equivalent inline content:</p> <div class="example" id="example-498" data-section="Links"> <div class="examplenum"><a href="#example-498">Example 498</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[bar][foo\!] [foo!]:<span class="space"> </span>/url </code></pre> <pre><code class="language-html">&lt;p&gt;[bar][foo!]&lt;/p&gt; </code></pre> </div> <p><a href="#link-label">Link labels</a> cannot contain brackets, unless they are backslash-escaped:</p> <div class="example" id="example-499" data-section="Links"> <div class="examplenum"><a href="#example-499">Example 499</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo][ref[] [ref[]:<span class="space"> </span>/uri </code></pre> <pre><code class="language-html">&lt;p&gt;[foo][ref[]&lt;/p&gt; &lt;p&gt;[ref[]:<span class="space"> </span>/uri&lt;/p&gt; </code></pre> </div> <div class="example" id="example-500" data-section="Links"> <div class="examplenum"><a href="#example-500">Example 500</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo][ref[bar]] [ref[bar]]:<span class="space"> </span>/uri </code></pre> <pre><code class="language-html">&lt;p&gt;[foo][ref[bar]]&lt;/p&gt; &lt;p&gt;[ref[bar]]:<span class="space"> </span>/uri&lt;/p&gt; </code></pre> </div> <div class="example" id="example-501" data-section="Links"> <div class="examplenum"><a href="#example-501">Example 501</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[[[foo]]] [[[foo]]]:<span class="space"> </span>/url </code></pre> <pre><code class="language-html">&lt;p&gt;[[[foo]]]&lt;/p&gt; &lt;p&gt;[[[foo]]]:<span class="space"> </span>/url&lt;/p&gt; </code></pre> </div> <div class="example" id="example-502" data-section="Links"> <div class="examplenum"><a href="#example-502">Example 502</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo][ref\[] [ref\[]:<span class="space"> </span>/uri </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/uri&quot;&gt;foo&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>A <a href="#link-label">link label</a> must contain at least one <a href="#non-whitespace-character">non-whitespace character</a>:</p> <div class="example" id="example-503" data-section="Links"> <div class="examplenum"><a href="#example-503">Example 503</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[] []:<span class="space"> </span>/uri </code></pre> <pre><code class="language-html">&lt;p&gt;[]&lt;/p&gt; &lt;p&gt;[]:<span class="space"> </span>/uri&lt;/p&gt; </code></pre> </div> <div class="example" id="example-504" data-section="Links"> <div class="examplenum"><a href="#example-504">Example 504</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[ <span class="space"> </span>] [ <span class="space"> </span>]:<span class="space"> </span>/uri </code></pre> <pre><code class="language-html">&lt;p&gt;[ ]&lt;/p&gt; &lt;p&gt;[ ]:<span class="space"> </span>/uri&lt;/p&gt; </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 <a href="#whitespace">whitespace</a>, 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 class="example" id="example-505" data-section="Links"> <div class="examplenum"><a href="#example-505">Example 505</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo][] [foo]:<span class="space"> </span>/url<span class="space"> </span>&quot;title&quot; </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/url&quot;<span class="space"> </span>title=&quot;title&quot;&gt;foo&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-506" data-section="Links"> <div class="examplenum"><a href="#example-506">Example 506</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[*foo*<span class="space"> </span>bar][] [*foo*<span class="space"> </span>bar]:<span class="space"> </span>/url<span class="space"> </span>&quot;title&quot; </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/url&quot;<span class="space"> </span>title=&quot;title&quot;&gt;&lt;em&gt;foo&lt;/em&gt;<span class="space"> </span>bar&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>The link labels are case-insensitive:</p> <div class="example" id="example-507" data-section="Links"> <div class="examplenum"><a href="#example-507">Example 507</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[Foo][] [foo]:<span class="space"> </span>/url<span class="space"> </span>&quot;title&quot; </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/url&quot;<span class="space"> </span>title=&quot;title&quot;&gt;Foo&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>As with full reference links, <a href="#whitespace">whitespace</a> is allowed between the two sets of brackets:</p> <div class="example" id="example-508" data-section="Links"> <div class="examplenum"><a href="#example-508">Example 508</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo]<span class="space"> </span> [] [foo]:<span class="space"> </span>/url<span class="space"> </span>&quot;title&quot; </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/url&quot;<span class="space"> </span>title=&quot;title&quot;&gt;foo&lt;/a&gt;&lt;/p&gt; </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 class="example" id="example-509" data-section="Links"> <div class="examplenum"><a href="#example-509">Example 509</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo] [foo]:<span class="space"> </span>/url<span class="space"> </span>&quot;title&quot; </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/url&quot;<span class="space"> </span>title=&quot;title&quot;&gt;foo&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-510" data-section="Links"> <div class="examplenum"><a href="#example-510">Example 510</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[*foo*<span class="space"> </span>bar] [*foo*<span class="space"> </span>bar]:<span class="space"> </span>/url<span class="space"> </span>&quot;title&quot; </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/url&quot;<span class="space"> </span>title=&quot;title&quot;&gt;&lt;em&gt;foo&lt;/em&gt;<span class="space"> </span>bar&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-511" data-section="Links"> <div class="examplenum"><a href="#example-511">Example 511</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[[*foo*<span class="space"> </span>bar]] [*foo*<span class="space"> </span>bar]:<span class="space"> </span>/url<span class="space"> </span>&quot;title&quot; </code></pre> <pre><code class="language-html">&lt;p&gt;[&lt;a<span class="space"> </span>href=&quot;/url&quot;<span class="space"> </span>title=&quot;title&quot;&gt;&lt;em&gt;foo&lt;/em&gt;<span class="space"> </span>bar&lt;/a&gt;]&lt;/p&gt; </code></pre> </div> <div class="example" id="example-512" data-section="Links"> <div class="examplenum"><a href="#example-512">Example 512</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[[bar<span class="space"> </span>[foo] [foo]:<span class="space"> </span>/url </code></pre> <pre><code class="language-html">&lt;p&gt;[[bar<span class="space"> </span>&lt;a<span class="space"> </span>href=&quot;/url&quot;&gt;foo&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>The link labels are case-insensitive:</p> <div class="example" id="example-513" data-section="Links"> <div class="examplenum"><a href="#example-513">Example 513</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[Foo] [foo]:<span class="space"> </span>/url<span class="space"> </span>&quot;title&quot; </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/url&quot;<span class="space"> </span>title=&quot;title&quot;&gt;Foo&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>A space after the link text should be preserved:</p> <div class="example" id="example-514" data-section="Links"> <div class="examplenum"><a href="#example-514">Example 514</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo]<span class="space"> </span>bar [foo]:<span class="space"> </span>/url </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/url&quot;&gt;foo&lt;/a&gt;<span class="space"> </span>bar&lt;/p&gt; </code></pre> </div> <p>If you just want bracketed text, you can backslash-escape the opening bracket to avoid links:</p> <div class="example" id="example-515" data-section="Links"> <div class="examplenum"><a href="#example-515">Example 515</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">\[foo] [foo]:<span class="space"> </span>/url<span class="space"> </span>&quot;title&quot; </code></pre> <pre><code class="language-html">&lt;p&gt;[foo]&lt;/p&gt; </code></pre> </div> <p>Note that this is a link, because a link label ends with the first following closing bracket:</p> <div class="example" id="example-516" data-section="Links"> <div class="examplenum"><a href="#example-516">Example 516</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo*]:<span class="space"> </span>/url *[foo*] </code></pre> <pre><code class="language-html">&lt;p&gt;*&lt;a<span class="space"> </span>href=&quot;/url&quot;&gt;foo*&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>Full references take precedence over shortcut references:</p> <div class="example" id="example-517" data-section="Links"> <div class="examplenum"><a href="#example-517">Example 517</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo][bar] [foo]:<span class="space"> </span>/url1 [bar]:<span class="space"> </span>/url2 </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/url2&quot;&gt;foo&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>In the following case <code>[bar][baz]</code> is parsed as a reference, <code>[foo]</code> as normal text:</p> <div class="example" id="example-518" data-section="Links"> <div class="examplenum"><a href="#example-518">Example 518</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo][bar][baz] [baz]:<span class="space"> </span>/url </code></pre> <pre><code class="language-html">&lt;p&gt;[foo]&lt;a<span class="space"> </span>href=&quot;/url&quot;&gt;bar&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>Here, though, <code>[foo][bar]</code> is parsed as a reference, since <code>[bar]</code> is defined:</p> <div class="example" id="example-519" data-section="Links"> <div class="examplenum"><a href="#example-519">Example 519</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo][bar][baz] [baz]:<span class="space"> </span>/url1 [bar]:<span class="space"> </span>/url2 </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/url2&quot;&gt;foo&lt;/a&gt;&lt;a<span class="space"> </span>href=&quot;/url1&quot;&gt;baz&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>Here <code>[foo]</code> is not parsed as a shortcut reference, because it is followed by a link label (even though <code>[bar]</code> is not defined):</p> <div class="example" id="example-520" data-section="Links"> <div class="examplenum"><a href="#example-520">Example 520</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">[foo][bar][baz] [baz]:<span class="space"> </span>/url1 [foo]:<span class="space"> </span>/url2 </code></pre> <pre><code class="language-html">&lt;p&gt;[foo]&lt;a<span class="space"> </span>href=&quot;/url1&quot;&gt;bar&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <h2><a id="images"></a><span class="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. 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 class="example" id="example-521" data-section="Images"> <div class="examplenum"><a href="#example-521">Example 521</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">![foo](/url<span class="space"> </span>&quot;title&quot;) </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;img<span class="space"> </span>src=&quot;/url&quot;<span class="space"> </span>alt=&quot;foo&quot;<span class="space"> </span>title=&quot;title&quot;<span class="space"> </span>/&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-522" data-section="Images"> <div class="examplenum"><a href="#example-522">Example 522</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">![foo<span class="space"> </span>*bar*] [foo<span class="space"> </span>*bar*]:<span class="space"> </span>train.jpg<span class="space"> </span>&quot;train<span class="space"> </span>&amp;<span class="space"> </span>tracks&quot; </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;img<span class="space"> </span>src=&quot;train.jpg&quot;<span class="space"> </span>alt=&quot;foo<span class="space"> </span>bar&quot;<span class="space"> </span>title=&quot;train<span class="space"> </span>&amp;amp;<span class="space"> </span>tracks&quot;<span class="space"> </span>/&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-523" data-section="Images"> <div class="examplenum"><a href="#example-523">Example 523</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">![foo<span class="space"> </span>![bar](/url)](/url2) </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;img<span class="space"> </span>src=&quot;/url2&quot;<span class="space"> </span>alt=&quot;foo<span class="space"> </span>bar&quot;<span class="space"> </span>/&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-524" data-section="Images"> <div class="examplenum"><a href="#example-524">Example 524</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">![foo<span class="space"> </span>[bar](/url)](/url2) </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;img<span class="space"> </span>src=&quot;/url2&quot;<span class="space"> </span>alt=&quot;foo<span class="space"> </span>bar&quot;<span class="space"> </span>/&gt;&lt;/p&gt; </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 &lt;a href=&quot;/url&quot;&gt;bar&lt;/a&gt;</code>. Only the plain string content is rendered, without formatting.</p> <div class="example" id="example-525" data-section="Images"> <div class="examplenum"><a href="#example-525">Example 525</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">![foo<span class="space"> </span>*bar*][] [foo<span class="space"> </span>*bar*]:<span class="space"> </span>train.jpg<span class="space"> </span>&quot;train<span class="space"> </span>&amp;<span class="space"> </span>tracks&quot; </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;img<span class="space"> </span>src=&quot;train.jpg&quot;<span class="space"> </span>alt=&quot;foo<span class="space"> </span>bar&quot;<span class="space"> </span>title=&quot;train<span class="space"> </span>&amp;amp;<span class="space"> </span>tracks&quot;<span class="space"> </span>/&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-526" data-section="Images"> <div class="examplenum"><a href="#example-526">Example 526</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">![foo<span class="space"> </span>*bar*][foobar] [FOOBAR]:<span class="space"> </span>train.jpg<span class="space"> </span>&quot;train<span class="space"> </span>&amp;<span class="space"> </span>tracks&quot; </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;img<span class="space"> </span>src=&quot;train.jpg&quot;<span class="space"> </span>alt=&quot;foo<span class="space"> </span>bar&quot;<span class="space"> </span>title=&quot;train<span class="space"> </span>&amp;amp;<span class="space"> </span>tracks&quot;<span class="space"> </span>/&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-527" data-section="Images"> <div class="examplenum"><a href="#example-527">Example 527</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">![foo](train.jpg) </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;img<span class="space"> </span>src=&quot;train.jpg&quot;<span class="space"> </span>alt=&quot;foo&quot;<span class="space"> </span>/&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-528" data-section="Images"> <div class="examplenum"><a href="#example-528">Example 528</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">My<span class="space"> </span>![foo<span class="space"> </span>bar](/path/to/train.jpg<span class="space"> </span><span class="space"> </span>&quot;title&quot;<span class="space"> </span><span class="space"> </span><span class="space"> </span>) </code></pre> <pre><code class="language-html">&lt;p&gt;My<span class="space"> </span>&lt;img<span class="space"> </span>src=&quot;/path/to/train.jpg&quot;<span class="space"> </span>alt=&quot;foo<span class="space"> </span>bar&quot;<span class="space"> </span>title=&quot;title&quot;<span class="space"> </span>/&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-529" data-section="Images"> <div class="examplenum"><a href="#example-529">Example 529</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">![foo](&lt;url&gt;) </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;img<span class="space"> </span>src=&quot;url&quot;<span class="space"> </span>alt=&quot;foo&quot;<span class="space"> </span>/&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-530" data-section="Images"> <div class="examplenum"><a href="#example-530">Example 530</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">![](/url) </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;img<span class="space"> </span>src=&quot;/url&quot;<span class="space"> </span>alt=&quot;&quot;<span class="space"> </span>/&gt;&lt;/p&gt; </code></pre> </div> <p>Reference-style:</p> <div class="example" id="example-531" data-section="Images"> <div class="examplenum"><a href="#example-531">Example 531</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">![foo]<span class="space"> </span>[bar] [bar]:<span class="space"> </span>/url </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;img<span class="space"> </span>src=&quot;/url&quot;<span class="space"> </span>alt=&quot;foo&quot;<span class="space"> </span>/&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-532" data-section="Images"> <div class="examplenum"><a href="#example-532">Example 532</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">![foo]<span class="space"> </span>[bar] [BAR]:<span class="space"> </span>/url </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;img<span class="space"> </span>src=&quot;/url&quot;<span class="space"> </span>alt=&quot;foo&quot;<span class="space"> </span>/&gt;&lt;/p&gt; </code></pre> </div> <p>Collapsed:</p> <div class="example" id="example-533" data-section="Images"> <div class="examplenum"><a href="#example-533">Example 533</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">![foo][] [foo]:<span class="space"> </span>/url<span class="space"> </span>&quot;title&quot; </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;img<span class="space"> </span>src=&quot;/url&quot;<span class="space"> </span>alt=&quot;foo&quot;<span class="space"> </span>title=&quot;title&quot;<span class="space"> </span>/&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-534" data-section="Images"> <div class="examplenum"><a href="#example-534">Example 534</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">![*foo*<span class="space"> </span>bar][] [*foo*<span class="space"> </span>bar]:<span class="space"> </span>/url<span class="space"> </span>&quot;title&quot; </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;img<span class="space"> </span>src=&quot;/url&quot;<span class="space"> </span>alt=&quot;foo<span class="space"> </span>bar&quot;<span class="space"> </span>title=&quot;title&quot;<span class="space"> </span>/&gt;&lt;/p&gt; </code></pre> </div> <p>The labels are case-insensitive:</p> <div class="example" id="example-535" data-section="Images"> <div class="examplenum"><a href="#example-535">Example 535</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">![Foo][] [foo]:<span class="space"> </span>/url<span class="space"> </span>&quot;title&quot; </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;img<span class="space"> </span>src=&quot;/url&quot;<span class="space"> </span>alt=&quot;Foo&quot;<span class="space"> </span>title=&quot;title&quot;<span class="space"> </span>/&gt;&lt;/p&gt; </code></pre> </div> <p>As with full reference links, <a href="#whitespace">whitespace</a> is allowed between the two sets of brackets:</p> <div class="example" id="example-536" data-section="Images"> <div class="examplenum"><a href="#example-536">Example 536</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">![foo]<span class="space"> </span> [] [foo]:<span class="space"> </span>/url<span class="space"> </span>&quot;title&quot; </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;img<span class="space"> </span>src=&quot;/url&quot;<span class="space"> </span>alt=&quot;foo&quot;<span class="space"> </span>title=&quot;title&quot;<span class="space"> </span>/&gt;&lt;/p&gt; </code></pre> </div> <p>Shortcut:</p> <div class="example" id="example-537" data-section="Images"> <div class="examplenum"><a href="#example-537">Example 537</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">![foo] [foo]:<span class="space"> </span>/url<span class="space"> </span>&quot;title&quot; </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;img<span class="space"> </span>src=&quot;/url&quot;<span class="space"> </span>alt=&quot;foo&quot;<span class="space"> </span>title=&quot;title&quot;<span class="space"> </span>/&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-538" data-section="Images"> <div class="examplenum"><a href="#example-538">Example 538</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">![*foo*<span class="space"> </span>bar] [*foo*<span class="space"> </span>bar]:<span class="space"> </span>/url<span class="space"> </span>&quot;title&quot; </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;img<span class="space"> </span>src=&quot;/url&quot;<span class="space"> </span>alt=&quot;foo<span class="space"> </span>bar&quot;<span class="space"> </span>title=&quot;title&quot;<span class="space"> </span>/&gt;&lt;/p&gt; </code></pre> </div> <p>Note that link labels cannot contain unescaped brackets:</p> <div class="example" id="example-539" data-section="Images"> <div class="examplenum"><a href="#example-539">Example 539</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">![[foo]] [[foo]]:<span class="space"> </span>/url<span class="space"> </span>&quot;title&quot; </code></pre> <pre><code class="language-html">&lt;p&gt;![[foo]]&lt;/p&gt; &lt;p&gt;[[foo]]:<span class="space"> </span>/url<span class="space"> </span>&amp;quot;title&amp;quot;&lt;/p&gt; </code></pre> </div> <p>The link labels are case-insensitive:</p> <div class="example" id="example-540" data-section="Images"> <div class="examplenum"><a href="#example-540">Example 540</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">![Foo] [foo]:<span class="space"> </span>/url<span class="space"> </span>&quot;title&quot; </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;img<span class="space"> </span>src=&quot;/url&quot;<span class="space"> </span>alt=&quot;Foo&quot;<span class="space"> </span>title=&quot;title&quot;<span class="space"> </span>/&gt;&lt;/p&gt; </code></pre> </div> <p>If you just want bracketed text, you can backslash-escape the opening <code>!</code> and <code>[</code>:</p> <div class="example" id="example-541" data-section="Images"> <div class="examplenum"><a href="#example-541">Example 541</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">\!\[foo] [foo]:<span class="space"> </span>/url<span class="space"> </span>&quot;title&quot; </code></pre> <pre><code class="language-html">&lt;p&gt;![foo]&lt;/p&gt; </code></pre> </div> <p>If you want a link after a literal <code>!</code>, backslash-escape the <code>!</code>:</p> <div class="example" id="example-542" data-section="Images"> <div class="examplenum"><a href="#example-542">Example 542</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">\![foo] [foo]:<span class="space"> </span>/url<span class="space"> </span>&quot;title&quot; </code></pre> <pre><code class="language-html">&lt;p&gt;!&lt;a<span class="space"> </span>href=&quot;/url&quot;<span class="space"> </span>title=&quot;title&quot;&gt;foo&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <h2><a id="autolinks"></a><span class="number">6.7</span> Autolinks</h2> <p><a id="autolink" href="#autolink" class="definition">Autolinks</a> are absolute URIs and email addresses inside <code>&lt;</code> and <code>&gt;</code>. They are parsed as links, with the URL or email address as the link label.</p> <p>A <a id="uri-autolink" href="#uri-autolink" class="definition">URI autolink</a> consists of <code>&lt;</code>, followed by an <a href="#absolute-uri">absolute URI</a> not containing <code>&lt;</code>, followed by <code>&gt;</code>. It is parsed as a link to the URI, with the URI as the link’s label.</p> <p>An <a id="absolute-uri" href="#absolute-uri" class="definition">absolute URI</a>, for these purposes, consists of a [scheme] followed by a colon (<code>:</code>) followed by zero or more characters other than ASCII <a href="#whitespace">whitespace</a> and control characters, <code>&lt;</code>, and <code>&gt;</code>. If the URI includes these characters, you must use percent-encoding (e.g. <code>%20</code> for a space).</p> <p>The following <a 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 class="example" id="example-543" data-section="Autolinks"> <div class="examplenum"><a href="#example-543">Example 543</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;http://foo.bar.baz&gt; </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;http://foo.bar.baz&quot;&gt;http://foo.bar.baz&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-544" data-section="Autolinks"> <div class="examplenum"><a href="#example-544">Example 544</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;http://foo.bar.baz/test?q=hello&amp;id=22&amp;boolean&gt; </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;http://foo.bar.baz/test?q=hello&amp;amp;id=22&amp;amp;boolean&quot;&gt;http://foo.bar.baz/test?q=hello&amp;amp;id=22&amp;amp;boolean&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-545" data-section="Autolinks"> <div class="examplenum"><a href="#example-545">Example 545</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;irc://foo.bar:2233/baz&gt; </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;irc://foo.bar:2233/baz&quot;&gt;irc://foo.bar:2233/baz&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>Uppercase is also fine:</p> <div class="example" id="example-546" data-section="Autolinks"> <div class="examplenum"><a href="#example-546">Example 546</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;MAILTO:FOO@BAR.BAZ&gt; </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;MAILTO:FOO@BAR.BAZ&quot;&gt;MAILTO:FOO@BAR.BAZ&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>Spaces are not allowed in autolinks:</p> <div class="example" id="example-547" data-section="Autolinks"> <div class="examplenum"><a href="#example-547">Example 547</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;http://foo.bar/baz<span class="space"> </span>bim&gt; </code></pre> <pre><code class="language-html">&lt;p&gt;&amp;lt;http://foo.bar/baz<span class="space"> </span>bim&amp;gt;&lt;/p&gt; </code></pre> </div> <p>Backslash-escapes do not work inside autolinks:</p> <div class="example" id="example-548" data-section="Autolinks"> <div class="examplenum"><a href="#example-548">Example 548</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;http://example.com/\[\&gt; </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;http://example.com/%5C%5B%5C&quot;&gt;http://example.com/\[\&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>An <a id="email-autolink" href="#email-autolink" class="definition">email autolink</a> consists of <code>&lt;</code>, followed by an <a href="#email-address">email address</a>, followed by <code>&gt;</code>. The link’s label is the email address, and the URL is <code>mailto:</code> followed by the email address.</p> <p>An <a id="email-address" href="#email-address" class="definition">email address</a>, for these purposes, is anything that matches the <a href="https://html.spec.whatwg.org/multipage/forms.html#e-mail-state-(type=email)">non-normative regex from the HTML5 spec</a>:</p> <pre><code>/^[a-zA-Z0-9.!#$%&amp;'*+/=?^_`{|}~-]+@[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 class="example" id="example-549" data-section="Autolinks"> <div class="examplenum"><a href="#example-549">Example 549</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;foo@bar.example.com&gt; </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;mailto:foo@bar.example.com&quot;&gt;foo@bar.example.com&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-550" data-section="Autolinks"> <div class="examplenum"><a href="#example-550">Example 550</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;foo+special@Bar.baz-bar0.com&gt; </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;mailto:foo+special@Bar.baz-bar0.com&quot;&gt;foo+special@Bar.baz-bar0.com&lt;/a&gt;&lt;/p&gt; </code></pre> </div> <p>Backslash-escapes do not work inside email autolinks:</p> <div class="example" id="example-551" data-section="Autolinks"> <div class="examplenum"><a href="#example-551">Example 551</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;foo\+@bar.example.com&gt; </code></pre> <pre><code class="language-html">&lt;p&gt;&amp;lt;foo+@bar.example.com&amp;gt;&lt;/p&gt; </code></pre> </div> <p>These are not autolinks:</p> <div class="example" id="example-552" data-section="Autolinks"> <div class="examplenum"><a href="#example-552">Example 552</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;&gt; </code></pre> <pre><code class="language-html">&lt;p&gt;&amp;lt;&amp;gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-553" data-section="Autolinks"> <div class="examplenum"><a href="#example-553">Example 553</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;heck://bing.bong&gt; </code></pre> <pre><code class="language-html">&lt;p&gt;&amp;lt;heck://bing.bong&amp;gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-554" data-section="Autolinks"> <div class="examplenum"><a href="#example-554">Example 554</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;<span class="space"> </span>http://foo.bar<span class="space"> </span>&gt; </code></pre> <pre><code class="language-html">&lt;p&gt;&amp;lt;<span class="space"> </span>http://foo.bar<span class="space"> </span>&amp;gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-555" data-section="Autolinks"> <div class="examplenum"><a href="#example-555">Example 555</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;foo.bar.baz&gt; </code></pre> <pre><code class="language-html">&lt;p&gt;&amp;lt;foo.bar.baz&amp;gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-556" data-section="Autolinks"> <div class="examplenum"><a href="#example-556">Example 556</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;localhost:5001/foo&gt; </code></pre> <pre><code class="language-html">&lt;p&gt;&amp;lt;localhost:5001/foo&amp;gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-557" data-section="Autolinks"> <div class="examplenum"><a href="#example-557">Example 557</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">http://example.com </code></pre> <pre><code class="language-html">&lt;p&gt;http://example.com&lt;/p&gt; </code></pre> </div> <div class="example" id="example-558" data-section="Autolinks"> <div class="examplenum"><a href="#example-558">Example 558</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">foo@bar.example.com </code></pre> <pre><code class="language-html">&lt;p&gt;foo@bar.example.com&lt;/p&gt; </code></pre> </div> <h2><a id="raw-html"></a><span class="number">6.8</span> Raw HTML</h2> <p>Text between <code>&lt;</code> and <code>&gt;</code> that looks like an HTML tag is parsed as a raw HTML tag and will be rendered in HTML without escaping. Tag and attribute names are not limited to current HTML tags, so custom tags (and even, say, DocBook tags) may be used.</p> <p>Here is the grammar for tags:</p> <p>A <a id="tag-name" href="#tag-name" class="definition">tag name</a> consists of an ASCII letter followed by zero or more ASCII letters, digits, or hyphens (<code>-</code>).</p> <p>An <a id="attribute" href="#attribute" class="definition">attribute</a> consists of <a href="#whitespace">whitespace</a>, 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 <a href="#whitespace">whitespace</a>, a <code>=</code> character, optional <a href="#whitespace">whitespace</a>, 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>&quot;</code>, <code>'</code>, <code>=</code>, <code>&lt;</code>, <code>&gt;</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>&quot;</code>, zero or more characters not including <code>&quot;</code>, and a final <code>&quot;</code>.</p> <p>An <a id="open-tag" href="#open-tag" class="definition">open tag</a> consists of a <code>&lt;</code> character, a <a href="#tag-name">tag name</a>, zero or more [attributes](@attribute], optional <a href="#whitespace">whitespace</a>, an optional <code>/</code> character, and a <code>&gt;</code> character.</p> <p>A <a id="closing-tag" href="#closing-tag" class="definition">closing tag</a> consists of the string <code>&lt;/</code>, a <a href="#tag-name">tag name</a>, optional <a href="#whitespace">whitespace</a>, and the character <code>&gt;</code>.</p> <p>An <a id="html-comment" href="#html-comment" class="definition">HTML comment</a> consists of <code>&lt;!--</code> + <em>text</em> + <code>--&gt;</code>, where <em>text</em> does not start with <code>&gt;</code> or <code>-&gt;</code>, does not end with <code>-</code>, and does not contain <code>--</code>. (See the <a href="http://www.w3.org/TR/html5/syntax.html#comments">HTML5 spec</a>.)</p> <p>A <a id="processing-instruction" href="#processing-instruction" class="definition">processing instruction</a> consists of the string <code>&lt;?</code>, a string of characters not including the string <code>?&gt;</code>, and the string <code>?&gt;</code>.</p> <p>A <a id="declaration" href="#declaration" class="definition">declaration</a> consists of the string <code>&lt;!</code>, a name consisting of one or more uppercase ASCII letters, <a href="#whitespace">whitespace</a>, a string of characters not including the character <code>&gt;</code>, and the character <code>&gt;</code>.</p> <p>A <a id="cdata-section" href="#cdata-section" class="definition">CDATA section</a> consists of the string <code>&lt;![CDATA[</code>, a string of characters not including the string <code>]]&gt;</code>, and the string <code>]]&gt;</code>.</p> <p>An <a 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>, a <a href="#declaration">declaration</a>, or a <a href="#cdata-section">CDATA section</a>.</p> <p>Here are some simple open tags:</p> <div class="example" id="example-559" data-section="Raw HTML"> <div class="examplenum"><a href="#example-559">Example 559</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;a&gt;&lt;bab&gt;&lt;c2c&gt; </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a&gt;&lt;bab&gt;&lt;c2c&gt;&lt;/p&gt; </code></pre> </div> <p>Empty elements:</p> <div class="example" id="example-560" data-section="Raw HTML"> <div class="examplenum"><a href="#example-560">Example 560</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;a/&gt;&lt;b2/&gt; </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a/&gt;&lt;b2/&gt;&lt;/p&gt; </code></pre> </div> <p><a href="#whitespace">Whitespace</a> is allowed:</p> <div class="example" id="example-561" data-section="Raw HTML"> <div class="examplenum"><a href="#example-561">Example 561</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;a<span class="space"> </span><span class="space"> </span>/&gt;&lt;b2 data=&quot;foo&quot;<span class="space"> </span>&gt; </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span><span class="space"> </span>/&gt;&lt;b2 data=&quot;foo&quot;<span class="space"> </span>&gt;&lt;/p&gt; </code></pre> </div> <p>With attributes:</p> <div class="example" id="example-562" data-section="Raw HTML"> <div class="examplenum"><a href="#example-562">Example 562</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;a<span class="space"> </span>foo=&quot;bar&quot;<span class="space"> </span>bam<span class="space"> </span>=<span class="space"> </span>'baz<span class="space"> </span>&lt;em&gt;&quot;&lt;/em&gt;' _boolean<span class="space"> </span>zoop:33=zoop:33<span class="space"> </span>/&gt; </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>foo=&quot;bar&quot;<span class="space"> </span>bam<span class="space"> </span>=<span class="space"> </span>'baz<span class="space"> </span>&lt;em&gt;&quot;&lt;/em&gt;' _boolean<span class="space"> </span>zoop:33=zoop:33<span class="space"> </span>/&gt;&lt;/p&gt; </code></pre> </div> <p>Custom tag names can be used:</p> <div class="example" id="example-563" data-section="Raw HTML"> <div class="examplenum"><a href="#example-563">Example 563</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;responsive-image<span class="space"> </span>src=&quot;foo.jpg&quot;<span class="space"> </span>/&gt; &lt;My-Tag&gt; foo &lt;/My-Tag&gt; </code></pre> <pre><code class="language-html">&lt;responsive-image<span class="space"> </span>src=&quot;foo.jpg&quot;<span class="space"> </span>/&gt; &lt;My-Tag&gt; foo &lt;/My-Tag&gt; </code></pre> </div> <p>Illegal tag names, not parsed as HTML:</p> <div class="example" id="example-564" data-section="Raw HTML"> <div class="examplenum"><a href="#example-564">Example 564</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;33&gt;<span class="space"> </span>&lt;__&gt; </code></pre> <pre><code class="language-html">&lt;p&gt;&amp;lt;33&amp;gt;<span class="space"> </span>&amp;lt;__&amp;gt;&lt;/p&gt; </code></pre> </div> <p>Illegal attribute names:</p> <div class="example" id="example-565" data-section="Raw HTML"> <div class="examplenum"><a href="#example-565">Example 565</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;a<span class="space"> </span>h*#ref=&quot;hi&quot;&gt; </code></pre> <pre><code class="language-html">&lt;p&gt;&amp;lt;a<span class="space"> </span>h*#ref=&amp;quot;hi&amp;quot;&amp;gt;&lt;/p&gt; </code></pre> </div> <p>Illegal attribute values:</p> <div class="example" id="example-566" data-section="Raw HTML"> <div class="examplenum"><a href="#example-566">Example 566</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;a<span class="space"> </span>href=&quot;hi'&gt;<span class="space"> </span>&lt;a<span class="space"> </span>href=hi'&gt; </code></pre> <pre><code class="language-html">&lt;p&gt;&amp;lt;a<span class="space"> </span>href=&amp;quot;hi'&amp;gt;<span class="space"> </span>&amp;lt;a<span class="space"> </span>href=hi'&amp;gt;&lt;/p&gt; </code></pre> </div> <p>Illegal <a href="#whitespace">whitespace</a>:</p> <div class="example" id="example-567" data-section="Raw HTML"> <div class="examplenum"><a href="#example-567">Example 567</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;<span class="space"> </span>a&gt;&lt; foo&gt;&lt;bar/<span class="space"> </span>&gt; </code></pre> <pre><code class="language-html">&lt;p&gt;&amp;lt;<span class="space"> </span>a&amp;gt;&amp;lt; foo&amp;gt;&amp;lt;bar/<span class="space"> </span>&amp;gt;&lt;/p&gt; </code></pre> </div> <p>Missing <a href="#whitespace">whitespace</a>:</p> <div class="example" id="example-568" data-section="Raw HTML"> <div class="examplenum"><a href="#example-568">Example 568</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;a<span class="space"> </span>href='bar'title=title&gt; </code></pre> <pre><code class="language-html">&lt;p&gt;&amp;lt;a<span class="space"> </span>href='bar'title=title&amp;gt;&lt;/p&gt; </code></pre> </div> <p>Closing tags:</p> <div class="example" id="example-569" data-section="Raw HTML"> <div class="examplenum"><a href="#example-569">Example 569</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;/a&gt; &lt;/foo<span class="space"> </span>&gt; </code></pre> <pre><code class="language-html">&lt;/a&gt; &lt;/foo<span class="space"> </span>&gt; </code></pre> </div> <p>Illegal attributes in closing tag:</p> <div class="example" id="example-570" data-section="Raw HTML"> <div class="examplenum"><a href="#example-570">Example 570</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;/a<span class="space"> </span>href=&quot;foo&quot;&gt; </code></pre> <pre><code class="language-html">&lt;p&gt;&amp;lt;/a<span class="space"> </span>href=&amp;quot;foo&amp;quot;&amp;gt;&lt;/p&gt; </code></pre> </div> <p>Comments:</p> <div class="example" id="example-571" data-section="Raw HTML"> <div class="examplenum"><a href="#example-571">Example 571</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">foo<span class="space"> </span>&lt;!--<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>--&gt; </code></pre> <pre><code class="language-html">&lt;p&gt;foo<span class="space"> </span>&lt;!--<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>--&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-572" data-section="Raw HTML"> <div class="examplenum"><a href="#example-572">Example 572</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">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; </code></pre> <pre><code class="language-html">&lt;p&gt;foo<span class="space"> </span>&amp;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>--&amp;gt;&lt;/p&gt; </code></pre> </div> <p>Not comments:</p> <div class="example" id="example-573" data-section="Raw HTML"> <div class="examplenum"><a href="#example-573">Example 573</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">foo<span class="space"> </span>&lt;!--&gt;<span class="space"> </span>foo<span class="space"> </span>--&gt; foo<span class="space"> </span>&lt;!--<span class="space"> </span>foo---&gt; </code></pre> <pre><code class="language-html">&lt;p&gt;foo<span class="space"> </span>&amp;lt;!--&amp;gt;<span class="space"> </span>foo<span class="space"> </span>--&amp;gt;&lt;/p&gt; &lt;p&gt;foo<span class="space"> </span>&amp;lt;!--<span class="space"> </span>foo---&amp;gt;&lt;/p&gt; </code></pre> </div> <p>Processing instructions:</p> <div class="example" id="example-574" data-section="Raw HTML"> <div class="examplenum"><a href="#example-574">Example 574</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">foo<span class="space"> </span>&lt;?php<span class="space"> </span>echo<span class="space"> </span>$a;<span class="space"> </span>?&gt; </code></pre> <pre><code class="language-html">&lt;p&gt;foo<span class="space"> </span>&lt;?php<span class="space"> </span>echo<span class="space"> </span>$a;<span class="space"> </span>?&gt;&lt;/p&gt; </code></pre> </div> <p>Declarations:</p> <div class="example" id="example-575" data-section="Raw HTML"> <div class="examplenum"><a href="#example-575">Example 575</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">foo<span class="space"> </span>&lt;!ELEMENT<span class="space"> </span>br<span class="space"> </span>EMPTY&gt; </code></pre> <pre><code class="language-html">&lt;p&gt;foo<span class="space"> </span>&lt;!ELEMENT<span class="space"> </span>br<span class="space"> </span>EMPTY&gt;&lt;/p&gt; </code></pre> </div> <p>CDATA sections:</p> <div class="example" id="example-576" data-section="Raw HTML"> <div class="examplenum"><a href="#example-576">Example 576</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">foo<span class="space"> </span>&lt;![CDATA[&gt;&amp;&lt;]]&gt; </code></pre> <pre><code class="language-html">&lt;p&gt;foo<span class="space"> </span>&lt;![CDATA[&gt;&amp;&lt;]]&gt;&lt;/p&gt; </code></pre> </div> <p>Entities are preserved in HTML attributes:</p> <div class="example" id="example-577" data-section="Raw HTML"> <div class="examplenum"><a href="#example-577">Example 577</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;a<span class="space"> </span>href=&quot;&amp;ouml;&quot;&gt; </code></pre> <pre><code class="language-html">&lt;a<span class="space"> </span>href=&quot;&amp;ouml;&quot;&gt; </code></pre> </div> <p>Backslash escapes do not work in HTML attributes:</p> <div class="example" id="example-578" data-section="Raw HTML"> <div class="examplenum"><a href="#example-578">Example 578</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;a<span class="space"> </span>href=&quot;\*&quot;&gt; </code></pre> <pre><code class="language-html">&lt;a<span class="space"> </span>href=&quot;\*&quot;&gt; </code></pre> </div> <div class="example" id="example-579" data-section="Raw HTML"> <div class="examplenum"><a href="#example-579">Example 579</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;a<span class="space"> </span>href=&quot;\&quot;&quot;&gt; </code></pre> <pre><code class="language-html">&lt;p&gt;&amp;lt;a<span class="space"> </span>href=&amp;quot;&amp;quot;&amp;quot;&amp;gt;&lt;/p&gt; </code></pre> </div> <h2><a id="hard-line-breaks"></a><span class="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>&lt;br /&gt;</code> tag):</p> <div class="example" id="example-580" data-section="Hard line breaks"> <div class="examplenum"><a href="#example-580">Example 580</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">foo<span class="space"> </span><span class="space"> </span> baz </code></pre> <pre><code class="language-html">&lt;p&gt;foo&lt;br<span class="space"> </span>/&gt; baz&lt;/p&gt; </code></pre> </div> <p>For a more visible alternative, a backslash before the <a href="#line-ending">line ending</a> may be used instead of two spaces:</p> <div class="example" id="example-581" data-section="Hard line breaks"> <div class="examplenum"><a href="#example-581">Example 581</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">foo\ baz </code></pre> <pre><code class="language-html">&lt;p&gt;foo&lt;br<span class="space"> </span>/&gt; baz&lt;/p&gt; </code></pre> </div> <p>More than two spaces can be used:</p> <div class="example" id="example-582" data-section="Hard line breaks"> <div class="examplenum"><a href="#example-582">Example 582</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">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><code class="language-html">&lt;p&gt;foo&lt;br<span class="space"> </span>/&gt; baz&lt;/p&gt; </code></pre> </div> <p>Leading spaces at the beginning of the next line are ignored:</p> <div class="example" id="example-583" data-section="Hard line breaks"> <div class="examplenum"><a href="#example-583">Example 583</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">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><code class="language-html">&lt;p&gt;foo&lt;br<span class="space"> </span>/&gt; bar&lt;/p&gt; </code></pre> </div> <div class="example" id="example-584" data-section="Hard line breaks"> <div class="examplenum"><a href="#example-584">Example 584</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">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><code class="language-html">&lt;p&gt;foo&lt;br<span class="space"> </span>/&gt; bar&lt;/p&gt; </code></pre> </div> <p>Line breaks can occur inside emphasis, links, and other constructs that allow inline content:</p> <div class="example" id="example-585" data-section="Hard line breaks"> <div class="examplenum"><a href="#example-585">Example 585</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">*foo<span class="space"> </span><span class="space"> </span> bar* </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;foo&lt;br<span class="space"> </span>/&gt; bar&lt;/em&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-586" data-section="Hard line breaks"> <div class="examplenum"><a href="#example-586">Example 586</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">*foo\ bar* </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;foo&lt;br<span class="space"> </span>/&gt; bar&lt;/em&gt;&lt;/p&gt; </code></pre> </div> <p>Line breaks do not occur inside code spans</p> <div class="example" id="example-587" data-section="Hard line breaks"> <div class="examplenum"><a href="#example-587">Example 587</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">`code<span class="space"> </span><span class="space"> </span> span` </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;code&gt;code<span class="space"> </span>span&lt;/code&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-588" data-section="Hard line breaks"> <div class="examplenum"><a href="#example-588">Example 588</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">`code\ span` </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;code&gt;code\<span class="space"> </span>span&lt;/code&gt;&lt;/p&gt; </code></pre> </div> <p>or HTML tags:</p> <div class="example" id="example-589" data-section="Hard line breaks"> <div class="examplenum"><a href="#example-589">Example 589</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;a<span class="space"> </span>href=&quot;foo<span class="space"> </span><span class="space"> </span> bar&quot;&gt; </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;foo<span class="space"> </span><span class="space"> </span> bar&quot;&gt;&lt;/p&gt; </code></pre> </div> <div class="example" id="example-590" data-section="Hard line breaks"> <div class="examplenum"><a href="#example-590">Example 590</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">&lt;a<span class="space"> </span>href=&quot;foo\ bar&quot;&gt; </code></pre> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;foo\ bar&quot;&gt;&lt;/p&gt; </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 class="example" id="example-591" data-section="Hard line breaks"> <div class="examplenum"><a href="#example-591">Example 591</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">foo\ </code></pre> <pre><code class="language-html">&lt;p&gt;foo\&lt;/p&gt; </code></pre> </div> <div class="example" id="example-592" data-section="Hard line breaks"> <div class="examplenum"><a href="#example-592">Example 592</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">foo<span class="space"> </span><span class="space"> </span> </code></pre> <pre><code class="language-html">&lt;p&gt;foo&lt;/p&gt; </code></pre> </div> <div class="example" id="example-593" data-section="Hard line breaks"> <div class="examplenum"><a href="#example-593">Example 593</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">###<span class="space"> </span>foo\ </code></pre> <pre><code class="language-html">&lt;h3&gt;foo\&lt;/h3&gt; </code></pre> </div> <div class="example" id="example-594" data-section="Hard line breaks"> <div class="examplenum"><a href="#example-594">Example 594</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">###<span class="space"> </span>foo<span class="space"> </span><span class="space"> </span> </code></pre> <pre><code class="language-html">&lt;h3&gt;foo&lt;/h3&gt; </code></pre> </div> <h2><a id="soft-line-breaks"></a><span class="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 or a backslash is parsed as a softbreak. (A softbreak may be rendered in HTML either as a <a href="#line-ending">line ending</a> or as a space. The result will be the same in browsers. In the examples here, a <a href="#line-ending">line ending</a> will be used.)</p> <div class="example" id="example-595" data-section="Soft line breaks"> <div class="examplenum"><a href="#example-595">Example 595</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">foo baz </code></pre> <pre><code class="language-html">&lt;p&gt;foo baz&lt;/p&gt; </code></pre> </div> <p>Spaces at the end of the line and beginning of the next line are removed:</p> <div class="example" id="example-596" data-section="Soft line breaks"> <div class="examplenum"><a href="#example-596">Example 596</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">foo<span class="space"> </span> <span class="space"> </span>baz </code></pre> <pre><code class="language-html">&lt;p&gt;foo baz&lt;/p&gt; </code></pre> </div> <p>A conforming parser may render a soft line break in HTML either as a line break or as a space.</p> <p>A renderer may also provide an option to render soft line breaks as hard line breaks.</p> <h2><a id="textual-content"></a><span class="number">6.11</span> Textual content</h2> <p>Any characters not given an interpretation by the above rules will be parsed as plain textual content.</p> <div class="example" id="example-597" data-section="Textual content"> <div class="examplenum"><a href="#example-597">Example 597</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">hello<span class="space"> </span>$.;'there </code></pre> <pre><code class="language-html">&lt;p&gt;hello<span class="space"> </span>$.;'there&lt;/p&gt; </code></pre> </div> <div class="example" id="example-598" data-section="Textual content"> <div class="examplenum"><a href="#example-598">Example 598</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">Foo<span class="space"> </span>χρῆν </code></pre> <pre><code class="language-html">&lt;p&gt;Foo<span class="space"> </span>χρῆν&lt;/p&gt; </code></pre> </div> <p>Internal spaces are preserved verbatim:</p> <div class="example" id="example-599" data-section="Textual content"> <div class="examplenum"><a href="#example-599">Example 599</a>&nbsp;&nbsp;<a class="dingus" title="open in interactive dingus">(interact)</a></div> <pre><code class="language-markdown">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><code class="language-html">&lt;p&gt;Multiple<span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>spaces&lt;/p&gt; </code></pre> </div> <!-- END TESTS --> <h1><a id="appendix-a-parsing-strategy"></a><span class="number"></span> Appendix: A parsing strategy</h1> <p>In this appendix we describe some features of the parsing strategy used in the CommonMark reference implementations.</p> <h2><a id="overview"></a><span class="number"></span> Overview</h2> <p>Parsing has two phases:</p> <ol> <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> <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><code class="language-tree">-&gt; document -&gt; block_quote paragraph &quot;Lorem ipsum dolor\nsit amet.&quot; -&gt; list (type=bullet tight=true bullet_char=-) list_item paragraph &quot;Qui *quodsi iracundia*&quot; -&gt; list_item -&gt; paragraph &quot;aliquando id&quot; </code></pre> <h2><a id="phase-1-block-structure"></a><span class="number"></span> Phase 1: block structure</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> <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>For each line, we follow this procedure:</p> <ol> <li> <p>First we iterate through the open blocks, starting with the root document, and descending through last children down to the last open block. Each block imposes a condition that the line must satisfy if the block is to remain open. For example, a block quote requires a <code>&gt;</code> character. A paragraph requires a non-blank line. In this phase we may match all or just some of the open blocks. But we cannot close unmatched blocks yet, because we may have a <a href="#lazy-continuation-line">lazy continuation line</a>.</p> </li> <li> <p>Next, after consuming the continuation markers for existing blocks, we look for new block starts (e.g. <code>&gt;</code> for a block quote. If we encounter a new block start, we close any blocks unmatched in step 1 before creating the new block as a child of the last matched block.</p> </li> <li> <p>Finally, we look at the remainder of the line (after block markers like <code>&gt;</code>, list markers, and indentation have been consumed). This is text that can be incorporated into the last open block (a paragraph, code block, header, or raw HTML).</p> </li> </ol> <p>Setext headers are formed when we detect that the second line of a paragraph is a setext header line.</p> <p>Reference link definitions are detected when a paragraph is closed; the accumulated text lines are parsed to see if they begin with one or more reference link definitions. Any remainder becomes a normal paragraph.</p> <p>We can see how this works by considering how the tree above is generated by four lines of Markdown:</p> <pre><code class="language-markdown">&gt; Lorem ipsum dolor sit amet. &gt; - Qui *quodsi iracundia* &gt; - aliquando id </code></pre> <p>At the outset, our document model is just</p> <pre><code class="language-tree">-&gt; document </code></pre> <p>The first line of our text,</p> <pre><code class="language-markdown">&gt; Lorem ipsum dolor </code></pre> <p>causes a <code>block_quote</code> block to be created as a child of our open <code>document</code> block, and a <code>paragraph</code> block as a child of the <code>block_quote</code>. Then the text is added to the last open block, the <code>paragraph</code>:</p> <pre><code class="language-tree">-&gt; document -&gt; block_quote -&gt; paragraph &quot;Lorem ipsum dolor&quot; </code></pre> <p>The next line,</p> <pre><code class="language-markdown">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><code class="language-tree">-&gt; document -&gt; block_quote -&gt; paragraph &quot;Lorem ipsum dolor\nsit amet.&quot; </code></pre> <p>The third line,</p> <pre><code class="language-markdown">&gt; - Qui *quodsi iracundia* </code></pre> <p>causes the <code>paragraph</code> block to be closed, and a new <code>list</code> block opened as a child of the <code>block_quote</code>. A <code>list_item</code> is also added as a child of the <code>list</code>, and a <code>paragraph</code> as a child of the <code>list_item</code>. The text is then added to the new <code>paragraph</code>:</p> <pre><code class="language-tree">-&gt; document -&gt; block_quote paragraph &quot;Lorem ipsum dolor\nsit amet.&quot; -&gt; list (type=bullet tight=true bullet_char=-) -&gt; list_item -&gt; paragraph &quot;Qui *quodsi iracundia*&quot; </code></pre> <p>The fourth line,</p> <pre><code class="language-markdown">&gt; - aliquando id </code></pre> <p>causes the <code>list_item</code> (and its child the <code>paragraph</code>) to be closed, and a new <code>list_item</code> opened up as child of the <code>list</code>. A <code>paragraph</code> is added as a child of the new <code>list_item</code>, to contain the text. We thus obtain the final tree:</p> <pre><code class="language-tree">-&gt; document -&gt; block_quote paragraph &quot;Lorem ipsum dolor\nsit amet.&quot; -&gt; list (type=bullet tight=true bullet_char=-) list_item paragraph &quot;Qui *quodsi iracundia*&quot; -&gt; list_item -&gt; paragraph &quot;aliquando id&quot; </code></pre> <h2><a id="phase-2-inline-structure"></a><span class="number"></span> Phase 2: inline structure</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><code class="language-tree">document block_quote paragraph str &quot;Lorem ipsum dolor&quot; softbreak str &quot;sit amet.&quot; list (type=bullet tight=true bullet_char=-) list_item paragraph str &quot;Qui &quot; emph str &quot;quodsi iracundia&quot; list_item paragraph str &quot;aliquando id&quot; </code></pre> <p>Notice how the <a href="#line-ending">line ending</a> 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> <h3><a id="an-algorithm-for-parsing-nested-emphasis-and-links"></a><span class="number"></span> An algorithm for parsing nested emphasis and links</h3> <p>By far the trickiest part of inline parsing is handling emphasis, strong emphasis, links, and images. This is done using the following algorithm.</p> <p>When we’re parsing inlines and we hit either</p> <ul> <li>a run of <code>*</code> or <code>_</code> characters, or</li> <li>a <code>[</code> or <code>![</code></li> </ul> <p>we insert a text node with these symbols as its literal content, and we add a pointer to this text node to the <a id="delimiter-stack" href="#delimiter-stack" class="definition">delimiter stack</a>.</p> <p>The <a href="#delimiter-stack">delimiter stack</a> is a doubly linked list. Each element contains a pointer to a text node, plus information about</p> <ul> <li>the type of delimiter (<code>[</code>, <code>![</code>, <code>*</code>, <code>_</code>)</li> <li>the number of delimiters,</li> <li>whether the delimiter is “active” (all are active to start), and</li> <li>whether the delimiter is a potential opener, a potential closer, or both (which depends on what sort of characters precede and follow the delimiters).</li> </ul> <p>When we hit a <code>]</code> character, we call the <em>look for link or image</em> procedure (see below).</p> <p>When we hit the end of the input, we call the <em>process emphasis</em> procedure (see below), with <code>stack_bottom</code> = NULL.</p> <h4><a id="-look-for-link-or-image-"></a><span class="number"></span> <em>look for link or image</em></h4> <p>Starting at the top of the delimiter stack, we look backwards through the stack for an opening <code>[</code> or <code>![</code> delimiter.</p> <ul> <li> <p>If we don’t find one, we return a literal text node <code>]</code>.</p> </li> <li> <p>If we do find one, but it’s not <em>active</em>, we remove the inactive delimiter from the stack, and return a literal text node <code>]</code>.</p> </li> <li> <p>If we find one and it’s active, then we parse ahead to see if we have an inline link/image, reference link/image, compact reference link/image, or shortcut reference link/image.</p> <ul> <li> <p>If we don’t, then we remove the opening delimiter from the delimiter stack and return a literal text node <code>]</code>.</p> </li> <li> <p>If we do, then</p> <ul> <li> <p>We return a link or image node whose children are the inlines after the text node pointed to by the opening delimiter.</p> </li> <li> <p>We run <em>process emphasis</em> on these inlines, with the <code>[</code> opener as <code>stack_bottom</code>.</p> </li> <li> <p>We remove the opening delimiter.</p> </li> <li> <p>If we have a link (and not an image), we also set all <code>[</code> delimiters before the opening delimiter to <em>inactive</em>. (This will prevent us from getting links within links.)</p> </li> </ul> </li> </ul> </li> </ul> <h4><a id="-process-emphasis-"></a><span class="number"></span> <em>process emphasis</em></h4> <p>Parameter <code>stack_bottom</code> sets a lower bound to how far we descend in the <a href="#delimiter-stack">delimiter stack</a>. If it is NULL, we can go all the way to the bottom. Otherwise, we stop before visiting <code>stack_bottom</code>.</p> <p>Let <code>current_position</code> point to the element on the <a href="#delimiter-stack">delimiter stack</a> just above <code>stack_bottom</code> (or the first element if <code>stack_bottom</code> is NULL).</p> <p>We keep track of the <code>openers_bottom</code> for each delimiter type (<code>*</code>, <code>_</code>). Initialize this to <code>stack_bottom</code>.</p> <p>Then we repeat the following until we run out of potential closers:</p> <ul> <li> <p>Move <code>current_position</code> forward in the delimiter stack (if needed) until we find the first potential closer with delimiter <code>*</code> or <code>_</code>. (This will be the potential closer closest to the beginning of the input – the first one in parse order.)</p> </li> <li> <p>Now, look back in the stack (staying above <code>stack_bottom</code> and the <code>openers_bottom</code> for this delimiter type) for the first matching potential opener (“matching” means same delimiter).</p> </li> <li> <p>If one is found:</p> <ul> <li> <p>Figure out whether we have emphasis or strong emphasis: if both closer and opener spans have length &gt;= 2, we have strong, otherwise regular.</p> </li> <li> <p>Insert an emph or strong emph node accordingly, after the text node corresponding to the opener.</p> </li> <li> <p>Remove any delimiters between the opener and closer from the delimiter stack.</p> </li> <li> <p>Remove 1 (for regular emph) or 2 (for strong emph) delimiters from the opening and closing text nodes. If they become empty as a result, remove them and remove the corresponding element of the delimiter stack. If the closing node is removed, reset <code>current_position</code> to the next element in the stack.</p> </li> </ul> </li> <li> <p>If none in found:</p> <ul> <li> <p>Set <code>openers_bottom</code> to the element before <code>current_position</code>. (We know that there are no openers for this kind of closer up to and including this point, so this puts a lower bound on future searches.)</p> </li> <li> <p>If the closer at <code>current_position</code> is not a potential opener, remove it from the delimiter stack (since we know it can’t be a closer either).</p> </li> <li> <p>Advance <code>current_position</code> to the next element in the stack.</p> </li> </ul> </li> </ul> <p>After we’re done, we remove all delimiters above <code>stack_bottom</code> from the delimiter stack.</p> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10