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.number:after { content: "  " } 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; } .example { font-size: 0; /* hack to get width:50% to work on inline-block */ padding-bottom: 6pt; } .column pre { font-size: 11pt; padding-left: 6pt; padding-right: 6pt; padding-top: 2pt; padding-bottom: 2pt; } div.examplenum { font-size: 11pt; text-align: left; margin-bottom:10px; } div.column { display: inline-block; width: 50%; vertical-align: top; } div.example > div:nth-child(2) { clear:left; background-color: #D3E1E4; } div.example > div: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; } a.dingus { margin-left: 1em; cursor: pointer; line-height: 30px; padding: 4px 7px; color: #FFF; background-color: #33C3F0; box-shadow: 2px 2px 2px rgba(0,0,0,.2); border-color: #4FCAEF; border-bottom: 2px #2A9EC1 solid; border-right: 2px #2A9EC1 solid; } a.footnoteRef > sup:before { content: "["; } a.footnoteRef > sup:after { content: "]"; } a.footnoteRef > sup { vertical-align: baseline; font-size: 100%; } @media print { @page { size: auto; margin: 1.2in 1.2in 1.2in 1.2in; } body { margin: 0px; line-height: 1.2; font-size: 10pt; } .column pre { font-size: 9pt; } div.examplenum { font-size: 9pt; } a.dingus { display: none; } } </style> <script src="https://code.jquery.com/jquery-2.2.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).text())); }); }); </script> </head> <body> <h1 class="title">CommonMark Spec</h1> <div class="version">Version 0.28 (2017-08-01)</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"><span class="number">1</span>Introduction</a> <ul> <li><a href="#what-is-markdown-"><span class="number">1.1</span>What is Markdown?</a></li> <li><a href="#why-is-a-spec-needed-"><span class="number">1.2</span>Why is a spec needed?</a></li> <li><a href="#about-this-document"><span class="number">1.3</span>About this document</a></li> </ul> </li> <li><a href="#preliminaries"><span class="number">2</span>Preliminaries</a> <ul> <li><a href="#characters-and-lines"><span class="number">2.1</span>Characters and lines</a></li> <li><a href="#tabs"><span class="number">2.2</span>Tabs</a></li> <li><a href="#insecure-characters"><span class="number">2.3</span>Insecure characters</a></li> </ul> </li> <li><a href="#blocks-and-inlines"><span class="number">3</span>Blocks and inlines</a> <ul> <li><a href="#precedence"><span class="number">3.1</span>Precedence</a></li> <li><a href="#container-blocks-and-leaf-blocks"><span class="number">3.2</span>Container blocks and leaf blocks</a></li> </ul> </li> <li><a href="#leaf-blocks"><span class="number">4</span>Leaf blocks</a> <ul> <li><a href="#thematic-breaks"><span class="number">4.1</span>Thematic breaks</a></li> <li><a href="#atx-headings"><span class="number">4.2</span>ATX headings</a></li> <li><a href="#setext-headings"><span class="number">4.3</span>Setext headings</a></li> <li><a href="#indented-code-blocks"><span class="number">4.4</span>Indented code blocks</a></li> <li><a href="#fenced-code-blocks"><span class="number">4.5</span>Fenced code blocks</a></li> <li><a href="#html-blocks"><span class="number">4.6</span>HTML blocks</a></li> <li><a href="#link-reference-definitions"><span class="number">4.7</span>Link reference definitions</a></li> <li><a href="#paragraphs"><span class="number">4.8</span>Paragraphs</a></li> <li><a href="#blank-lines"><span class="number">4.9</span>Blank lines</a></li> </ul> </li> <li><a href="#container-blocks"><span class="number">5</span>Container blocks</a> <ul> <li><a href="#block-quotes"><span class="number">5.1</span>Block quotes</a></li> <li><a href="#list-items"><span class="number">5.2</span>List items</a></li> <li><a href="#lists"><span class="number">5.3</span>Lists</a></li> </ul> </li> <li><a href="#inlines"><span class="number">6</span>Inlines</a> <ul> <li><a href="#backslash-escapes"><span class="number">6.1</span>Backslash escapes</a></li> <li><a href="#entity-and-numeric-character-references"><span class="number">6.2</span>Entity and numeric character references</a></li> <li><a href="#code-spans"><span class="number">6.3</span>Code spans</a></li> <li><a href="#emphasis-and-strong-emphasis"><span class="number">6.4</span>Emphasis and strong emphasis</a></li> <li><a href="#links"><span class="number">6.5</span>Links</a></li> <li><a href="#images"><span class="number">6.6</span>Images</a></li> <li><a href="#autolinks"><span class="number">6.7</span>Autolinks</a></li> <li><a href="#raw-html"><span class="number">6.8</span>Raw HTML</a></li> <li><a href="#hard-line-breaks"><span class="number">6.9</span>Hard line breaks</a></li> <li><a href="#soft-line-breaks"><span class="number">6.10</span>Soft line breaks</a></li> <li><a href="#textual-content"><span class="number">6.11</span>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></li> </ul> </li> </ul> </div> <h1 id="introduction" href="#introduction" class="definition"> <span class="number">1</span>Introduction </h1> <h2 id="what-is-markdown-" href="#what-is-markdown-" class="definition"> <span class="number">1.1</span>What is Markdown? </h2> <p>Markdown is a plain text format for writing structured documents, based on conventions for indicating formatting in email and usenet posts. It was developed by John Gruber (with help from Aaron Swartz) and released in 2004 in the form of a <a href="http://daringfireball.net/projects/markdown/syntax">syntax description</a> and a Perl script (<code>Markdown.pl</code>) for converting Markdown to HTML. In the next decade, dozens of implementations were developed in many languages. Some extended the original Markdown syntax with conventions for footnotes, tables, and other document elements. Some allowed Markdown documents to be rendered in formats other than HTML. Websites like Reddit, StackOverflow, and GitHub had millions of people using Markdown. And Markdown started to be used beyond the web, to author books, articles, slide shows, letters, and lecture notes.</p> <p>What distinguishes Markdown from many other lightweight markup syntaxes, which are often easier to write, is its readability. As Gruber writes:</p> <blockquote> <p>The overriding design goal for Markdown’s formatting syntax is to make it as readable as possible. The idea is that a Markdown-formatted document should be publishable as-is, as plain text, without looking like it’s been marked up with tags or formatting instructions. (<a href="http://daringfireball.net/projects/markdown/">http://daringfireball.net/projects/markdown/</a>)</p> </blockquote> <p>The point can be illustrated by comparing a sample of <a href="http://www.methods.co.nz/asciidoc/">AsciiDoc</a> with an equivalent sample of Markdown. Here is a sample of AsciiDoc from the AsciiDoc manual:</p> <pre><code>1. List item one. + List item one continued with a second paragraph followed by an Indented block. + ................. $ ls *.sh $ mv *.sh ~/tmp ................. + List item continued with a third paragraph. 2. List item two continued with an open block. + -- This paragraph is part of the preceding list item. a. This list is nested and does not require explicit item continuation. + This paragraph is part of the preceding list item. b. List item b. This paragraph belongs to item two of the outer list. -- </code></pre> <p>And here is the equivalent in Markdown:</p> <pre><code>1. List item one. List item one continued with a second paragraph followed by an Indented block. $ ls *.sh $ mv *.sh ~/tmp List item continued with a third paragraph. 2. List item two continued with an open block. This paragraph is part of the preceding list item. 1. This list is nested and does not require explicit item continuation. This paragraph is part of the preceding list item. 2. List item b. This paragraph belongs to item two of the outer list. </code></pre> <p>The AsciiDoc version is, arguably, easier to write. You don’t need to worry about indentation. But the Markdown version is much easier to read. The nesting of list items is apparent to the eye in the source, not just in the processed document.</p> <h2 id="why-is-a-spec-needed-" href="#why-is-a-spec-needed-" class="definition"> <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 heading? 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 heading 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 thematic break in its second item, or two lists separated by a thematic break?</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 headings? (<code>Markdown.pl</code> does not allow this, but does allow blockquotes to include headings.)</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 id="about-this-document" href="#about-this-document" class="definition"> <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 id="preliminaries" href="#preliminaries" class="definition"> <span class="number">2</span>Preliminaries </h1> <h2 id="characters-and-lines" href="#characters-and-lines" class="definition"> <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> general category, 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 general Unicode categories <code>Pc</code>, <code>Pd</code>, <code>Pe</code>, <code>Pf</code>, <code>Pi</code>, <code>Po</code>, or <code>Ps</code>.</p> <h2 id="tabs" href="#tabs" class="definition"> <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 whitespace helps to define block structure, tabs behave as if they were replaced by spaces with a tab stop of 4 characters.</p> <p>Thus, for example, a tab can be used instead of four spaces in an indented code block. (Note, however, that internal tabs are passed through as literal tabs, not expanded to spaces.)</p> <div class="example" id="example-1"> <div class="examplenum"> <a href="#example-1">Example 1</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">→foo→baz→→bim </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;foo→baz→→bim &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> </div> <div class="example" id="example-2"> <div class="examplenum"> <a href="#example-2">Example 2</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown"><span class="space"> </span><span class="space"> </span>→foo→baz→→bim </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;foo→baz→→bim &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> </div> <div class="example" id="example-3"> <div class="examplenum"> <a href="#example-3">Example 3</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;a→a ὐ→a &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> </div> <p>In the following example, a continuation paragraph of a list item is indented with a tab; this has exactly the same effect as indentation with four spaces would:</p> <div class="example" id="example-4"> <div class="examplenum"> <a href="#example-4">Example 4</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown"><span class="space"> </span><span class="space"> </span>-<span class="space"> </span>foo →bar </code></pre> </div> <div class="column"> <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> <div class="example" id="example-5"> <div class="examplenum"> <a href="#example-5">Example 5</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">-<span class="space"> </span>foo →→bar </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;ul&gt; &lt;li&gt; &lt;p&gt;foo&lt;/p&gt; &lt;pre&gt;&lt;code&gt;<span class="space"> </span><span class="space"> </span>bar &lt;/code&gt;&lt;/pre&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> </div> </div> <p>Normally the <code>&gt;</code> that begins a block quote may be followed optionally by a space, which is not considered part of the content. In the following case <code>&gt;</code> is followed by a tab, which is treated as if it were expanded into three spaces. Since one of these spaces is considered part of the delimiter, <code>foo</code> is considered to be indented six spaces inside the block quote context, so we get an indented code block starting with two spaces.</p> <div class="example" id="example-6"> <div class="examplenum"> <a href="#example-6">Example 6</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&gt;→→foo </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;blockquote&gt; &lt;pre&gt;&lt;code&gt;<span class="space"> </span><span class="space"> </span>foo &lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; </code></pre> </div> </div> <div class="example" id="example-7"> <div class="examplenum"> <a href="#example-7">Example 7</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">-→→foo </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;ul&gt; &lt;li&gt; &lt;pre&gt;&lt;code&gt;<span class="space"> </span><span class="space"> </span>foo &lt;/code&gt;&lt;/pre&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> </div> </div> <div class="example" id="example-8"> <div class="examplenum"> <a href="#example-8">Example 8</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;foo bar &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> </div> <div class="example" id="example-9"> <div class="examplenum"> <a href="#example-9">Example 9</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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>baz </code></pre> </div> <div class="column"> <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> </div> <div class="example" id="example-10"> <div class="examplenum"> <a href="#example-10">Example 10</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">#→Foo </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;h1&gt;Foo&lt;/h1&gt; </code></pre> </div> </div> <div class="example" id="example-11"> <div class="examplenum"> <a href="#example-11">Example 11</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">*→*→*→ </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;hr<span class="space"> </span>/&gt; </code></pre> </div> </div> <h2 id="insecure-characters" href="#insecure-characters" class="definition"> <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 id="blocks-and-inlines" href="#blocks-and-inlines" class="definition"> <span class="number">3</span>Blocks and inlines </h1> <p>We can think of a document as a sequence of <a id="blocks" href="#blocks" class="definition">blocks</a>—structural elements like paragraphs, block quotations, lists, headings, rules, and code blocks. Some blocks (like block quotes and list items) contain other blocks; others (like headings and paragraphs) contain <a id="inline" href="#inline" class="definition">inline</a> content—text, links, emphasized text, images, code spans, and so on.</p> <h2 id="precedence" href="#precedence" class="definition"> <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-12"> <div class="examplenum"> <a href="#example-12">Example 12</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">-<span class="space"> </span>`one -<span class="space"> </span>two` </code></pre> </div> <div class="column"> <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> </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, headings, and other block constructs can be parsed for inline structure. The second step requires information about link reference definitions that will be available only at the end of the first step. Note that the first step requires processing lines in sequence, but the second can be parallelized, since the inline parsing of one block element does not affect the inline parsing of any other.</p> <h2 id="container-blocks-and-leaf-blocks" href="#container-blocks-and-leaf-blocks" class="definition"> <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 block</a>s, which can contain other blocks, and <a id="leaf-block" href="#leaf-block" class="definition">leaf block</a>s, which cannot.</p> <h1 id="leaf-blocks" href="#leaf-blocks" class="definition"> <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 id="thematic-breaks" href="#thematic-breaks" class="definition"> <span class="number">4.1</span>Thematic breaks </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="thematic-break" href="#thematic-break" class="definition">thematic break</a>.</p> <div class="example" id="example-13"> <div class="examplenum"> <a href="#example-13">Example 13</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">*** --- ___ </code></pre> </div> <div class="column"> <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> </div> <p>Wrong characters:</p> <div class="example" id="example-14"> <div class="examplenum"> <a href="#example-14">Example 14</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">+++ </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;+++&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-15"> <div class="examplenum"> <a href="#example-15">Example 15</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">=== </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;===&lt;/p&gt; </code></pre> </div> </div> <p>Not enough characters:</p> <div class="example" id="example-16"> <div class="examplenum"> <a href="#example-16">Example 16</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">-- ** __ </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;-- ** __&lt;/p&gt; </code></pre> </div> </div> <p>One to three spaces indent are allowed:</p> <div class="example" id="example-17"> <div class="examplenum"> <a href="#example-17">Example 17</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>Four spaces is too many:</p> <div class="example" id="example-18"> <div class="examplenum"> <a href="#example-18">Example 18</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown"><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>*** </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;*** &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> </div> <div class="example" id="example-19"> <div class="examplenum"> <a href="#example-19">Example 19</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">Foo <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>*** </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;Foo ***&lt;/p&gt; </code></pre> </div> </div> <p>More than three characters may be used:</p> <div class="example" id="example-20"> <div class="examplenum"> <a href="#example-20">Example 20</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">_____________________________________ </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;hr<span class="space"> </span>/&gt; </code></pre> </div> </div> <p>Spaces are allowed between the characters:</p> <div class="example" id="example-21"> <div class="examplenum"> <a href="#example-21">Example 21</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown"><span class="space"> </span>-<span class="space"> </span>-<span class="space"> </span>- </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;hr<span class="space"> </span>/&gt; </code></pre> </div> </div> <div class="example" id="example-22"> <div class="examplenum"> <a href="#example-22">Example 22</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <pre><code class="language-html">&lt;hr<span class="space"> </span>/&gt; </code></pre> </div> </div> <div class="example" id="example-23"> <div class="examplenum"> <a href="#example-23">Example 23</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <pre><code class="language-html">&lt;hr<span class="space"> </span>/&gt; </code></pre> </div> </div> <p>Spaces are allowed at the end:</p> <div class="example" id="example-24"> <div class="examplenum"> <a href="#example-24">Example 24</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <pre><code class="language-html">&lt;hr<span class="space"> </span>/&gt; </code></pre> </div> </div> <p>However, no other characters may occur in the line:</p> <div class="example" id="example-25"> <div class="examplenum"> <a href="#example-25">Example 25</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </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 thematic break:</p> <div class="example" id="example-26"> <div class="examplenum"> <a href="#example-26">Example 26</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown"><span class="space"> </span>*-* </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;-&lt;/em&gt;&lt;/p&gt; </code></pre> </div> </div> <p>Thematic breaks do not need blank lines before or after:</p> <div class="example" id="example-27"> <div class="examplenum"> <a href="#example-27">Example 27</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">-<span class="space"> </span>foo *** -<span class="space"> </span>bar </code></pre> </div> <div class="column"> <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> </div> <p>Thematic breaks can interrupt a paragraph:</p> <div class="example" id="example-28"> <div class="examplenum"> <a href="#example-28">Example 28</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">Foo *** bar </code></pre> </div> <div class="column"> <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> </div> <p>If a line of dashes that meets the above conditions for being a thematic break could also be interpreted as the underline of a <a href="#setext-heading">setext heading</a>, the interpretation as a <a href="#setext-heading">setext heading</a> takes precedence. Thus, for example, this is a setext heading, not a paragraph followed by a thematic break:</p> <div class="example" id="example-29"> <div class="examplenum"> <a href="#example-29">Example 29</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">Foo --- bar </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;h2&gt;Foo&lt;/h2&gt; &lt;p&gt;bar&lt;/p&gt; </code></pre> </div> </div> <p>When both a thematic break and a list item are possible interpretations of a line, the thematic break takes precedence:</p> <div class="example" id="example-30"> <div class="examplenum"> <a href="#example-30">Example 30</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>If you want a thematic break in a list item, use a different bullet:</p> <div class="example" id="example-31"> <div class="examplenum"> <a href="#example-31">Example 31</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">-<span class="space"> </span>Foo -<span class="space"> </span>*<span class="space"> </span>*<span class="space"> </span>* </code></pre> </div> <div class="column"> <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> </div> <h2 id="atx-headings" href="#atx-headings" class="definition"> <span class="number">4.2</span>ATX headings </h2> <p>An <a id="atx-heading" href="#atx-heading" class="definition">ATX heading</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 must be followed by a <a href="#space">space</a> or by the end of line. 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 heading are stripped of leading and trailing spaces before being parsed as inline content. The heading level is equal to the number of <code>#</code> characters in the opening sequence.</p> <p>Simple headings:</p> <div class="example" id="example-32"> <div class="examplenum"> <a href="#example-32">Example 32</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>More than six <code>#</code> characters is not a heading:</p> <div class="example" id="example-33"> <div class="examplenum"> <a href="#example-33">Example 33</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">#######<span class="space"> </span>foo </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;#######<span class="space"> </span>foo&lt;/p&gt; </code></pre> </div> </div> <p>At least one space is required between the <code>#</code> characters and the heading’s contents, unless the heading 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 headings:</p> <div class="example" id="example-34"> <div class="examplenum"> <a href="#example-34">Example 34</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">#5<span class="space"> </span>bolt #hashtag </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;#5<span class="space"> </span>bolt&lt;/p&gt; &lt;p&gt;#hashtag&lt;/p&gt; </code></pre> </div> </div> <p>This is not a heading, because the first <code>#</code> is escaped:</p> <div class="example" id="example-35"> <div class="examplenum"> <a href="#example-35">Example 35</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">\##<span class="space"> </span>foo </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;##<span class="space"> </span>foo&lt;/p&gt; </code></pre> </div> </div> <p>Contents are parsed as inlines:</p> <div class="example" id="example-36"> <div class="examplenum"> <a href="#example-36">Example 36</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">#<span class="space"> </span>foo<span class="space"> </span>*bar*<span class="space"> </span>\*baz\* </code></pre> </div> <div class="column"> <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> </div> <p>Leading and trailing blanks are ignored in parsing inline content:</p> <div class="example" id="example-37"> <div class="examplenum"> <a href="#example-37">Example 37</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <pre><code class="language-html">&lt;h1&gt;foo&lt;/h1&gt; </code></pre> </div> </div> <p>One to three spaces indentation are allowed:</p> <div class="example" id="example-38"> <div class="examplenum"> <a href="#example-38">Example 38</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>Four spaces are too much:</p> <div class="example" id="example-39"> <div class="examplenum"> <a href="#example-39">Example 39</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> <div class="example" id="example-40"> <div class="examplenum"> <a href="#example-40">Example 40</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;foo #<span class="space"> </span>bar&lt;/p&gt; </code></pre> </div> </div> <p>A closing sequence of <code>#</code> characters is optional:</p> <div class="example" id="example-41"> <div class="examplenum"> <a href="#example-41">Example 41</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <pre><code class="language-html">&lt;h2&gt;foo&lt;/h2&gt; &lt;h3&gt;bar&lt;/h3&gt; </code></pre> </div> </div> <p>It need not be the same length as the opening sequence:</p> <div class="example" id="example-42"> <div class="examplenum"> <a href="#example-42">Example 42</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <pre><code class="language-html">&lt;h1&gt;foo&lt;/h1&gt; &lt;h5&gt;foo&lt;/h5&gt; </code></pre> </div> </div> <p>Spaces are allowed after the closing sequence:</p> <div class="example" id="example-43"> <div class="examplenum"> <a href="#example-43">Example 43</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <pre><code class="language-html">&lt;h3&gt;foo&lt;/h3&gt; </code></pre> </div> </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 heading:</p> <div class="example" id="example-44"> <div class="examplenum"> <a href="#example-44">Example 44</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">###<span class="space"> </span>foo<span class="space"> </span>###<span class="space"> </span>b </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;h3&gt;foo<span class="space"> </span>###<span class="space"> </span>b&lt;/h3&gt; </code></pre> </div> </div> <p>The closing sequence must be preceded by a space:</p> <div class="example" id="example-45"> <div class="examplenum"> <a href="#example-45">Example 45</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">#<span class="space"> </span>foo# </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;h1&gt;foo#&lt;/h1&gt; </code></pre> </div> </div> <p>Backslash-escaped <code>#</code> characters do not count as part of the closing sequence:</p> <div class="example" id="example-46"> <div class="examplenum"> <a href="#example-46">Example 46</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>ATX headings need not be separated from surrounding content by blank lines, and they can interrupt paragraphs:</p> <div class="example" id="example-47"> <div class="examplenum"> <a href="#example-47">Example 47</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">**** ##<span class="space"> </span>foo **** </code></pre> </div> <div class="column"> <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> <div class="example" id="example-48"> <div class="examplenum"> <a href="#example-48">Example 48</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">Foo<span class="space"> </span>bar #<span class="space"> </span>baz Bar<span class="space"> </span>foo </code></pre> </div> <div class="column"> <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> </div> <p>ATX headings can be empty:</p> <div class="example" id="example-49"> <div class="examplenum"> <a href="#example-49">Example 49</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">##<span class="space"> </span> # ###<span class="space"> </span>### </code></pre> </div> <div class="column"> <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> </div> <h2 id="setext-headings" href="#setext-headings" class="definition"> <span class="number">4.3</span>Setext headings </h2> <p>A <a id="setext-heading" href="#setext-heading" class="definition">setext heading</a> consists of one or more lines of text, each 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-heading-underline">setext heading underline</a>. The lines of text must be such that, were they not followed by the setext heading underline, they would be interpreted as a paragraph: they cannot be interpretable as a <a href="#code-fence">code fence</a>, <a href="#atx-headings">ATX heading</a>, <a href="#block-quotes">block quote</a>, <a href="#thematic-break">thematic break</a>, <a href="#list-items">list item</a>, or <a href="#html-blocks">HTML block</a>.</p> <p>A <a id="setext-heading-underline" href="#setext-heading-underline" class="definition">setext heading 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-heading-underline">setext heading underline</a>.</p> <p>The heading is a level 1 heading if <code>=</code> characters are used in the <a href="#setext-heading-underline">setext heading underline</a>, and a level 2 heading if <code>-</code> characters are used. The contents of the heading are the result of parsing the preceding lines of text as CommonMark inline content.</p> <p>In general, a setext heading need not be preceded or followed by a blank line. However, it cannot interrupt a paragraph, so when a setext heading comes after a paragraph, a blank line is needed between them.</p> <p>Simple examples:</p> <div class="example" id="example-50"> <div class="examplenum"> <a href="#example-50">Example 50</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">Foo<span class="space"> </span>*bar* ========= Foo<span class="space"> </span>*bar* --------- </code></pre> </div> <div class="column"> <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> </div> <p>The content of the header may span more than one line:</p> <div class="example" id="example-51"> <div class="examplenum"> <a href="#example-51">Example 51</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">Foo<span class="space"> </span>*bar baz* ==== </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;h1&gt;Foo<span class="space"> </span>&lt;em&gt;bar baz&lt;/em&gt;&lt;/h1&gt; </code></pre> </div> </div> <p>The underlining can be any length:</p> <div class="example" id="example-52"> <div class="examplenum"> <a href="#example-52">Example 52</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">Foo ------------------------- Foo = </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;h2&gt;Foo&lt;/h2&gt; &lt;h1&gt;Foo&lt;/h1&gt; </code></pre> </div> </div> <p>The heading content can be indented up to three spaces, and need not line up with the underlining:</p> <div class="example" id="example-53"> <div class="examplenum"> <a href="#example-53">Example 53</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>Four spaces indent is too much:</p> <div class="example" id="example-54"> <div class="examplenum"> <a href="#example-54">Example 54</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>The setext heading underline can be indented up to three spaces, and may have trailing spaces:</p> <div class="example" id="example-55"> <div class="examplenum"> <a href="#example-55">Example 55</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <pre><code class="language-html">&lt;h2&gt;Foo&lt;/h2&gt; </code></pre> </div> </div> <p>Four spaces is too much:</p> <div class="example" id="example-56"> <div class="examplenum"> <a href="#example-56">Example 56</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">Foo <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>--- </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;Foo ---&lt;/p&gt; </code></pre> </div> </div> <p>The setext heading underline cannot contain internal spaces:</p> <div class="example" id="example-57"> <div class="examplenum"> <a href="#example-57">Example 57</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">Foo =<span class="space"> </span>= Foo ---<span class="space"> </span>- </code></pre> </div> <div class="column"> <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> </div> <p>Trailing spaces in the content line do not cause a line break:</p> <div class="example" id="example-58"> <div class="examplenum"> <a href="#example-58">Example 58</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">Foo<span class="space"> </span><span class="space"> </span> ----- </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;h2&gt;Foo&lt;/h2&gt; </code></pre> </div> </div> <p>Nor does a backslash at the end:</p> <div class="example" id="example-59"> <div class="examplenum"> <a href="#example-59">Example 59</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">Foo\ ---- </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;h2&gt;Foo\&lt;/h2&gt; </code></pre> </div> </div> <p>Since indicators of block structure take precedence over indicators of inline structure, the following are setext headings:</p> <div class="example" id="example-60"> <div class="examplenum"> <a href="#example-60">Example 60</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>The setext heading 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-61"> <div class="examplenum"> <a href="#example-61">Example 61</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&gt;<span class="space"> </span>Foo --- </code></pre> </div> <div class="column"> <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> <div class="example" id="example-62"> <div class="examplenum"> <a href="#example-62">Example 62</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&gt;<span class="space"> </span>foo bar === </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;blockquote&gt; &lt;p&gt;foo bar ===&lt;/p&gt; &lt;/blockquote&gt; </code></pre> </div> </div> <div class="example" id="example-63"> <div class="examplenum"> <a href="#example-63">Example 63</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">-<span class="space"> </span>Foo --- </code></pre> </div> <div class="column"> <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> <p>A blank line is needed between a paragraph and a following setext heading, since otherwise the paragraph becomes part of the heading’s content:</p> <div class="example" id="example-64"> <div class="examplenum"> <a href="#example-64">Example 64</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">Foo Bar --- </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;h2&gt;Foo Bar&lt;/h2&gt; </code></pre> </div> </div> <p>But in general a blank line is not required before or after setext headings:</p> <div class="example" id="example-65"> <div class="examplenum"> <a href="#example-65">Example 65</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">--- Foo --- Bar --- Baz </code></pre> </div> <div class="column"> <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> </div> <p>Setext headings cannot be empty:</p> <div class="example" id="example-66"> <div class="examplenum"> <a href="#example-66">Example 66</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown"> ==== </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;====&lt;/p&gt; </code></pre> </div> </div> <p>Setext heading text lines must not be interpretable as block constructs other than paragraphs. So, the line of dashes in these examples gets interpreted as a thematic break:</p> <div class="example" id="example-67"> <div class="examplenum"> <a href="#example-67">Example 67</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">--- --- </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;hr<span class="space"> </span>/&gt; &lt;hr<span class="space"> </span>/&gt; </code></pre> </div> </div> <div class="example" id="example-68"> <div class="examplenum"> <a href="#example-68">Example 68</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">-<span class="space"> </span>foo ----- </code></pre> </div> <div class="column"> <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> <div class="example" id="example-69"> <div class="examplenum"> <a href="#example-69">Example 69</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown"><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>foo --- </code></pre> </div> <div class="column"> <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> <div class="example" id="example-70"> <div class="examplenum"> <a href="#example-70">Example 70</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&gt;<span class="space"> </span>foo ----- </code></pre> </div> <div class="column"> <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> <p>If you want a heading with <code>&gt; foo</code> as its literal text, you can use backslash escapes:</p> <div class="example" id="example-71"> <div class="examplenum"> <a href="#example-71">Example 71</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">\&gt;<span class="space"> </span>foo ------ </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;h2&gt;&amp;gt;<span class="space"> </span>foo&lt;/h2&gt; </code></pre> </div> </div> <p><strong>Compatibility note:</strong> Most existing Markdown implementations do not allow the text of setext headings to span multiple lines. But there is no consensus about how to interpret</p> <pre><code class="language-markdown">Foo bar --- baz </code></pre> <p>One can find four different interpretations:</p> <ol> <li>paragraph “Foo”, heading “bar”, paragraph “baz”</li> <li>paragraph “Foo bar”, thematic break, paragraph “baz”</li> <li>paragraph “Foo bar — baz”</li> <li>heading “Foo bar”, paragraph “baz”</li> </ol> <p>We find interpretation 4 most natural, and interpretation 4 increases the expressive power of CommonMark, by allowing multiline headings. Authors who want interpretation 1 can put a blank line after the first paragraph:</p> <div class="example" id="example-72"> <div class="examplenum"> <a href="#example-72">Example 72</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">Foo bar --- baz </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;Foo&lt;/p&gt; &lt;h2&gt;bar&lt;/h2&gt; &lt;p&gt;baz&lt;/p&gt; </code></pre> </div> </div> <p>Authors who want interpretation 2 can put blank lines around the thematic break,</p> <div class="example" id="example-73"> <div class="examplenum"> <a href="#example-73">Example 73</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">Foo bar --- baz </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;Foo bar&lt;/p&gt; &lt;hr<span class="space"> </span>/&gt; &lt;p&gt;baz&lt;/p&gt; </code></pre> </div> </div> <p>or use a thematic break that cannot count as a <a href="#setext-heading-underline">setext heading underline</a>, such as</p> <div class="example" id="example-74"> <div class="examplenum"> <a href="#example-74">Example 74</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">Foo bar *<span class="space"> </span>*<span class="space"> </span>* baz </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;Foo bar&lt;/p&gt; &lt;hr<span class="space"> </span>/&gt; &lt;p&gt;baz&lt;/p&gt; </code></pre> </div> </div> <p>Authors who want interpretation 3 can use backslash escapes:</p> <div class="example" id="example-75"> <div class="examplenum"> <a href="#example-75">Example 75</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">Foo bar \--- baz </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;Foo bar --- baz&lt;/p&gt; </code></pre> </div> </div> <h2 id="indented-code-blocks" href="#indented-code-blocks" class="definition"> <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-76"> <div class="examplenum"> <a href="#example-76">Example 76</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </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-77"> <div class="examplenum"> <a href="#example-77">Example 77</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> <div class="example" id="example-78"> <div class="examplenum"> <a href="#example-78">Example 78</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>The contents of a code block are literal text, and do not get parsed as Markdown:</p> <div class="example" id="example-79"> <div class="examplenum"> <a href="#example-79">Example 79</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>Here we have three chunks separated by blank lines:</p> <div class="example" id="example-80"> <div class="examplenum"> <a href="#example-80">Example 80</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;chunk1 chunk2 chunk3 &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> </div> <p>Any initial spaces beyond four will be included in the content, even in interior blank lines:</p> <div class="example" id="example-81"> <div class="examplenum"> <a href="#example-81">Example 81</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>An indented code block cannot interrupt a paragraph. (This allows hanging indents and the like.)</p> <div class="example" id="example-82"> <div class="examplenum"> <a href="#example-82">Example 82</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;Foo bar&lt;/p&gt; </code></pre> </div> </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-83"> <div class="examplenum"> <a href="#example-83">Example 83</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>And indented code can occur immediately before and after other kinds of blocks:</p> <div class="example" id="example-84"> <div class="examplenum"> <a href="#example-84">Example 84</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">#<span class="space"> </span>Heading <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>foo Heading ------ <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>foo ---- </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;h1&gt;Heading&lt;/h1&gt; &lt;pre&gt;&lt;code&gt;foo &lt;/code&gt;&lt;/pre&gt; &lt;h2&gt;Heading&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> </div> <p>The first line can be indented more than four spaces:</p> <div class="example" id="example-85"> <div class="examplenum"> <a href="#example-85">Example 85</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>Blank lines preceding or following an indented code block are not included in it:</p> <div class="example" id="example-86"> <div class="examplenum"> <a href="#example-86">Example 86</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;foo &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> </div> <p>Trailing spaces are included in the code block’s content:</p> <div class="example" id="example-87"> <div class="examplenum"> <a href="#example-87">Example 87</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <h2 id="fenced-code-blocks" href="#fenced-code-blocks" class="definition"> <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-88"> <div class="examplenum"> <a href="#example-88">Example 88</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">``` &lt; <span class="space"> </span>&gt; ``` </code></pre> </div> <div class="column"> <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> </div> <p>With tildes:</p> <div class="example" id="example-89"> <div class="examplenum"> <a href="#example-89">Example 89</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">~~~ &lt; <span class="space"> </span>&gt; ~~~ </code></pre> </div> <div class="column"> <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> </div> <p>Fewer than three backticks is not enough:</p> <div class="example" id="example-90"> <div class="examplenum"> <a href="#example-90">Example 90</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">`` foo `` </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&lt;code&gt;foo&lt;/code&gt;&lt;/p&gt; </code></pre> </div> </div> <p>The closing code fence must use the same character as the opening fence:</p> <div class="example" id="example-91"> <div class="examplenum"> <a href="#example-91">Example 91</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">``` aaa ~~~ ``` </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;aaa ~~~ &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> </div> <div class="example" id="example-92"> <div class="examplenum"> <a href="#example-92">Example 92</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">~~~ aaa ``` ~~~ </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;aaa ``` &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> </div> <p>The closing code fence must be at least as long as the opening fence:</p> <div class="example" id="example-93"> <div class="examplenum"> <a href="#example-93">Example 93</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">```` aaa ``` `````` </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;aaa ``` &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> </div> <div class="example" id="example-94"> <div class="examplenum"> <a href="#example-94">Example 94</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">~~~~ aaa ~~~ ~~~~ </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;aaa ~~~ &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> </div> <p>Unclosed code blocks are closed by the end of the document (or the enclosing <a href="#block-quotes">block quote</a> or <a href="#list-items">list item</a>):</p> <div class="example" id="example-95"> <div class="examplenum"> <a href="#example-95">Example 95</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">``` </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;&lt;/code&gt;&lt;/pre&gt; </code></pre> </div> </div> <div class="example" id="example-96"> <div class="examplenum"> <a href="#example-96">Example 96</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">````` ``` aaa </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt; ``` aaa &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> </div> <div class="example" id="example-97"> <div class="examplenum"> <a href="#example-97">Example 97</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&gt;<span class="space"> </span>``` &gt;<span class="space"> </span>aaa bbb </code></pre> </div> <div class="column"> <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> </div> <p>A code block can have all empty lines as its content:</p> <div class="example" id="example-98"> <div class="examplenum"> <a href="#example-98">Example 98</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">``` <span class="space"> </span><span class="space"> </span> ``` </code></pre> </div> <div class="column"> <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> </div> <p>A code block can be empty:</p> <div class="example" id="example-99"> <div class="examplenum"> <a href="#example-99">Example 99</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">``` ``` </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;&lt;/code&gt;&lt;/pre&gt; </code></pre> </div> </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-100"> <div class="examplenum"> <a href="#example-100">Example 100</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown"><span class="space"> </span>``` <span class="space"> </span>aaa aaa ``` </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;aaa aaa &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> </div> <div class="example" id="example-101"> <div class="examplenum"> <a href="#example-101">Example 101</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;aaa aaa aaa &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> </div> <div class="example" id="example-102"> <div class="examplenum"> <a href="#example-102">Example 102</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>Four spaces indentation produces an indented code block:</p> <div class="example" id="example-103"> <div class="examplenum"> <a href="#example-103">Example 103</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;``` aaa ``` &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> </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-104"> <div class="examplenum"> <a href="#example-104">Example 104</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">``` aaa <span class="space"> </span><span class="space"> </span>``` </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;aaa &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> </div> <div class="example" id="example-105"> <div class="examplenum"> <a href="#example-105">Example 105</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;aaa &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> </div> <p>This is not a closing fence, because it is indented 4 spaces:</p> <div class="example" id="example-106"> <div class="examplenum"> <a href="#example-106">Example 106</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">``` aaa <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>``` </code></pre> </div> <div class="column"> <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> </div> <p>Code fences (opening and closing) cannot contain internal spaces:</p> <div class="example" id="example-107"> <div class="examplenum"> <a href="#example-107">Example 107</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">```<span class="space"> </span>``` aaa </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&lt;code&gt;&lt;/code&gt; aaa&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-108"> <div class="examplenum"> <a href="#example-108">Example 108</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">~~~~~~ aaa ~~~<span class="space"> </span>~~ </code></pre> </div> <div class="column"> <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> </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-109"> <div class="examplenum"> <a href="#example-109">Example 109</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">foo ``` bar ``` baz </code></pre> </div> <div class="column"> <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> </div> <p>Other blocks can also occur before and after fenced code blocks without an intervening blank line:</p> <div class="example" id="example-110"> <div class="examplenum"> <a href="#example-110">Example 110</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">foo --- ~~~ bar ~~~ #<span class="space"> </span>baz </code></pre> </div> <div class="column"> <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> </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-111"> <div class="examplenum"> <a href="#example-111">Example 111</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> <div class="example" id="example-112"> <div class="examplenum"> <a href="#example-112">Example 112</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> <div class="example" id="example-113"> <div class="examplenum"> <a href="#example-113">Example 113</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">````; ```` </code></pre> </div> <div class="column"> <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> </div> <p><a href="#info-string">Info strings</a> for backtick code blocks cannot contain backticks:</p> <div class="example" id="example-114"> <div class="examplenum"> <a href="#example-114">Example 114</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">```<span class="space"> </span>aa<span class="space"> </span>``` foo </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&lt;code&gt;aa&lt;/code&gt; foo&lt;/p&gt; </code></pre> </div> </div> <p>Closing code fences cannot have <a href="#info-string">info strings</a>:</p> <div class="example" id="example-115"> <div class="examplenum"> <a href="#example-115">Example 115</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">``` ```<span class="space"> </span>aaa ``` </code></pre> </div> <div class="column"> <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> </div> <h2 id="html-blocks" href="#html-blocks" class="definition"> <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 or other <a href="#container-block">container block</a>), 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>h2</code>, <code>h3</code>, <code>h4</code>, <code>h5</code>, <code>h6</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>HTML blocks continue until they are closed by their appropriate <a href="#end-condition">end condition</a>, or the last line of the document or other <a href="#container-block">container block</a>. This means any HTML <strong>within an HTML block</strong> that might otherwise be recognised as a start condition will be ignored by the parser and passed through as-is, without changing the parser’s state.</p> <p>For instance, <code>&lt;pre&gt;</code> within a HTML block started by <code>&lt;table&gt;</code> will not affect the parser state; as the HTML block was started in by start condition 6, it will end at any blank line. This can be surprising:</p> <div class="example" id="example-116"> <div class="examplenum"> <a href="#example-116">Example 116</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;table&gt;&lt;tr&gt;&lt;td&gt; &lt;pre&gt; **Hello**, _world_. &lt;/pre&gt; &lt;/td&gt;&lt;/tr&gt;&lt;/table&gt; </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;table&gt;&lt;tr&gt;&lt;td&gt; &lt;pre&gt; **Hello**, &lt;p&gt;&lt;em&gt;world&lt;/em&gt;. &lt;/pre&gt;&lt;/p&gt; &lt;/td&gt;&lt;/tr&gt;&lt;/table&gt; </code></pre> </div> </div> <p>In this case, the HTML block is terminated by the newline — the <code>**hello**</code> text remains verbatim — and regular parsing resumes, with a paragraph, emphasised <code>world</code> and inline and block HTML following.</p> <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-117"> <div class="examplenum"> <a href="#example-117">Example 117</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> <div class="example" id="example-118"> <div class="examplenum"> <a href="#example-118">Example 118</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>A block can also start with a closing tag:</p> <div class="example" id="example-119"> <div class="examplenum"> <a href="#example-119">Example 119</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;/div&gt; *foo* </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;/div&gt; *foo* </code></pre> </div> </div> <p>Here we have two HTML blocks with a Markdown paragraph between them:</p> <div class="example" id="example-120"> <div class="examplenum"> <a href="#example-120">Example 120</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;DIV<span class="space"> </span>CLASS=&quot;foo&quot;&gt; *Markdown* &lt;/DIV&gt; </code></pre> </div> <div class="column"> <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> </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-121"> <div class="examplenum"> <a href="#example-121">Example 121</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> <div class="example" id="example-122"> <div class="examplenum"> <a href="#example-122">Example 122</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>An open tag need not be closed:</p> <div class="example" id="example-123"> <div class="examplenum"> <a href="#example-123">Example 123</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;div&gt; *foo* *bar* </code></pre> </div> <div class="column"> <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> </div> <p>A partial tag need not even be completed (garbage in, garbage out):</p> <div class="example" id="example-124"> <div class="examplenum"> <a href="#example-124">Example 124</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;div<span class="space"> </span>id=&quot;foo&quot; *hi* </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;div<span class="space"> </span>id=&quot;foo&quot; *hi* </code></pre> </div> </div> <div class="example" id="example-125"> <div class="examplenum"> <a href="#example-125">Example 125</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;div<span class="space"> </span>class foo </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;div<span class="space"> </span>class foo </code></pre> </div> </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-126"> <div class="examplenum"> <a href="#example-126">Example 126</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;div<span class="space"> </span>*???-&amp;&amp;&amp;-&lt;--- *foo* </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;div<span class="space"> </span>*???-&amp;&amp;&amp;-&lt;--- *foo* </code></pre> </div> </div> <p>In type 6 blocks, the initial tag need not be on a line by itself:</p> <div class="example" id="example-127"> <div class="examplenum"> <a href="#example-127">Example 127</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> <div class="example" id="example-128"> <div class="examplenum"> <a href="#example-128">Example 128</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </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-129"> <div class="examplenum"> <a href="#example-129">Example 129</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </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-130"> <div class="examplenum"> <a href="#example-130">Example 130</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;a<span class="space"> </span>href=&quot;foo&quot;&gt; *bar* &lt;/a&gt; </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;a<span class="space"> </span>href=&quot;foo&quot;&gt; *bar* &lt;/a&gt; </code></pre> </div> </div> <p>In type 7 blocks, the <a href="#tag-name">tag name</a> can be anything:</p> <div class="example" id="example-131"> <div class="examplenum"> <a href="#example-131">Example 131</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;Warning&gt; *bar* &lt;/Warning&gt; </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;Warning&gt; *bar* &lt;/Warning&gt; </code></pre> </div> </div> <div class="example" id="example-132"> <div class="examplenum"> <a href="#example-132">Example 132</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;i<span class="space"> </span>class=&quot;foo&quot;&gt; *bar* &lt;/i&gt; </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;i<span class="space"> </span>class=&quot;foo&quot;&gt; *bar* &lt;/i&gt; </code></pre> </div> </div> <div class="example" id="example-133"> <div class="examplenum"> <a href="#example-133">Example 133</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;/ins&gt; *bar* </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;/ins&gt; *bar* </code></pre> </div> </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-134"> <div class="examplenum"> <a href="#example-134">Example 134</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;del&gt; *foo* &lt;/del&gt; </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;del&gt; *foo* &lt;/del&gt; </code></pre> </div> </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-135"> <div class="examplenum"> <a href="#example-135">Example 135</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;del&gt; *foo* &lt;/del&gt; </code></pre> </div> <div class="column"> <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> </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-136"> <div class="examplenum"> <a href="#example-136">Example 136</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;del&gt;*foo*&lt;/del&gt; </code></pre> </div> <div class="column"> <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> </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-137"> <div class="examplenum"> <a href="#example-137">Example 137</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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; okay </code></pre> </div> <div class="column"> <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; &lt;p&gt;okay&lt;/p&gt; </code></pre> </div> </div> <p>A script tag (type 1):</p> <div class="example" id="example-138"> <div class="examplenum"> <a href="#example-138">Example 138</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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; okay </code></pre> </div> <div class="column"> <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; &lt;p&gt;okay&lt;/p&gt; </code></pre> </div> </div> <p>A style tag (type 1):</p> <div class="example" id="example-139"> <div class="examplenum"> <a href="#example-139">Example 139</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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; okay </code></pre> </div> <div class="column"> <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; &lt;p&gt;okay&lt;/p&gt; </code></pre> </div> </div> <p>If there is no matching end tag, the block will end at the end of the document (or the enclosing <a href="#block-quotes">block quote</a> or <a href="#list-items">list item</a>):</p> <div class="example" id="example-140"> <div class="examplenum"> <a href="#example-140">Example 140</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;style <span class="space"> </span><span class="space"> </span>type=&quot;text/css&quot;&gt; foo </code></pre> </div> <div class="column"> <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> <div class="example" id="example-141"> <div class="examplenum"> <a href="#example-141">Example 141</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&gt;<span class="space"> </span>&lt;div&gt; &gt;<span class="space"> </span>foo bar </code></pre> </div> <div class="column"> <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> <div class="example" id="example-142"> <div class="examplenum"> <a href="#example-142">Example 142</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">-<span class="space"> </span>&lt;div&gt; -<span class="space"> </span>foo </code></pre> </div> <div class="column"> <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> </div> <p>The end tag can occur on the same line as the start tag:</p> <div class="example" id="example-143"> <div class="examplenum"> <a href="#example-143">Example 143</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;style&gt;p{color:red;}&lt;/style&gt; *foo* </code></pre> </div> <div class="column"> <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> <div class="example" id="example-144"> <div class="examplenum"> <a href="#example-144">Example 144</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;!--<span class="space"> </span>foo<span class="space"> </span>--&gt;*bar* *baz* </code></pre> </div> <div class="column"> <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> </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-145"> <div class="examplenum"> <a href="#example-145">Example 145</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;script&gt; foo &lt;/script&gt;1.<span class="space"> </span>*bar* </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;script&gt; foo &lt;/script&gt;1.<span class="space"> </span>*bar* </code></pre> </div> </div> <p>A comment (type 2):</p> <div class="example" id="example-146"> <div class="examplenum"> <a href="#example-146">Example 146</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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; okay </code></pre> </div> <div class="column"> <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; &lt;p&gt;okay&lt;/p&gt; </code></pre> </div> </div> <p>A processing instruction (type 3):</p> <div class="example" id="example-147"> <div class="examplenum"> <a href="#example-147">Example 147</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;?php <span class="space"> </span><span class="space"> </span>echo<span class="space"> </span>'&gt;'; ?&gt; okay </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;?php <span class="space"> </span><span class="space"> </span>echo<span class="space"> </span>'&gt;'; ?&gt; &lt;p&gt;okay&lt;/p&gt; </code></pre> </div> </div> <p>A declaration (type 4):</p> <div class="example" id="example-148"> <div class="examplenum"> <a href="#example-148">Example 148</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;!DOCTYPE<span class="space"> </span>html&gt; </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;!DOCTYPE<span class="space"> </span>html&gt; </code></pre> </div> </div> <p>CDATA (type 5):</p> <div class="example" id="example-149"> <div class="examplenum"> <a href="#example-149">Example 149</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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; okay </code></pre> </div> <div class="column"> <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; &lt;p&gt;okay&lt;/p&gt; </code></pre> </div> </div> <p>The opening tag can be indented 1-3 spaces, but not 4:</p> <div class="example" id="example-150"> <div class="examplenum"> <a href="#example-150">Example 150</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> <div class="example" id="example-151"> <div class="examplenum"> <a href="#example-151">Example 151</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </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-152"> <div class="examplenum"> <a href="#example-152">Example 152</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">Foo &lt;div&gt; bar &lt;/div&gt; </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;Foo&lt;/p&gt; &lt;div&gt; bar &lt;/div&gt; </code></pre> </div> </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-153"> <div class="examplenum"> <a href="#example-153">Example 153</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;div&gt; bar &lt;/div&gt; *foo* </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;div&gt; bar &lt;/div&gt; *foo* </code></pre> </div> </div> <p>HTML blocks of type 7 cannot interrupt a paragraph:</p> <div class="example" id="example-154"> <div class="examplenum"> <a href="#example-154">Example 154</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">Foo &lt;a<span class="space"> </span>href=&quot;bar&quot;&gt; baz </code></pre> </div> <div class="column"> <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> </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-155"> <div class="examplenum"> <a href="#example-155">Example 155</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;div&gt; *Emphasized*<span class="space"> </span>text. &lt;/div&gt; </code></pre> </div> <div class="column"> <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> <div class="example" id="example-156"> <div class="examplenum"> <a href="#example-156">Example 156</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;div&gt; *Emphasized*<span class="space"> </span>text. &lt;/div&gt; </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;div&gt; *Emphasized*<span class="space"> </span>text. &lt;/div&gt; </code></pre> </div> </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-157"> <div class="examplenum"> <a href="#example-157">Example 157</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </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-158"> <div class="examplenum"> <a href="#example-158">Example 158</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </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 id="link-reference-definitions" href="#link-reference-definitions" class="definition"> <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-definition">Link reference definitions</a> can come either before or after the links that use them.</p> <div class="example" id="example-159"> <div class="examplenum"> <a href="#example-159">Example 159</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[foo]:<span class="space"> </span>/url<span class="space"> </span>&quot;title&quot; [foo] </code></pre> </div> <div class="column"> <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> <div class="example" id="example-160"> <div class="examplenum"> <a href="#example-160">Example 160</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> <div class="example" id="example-161"> <div class="examplenum"> <a href="#example-161">Example 161</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> <div class="example" id="example-162"> <div class="examplenum"> <a href="#example-162">Example 162</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[Foo<span class="space"> </span>bar]: &lt;my%20url&gt; 'title' [Foo<span class="space"> </span>bar] </code></pre> </div> <div class="column"> <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> </div> <p>The title may extend over multiple lines:</p> <div class="example" id="example-163"> <div class="examplenum"> <a href="#example-163">Example 163</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[foo]:<span class="space"> </span>/url<span class="space"> </span>' title line1 line2 ' [foo] </code></pre> </div> <div class="column"> <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> </div> <p>However, it may not contain a <a href="#blank-line">blank line</a>:</p> <div class="example" id="example-164"> <div class="examplenum"> <a href="#example-164">Example 164</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>The title may be omitted:</p> <div class="example" id="example-165"> <div class="examplenum"> <a href="#example-165">Example 165</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[foo]: /url [foo] </code></pre> </div> <div class="column"> <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> <p>The link destination may not be omitted:</p> <div class="example" id="example-166"> <div class="examplenum"> <a href="#example-166">Example 166</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[foo]: [foo] </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;[foo]:&lt;/p&gt; &lt;p&gt;[foo]&lt;/p&gt; </code></pre> </div> </div> <p>Both title and destination can contain backslash escapes and literal backslashes:</p> <div class="example" id="example-167"> <div class="examplenum"> <a href="#example-167">Example 167</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>A link can come before its corresponding definition:</p> <div class="example" id="example-168"> <div class="examplenum"> <a href="#example-168">Example 168</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[foo] [foo]:<span class="space"> </span>url </code></pre> </div> <div class="column"> <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> <p>If there are several matching definitions, the first one takes precedence:</p> <div class="example" id="example-169"> <div class="examplenum"> <a href="#example-169">Example 169</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[foo] [foo]:<span class="space"> </span>first [foo]:<span class="space"> </span>second </code></pre> </div> <div class="column"> <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> </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-170"> <div class="examplenum"> <a href="#example-170">Example 170</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[FOO]:<span class="space"> </span>/url [Foo] </code></pre> </div> <div class="column"> <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> <div class="example" id="example-171"> <div class="examplenum"> <a href="#example-171">Example 171</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[ΑΓΩ]:<span class="space"> </span>/φου [αγω] </code></pre> </div> <div class="column"> <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> </div> <p>Here is a link reference definition with no corresponding link. It contributes nothing to the document.</p> <div class="example" id="example-172"> <div class="examplenum"> <a href="#example-172">Example 172</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[foo]:<span class="space"> </span>/url </code></pre> </div> <div class="column"> <pre><code class="language-html"></code></pre> </div> </div> <p>Here is another one:</p> <div class="example" id="example-173"> <div class="examplenum"> <a href="#example-173">Example 173</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[ foo ]:<span class="space"> </span>/url bar </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;bar&lt;/p&gt; </code></pre> </div> </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-174"> <div class="examplenum"> <a href="#example-174">Example 174</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>This is a link reference definition, but it has no title:</p> <div class="example" id="example-175"> <div class="examplenum"> <a href="#example-175">Example 175</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[foo]:<span class="space"> </span>/url &quot;title&quot;<span class="space"> </span>ok </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&amp;quot;title&amp;quot;<span class="space"> </span>ok&lt;/p&gt; </code></pre> </div> </div> <p>This is not a link reference definition, because it is indented four spaces:</p> <div class="example" id="example-176"> <div class="examplenum"> <a href="#example-176">Example 176</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>This is not a link reference definition, because it occurs inside a code block:</p> <div class="example" id="example-177"> <div class="examplenum"> <a href="#example-177">Example 177</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">``` [foo]:<span class="space"> </span>/url ``` [foo] </code></pre> </div> <div class="column"> <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> </div> <p>A <a href="#link-reference-definition">link reference definition</a> cannot interrupt a paragraph.</p> <div class="example" id="example-178"> <div class="examplenum"> <a href="#example-178">Example 178</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">Foo [bar]:<span class="space"> </span>/baz [bar] </code></pre> </div> <div class="column"> <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> </div> <p>However, it can directly follow other block elements, such as headings and thematic breaks, and it need not be followed by a blank line.</p> <div class="example" id="example-179"> <div class="examplenum"> <a href="#example-179">Example 179</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">#<span class="space"> </span>[Foo] [foo]:<span class="space"> </span>/url &gt;<span class="space"> </span>bar </code></pre> </div> <div class="column"> <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> </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-180"> <div class="examplenum"> <a href="#example-180">Example 180</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </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-181"> <div class="examplenum"> <a href="#example-181">Example 181</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[foo] &gt;<span class="space"> </span>[foo]:<span class="space"> </span>/url </code></pre> </div> <div class="column"> <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> </div> <h2 id="paragraphs" href="#paragraphs" class="definition"> <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-182"> <div class="examplenum"> <a href="#example-182">Example 182</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">aaa bbb </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;aaa&lt;/p&gt; &lt;p&gt;bbb&lt;/p&gt; </code></pre> </div> </div> <p>Paragraphs can contain multiple lines, but no blank lines:</p> <div class="example" id="example-183"> <div class="examplenum"> <a href="#example-183">Example 183</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">aaa bbb ccc ddd </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;aaa bbb&lt;/p&gt; &lt;p&gt;ccc ddd&lt;/p&gt; </code></pre> </div> </div> <p>Multiple blank lines between paragraph have no effect:</p> <div class="example" id="example-184"> <div class="examplenum"> <a href="#example-184">Example 184</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">aaa bbb </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;aaa&lt;/p&gt; &lt;p&gt;bbb&lt;/p&gt; </code></pre> </div> </div> <p>Leading spaces are skipped:</p> <div class="example" id="example-185"> <div class="examplenum"> <a href="#example-185">Example 185</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown"><span class="space"> </span><span class="space"> </span>aaa <span class="space"> </span>bbb </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;aaa bbb&lt;/p&gt; </code></pre> </div> </div> <p>Lines after the first may be indented any amount, since indented code blocks cannot interrupt paragraphs.</p> <div class="example" id="example-186"> <div class="examplenum"> <a href="#example-186">Example 186</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;aaa bbb ccc&lt;/p&gt; </code></pre> </div> </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-187"> <div class="examplenum"> <a href="#example-187">Example 187</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown"><span class="space"> </span><span class="space"> </span><span class="space"> </span>aaa bbb </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;aaa bbb&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-188"> <div class="examplenum"> <a href="#example-188">Example 188</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </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-189"> <div class="examplenum"> <a href="#example-189">Example 189</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;aaa&lt;br<span class="space"> </span>/&gt; bbb&lt;/p&gt; </code></pre> </div> </div> <h2 id="blank-lines" href="#blank-lines" class="definition"> <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-190"> <div class="examplenum"> <a href="#example-190">Example 190</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;aaa&lt;/p&gt; &lt;h1&gt;aaa&lt;/h1&gt; </code></pre> </div> </div> <h1 id="container-blocks" href="#container-blocks" class="definition"> <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="#list">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 id="block-quotes" href="#block-quotes" class="definition"> <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-191"> <div class="examplenum"> <a href="#example-191">Example 191</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>The spaces after the <code>&gt;</code> characters can be omitted:</p> <div class="example" id="example-192"> <div class="examplenum"> <a href="#example-192">Example 192</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&gt;#<span class="space"> </span>Foo &gt;bar &gt;<span class="space"> </span>baz </code></pre> </div> <div class="column"> <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> </div> <p>The <code>&gt;</code> characters can be indented 1-3 spaces:</p> <div class="example" id="example-193"> <div class="examplenum"> <a href="#example-193">Example 193</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>Four spaces gives us a code block:</p> <div class="example" id="example-194"> <div class="examplenum"> <a href="#example-194">Example 194</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>The Laziness clause allows us to omit the <code>&gt;</code> before <a href="#paragraph-continuation-text">paragraph continuation text</a>:</p> <div class="example" id="example-195"> <div class="examplenum"> <a href="#example-195">Example 195</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&gt;<span class="space"> </span>#<span class="space"> </span>Foo &gt;<span class="space"> </span>bar baz </code></pre> </div> <div class="column"> <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> </div> <p>A block quote can contain some lazy and some non-lazy continuation lines:</p> <div class="example" id="example-196"> <div class="examplenum"> <a href="#example-196">Example 196</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&gt;<span class="space"> </span>bar baz &gt;<span class="space"> </span>foo </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;blockquote&gt; &lt;p&gt;bar baz foo&lt;/p&gt; &lt;/blockquote&gt; </code></pre> </div> </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-197"> <div class="examplenum"> <a href="#example-197">Example 197</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&gt;<span class="space"> </span>foo --- </code></pre> </div> <div class="column"> <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> <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-198"> <div class="examplenum"> <a href="#example-198">Example 198</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&gt;<span class="space"> </span>-<span class="space"> </span>foo -<span class="space"> </span>bar </code></pre> </div> <div class="column"> <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> </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-199"> <div class="examplenum"> <a href="#example-199">Example 199</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> <div class="example" id="example-200"> <div class="examplenum"> <a href="#example-200">Example 200</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&gt;<span class="space"> </span>``` foo ``` </code></pre> </div> <div class="column"> <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> </div> <p>Note that in the following case, we have a <a href="#lazy-continuation-line">lazy continuation line</a>:</p> <div class="example" id="example-201"> <div class="examplenum"> <a href="#example-201">Example 201</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </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 href="#paragraph-continuation-text">paragraph continuation text</a>.</p> <p>A block quote can be empty:</p> <div class="example" id="example-202"> <div class="examplenum"> <a href="#example-202">Example 202</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&gt; </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;blockquote&gt; &lt;/blockquote&gt; </code></pre> </div> </div> <div class="example" id="example-203"> <div class="examplenum"> <a href="#example-203">Example 203</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&gt; &gt;<span class="space"> </span><span class="space"> </span> &gt;<span class="space"> </span> </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;blockquote&gt; &lt;/blockquote&gt; </code></pre> </div> </div> <p>A block quote can have initial or final blank lines:</p> <div class="example" id="example-204"> <div class="examplenum"> <a href="#example-204">Example 204</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&gt; &gt;<span class="space"> </span>foo &gt;<span class="space"> </span><span class="space"> </span> </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;blockquote&gt; &lt;p&gt;foo&lt;/p&gt; &lt;/blockquote&gt; </code></pre> </div> </div> <p>A blank line always separates block quotes:</p> <div class="example" id="example-205"> <div class="examplenum"> <a href="#example-205">Example 205</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&gt;<span class="space"> </span>foo &gt;<span class="space"> </span>bar </code></pre> </div> <div class="column"> <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> </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-206"> <div class="examplenum"> <a href="#example-206">Example 206</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&gt;<span class="space"> </span>foo &gt;<span class="space"> </span>bar </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;blockquote&gt; &lt;p&gt;foo bar&lt;/p&gt; &lt;/blockquote&gt; </code></pre> </div> </div> <p>To get a block quote with two paragraphs, use:</p> <div class="example" id="example-207"> <div class="examplenum"> <a href="#example-207">Example 207</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&gt;<span class="space"> </span>foo &gt; &gt;<span class="space"> </span>bar </code></pre> </div> <div class="column"> <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> </div> <p>Block quotes can interrupt paragraphs:</p> <div class="example" id="example-208"> <div class="examplenum"> <a href="#example-208">Example 208</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">foo &gt;<span class="space"> </span>bar </code></pre> </div> <div class="column"> <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> </div> <p>In general, blank lines are not needed before or after block quotes:</p> <div class="example" id="example-209"> <div class="examplenum"> <a href="#example-209">Example 209</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&gt;<span class="space"> </span>aaa *** &gt;<span class="space"> </span>bbb </code></pre> </div> <div class="column"> <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> </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-210"> <div class="examplenum"> <a href="#example-210">Example 210</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&gt;<span class="space"> </span>bar baz </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;blockquote&gt; &lt;p&gt;bar baz&lt;/p&gt; &lt;/blockquote&gt; </code></pre> </div> </div> <div class="example" id="example-211"> <div class="examplenum"> <a href="#example-211">Example 211</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&gt;<span class="space"> </span>bar baz </code></pre> </div> <div class="column"> <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> <div class="example" id="example-212"> <div class="examplenum"> <a href="#example-212">Example 212</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&gt;<span class="space"> </span>bar &gt; baz </code></pre> </div> <div class="column"> <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> <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-213"> <div class="examplenum"> <a href="#example-213">Example 213</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&gt;<span class="space"> </span>&gt;<span class="space"> </span>&gt;<span class="space"> </span>foo bar </code></pre> </div> <div class="column"> <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> <div class="example" id="example-214"> <div class="examplenum"> <a href="#example-214">Example 214</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&gt;&gt;&gt;<span class="space"> </span>foo &gt;<span class="space"> </span>bar &gt;&gt;baz </code></pre> </div> <div class="column"> <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> </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-215"> <div class="examplenum"> <a href="#example-215">Example 215</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <h2 id="list-items" href="#list-items" class="definition"> <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> <p><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 1 ≤ <em>N</em> ≤ 4 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.</p> <p>Exceptions:</p> <ol> <li>When the first list item in a <a href="#list">list</a> interrupts a paragraph—that is, when it starts on a line that would otherwise count as <a href="#paragraph-continuation-text">paragraph continuation text</a>—then (a) the lines <em>Ls</em> must not begin with a blank line, and (b) if the list item is ordered, the start number must be 1.</li> <li>If any line is a <a href="#thematic-break">thematic break</a> then that line is not a list item.</li> </ol> </li> </ol> <p>For example, let <em>Ls</em> be the lines</p> <div class="example" id="example-216"> <div class="examplenum"> <a href="#example-216">Example 216</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </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-217"> <div class="examplenum"> <a href="#example-217">Example 217</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </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-218"> <div class="examplenum"> <a href="#example-218">Example 218</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">-<span class="space"> </span>one <span class="space"> </span>two </code></pre> </div> <div class="column"> <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> <div class="example" id="example-219"> <div class="examplenum"> <a href="#example-219">Example 219</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">-<span class="space"> </span>one <span class="space"> </span><span class="space"> </span>two </code></pre> </div> <div class="column"> <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> <div class="example" id="example-220"> <div class="examplenum"> <a href="#example-220">Example 220</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> <div class="example" id="example-221"> <div class="examplenum"> <a href="#example-221">Example 221</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> <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-222"> <div class="examplenum"> <a href="#example-222">Example 222</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </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-223"> <div class="examplenum"> <a href="#example-223">Example 223</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </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-224"> <div class="examplenum"> <a href="#example-224">Example 224</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">-one 2.two </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;-one&lt;/p&gt; &lt;p&gt;2.two&lt;/p&gt; </code></pre> </div> </div> <p>A list item may contain blocks that are separated by more than one blank line.</p> <div class="example" id="example-225"> <div class="examplenum"> <a href="#example-225">Example 225</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">-<span class="space"> </span>foo <span class="space"> </span><span class="space"> </span>bar </code></pre> </div> <div class="column"> <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> <p>A list item may contain any kind of block:</p> <div class="example" id="example-226"> <div class="examplenum"> <a href="#example-226">Example 226</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>A list item that contains an indented code block will preserve empty lines within the code block verbatim.</p> <div class="example" id="example-227"> <div class="examplenum"> <a href="#example-227">Example 227</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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><span class="space"> </span><span class="space"> </span>baz </code></pre> </div> <div class="column"> <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 baz &lt;/code&gt;&lt;/pre&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> </div> </div> <p>Note that ordered list start numbers must be nine digits or less:</p> <div class="example" id="example-228"> <div class="examplenum"> <a href="#example-228">Example 228</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">123456789.<span class="space"> </span>ok </code></pre> </div> <div class="column"> <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> <div class="example" id="example-229"> <div class="examplenum"> <a href="#example-229">Example 229</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">1234567890.<span class="space"> </span>not<span class="space"> </span>ok </code></pre> </div> <div class="column"> <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> </div> <p>A start number may begin with 0s:</p> <div class="example" id="example-230"> <div class="examplenum"> <a href="#example-230">Example 230</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">0.<span class="space"> </span>ok </code></pre> </div> <div class="column"> <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> <div class="example" id="example-231"> <div class="examplenum"> <a href="#example-231">Example 231</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">003.<span class="space"> </span>ok </code></pre> </div> <div class="column"> <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> </div> <p>A start number may not be negative:</p> <div class="example" id="example-232"> <div class="examplenum"> <a href="#example-232">Example 232</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">-1.<span class="space"> </span>not<span class="space"> </span>ok </code></pre> </div> <div class="column"> <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> </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-233"> <div class="examplenum"> <a href="#example-233">Example 233</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>And in this case it is 11 spaces:</p> <div class="example" id="example-234"> <div class="examplenum"> <a href="#example-234">Example 234</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </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-235"> <div class="examplenum"> <a href="#example-235">Example 235</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> <div class="example" id="example-236"> <div class="examplenum"> <a href="#example-236">Example 236</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>Note that an additional space indent is interpreted as space inside the code block:</p> <div class="example" id="example-237"> <div class="examplenum"> <a href="#example-237">Example 237</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </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-238"> <div class="examplenum"> <a href="#example-238">Example 238</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown"><span class="space"> </span><span class="space"> </span><span class="space"> </span>foo bar </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;foo&lt;/p&gt; &lt;p&gt;bar&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-239"> <div class="examplenum"> <a href="#example-239">Example 239</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </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-240"> <div class="examplenum"> <a href="#example-240">Example 240</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> <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-241"> <div class="examplenum"> <a href="#example-241">Example 241</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>When the list item starts with a blank line, the number of spaces following the list marker doesn’t change the required indentation:</p> <div class="example" id="example-242"> <div class="examplenum"> <a href="#example-242">Example 242</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <pre><code class="language-html">&lt;ul&gt; &lt;li&gt;foo&lt;/li&gt; &lt;/ul&gt; </code></pre> </div> </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-243"> <div class="examplenum"> <a href="#example-243">Example 243</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">- <span class="space"> </span><span class="space"> </span>foo </code></pre> </div> <div class="column"> <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> </div> <p>Here is an empty bullet list item:</p> <div class="example" id="example-244"> <div class="examplenum"> <a href="#example-244">Example 244</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">-<span class="space"> </span>foo - -<span class="space"> </span>bar </code></pre> </div> <div class="column"> <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> </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-245"> <div class="examplenum"> <a href="#example-245">Example 245</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>Here is an empty ordered list item:</p> <div class="example" id="example-246"> <div class="examplenum"> <a href="#example-246">Example 246</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">1.<span class="space"> </span>foo 2. 3.<span class="space"> </span>bar </code></pre> </div> <div class="column"> <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> </div> <p>A list may start or end with an empty list item:</p> <div class="example" id="example-247"> <div class="examplenum"> <a href="#example-247">Example 247</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">* </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;ul&gt; &lt;li&gt;&lt;/li&gt; &lt;/ul&gt; </code></pre> </div> </div> <p>However, an empty list item cannot interrupt a paragraph:</p> <div class="example" id="example-248"> <div class="examplenum"> <a href="#example-248">Example 248</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">foo * foo 1. </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;foo *&lt;/p&gt; &lt;p&gt;foo 1.&lt;/p&gt; </code></pre> </div> </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-249"> <div class="examplenum"> <a href="#example-249">Example 249</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>Indented two spaces:</p> <div class="example" id="example-250"> <div class="examplenum"> <a href="#example-250">Example 250</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>Indented three spaces:</p> <div class="example" id="example-251"> <div class="examplenum"> <a href="#example-251">Example 251</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>Four spaces indent gives a code block:</p> <div class="example" id="example-252"> <div class="examplenum"> <a href="#example-252">Example 252</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </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 line</a>s.</li> </ol> <p>Here is an example with <a href="#lazy-continuation-line">lazy continuation lines</a>:</p> <div class="example" id="example-253"> <div class="examplenum"> <a href="#example-253">Example 253</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>Indentation can be partially deleted:</p> <div class="example" id="example-254"> <div class="examplenum"> <a href="#example-254">Example 254</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>These examples show how laziness can work in nested structures:</p> <div class="example" id="example-255"> <div class="examplenum"> <a href="#example-255">Example 255</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> <div class="example" id="example-256"> <div class="examplenum"> <a href="#example-256">Example 256</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> <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-257"> <div class="examplenum"> <a href="#example-257">Example 257</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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>-<span class="space"> </span>boo </code></pre> </div> <div class="column"> <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;ul&gt; &lt;li&gt;boo&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> </div> </div> <p>One is not enough:</p> <div class="example" id="example-258"> <div class="examplenum"> <a href="#example-258">Example 258</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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 <span class="space"> </span><span class="space"> </span><span class="space"> </span>-<span class="space"> </span>boo </code></pre> </div> <div class="column"> <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;li&gt;boo&lt;/li&gt; &lt;/ul&gt; </code></pre> </div> </div> <p>Here we need four, because the list marker is wider:</p> <div class="example" id="example-259"> <div class="examplenum"> <a href="#example-259">Example 259</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>Three is not enough:</p> <div class="example" id="example-260"> <div class="examplenum"> <a href="#example-260">Example 260</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>A list may be the first block in a list item:</p> <div class="example" id="example-261"> <div class="examplenum"> <a href="#example-261">Example 261</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">-<span class="space"> </span>-<span class="space"> </span>foo </code></pre> </div> <div class="column"> <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> <div class="example" id="example-262"> <div class="examplenum"> <a href="#example-262">Example 262</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">1.<span class="space"> </span>-<span class="space"> </span>2.<span class="space"> </span>foo </code></pre> </div> <div class="column"> <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> </div> <p>A list item can contain a heading:</p> <div class="example" id="example-263"> <div class="examplenum"> <a href="#example-263">Example 263</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <h3 id="motivation" href="#motivation" class="definition"> <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 id="lists" href="#lists" class="definition"> <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 any number of blank lines.</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-264"> <div class="examplenum"> <a href="#example-264">Example 264</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">-<span class="space"> </span>foo -<span class="space"> </span>bar +<span class="space"> </span>baz </code></pre> </div> <div class="column"> <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> <div class="example" id="example-265"> <div class="examplenum"> <a href="#example-265">Example 265</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </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-266"> <div class="examplenum"> <a href="#example-266">Example 266</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">Foo -<span class="space"> </span>bar -<span class="space"> </span>baz </code></pre> </div> <div class="column"> <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> </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> <pre><code class="language-markdown">The number of windows in my house is 14. The number of doors is 6. </code></pre> <p>Oddly, though, <code>Markdown.pl</code> <em>does</em> allow a blockquote to interrupt a paragraph, even though the same considerations might apply.</p> <p>In CommonMark, we do allow lists to interrupt paragraphs, for two reasons. First, it is natural and not uncommon for people to start lists without blank lines:</p> <pre><code class="language-markdown">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 class="language-markdown"> * 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 class="language-markdown">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>Since it is well established Markdown practice to allow lists to interrupt paragraphs inside list items, the <a href="#principle-of-uniformity">principle of uniformity</a> requires us to allow this outside list items as well. (<a href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> takes a different approach, requiring blank lines before lists even inside other list items.)</p> <p>In order to solve of unwanted lists in paragraphs with hard-wrapped numerals, we allow only lists starting with <code>1</code> to interrupt paragraphs. Thus,</p> <div class="example" id="example-267"> <div class="examplenum"> <a href="#example-267">Example 267</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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 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.&lt;/p&gt; </code></pre> </div> </div> <p>We may still get an unintended result in cases like</p> <div class="example" id="example-268"> <div class="examplenum"> <a href="#example-268">Example 268</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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 1.<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> </div> <div class="column"> <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&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> </div> <p>but this rule should prevent most spurious list captures.</p> <p>There can be any number of blank lines between items:</p> <div class="example" id="example-269"> <div class="examplenum"> <a href="#example-269">Example 269</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">-<span class="space"> </span>foo -<span class="space"> </span>bar -<span class="space"> </span>baz </code></pre> </div> <div class="column"> <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;li&gt; &lt;p&gt;baz&lt;/p&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> </div> </div> <div class="example" id="example-270"> <div class="examplenum"> <a href="#example-270">Example 270</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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; &lt;p&gt;baz&lt;/p&gt; &lt;p&gt;bim&lt;/p&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> </div> </div> <p>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, you can insert a blank HTML comment:</p> <div class="example" id="example-271"> <div class="examplenum"> <a href="#example-271">Example 271</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">-<span class="space"> </span>foo -<span class="space"> </span>bar &lt;!--<span class="space"> </span>--&gt; -<span class="space"> </span>baz -<span class="space"> </span>bim </code></pre> </div> <div class="column"> <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;!--<span class="space"> </span>--&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> <div class="example" id="example-272"> <div class="examplenum"> <a href="#example-272">Example 272</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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 &lt;!--<span class="space"> </span>--&gt; <span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>code </code></pre> </div> <div class="column"> <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;!--<span class="space"> </span>--&gt; &lt;pre&gt;&lt;code&gt;code &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> </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-273"> <div class="examplenum"> <a href="#example-273">Example 273</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> <div class="example" id="example-274"> <div class="examplenum"> <a href="#example-274">Example 274</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </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-275"> <div class="examplenum"> <a href="#example-275">Example 275</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">-<span class="space"> </span>a -<span class="space"> </span>b -<span class="space"> </span>c </code></pre> </div> <div class="column"> <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> </div> <p>So is this, with a empty second item:</p> <div class="example" id="example-276"> <div class="examplenum"> <a href="#example-276">Example 276</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">*<span class="space"> </span>a * *<span class="space"> </span>c </code></pre> </div> <div class="column"> <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> </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-277"> <div class="examplenum"> <a href="#example-277">Example 277</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> <div class="example" id="example-278"> <div class="examplenum"> <a href="#example-278">Example 278</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>This is a tight list, because the blank lines are in a code block:</p> <div class="example" id="example-279"> <div class="examplenum"> <a href="#example-279">Example 279</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </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-280"> <div class="examplenum"> <a href="#example-280">Example 280</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>This is a tight list, because the blank line is inside the block quote:</p> <div class="example" id="example-281"> <div class="examplenum"> <a href="#example-281">Example 281</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>This list is tight, because the consecutive block elements are not separated by blank lines:</p> <div class="example" id="example-282"> <div class="examplenum"> <a href="#example-282">Example 282</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>A single-paragraph list is tight:</p> <div class="example" id="example-283"> <div class="examplenum"> <a href="#example-283">Example 283</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">-<span class="space"> </span>a </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;ul&gt; &lt;li&gt;a&lt;/li&gt; &lt;/ul&gt; </code></pre> </div> </div> <div class="example" id="example-284"> <div class="examplenum"> <a href="#example-284">Example 284</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </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-285"> <div class="examplenum"> <a href="#example-285">Example 285</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>Here the outer list is loose, the inner list tight:</p> <div class="example" id="example-286"> <div class="examplenum"> <a href="#example-286">Example 286</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> <div class="example" id="example-287"> <div class="examplenum"> <a href="#example-287">Example 287</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <h1 id="inlines" href="#inlines" class="definition"> <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-288"> <div class="examplenum"> <a href="#example-288">Example 288</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">`hi`lo` </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&lt;code&gt;hi&lt;/code&gt;lo`&lt;/p&gt; </code></pre> </div> </div> <p><code>hi</code> is parsed as code, leaving the backtick at the end as a literal backtick.</p> <h2 id="backslash-escapes" href="#backslash-escapes" class="definition"> <span class="number">6.1</span>Backslash escapes </h2> <p>Any ASCII punctuation character may be backslash-escaped:</p> <div class="example" id="example-289"> <div class="examplenum"> <a href="#example-289">Example 289</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">\!\&quot;\#\$\%\&amp;\'\(\)\*\+\,\-\.\/\:\;\&lt;\=\&gt;\?\@\[\\\]\^\_\`\{\|\}\~ </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;!&amp;quot;#$%&amp;amp;'()*+,-./:;&amp;lt;=&amp;gt;?@[\]^_`{|}~&lt;/p&gt; </code></pre> </div> </div> <p>Backslashes before other characters are treated as literal backslashes:</p> <div class="example" id="example-290"> <div class="examplenum"> <a href="#example-290">Example 290</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">\→\A\a\<span class="space"> </span>\3\φ\« </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;\→\A\a\<span class="space"> </span>\3\φ\«&lt;/p&gt; </code></pre> </div> </div> <p>Escaped characters are treated as regular characters and do not have their usual Markdown meanings:</p> <div class="example" id="example-291"> <div class="examplenum"> <a href="#example-291">Example 291</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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>heading \[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> </div> <div class="column"> <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>heading [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> </div> <p>If a backslash is itself escaped, the following character is not:</p> <div class="example" id="example-292"> <div class="examplenum"> <a href="#example-292">Example 292</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">\\*emphasis* </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;\&lt;em&gt;emphasis&lt;/em&gt;&lt;/p&gt; </code></pre> </div> </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-293"> <div class="examplenum"> <a href="#example-293">Example 293</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">foo\ bar </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;foo&lt;br<span class="space"> </span>/&gt; bar&lt;/p&gt; </code></pre> </div> </div> <p>Backslash escapes do not work in code blocks, code spans, autolinks, or raw HTML:</p> <div class="example" id="example-294"> <div class="examplenum"> <a href="#example-294">Example 294</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">``<span class="space"> </span>\[\`<span class="space"> </span>`` </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&lt;code&gt;\[\`&lt;/code&gt;&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-295"> <div class="examplenum"> <a href="#example-295">Example 295</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown"><span class="space"> </span><span class="space"> </span><span class="space"> </span><span class="space"> </span>\[\] </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;\[\] &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> </div> <div class="example" id="example-296"> <div class="examplenum"> <a href="#example-296">Example 296</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">~~~ \[\] ~~~ </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;pre&gt;&lt;code&gt;\[\] &lt;/code&gt;&lt;/pre&gt; </code></pre> </div> </div> <div class="example" id="example-297"> <div class="examplenum"> <a href="#example-297">Example 297</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;http://example.com?find=\*&gt; </code></pre> </div> <div class="column"> <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> <div class="example" id="example-298"> <div class="examplenum"> <a href="#example-298">Example 298</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;a<span class="space"> </span>href=&quot;/bar\/)&quot;&gt; </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;a<span class="space"> </span>href=&quot;/bar\/)&quot;&gt; </code></pre> </div> </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-299"> <div class="examplenum"> <a href="#example-299">Example 299</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[foo](/bar\*<span class="space"> </span>&quot;ti\*tle&quot;) </code></pre> </div> <div class="column"> <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> <div class="example" id="example-300"> <div class="examplenum"> <a href="#example-300">Example 300</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[foo] [foo]:<span class="space"> </span>/bar\*<span class="space"> </span>&quot;ti\*tle&quot; </code></pre> </div> <div class="column"> <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> <div class="example" id="example-301"> <div class="examplenum"> <a href="#example-301">Example 301</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">```<span class="space"> </span>foo\+bar foo ``` </code></pre> </div> <div class="column"> <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> </div> <h2 id="entity-and-numeric-character-references" href="#entity-and-numeric-character-references" class="definition"> <span class="number">6.2</span>Entity and numeric character references </h2> <p>All valid HTML entity references and numeric character references, except those occuring in code blocks and code spans, are recognized as such and treated as equivalent to the corresponding Unicode characters. Conforming CommonMark parsers need not store information about whether a particular character was represented in the source using a Unicode character or an entity reference.</p> <p><a id="entity-references" href="#entity-references" class="definition">Entity references</a> consist of <code>&amp;</code> + any of the valid HTML5 entity names + <code>;</code>. The document <a href="https://html.spec.whatwg.org/multipage/entities.json">https://html.spec.whatwg.org/multipage/entities.json</a> is used as an authoritative source for the valid entity references and their corresponding code points.</p> <div class="example" id="example-302"> <div class="examplenum"> <a href="#example-302">Example 302</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p><a id="decimal-numeric-character" href="#decimal-numeric-character" class="definition">Decimal numeric character</a> consist of <code>&amp;#</code> + a string of 1–8 arabic digits + <code>;</code>. A numeric character reference is parsed as the corresponding Unicode character. Invalid Unicode code points will be replaced by the REPLACEMENT 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-303"> <div class="examplenum"> <a href="#example-303">Example 303</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p><a id="hexadecimal-numeric-character" href="#hexadecimal-numeric-character" class="definition">Hexadecimal numeric character</a> consist of <code>&amp;#</code> + either <code>X</code> or <code>x</code> + a string of 1-8 hexadecimal digits + <code>;</code>. They too are parsed as the corresponding Unicode character (this time specified with a hexadecimal numeral instead of decimal).</p> <div class="example" id="example-304"> <div class="examplenum"> <a href="#example-304">Example 304</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&amp;#X22;<span class="space"> </span>&amp;#XD06;<span class="space"> </span>&amp;#xcab; </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&amp;quot;<span class="space"> </span>ആ<span class="space"> </span>ಫ&lt;/p&gt; </code></pre> </div> </div> <p>Here are some nonentities:</p> <div class="example" id="example-305"> <div class="examplenum"> <a href="#example-305">Example 305</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&amp;nbsp<span class="space"> </span>&amp;x;<span class="space"> </span>&amp;#;<span class="space"> </span>&amp;#x; &amp;ThisIsNotDefined;<span class="space"> </span>&amp;hi?; </code></pre> </div> <div class="column"> <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; &amp;amp;ThisIsNotDefined;<span class="space"> </span>&amp;amp;hi?;&lt;/p&gt; </code></pre> </div> </div> <p>Although HTML5 does accept some entity references without a trailing semicolon (such as <code>&amp;copy</code>), these are not recognized here, because it makes the grammar too ambiguous:</p> <div class="example" id="example-306"> <div class="examplenum"> <a href="#example-306">Example 306</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&amp;copy </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&amp;amp;copy&lt;/p&gt; </code></pre> </div> </div> <p>Strings that are not on the list of HTML5 named entities are not recognized as entity references either:</p> <div class="example" id="example-307"> <div class="examplenum"> <a href="#example-307">Example 307</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&amp;MadeUpEntity; </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&amp;amp;MadeUpEntity;&lt;/p&gt; </code></pre> </div> </div> <p>Entity and numeric character references are recognized in any context besides code spans or code blocks, including URLs, <a href="#link-title">link titles</a>, and <a href="#fenced-code-block">fenced code block</a> <a href="#info-string">info strings</a>:</p> <div class="example" id="example-308"> <div class="examplenum"> <a href="#example-308">Example 308</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;a<span class="space"> </span>href=&quot;&amp;ouml;&amp;ouml;.html&quot;&gt; </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;a<span class="space"> </span>href=&quot;&amp;ouml;&amp;ouml;.html&quot;&gt; </code></pre> </div> </div> <div class="example" id="example-309"> <div class="examplenum"> <a href="#example-309">Example 309</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[foo](/f&amp;ouml;&amp;ouml;<span class="space"> </span>&quot;f&amp;ouml;&amp;ouml;&quot;) </code></pre> </div> <div class="column"> <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> <div class="example" id="example-310"> <div class="examplenum"> <a href="#example-310">Example 310</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> <div class="example" id="example-311"> <div class="examplenum"> <a href="#example-311">Example 311</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">```<span class="space"> </span>f&amp;ouml;&amp;ouml; foo ``` </code></pre> </div> <div class="column"> <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> </div> <p>Entity and numeric character references are treated as literal text in code spans and code blocks:</p> <div class="example" id="example-312"> <div class="examplenum"> <a href="#example-312">Example 312</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">`f&amp;ouml;&amp;ouml;` </code></pre> </div> <div class="column"> <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> <div class="example" id="example-313"> <div class="examplenum"> <a href="#example-313">Example 313</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <h2 id="code-spans" href="#code-spans" class="definition"> <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-314"> <div class="examplenum"> <a href="#example-314">Example 314</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">`foo` </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&lt;code&gt;foo&lt;/code&gt;&lt;/p&gt; </code></pre> </div> </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-315"> <div class="examplenum"> <a href="#example-315">Example 315</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>This example shows the motivation for stripping leading and trailing spaces:</p> <div class="example" id="example-316"> <div class="examplenum"> <a href="#example-316">Example 316</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">`<span class="space"> </span>``<span class="space"> </span>` </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&lt;code&gt;``&lt;/code&gt;&lt;/p&gt; </code></pre> </div> </div> <p><a href="#line-ending">Line endings</a> are treated like spaces:</p> <div class="example" id="example-317"> <div class="examplenum"> <a href="#example-317">Example 317</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">`` foo `` </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&lt;code&gt;foo&lt;/code&gt;&lt;/p&gt; </code></pre> </div> </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-318"> <div class="examplenum"> <a href="#example-318">Example 318</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>Not all <a href="#unicode-whitespace">Unicode whitespace</a> (for instance, non-breaking space) is collapsed, however:</p> <div class="example" id="example-319"> <div class="examplenum"> <a href="#example-319">Example 319</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">`a  b` </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&lt;code&gt;a  b&lt;/code&gt;&lt;/p&gt; </code></pre> </div> </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-320"> <div class="examplenum"> <a href="#example-320">Example 320</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">`foo<span class="space"> </span>``<span class="space"> </span>bar` </code></pre> </div> <div class="column"> <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> </div> <p>Note that backslash escapes do not work in code spans. All backslashes are treated literally:</p> <div class="example" id="example-321"> <div class="examplenum"> <a href="#example-321">Example 321</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">`foo\`bar` </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&lt;code&gt;foo\&lt;/code&gt;bar`&lt;/p&gt; </code></pre> </div> </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-322"> <div class="examplenum"> <a href="#example-322">Example 322</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">*foo`*` </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;*foo&lt;code&gt;*&lt;/code&gt;&lt;/p&gt; </code></pre> </div> </div> <p>And this is not parsed as a link:</p> <div class="example" id="example-323"> <div class="examplenum"> <a href="#example-323">Example 323</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[not<span class="space"> </span>a<span class="space"> </span>`link](/foo`) </code></pre> </div> <div class="column"> <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> </div> <p>Code spans, HTML tags, and autolinks have the same precedence. Thus, this is code:</p> <div class="example" id="example-324"> <div class="examplenum"> <a href="#example-324">Example 324</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">`&lt;a<span class="space"> </span>href=&quot;`&quot;&gt;` </code></pre> </div> <div class="column"> <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> </div> <p>But this is an HTML tag:</p> <div class="example" id="example-325"> <div class="examplenum"> <a href="#example-325">Example 325</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;a<span class="space"> </span>href=&quot;`&quot;&gt;` </code></pre> </div> <div class="column"> <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> <p>And this is code:</p> <div class="example" id="example-326"> <div class="examplenum"> <a href="#example-326">Example 326</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">`&lt;http://foo.bar.`baz&gt;` </code></pre> </div> <div class="column"> <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> </div> <p>But this is an autolink:</p> <div class="example" id="example-327"> <div class="examplenum"> <a href="#example-327">Example 327</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;http://foo.bar.`baz&gt;` </code></pre> </div> <div class="column"> <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> </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-328"> <div class="examplenum"> <a href="#example-328">Example 328</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">```foo`` </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;```foo``&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-329"> <div class="examplenum"> <a href="#example-329">Example 329</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">`foo </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;`foo&lt;/p&gt; </code></pre> </div> </div> <p>The following case also illustrates the need for opening and closing backtick strings to be equal in length:</p> <div class="example" id="example-330"> <div class="examplenum"> <a href="#example-330">Example 330</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">`foo``bar`` </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;`foo&lt;code&gt;bar&lt;/code&gt;&lt;/p&gt; </code></pre> </div> </div> <h2 id="emphasis-and-strong-emphasis" href="#emphasis-and-strong-emphasis" class="definition"> <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 non-backslash-escaped <code>*</code> character, or a sequence of one or more <code>_</code> characters that is not preceded or followed by a non-backslash-escaped <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) 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) 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 <a href="#right-flanking-delimiter-run">right-flanking delimiter run</a> 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 <a href="#left-flanking-delimiter-run">left-flanking delimiter run</a> 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 <a href="#right-flanking-delimiter-run">right-flanking delimiter run</a> 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> 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 <a href="#left-flanking-delimiter-run">left-flanking delimiter run</a> 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. The opening and closing delimiters must belong to separate <a href="#delimiter-run">delimiter runs</a>. If one of the delimiters can both open and close emphasis, then the sum of the lengths of the delimiter runs containing the opening and closing delimiters must not be a multiple of 3.</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. The opening and closing delimiters must belong to separate <a href="#delimiter-run">delimiter runs</a>. If one of the delimiters can both open and close strong emphasis, then the sum of the lengths of the delimiter runs containing the opening and closing delimiters must not be a multiple of 3.</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;em&gt;&lt;strong&gt;...&lt;/strong&gt;&lt;/em&gt;</code> is always preferred to <code>&lt;strong&gt;&lt;em&gt;...&lt;/em&gt;&lt;/strong&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>.</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-331"> <div class="examplenum"> <a href="#example-331">Example 331</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">*foo<span class="space"> </span>bar* </code></pre> </div> <div class="column"> <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> </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-332"> <div class="examplenum"> <a href="#example-332">Example 332</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">a<span class="space"> </span>*<span class="space"> </span>foo<span class="space"> </span>bar* </code></pre> </div> <div class="column"> <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> </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-333"> <div class="examplenum"> <a href="#example-333">Example 333</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">a*&quot;foo&quot;* </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;a*&amp;quot;foo&amp;quot;*&lt;/p&gt; </code></pre> </div> </div> <p>Unicode nonbreaking spaces count as whitespace, too:</p> <div class="example" id="example-334"> <div class="examplenum"> <a href="#example-334">Example 334</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">* a * </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;* a *&lt;/p&gt; </code></pre> </div> </div> <p>Intraword emphasis with <code>*</code> is permitted:</p> <div class="example" id="example-335"> <div class="examplenum"> <a href="#example-335">Example 335</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">foo*bar* </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;foo&lt;em&gt;bar&lt;/em&gt;&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-336"> <div class="examplenum"> <a href="#example-336">Example 336</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">5*6*78 </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;5&lt;em&gt;6&lt;/em&gt;78&lt;/p&gt; </code></pre> </div> </div> <p>Rule 2:</p> <div class="example" id="example-337"> <div class="examplenum"> <a href="#example-337">Example 337</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">_foo<span class="space"> </span>bar_ </code></pre> </div> <div class="column"> <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> </div> <p>This is not emphasis, because the opening <code>_</code> is followed by whitespace:</p> <div class="example" id="example-338"> <div class="examplenum"> <a href="#example-338">Example 338</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">_<span class="space"> </span>foo<span class="space"> </span>bar_ </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;_<span class="space"> </span>foo<span class="space"> </span>bar_&lt;/p&gt; </code></pre> </div> </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-339"> <div class="examplenum"> <a href="#example-339">Example 339</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">a_&quot;foo&quot;_ </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;a_&amp;quot;foo&amp;quot;_&lt;/p&gt; </code></pre> </div> </div> <p>Emphasis with <code>_</code> is not allowed inside words:</p> <div class="example" id="example-340"> <div class="examplenum"> <a href="#example-340">Example 340</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">foo_bar_ </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;foo_bar_&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-341"> <div class="examplenum"> <a href="#example-341">Example 341</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">5_6_78 </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;5_6_78&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-342"> <div class="examplenum"> <a href="#example-342">Example 342</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">пристаням_стремятся_ </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;пристаням_стремятся_&lt;/p&gt; </code></pre> </div> </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-343"> <div class="examplenum"> <a href="#example-343">Example 343</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">aa_&quot;bb&quot;_cc </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;aa_&amp;quot;bb&amp;quot;_cc&lt;/p&gt; </code></pre> </div> </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-344"> <div class="examplenum"> <a href="#example-344">Example 344</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">foo-_(bar)_ </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;foo-&lt;em&gt;(bar)&lt;/em&gt;&lt;/p&gt; </code></pre> </div> </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-345"> <div class="examplenum"> <a href="#example-345">Example 345</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">_foo* </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;_foo*&lt;/p&gt; </code></pre> </div> </div> <p>This is not emphasis, because the closing <code>*</code> is preceded by whitespace:</p> <div class="example" id="example-346"> <div class="examplenum"> <a href="#example-346">Example 346</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">*foo<span class="space"> </span>bar<span class="space"> </span>* </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;*foo<span class="space"> </span>bar<span class="space"> </span>*&lt;/p&gt; </code></pre> </div> </div> <p>A newline also counts as whitespace:</p> <div class="example" id="example-347"> <div class="examplenum"> <a href="#example-347">Example 347</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">*foo<span class="space"> </span>bar * </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;*foo<span class="space"> </span>bar *&lt;/p&gt; </code></pre> </div> </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-348"> <div class="examplenum"> <a href="#example-348">Example 348</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">*(*foo) </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;*(*foo)&lt;/p&gt; </code></pre> </div> </div> <p>The point of this restriction is more easily appreciated with this example:</p> <div class="example" id="example-349"> <div class="examplenum"> <a href="#example-349">Example 349</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">*(*foo*)* </code></pre> </div> <div class="column"> <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> <p>Intraword emphasis with <code>*</code> is allowed:</p> <div class="example" id="example-350"> <div class="examplenum"> <a href="#example-350">Example 350</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">*foo*bar </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;foo&lt;/em&gt;bar&lt;/p&gt; </code></pre> </div> </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-351"> <div class="examplenum"> <a href="#example-351">Example 351</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">_foo<span class="space"> </span>bar<span class="space"> </span>_ </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;_foo<span class="space"> </span>bar<span class="space"> </span>_&lt;/p&gt; </code></pre> </div> </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-352"> <div class="examplenum"> <a href="#example-352">Example 352</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">_(_foo) </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;_(_foo)&lt;/p&gt; </code></pre> </div> </div> <p>This is emphasis within emphasis:</p> <div class="example" id="example-353"> <div class="examplenum"> <a href="#example-353">Example 353</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">_(_foo_)_ </code></pre> </div> <div class="column"> <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> <p>Intraword emphasis is disallowed for <code>_</code>:</p> <div class="example" id="example-354"> <div class="examplenum"> <a href="#example-354">Example 354</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">_foo_bar </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;_foo_bar&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-355"> <div class="examplenum"> <a href="#example-355">Example 355</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">_пристаням_стремятся </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;_пристаням_стремятся&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-356"> <div class="examplenum"> <a href="#example-356">Example 356</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">_foo_bar_baz_ </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;foo_bar_baz&lt;/em&gt;&lt;/p&gt; </code></pre> </div> </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-357"> <div class="examplenum"> <a href="#example-357">Example 357</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">_(bar)_. </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;(bar)&lt;/em&gt;.&lt;/p&gt; </code></pre> </div> </div> <p>Rule 5:</p> <div class="example" id="example-358"> <div class="examplenum"> <a href="#example-358">Example 358</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">**foo<span class="space"> </span>bar** </code></pre> </div> <div class="column"> <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> </div> <p>This is not strong emphasis, because the opening delimiter is followed by whitespace:</p> <div class="example" id="example-359"> <div class="examplenum"> <a href="#example-359">Example 359</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">**<span class="space"> </span>foo<span class="space"> </span>bar** </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;**<span class="space"> </span>foo<span class="space"> </span>bar**&lt;/p&gt; </code></pre> </div> </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-360"> <div class="examplenum"> <a href="#example-360">Example 360</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">a**&quot;foo&quot;** </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;a**&amp;quot;foo&amp;quot;**&lt;/p&gt; </code></pre> </div> </div> <p>Intraword strong emphasis with <code>**</code> is permitted:</p> <div class="example" id="example-361"> <div class="examplenum"> <a href="#example-361">Example 361</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">foo**bar** </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;foo&lt;strong&gt;bar&lt;/strong&gt;&lt;/p&gt; </code></pre> </div> </div> <p>Rule 6:</p> <div class="example" id="example-362"> <div class="examplenum"> <a href="#example-362">Example 362</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">__foo<span class="space"> </span>bar__ </code></pre> </div> <div class="column"> <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> </div> <p>This is not strong emphasis, because the opening delimiter is followed by whitespace:</p> <div class="example" id="example-363"> <div class="examplenum"> <a href="#example-363">Example 363</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">__<span class="space"> </span>foo<span class="space"> </span>bar__ </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;__<span class="space"> </span>foo<span class="space"> </span>bar__&lt;/p&gt; </code></pre> </div> </div> <p>A newline counts as whitespace:</p> <div class="example" id="example-364"> <div class="examplenum"> <a href="#example-364">Example 364</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">__ foo<span class="space"> </span>bar__ </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;__ foo<span class="space"> </span>bar__&lt;/p&gt; </code></pre> </div> </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-365"> <div class="examplenum"> <a href="#example-365">Example 365</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">a__&quot;foo&quot;__ </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;a__&amp;quot;foo&amp;quot;__&lt;/p&gt; </code></pre> </div> </div> <p>Intraword strong emphasis is forbidden with <code>__</code>:</p> <div class="example" id="example-366"> <div class="examplenum"> <a href="#example-366">Example 366</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">foo__bar__ </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;foo__bar__&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-367"> <div class="examplenum"> <a href="#example-367">Example 367</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">5__6__78 </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;5__6__78&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-368"> <div class="examplenum"> <a href="#example-368">Example 368</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">пристаням__стремятся__ </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;пристаням__стремятся__&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-369"> <div class="examplenum"> <a href="#example-369">Example 369</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">__foo,<span class="space"> </span>__bar__,<span class="space"> </span>baz__ </code></pre> </div> <div class="column"> <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> <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-370"> <div class="examplenum"> <a href="#example-370">Example 370</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">foo-__(bar)__ </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;foo-&lt;strong&gt;(bar)&lt;/strong&gt;&lt;/p&gt; </code></pre> </div> </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-371"> <div class="examplenum"> <a href="#example-371">Example 371</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">**foo<span class="space"> </span>bar<span class="space"> </span>** </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;**foo<span class="space"> </span>bar<span class="space"> </span>**&lt;/p&gt; </code></pre> </div> </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-372"> <div class="examplenum"> <a href="#example-372">Example 372</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">**(**foo) </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;**(**foo)&lt;/p&gt; </code></pre> </div> </div> <p>The point of this restriction is more easily appreciated with these examples:</p> <div class="example" id="example-373"> <div class="examplenum"> <a href="#example-373">Example 373</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">*(**foo**)* </code></pre> </div> <div class="column"> <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> <div class="example" id="example-374"> <div class="examplenum"> <a href="#example-374">Example 374</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> <div class="example" id="example-375"> <div class="examplenum"> <a href="#example-375">Example 375</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">**foo<span class="space"> </span>&quot;*bar*&quot;<span class="space"> </span>foo** </code></pre> </div> <div class="column"> <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> </div> <p>Intraword emphasis:</p> <div class="example" id="example-376"> <div class="examplenum"> <a href="#example-376">Example 376</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">**foo**bar </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&lt;strong&gt;foo&lt;/strong&gt;bar&lt;/p&gt; </code></pre> </div> </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-377"> <div class="examplenum"> <a href="#example-377">Example 377</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">__foo<span class="space"> </span>bar<span class="space"> </span>__ </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;__foo<span class="space"> </span>bar<span class="space"> </span>__&lt;/p&gt; </code></pre> </div> </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-378"> <div class="examplenum"> <a href="#example-378">Example 378</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">__(__foo) </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;__(__foo)&lt;/p&gt; </code></pre> </div> </div> <p>The point of this restriction is more easily appreciated with this example:</p> <div class="example" id="example-379"> <div class="examplenum"> <a href="#example-379">Example 379</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">_(__foo__)_ </code></pre> </div> <div class="column"> <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> <p>Intraword strong emphasis is forbidden with <code>__</code>:</p> <div class="example" id="example-380"> <div class="examplenum"> <a href="#example-380">Example 380</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">__foo__bar </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;__foo__bar&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-381"> <div class="examplenum"> <a href="#example-381">Example 381</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">__пристаням__стремятся </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;__пристаням__стремятся&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-382"> <div class="examplenum"> <a href="#example-382">Example 382</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">__foo__bar__baz__ </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&lt;strong&gt;foo__bar__baz&lt;/strong&gt;&lt;/p&gt; </code></pre> </div> </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-383"> <div class="examplenum"> <a href="#example-383">Example 383</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">__(bar)__. </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&lt;strong&gt;(bar)&lt;/strong&gt;.&lt;/p&gt; </code></pre> </div> </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-384"> <div class="examplenum"> <a href="#example-384">Example 384</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">*foo<span class="space"> </span>[bar](/url)* </code></pre> </div> <div class="column"> <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> <div class="example" id="example-385"> <div class="examplenum"> <a href="#example-385">Example 385</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">*foo bar* </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;foo bar&lt;/em&gt;&lt;/p&gt; </code></pre> </div> </div> <p>In particular, emphasis and strong emphasis can be nested inside emphasis:</p> <div class="example" id="example-386"> <div class="examplenum"> <a href="#example-386">Example 386</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">_foo<span class="space"> </span>__bar__<span class="space"> </span>baz_ </code></pre> </div> <div class="column"> <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> <div class="example" id="example-387"> <div class="examplenum"> <a href="#example-387">Example 387</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">_foo<span class="space"> </span>_bar_<span class="space"> </span>baz_ </code></pre> </div> <div class="column"> <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> <div class="example" id="example-388"> <div class="examplenum"> <a href="#example-388">Example 388</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">__foo_<span class="space"> </span>bar_ </code></pre> </div> <div class="column"> <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> <div class="example" id="example-389"> <div class="examplenum"> <a href="#example-389">Example 389</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">*foo<span class="space"> </span>*bar** </code></pre> </div> <div class="column"> <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> <div class="example" id="example-390"> <div class="examplenum"> <a href="#example-390">Example 390</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">*foo<span class="space"> </span>**bar**<span class="space"> </span>baz* </code></pre> </div> <div class="column"> <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> <div class="example" id="example-391"> <div class="examplenum"> <a href="#example-391">Example 391</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">*foo**bar**baz* </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;foo&lt;strong&gt;bar&lt;/strong&gt;baz&lt;/em&gt;&lt;/p&gt; </code></pre> </div> </div> <p>Note that in the preceding case, the interpretation</p> <pre><code class="language-markdown">&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> <p>is precluded by the condition that a delimiter that can both open and close (like the <code>*</code> after <code>foo</code>) cannot form emphasis if the sum of the lengths of the delimiter runs containing the opening and closing delimiters is a multiple of 3.</p> <p>The same condition ensures that the following cases are all strong emphasis nested inside emphasis, even when the interior spaces are omitted:</p> <div class="example" id="example-392"> <div class="examplenum"> <a href="#example-392">Example 392</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">***foo**<span class="space"> </span>bar* </code></pre> </div> <div class="column"> <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> <div class="example" id="example-393"> <div class="examplenum"> <a href="#example-393">Example 393</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">*foo<span class="space"> </span>**bar*** </code></pre> </div> <div class="column"> <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> </div> <div class="example" id="example-394"> <div class="examplenum"> <a href="#example-394">Example 394</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">*foo**bar*** </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;foo&lt;strong&gt;bar&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt; </code></pre> </div> </div> <p>Indefinite levels of nesting are possible:</p> <div class="example" id="example-395"> <div class="examplenum"> <a href="#example-395">Example 395</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> <div class="example" id="example-396"> <div class="examplenum"> <a href="#example-396">Example 396</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">*foo<span class="space"> </span>[*bar*](/url)* </code></pre> </div> <div class="column"> <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> </div> <p>There can be no empty emphasis or strong emphasis:</p> <div class="example" id="example-397"> <div class="examplenum"> <a href="#example-397">Example 397</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> <div class="example" id="example-398"> <div class="examplenum"> <a href="#example-398">Example 398</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </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-399"> <div class="examplenum"> <a href="#example-399">Example 399</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">**foo<span class="space"> </span>[bar](/url)** </code></pre> </div> <div class="column"> <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> <div class="example" id="example-400"> <div class="examplenum"> <a href="#example-400">Example 400</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">**foo bar** </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&lt;strong&gt;foo bar&lt;/strong&gt;&lt;/p&gt; </code></pre> </div> </div> <p>In particular, emphasis and strong emphasis can be nested inside strong emphasis:</p> <div class="example" id="example-401"> <div class="examplenum"> <a href="#example-401">Example 401</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">__foo<span class="space"> </span>_bar_<span class="space"> </span>baz__ </code></pre> </div> <div class="column"> <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> <div class="example" id="example-402"> <div class="examplenum"> <a href="#example-402">Example 402</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">__foo<span class="space"> </span>__bar__<span class="space"> </span>baz__ </code></pre> </div> <div class="column"> <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> <div class="example" id="example-403"> <div class="examplenum"> <a href="#example-403">Example 403</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">____foo__<span class="space"> </span>bar__ </code></pre> </div> <div class="column"> <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> <div class="example" id="example-404"> <div class="examplenum"> <a href="#example-404">Example 404</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">**foo<span class="space"> </span>**bar**** </code></pre> </div> <div class="column"> <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> <div class="example" id="example-405"> <div class="examplenum"> <a href="#example-405">Example 405</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">**foo<span class="space"> </span>*bar*<span class="space"> </span>baz** </code></pre> </div> <div class="column"> <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> <div class="example" id="example-406"> <div class="examplenum"> <a href="#example-406">Example 406</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">**foo*bar*baz** </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&lt;strong&gt;foo&lt;em&gt;bar&lt;/em&gt;baz&lt;/strong&gt;&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-407"> <div class="examplenum"> <a href="#example-407">Example 407</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">***foo*<span class="space"> </span>bar** </code></pre> </div> <div class="column"> <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> <div class="example" id="example-408"> <div class="examplenum"> <a href="#example-408">Example 408</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">**foo<span class="space"> </span>*bar*** </code></pre> </div> <div class="column"> <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> </div> <p>Indefinite levels of nesting are possible:</p> <div class="example" id="example-409"> <div class="examplenum"> <a href="#example-409">Example 409</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">**foo<span class="space"> </span>*bar<span class="space"> </span>**baz** bim*<span class="space"> </span>bop** </code></pre> </div> <div class="column"> <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> <div class="example" id="example-410"> <div class="examplenum"> <a href="#example-410">Example 410</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">**foo<span class="space"> </span>[*bar*](/url)** </code></pre> </div> <div class="column"> <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> </div> <p>There can be no empty emphasis or strong emphasis:</p> <div class="example" id="example-411"> <div class="examplenum"> <a href="#example-411">Example 411</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> <div class="example" id="example-412"> <div class="examplenum"> <a href="#example-412">Example 412</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>Rule 11:</p> <div class="example" id="example-413"> <div class="examplenum"> <a href="#example-413">Example 413</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">foo<span class="space"> </span>*** </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;foo<span class="space"> </span>***&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-414"> <div class="examplenum"> <a href="#example-414">Example 414</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">foo<span class="space"> </span>*\** </code></pre> </div> <div class="column"> <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> <div class="example" id="example-415"> <div class="examplenum"> <a href="#example-415">Example 415</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">foo<span class="space"> </span>*_* </code></pre> </div> <div class="column"> <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> <div class="example" id="example-416"> <div class="examplenum"> <a href="#example-416">Example 416</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">foo<span class="space"> </span>***** </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;foo<span class="space"> </span>*****&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-417"> <div class="examplenum"> <a href="#example-417">Example 417</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">foo<span class="space"> </span>**\*** </code></pre> </div> <div class="column"> <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> <div class="example" id="example-418"> <div class="examplenum"> <a href="#example-418">Example 418</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">foo<span class="space"> </span>**_** </code></pre> </div> <div class="column"> <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> <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-419"> <div class="examplenum"> <a href="#example-419">Example 419</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">**foo* </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;*&lt;em&gt;foo&lt;/em&gt;&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-420"> <div class="examplenum"> <a href="#example-420">Example 420</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">*foo** </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;foo&lt;/em&gt;*&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-421"> <div class="examplenum"> <a href="#example-421">Example 421</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">***foo** </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;*&lt;strong&gt;foo&lt;/strong&gt;&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-422"> <div class="examplenum"> <a href="#example-422">Example 422</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">****foo* </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;***&lt;em&gt;foo&lt;/em&gt;&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-423"> <div class="examplenum"> <a href="#example-423">Example 423</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">**foo*** </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&lt;strong&gt;foo&lt;/strong&gt;*&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-424"> <div class="examplenum"> <a href="#example-424">Example 424</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">*foo**** </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;foo&lt;/em&gt;***&lt;/p&gt; </code></pre> </div> </div> <p>Rule 12:</p> <div class="example" id="example-425"> <div class="examplenum"> <a href="#example-425">Example 425</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">foo<span class="space"> </span>___ </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;foo<span class="space"> </span>___&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-426"> <div class="examplenum"> <a href="#example-426">Example 426</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">foo<span class="space"> </span>_\__ </code></pre> </div> <div class="column"> <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> <div class="example" id="example-427"> <div class="examplenum"> <a href="#example-427">Example 427</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">foo<span class="space"> </span>_*_ </code></pre> </div> <div class="column"> <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> <div class="example" id="example-428"> <div class="examplenum"> <a href="#example-428">Example 428</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">foo<span class="space"> </span>_____ </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;foo<span class="space"> </span>_____&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-429"> <div class="examplenum"> <a href="#example-429">Example 429</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">foo<span class="space"> </span>__\___ </code></pre> </div> <div class="column"> <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> <div class="example" id="example-430"> <div class="examplenum"> <a href="#example-430">Example 430</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">foo<span class="space"> </span>__*__ </code></pre> </div> <div class="column"> <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> <div class="example" id="example-431"> <div class="examplenum"> <a href="#example-431">Example 431</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">__foo_ </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;_&lt;em&gt;foo&lt;/em&gt;&lt;/p&gt; </code></pre> </div> </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-432"> <div class="examplenum"> <a href="#example-432">Example 432</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">_foo__ </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;foo&lt;/em&gt;_&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-433"> <div class="examplenum"> <a href="#example-433">Example 433</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">___foo__ </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;_&lt;strong&gt;foo&lt;/strong&gt;&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-434"> <div class="examplenum"> <a href="#example-434">Example 434</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">____foo_ </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;___&lt;em&gt;foo&lt;/em&gt;&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-435"> <div class="examplenum"> <a href="#example-435">Example 435</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">__foo___ </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&lt;strong&gt;foo&lt;/strong&gt;_&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-436"> <div class="examplenum"> <a href="#example-436">Example 436</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">_foo____ </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;foo&lt;/em&gt;___&lt;/p&gt; </code></pre> </div> </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-437"> <div class="examplenum"> <a href="#example-437">Example 437</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">**foo** </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&lt;strong&gt;foo&lt;/strong&gt;&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-438"> <div class="examplenum"> <a href="#example-438">Example 438</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">*_foo_* </code></pre> </div> <div class="column"> <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> <div class="example" id="example-439"> <div class="examplenum"> <a href="#example-439">Example 439</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">__foo__ </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&lt;strong&gt;foo&lt;/strong&gt;&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-440"> <div class="examplenum"> <a href="#example-440">Example 440</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">_*foo*_ </code></pre> </div> <div class="column"> <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> <p>However, strong emphasis within strong emphasis is possible without switching delimiters:</p> <div class="example" id="example-441"> <div class="examplenum"> <a href="#example-441">Example 441</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">****foo**** </code></pre> </div> <div class="column"> <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> <div class="example" id="example-442"> <div class="examplenum"> <a href="#example-442">Example 442</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">____foo____ </code></pre> </div> <div class="column"> <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> <p>Rule 13 can be applied to arbitrarily long sequences of delimiters:</p> <div class="example" id="example-443"> <div class="examplenum"> <a href="#example-443">Example 443</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">******foo****** </code></pre> </div> <div class="column"> <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> </div> <p>Rule 14:</p> <div class="example" id="example-444"> <div class="examplenum"> <a href="#example-444">Example 444</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">***foo*** </code></pre> </div> <div class="column"> <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> <div class="example" id="example-445"> <div class="examplenum"> <a href="#example-445">Example 445</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">_____foo_____ </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&lt;em&gt;&lt;strong&gt;&lt;strong&gt;foo&lt;/strong&gt;&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt; </code></pre> </div> </div> <p>Rule 15:</p> <div class="example" id="example-446"> <div class="examplenum"> <a href="#example-446">Example 446</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">*foo<span class="space"> </span>_bar*<span class="space"> </span>baz_ </code></pre> </div> <div class="column"> <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> <div class="example" id="example-447"> <div class="examplenum"> <a href="#example-447">Example 447</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>Rule 16:</p> <div class="example" id="example-448"> <div class="examplenum"> <a href="#example-448">Example 448</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">**foo<span class="space"> </span>**bar<span class="space"> </span>baz** </code></pre> </div> <div class="column"> <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> <div class="example" id="example-449"> <div class="examplenum"> <a href="#example-449">Example 449</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">*foo<span class="space"> </span>*bar<span class="space"> </span>baz* </code></pre> </div> <div class="column"> <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> </div> <p>Rule 17:</p> <div class="example" id="example-450"> <div class="examplenum"> <a href="#example-450">Example 450</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">*[bar*](/url) </code></pre> </div> <div class="column"> <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> <div class="example" id="example-451"> <div class="examplenum"> <a href="#example-451">Example 451</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">_foo<span class="space"> </span>[bar_](/url) </code></pre> </div> <div class="column"> <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> <div class="example" id="example-452"> <div class="examplenum"> <a href="#example-452">Example 452</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> <div class="example" id="example-453"> <div class="examplenum"> <a href="#example-453">Example 453</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">**&lt;a<span class="space"> </span>href=&quot;**&quot;&gt; </code></pre> </div> <div class="column"> <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> <div class="example" id="example-454"> <div class="examplenum"> <a href="#example-454">Example 454</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">__&lt;a<span class="space"> </span>href=&quot;__&quot;&gt; </code></pre> </div> <div class="column"> <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> <div class="example" id="example-455"> <div class="examplenum"> <a href="#example-455">Example 455</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">*a<span class="space"> </span>`*`* </code></pre> </div> <div class="column"> <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> <div class="example" id="example-456"> <div class="examplenum"> <a href="#example-456">Example 456</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">_a<span class="space"> </span>`_`_ </code></pre> </div> <div class="column"> <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> <div class="example" id="example-457"> <div class="examplenum"> <a href="#example-457">Example 457</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">**a&lt;http://foo.bar/?q=**&gt; </code></pre> </div> <div class="column"> <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> <div class="example" id="example-458"> <div class="examplenum"> <a href="#example-458">Example 458</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">__a&lt;http://foo.bar/?q=__&gt; </code></pre> </div> <div class="column"> <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> <h2 id="links" href="#links" class="definition"> <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="#autolinks">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 spaces, 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. (Implementations may impose limits on parentheses nesting to avoid performance issues, but at least three levels of nesting should be supported.)</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-459"> <div class="examplenum"> <a href="#example-459">Example 459</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[link](/uri<span class="space"> </span>&quot;title&quot;) </code></pre> </div> <div class="column"> <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> </div> <p>The title may be omitted:</p> <div class="example" id="example-460"> <div class="examplenum"> <a href="#example-460">Example 460</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[link](/uri) </code></pre> </div> <div class="column"> <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> </div> <p>Both the title and the destination may be omitted:</p> <div class="example" id="example-461"> <div class="examplenum"> <a href="#example-461">Example 461</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[link]() </code></pre> </div> <div class="column"> <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> <div class="example" id="example-462"> <div class="examplenum"> <a href="#example-462">Example 462</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[link](&lt;&gt;) </code></pre> </div> <div class="column"> <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> <p>The destination cannot contain spaces or line breaks, even if enclosed in pointy brackets:</p> <div class="example" id="example-463"> <div class="examplenum"> <a href="#example-463">Example 463</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[link](/my<span class="space"> </span>uri) </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;[link](/my<span class="space"> </span>uri)&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-464"> <div class="examplenum"> <a href="#example-464">Example 464</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[link](&lt;/my<span class="space"> </span>uri&gt;) </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;[link](&amp;lt;/my<span class="space"> </span>uri&amp;gt;)&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-465"> <div class="examplenum"> <a href="#example-465">Example 465</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[link](foo bar) </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;[link](foo bar)&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-466"> <div class="examplenum"> <a href="#example-466">Example 466</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[link](&lt;foo bar&gt;) </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;[link](&lt;foo bar&gt;)&lt;/p&gt; </code></pre> </div> </div> <p>Parentheses inside the link destination may be escaped:</p> <div class="example" id="example-467"> <div class="examplenum"> <a href="#example-467">Example 467</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[link](\(foo\)) </code></pre> </div> <div class="column"> <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> </div> <p>Any number of parentheses are allowed without escaping, as long as they are balanced:</p> <div class="example" id="example-468"> <div class="examplenum"> <a href="#example-468">Example 468</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[link](foo(and(bar))) </code></pre> </div> <div class="column"> <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> <p>However, if you have unbalanced parentheses, you need to escape or use the <code>&lt;...&gt;</code> form:</p> <div class="example" id="example-469"> <div class="examplenum"> <a href="#example-469">Example 469</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[link](foo\(and\(bar\)) </code></pre> </div> <div class="column"> <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> <div class="example" id="example-470"> <div class="examplenum"> <a href="#example-470">Example 470</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[link](&lt;foo(and(bar)&gt;) </code></pre> </div> <div class="column"> <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> <p>Parentheses and other symbols can also be escaped, as usual in Markdown:</p> <div class="example" id="example-471"> <div class="examplenum"> <a href="#example-471">Example 471</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[link](foo\)\:) </code></pre> </div> <div class="column"> <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> </div> <p>A link can contain fragment identifiers and queries:</p> <div class="example" id="example-472"> <div class="examplenum"> <a href="#example-472">Example 472</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[link](#fragment) [link](http://example.com#fragment) [link](http://example.com?foo=3#frag) </code></pre> </div> <div class="column"> <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=3#frag&quot;&gt;link&lt;/a&gt;&lt;/p&gt; </code></pre> </div> </div> <p>Note that a backslash before a non-escapable character is just a backslash:</p> <div class="example" id="example-473"> <div class="examplenum"> <a href="#example-473">Example 473</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[link](foo\bar) </code></pre> </div> <div class="column"> <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> </div> <p>URL-escaping should be left alone inside the destination, as all URL-escaped characters are also valid URL characters. Entity and numerical character references in the destination will be parsed into the corresponding Unicode code points, as usual. These may be optionally URL-escaped when written as HTML, but this spec does not enforce any particular policy for rendering URLs in HTML or other formats. Renderers may make different decisions about how to escape or normalize URLs in the output.</p> <div class="example" id="example-474"> <div class="examplenum"> <a href="#example-474">Example 474</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[link](foo%20b&amp;auml;) </code></pre> </div> <div class="column"> <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> </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-475"> <div class="examplenum"> <a href="#example-475">Example 475</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[link](&quot;title&quot;) </code></pre> </div> <div class="column"> <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> </div> <p>Titles may be in single quotes, double quotes, or parentheses:</p> <div class="example" id="example-476"> <div class="examplenum"> <a href="#example-476">Example 476</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>Backslash escapes and entity and numeric character references may be used in titles:</p> <div class="example" id="example-477"> <div class="examplenum"> <a href="#example-477">Example 477</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[link](/url<span class="space"> </span>&quot;title<span class="space"> </span>\&quot;&amp;quot;&quot;) </code></pre> </div> <div class="column"> <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> </div> <p>Titles must be separated from the link using a <a href="#whitespace">whitespace</a>. Other <a href="#unicode-whitespace">Unicode whitespace</a> like non-breaking space doesn’t work.</p> <div class="example" id="example-478"> <div class="examplenum"> <a href="#example-478">Example 478</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[link](/url &quot;title&quot;) </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/url%C2%A0%22title%22&quot;&gt;link&lt;/a&gt;&lt;/p&gt; </code></pre> </div> </div> <p>Nested balanced quotes are not allowed without escaping:</p> <div class="example" id="example-479"> <div class="examplenum"> <a href="#example-479">Example 479</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>But it is easy to work around this by using a different quote type:</p> <div class="example" id="example-480"> <div class="examplenum"> <a href="#example-480">Example 480</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </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, entity and numeric character references, 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-481"> <div class="examplenum"> <a href="#example-481">Example 481</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>But it is not allowed between the link text and the following parenthesis:</p> <div class="example" id="example-482"> <div class="examplenum"> <a href="#example-482">Example 482</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[link]<span class="space"> </span>(/uri) </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;[link]<span class="space"> </span>(/uri)&lt;/p&gt; </code></pre> </div> </div> <p>The link text may contain balanced brackets, but not unbalanced ones, unless they are escaped:</p> <div class="example" id="example-483"> <div class="examplenum"> <a href="#example-483">Example 483</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[link<span class="space"> </span>[foo<span class="space"> </span>[bar]]](/uri) </code></pre> </div> <div class="column"> <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> <div class="example" id="example-484"> <div class="examplenum"> <a href="#example-484">Example 484</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[link]<span class="space"> </span>bar](/uri) </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;[link]<span class="space"> </span>bar](/uri)&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-485"> <div class="examplenum"> <a href="#example-485">Example 485</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[link<span class="space"> </span>[bar](/uri) </code></pre> </div> <div class="column"> <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> <div class="example" id="example-486"> <div class="examplenum"> <a href="#example-486">Example 486</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[link<span class="space"> </span>\[bar](/uri) </code></pre> </div> <div class="column"> <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> </div> <p>The link text may contain inline content:</p> <div class="example" id="example-487"> <div class="examplenum"> <a href="#example-487">Example 487</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[link<span class="space"> </span>*foo<span class="space"> </span>**bar**<span class="space"> </span>`#`*](/uri) </code></pre> </div> <div class="column"> <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> <div class="example" id="example-488"> <div class="examplenum"> <a href="#example-488">Example 488</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[![moon](moon.jpg)](/uri) </code></pre> </div> <div class="column"> <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> </div> <p>However, links may not contain other links, at any level of nesting.</p> <div class="example" id="example-489"> <div class="examplenum"> <a href="#example-489">Example 489</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[foo<span class="space"> </span>[bar](/uri)](/uri) </code></pre> </div> <div class="column"> <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> <div class="example" id="example-490"> <div class="examplenum"> <a href="#example-490">Example 490</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[foo<span class="space"> </span>*[bar<span class="space"> </span>[baz](/uri)](/uri)*](/uri) </code></pre> </div> <div class="column"> <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> <div class="example" id="example-491"> <div class="examplenum"> <a href="#example-491">Example 491</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">![[[foo](uri1)](uri2)](uri3) </code></pre> </div> <div class="column"> <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> </div> <p>These cases illustrate the precedence of link text grouping over emphasis grouping:</p> <div class="example" id="example-492"> <div class="examplenum"> <a href="#example-492">Example 492</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">*[foo*](/uri) </code></pre> </div> <div class="column"> <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> <div class="example" id="example-493"> <div class="examplenum"> <a href="#example-493">Example 493</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[foo<span class="space"> </span>*bar](baz*) </code></pre> </div> <div class="column"> <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> </div> <p>Note that brackets that <em>aren’t</em> part of links do not take precedence:</p> <div class="example" id="example-494"> <div class="examplenum"> <a href="#example-494">Example 494</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">*foo<span class="space"> </span>[bar*<span class="space"> </span>baz] </code></pre> </div> <div class="column"> <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> <p>These cases illustrate the precedence of HTML tags, code spans, and autolinks over link grouping:</p> <div class="example" id="example-495"> <div class="examplenum"> <a href="#example-495">Example 495</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[foo<span class="space"> </span>&lt;bar<span class="space"> </span>attr=&quot;](baz)&quot;&gt; </code></pre> </div> <div class="column"> <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> <div class="example" id="example-496"> <div class="examplenum"> <a href="#example-496">Example 496</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[foo`](/uri)` </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;[foo&lt;code&gt;](/uri)&lt;/code&gt;&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-497"> <div class="examplenum"> <a href="#example-497">Example 497</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[foo&lt;http://example.com/?search=](uri)&gt; </code></pre> </div> <div class="column"> <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> </div> <p>There are three kinds of <a id="reference-link" href="#reference-link" class="definition">reference link</a>s: <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> immediately followed by 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 inside the opening and closing square brackets of <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, strip off the opening and closing brackets, perform the <em>Unicode case fold</em>, strip leading and trailing <a href="#whitespace">whitespace</a> 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-498"> <div class="examplenum"> <a href="#example-498">Example 498</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[foo][bar] [bar]:<span class="space"> </span>/url<span class="space"> </span>&quot;title&quot; </code></pre> </div> <div class="column"> <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> <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-499"> <div class="examplenum"> <a href="#example-499">Example 499</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> <div class="example" id="example-500"> <div class="examplenum"> <a href="#example-500">Example 500</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[link<span class="space"> </span>\[bar][ref] [ref]:<span class="space"> </span>/uri </code></pre> </div> <div class="column"> <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> </div> <p>The link text may contain inline content:</p> <div class="example" id="example-501"> <div class="examplenum"> <a href="#example-501">Example 501</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> <div class="example" id="example-502"> <div class="examplenum"> <a href="#example-502">Example 502</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[![moon](moon.jpg)][ref] [ref]:<span class="space"> </span>/uri </code></pre> </div> <div class="column"> <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> </div> <p>However, links may not contain other links, at any level of nesting.</p> <div class="example" id="example-503"> <div class="examplenum"> <a href="#example-503">Example 503</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[foo<span class="space"> </span>[bar](/uri)][ref] [ref]:<span class="space"> </span>/uri </code></pre> </div> <div class="column"> <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> <div class="example" id="example-504"> <div class="examplenum"> <a href="#example-504">Example 504</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </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-505"> <div class="examplenum"> <a href="#example-505">Example 505</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">*[foo*][ref] [ref]:<span class="space"> </span>/uri </code></pre> </div> <div class="column"> <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> <div class="example" id="example-506"> <div class="examplenum"> <a href="#example-506">Example 506</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[foo<span class="space"> </span>*bar][ref] [ref]:<span class="space"> </span>/uri </code></pre> </div> <div class="column"> <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> </div> <p>These cases illustrate the precedence of HTML tags, code spans, and autolinks over link grouping:</p> <div class="example" id="example-507"> <div class="examplenum"> <a href="#example-507">Example 507</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> <div class="example" id="example-508"> <div class="examplenum"> <a href="#example-508">Example 508</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[foo`][ref]` [ref]:<span class="space"> </span>/uri </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;[foo&lt;code&gt;][ref]&lt;/code&gt;&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-509"> <div class="examplenum"> <a href="#example-509">Example 509</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[foo&lt;http://example.com/?search=][ref]&gt; [ref]:<span class="space"> </span>/uri </code></pre> </div> <div class="column"> <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> </div> <p>Matching is case-insensitive:</p> <div class="example" id="example-510"> <div class="examplenum"> <a href="#example-510">Example 510</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[foo][BaR] [bar]:<span class="space"> </span>/url<span class="space"> </span>&quot;title&quot; </code></pre> </div> <div class="column"> <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> <p>Unicode case fold is used:</p> <div class="example" id="example-511"> <div class="examplenum"> <a href="#example-511">Example 511</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </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-512"> <div class="examplenum"> <a href="#example-512">Example 512</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>No <a href="#whitespace">whitespace</a> is allowed between the <a href="#link-text">link text</a> and the <a href="#link-label">link label</a>:</p> <div class="example" id="example-513"> <div class="examplenum"> <a href="#example-513">Example 513</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;[foo]<span class="space"> </span>&lt;a<span class="space"> </span>href=&quot;/url&quot;<span class="space"> </span>title=&quot;title&quot;&gt;bar&lt;/a&gt;&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-514"> <div class="examplenum"> <a href="#example-514">Example 514</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[foo] [bar] [bar]:<span class="space"> </span>/url<span class="space"> </span>&quot;title&quot; </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;[foo] &lt;a<span class="space"> </span>href=&quot;/url&quot;<span class="space"> </span>title=&quot;title&quot;&gt;bar&lt;/a&gt;&lt;/p&gt; </code></pre> </div> </div> <p>This is a departure from John Gruber’s original Markdown syntax description, which explicitly allows whitespace between the link text and the link label. It brings reference links in line with <a href="#inline-link">inline links</a>, which (according to both original Markdown and this spec) cannot have whitespace after the link text. More importantly, it prevents inadvertent capture of consecutive <a href="#shortcut-reference-link">shortcut reference links</a>. If whitespace is allowed between the link text and the link label, then in the following we will have a single reference link, not two shortcut reference links, as intended:</p> <pre><code class="language-markdown">[foo] [bar] [foo]: /url1 [bar]: /url2 </code></pre> <p>(Note that <a href="#shortcut-reference-link">shortcut reference links</a> were introduced by Gruber himself in a beta version of <code>Markdown.pl</code>, but never included in the official syntax description. Without shortcut reference links, it is harmless to allow space between the link text and link label; but once shortcut references are introduced, it is too dangerous to allow this, as it frequently leads to unintended results.)</p> <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-515"> <div class="examplenum"> <a href="#example-515">Example 515</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[foo]:<span class="space"> </span>/url1 [foo]:<span class="space"> </span>/url2 [bar][foo] </code></pre> </div> <div class="column"> <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> </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-516"> <div class="examplenum"> <a href="#example-516">Example 516</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[bar][foo\!] [foo!]:<span class="space"> </span>/url </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;[bar][foo!]&lt;/p&gt; </code></pre> </div> </div> <p><a href="#link-label">Link labels</a> cannot contain brackets, unless they are backslash-escaped:</p> <div class="example" id="example-517"> <div class="examplenum"> <a href="#example-517">Example 517</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[foo][ref[] [ref[]:<span class="space"> </span>/uri </code></pre> </div> <div class="column"> <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> <div class="example" id="example-518"> <div class="examplenum"> <a href="#example-518">Example 518</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[foo][ref[bar]] [ref[bar]]:<span class="space"> </span>/uri </code></pre> </div> <div class="column"> <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> <div class="example" id="example-519"> <div class="examplenum"> <a href="#example-519">Example 519</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[[[foo]]] [[[foo]]]:<span class="space"> </span>/url </code></pre> </div> <div class="column"> <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> <div class="example" id="example-520"> <div class="examplenum"> <a href="#example-520">Example 520</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[foo][ref\[] [ref\[]:<span class="space"> </span>/uri </code></pre> </div> <div class="column"> <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> <p>Note that in this example <code>]</code> is not backslash-escaped:</p> <div class="example" id="example-521"> <div class="examplenum"> <a href="#example-521">Example 521</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[bar\\]:<span class="space"> </span>/uri [bar\\] </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/uri&quot;&gt;bar\&lt;/a&gt;&lt;/p&gt; </code></pre> </div> </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-522"> <div class="examplenum"> <a href="#example-522">Example 522</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[] []:<span class="space"> </span>/uri </code></pre> </div> <div class="column"> <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> <div class="example" id="example-523"> <div class="examplenum"> <a href="#example-523">Example 523</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[ <span class="space"> </span>] [ <span class="space"> </span>]:<span class="space"> </span>/uri </code></pre> </div> <div class="column"> <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> <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, followed by 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-524"> <div class="examplenum"> <a href="#example-524">Example 524</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[foo][] [foo]:<span class="space"> </span>/url<span class="space"> </span>&quot;title&quot; </code></pre> </div> <div class="column"> <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> <div class="example" id="example-525"> <div class="examplenum"> <a href="#example-525">Example 525</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> <p>The link labels are case-insensitive:</p> <div class="example" id="example-526"> <div class="examplenum"> <a href="#example-526">Example 526</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[Foo][] [foo]:<span class="space"> </span>/url<span class="space"> </span>&quot;title&quot; </code></pre> </div> <div class="column"> <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> <p>As with full reference links, <a href="#whitespace">whitespace</a> is not allowed between the two sets of brackets:</p> <div class="example" id="example-527"> <div class="examplenum"> <a href="#example-527">Example 527</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> <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-528"> <div class="examplenum"> <a href="#example-528">Example 528</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[foo] [foo]:<span class="space"> </span>/url<span class="space"> </span>&quot;title&quot; </code></pre> </div> <div class="column"> <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> <div class="example" id="example-529"> <div class="examplenum"> <a href="#example-529">Example 529</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> <div class="example" id="example-530"> <div class="examplenum"> <a href="#example-530">Example 530</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> <div class="example" id="example-531"> <div class="examplenum"> <a href="#example-531">Example 531</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[[bar<span class="space"> </span>[foo] [foo]:<span class="space"> </span>/url </code></pre> </div> <div class="column"> <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> </div> <p>The link labels are case-insensitive:</p> <div class="example" id="example-532"> <div class="examplenum"> <a href="#example-532">Example 532</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[Foo] [foo]:<span class="space"> </span>/url<span class="space"> </span>&quot;title&quot; </code></pre> </div> <div class="column"> <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> <p>A space after the link text should be preserved:</p> <div class="example" id="example-533"> <div class="examplenum"> <a href="#example-533">Example 533</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[foo]<span class="space"> </span>bar [foo]:<span class="space"> </span>/url </code></pre> </div> <div class="column"> <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> </div> <p>If you just want bracketed text, you can backslash-escape the opening bracket to avoid links:</p> <div class="example" id="example-534"> <div class="examplenum"> <a href="#example-534">Example 534</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">\[foo] [foo]:<span class="space"> </span>/url<span class="space"> </span>&quot;title&quot; </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;[foo]&lt;/p&gt; </code></pre> </div> </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-535"> <div class="examplenum"> <a href="#example-535">Example 535</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[foo*]:<span class="space"> </span>/url *[foo*] </code></pre> </div> <div class="column"> <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> <p>Full and compact references take precedence over shortcut references:</p> <div class="example" id="example-536"> <div class="examplenum"> <a href="#example-536">Example 536</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[foo][bar] [foo]:<span class="space"> </span>/url1 [bar]:<span class="space"> </span>/url2 </code></pre> </div> <div class="column"> <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> </div> <div class="example" id="example-537"> <div class="examplenum"> <a href="#example-537">Example 537</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[foo][] [foo]:<span class="space"> </span>/url1 </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/url1&quot;&gt;foo&lt;/a&gt;&lt;/p&gt; </code></pre> </div> </div> <p>Inline links also take precedence:</p> <div class="example" id="example-538"> <div class="examplenum"> <a href="#example-538">Example 538</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[foo]() [foo]:<span class="space"> </span>/url1 </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;&quot;&gt;foo&lt;/a&gt;&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-539"> <div class="examplenum"> <a href="#example-539">Example 539</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[foo](not<span class="space"> </span>a<span class="space"> </span>link) [foo]:<span class="space"> </span>/url1 </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;/url1&quot;&gt;foo&lt;/a&gt;(not<span class="space"> </span>a<span class="space"> </span>link)&lt;/p&gt; </code></pre> </div> </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-540"> <div class="examplenum"> <a href="#example-540">Example 540</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[foo][bar][baz] [baz]:<span class="space"> </span>/url </code></pre> </div> <div class="column"> <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> </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-541"> <div class="examplenum"> <a href="#example-541">Example 541</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[foo][bar][baz] [baz]:<span class="space"> </span>/url1 [bar]:<span class="space"> </span>/url2 </code></pre> </div> <div class="column"> <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> </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-542"> <div class="examplenum"> <a href="#example-542">Example 542</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">[foo][bar][baz] [baz]:<span class="space"> </span>/url1 [foo]:<span class="space"> </span>/url2 </code></pre> </div> <div class="column"> <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> </div> <h2 id="images" href="#images" class="definition"> <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-543"> <div class="examplenum"> <a href="#example-543">Example 543</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">![foo](/url<span class="space"> </span>&quot;title&quot;) </code></pre> </div> <div class="column"> <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> <div class="example" id="example-544"> <div class="examplenum"> <a href="#example-544">Example 544</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> <div class="example" id="example-545"> <div class="examplenum"> <a href="#example-545">Example 545</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">![foo<span class="space"> </span>![bar](/url)](/url2) </code></pre> </div> <div class="column"> <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> <div class="example" id="example-546"> <div class="examplenum"> <a href="#example-546">Example 546</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">![foo<span class="space"> </span>[bar](/url)](/url2) </code></pre> </div> <div class="column"> <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> <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-547"> <div class="examplenum"> <a href="#example-547">Example 547</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> <div class="example" id="example-548"> <div class="examplenum"> <a href="#example-548">Example 548</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> <div class="example" id="example-549"> <div class="examplenum"> <a href="#example-549">Example 549</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">![foo](train.jpg) </code></pre> </div> <div class="column"> <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> <div class="example" id="example-550"> <div class="examplenum"> <a href="#example-550">Example 550</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> <div class="example" id="example-551"> <div class="examplenum"> <a href="#example-551">Example 551</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">![foo](&lt;url&gt;) </code></pre> </div> <div class="column"> <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> <div class="example" id="example-552"> <div class="examplenum"> <a href="#example-552">Example 552</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">![](/url) </code></pre> </div> <div class="column"> <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> </div> <p>Reference-style:</p> <div class="example" id="example-553"> <div class="examplenum"> <a href="#example-553">Example 553</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">![foo][bar] [bar]:<span class="space"> </span>/url </code></pre> </div> <div class="column"> <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> <div class="example" id="example-554"> <div class="examplenum"> <a href="#example-554">Example 554</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">![foo][bar] [BAR]:<span class="space"> </span>/url </code></pre> </div> <div class="column"> <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> <p>Collapsed:</p> <div class="example" id="example-555"> <div class="examplenum"> <a href="#example-555">Example 555</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">![foo][] [foo]:<span class="space"> </span>/url<span class="space"> </span>&quot;title&quot; </code></pre> </div> <div class="column"> <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> <div class="example" id="example-556"> <div class="examplenum"> <a href="#example-556">Example 556</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>The labels are case-insensitive:</p> <div class="example" id="example-557"> <div class="examplenum"> <a href="#example-557">Example 557</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">![Foo][] [foo]:<span class="space"> </span>/url<span class="space"> </span>&quot;title&quot; </code></pre> </div> <div class="column"> <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> <p>As with reference links, <a href="#whitespace">whitespace</a> is not allowed between the two sets of brackets:</p> <div class="example" id="example-558"> <div class="examplenum"> <a href="#example-558">Example 558</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> <p>Shortcut:</p> <div class="example" id="example-559"> <div class="examplenum"> <a href="#example-559">Example 559</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">![foo] [foo]:<span class="space"> </span>/url<span class="space"> </span>&quot;title&quot; </code></pre> </div> <div class="column"> <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> <div class="example" id="example-560"> <div class="examplenum"> <a href="#example-560">Example 560</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>Note that link labels cannot contain unescaped brackets:</p> <div class="example" id="example-561"> <div class="examplenum"> <a href="#example-561">Example 561</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">![[foo]] [[foo]]:<span class="space"> </span>/url<span class="space"> </span>&quot;title&quot; </code></pre> </div> <div class="column"> <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> </div> <p>The link labels are case-insensitive:</p> <div class="example" id="example-562"> <div class="examplenum"> <a href="#example-562">Example 562</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">![Foo] [foo]:<span class="space"> </span>/url<span class="space"> </span>&quot;title&quot; </code></pre> </div> <div class="column"> <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> <p>If you just want a literal <code>!</code> followed by bracketed text, you can backslash-escape the opening <code>[</code>:</p> <div class="example" id="example-563"> <div class="examplenum"> <a href="#example-563">Example 563</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">!\[foo] [foo]:<span class="space"> </span>/url<span class="space"> </span>&quot;title&quot; </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;![foo]&lt;/p&gt; </code></pre> </div> </div> <p>If you want a link after a literal <code>!</code>, backslash-escape the <code>!</code>:</p> <div class="example" id="example-564"> <div class="examplenum"> <a href="#example-564">Example 564</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">\![foo] [foo]:<span class="space"> </span>/url<span class="space"> </span>&quot;title&quot; </code></pre> </div> <div class="column"> <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> <h2 id="autolinks" href="#autolinks" class="definition"> <span class="number">6.7</span>Autolinks </h2> <p><a id="autolink" href="#autolink" class="definition">Autolink</a>s 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 <a href="#scheme">scheme</a> 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, they must be percent-encoded (e.g. <code>%20</code> for a space).</p> <p>For purposes of this spec, a <a id="scheme" href="#scheme" class="definition">scheme</a> is any sequence of 2–32 characters beginning with an ASCII letter and followed by any combination of ASCII letters, digits, or the symbols plus (”+”), period (”.”), or hyphen (”-”).</p> <p>Here are some valid autolinks:</p> <div class="example" id="example-565"> <div class="examplenum"> <a href="#example-565">Example 565</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;http://foo.bar.baz&gt; </code></pre> </div> <div class="column"> <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> <div class="example" id="example-566"> <div class="examplenum"> <a href="#example-566">Example 566</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;http://foo.bar.baz/test?q=hello&amp;id=22&amp;boolean&gt; </code></pre> </div> <div class="column"> <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> <div class="example" id="example-567"> <div class="examplenum"> <a href="#example-567">Example 567</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;irc://foo.bar:2233/baz&gt; </code></pre> </div> <div class="column"> <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> </div> <p>Uppercase is also fine:</p> <div class="example" id="example-568"> <div class="examplenum"> <a href="#example-568">Example 568</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;MAILTO:FOO@BAR.BAZ&gt; </code></pre> </div> <div class="column"> <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> </div> <p>Note that many strings that count as <a href="#absolute-uri">absolute URIs</a> for purposes of this spec are not valid URIs, because their schemes are not registered or because of other problems with their syntax:</p> <div class="example" id="example-569"> <div class="examplenum"> <a href="#example-569">Example 569</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;a+b+c:d&gt; </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;a+b+c:d&quot;&gt;a+b+c:d&lt;/a&gt;&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-570"> <div class="examplenum"> <a href="#example-570">Example 570</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;made-up-scheme://foo,bar&gt; </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;made-up-scheme://foo,bar&quot;&gt;made-up-scheme://foo,bar&lt;/a&gt;&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-571"> <div class="examplenum"> <a href="#example-571">Example 571</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;http://../&gt; </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;http://../&quot;&gt;http://../&lt;/a&gt;&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-572"> <div class="examplenum"> <a href="#example-572">Example 572</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;localhost:5001/foo&gt; </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&lt;a<span class="space"> </span>href=&quot;localhost:5001/foo&quot;&gt;localhost:5001/foo&lt;/a&gt;&lt;/p&gt; </code></pre> </div> </div> <p>Spaces are not allowed in autolinks:</p> <div class="example" id="example-573"> <div class="examplenum"> <a href="#example-573">Example 573</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;http://foo.bar/baz<span class="space"> </span>bim&gt; </code></pre> </div> <div class="column"> <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> </div> <p>Backslash-escapes do not work inside autolinks:</p> <div class="example" id="example-574"> <div class="examplenum"> <a href="#example-574">Example 574</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;http://example.com/\[\&gt; </code></pre> </div> <div class="column"> <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> </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-575"> <div class="examplenum"> <a href="#example-575">Example 575</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;foo@bar.example.com&gt; </code></pre> </div> <div class="column"> <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> <div class="example" id="example-576"> <div class="examplenum"> <a href="#example-576">Example 576</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;foo+special@Bar.baz-bar0.com&gt; </code></pre> </div> <div class="column"> <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> </div> <p>Backslash-escapes do not work inside email autolinks:</p> <div class="example" id="example-577"> <div class="examplenum"> <a href="#example-577">Example 577</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;foo\+@bar.example.com&gt; </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&amp;lt;foo+@bar.example.com&amp;gt;&lt;/p&gt; </code></pre> </div> </div> <p>These are not autolinks:</p> <div class="example" id="example-578"> <div class="examplenum"> <a href="#example-578">Example 578</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;&gt; </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&amp;lt;&amp;gt;&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-579"> <div class="examplenum"> <a href="#example-579">Example 579</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;<span class="space"> </span>http://foo.bar<span class="space"> </span>&gt; </code></pre> </div> <div class="column"> <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> <div class="example" id="example-580"> <div class="examplenum"> <a href="#example-580">Example 580</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;m:abc&gt; </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&amp;lt;m:abc&amp;gt;&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-581"> <div class="examplenum"> <a href="#example-581">Example 581</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;foo.bar.baz&gt; </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&amp;lt;foo.bar.baz&amp;gt;&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-582"> <div class="examplenum"> <a href="#example-582">Example 582</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">http://example.com </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;http://example.com&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-583"> <div class="examplenum"> <a href="#example-583">Example 583</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">foo@bar.example.com </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;foo@bar.example.com&lt;/p&gt; </code></pre> </div> </div> <h2 id="raw-html" href="#raw-html" class="definition"> <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 <a href="#attribute">attributes</a>, 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-584"> <div class="examplenum"> <a href="#example-584">Example 584</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;a&gt;&lt;bab&gt;&lt;c2c&gt; </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&lt;a&gt;&lt;bab&gt;&lt;c2c&gt;&lt;/p&gt; </code></pre> </div> </div> <p>Empty elements:</p> <div class="example" id="example-585"> <div class="examplenum"> <a href="#example-585">Example 585</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;a/&gt;&lt;b2/&gt; </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&lt;a/&gt;&lt;b2/&gt;&lt;/p&gt; </code></pre> </div> </div> <p><a href="#whitespace">Whitespace</a> is allowed:</p> <div class="example" id="example-586"> <div class="examplenum"> <a href="#example-586">Example 586</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>With attributes:</p> <div class="example" id="example-587"> <div class="examplenum"> <a href="#example-587">Example 587</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>Custom tag names can be used:</p> <div class="example" id="example-588"> <div class="examplenum"> <a href="#example-588">Example 588</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">Foo<span class="space"> </span>&lt;responsive-image<span class="space"> </span>src=&quot;foo.jpg&quot;<span class="space"> </span>/&gt; </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;Foo<span class="space"> </span>&lt;responsive-image<span class="space"> </span>src=&quot;foo.jpg&quot;<span class="space"> </span>/&gt;&lt;/p&gt; </code></pre> </div> </div> <p>Illegal tag names, not parsed as HTML:</p> <div class="example" id="example-589"> <div class="examplenum"> <a href="#example-589">Example 589</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;33&gt;<span class="space"> </span>&lt;__&gt; </code></pre> </div> <div class="column"> <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> </div> <p>Illegal attribute names:</p> <div class="example" id="example-590"> <div class="examplenum"> <a href="#example-590">Example 590</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;a<span class="space"> </span>h*#ref=&quot;hi&quot;&gt; </code></pre> </div> <div class="column"> <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> </div> <p>Illegal attribute values:</p> <div class="example" id="example-591"> <div class="examplenum"> <a href="#example-591">Example 591</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>Illegal <a href="#whitespace">whitespace</a>:</p> <div class="example" id="example-592"> <div class="examplenum"> <a href="#example-592">Example 592</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;<span class="space"> </span>a&gt;&lt; foo&gt;&lt;bar/<span class="space"> </span>&gt; </code></pre> </div> <div class="column"> <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> </div> <p>Missing <a href="#whitespace">whitespace</a>:</p> <div class="example" id="example-593"> <div class="examplenum"> <a href="#example-593">Example 593</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;a<span class="space"> </span>href='bar'title=title&gt; </code></pre> </div> <div class="column"> <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> </div> <p>Closing tags:</p> <div class="example" id="example-594"> <div class="examplenum"> <a href="#example-594">Example 594</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;/a&gt;&lt;/foo<span class="space"> </span>&gt; </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;&lt;/a&gt;&lt;/foo<span class="space"> </span>&gt;&lt;/p&gt; </code></pre> </div> </div> <p>Illegal attributes in closing tag:</p> <div class="example" id="example-595"> <div class="examplenum"> <a href="#example-595">Example 595</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;/a<span class="space"> </span>href=&quot;foo&quot;&gt; </code></pre> </div> <div class="column"> <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> </div> <p>Comments:</p> <div class="example" id="example-596"> <div class="examplenum"> <a href="#example-596">Example 596</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> <div class="example" id="example-597"> <div class="examplenum"> <a href="#example-597">Example 597</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>Not comments:</p> <div class="example" id="example-598"> <div class="examplenum"> <a href="#example-598">Example 598</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>Processing instructions:</p> <div class="example" id="example-599"> <div class="examplenum"> <a href="#example-599">Example 599</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>Declarations:</p> <div class="example" id="example-600"> <div class="examplenum"> <a href="#example-600">Example 600</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <p>CDATA sections:</p> <div class="example" id="example-601"> <div class="examplenum"> <a href="#example-601">Example 601</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">foo<span class="space"> </span>&lt;![CDATA[&gt;&amp;&lt;]]&gt; </code></pre> </div> <div class="column"> <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> </div> <p>Entity and numeric character references are preserved in HTML attributes:</p> <div class="example" id="example-602"> <div class="examplenum"> <a href="#example-602">Example 602</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">foo<span class="space"> </span>&lt;a<span class="space"> </span>href=&quot;&amp;ouml;&quot;&gt; </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;foo<span class="space"> </span>&lt;a<span class="space"> </span>href=&quot;&amp;ouml;&quot;&gt;&lt;/p&gt; </code></pre> </div> </div> <p>Backslash escapes do not work in HTML attributes:</p> <div class="example" id="example-603"> <div class="examplenum"> <a href="#example-603">Example 603</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">foo<span class="space"> </span>&lt;a<span class="space"> </span>href=&quot;\*&quot;&gt; </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;foo<span class="space"> </span>&lt;a<span class="space"> </span>href=&quot;\*&quot;&gt;&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-604"> <div class="examplenum"> <a href="#example-604">Example 604</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;a<span class="space"> </span>href=&quot;\&quot;&quot;&gt; </code></pre> </div> <div class="column"> <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> </div> <h2 id="hard-line-breaks" href="#hard-line-breaks" class="definition"> <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-605"> <div class="examplenum"> <a href="#example-605">Example 605</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">foo<span class="space"> </span><span class="space"> </span> baz </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;foo&lt;br<span class="space"> </span>/&gt; baz&lt;/p&gt; </code></pre> </div> </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-606"> <div class="examplenum"> <a href="#example-606">Example 606</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">foo\ baz </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;foo&lt;br<span class="space"> </span>/&gt; baz&lt;/p&gt; </code></pre> </div> </div> <p>More than two spaces can be used:</p> <div class="example" id="example-607"> <div class="examplenum"> <a href="#example-607">Example 607</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;foo&lt;br<span class="space"> </span>/&gt; baz&lt;/p&gt; </code></pre> </div> </div> <p>Leading spaces at the beginning of the next line are ignored:</p> <div class="example" id="example-608"> <div class="examplenum"> <a href="#example-608">Example 608</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;foo&lt;br<span class="space"> </span>/&gt; bar&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-609"> <div class="examplenum"> <a href="#example-609">Example 609</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;foo&lt;br<span class="space"> </span>/&gt; bar&lt;/p&gt; </code></pre> </div> </div> <p>Line breaks can occur inside emphasis, links, and other constructs that allow inline content:</p> <div class="example" id="example-610"> <div class="examplenum"> <a href="#example-610">Example 610</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">*foo<span class="space"> </span><span class="space"> </span> bar* </code></pre> </div> <div class="column"> <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> <div class="example" id="example-611"> <div class="examplenum"> <a href="#example-611">Example 611</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">*foo\ bar* </code></pre> </div> <div class="column"> <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> <p>Line breaks do not occur inside code spans</p> <div class="example" id="example-612"> <div class="examplenum"> <a href="#example-612">Example 612</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">`code<span class="space"> </span><span class="space"> </span> span` </code></pre> </div> <div class="column"> <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> <div class="example" id="example-613"> <div class="examplenum"> <a href="#example-613">Example 613</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">`code\ span` </code></pre> </div> <div class="column"> <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> <p>or HTML tags:</p> <div class="example" id="example-614"> <div class="examplenum"> <a href="#example-614">Example 614</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> <div class="example" id="example-615"> <div class="examplenum"> <a href="#example-615">Example 615</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">&lt;a<span class="space"> </span>href=&quot;foo\ bar&quot;&gt; </code></pre> </div> <div class="column"> <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> </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-616"> <div class="examplenum"> <a href="#example-616">Example 616</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">foo\ </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;foo\&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-617"> <div class="examplenum"> <a href="#example-617">Example 617</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">foo<span class="space"> </span><span class="space"> </span> </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;foo&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-618"> <div class="examplenum"> <a href="#example-618">Example 618</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">###<span class="space"> </span>foo\ </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;h3&gt;foo\&lt;/h3&gt; </code></pre> </div> </div> <div class="example" id="example-619"> <div class="examplenum"> <a href="#example-619">Example 619</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">###<span class="space"> </span>foo<span class="space"> </span><span class="space"> </span> </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;h3&gt;foo&lt;/h3&gt; </code></pre> </div> </div> <h2 id="soft-line-breaks" href="#soft-line-breaks" class="definition"> <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 <a id="softbreak" href="#softbreak" class="definition">softbreak</a>. (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-620"> <div class="examplenum"> <a href="#example-620">Example 620</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">foo baz </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;foo baz&lt;/p&gt; </code></pre> </div> </div> <p>Spaces at the end of the line and beginning of the next line are removed:</p> <div class="example" id="example-621"> <div class="examplenum"> <a href="#example-621">Example 621</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">foo<span class="space"> </span> <span class="space"> </span>baz </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;foo baz&lt;/p&gt; </code></pre> </div> </div> <p>A conforming parser may render a soft line break in HTML either as a line break or as a space.</p> <p>A renderer may also provide an option to render soft line breaks as hard line breaks.</p> <h2 id="textual-content" href="#textual-content" class="definition"> <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-622"> <div class="examplenum"> <a href="#example-622">Example 622</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">hello<span class="space"> </span>$.;'there </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;hello<span class="space"> </span>$.;'there&lt;/p&gt; </code></pre> </div> </div> <div class="example" id="example-623"> <div class="examplenum"> <a href="#example-623">Example 623</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <pre><code class="language-markdown">Foo<span class="space"> </span>χρῆν </code></pre> </div> <div class="column"> <pre><code class="language-html">&lt;p&gt;Foo<span class="space"> </span>χρῆν&lt;/p&gt; </code></pre> </div> </div> <p>Internal spaces are preserved verbatim:</p> <div class="example" id="example-624"> <div class="examplenum"> <a href="#example-624">Example 624</a><a class="dingus" title="open in interactive dingus">Try It</a> </div> <div class="column"> <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> </div> <div class="column"> <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> </div> <!-- END TESTS --> <div class="appendices"> <h1 id="appendix-a-parsing-strategy" href="#appendix-a-parsing-strategy" class="definition"> Appendix: A parsing strategy </h1> </div> <p>In this appendix we describe some features of the parsing strategy used in the CommonMark reference implementations.</p> <h2 id="overview" href="#overview" class="definition"> 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 headings 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 id="phase-1-block-structure" href="#phase-1-block-structure" class="definition"> 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, heading, or raw HTML).</p> </li> </ol> <p>Setext headings are formed when we see a line of a paragraph that is a <a href="#setext-heading-underline">setext heading underline</a>.</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 id="phase-2-inline-structure" href="#phase-2-inline-structure" class="definition"> 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 headings 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 id="an-algorithm-for-parsing-nested-emphasis-and-links" href="#an-algorithm-for-parsing-nested-emphasis-and-links" class="definition"> 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 id="-look-for-link-or-image-" href="#-look-for-link-or-image-" class="definition"> <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 id="-process-emphasis-" href="#-process-emphasis-" class="definition"> <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