1*72b2703bSAndreas Gohr--- 2*72b2703bSAndreas Gohrtitle: GitHub Flavored Markdown Spec 3*72b2703bSAndreas Gohrversion: 0.29 4*72b2703bSAndreas Gohrdate: '2019-04-06' 5*72b2703bSAndreas Gohrlicense: '[CC-BY-SA 4.0](http://creativecommons.org/licenses/by-sa/4.0/)' 6*72b2703bSAndreas Gohr... 7*72b2703bSAndreas Gohr 8*72b2703bSAndreas Gohr# Introduction 9*72b2703bSAndreas Gohr 10*72b2703bSAndreas Gohr## What is GitHub Flavored Markdown? 11*72b2703bSAndreas Gohr 12*72b2703bSAndreas GohrGitHub Flavored Markdown, often shortened as GFM, is the dialect of Markdown 13*72b2703bSAndreas Gohrthat is currently supported for user content on GitHub.com and GitHub 14*72b2703bSAndreas GohrEnterprise. 15*72b2703bSAndreas Gohr 16*72b2703bSAndreas GohrThis formal specification, based on the CommonMark Spec, defines the syntax and 17*72b2703bSAndreas Gohrsemantics of this dialect. 18*72b2703bSAndreas Gohr 19*72b2703bSAndreas GohrGFM is a strict superset of CommonMark. All the features which are supported in 20*72b2703bSAndreas GohrGitHub user content and that are not specified on the original CommonMark Spec 21*72b2703bSAndreas Gohrare hence known as **extensions**, and highlighted as such. 22*72b2703bSAndreas Gohr 23*72b2703bSAndreas GohrWhile GFM supports a wide range of inputs, it's worth noting that GitHub.com 24*72b2703bSAndreas Gohrand GitHub Enterprise perform additional post-processing and sanitization after 25*72b2703bSAndreas GohrGFM is converted to HTML to ensure security and consistency of the website. 26*72b2703bSAndreas Gohr 27*72b2703bSAndreas Gohr## What is Markdown? 28*72b2703bSAndreas Gohr 29*72b2703bSAndreas GohrMarkdown is a plain text format for writing structured documents, 30*72b2703bSAndreas Gohrbased on conventions for indicating formatting in email 31*72b2703bSAndreas Gohrand usenet posts. It was developed by John Gruber (with 32*72b2703bSAndreas Gohrhelp from Aaron Swartz) and released in 2004 in the form of a 33*72b2703bSAndreas Gohr[syntax description](http://daringfireball.net/projects/markdown/syntax) 34*72b2703bSAndreas Gohrand a Perl script (`Markdown.pl`) for converting Markdown to 35*72b2703bSAndreas GohrHTML. In the next decade, dozens of implementations were 36*72b2703bSAndreas Gohrdeveloped in many languages. Some extended the original 37*72b2703bSAndreas GohrMarkdown syntax with conventions for footnotes, tables, and 38*72b2703bSAndreas Gohrother document elements. Some allowed Markdown documents to be 39*72b2703bSAndreas Gohrrendered in formats other than HTML. Websites like Reddit, 40*72b2703bSAndreas GohrStackOverflow, and GitHub had millions of people using Markdown. 41*72b2703bSAndreas GohrAnd Markdown started to be used beyond the web, to author books, 42*72b2703bSAndreas Gohrarticles, slide shows, letters, and lecture notes. 43*72b2703bSAndreas Gohr 44*72b2703bSAndreas GohrWhat distinguishes Markdown from many other lightweight markup 45*72b2703bSAndreas Gohrsyntaxes, which are often easier to write, is its readability. 46*72b2703bSAndreas GohrAs Gruber writes: 47*72b2703bSAndreas Gohr 48*72b2703bSAndreas Gohr> The overriding design goal for Markdown's formatting syntax is 49*72b2703bSAndreas Gohr> to make it as readable as possible. The idea is that a 50*72b2703bSAndreas Gohr> Markdown-formatted document should be publishable as-is, as 51*72b2703bSAndreas Gohr> plain text, without looking like it's been marked up with tags 52*72b2703bSAndreas Gohr> or formatting instructions. 53*72b2703bSAndreas Gohr> (<http://daringfireball.net/projects/markdown/>) 54*72b2703bSAndreas Gohr 55*72b2703bSAndreas GohrThe point can be illustrated by comparing a sample of 56*72b2703bSAndreas Gohr[AsciiDoc](http://www.methods.co.nz/asciidoc/) with 57*72b2703bSAndreas Gohran equivalent sample of Markdown. Here is a sample of 58*72b2703bSAndreas GohrAsciiDoc from the AsciiDoc manual: 59*72b2703bSAndreas Gohr 60*72b2703bSAndreas Gohr``` 61*72b2703bSAndreas Gohr1. List item one. 62*72b2703bSAndreas Gohr+ 63*72b2703bSAndreas GohrList item one continued with a second paragraph followed by an 64*72b2703bSAndreas GohrIndented block. 65*72b2703bSAndreas Gohr+ 66*72b2703bSAndreas Gohr................. 67*72b2703bSAndreas Gohr$ ls *.sh 68*72b2703bSAndreas Gohr$ mv *.sh ~/tmp 69*72b2703bSAndreas Gohr................. 70*72b2703bSAndreas Gohr+ 71*72b2703bSAndreas GohrList item continued with a third paragraph. 72*72b2703bSAndreas Gohr 73*72b2703bSAndreas Gohr2. List item two continued with an open block. 74*72b2703bSAndreas Gohr+ 75*72b2703bSAndreas Gohr-- 76*72b2703bSAndreas GohrThis paragraph is part of the preceding list item. 77*72b2703bSAndreas Gohr 78*72b2703bSAndreas Gohra. This list is nested and does not require explicit item 79*72b2703bSAndreas Gohrcontinuation. 80*72b2703bSAndreas Gohr+ 81*72b2703bSAndreas GohrThis paragraph is part of the preceding list item. 82*72b2703bSAndreas Gohr 83*72b2703bSAndreas Gohrb. List item b. 84*72b2703bSAndreas Gohr 85*72b2703bSAndreas GohrThis paragraph belongs to item two of the outer list. 86*72b2703bSAndreas Gohr-- 87*72b2703bSAndreas Gohr``` 88*72b2703bSAndreas Gohr 89*72b2703bSAndreas GohrAnd here is the equivalent in Markdown: 90*72b2703bSAndreas Gohr``` 91*72b2703bSAndreas Gohr1. List item one. 92*72b2703bSAndreas Gohr 93*72b2703bSAndreas Gohr List item one continued with a second paragraph followed by an 94*72b2703bSAndreas Gohr Indented block. 95*72b2703bSAndreas Gohr 96*72b2703bSAndreas Gohr $ ls *.sh 97*72b2703bSAndreas Gohr $ mv *.sh ~/tmp 98*72b2703bSAndreas Gohr 99*72b2703bSAndreas Gohr List item continued with a third paragraph. 100*72b2703bSAndreas Gohr 101*72b2703bSAndreas Gohr2. List item two continued with an open block. 102*72b2703bSAndreas Gohr 103*72b2703bSAndreas Gohr This paragraph is part of the preceding list item. 104*72b2703bSAndreas Gohr 105*72b2703bSAndreas Gohr 1. This list is nested and does not require explicit item continuation. 106*72b2703bSAndreas Gohr 107*72b2703bSAndreas Gohr This paragraph is part of the preceding list item. 108*72b2703bSAndreas Gohr 109*72b2703bSAndreas Gohr 2. List item b. 110*72b2703bSAndreas Gohr 111*72b2703bSAndreas Gohr This paragraph belongs to item two of the outer list. 112*72b2703bSAndreas Gohr``` 113*72b2703bSAndreas Gohr 114*72b2703bSAndreas GohrThe AsciiDoc version is, arguably, easier to write. You don't need 115*72b2703bSAndreas Gohrto worry about indentation. But the Markdown version is much easier 116*72b2703bSAndreas Gohrto read. The nesting of list items is apparent to the eye in the 117*72b2703bSAndreas Gohrsource, not just in the processed document. 118*72b2703bSAndreas Gohr 119*72b2703bSAndreas Gohr## Why is a spec needed? 120*72b2703bSAndreas Gohr 121*72b2703bSAndreas GohrJohn Gruber's [canonical description of Markdown's 122*72b2703bSAndreas Gohrsyntax](http://daringfireball.net/projects/markdown/syntax) 123*72b2703bSAndreas Gohrdoes not specify the syntax unambiguously. Here are some examples of 124*72b2703bSAndreas Gohrquestions it does not answer: 125*72b2703bSAndreas Gohr 126*72b2703bSAndreas Gohr1. How much indentation is needed for a sublist? The spec says that 127*72b2703bSAndreas Gohr continuation paragraphs need to be indented four spaces, but is 128*72b2703bSAndreas Gohr not fully explicit about sublists. It is natural to think that 129*72b2703bSAndreas Gohr they, too, must be indented four spaces, but `Markdown.pl` does 130*72b2703bSAndreas Gohr not require that. This is hardly a "corner case," and divergences 131*72b2703bSAndreas Gohr between implementations on this issue often lead to surprises for 132*72b2703bSAndreas Gohr users in real documents. (See [this comment by John 133*72b2703bSAndreas Gohr Gruber](https://web.archive.org/web/20170611172104/http://article.gmane.org/gmane.text.markdown.general/1997).) 134*72b2703bSAndreas Gohr 135*72b2703bSAndreas Gohr2. Is a blank line needed before a block quote or heading? 136*72b2703bSAndreas Gohr Most implementations do not require the blank line. However, 137*72b2703bSAndreas Gohr this can lead to unexpected results in hard-wrapped text, and 138*72b2703bSAndreas Gohr also to ambiguities in parsing (note that some implementations 139*72b2703bSAndreas Gohr put the heading inside the blockquote, while others do not). 140*72b2703bSAndreas Gohr (John Gruber has also spoken [in favor of requiring the blank 141*72b2703bSAndreas Gohr lines](https://web.archive.org/web/20170611172104/http://article.gmane.org/gmane.text.markdown.general/2146).) 142*72b2703bSAndreas Gohr 143*72b2703bSAndreas Gohr3. Is a blank line needed before an indented code block? 144*72b2703bSAndreas Gohr (`Markdown.pl` requires it, but this is not mentioned in the 145*72b2703bSAndreas Gohr documentation, and some implementations do not require it.) 146*72b2703bSAndreas Gohr 147*72b2703bSAndreas Gohr ``` markdown 148*72b2703bSAndreas Gohr paragraph 149*72b2703bSAndreas Gohr code? 150*72b2703bSAndreas Gohr ``` 151*72b2703bSAndreas Gohr 152*72b2703bSAndreas Gohr4. What is the exact rule for determining when list items get 153*72b2703bSAndreas Gohr wrapped in `<p>` tags? Can a list be partially "loose" and partially 154*72b2703bSAndreas Gohr "tight"? What should we do with a list like this? 155*72b2703bSAndreas Gohr 156*72b2703bSAndreas Gohr ``` markdown 157*72b2703bSAndreas Gohr 1. one 158*72b2703bSAndreas Gohr 159*72b2703bSAndreas Gohr 2. two 160*72b2703bSAndreas Gohr 3. three 161*72b2703bSAndreas Gohr ``` 162*72b2703bSAndreas Gohr 163*72b2703bSAndreas Gohr Or this? 164*72b2703bSAndreas Gohr 165*72b2703bSAndreas Gohr ``` markdown 166*72b2703bSAndreas Gohr 1. one 167*72b2703bSAndreas Gohr - a 168*72b2703bSAndreas Gohr 169*72b2703bSAndreas Gohr - b 170*72b2703bSAndreas Gohr 2. two 171*72b2703bSAndreas Gohr ``` 172*72b2703bSAndreas Gohr 173*72b2703bSAndreas Gohr (There are some relevant comments by John Gruber 174*72b2703bSAndreas Gohr [here](https://web.archive.org/web/20170611172104/http://article.gmane.org/gmane.text.markdown.general/2554).) 175*72b2703bSAndreas Gohr 176*72b2703bSAndreas Gohr5. Can list markers be indented? Can ordered list markers be right-aligned? 177*72b2703bSAndreas Gohr 178*72b2703bSAndreas Gohr ``` markdown 179*72b2703bSAndreas Gohr 8. item 1 180*72b2703bSAndreas Gohr 9. item 2 181*72b2703bSAndreas Gohr 10. item 2a 182*72b2703bSAndreas Gohr ``` 183*72b2703bSAndreas Gohr 184*72b2703bSAndreas Gohr6. Is this one list with a thematic break in its second item, 185*72b2703bSAndreas Gohr or two lists separated by a thematic break? 186*72b2703bSAndreas Gohr 187*72b2703bSAndreas Gohr ``` markdown 188*72b2703bSAndreas Gohr * a 189*72b2703bSAndreas Gohr * * * * * 190*72b2703bSAndreas Gohr * b 191*72b2703bSAndreas Gohr ``` 192*72b2703bSAndreas Gohr 193*72b2703bSAndreas Gohr7. When list markers change from numbers to bullets, do we have 194*72b2703bSAndreas Gohr two lists or one? (The Markdown syntax description suggests two, 195*72b2703bSAndreas Gohr but the perl scripts and many other implementations produce one.) 196*72b2703bSAndreas Gohr 197*72b2703bSAndreas Gohr ``` markdown 198*72b2703bSAndreas Gohr 1. fee 199*72b2703bSAndreas Gohr 2. fie 200*72b2703bSAndreas Gohr - foe 201*72b2703bSAndreas Gohr - fum 202*72b2703bSAndreas Gohr ``` 203*72b2703bSAndreas Gohr 204*72b2703bSAndreas Gohr8. What are the precedence rules for the markers of inline structure? 205*72b2703bSAndreas Gohr For example, is the following a valid link, or does the code span 206*72b2703bSAndreas Gohr take precedence ? 207*72b2703bSAndreas Gohr 208*72b2703bSAndreas Gohr ``` markdown 209*72b2703bSAndreas Gohr [a backtick (`)](/url) and [another backtick (`)](/url). 210*72b2703bSAndreas Gohr ``` 211*72b2703bSAndreas Gohr 212*72b2703bSAndreas Gohr9. What are the precedence rules for markers of emphasis and strong 213*72b2703bSAndreas Gohr emphasis? For example, how should the following be parsed? 214*72b2703bSAndreas Gohr 215*72b2703bSAndreas Gohr ``` markdown 216*72b2703bSAndreas Gohr *foo *bar* baz* 217*72b2703bSAndreas Gohr ``` 218*72b2703bSAndreas Gohr 219*72b2703bSAndreas Gohr10. What are the precedence rules between block-level and inline-level 220*72b2703bSAndreas Gohr structure? For example, how should the following be parsed? 221*72b2703bSAndreas Gohr 222*72b2703bSAndreas Gohr ``` markdown 223*72b2703bSAndreas Gohr - `a long code span can contain a hyphen like this 224*72b2703bSAndreas Gohr - and it can screw things up` 225*72b2703bSAndreas Gohr ``` 226*72b2703bSAndreas Gohr 227*72b2703bSAndreas Gohr11. Can list items include section headings? (`Markdown.pl` does not 228*72b2703bSAndreas Gohr allow this, but does allow blockquotes to include headings.) 229*72b2703bSAndreas Gohr 230*72b2703bSAndreas Gohr ``` markdown 231*72b2703bSAndreas Gohr - # Heading 232*72b2703bSAndreas Gohr ``` 233*72b2703bSAndreas Gohr 234*72b2703bSAndreas Gohr12. Can list items be empty? 235*72b2703bSAndreas Gohr 236*72b2703bSAndreas Gohr ``` markdown 237*72b2703bSAndreas Gohr * a 238*72b2703bSAndreas Gohr * 239*72b2703bSAndreas Gohr * b 240*72b2703bSAndreas Gohr ``` 241*72b2703bSAndreas Gohr 242*72b2703bSAndreas Gohr13. Can link references be defined inside block quotes or list items? 243*72b2703bSAndreas Gohr 244*72b2703bSAndreas Gohr ``` markdown 245*72b2703bSAndreas Gohr > Blockquote [foo]. 246*72b2703bSAndreas Gohr > 247*72b2703bSAndreas Gohr > [foo]: /url 248*72b2703bSAndreas Gohr ``` 249*72b2703bSAndreas Gohr 250*72b2703bSAndreas Gohr14. If there are multiple definitions for the same reference, which takes 251*72b2703bSAndreas Gohr precedence? 252*72b2703bSAndreas Gohr 253*72b2703bSAndreas Gohr ``` markdown 254*72b2703bSAndreas Gohr [foo]: /url1 255*72b2703bSAndreas Gohr [foo]: /url2 256*72b2703bSAndreas Gohr 257*72b2703bSAndreas Gohr [foo][] 258*72b2703bSAndreas Gohr ``` 259*72b2703bSAndreas Gohr 260*72b2703bSAndreas GohrIn the absence of a spec, early implementers consulted `Markdown.pl` 261*72b2703bSAndreas Gohrto resolve these ambiguities. But `Markdown.pl` was quite buggy, and 262*72b2703bSAndreas Gohrgave manifestly bad results in many cases, so it was not a 263*72b2703bSAndreas Gohrsatisfactory replacement for a spec. 264*72b2703bSAndreas Gohr 265*72b2703bSAndreas GohrBecause there is no unambiguous spec, implementations have diverged 266*72b2703bSAndreas Gohrconsiderably. As a result, users are often surprised to find that 267*72b2703bSAndreas Gohra document that renders one way on one system (say, a GitHub wiki) 268*72b2703bSAndreas Gohrrenders differently on another (say, converting to docbook using 269*72b2703bSAndreas Gohrpandoc). To make matters worse, because nothing in Markdown counts 270*72b2703bSAndreas Gohras a "syntax error," the divergence often isn't discovered right away. 271*72b2703bSAndreas Gohr 272*72b2703bSAndreas Gohr## About this document 273*72b2703bSAndreas Gohr 274*72b2703bSAndreas GohrThis document attempts to specify Markdown syntax unambiguously. 275*72b2703bSAndreas GohrIt contains many examples with side-by-side Markdown and 276*72b2703bSAndreas GohrHTML. These are intended to double as conformance tests. An 277*72b2703bSAndreas Gohraccompanying script `spec_tests.py` can be used to run the tests 278*72b2703bSAndreas Gohragainst any Markdown program: 279*72b2703bSAndreas Gohr 280*72b2703bSAndreas Gohr python test/spec_tests.py --spec spec.txt --program PROGRAM 281*72b2703bSAndreas Gohr 282*72b2703bSAndreas GohrSince this document describes how Markdown is to be parsed into 283*72b2703bSAndreas Gohran abstract syntax tree, it would have made sense to use an abstract 284*72b2703bSAndreas Gohrrepresentation of the syntax tree instead of HTML. But HTML is capable 285*72b2703bSAndreas Gohrof representing the structural distinctions we need to make, and the 286*72b2703bSAndreas Gohrchoice of HTML for the tests makes it possible to run the tests against 287*72b2703bSAndreas Gohran implementation without writing an abstract syntax tree renderer. 288*72b2703bSAndreas Gohr 289*72b2703bSAndreas GohrThis document is generated from a text file, `spec.txt`, written 290*72b2703bSAndreas Gohrin Markdown with a small extension for the side-by-side tests. 291*72b2703bSAndreas GohrThe script `tools/makespec.py` can be used to convert `spec.txt` into 292*72b2703bSAndreas GohrHTML or CommonMark (which can then be converted into other formats). 293*72b2703bSAndreas Gohr 294*72b2703bSAndreas GohrIn the examples, the `→` character is used to represent tabs. 295*72b2703bSAndreas Gohr 296*72b2703bSAndreas Gohr# Preliminaries 297*72b2703bSAndreas Gohr 298*72b2703bSAndreas Gohr## Characters and lines 299*72b2703bSAndreas Gohr 300*72b2703bSAndreas GohrAny sequence of [characters] is a valid CommonMark 301*72b2703bSAndreas Gohrdocument. 302*72b2703bSAndreas Gohr 303*72b2703bSAndreas GohrA [character](@) is a Unicode code point. Although some 304*72b2703bSAndreas Gohrcode points (for example, combining accents) do not correspond to 305*72b2703bSAndreas Gohrcharacters in an intuitive sense, all code points count as characters 306*72b2703bSAndreas Gohrfor purposes of this spec. 307*72b2703bSAndreas Gohr 308*72b2703bSAndreas GohrThis spec does not specify an encoding; it thinks of lines as composed 309*72b2703bSAndreas Gohrof [characters] rather than bytes. A conforming parser may be limited 310*72b2703bSAndreas Gohrto a certain encoding. 311*72b2703bSAndreas Gohr 312*72b2703bSAndreas GohrA [line](@) is a sequence of zero or more [characters] 313*72b2703bSAndreas Gohrother than newline (`U+000A`) or carriage return (`U+000D`), 314*72b2703bSAndreas Gohrfollowed by a [line ending] or by the end of file. 315*72b2703bSAndreas Gohr 316*72b2703bSAndreas GohrA [line ending](@) is a newline (`U+000A`), a carriage return 317*72b2703bSAndreas Gohr(`U+000D`) not followed by a newline, or a carriage return and a 318*72b2703bSAndreas Gohrfollowing newline. 319*72b2703bSAndreas Gohr 320*72b2703bSAndreas GohrA line containing no characters, or a line containing only spaces 321*72b2703bSAndreas Gohr(`U+0020`) or tabs (`U+0009`), is called a [blank line](@). 322*72b2703bSAndreas Gohr 323*72b2703bSAndreas GohrThe following definitions of character classes will be used in this spec: 324*72b2703bSAndreas Gohr 325*72b2703bSAndreas GohrA [whitespace character](@) is a space 326*72b2703bSAndreas Gohr(`U+0020`), tab (`U+0009`), newline (`U+000A`), line tabulation (`U+000B`), 327*72b2703bSAndreas Gohrform feed (`U+000C`), or carriage return (`U+000D`). 328*72b2703bSAndreas Gohr 329*72b2703bSAndreas Gohr[Whitespace](@) is a sequence of one or more [whitespace 330*72b2703bSAndreas Gohrcharacters]. 331*72b2703bSAndreas Gohr 332*72b2703bSAndreas GohrA [Unicode whitespace character](@) is 333*72b2703bSAndreas Gohrany code point in the Unicode `Zs` general category, or a tab (`U+0009`), 334*72b2703bSAndreas Gohrcarriage return (`U+000D`), newline (`U+000A`), or form feed 335*72b2703bSAndreas Gohr(`U+000C`). 336*72b2703bSAndreas Gohr 337*72b2703bSAndreas Gohr[Unicode whitespace](@) is a sequence of one 338*72b2703bSAndreas Gohror more [Unicode whitespace characters]. 339*72b2703bSAndreas Gohr 340*72b2703bSAndreas GohrA [space](@) is `U+0020`. 341*72b2703bSAndreas Gohr 342*72b2703bSAndreas GohrA [non-whitespace character](@) is any character 343*72b2703bSAndreas Gohrthat is not a [whitespace character]. 344*72b2703bSAndreas Gohr 345*72b2703bSAndreas GohrAn [ASCII punctuation character](@) 346*72b2703bSAndreas Gohris `!`, `"`, `#`, `$`, `%`, `&`, `'`, `(`, `)`, 347*72b2703bSAndreas Gohr`*`, `+`, `,`, `-`, `.`, `/` (U+0021–2F), 348*72b2703bSAndreas Gohr`:`, `;`, `<`, `=`, `>`, `?`, `@` (U+003A–0040), 349*72b2703bSAndreas Gohr`[`, `\`, `]`, `^`, `_`, `` ` `` (U+005B–0060), 350*72b2703bSAndreas Gohr`{`, `|`, `}`, or `~` (U+007B–007E). 351*72b2703bSAndreas Gohr 352*72b2703bSAndreas GohrA [punctuation character](@) is an [ASCII 353*72b2703bSAndreas Gohrpunctuation character] or anything in 354*72b2703bSAndreas Gohrthe general Unicode categories `Pc`, `Pd`, `Pe`, `Pf`, `Pi`, `Po`, or `Ps`. 355*72b2703bSAndreas Gohr 356*72b2703bSAndreas Gohr## Tabs 357*72b2703bSAndreas Gohr 358*72b2703bSAndreas GohrTabs in lines are not expanded to [spaces]. However, 359*72b2703bSAndreas Gohrin contexts where whitespace helps to define block structure, 360*72b2703bSAndreas Gohrtabs behave as if they were replaced by spaces with a tab stop 361*72b2703bSAndreas Gohrof 4 characters. 362*72b2703bSAndreas Gohr 363*72b2703bSAndreas GohrThus, for example, a tab can be used instead of four spaces 364*72b2703bSAndreas Gohrin an indented code block. (Note, however, that internal 365*72b2703bSAndreas Gohrtabs are passed through as literal tabs, not expanded to 366*72b2703bSAndreas Gohrspaces.) 367*72b2703bSAndreas Gohr 368*72b2703bSAndreas Gohr```````````````````````````````` example 369*72b2703bSAndreas Gohr→foo→baz→→bim 370*72b2703bSAndreas Gohr. 371*72b2703bSAndreas Gohr<pre><code>foo→baz→→bim 372*72b2703bSAndreas Gohr</code></pre> 373*72b2703bSAndreas Gohr```````````````````````````````` 374*72b2703bSAndreas Gohr 375*72b2703bSAndreas Gohr```````````````````````````````` example 376*72b2703bSAndreas Gohr →foo→baz→→bim 377*72b2703bSAndreas Gohr. 378*72b2703bSAndreas Gohr<pre><code>foo→baz→→bim 379*72b2703bSAndreas Gohr</code></pre> 380*72b2703bSAndreas Gohr```````````````````````````````` 381*72b2703bSAndreas Gohr 382*72b2703bSAndreas Gohr```````````````````````````````` example 383*72b2703bSAndreas Gohr a→a 384*72b2703bSAndreas Gohr ὐ→a 385*72b2703bSAndreas Gohr. 386*72b2703bSAndreas Gohr<pre><code>a→a 387*72b2703bSAndreas Gohrὐ→a 388*72b2703bSAndreas Gohr</code></pre> 389*72b2703bSAndreas Gohr```````````````````````````````` 390*72b2703bSAndreas Gohr 391*72b2703bSAndreas GohrIn the following example, a continuation paragraph of a list 392*72b2703bSAndreas Gohritem is indented with a tab; this has exactly the same effect 393*72b2703bSAndreas Gohras indentation with four spaces would: 394*72b2703bSAndreas Gohr 395*72b2703bSAndreas Gohr```````````````````````````````` example 396*72b2703bSAndreas Gohr - foo 397*72b2703bSAndreas Gohr 398*72b2703bSAndreas Gohr→bar 399*72b2703bSAndreas Gohr. 400*72b2703bSAndreas Gohr<ul> 401*72b2703bSAndreas Gohr<li> 402*72b2703bSAndreas Gohr<p>foo</p> 403*72b2703bSAndreas Gohr<p>bar</p> 404*72b2703bSAndreas Gohr</li> 405*72b2703bSAndreas Gohr</ul> 406*72b2703bSAndreas Gohr```````````````````````````````` 407*72b2703bSAndreas Gohr 408*72b2703bSAndreas Gohr```````````````````````````````` example 409*72b2703bSAndreas Gohr- foo 410*72b2703bSAndreas Gohr 411*72b2703bSAndreas Gohr→→bar 412*72b2703bSAndreas Gohr. 413*72b2703bSAndreas Gohr<ul> 414*72b2703bSAndreas Gohr<li> 415*72b2703bSAndreas Gohr<p>foo</p> 416*72b2703bSAndreas Gohr<pre><code> bar 417*72b2703bSAndreas Gohr</code></pre> 418*72b2703bSAndreas Gohr</li> 419*72b2703bSAndreas Gohr</ul> 420*72b2703bSAndreas Gohr```````````````````````````````` 421*72b2703bSAndreas Gohr 422*72b2703bSAndreas GohrNormally the `>` that begins a block quote may be followed 423*72b2703bSAndreas Gohroptionally by a space, which is not considered part of the 424*72b2703bSAndreas Gohrcontent. In the following case `>` is followed by a tab, 425*72b2703bSAndreas Gohrwhich is treated as if it were expanded into three spaces. 426*72b2703bSAndreas GohrSince one of these spaces is considered part of the 427*72b2703bSAndreas Gohrdelimiter, `foo` is considered to be indented six spaces 428*72b2703bSAndreas Gohrinside the block quote context, so we get an indented 429*72b2703bSAndreas Gohrcode block starting with two spaces. 430*72b2703bSAndreas Gohr 431*72b2703bSAndreas Gohr```````````````````````````````` example 432*72b2703bSAndreas Gohr>→→foo 433*72b2703bSAndreas Gohr. 434*72b2703bSAndreas Gohr<blockquote> 435*72b2703bSAndreas Gohr<pre><code> foo 436*72b2703bSAndreas Gohr</code></pre> 437*72b2703bSAndreas Gohr</blockquote> 438*72b2703bSAndreas Gohr```````````````````````````````` 439*72b2703bSAndreas Gohr 440*72b2703bSAndreas Gohr```````````````````````````````` example 441*72b2703bSAndreas Gohr-→→foo 442*72b2703bSAndreas Gohr. 443*72b2703bSAndreas Gohr<ul> 444*72b2703bSAndreas Gohr<li> 445*72b2703bSAndreas Gohr<pre><code> foo 446*72b2703bSAndreas Gohr</code></pre> 447*72b2703bSAndreas Gohr</li> 448*72b2703bSAndreas Gohr</ul> 449*72b2703bSAndreas Gohr```````````````````````````````` 450*72b2703bSAndreas Gohr 451*72b2703bSAndreas Gohr 452*72b2703bSAndreas Gohr```````````````````````````````` example 453*72b2703bSAndreas Gohr foo 454*72b2703bSAndreas Gohr→bar 455*72b2703bSAndreas Gohr. 456*72b2703bSAndreas Gohr<pre><code>foo 457*72b2703bSAndreas Gohrbar 458*72b2703bSAndreas Gohr</code></pre> 459*72b2703bSAndreas Gohr```````````````````````````````` 460*72b2703bSAndreas Gohr 461*72b2703bSAndreas Gohr```````````````````````````````` example 462*72b2703bSAndreas Gohr - foo 463*72b2703bSAndreas Gohr - bar 464*72b2703bSAndreas Gohr→ - baz 465*72b2703bSAndreas Gohr. 466*72b2703bSAndreas Gohr<ul> 467*72b2703bSAndreas Gohr<li>foo 468*72b2703bSAndreas Gohr<ul> 469*72b2703bSAndreas Gohr<li>bar 470*72b2703bSAndreas Gohr<ul> 471*72b2703bSAndreas Gohr<li>baz</li> 472*72b2703bSAndreas Gohr</ul> 473*72b2703bSAndreas Gohr</li> 474*72b2703bSAndreas Gohr</ul> 475*72b2703bSAndreas Gohr</li> 476*72b2703bSAndreas Gohr</ul> 477*72b2703bSAndreas Gohr```````````````````````````````` 478*72b2703bSAndreas Gohr 479*72b2703bSAndreas Gohr```````````````````````````````` example 480*72b2703bSAndreas Gohr#→Foo 481*72b2703bSAndreas Gohr. 482*72b2703bSAndreas Gohr<h1>Foo</h1> 483*72b2703bSAndreas Gohr```````````````````````````````` 484*72b2703bSAndreas Gohr 485*72b2703bSAndreas Gohr```````````````````````````````` example 486*72b2703bSAndreas Gohr*→*→*→ 487*72b2703bSAndreas Gohr. 488*72b2703bSAndreas Gohr<hr /> 489*72b2703bSAndreas Gohr```````````````````````````````` 490*72b2703bSAndreas Gohr 491*72b2703bSAndreas Gohr 492*72b2703bSAndreas Gohr## Insecure characters 493*72b2703bSAndreas Gohr 494*72b2703bSAndreas GohrFor security reasons, the Unicode character `U+0000` must be replaced 495*72b2703bSAndreas Gohrwith the REPLACEMENT CHARACTER (`U+FFFD`). 496*72b2703bSAndreas Gohr 497*72b2703bSAndreas Gohr# Blocks and inlines 498*72b2703bSAndreas Gohr 499*72b2703bSAndreas GohrWe can think of a document as a sequence of 500*72b2703bSAndreas Gohr[blocks](@)---structural elements like paragraphs, block 501*72b2703bSAndreas Gohrquotations, lists, headings, rules, and code blocks. Some blocks (like 502*72b2703bSAndreas Gohrblock quotes and list items) contain other blocks; others (like 503*72b2703bSAndreas Gohrheadings and paragraphs) contain [inline](@) content---text, 504*72b2703bSAndreas Gohrlinks, emphasized text, images, code spans, and so on. 505*72b2703bSAndreas Gohr 506*72b2703bSAndreas Gohr## Precedence 507*72b2703bSAndreas Gohr 508*72b2703bSAndreas GohrIndicators of block structure always take precedence over indicators 509*72b2703bSAndreas Gohrof inline structure. So, for example, the following is a list with 510*72b2703bSAndreas Gohrtwo items, not a list with one item containing a code span: 511*72b2703bSAndreas Gohr 512*72b2703bSAndreas Gohr```````````````````````````````` example 513*72b2703bSAndreas Gohr- `one 514*72b2703bSAndreas Gohr- two` 515*72b2703bSAndreas Gohr. 516*72b2703bSAndreas Gohr<ul> 517*72b2703bSAndreas Gohr<li>`one</li> 518*72b2703bSAndreas Gohr<li>two`</li> 519*72b2703bSAndreas Gohr</ul> 520*72b2703bSAndreas Gohr```````````````````````````````` 521*72b2703bSAndreas Gohr 522*72b2703bSAndreas Gohr 523*72b2703bSAndreas GohrThis means that parsing can proceed in two steps: first, the block 524*72b2703bSAndreas Gohrstructure of the document can be discerned; second, text lines inside 525*72b2703bSAndreas Gohrparagraphs, headings, and other block constructs can be parsed for inline 526*72b2703bSAndreas Gohrstructure. The second step requires information about link reference 527*72b2703bSAndreas Gohrdefinitions that will be available only at the end of the first 528*72b2703bSAndreas Gohrstep. Note that the first step requires processing lines in sequence, 529*72b2703bSAndreas Gohrbut the second can be parallelized, since the inline parsing of 530*72b2703bSAndreas Gohrone block element does not affect the inline parsing of any other. 531*72b2703bSAndreas Gohr 532*72b2703bSAndreas Gohr## Container blocks and leaf blocks 533*72b2703bSAndreas Gohr 534*72b2703bSAndreas GohrWe can divide blocks into two types: 535*72b2703bSAndreas Gohr[container blocks](@), 536*72b2703bSAndreas Gohrwhich can contain other blocks, and [leaf blocks](@), 537*72b2703bSAndreas Gohrwhich cannot. 538*72b2703bSAndreas Gohr 539*72b2703bSAndreas Gohr# Leaf blocks 540*72b2703bSAndreas Gohr 541*72b2703bSAndreas GohrThis section describes the different kinds of leaf block that make up a 542*72b2703bSAndreas GohrMarkdown document. 543*72b2703bSAndreas Gohr 544*72b2703bSAndreas Gohr## Thematic breaks 545*72b2703bSAndreas Gohr 546*72b2703bSAndreas GohrA line consisting of 0-3 spaces of indentation, followed by a sequence 547*72b2703bSAndreas Gohrof three or more matching `-`, `_`, or `*` characters, each followed 548*72b2703bSAndreas Gohroptionally by any number of spaces or tabs, forms a 549*72b2703bSAndreas Gohr[thematic break](@). 550*72b2703bSAndreas Gohr 551*72b2703bSAndreas Gohr```````````````````````````````` example 552*72b2703bSAndreas Gohr*** 553*72b2703bSAndreas Gohr--- 554*72b2703bSAndreas Gohr___ 555*72b2703bSAndreas Gohr. 556*72b2703bSAndreas Gohr<hr /> 557*72b2703bSAndreas Gohr<hr /> 558*72b2703bSAndreas Gohr<hr /> 559*72b2703bSAndreas Gohr```````````````````````````````` 560*72b2703bSAndreas Gohr 561*72b2703bSAndreas Gohr 562*72b2703bSAndreas GohrWrong characters: 563*72b2703bSAndreas Gohr 564*72b2703bSAndreas Gohr```````````````````````````````` example 565*72b2703bSAndreas Gohr+++ 566*72b2703bSAndreas Gohr. 567*72b2703bSAndreas Gohr<p>+++</p> 568*72b2703bSAndreas Gohr```````````````````````````````` 569*72b2703bSAndreas Gohr 570*72b2703bSAndreas Gohr 571*72b2703bSAndreas Gohr```````````````````````````````` example 572*72b2703bSAndreas Gohr=== 573*72b2703bSAndreas Gohr. 574*72b2703bSAndreas Gohr<p>===</p> 575*72b2703bSAndreas Gohr```````````````````````````````` 576*72b2703bSAndreas Gohr 577*72b2703bSAndreas Gohr 578*72b2703bSAndreas GohrNot enough characters: 579*72b2703bSAndreas Gohr 580*72b2703bSAndreas Gohr```````````````````````````````` example 581*72b2703bSAndreas Gohr-- 582*72b2703bSAndreas Gohr** 583*72b2703bSAndreas Gohr__ 584*72b2703bSAndreas Gohr. 585*72b2703bSAndreas Gohr<p>-- 586*72b2703bSAndreas Gohr** 587*72b2703bSAndreas Gohr__</p> 588*72b2703bSAndreas Gohr```````````````````````````````` 589*72b2703bSAndreas Gohr 590*72b2703bSAndreas Gohr 591*72b2703bSAndreas GohrOne to three spaces indent are allowed: 592*72b2703bSAndreas Gohr 593*72b2703bSAndreas Gohr```````````````````````````````` example 594*72b2703bSAndreas Gohr *** 595*72b2703bSAndreas Gohr *** 596*72b2703bSAndreas Gohr *** 597*72b2703bSAndreas Gohr. 598*72b2703bSAndreas Gohr<hr /> 599*72b2703bSAndreas Gohr<hr /> 600*72b2703bSAndreas Gohr<hr /> 601*72b2703bSAndreas Gohr```````````````````````````````` 602*72b2703bSAndreas Gohr 603*72b2703bSAndreas Gohr 604*72b2703bSAndreas GohrFour spaces is too many: 605*72b2703bSAndreas Gohr 606*72b2703bSAndreas Gohr```````````````````````````````` example 607*72b2703bSAndreas Gohr *** 608*72b2703bSAndreas Gohr. 609*72b2703bSAndreas Gohr<pre><code>*** 610*72b2703bSAndreas Gohr</code></pre> 611*72b2703bSAndreas Gohr```````````````````````````````` 612*72b2703bSAndreas Gohr 613*72b2703bSAndreas Gohr 614*72b2703bSAndreas Gohr```````````````````````````````` example 615*72b2703bSAndreas GohrFoo 616*72b2703bSAndreas Gohr *** 617*72b2703bSAndreas Gohr. 618*72b2703bSAndreas Gohr<p>Foo 619*72b2703bSAndreas Gohr***</p> 620*72b2703bSAndreas Gohr```````````````````````````````` 621*72b2703bSAndreas Gohr 622*72b2703bSAndreas Gohr 623*72b2703bSAndreas GohrMore than three characters may be used: 624*72b2703bSAndreas Gohr 625*72b2703bSAndreas Gohr```````````````````````````````` example 626*72b2703bSAndreas Gohr_____________________________________ 627*72b2703bSAndreas Gohr. 628*72b2703bSAndreas Gohr<hr /> 629*72b2703bSAndreas Gohr```````````````````````````````` 630*72b2703bSAndreas Gohr 631*72b2703bSAndreas Gohr 632*72b2703bSAndreas GohrSpaces are allowed between the characters: 633*72b2703bSAndreas Gohr 634*72b2703bSAndreas Gohr```````````````````````````````` example 635*72b2703bSAndreas Gohr - - - 636*72b2703bSAndreas Gohr. 637*72b2703bSAndreas Gohr<hr /> 638*72b2703bSAndreas Gohr```````````````````````````````` 639*72b2703bSAndreas Gohr 640*72b2703bSAndreas Gohr 641*72b2703bSAndreas Gohr```````````````````````````````` example 642*72b2703bSAndreas Gohr ** * ** * ** * ** 643*72b2703bSAndreas Gohr. 644*72b2703bSAndreas Gohr<hr /> 645*72b2703bSAndreas Gohr```````````````````````````````` 646*72b2703bSAndreas Gohr 647*72b2703bSAndreas Gohr 648*72b2703bSAndreas Gohr```````````````````````````````` example 649*72b2703bSAndreas Gohr- - - - 650*72b2703bSAndreas Gohr. 651*72b2703bSAndreas Gohr<hr /> 652*72b2703bSAndreas Gohr```````````````````````````````` 653*72b2703bSAndreas Gohr 654*72b2703bSAndreas Gohr 655*72b2703bSAndreas GohrSpaces are allowed at the end: 656*72b2703bSAndreas Gohr 657*72b2703bSAndreas Gohr```````````````````````````````` example 658*72b2703bSAndreas Gohr- - - - 659*72b2703bSAndreas Gohr. 660*72b2703bSAndreas Gohr<hr /> 661*72b2703bSAndreas Gohr```````````````````````````````` 662*72b2703bSAndreas Gohr 663*72b2703bSAndreas Gohr 664*72b2703bSAndreas GohrHowever, no other characters may occur in the line: 665*72b2703bSAndreas Gohr 666*72b2703bSAndreas Gohr```````````````````````````````` example 667*72b2703bSAndreas Gohr_ _ _ _ a 668*72b2703bSAndreas Gohr 669*72b2703bSAndreas Gohra------ 670*72b2703bSAndreas Gohr 671*72b2703bSAndreas Gohr---a--- 672*72b2703bSAndreas Gohr. 673*72b2703bSAndreas Gohr<p>_ _ _ _ a</p> 674*72b2703bSAndreas Gohr<p>a------</p> 675*72b2703bSAndreas Gohr<p>---a---</p> 676*72b2703bSAndreas Gohr```````````````````````````````` 677*72b2703bSAndreas Gohr 678*72b2703bSAndreas Gohr 679*72b2703bSAndreas GohrIt is required that all of the [non-whitespace characters] be the same. 680*72b2703bSAndreas GohrSo, this is not a thematic break: 681*72b2703bSAndreas Gohr 682*72b2703bSAndreas Gohr```````````````````````````````` example 683*72b2703bSAndreas Gohr *-* 684*72b2703bSAndreas Gohr. 685*72b2703bSAndreas Gohr<p><em>-</em></p> 686*72b2703bSAndreas Gohr```````````````````````````````` 687*72b2703bSAndreas Gohr 688*72b2703bSAndreas Gohr 689*72b2703bSAndreas GohrThematic breaks do not need blank lines before or after: 690*72b2703bSAndreas Gohr 691*72b2703bSAndreas Gohr```````````````````````````````` example 692*72b2703bSAndreas Gohr- foo 693*72b2703bSAndreas Gohr*** 694*72b2703bSAndreas Gohr- bar 695*72b2703bSAndreas Gohr. 696*72b2703bSAndreas Gohr<ul> 697*72b2703bSAndreas Gohr<li>foo</li> 698*72b2703bSAndreas Gohr</ul> 699*72b2703bSAndreas Gohr<hr /> 700*72b2703bSAndreas Gohr<ul> 701*72b2703bSAndreas Gohr<li>bar</li> 702*72b2703bSAndreas Gohr</ul> 703*72b2703bSAndreas Gohr```````````````````````````````` 704*72b2703bSAndreas Gohr 705*72b2703bSAndreas Gohr 706*72b2703bSAndreas GohrThematic breaks can interrupt a paragraph: 707*72b2703bSAndreas Gohr 708*72b2703bSAndreas Gohr```````````````````````````````` example 709*72b2703bSAndreas GohrFoo 710*72b2703bSAndreas Gohr*** 711*72b2703bSAndreas Gohrbar 712*72b2703bSAndreas Gohr. 713*72b2703bSAndreas Gohr<p>Foo</p> 714*72b2703bSAndreas Gohr<hr /> 715*72b2703bSAndreas Gohr<p>bar</p> 716*72b2703bSAndreas Gohr```````````````````````````````` 717*72b2703bSAndreas Gohr 718*72b2703bSAndreas Gohr 719*72b2703bSAndreas GohrIf a line of dashes that meets the above conditions for being a 720*72b2703bSAndreas Gohrthematic break could also be interpreted as the underline of a [setext 721*72b2703bSAndreas Gohrheading], the interpretation as a 722*72b2703bSAndreas Gohr[setext heading] takes precedence. Thus, for example, 723*72b2703bSAndreas Gohrthis is a setext heading, not a paragraph followed by a thematic break: 724*72b2703bSAndreas Gohr 725*72b2703bSAndreas Gohr```````````````````````````````` example 726*72b2703bSAndreas GohrFoo 727*72b2703bSAndreas Gohr--- 728*72b2703bSAndreas Gohrbar 729*72b2703bSAndreas Gohr. 730*72b2703bSAndreas Gohr<h2>Foo</h2> 731*72b2703bSAndreas Gohr<p>bar</p> 732*72b2703bSAndreas Gohr```````````````````````````````` 733*72b2703bSAndreas Gohr 734*72b2703bSAndreas Gohr 735*72b2703bSAndreas GohrWhen both a thematic break and a list item are possible 736*72b2703bSAndreas Gohrinterpretations of a line, the thematic break takes precedence: 737*72b2703bSAndreas Gohr 738*72b2703bSAndreas Gohr```````````````````````````````` example 739*72b2703bSAndreas Gohr* Foo 740*72b2703bSAndreas Gohr* * * 741*72b2703bSAndreas Gohr* Bar 742*72b2703bSAndreas Gohr. 743*72b2703bSAndreas Gohr<ul> 744*72b2703bSAndreas Gohr<li>Foo</li> 745*72b2703bSAndreas Gohr</ul> 746*72b2703bSAndreas Gohr<hr /> 747*72b2703bSAndreas Gohr<ul> 748*72b2703bSAndreas Gohr<li>Bar</li> 749*72b2703bSAndreas Gohr</ul> 750*72b2703bSAndreas Gohr```````````````````````````````` 751*72b2703bSAndreas Gohr 752*72b2703bSAndreas Gohr 753*72b2703bSAndreas GohrIf you want a thematic break in a list item, use a different bullet: 754*72b2703bSAndreas Gohr 755*72b2703bSAndreas Gohr```````````````````````````````` example 756*72b2703bSAndreas Gohr- Foo 757*72b2703bSAndreas Gohr- * * * 758*72b2703bSAndreas Gohr. 759*72b2703bSAndreas Gohr<ul> 760*72b2703bSAndreas Gohr<li>Foo</li> 761*72b2703bSAndreas Gohr<li> 762*72b2703bSAndreas Gohr<hr /> 763*72b2703bSAndreas Gohr</li> 764*72b2703bSAndreas Gohr</ul> 765*72b2703bSAndreas Gohr```````````````````````````````` 766*72b2703bSAndreas Gohr 767*72b2703bSAndreas Gohr 768*72b2703bSAndreas Gohr## ATX headings 769*72b2703bSAndreas Gohr 770*72b2703bSAndreas GohrAn [ATX heading](@) 771*72b2703bSAndreas Gohrconsists of a string of characters, parsed as inline content, between an 772*72b2703bSAndreas Gohropening sequence of 1--6 unescaped `#` characters and an optional 773*72b2703bSAndreas Gohrclosing sequence of any number of unescaped `#` characters. 774*72b2703bSAndreas GohrThe opening sequence of `#` characters must be followed by a 775*72b2703bSAndreas Gohr[space] or by the end of line. The optional closing sequence of `#`s must be 776*72b2703bSAndreas Gohrpreceded by a [space] and may be followed by spaces only. The opening 777*72b2703bSAndreas Gohr`#` character may be indented 0-3 spaces. The raw contents of the 778*72b2703bSAndreas Gohrheading are stripped of leading and trailing spaces before being parsed 779*72b2703bSAndreas Gohras inline content. The heading level is equal to the number of `#` 780*72b2703bSAndreas Gohrcharacters in the opening sequence. 781*72b2703bSAndreas Gohr 782*72b2703bSAndreas GohrSimple headings: 783*72b2703bSAndreas Gohr 784*72b2703bSAndreas Gohr```````````````````````````````` example 785*72b2703bSAndreas Gohr# foo 786*72b2703bSAndreas Gohr## foo 787*72b2703bSAndreas Gohr### foo 788*72b2703bSAndreas Gohr#### foo 789*72b2703bSAndreas Gohr##### foo 790*72b2703bSAndreas Gohr###### foo 791*72b2703bSAndreas Gohr. 792*72b2703bSAndreas Gohr<h1>foo</h1> 793*72b2703bSAndreas Gohr<h2>foo</h2> 794*72b2703bSAndreas Gohr<h3>foo</h3> 795*72b2703bSAndreas Gohr<h4>foo</h4> 796*72b2703bSAndreas Gohr<h5>foo</h5> 797*72b2703bSAndreas Gohr<h6>foo</h6> 798*72b2703bSAndreas Gohr```````````````````````````````` 799*72b2703bSAndreas Gohr 800*72b2703bSAndreas Gohr 801*72b2703bSAndreas GohrMore than six `#` characters is not a heading: 802*72b2703bSAndreas Gohr 803*72b2703bSAndreas Gohr```````````````````````````````` example 804*72b2703bSAndreas Gohr####### foo 805*72b2703bSAndreas Gohr. 806*72b2703bSAndreas Gohr<p>####### foo</p> 807*72b2703bSAndreas Gohr```````````````````````````````` 808*72b2703bSAndreas Gohr 809*72b2703bSAndreas Gohr 810*72b2703bSAndreas GohrAt least one space is required between the `#` characters and the 811*72b2703bSAndreas Gohrheading's contents, unless the heading is empty. Note that many 812*72b2703bSAndreas Gohrimplementations currently do not require the space. However, the 813*72b2703bSAndreas Gohrspace was required by the 814*72b2703bSAndreas Gohr[original ATX implementation](http://www.aaronsw.com/2002/atx/atx.py), 815*72b2703bSAndreas Gohrand it helps prevent things like the following from being parsed as 816*72b2703bSAndreas Gohrheadings: 817*72b2703bSAndreas Gohr 818*72b2703bSAndreas Gohr```````````````````````````````` example 819*72b2703bSAndreas Gohr#5 bolt 820*72b2703bSAndreas Gohr 821*72b2703bSAndreas Gohr#hashtag 822*72b2703bSAndreas Gohr. 823*72b2703bSAndreas Gohr<p>#5 bolt</p> 824*72b2703bSAndreas Gohr<p>#hashtag</p> 825*72b2703bSAndreas Gohr```````````````````````````````` 826*72b2703bSAndreas Gohr 827*72b2703bSAndreas Gohr 828*72b2703bSAndreas GohrThis is not a heading, because the first `#` is escaped: 829*72b2703bSAndreas Gohr 830*72b2703bSAndreas Gohr```````````````````````````````` example 831*72b2703bSAndreas Gohr\## foo 832*72b2703bSAndreas Gohr. 833*72b2703bSAndreas Gohr<p>## foo</p> 834*72b2703bSAndreas Gohr```````````````````````````````` 835*72b2703bSAndreas Gohr 836*72b2703bSAndreas Gohr 837*72b2703bSAndreas GohrContents are parsed as inlines: 838*72b2703bSAndreas Gohr 839*72b2703bSAndreas Gohr```````````````````````````````` example 840*72b2703bSAndreas Gohr# foo *bar* \*baz\* 841*72b2703bSAndreas Gohr. 842*72b2703bSAndreas Gohr<h1>foo <em>bar</em> *baz*</h1> 843*72b2703bSAndreas Gohr```````````````````````````````` 844*72b2703bSAndreas Gohr 845*72b2703bSAndreas Gohr 846*72b2703bSAndreas GohrLeading and trailing [whitespace] is ignored in parsing inline content: 847*72b2703bSAndreas Gohr 848*72b2703bSAndreas Gohr```````````````````````````````` example 849*72b2703bSAndreas Gohr# foo 850*72b2703bSAndreas Gohr. 851*72b2703bSAndreas Gohr<h1>foo</h1> 852*72b2703bSAndreas Gohr```````````````````````````````` 853*72b2703bSAndreas Gohr 854*72b2703bSAndreas Gohr 855*72b2703bSAndreas GohrOne to three spaces indentation are allowed: 856*72b2703bSAndreas Gohr 857*72b2703bSAndreas Gohr```````````````````````````````` example 858*72b2703bSAndreas Gohr ### foo 859*72b2703bSAndreas Gohr ## foo 860*72b2703bSAndreas Gohr # foo 861*72b2703bSAndreas Gohr. 862*72b2703bSAndreas Gohr<h3>foo</h3> 863*72b2703bSAndreas Gohr<h2>foo</h2> 864*72b2703bSAndreas Gohr<h1>foo</h1> 865*72b2703bSAndreas Gohr```````````````````````````````` 866*72b2703bSAndreas Gohr 867*72b2703bSAndreas Gohr 868*72b2703bSAndreas GohrFour spaces are too much: 869*72b2703bSAndreas Gohr 870*72b2703bSAndreas Gohr```````````````````````````````` example 871*72b2703bSAndreas Gohr # foo 872*72b2703bSAndreas Gohr. 873*72b2703bSAndreas Gohr<pre><code># foo 874*72b2703bSAndreas Gohr</code></pre> 875*72b2703bSAndreas Gohr```````````````````````````````` 876*72b2703bSAndreas Gohr 877*72b2703bSAndreas Gohr 878*72b2703bSAndreas Gohr```````````````````````````````` example 879*72b2703bSAndreas Gohrfoo 880*72b2703bSAndreas Gohr # bar 881*72b2703bSAndreas Gohr. 882*72b2703bSAndreas Gohr<p>foo 883*72b2703bSAndreas Gohr# bar</p> 884*72b2703bSAndreas Gohr```````````````````````````````` 885*72b2703bSAndreas Gohr 886*72b2703bSAndreas Gohr 887*72b2703bSAndreas GohrA closing sequence of `#` characters is optional: 888*72b2703bSAndreas Gohr 889*72b2703bSAndreas Gohr```````````````````````````````` example 890*72b2703bSAndreas Gohr## foo ## 891*72b2703bSAndreas Gohr ### bar ### 892*72b2703bSAndreas Gohr. 893*72b2703bSAndreas Gohr<h2>foo</h2> 894*72b2703bSAndreas Gohr<h3>bar</h3> 895*72b2703bSAndreas Gohr```````````````````````````````` 896*72b2703bSAndreas Gohr 897*72b2703bSAndreas Gohr 898*72b2703bSAndreas GohrIt need not be the same length as the opening sequence: 899*72b2703bSAndreas Gohr 900*72b2703bSAndreas Gohr```````````````````````````````` example 901*72b2703bSAndreas Gohr# foo ################################## 902*72b2703bSAndreas Gohr##### foo ## 903*72b2703bSAndreas Gohr. 904*72b2703bSAndreas Gohr<h1>foo</h1> 905*72b2703bSAndreas Gohr<h5>foo</h5> 906*72b2703bSAndreas Gohr```````````````````````````````` 907*72b2703bSAndreas Gohr 908*72b2703bSAndreas Gohr 909*72b2703bSAndreas GohrSpaces are allowed after the closing sequence: 910*72b2703bSAndreas Gohr 911*72b2703bSAndreas Gohr```````````````````````````````` example 912*72b2703bSAndreas Gohr### foo ### 913*72b2703bSAndreas Gohr. 914*72b2703bSAndreas Gohr<h3>foo</h3> 915*72b2703bSAndreas Gohr```````````````````````````````` 916*72b2703bSAndreas Gohr 917*72b2703bSAndreas Gohr 918*72b2703bSAndreas GohrA sequence of `#` characters with anything but [spaces] following it 919*72b2703bSAndreas Gohris not a closing sequence, but counts as part of the contents of the 920*72b2703bSAndreas Gohrheading: 921*72b2703bSAndreas Gohr 922*72b2703bSAndreas Gohr```````````````````````````````` example 923*72b2703bSAndreas Gohr### foo ### b 924*72b2703bSAndreas Gohr. 925*72b2703bSAndreas Gohr<h3>foo ### b</h3> 926*72b2703bSAndreas Gohr```````````````````````````````` 927*72b2703bSAndreas Gohr 928*72b2703bSAndreas Gohr 929*72b2703bSAndreas GohrThe closing sequence must be preceded by a space: 930*72b2703bSAndreas Gohr 931*72b2703bSAndreas Gohr```````````````````````````````` example 932*72b2703bSAndreas Gohr# foo# 933*72b2703bSAndreas Gohr. 934*72b2703bSAndreas Gohr<h1>foo#</h1> 935*72b2703bSAndreas Gohr```````````````````````````````` 936*72b2703bSAndreas Gohr 937*72b2703bSAndreas Gohr 938*72b2703bSAndreas GohrBackslash-escaped `#` characters do not count as part 939*72b2703bSAndreas Gohrof the closing sequence: 940*72b2703bSAndreas Gohr 941*72b2703bSAndreas Gohr```````````````````````````````` example 942*72b2703bSAndreas Gohr### foo \### 943*72b2703bSAndreas Gohr## foo #\## 944*72b2703bSAndreas Gohr# foo \# 945*72b2703bSAndreas Gohr. 946*72b2703bSAndreas Gohr<h3>foo ###</h3> 947*72b2703bSAndreas Gohr<h2>foo ###</h2> 948*72b2703bSAndreas Gohr<h1>foo #</h1> 949*72b2703bSAndreas Gohr```````````````````````````````` 950*72b2703bSAndreas Gohr 951*72b2703bSAndreas Gohr 952*72b2703bSAndreas GohrATX headings need not be separated from surrounding content by blank 953*72b2703bSAndreas Gohrlines, and they can interrupt paragraphs: 954*72b2703bSAndreas Gohr 955*72b2703bSAndreas Gohr```````````````````````````````` example 956*72b2703bSAndreas Gohr**** 957*72b2703bSAndreas Gohr## foo 958*72b2703bSAndreas Gohr**** 959*72b2703bSAndreas Gohr. 960*72b2703bSAndreas Gohr<hr /> 961*72b2703bSAndreas Gohr<h2>foo</h2> 962*72b2703bSAndreas Gohr<hr /> 963*72b2703bSAndreas Gohr```````````````````````````````` 964*72b2703bSAndreas Gohr 965*72b2703bSAndreas Gohr 966*72b2703bSAndreas Gohr```````````````````````````````` example 967*72b2703bSAndreas GohrFoo bar 968*72b2703bSAndreas Gohr# baz 969*72b2703bSAndreas GohrBar foo 970*72b2703bSAndreas Gohr. 971*72b2703bSAndreas Gohr<p>Foo bar</p> 972*72b2703bSAndreas Gohr<h1>baz</h1> 973*72b2703bSAndreas Gohr<p>Bar foo</p> 974*72b2703bSAndreas Gohr```````````````````````````````` 975*72b2703bSAndreas Gohr 976*72b2703bSAndreas Gohr 977*72b2703bSAndreas GohrATX headings can be empty: 978*72b2703bSAndreas Gohr 979*72b2703bSAndreas Gohr```````````````````````````````` example 980*72b2703bSAndreas Gohr## 981*72b2703bSAndreas Gohr# 982*72b2703bSAndreas Gohr### ### 983*72b2703bSAndreas Gohr. 984*72b2703bSAndreas Gohr<h2></h2> 985*72b2703bSAndreas Gohr<h1></h1> 986*72b2703bSAndreas Gohr<h3></h3> 987*72b2703bSAndreas Gohr```````````````````````````````` 988*72b2703bSAndreas Gohr 989*72b2703bSAndreas Gohr 990*72b2703bSAndreas Gohr## Setext headings 991*72b2703bSAndreas Gohr 992*72b2703bSAndreas GohrA [setext heading](@) consists of one or more 993*72b2703bSAndreas Gohrlines of text, each containing at least one [non-whitespace 994*72b2703bSAndreas Gohrcharacter], with no more than 3 spaces indentation, followed by 995*72b2703bSAndreas Gohra [setext heading underline]. The lines of text must be such 996*72b2703bSAndreas Gohrthat, were they not followed by the setext heading underline, 997*72b2703bSAndreas Gohrthey would be interpreted as a paragraph: they cannot be 998*72b2703bSAndreas Gohrinterpretable as a [code fence], [ATX heading][ATX headings], 999*72b2703bSAndreas Gohr[block quote][block quotes], [thematic break][thematic breaks], 1000*72b2703bSAndreas Gohr[list item][list items], or [HTML block][HTML blocks]. 1001*72b2703bSAndreas Gohr 1002*72b2703bSAndreas GohrA [setext heading underline](@) is a sequence of 1003*72b2703bSAndreas Gohr`=` characters or a sequence of `-` characters, with no more than 3 1004*72b2703bSAndreas Gohrspaces of indentation and any number of trailing spaces or tabs. 1005*72b2703bSAndreas Gohr 1006*72b2703bSAndreas GohrThe heading is a level 1 heading if `=` characters are used in 1007*72b2703bSAndreas Gohrthe [setext heading underline], and a level 2 heading if `-` 1008*72b2703bSAndreas Gohrcharacters are used. The contents of the heading are the result 1009*72b2703bSAndreas Gohrof parsing the preceding lines of text as CommonMark inline 1010*72b2703bSAndreas Gohrcontent. 1011*72b2703bSAndreas Gohr 1012*72b2703bSAndreas GohrIn general, a setext heading need not be preceded or followed by a 1013*72b2703bSAndreas Gohrblank line. However, it cannot interrupt a paragraph, so when a 1014*72b2703bSAndreas Gohrsetext heading comes after a paragraph, a blank line is needed between 1015*72b2703bSAndreas Gohrthem. 1016*72b2703bSAndreas Gohr 1017*72b2703bSAndreas GohrSimple examples: 1018*72b2703bSAndreas Gohr 1019*72b2703bSAndreas Gohr```````````````````````````````` example 1020*72b2703bSAndreas GohrFoo *bar* 1021*72b2703bSAndreas Gohr========= 1022*72b2703bSAndreas Gohr 1023*72b2703bSAndreas GohrFoo *bar* 1024*72b2703bSAndreas Gohr--------- 1025*72b2703bSAndreas Gohr. 1026*72b2703bSAndreas Gohr<h1>Foo <em>bar</em></h1> 1027*72b2703bSAndreas Gohr<h2>Foo <em>bar</em></h2> 1028*72b2703bSAndreas Gohr```````````````````````````````` 1029*72b2703bSAndreas Gohr 1030*72b2703bSAndreas Gohr 1031*72b2703bSAndreas GohrThe content of the header may span more than one line: 1032*72b2703bSAndreas Gohr 1033*72b2703bSAndreas Gohr```````````````````````````````` example 1034*72b2703bSAndreas GohrFoo *bar 1035*72b2703bSAndreas Gohrbaz* 1036*72b2703bSAndreas Gohr==== 1037*72b2703bSAndreas Gohr. 1038*72b2703bSAndreas Gohr<h1>Foo <em>bar 1039*72b2703bSAndreas Gohrbaz</em></h1> 1040*72b2703bSAndreas Gohr```````````````````````````````` 1041*72b2703bSAndreas Gohr 1042*72b2703bSAndreas GohrThe contents are the result of parsing the headings's raw 1043*72b2703bSAndreas Gohrcontent as inlines. The heading's raw content is formed by 1044*72b2703bSAndreas Gohrconcatenating the lines and removing initial and final 1045*72b2703bSAndreas Gohr[whitespace]. 1046*72b2703bSAndreas Gohr 1047*72b2703bSAndreas Gohr```````````````````````````````` example 1048*72b2703bSAndreas Gohr Foo *bar 1049*72b2703bSAndreas Gohrbaz*→ 1050*72b2703bSAndreas Gohr==== 1051*72b2703bSAndreas Gohr. 1052*72b2703bSAndreas Gohr<h1>Foo <em>bar 1053*72b2703bSAndreas Gohrbaz</em></h1> 1054*72b2703bSAndreas Gohr```````````````````````````````` 1055*72b2703bSAndreas Gohr 1056*72b2703bSAndreas Gohr 1057*72b2703bSAndreas GohrThe underlining can be any length: 1058*72b2703bSAndreas Gohr 1059*72b2703bSAndreas Gohr```````````````````````````````` example 1060*72b2703bSAndreas GohrFoo 1061*72b2703bSAndreas Gohr------------------------- 1062*72b2703bSAndreas Gohr 1063*72b2703bSAndreas GohrFoo 1064*72b2703bSAndreas Gohr= 1065*72b2703bSAndreas Gohr. 1066*72b2703bSAndreas Gohr<h2>Foo</h2> 1067*72b2703bSAndreas Gohr<h1>Foo</h1> 1068*72b2703bSAndreas Gohr```````````````````````````````` 1069*72b2703bSAndreas Gohr 1070*72b2703bSAndreas Gohr 1071*72b2703bSAndreas GohrThe heading content can be indented up to three spaces, and need 1072*72b2703bSAndreas Gohrnot line up with the underlining: 1073*72b2703bSAndreas Gohr 1074*72b2703bSAndreas Gohr```````````````````````````````` example 1075*72b2703bSAndreas Gohr Foo 1076*72b2703bSAndreas Gohr--- 1077*72b2703bSAndreas Gohr 1078*72b2703bSAndreas Gohr Foo 1079*72b2703bSAndreas Gohr----- 1080*72b2703bSAndreas Gohr 1081*72b2703bSAndreas Gohr Foo 1082*72b2703bSAndreas Gohr === 1083*72b2703bSAndreas Gohr. 1084*72b2703bSAndreas Gohr<h2>Foo</h2> 1085*72b2703bSAndreas Gohr<h2>Foo</h2> 1086*72b2703bSAndreas Gohr<h1>Foo</h1> 1087*72b2703bSAndreas Gohr```````````````````````````````` 1088*72b2703bSAndreas Gohr 1089*72b2703bSAndreas Gohr 1090*72b2703bSAndreas GohrFour spaces indent is too much: 1091*72b2703bSAndreas Gohr 1092*72b2703bSAndreas Gohr```````````````````````````````` example 1093*72b2703bSAndreas Gohr Foo 1094*72b2703bSAndreas Gohr --- 1095*72b2703bSAndreas Gohr 1096*72b2703bSAndreas Gohr Foo 1097*72b2703bSAndreas Gohr--- 1098*72b2703bSAndreas Gohr. 1099*72b2703bSAndreas Gohr<pre><code>Foo 1100*72b2703bSAndreas Gohr--- 1101*72b2703bSAndreas Gohr 1102*72b2703bSAndreas GohrFoo 1103*72b2703bSAndreas Gohr</code></pre> 1104*72b2703bSAndreas Gohr<hr /> 1105*72b2703bSAndreas Gohr```````````````````````````````` 1106*72b2703bSAndreas Gohr 1107*72b2703bSAndreas Gohr 1108*72b2703bSAndreas GohrThe setext heading underline can be indented up to three spaces, and 1109*72b2703bSAndreas Gohrmay have trailing spaces: 1110*72b2703bSAndreas Gohr 1111*72b2703bSAndreas Gohr```````````````````````````````` example 1112*72b2703bSAndreas GohrFoo 1113*72b2703bSAndreas Gohr ---- 1114*72b2703bSAndreas Gohr. 1115*72b2703bSAndreas Gohr<h2>Foo</h2> 1116*72b2703bSAndreas Gohr```````````````````````````````` 1117*72b2703bSAndreas Gohr 1118*72b2703bSAndreas Gohr 1119*72b2703bSAndreas GohrFour spaces is too much: 1120*72b2703bSAndreas Gohr 1121*72b2703bSAndreas Gohr```````````````````````````````` example 1122*72b2703bSAndreas GohrFoo 1123*72b2703bSAndreas Gohr --- 1124*72b2703bSAndreas Gohr. 1125*72b2703bSAndreas Gohr<p>Foo 1126*72b2703bSAndreas Gohr---</p> 1127*72b2703bSAndreas Gohr```````````````````````````````` 1128*72b2703bSAndreas Gohr 1129*72b2703bSAndreas Gohr 1130*72b2703bSAndreas GohrThe setext heading underline cannot contain internal spaces: 1131*72b2703bSAndreas Gohr 1132*72b2703bSAndreas Gohr```````````````````````````````` example 1133*72b2703bSAndreas GohrFoo 1134*72b2703bSAndreas Gohr= = 1135*72b2703bSAndreas Gohr 1136*72b2703bSAndreas GohrFoo 1137*72b2703bSAndreas Gohr--- - 1138*72b2703bSAndreas Gohr. 1139*72b2703bSAndreas Gohr<p>Foo 1140*72b2703bSAndreas Gohr= =</p> 1141*72b2703bSAndreas Gohr<p>Foo</p> 1142*72b2703bSAndreas Gohr<hr /> 1143*72b2703bSAndreas Gohr```````````````````````````````` 1144*72b2703bSAndreas Gohr 1145*72b2703bSAndreas Gohr 1146*72b2703bSAndreas GohrTrailing spaces in the content line do not cause a line break: 1147*72b2703bSAndreas Gohr 1148*72b2703bSAndreas Gohr```````````````````````````````` example 1149*72b2703bSAndreas GohrFoo 1150*72b2703bSAndreas Gohr----- 1151*72b2703bSAndreas Gohr. 1152*72b2703bSAndreas Gohr<h2>Foo</h2> 1153*72b2703bSAndreas Gohr```````````````````````````````` 1154*72b2703bSAndreas Gohr 1155*72b2703bSAndreas Gohr 1156*72b2703bSAndreas GohrNor does a backslash at the end: 1157*72b2703bSAndreas Gohr 1158*72b2703bSAndreas Gohr```````````````````````````````` example 1159*72b2703bSAndreas GohrFoo\ 1160*72b2703bSAndreas Gohr---- 1161*72b2703bSAndreas Gohr. 1162*72b2703bSAndreas Gohr<h2>Foo\</h2> 1163*72b2703bSAndreas Gohr```````````````````````````````` 1164*72b2703bSAndreas Gohr 1165*72b2703bSAndreas Gohr 1166*72b2703bSAndreas GohrSince indicators of block structure take precedence over 1167*72b2703bSAndreas Gohrindicators of inline structure, the following are setext headings: 1168*72b2703bSAndreas Gohr 1169*72b2703bSAndreas Gohr```````````````````````````````` example 1170*72b2703bSAndreas Gohr`Foo 1171*72b2703bSAndreas Gohr---- 1172*72b2703bSAndreas Gohr` 1173*72b2703bSAndreas Gohr 1174*72b2703bSAndreas Gohr<a title="a lot 1175*72b2703bSAndreas Gohr--- 1176*72b2703bSAndreas Gohrof dashes"/> 1177*72b2703bSAndreas Gohr. 1178*72b2703bSAndreas Gohr<h2>`Foo</h2> 1179*72b2703bSAndreas Gohr<p>`</p> 1180*72b2703bSAndreas Gohr<h2><a title="a lot</h2> 1181*72b2703bSAndreas Gohr<p>of dashes"/></p> 1182*72b2703bSAndreas Gohr```````````````````````````````` 1183*72b2703bSAndreas Gohr 1184*72b2703bSAndreas Gohr 1185*72b2703bSAndreas GohrThe setext heading underline cannot be a [lazy continuation 1186*72b2703bSAndreas Gohrline] in a list item or block quote: 1187*72b2703bSAndreas Gohr 1188*72b2703bSAndreas Gohr```````````````````````````````` example 1189*72b2703bSAndreas Gohr> Foo 1190*72b2703bSAndreas Gohr--- 1191*72b2703bSAndreas Gohr. 1192*72b2703bSAndreas Gohr<blockquote> 1193*72b2703bSAndreas Gohr<p>Foo</p> 1194*72b2703bSAndreas Gohr</blockquote> 1195*72b2703bSAndreas Gohr<hr /> 1196*72b2703bSAndreas Gohr```````````````````````````````` 1197*72b2703bSAndreas Gohr 1198*72b2703bSAndreas Gohr 1199*72b2703bSAndreas Gohr```````````````````````````````` example 1200*72b2703bSAndreas Gohr> foo 1201*72b2703bSAndreas Gohrbar 1202*72b2703bSAndreas Gohr=== 1203*72b2703bSAndreas Gohr. 1204*72b2703bSAndreas Gohr<blockquote> 1205*72b2703bSAndreas Gohr<p>foo 1206*72b2703bSAndreas Gohrbar 1207*72b2703bSAndreas Gohr===</p> 1208*72b2703bSAndreas Gohr</blockquote> 1209*72b2703bSAndreas Gohr```````````````````````````````` 1210*72b2703bSAndreas Gohr 1211*72b2703bSAndreas Gohr 1212*72b2703bSAndreas Gohr```````````````````````````````` example 1213*72b2703bSAndreas Gohr- Foo 1214*72b2703bSAndreas Gohr--- 1215*72b2703bSAndreas Gohr. 1216*72b2703bSAndreas Gohr<ul> 1217*72b2703bSAndreas Gohr<li>Foo</li> 1218*72b2703bSAndreas Gohr</ul> 1219*72b2703bSAndreas Gohr<hr /> 1220*72b2703bSAndreas Gohr```````````````````````````````` 1221*72b2703bSAndreas Gohr 1222*72b2703bSAndreas Gohr 1223*72b2703bSAndreas GohrA blank line is needed between a paragraph and a following 1224*72b2703bSAndreas Gohrsetext heading, since otherwise the paragraph becomes part 1225*72b2703bSAndreas Gohrof the heading's content: 1226*72b2703bSAndreas Gohr 1227*72b2703bSAndreas Gohr```````````````````````````````` example 1228*72b2703bSAndreas GohrFoo 1229*72b2703bSAndreas GohrBar 1230*72b2703bSAndreas Gohr--- 1231*72b2703bSAndreas Gohr. 1232*72b2703bSAndreas Gohr<h2>Foo 1233*72b2703bSAndreas GohrBar</h2> 1234*72b2703bSAndreas Gohr```````````````````````````````` 1235*72b2703bSAndreas Gohr 1236*72b2703bSAndreas Gohr 1237*72b2703bSAndreas GohrBut in general a blank line is not required before or after 1238*72b2703bSAndreas Gohrsetext headings: 1239*72b2703bSAndreas Gohr 1240*72b2703bSAndreas Gohr```````````````````````````````` example 1241*72b2703bSAndreas Gohr--- 1242*72b2703bSAndreas GohrFoo 1243*72b2703bSAndreas Gohr--- 1244*72b2703bSAndreas GohrBar 1245*72b2703bSAndreas Gohr--- 1246*72b2703bSAndreas GohrBaz 1247*72b2703bSAndreas Gohr. 1248*72b2703bSAndreas Gohr<hr /> 1249*72b2703bSAndreas Gohr<h2>Foo</h2> 1250*72b2703bSAndreas Gohr<h2>Bar</h2> 1251*72b2703bSAndreas Gohr<p>Baz</p> 1252*72b2703bSAndreas Gohr```````````````````````````````` 1253*72b2703bSAndreas Gohr 1254*72b2703bSAndreas Gohr 1255*72b2703bSAndreas GohrSetext headings cannot be empty: 1256*72b2703bSAndreas Gohr 1257*72b2703bSAndreas Gohr```````````````````````````````` example 1258*72b2703bSAndreas Gohr 1259*72b2703bSAndreas Gohr==== 1260*72b2703bSAndreas Gohr. 1261*72b2703bSAndreas Gohr<p>====</p> 1262*72b2703bSAndreas Gohr```````````````````````````````` 1263*72b2703bSAndreas Gohr 1264*72b2703bSAndreas Gohr 1265*72b2703bSAndreas GohrSetext heading text lines must not be interpretable as block 1266*72b2703bSAndreas Gohrconstructs other than paragraphs. So, the line of dashes 1267*72b2703bSAndreas Gohrin these examples gets interpreted as a thematic break: 1268*72b2703bSAndreas Gohr 1269*72b2703bSAndreas Gohr```````````````````````````````` example 1270*72b2703bSAndreas Gohr--- 1271*72b2703bSAndreas Gohr--- 1272*72b2703bSAndreas Gohr. 1273*72b2703bSAndreas Gohr<hr /> 1274*72b2703bSAndreas Gohr<hr /> 1275*72b2703bSAndreas Gohr```````````````````````````````` 1276*72b2703bSAndreas Gohr 1277*72b2703bSAndreas Gohr 1278*72b2703bSAndreas Gohr```````````````````````````````` example 1279*72b2703bSAndreas Gohr- foo 1280*72b2703bSAndreas Gohr----- 1281*72b2703bSAndreas Gohr. 1282*72b2703bSAndreas Gohr<ul> 1283*72b2703bSAndreas Gohr<li>foo</li> 1284*72b2703bSAndreas Gohr</ul> 1285*72b2703bSAndreas Gohr<hr /> 1286*72b2703bSAndreas Gohr```````````````````````````````` 1287*72b2703bSAndreas Gohr 1288*72b2703bSAndreas Gohr 1289*72b2703bSAndreas Gohr```````````````````````````````` example 1290*72b2703bSAndreas Gohr foo 1291*72b2703bSAndreas Gohr--- 1292*72b2703bSAndreas Gohr. 1293*72b2703bSAndreas Gohr<pre><code>foo 1294*72b2703bSAndreas Gohr</code></pre> 1295*72b2703bSAndreas Gohr<hr /> 1296*72b2703bSAndreas Gohr```````````````````````````````` 1297*72b2703bSAndreas Gohr 1298*72b2703bSAndreas Gohr 1299*72b2703bSAndreas Gohr```````````````````````````````` example 1300*72b2703bSAndreas Gohr> foo 1301*72b2703bSAndreas Gohr----- 1302*72b2703bSAndreas Gohr. 1303*72b2703bSAndreas Gohr<blockquote> 1304*72b2703bSAndreas Gohr<p>foo</p> 1305*72b2703bSAndreas Gohr</blockquote> 1306*72b2703bSAndreas Gohr<hr /> 1307*72b2703bSAndreas Gohr```````````````````````````````` 1308*72b2703bSAndreas Gohr 1309*72b2703bSAndreas Gohr 1310*72b2703bSAndreas GohrIf you want a heading with `> foo` as its literal text, you can 1311*72b2703bSAndreas Gohruse backslash escapes: 1312*72b2703bSAndreas Gohr 1313*72b2703bSAndreas Gohr```````````````````````````````` example 1314*72b2703bSAndreas Gohr\> foo 1315*72b2703bSAndreas Gohr------ 1316*72b2703bSAndreas Gohr. 1317*72b2703bSAndreas Gohr<h2>> foo</h2> 1318*72b2703bSAndreas Gohr```````````````````````````````` 1319*72b2703bSAndreas Gohr 1320*72b2703bSAndreas Gohr 1321*72b2703bSAndreas Gohr**Compatibility note:** Most existing Markdown implementations 1322*72b2703bSAndreas Gohrdo not allow the text of setext headings to span multiple lines. 1323*72b2703bSAndreas GohrBut there is no consensus about how to interpret 1324*72b2703bSAndreas Gohr 1325*72b2703bSAndreas Gohr``` markdown 1326*72b2703bSAndreas GohrFoo 1327*72b2703bSAndreas Gohrbar 1328*72b2703bSAndreas Gohr--- 1329*72b2703bSAndreas Gohrbaz 1330*72b2703bSAndreas Gohr``` 1331*72b2703bSAndreas Gohr 1332*72b2703bSAndreas GohrOne can find four different interpretations: 1333*72b2703bSAndreas Gohr 1334*72b2703bSAndreas Gohr1. paragraph "Foo", heading "bar", paragraph "baz" 1335*72b2703bSAndreas Gohr2. paragraph "Foo bar", thematic break, paragraph "baz" 1336*72b2703bSAndreas Gohr3. paragraph "Foo bar --- baz" 1337*72b2703bSAndreas Gohr4. heading "Foo bar", paragraph "baz" 1338*72b2703bSAndreas Gohr 1339*72b2703bSAndreas GohrWe find interpretation 4 most natural, and interpretation 4 1340*72b2703bSAndreas Gohrincreases the expressive power of CommonMark, by allowing 1341*72b2703bSAndreas Gohrmultiline headings. Authors who want interpretation 1 can 1342*72b2703bSAndreas Gohrput a blank line after the first paragraph: 1343*72b2703bSAndreas Gohr 1344*72b2703bSAndreas Gohr```````````````````````````````` example 1345*72b2703bSAndreas GohrFoo 1346*72b2703bSAndreas Gohr 1347*72b2703bSAndreas Gohrbar 1348*72b2703bSAndreas Gohr--- 1349*72b2703bSAndreas Gohrbaz 1350*72b2703bSAndreas Gohr. 1351*72b2703bSAndreas Gohr<p>Foo</p> 1352*72b2703bSAndreas Gohr<h2>bar</h2> 1353*72b2703bSAndreas Gohr<p>baz</p> 1354*72b2703bSAndreas Gohr```````````````````````````````` 1355*72b2703bSAndreas Gohr 1356*72b2703bSAndreas Gohr 1357*72b2703bSAndreas GohrAuthors who want interpretation 2 can put blank lines around 1358*72b2703bSAndreas Gohrthe thematic break, 1359*72b2703bSAndreas Gohr 1360*72b2703bSAndreas Gohr```````````````````````````````` example 1361*72b2703bSAndreas GohrFoo 1362*72b2703bSAndreas Gohrbar 1363*72b2703bSAndreas Gohr 1364*72b2703bSAndreas Gohr--- 1365*72b2703bSAndreas Gohr 1366*72b2703bSAndreas Gohrbaz 1367*72b2703bSAndreas Gohr. 1368*72b2703bSAndreas Gohr<p>Foo 1369*72b2703bSAndreas Gohrbar</p> 1370*72b2703bSAndreas Gohr<hr /> 1371*72b2703bSAndreas Gohr<p>baz</p> 1372*72b2703bSAndreas Gohr```````````````````````````````` 1373*72b2703bSAndreas Gohr 1374*72b2703bSAndreas Gohr 1375*72b2703bSAndreas Gohror use a thematic break that cannot count as a [setext heading 1376*72b2703bSAndreas Gohrunderline], such as 1377*72b2703bSAndreas Gohr 1378*72b2703bSAndreas Gohr```````````````````````````````` example 1379*72b2703bSAndreas GohrFoo 1380*72b2703bSAndreas Gohrbar 1381*72b2703bSAndreas Gohr* * * 1382*72b2703bSAndreas Gohrbaz 1383*72b2703bSAndreas Gohr. 1384*72b2703bSAndreas Gohr<p>Foo 1385*72b2703bSAndreas Gohrbar</p> 1386*72b2703bSAndreas Gohr<hr /> 1387*72b2703bSAndreas Gohr<p>baz</p> 1388*72b2703bSAndreas Gohr```````````````````````````````` 1389*72b2703bSAndreas Gohr 1390*72b2703bSAndreas Gohr 1391*72b2703bSAndreas GohrAuthors who want interpretation 3 can use backslash escapes: 1392*72b2703bSAndreas Gohr 1393*72b2703bSAndreas Gohr```````````````````````````````` example 1394*72b2703bSAndreas GohrFoo 1395*72b2703bSAndreas Gohrbar 1396*72b2703bSAndreas Gohr\--- 1397*72b2703bSAndreas Gohrbaz 1398*72b2703bSAndreas Gohr. 1399*72b2703bSAndreas Gohr<p>Foo 1400*72b2703bSAndreas Gohrbar 1401*72b2703bSAndreas Gohr--- 1402*72b2703bSAndreas Gohrbaz</p> 1403*72b2703bSAndreas Gohr```````````````````````````````` 1404*72b2703bSAndreas Gohr 1405*72b2703bSAndreas Gohr 1406*72b2703bSAndreas Gohr## Indented code blocks 1407*72b2703bSAndreas Gohr 1408*72b2703bSAndreas GohrAn [indented code block](@) is composed of one or more 1409*72b2703bSAndreas Gohr[indented chunks] separated by blank lines. 1410*72b2703bSAndreas GohrAn [indented chunk](@) is a sequence of non-blank lines, 1411*72b2703bSAndreas Gohreach indented four or more spaces. The contents of the code block are 1412*72b2703bSAndreas Gohrthe literal contents of the lines, including trailing 1413*72b2703bSAndreas Gohr[line endings], minus four spaces of indentation. 1414*72b2703bSAndreas GohrAn indented code block has no [info string]. 1415*72b2703bSAndreas Gohr 1416*72b2703bSAndreas GohrAn indented code block cannot interrupt a paragraph, so there must be 1417*72b2703bSAndreas Gohra blank line between a paragraph and a following indented code block. 1418*72b2703bSAndreas Gohr(A blank line is not needed, however, between a code block and a following 1419*72b2703bSAndreas Gohrparagraph.) 1420*72b2703bSAndreas Gohr 1421*72b2703bSAndreas Gohr```````````````````````````````` example 1422*72b2703bSAndreas Gohr a simple 1423*72b2703bSAndreas Gohr indented code block 1424*72b2703bSAndreas Gohr. 1425*72b2703bSAndreas Gohr<pre><code>a simple 1426*72b2703bSAndreas Gohr indented code block 1427*72b2703bSAndreas Gohr</code></pre> 1428*72b2703bSAndreas Gohr```````````````````````````````` 1429*72b2703bSAndreas Gohr 1430*72b2703bSAndreas Gohr 1431*72b2703bSAndreas GohrIf there is any ambiguity between an interpretation of indentation 1432*72b2703bSAndreas Gohras a code block and as indicating that material belongs to a [list 1433*72b2703bSAndreas Gohritem][list items], the list item interpretation takes precedence: 1434*72b2703bSAndreas Gohr 1435*72b2703bSAndreas Gohr```````````````````````````````` example 1436*72b2703bSAndreas Gohr - foo 1437*72b2703bSAndreas Gohr 1438*72b2703bSAndreas Gohr bar 1439*72b2703bSAndreas Gohr. 1440*72b2703bSAndreas Gohr<ul> 1441*72b2703bSAndreas Gohr<li> 1442*72b2703bSAndreas Gohr<p>foo</p> 1443*72b2703bSAndreas Gohr<p>bar</p> 1444*72b2703bSAndreas Gohr</li> 1445*72b2703bSAndreas Gohr</ul> 1446*72b2703bSAndreas Gohr```````````````````````````````` 1447*72b2703bSAndreas Gohr 1448*72b2703bSAndreas Gohr 1449*72b2703bSAndreas Gohr```````````````````````````````` example 1450*72b2703bSAndreas Gohr1. foo 1451*72b2703bSAndreas Gohr 1452*72b2703bSAndreas Gohr - bar 1453*72b2703bSAndreas Gohr. 1454*72b2703bSAndreas Gohr<ol> 1455*72b2703bSAndreas Gohr<li> 1456*72b2703bSAndreas Gohr<p>foo</p> 1457*72b2703bSAndreas Gohr<ul> 1458*72b2703bSAndreas Gohr<li>bar</li> 1459*72b2703bSAndreas Gohr</ul> 1460*72b2703bSAndreas Gohr</li> 1461*72b2703bSAndreas Gohr</ol> 1462*72b2703bSAndreas Gohr```````````````````````````````` 1463*72b2703bSAndreas Gohr 1464*72b2703bSAndreas Gohr 1465*72b2703bSAndreas Gohr 1466*72b2703bSAndreas GohrThe contents of a code block are literal text, and do not get parsed 1467*72b2703bSAndreas Gohras Markdown: 1468*72b2703bSAndreas Gohr 1469*72b2703bSAndreas Gohr```````````````````````````````` example 1470*72b2703bSAndreas Gohr <a/> 1471*72b2703bSAndreas Gohr *hi* 1472*72b2703bSAndreas Gohr 1473*72b2703bSAndreas Gohr - one 1474*72b2703bSAndreas Gohr. 1475*72b2703bSAndreas Gohr<pre><code><a/> 1476*72b2703bSAndreas Gohr*hi* 1477*72b2703bSAndreas Gohr 1478*72b2703bSAndreas Gohr- one 1479*72b2703bSAndreas Gohr</code></pre> 1480*72b2703bSAndreas Gohr```````````````````````````````` 1481*72b2703bSAndreas Gohr 1482*72b2703bSAndreas Gohr 1483*72b2703bSAndreas GohrHere we have three chunks separated by blank lines: 1484*72b2703bSAndreas Gohr 1485*72b2703bSAndreas Gohr```````````````````````````````` example 1486*72b2703bSAndreas Gohr chunk1 1487*72b2703bSAndreas Gohr 1488*72b2703bSAndreas Gohr chunk2 1489*72b2703bSAndreas Gohr 1490*72b2703bSAndreas Gohr 1491*72b2703bSAndreas Gohr 1492*72b2703bSAndreas Gohr chunk3 1493*72b2703bSAndreas Gohr. 1494*72b2703bSAndreas Gohr<pre><code>chunk1 1495*72b2703bSAndreas Gohr 1496*72b2703bSAndreas Gohrchunk2 1497*72b2703bSAndreas Gohr 1498*72b2703bSAndreas Gohr 1499*72b2703bSAndreas Gohr 1500*72b2703bSAndreas Gohrchunk3 1501*72b2703bSAndreas Gohr</code></pre> 1502*72b2703bSAndreas Gohr```````````````````````````````` 1503*72b2703bSAndreas Gohr 1504*72b2703bSAndreas Gohr 1505*72b2703bSAndreas GohrAny initial spaces beyond four will be included in the content, even 1506*72b2703bSAndreas Gohrin interior blank lines: 1507*72b2703bSAndreas Gohr 1508*72b2703bSAndreas Gohr```````````````````````````````` example 1509*72b2703bSAndreas Gohr chunk1 1510*72b2703bSAndreas Gohr 1511*72b2703bSAndreas Gohr chunk2 1512*72b2703bSAndreas Gohr. 1513*72b2703bSAndreas Gohr<pre><code>chunk1 1514*72b2703bSAndreas Gohr 1515*72b2703bSAndreas Gohr chunk2 1516*72b2703bSAndreas Gohr</code></pre> 1517*72b2703bSAndreas Gohr```````````````````````````````` 1518*72b2703bSAndreas Gohr 1519*72b2703bSAndreas Gohr 1520*72b2703bSAndreas GohrAn indented code block cannot interrupt a paragraph. (This 1521*72b2703bSAndreas Gohrallows hanging indents and the like.) 1522*72b2703bSAndreas Gohr 1523*72b2703bSAndreas Gohr```````````````````````````````` example 1524*72b2703bSAndreas GohrFoo 1525*72b2703bSAndreas Gohr bar 1526*72b2703bSAndreas Gohr 1527*72b2703bSAndreas Gohr. 1528*72b2703bSAndreas Gohr<p>Foo 1529*72b2703bSAndreas Gohrbar</p> 1530*72b2703bSAndreas Gohr```````````````````````````````` 1531*72b2703bSAndreas Gohr 1532*72b2703bSAndreas Gohr 1533*72b2703bSAndreas GohrHowever, any non-blank line with fewer than four leading spaces ends 1534*72b2703bSAndreas Gohrthe code block immediately. So a paragraph may occur immediately 1535*72b2703bSAndreas Gohrafter indented code: 1536*72b2703bSAndreas Gohr 1537*72b2703bSAndreas Gohr```````````````````````````````` example 1538*72b2703bSAndreas Gohr foo 1539*72b2703bSAndreas Gohrbar 1540*72b2703bSAndreas Gohr. 1541*72b2703bSAndreas Gohr<pre><code>foo 1542*72b2703bSAndreas Gohr</code></pre> 1543*72b2703bSAndreas Gohr<p>bar</p> 1544*72b2703bSAndreas Gohr```````````````````````````````` 1545*72b2703bSAndreas Gohr 1546*72b2703bSAndreas Gohr 1547*72b2703bSAndreas GohrAnd indented code can occur immediately before and after other kinds of 1548*72b2703bSAndreas Gohrblocks: 1549*72b2703bSAndreas Gohr 1550*72b2703bSAndreas Gohr```````````````````````````````` example 1551*72b2703bSAndreas Gohr# Heading 1552*72b2703bSAndreas Gohr foo 1553*72b2703bSAndreas GohrHeading 1554*72b2703bSAndreas Gohr------ 1555*72b2703bSAndreas Gohr foo 1556*72b2703bSAndreas Gohr---- 1557*72b2703bSAndreas Gohr. 1558*72b2703bSAndreas Gohr<h1>Heading</h1> 1559*72b2703bSAndreas Gohr<pre><code>foo 1560*72b2703bSAndreas Gohr</code></pre> 1561*72b2703bSAndreas Gohr<h2>Heading</h2> 1562*72b2703bSAndreas Gohr<pre><code>foo 1563*72b2703bSAndreas Gohr</code></pre> 1564*72b2703bSAndreas Gohr<hr /> 1565*72b2703bSAndreas Gohr```````````````````````````````` 1566*72b2703bSAndreas Gohr 1567*72b2703bSAndreas Gohr 1568*72b2703bSAndreas GohrThe first line can be indented more than four spaces: 1569*72b2703bSAndreas Gohr 1570*72b2703bSAndreas Gohr```````````````````````````````` example 1571*72b2703bSAndreas Gohr foo 1572*72b2703bSAndreas Gohr bar 1573*72b2703bSAndreas Gohr. 1574*72b2703bSAndreas Gohr<pre><code> foo 1575*72b2703bSAndreas Gohrbar 1576*72b2703bSAndreas Gohr</code></pre> 1577*72b2703bSAndreas Gohr```````````````````````````````` 1578*72b2703bSAndreas Gohr 1579*72b2703bSAndreas Gohr 1580*72b2703bSAndreas GohrBlank lines preceding or following an indented code block 1581*72b2703bSAndreas Gohrare not included in it: 1582*72b2703bSAndreas Gohr 1583*72b2703bSAndreas Gohr```````````````````````````````` example 1584*72b2703bSAndreas Gohr 1585*72b2703bSAndreas Gohr 1586*72b2703bSAndreas Gohr foo 1587*72b2703bSAndreas Gohr 1588*72b2703bSAndreas Gohr 1589*72b2703bSAndreas Gohr. 1590*72b2703bSAndreas Gohr<pre><code>foo 1591*72b2703bSAndreas Gohr</code></pre> 1592*72b2703bSAndreas Gohr```````````````````````````````` 1593*72b2703bSAndreas Gohr 1594*72b2703bSAndreas Gohr 1595*72b2703bSAndreas GohrTrailing spaces are included in the code block's content: 1596*72b2703bSAndreas Gohr 1597*72b2703bSAndreas Gohr```````````````````````````````` example 1598*72b2703bSAndreas Gohr foo 1599*72b2703bSAndreas Gohr. 1600*72b2703bSAndreas Gohr<pre><code>foo 1601*72b2703bSAndreas Gohr</code></pre> 1602*72b2703bSAndreas Gohr```````````````````````````````` 1603*72b2703bSAndreas Gohr 1604*72b2703bSAndreas Gohr 1605*72b2703bSAndreas Gohr 1606*72b2703bSAndreas Gohr## Fenced code blocks 1607*72b2703bSAndreas Gohr 1608*72b2703bSAndreas GohrA [code fence](@) is a sequence 1609*72b2703bSAndreas Gohrof at least three consecutive backtick characters (`` ` ``) or 1610*72b2703bSAndreas Gohrtildes (`~`). (Tildes and backticks cannot be mixed.) 1611*72b2703bSAndreas GohrA [fenced code block](@) 1612*72b2703bSAndreas Gohrbegins with a code fence, indented no more than three spaces. 1613*72b2703bSAndreas Gohr 1614*72b2703bSAndreas GohrThe line with the opening code fence may optionally contain some text 1615*72b2703bSAndreas Gohrfollowing the code fence; this is trimmed of leading and trailing 1616*72b2703bSAndreas Gohrwhitespace and called the [info string](@). If the [info string] comes 1617*72b2703bSAndreas Gohrafter a backtick fence, it may not contain any backtick 1618*72b2703bSAndreas Gohrcharacters. (The reason for this restriction is that otherwise 1619*72b2703bSAndreas Gohrsome inline code would be incorrectly interpreted as the 1620*72b2703bSAndreas Gohrbeginning of a fenced code block.) 1621*72b2703bSAndreas Gohr 1622*72b2703bSAndreas GohrThe content of the code block consists of all subsequent lines, until 1623*72b2703bSAndreas Gohra closing [code fence] of the same type as the code block 1624*72b2703bSAndreas Gohrbegan with (backticks or tildes), and with at least as many backticks 1625*72b2703bSAndreas Gohror tildes as the opening code fence. If the leading code fence is 1626*72b2703bSAndreas Gohrindented N spaces, then up to N spaces of indentation are removed from 1627*72b2703bSAndreas Gohreach line of the content (if present). (If a content line is not 1628*72b2703bSAndreas Gohrindented, it is preserved unchanged. If it is indented less than N 1629*72b2703bSAndreas Gohrspaces, all of the indentation is removed.) 1630*72b2703bSAndreas Gohr 1631*72b2703bSAndreas GohrThe closing code fence may be indented up to three spaces, and may be 1632*72b2703bSAndreas Gohrfollowed only by spaces, which are ignored. If the end of the 1633*72b2703bSAndreas Gohrcontaining block (or document) is reached and no closing code fence 1634*72b2703bSAndreas Gohrhas been found, the code block contains all of the lines after the 1635*72b2703bSAndreas Gohropening code fence until the end of the containing block (or 1636*72b2703bSAndreas Gohrdocument). (An alternative spec would require backtracking in the 1637*72b2703bSAndreas Gohrevent that a closing code fence is not found. But this makes parsing 1638*72b2703bSAndreas Gohrmuch less efficient, and there seems to be no real downside to the 1639*72b2703bSAndreas Gohrbehavior described here.) 1640*72b2703bSAndreas Gohr 1641*72b2703bSAndreas GohrA fenced code block may interrupt a paragraph, and does not require 1642*72b2703bSAndreas Gohra blank line either before or after. 1643*72b2703bSAndreas Gohr 1644*72b2703bSAndreas GohrThe content of a code fence is treated as literal text, not parsed 1645*72b2703bSAndreas Gohras inlines. The first word of the [info string] is typically used to 1646*72b2703bSAndreas Gohrspecify the language of the code sample, and rendered in the `class` 1647*72b2703bSAndreas Gohrattribute of the `code` tag. However, this spec does not mandate any 1648*72b2703bSAndreas Gohrparticular treatment of the [info string]. 1649*72b2703bSAndreas Gohr 1650*72b2703bSAndreas GohrHere is a simple example with backticks: 1651*72b2703bSAndreas Gohr 1652*72b2703bSAndreas Gohr```````````````````````````````` example 1653*72b2703bSAndreas Gohr``` 1654*72b2703bSAndreas Gohr< 1655*72b2703bSAndreas Gohr > 1656*72b2703bSAndreas Gohr``` 1657*72b2703bSAndreas Gohr. 1658*72b2703bSAndreas Gohr<pre><code>< 1659*72b2703bSAndreas Gohr > 1660*72b2703bSAndreas Gohr</code></pre> 1661*72b2703bSAndreas Gohr```````````````````````````````` 1662*72b2703bSAndreas Gohr 1663*72b2703bSAndreas Gohr 1664*72b2703bSAndreas GohrWith tildes: 1665*72b2703bSAndreas Gohr 1666*72b2703bSAndreas Gohr```````````````````````````````` example 1667*72b2703bSAndreas Gohr~~~ 1668*72b2703bSAndreas Gohr< 1669*72b2703bSAndreas Gohr > 1670*72b2703bSAndreas Gohr~~~ 1671*72b2703bSAndreas Gohr. 1672*72b2703bSAndreas Gohr<pre><code>< 1673*72b2703bSAndreas Gohr > 1674*72b2703bSAndreas Gohr</code></pre> 1675*72b2703bSAndreas Gohr```````````````````````````````` 1676*72b2703bSAndreas Gohr 1677*72b2703bSAndreas GohrFewer than three backticks is not enough: 1678*72b2703bSAndreas Gohr 1679*72b2703bSAndreas Gohr```````````````````````````````` example 1680*72b2703bSAndreas Gohr`` 1681*72b2703bSAndreas Gohrfoo 1682*72b2703bSAndreas Gohr`` 1683*72b2703bSAndreas Gohr. 1684*72b2703bSAndreas Gohr<p><code>foo</code></p> 1685*72b2703bSAndreas Gohr```````````````````````````````` 1686*72b2703bSAndreas Gohr 1687*72b2703bSAndreas GohrThe closing code fence must use the same character as the opening 1688*72b2703bSAndreas Gohrfence: 1689*72b2703bSAndreas Gohr 1690*72b2703bSAndreas Gohr```````````````````````````````` example 1691*72b2703bSAndreas Gohr``` 1692*72b2703bSAndreas Gohraaa 1693*72b2703bSAndreas Gohr~~~ 1694*72b2703bSAndreas Gohr``` 1695*72b2703bSAndreas Gohr. 1696*72b2703bSAndreas Gohr<pre><code>aaa 1697*72b2703bSAndreas Gohr~~~ 1698*72b2703bSAndreas Gohr</code></pre> 1699*72b2703bSAndreas Gohr```````````````````````````````` 1700*72b2703bSAndreas Gohr 1701*72b2703bSAndreas Gohr 1702*72b2703bSAndreas Gohr```````````````````````````````` example 1703*72b2703bSAndreas Gohr~~~ 1704*72b2703bSAndreas Gohraaa 1705*72b2703bSAndreas Gohr``` 1706*72b2703bSAndreas Gohr~~~ 1707*72b2703bSAndreas Gohr. 1708*72b2703bSAndreas Gohr<pre><code>aaa 1709*72b2703bSAndreas Gohr``` 1710*72b2703bSAndreas Gohr</code></pre> 1711*72b2703bSAndreas Gohr```````````````````````````````` 1712*72b2703bSAndreas Gohr 1713*72b2703bSAndreas Gohr 1714*72b2703bSAndreas GohrThe closing code fence must be at least as long as the opening fence: 1715*72b2703bSAndreas Gohr 1716*72b2703bSAndreas Gohr```````````````````````````````` example 1717*72b2703bSAndreas Gohr```` 1718*72b2703bSAndreas Gohraaa 1719*72b2703bSAndreas Gohr``` 1720*72b2703bSAndreas Gohr`````` 1721*72b2703bSAndreas Gohr. 1722*72b2703bSAndreas Gohr<pre><code>aaa 1723*72b2703bSAndreas Gohr``` 1724*72b2703bSAndreas Gohr</code></pre> 1725*72b2703bSAndreas Gohr```````````````````````````````` 1726*72b2703bSAndreas Gohr 1727*72b2703bSAndreas Gohr 1728*72b2703bSAndreas Gohr```````````````````````````````` example 1729*72b2703bSAndreas Gohr~~~~ 1730*72b2703bSAndreas Gohraaa 1731*72b2703bSAndreas Gohr~~~ 1732*72b2703bSAndreas Gohr~~~~ 1733*72b2703bSAndreas Gohr. 1734*72b2703bSAndreas Gohr<pre><code>aaa 1735*72b2703bSAndreas Gohr~~~ 1736*72b2703bSAndreas Gohr</code></pre> 1737*72b2703bSAndreas Gohr```````````````````````````````` 1738*72b2703bSAndreas Gohr 1739*72b2703bSAndreas Gohr 1740*72b2703bSAndreas GohrUnclosed code blocks are closed by the end of the document 1741*72b2703bSAndreas Gohr(or the enclosing [block quote][block quotes] or [list item][list items]): 1742*72b2703bSAndreas Gohr 1743*72b2703bSAndreas Gohr```````````````````````````````` example 1744*72b2703bSAndreas Gohr``` 1745*72b2703bSAndreas Gohr. 1746*72b2703bSAndreas Gohr<pre><code></code></pre> 1747*72b2703bSAndreas Gohr```````````````````````````````` 1748*72b2703bSAndreas Gohr 1749*72b2703bSAndreas Gohr 1750*72b2703bSAndreas Gohr```````````````````````````````` example 1751*72b2703bSAndreas Gohr````` 1752*72b2703bSAndreas Gohr 1753*72b2703bSAndreas Gohr``` 1754*72b2703bSAndreas Gohraaa 1755*72b2703bSAndreas Gohr. 1756*72b2703bSAndreas Gohr<pre><code> 1757*72b2703bSAndreas Gohr``` 1758*72b2703bSAndreas Gohraaa 1759*72b2703bSAndreas Gohr</code></pre> 1760*72b2703bSAndreas Gohr```````````````````````````````` 1761*72b2703bSAndreas Gohr 1762*72b2703bSAndreas Gohr 1763*72b2703bSAndreas Gohr```````````````````````````````` example 1764*72b2703bSAndreas Gohr> ``` 1765*72b2703bSAndreas Gohr> aaa 1766*72b2703bSAndreas Gohr 1767*72b2703bSAndreas Gohrbbb 1768*72b2703bSAndreas Gohr. 1769*72b2703bSAndreas Gohr<blockquote> 1770*72b2703bSAndreas Gohr<pre><code>aaa 1771*72b2703bSAndreas Gohr</code></pre> 1772*72b2703bSAndreas Gohr</blockquote> 1773*72b2703bSAndreas Gohr<p>bbb</p> 1774*72b2703bSAndreas Gohr```````````````````````````````` 1775*72b2703bSAndreas Gohr 1776*72b2703bSAndreas Gohr 1777*72b2703bSAndreas GohrA code block can have all empty lines as its content: 1778*72b2703bSAndreas Gohr 1779*72b2703bSAndreas Gohr```````````````````````````````` example 1780*72b2703bSAndreas Gohr``` 1781*72b2703bSAndreas Gohr 1782*72b2703bSAndreas Gohr 1783*72b2703bSAndreas Gohr``` 1784*72b2703bSAndreas Gohr. 1785*72b2703bSAndreas Gohr<pre><code> 1786*72b2703bSAndreas Gohr 1787*72b2703bSAndreas Gohr</code></pre> 1788*72b2703bSAndreas Gohr```````````````````````````````` 1789*72b2703bSAndreas Gohr 1790*72b2703bSAndreas Gohr 1791*72b2703bSAndreas GohrA code block can be empty: 1792*72b2703bSAndreas Gohr 1793*72b2703bSAndreas Gohr```````````````````````````````` example 1794*72b2703bSAndreas Gohr``` 1795*72b2703bSAndreas Gohr``` 1796*72b2703bSAndreas Gohr. 1797*72b2703bSAndreas Gohr<pre><code></code></pre> 1798*72b2703bSAndreas Gohr```````````````````````````````` 1799*72b2703bSAndreas Gohr 1800*72b2703bSAndreas Gohr 1801*72b2703bSAndreas GohrFences can be indented. If the opening fence is indented, 1802*72b2703bSAndreas Gohrcontent lines will have equivalent opening indentation removed, 1803*72b2703bSAndreas Gohrif present: 1804*72b2703bSAndreas Gohr 1805*72b2703bSAndreas Gohr```````````````````````````````` example 1806*72b2703bSAndreas Gohr ``` 1807*72b2703bSAndreas Gohr aaa 1808*72b2703bSAndreas Gohraaa 1809*72b2703bSAndreas Gohr``` 1810*72b2703bSAndreas Gohr. 1811*72b2703bSAndreas Gohr<pre><code>aaa 1812*72b2703bSAndreas Gohraaa 1813*72b2703bSAndreas Gohr</code></pre> 1814*72b2703bSAndreas Gohr```````````````````````````````` 1815*72b2703bSAndreas Gohr 1816*72b2703bSAndreas Gohr 1817*72b2703bSAndreas Gohr```````````````````````````````` example 1818*72b2703bSAndreas Gohr ``` 1819*72b2703bSAndreas Gohraaa 1820*72b2703bSAndreas Gohr aaa 1821*72b2703bSAndreas Gohraaa 1822*72b2703bSAndreas Gohr ``` 1823*72b2703bSAndreas Gohr. 1824*72b2703bSAndreas Gohr<pre><code>aaa 1825*72b2703bSAndreas Gohraaa 1826*72b2703bSAndreas Gohraaa 1827*72b2703bSAndreas Gohr</code></pre> 1828*72b2703bSAndreas Gohr```````````````````````````````` 1829*72b2703bSAndreas Gohr 1830*72b2703bSAndreas Gohr 1831*72b2703bSAndreas Gohr```````````````````````````````` example 1832*72b2703bSAndreas Gohr ``` 1833*72b2703bSAndreas Gohr aaa 1834*72b2703bSAndreas Gohr aaa 1835*72b2703bSAndreas Gohr aaa 1836*72b2703bSAndreas Gohr ``` 1837*72b2703bSAndreas Gohr. 1838*72b2703bSAndreas Gohr<pre><code>aaa 1839*72b2703bSAndreas Gohr aaa 1840*72b2703bSAndreas Gohraaa 1841*72b2703bSAndreas Gohr</code></pre> 1842*72b2703bSAndreas Gohr```````````````````````````````` 1843*72b2703bSAndreas Gohr 1844*72b2703bSAndreas Gohr 1845*72b2703bSAndreas GohrFour spaces indentation produces an indented code block: 1846*72b2703bSAndreas Gohr 1847*72b2703bSAndreas Gohr```````````````````````````````` example 1848*72b2703bSAndreas Gohr ``` 1849*72b2703bSAndreas Gohr aaa 1850*72b2703bSAndreas Gohr ``` 1851*72b2703bSAndreas Gohr. 1852*72b2703bSAndreas Gohr<pre><code>``` 1853*72b2703bSAndreas Gohraaa 1854*72b2703bSAndreas Gohr``` 1855*72b2703bSAndreas Gohr</code></pre> 1856*72b2703bSAndreas Gohr```````````````````````````````` 1857*72b2703bSAndreas Gohr 1858*72b2703bSAndreas Gohr 1859*72b2703bSAndreas GohrClosing fences may be indented by 0-3 spaces, and their indentation 1860*72b2703bSAndreas Gohrneed not match that of the opening fence: 1861*72b2703bSAndreas Gohr 1862*72b2703bSAndreas Gohr```````````````````````````````` example 1863*72b2703bSAndreas Gohr``` 1864*72b2703bSAndreas Gohraaa 1865*72b2703bSAndreas Gohr ``` 1866*72b2703bSAndreas Gohr. 1867*72b2703bSAndreas Gohr<pre><code>aaa 1868*72b2703bSAndreas Gohr</code></pre> 1869*72b2703bSAndreas Gohr```````````````````````````````` 1870*72b2703bSAndreas Gohr 1871*72b2703bSAndreas Gohr 1872*72b2703bSAndreas Gohr```````````````````````````````` example 1873*72b2703bSAndreas Gohr ``` 1874*72b2703bSAndreas Gohraaa 1875*72b2703bSAndreas Gohr ``` 1876*72b2703bSAndreas Gohr. 1877*72b2703bSAndreas Gohr<pre><code>aaa 1878*72b2703bSAndreas Gohr</code></pre> 1879*72b2703bSAndreas Gohr```````````````````````````````` 1880*72b2703bSAndreas Gohr 1881*72b2703bSAndreas Gohr 1882*72b2703bSAndreas GohrThis is not a closing fence, because it is indented 4 spaces: 1883*72b2703bSAndreas Gohr 1884*72b2703bSAndreas Gohr```````````````````````````````` example 1885*72b2703bSAndreas Gohr``` 1886*72b2703bSAndreas Gohraaa 1887*72b2703bSAndreas Gohr ``` 1888*72b2703bSAndreas Gohr. 1889*72b2703bSAndreas Gohr<pre><code>aaa 1890*72b2703bSAndreas Gohr ``` 1891*72b2703bSAndreas Gohr</code></pre> 1892*72b2703bSAndreas Gohr```````````````````````````````` 1893*72b2703bSAndreas Gohr 1894*72b2703bSAndreas Gohr 1895*72b2703bSAndreas Gohr 1896*72b2703bSAndreas GohrCode fences (opening and closing) cannot contain internal spaces: 1897*72b2703bSAndreas Gohr 1898*72b2703bSAndreas Gohr```````````````````````````````` example 1899*72b2703bSAndreas Gohr``` ``` 1900*72b2703bSAndreas Gohraaa 1901*72b2703bSAndreas Gohr. 1902*72b2703bSAndreas Gohr<p><code> </code> 1903*72b2703bSAndreas Gohraaa</p> 1904*72b2703bSAndreas Gohr```````````````````````````````` 1905*72b2703bSAndreas Gohr 1906*72b2703bSAndreas Gohr 1907*72b2703bSAndreas Gohr```````````````````````````````` example 1908*72b2703bSAndreas Gohr~~~~~~ 1909*72b2703bSAndreas Gohraaa 1910*72b2703bSAndreas Gohr~~~ ~~ 1911*72b2703bSAndreas Gohr. 1912*72b2703bSAndreas Gohr<pre><code>aaa 1913*72b2703bSAndreas Gohr~~~ ~~ 1914*72b2703bSAndreas Gohr</code></pre> 1915*72b2703bSAndreas Gohr```````````````````````````````` 1916*72b2703bSAndreas Gohr 1917*72b2703bSAndreas Gohr 1918*72b2703bSAndreas GohrFenced code blocks can interrupt paragraphs, and can be followed 1919*72b2703bSAndreas Gohrdirectly by paragraphs, without a blank line between: 1920*72b2703bSAndreas Gohr 1921*72b2703bSAndreas Gohr```````````````````````````````` example 1922*72b2703bSAndreas Gohrfoo 1923*72b2703bSAndreas Gohr``` 1924*72b2703bSAndreas Gohrbar 1925*72b2703bSAndreas Gohr``` 1926*72b2703bSAndreas Gohrbaz 1927*72b2703bSAndreas Gohr. 1928*72b2703bSAndreas Gohr<p>foo</p> 1929*72b2703bSAndreas Gohr<pre><code>bar 1930*72b2703bSAndreas Gohr</code></pre> 1931*72b2703bSAndreas Gohr<p>baz</p> 1932*72b2703bSAndreas Gohr```````````````````````````````` 1933*72b2703bSAndreas Gohr 1934*72b2703bSAndreas Gohr 1935*72b2703bSAndreas GohrOther blocks can also occur before and after fenced code blocks 1936*72b2703bSAndreas Gohrwithout an intervening blank line: 1937*72b2703bSAndreas Gohr 1938*72b2703bSAndreas Gohr```````````````````````````````` example 1939*72b2703bSAndreas Gohrfoo 1940*72b2703bSAndreas Gohr--- 1941*72b2703bSAndreas Gohr~~~ 1942*72b2703bSAndreas Gohrbar 1943*72b2703bSAndreas Gohr~~~ 1944*72b2703bSAndreas Gohr# baz 1945*72b2703bSAndreas Gohr. 1946*72b2703bSAndreas Gohr<h2>foo</h2> 1947*72b2703bSAndreas Gohr<pre><code>bar 1948*72b2703bSAndreas Gohr</code></pre> 1949*72b2703bSAndreas Gohr<h1>baz</h1> 1950*72b2703bSAndreas Gohr```````````````````````````````` 1951*72b2703bSAndreas Gohr 1952*72b2703bSAndreas Gohr 1953*72b2703bSAndreas GohrAn [info string] can be provided after the opening code fence. 1954*72b2703bSAndreas GohrAlthough this spec doesn't mandate any particular treatment of 1955*72b2703bSAndreas Gohrthe info string, the first word is typically used to specify 1956*72b2703bSAndreas Gohrthe language of the code block. In HTML output, the language is 1957*72b2703bSAndreas Gohrnormally indicated by adding a class to the `code` element consisting 1958*72b2703bSAndreas Gohrof `language-` followed by the language name. 1959*72b2703bSAndreas Gohr 1960*72b2703bSAndreas Gohr```````````````````````````````` example 1961*72b2703bSAndreas Gohr```ruby 1962*72b2703bSAndreas Gohrdef foo(x) 1963*72b2703bSAndreas Gohr return 3 1964*72b2703bSAndreas Gohrend 1965*72b2703bSAndreas Gohr``` 1966*72b2703bSAndreas Gohr. 1967*72b2703bSAndreas Gohr<pre><code class="language-ruby">def foo(x) 1968*72b2703bSAndreas Gohr return 3 1969*72b2703bSAndreas Gohrend 1970*72b2703bSAndreas Gohr</code></pre> 1971*72b2703bSAndreas Gohr```````````````````````````````` 1972*72b2703bSAndreas Gohr 1973*72b2703bSAndreas Gohr 1974*72b2703bSAndreas Gohr```````````````````````````````` example 1975*72b2703bSAndreas Gohr~~~~ ruby startline=3 $%@#$ 1976*72b2703bSAndreas Gohrdef foo(x) 1977*72b2703bSAndreas Gohr return 3 1978*72b2703bSAndreas Gohrend 1979*72b2703bSAndreas Gohr~~~~~~~ 1980*72b2703bSAndreas Gohr. 1981*72b2703bSAndreas Gohr<pre><code class="language-ruby">def foo(x) 1982*72b2703bSAndreas Gohr return 3 1983*72b2703bSAndreas Gohrend 1984*72b2703bSAndreas Gohr</code></pre> 1985*72b2703bSAndreas Gohr```````````````````````````````` 1986*72b2703bSAndreas Gohr 1987*72b2703bSAndreas Gohr 1988*72b2703bSAndreas Gohr```````````````````````````````` example 1989*72b2703bSAndreas Gohr````; 1990*72b2703bSAndreas Gohr```` 1991*72b2703bSAndreas Gohr. 1992*72b2703bSAndreas Gohr<pre><code class="language-;"></code></pre> 1993*72b2703bSAndreas Gohr```````````````````````````````` 1994*72b2703bSAndreas Gohr 1995*72b2703bSAndreas Gohr 1996*72b2703bSAndreas Gohr[Info strings] for backtick code blocks cannot contain backticks: 1997*72b2703bSAndreas Gohr 1998*72b2703bSAndreas Gohr```````````````````````````````` example 1999*72b2703bSAndreas Gohr``` aa ``` 2000*72b2703bSAndreas Gohrfoo 2001*72b2703bSAndreas Gohr. 2002*72b2703bSAndreas Gohr<p><code>aa</code> 2003*72b2703bSAndreas Gohrfoo</p> 2004*72b2703bSAndreas Gohr```````````````````````````````` 2005*72b2703bSAndreas Gohr 2006*72b2703bSAndreas Gohr 2007*72b2703bSAndreas Gohr[Info strings] for tilde code blocks can contain backticks and tildes: 2008*72b2703bSAndreas Gohr 2009*72b2703bSAndreas Gohr```````````````````````````````` example 2010*72b2703bSAndreas Gohr~~~ aa ``` ~~~ 2011*72b2703bSAndreas Gohrfoo 2012*72b2703bSAndreas Gohr~~~ 2013*72b2703bSAndreas Gohr. 2014*72b2703bSAndreas Gohr<pre><code class="language-aa">foo 2015*72b2703bSAndreas Gohr</code></pre> 2016*72b2703bSAndreas Gohr```````````````````````````````` 2017*72b2703bSAndreas Gohr 2018*72b2703bSAndreas Gohr 2019*72b2703bSAndreas GohrClosing code fences cannot have [info strings]: 2020*72b2703bSAndreas Gohr 2021*72b2703bSAndreas Gohr```````````````````````````````` example 2022*72b2703bSAndreas Gohr``` 2023*72b2703bSAndreas Gohr``` aaa 2024*72b2703bSAndreas Gohr``` 2025*72b2703bSAndreas Gohr. 2026*72b2703bSAndreas Gohr<pre><code>``` aaa 2027*72b2703bSAndreas Gohr</code></pre> 2028*72b2703bSAndreas Gohr```````````````````````````````` 2029*72b2703bSAndreas Gohr 2030*72b2703bSAndreas Gohr 2031*72b2703bSAndreas Gohr 2032*72b2703bSAndreas Gohr## HTML blocks 2033*72b2703bSAndreas Gohr 2034*72b2703bSAndreas GohrAn [HTML block](@) is a group of lines that is treated 2035*72b2703bSAndreas Gohras raw HTML (and will not be escaped in HTML output). 2036*72b2703bSAndreas Gohr 2037*72b2703bSAndreas GohrThere are seven kinds of [HTML block], which can be defined by their 2038*72b2703bSAndreas Gohrstart and end conditions. The block begins with a line that meets a 2039*72b2703bSAndreas Gohr[start condition](@) (after up to three spaces optional indentation). 2040*72b2703bSAndreas GohrIt ends with the first subsequent line that meets a matching [end 2041*72b2703bSAndreas Gohrcondition](@), or the last line of the document, or the last line of 2042*72b2703bSAndreas Gohrthe [container block](#container-blocks) containing the current HTML 2043*72b2703bSAndreas Gohrblock, if no line is encountered that meets the [end condition]. If 2044*72b2703bSAndreas Gohrthe first line meets both the [start condition] and the [end 2045*72b2703bSAndreas Gohrcondition], the block will contain just that line. 2046*72b2703bSAndreas Gohr 2047*72b2703bSAndreas Gohr1. **Start condition:** line begins with the string `<script`, 2048*72b2703bSAndreas Gohr`<pre`, or `<style` (case-insensitive), followed by whitespace, 2049*72b2703bSAndreas Gohrthe string `>`, or the end of the line.\ 2050*72b2703bSAndreas Gohr**End condition:** line contains an end tag 2051*72b2703bSAndreas Gohr`</script>`, `</pre>`, or `</style>` (case-insensitive; it 2052*72b2703bSAndreas Gohrneed not match the start tag). 2053*72b2703bSAndreas Gohr 2054*72b2703bSAndreas Gohr2. **Start condition:** line begins with the string `<!--`.\ 2055*72b2703bSAndreas Gohr**End condition:** line contains the string `-->`. 2056*72b2703bSAndreas Gohr 2057*72b2703bSAndreas Gohr3. **Start condition:** line begins with the string `<?`.\ 2058*72b2703bSAndreas Gohr**End condition:** line contains the string `?>`. 2059*72b2703bSAndreas Gohr 2060*72b2703bSAndreas Gohr4. **Start condition:** line begins with the string `<!` 2061*72b2703bSAndreas Gohrfollowed by an uppercase ASCII letter.\ 2062*72b2703bSAndreas Gohr**End condition:** line contains the character `>`. 2063*72b2703bSAndreas Gohr 2064*72b2703bSAndreas Gohr5. **Start condition:** line begins with the string 2065*72b2703bSAndreas Gohr`<![CDATA[`.\ 2066*72b2703bSAndreas Gohr**End condition:** line contains the string `]]>`. 2067*72b2703bSAndreas Gohr 2068*72b2703bSAndreas Gohr6. **Start condition:** line begins with the string `<` or `</` 2069*72b2703bSAndreas Gohrfollowed by one of the strings (case-insensitive) `address`, 2070*72b2703bSAndreas Gohr`article`, `aside`, `base`, `basefont`, `blockquote`, `body`, 2071*72b2703bSAndreas Gohr`caption`, `center`, `col`, `colgroup`, `dd`, `details`, `dialog`, 2072*72b2703bSAndreas Gohr`dir`, `div`, `dl`, `dt`, `fieldset`, `figcaption`, `figure`, 2073*72b2703bSAndreas Gohr`footer`, `form`, `frame`, `frameset`, 2074*72b2703bSAndreas Gohr`h1`, `h2`, `h3`, `h4`, `h5`, `h6`, `head`, `header`, `hr`, 2075*72b2703bSAndreas Gohr`html`, `iframe`, `legend`, `li`, `link`, `main`, `menu`, `menuitem`, 2076*72b2703bSAndreas Gohr`nav`, `noframes`, `ol`, `optgroup`, `option`, `p`, `param`, 2077*72b2703bSAndreas Gohr`section`, `summary`, `table`, `tbody`, `td`, 2078*72b2703bSAndreas Gohr`tfoot`, `th`, `thead`, `title`, `tr`, `track`, `ul`, followed 2079*72b2703bSAndreas Gohrby [whitespace], the end of the line, the string `>`, or 2080*72b2703bSAndreas Gohrthe string `/>`.\ 2081*72b2703bSAndreas Gohr**End condition:** line is followed by a [blank line]. 2082*72b2703bSAndreas Gohr 2083*72b2703bSAndreas Gohr7. **Start condition:** line begins with a complete [open tag] 2084*72b2703bSAndreas Gohr(with any [tag name] other than `script`, 2085*72b2703bSAndreas Gohr`style`, or `pre`) or a complete [closing tag], 2086*72b2703bSAndreas Gohrfollowed only by [whitespace] or the end of the line.\ 2087*72b2703bSAndreas Gohr**End condition:** line is followed by a [blank line]. 2088*72b2703bSAndreas Gohr 2089*72b2703bSAndreas GohrHTML blocks continue until they are closed by their appropriate 2090*72b2703bSAndreas Gohr[end condition], or the last line of the document or other [container 2091*72b2703bSAndreas Gohrblock](#container-blocks). This means any HTML **within an HTML 2092*72b2703bSAndreas Gohrblock** that might otherwise be recognised as a start condition will 2093*72b2703bSAndreas Gohrbe ignored by the parser and passed through as-is, without changing 2094*72b2703bSAndreas Gohrthe parser's state. 2095*72b2703bSAndreas Gohr 2096*72b2703bSAndreas GohrFor instance, `<pre>` within a HTML block started by `<table>` will not affect 2097*72b2703bSAndreas Gohrthe parser state; as the HTML block was started in by start condition 6, it 2098*72b2703bSAndreas Gohrwill end at any blank line. This can be surprising: 2099*72b2703bSAndreas Gohr 2100*72b2703bSAndreas Gohr```````````````````````````````` example 2101*72b2703bSAndreas Gohr<table><tr><td> 2102*72b2703bSAndreas Gohr<pre> 2103*72b2703bSAndreas Gohr**Hello**, 2104*72b2703bSAndreas Gohr 2105*72b2703bSAndreas Gohr_world_. 2106*72b2703bSAndreas Gohr</pre> 2107*72b2703bSAndreas Gohr</td></tr></table> 2108*72b2703bSAndreas Gohr. 2109*72b2703bSAndreas Gohr<table><tr><td> 2110*72b2703bSAndreas Gohr<pre> 2111*72b2703bSAndreas Gohr**Hello**, 2112*72b2703bSAndreas Gohr<p><em>world</em>. 2113*72b2703bSAndreas Gohr</pre></p> 2114*72b2703bSAndreas Gohr</td></tr></table> 2115*72b2703bSAndreas Gohr```````````````````````````````` 2116*72b2703bSAndreas Gohr 2117*72b2703bSAndreas GohrIn this case, the HTML block is terminated by the newline — the `**Hello**` 2118*72b2703bSAndreas Gohrtext remains verbatim — and regular parsing resumes, with a paragraph, 2119*72b2703bSAndreas Gohremphasised `world` and inline and block HTML following. 2120*72b2703bSAndreas Gohr 2121*72b2703bSAndreas GohrAll types of [HTML blocks] except type 7 may interrupt 2122*72b2703bSAndreas Gohra paragraph. Blocks of type 7 may not interrupt a paragraph. 2123*72b2703bSAndreas Gohr(This restriction is intended to prevent unwanted interpretation 2124*72b2703bSAndreas Gohrof long tags inside a wrapped paragraph as starting HTML blocks.) 2125*72b2703bSAndreas Gohr 2126*72b2703bSAndreas GohrSome simple examples follow. Here are some basic HTML blocks 2127*72b2703bSAndreas Gohrof type 6: 2128*72b2703bSAndreas Gohr 2129*72b2703bSAndreas Gohr```````````````````````````````` example 2130*72b2703bSAndreas Gohr<table> 2131*72b2703bSAndreas Gohr <tr> 2132*72b2703bSAndreas Gohr <td> 2133*72b2703bSAndreas Gohr hi 2134*72b2703bSAndreas Gohr </td> 2135*72b2703bSAndreas Gohr </tr> 2136*72b2703bSAndreas Gohr</table> 2137*72b2703bSAndreas Gohr 2138*72b2703bSAndreas Gohrokay. 2139*72b2703bSAndreas Gohr. 2140*72b2703bSAndreas Gohr<table> 2141*72b2703bSAndreas Gohr <tr> 2142*72b2703bSAndreas Gohr <td> 2143*72b2703bSAndreas Gohr hi 2144*72b2703bSAndreas Gohr </td> 2145*72b2703bSAndreas Gohr </tr> 2146*72b2703bSAndreas Gohr</table> 2147*72b2703bSAndreas Gohr<p>okay.</p> 2148*72b2703bSAndreas Gohr```````````````````````````````` 2149*72b2703bSAndreas Gohr 2150*72b2703bSAndreas Gohr 2151*72b2703bSAndreas Gohr```````````````````````````````` example 2152*72b2703bSAndreas Gohr <div> 2153*72b2703bSAndreas Gohr *hello* 2154*72b2703bSAndreas Gohr <foo><a> 2155*72b2703bSAndreas Gohr. 2156*72b2703bSAndreas Gohr <div> 2157*72b2703bSAndreas Gohr *hello* 2158*72b2703bSAndreas Gohr <foo><a> 2159*72b2703bSAndreas Gohr```````````````````````````````` 2160*72b2703bSAndreas Gohr 2161*72b2703bSAndreas Gohr 2162*72b2703bSAndreas GohrA block can also start with a closing tag: 2163*72b2703bSAndreas Gohr 2164*72b2703bSAndreas Gohr```````````````````````````````` example 2165*72b2703bSAndreas Gohr</div> 2166*72b2703bSAndreas Gohr*foo* 2167*72b2703bSAndreas Gohr. 2168*72b2703bSAndreas Gohr</div> 2169*72b2703bSAndreas Gohr*foo* 2170*72b2703bSAndreas Gohr```````````````````````````````` 2171*72b2703bSAndreas Gohr 2172*72b2703bSAndreas Gohr 2173*72b2703bSAndreas GohrHere we have two HTML blocks with a Markdown paragraph between them: 2174*72b2703bSAndreas Gohr 2175*72b2703bSAndreas Gohr```````````````````````````````` example 2176*72b2703bSAndreas Gohr<DIV CLASS="foo"> 2177*72b2703bSAndreas Gohr 2178*72b2703bSAndreas Gohr*Markdown* 2179*72b2703bSAndreas Gohr 2180*72b2703bSAndreas Gohr</DIV> 2181*72b2703bSAndreas Gohr. 2182*72b2703bSAndreas Gohr<DIV CLASS="foo"> 2183*72b2703bSAndreas Gohr<p><em>Markdown</em></p> 2184*72b2703bSAndreas Gohr</DIV> 2185*72b2703bSAndreas Gohr```````````````````````````````` 2186*72b2703bSAndreas Gohr 2187*72b2703bSAndreas Gohr 2188*72b2703bSAndreas GohrThe tag on the first line can be partial, as long 2189*72b2703bSAndreas Gohras it is split where there would be whitespace: 2190*72b2703bSAndreas Gohr 2191*72b2703bSAndreas Gohr```````````````````````````````` example 2192*72b2703bSAndreas Gohr<div id="foo" 2193*72b2703bSAndreas Gohr class="bar"> 2194*72b2703bSAndreas Gohr</div> 2195*72b2703bSAndreas Gohr. 2196*72b2703bSAndreas Gohr<div id="foo" 2197*72b2703bSAndreas Gohr class="bar"> 2198*72b2703bSAndreas Gohr</div> 2199*72b2703bSAndreas Gohr```````````````````````````````` 2200*72b2703bSAndreas Gohr 2201*72b2703bSAndreas Gohr 2202*72b2703bSAndreas Gohr```````````````````````````````` example 2203*72b2703bSAndreas Gohr<div id="foo" class="bar 2204*72b2703bSAndreas Gohr baz"> 2205*72b2703bSAndreas Gohr</div> 2206*72b2703bSAndreas Gohr. 2207*72b2703bSAndreas Gohr<div id="foo" class="bar 2208*72b2703bSAndreas Gohr baz"> 2209*72b2703bSAndreas Gohr</div> 2210*72b2703bSAndreas Gohr```````````````````````````````` 2211*72b2703bSAndreas Gohr 2212*72b2703bSAndreas Gohr 2213*72b2703bSAndreas GohrAn open tag need not be closed: 2214*72b2703bSAndreas Gohr```````````````````````````````` example 2215*72b2703bSAndreas Gohr<div> 2216*72b2703bSAndreas Gohr*foo* 2217*72b2703bSAndreas Gohr 2218*72b2703bSAndreas Gohr*bar* 2219*72b2703bSAndreas Gohr. 2220*72b2703bSAndreas Gohr<div> 2221*72b2703bSAndreas Gohr*foo* 2222*72b2703bSAndreas Gohr<p><em>bar</em></p> 2223*72b2703bSAndreas Gohr```````````````````````````````` 2224*72b2703bSAndreas Gohr 2225*72b2703bSAndreas Gohr 2226*72b2703bSAndreas Gohr 2227*72b2703bSAndreas GohrA partial tag need not even be completed (garbage 2228*72b2703bSAndreas Gohrin, garbage out): 2229*72b2703bSAndreas Gohr 2230*72b2703bSAndreas Gohr```````````````````````````````` example 2231*72b2703bSAndreas Gohr<div id="foo" 2232*72b2703bSAndreas Gohr*hi* 2233*72b2703bSAndreas Gohr. 2234*72b2703bSAndreas Gohr<div id="foo" 2235*72b2703bSAndreas Gohr*hi* 2236*72b2703bSAndreas Gohr```````````````````````````````` 2237*72b2703bSAndreas Gohr 2238*72b2703bSAndreas Gohr 2239*72b2703bSAndreas Gohr```````````````````````````````` example 2240*72b2703bSAndreas Gohr<div class 2241*72b2703bSAndreas Gohrfoo 2242*72b2703bSAndreas Gohr. 2243*72b2703bSAndreas Gohr<div class 2244*72b2703bSAndreas Gohrfoo 2245*72b2703bSAndreas Gohr```````````````````````````````` 2246*72b2703bSAndreas Gohr 2247*72b2703bSAndreas Gohr 2248*72b2703bSAndreas GohrThe initial tag doesn't even need to be a valid 2249*72b2703bSAndreas Gohrtag, as long as it starts like one: 2250*72b2703bSAndreas Gohr 2251*72b2703bSAndreas Gohr```````````````````````````````` example 2252*72b2703bSAndreas Gohr<div *???-&&&-<--- 2253*72b2703bSAndreas Gohr*foo* 2254*72b2703bSAndreas Gohr. 2255*72b2703bSAndreas Gohr<div *???-&&&-<--- 2256*72b2703bSAndreas Gohr*foo* 2257*72b2703bSAndreas Gohr```````````````````````````````` 2258*72b2703bSAndreas Gohr 2259*72b2703bSAndreas Gohr 2260*72b2703bSAndreas GohrIn type 6 blocks, the initial tag need not be on a line by 2261*72b2703bSAndreas Gohritself: 2262*72b2703bSAndreas Gohr 2263*72b2703bSAndreas Gohr```````````````````````````````` example 2264*72b2703bSAndreas Gohr<div><a href="bar">*foo*</a></div> 2265*72b2703bSAndreas Gohr. 2266*72b2703bSAndreas Gohr<div><a href="bar">*foo*</a></div> 2267*72b2703bSAndreas Gohr```````````````````````````````` 2268*72b2703bSAndreas Gohr 2269*72b2703bSAndreas Gohr 2270*72b2703bSAndreas Gohr```````````````````````````````` example 2271*72b2703bSAndreas Gohr<table><tr><td> 2272*72b2703bSAndreas Gohrfoo 2273*72b2703bSAndreas Gohr</td></tr></table> 2274*72b2703bSAndreas Gohr. 2275*72b2703bSAndreas Gohr<table><tr><td> 2276*72b2703bSAndreas Gohrfoo 2277*72b2703bSAndreas Gohr</td></tr></table> 2278*72b2703bSAndreas Gohr```````````````````````````````` 2279*72b2703bSAndreas Gohr 2280*72b2703bSAndreas Gohr 2281*72b2703bSAndreas GohrEverything until the next blank line or end of document 2282*72b2703bSAndreas Gohrgets included in the HTML block. So, in the following 2283*72b2703bSAndreas Gohrexample, what looks like a Markdown code block 2284*72b2703bSAndreas Gohris actually part of the HTML block, which continues until a blank 2285*72b2703bSAndreas Gohrline or the end of the document is reached: 2286*72b2703bSAndreas Gohr 2287*72b2703bSAndreas Gohr```````````````````````````````` example 2288*72b2703bSAndreas Gohr<div></div> 2289*72b2703bSAndreas Gohr``` c 2290*72b2703bSAndreas Gohrint x = 33; 2291*72b2703bSAndreas Gohr``` 2292*72b2703bSAndreas Gohr. 2293*72b2703bSAndreas Gohr<div></div> 2294*72b2703bSAndreas Gohr``` c 2295*72b2703bSAndreas Gohrint x = 33; 2296*72b2703bSAndreas Gohr``` 2297*72b2703bSAndreas Gohr```````````````````````````````` 2298*72b2703bSAndreas Gohr 2299*72b2703bSAndreas Gohr 2300*72b2703bSAndreas GohrTo start an [HTML block] with a tag that is *not* in the 2301*72b2703bSAndreas Gohrlist of block-level tags in (6), you must put the tag by 2302*72b2703bSAndreas Gohritself on the first line (and it must be complete): 2303*72b2703bSAndreas Gohr 2304*72b2703bSAndreas Gohr```````````````````````````````` example 2305*72b2703bSAndreas Gohr<a href="foo"> 2306*72b2703bSAndreas Gohr*bar* 2307*72b2703bSAndreas Gohr</a> 2308*72b2703bSAndreas Gohr. 2309*72b2703bSAndreas Gohr<a href="foo"> 2310*72b2703bSAndreas Gohr*bar* 2311*72b2703bSAndreas Gohr</a> 2312*72b2703bSAndreas Gohr```````````````````````````````` 2313*72b2703bSAndreas Gohr 2314*72b2703bSAndreas Gohr 2315*72b2703bSAndreas GohrIn type 7 blocks, the [tag name] can be anything: 2316*72b2703bSAndreas Gohr 2317*72b2703bSAndreas Gohr```````````````````````````````` example 2318*72b2703bSAndreas Gohr<Warning> 2319*72b2703bSAndreas Gohr*bar* 2320*72b2703bSAndreas Gohr</Warning> 2321*72b2703bSAndreas Gohr. 2322*72b2703bSAndreas Gohr<Warning> 2323*72b2703bSAndreas Gohr*bar* 2324*72b2703bSAndreas Gohr</Warning> 2325*72b2703bSAndreas Gohr```````````````````````````````` 2326*72b2703bSAndreas Gohr 2327*72b2703bSAndreas Gohr 2328*72b2703bSAndreas Gohr```````````````````````````````` example 2329*72b2703bSAndreas Gohr<i class="foo"> 2330*72b2703bSAndreas Gohr*bar* 2331*72b2703bSAndreas Gohr</i> 2332*72b2703bSAndreas Gohr. 2333*72b2703bSAndreas Gohr<i class="foo"> 2334*72b2703bSAndreas Gohr*bar* 2335*72b2703bSAndreas Gohr</i> 2336*72b2703bSAndreas Gohr```````````````````````````````` 2337*72b2703bSAndreas Gohr 2338*72b2703bSAndreas Gohr 2339*72b2703bSAndreas Gohr```````````````````````````````` example 2340*72b2703bSAndreas Gohr</ins> 2341*72b2703bSAndreas Gohr*bar* 2342*72b2703bSAndreas Gohr. 2343*72b2703bSAndreas Gohr</ins> 2344*72b2703bSAndreas Gohr*bar* 2345*72b2703bSAndreas Gohr```````````````````````````````` 2346*72b2703bSAndreas Gohr 2347*72b2703bSAndreas Gohr 2348*72b2703bSAndreas GohrThese rules are designed to allow us to work with tags that 2349*72b2703bSAndreas Gohrcan function as either block-level or inline-level tags. 2350*72b2703bSAndreas GohrThe `<del>` tag is a nice example. We can surround content with 2351*72b2703bSAndreas Gohr`<del>` tags in three different ways. In this case, we get a raw 2352*72b2703bSAndreas GohrHTML block, because the `<del>` tag is on a line by itself: 2353*72b2703bSAndreas Gohr 2354*72b2703bSAndreas Gohr```````````````````````````````` example 2355*72b2703bSAndreas Gohr<del> 2356*72b2703bSAndreas Gohr*foo* 2357*72b2703bSAndreas Gohr</del> 2358*72b2703bSAndreas Gohr. 2359*72b2703bSAndreas Gohr<del> 2360*72b2703bSAndreas Gohr*foo* 2361*72b2703bSAndreas Gohr</del> 2362*72b2703bSAndreas Gohr```````````````````````````````` 2363*72b2703bSAndreas Gohr 2364*72b2703bSAndreas Gohr 2365*72b2703bSAndreas GohrIn this case, we get a raw HTML block that just includes 2366*72b2703bSAndreas Gohrthe `<del>` tag (because it ends with the following blank 2367*72b2703bSAndreas Gohrline). So the contents get interpreted as CommonMark: 2368*72b2703bSAndreas Gohr 2369*72b2703bSAndreas Gohr```````````````````````````````` example 2370*72b2703bSAndreas Gohr<del> 2371*72b2703bSAndreas Gohr 2372*72b2703bSAndreas Gohr*foo* 2373*72b2703bSAndreas Gohr 2374*72b2703bSAndreas Gohr</del> 2375*72b2703bSAndreas Gohr. 2376*72b2703bSAndreas Gohr<del> 2377*72b2703bSAndreas Gohr<p><em>foo</em></p> 2378*72b2703bSAndreas Gohr</del> 2379*72b2703bSAndreas Gohr```````````````````````````````` 2380*72b2703bSAndreas Gohr 2381*72b2703bSAndreas Gohr 2382*72b2703bSAndreas GohrFinally, in this case, the `<del>` tags are interpreted 2383*72b2703bSAndreas Gohras [raw HTML] *inside* the CommonMark paragraph. (Because 2384*72b2703bSAndreas Gohrthe tag is not on a line by itself, we get inline HTML 2385*72b2703bSAndreas Gohrrather than an [HTML block].) 2386*72b2703bSAndreas Gohr 2387*72b2703bSAndreas Gohr```````````````````````````````` example 2388*72b2703bSAndreas Gohr<del>*foo*</del> 2389*72b2703bSAndreas Gohr. 2390*72b2703bSAndreas Gohr<p><del><em>foo</em></del></p> 2391*72b2703bSAndreas Gohr```````````````````````````````` 2392*72b2703bSAndreas Gohr 2393*72b2703bSAndreas Gohr 2394*72b2703bSAndreas GohrHTML tags designed to contain literal content 2395*72b2703bSAndreas Gohr(`script`, `style`, `pre`), comments, processing instructions, 2396*72b2703bSAndreas Gohrand declarations are treated somewhat differently. 2397*72b2703bSAndreas GohrInstead of ending at the first blank line, these blocks 2398*72b2703bSAndreas Gohrend at the first line containing a corresponding end tag. 2399*72b2703bSAndreas GohrAs a result, these blocks can contain blank lines: 2400*72b2703bSAndreas Gohr 2401*72b2703bSAndreas GohrA pre tag (type 1): 2402*72b2703bSAndreas Gohr 2403*72b2703bSAndreas Gohr```````````````````````````````` example 2404*72b2703bSAndreas Gohr<pre language="haskell"><code> 2405*72b2703bSAndreas Gohrimport Text.HTML.TagSoup 2406*72b2703bSAndreas Gohr 2407*72b2703bSAndreas Gohrmain :: IO () 2408*72b2703bSAndreas Gohrmain = print $ parseTags tags 2409*72b2703bSAndreas Gohr</code></pre> 2410*72b2703bSAndreas Gohrokay 2411*72b2703bSAndreas Gohr. 2412*72b2703bSAndreas Gohr<pre language="haskell"><code> 2413*72b2703bSAndreas Gohrimport Text.HTML.TagSoup 2414*72b2703bSAndreas Gohr 2415*72b2703bSAndreas Gohrmain :: IO () 2416*72b2703bSAndreas Gohrmain = print $ parseTags tags 2417*72b2703bSAndreas Gohr</code></pre> 2418*72b2703bSAndreas Gohr<p>okay</p> 2419*72b2703bSAndreas Gohr```````````````````````````````` 2420*72b2703bSAndreas Gohr 2421*72b2703bSAndreas Gohr 2422*72b2703bSAndreas GohrA script tag (type 1): 2423*72b2703bSAndreas Gohr 2424*72b2703bSAndreas Gohr```````````````````````````````` example 2425*72b2703bSAndreas Gohr<script type="text/javascript"> 2426*72b2703bSAndreas Gohr// JavaScript example 2427*72b2703bSAndreas Gohr 2428*72b2703bSAndreas Gohrdocument.getElementById("demo").innerHTML = "Hello JavaScript!"; 2429*72b2703bSAndreas Gohr</script> 2430*72b2703bSAndreas Gohrokay 2431*72b2703bSAndreas Gohr. 2432*72b2703bSAndreas Gohr<script type="text/javascript"> 2433*72b2703bSAndreas Gohr// JavaScript example 2434*72b2703bSAndreas Gohr 2435*72b2703bSAndreas Gohrdocument.getElementById("demo").innerHTML = "Hello JavaScript!"; 2436*72b2703bSAndreas Gohr</script> 2437*72b2703bSAndreas Gohr<p>okay</p> 2438*72b2703bSAndreas Gohr```````````````````````````````` 2439*72b2703bSAndreas Gohr 2440*72b2703bSAndreas Gohr 2441*72b2703bSAndreas GohrA style tag (type 1): 2442*72b2703bSAndreas Gohr 2443*72b2703bSAndreas Gohr```````````````````````````````` example 2444*72b2703bSAndreas Gohr<style 2445*72b2703bSAndreas Gohr type="text/css"> 2446*72b2703bSAndreas Gohrh1 {color:red;} 2447*72b2703bSAndreas Gohr 2448*72b2703bSAndreas Gohrp {color:blue;} 2449*72b2703bSAndreas Gohr</style> 2450*72b2703bSAndreas Gohrokay 2451*72b2703bSAndreas Gohr. 2452*72b2703bSAndreas Gohr<style 2453*72b2703bSAndreas Gohr type="text/css"> 2454*72b2703bSAndreas Gohrh1 {color:red;} 2455*72b2703bSAndreas Gohr 2456*72b2703bSAndreas Gohrp {color:blue;} 2457*72b2703bSAndreas Gohr</style> 2458*72b2703bSAndreas Gohr<p>okay</p> 2459*72b2703bSAndreas Gohr```````````````````````````````` 2460*72b2703bSAndreas Gohr 2461*72b2703bSAndreas Gohr 2462*72b2703bSAndreas GohrIf there is no matching end tag, the block will end at the 2463*72b2703bSAndreas Gohrend of the document (or the enclosing [block quote][block quotes] 2464*72b2703bSAndreas Gohror [list item][list items]): 2465*72b2703bSAndreas Gohr 2466*72b2703bSAndreas Gohr```````````````````````````````` example 2467*72b2703bSAndreas Gohr<style 2468*72b2703bSAndreas Gohr type="text/css"> 2469*72b2703bSAndreas Gohr 2470*72b2703bSAndreas Gohrfoo 2471*72b2703bSAndreas Gohr. 2472*72b2703bSAndreas Gohr<style 2473*72b2703bSAndreas Gohr type="text/css"> 2474*72b2703bSAndreas Gohr 2475*72b2703bSAndreas Gohrfoo 2476*72b2703bSAndreas Gohr```````````````````````````````` 2477*72b2703bSAndreas Gohr 2478*72b2703bSAndreas Gohr 2479*72b2703bSAndreas Gohr```````````````````````````````` example 2480*72b2703bSAndreas Gohr> <div> 2481*72b2703bSAndreas Gohr> foo 2482*72b2703bSAndreas Gohr 2483*72b2703bSAndreas Gohrbar 2484*72b2703bSAndreas Gohr. 2485*72b2703bSAndreas Gohr<blockquote> 2486*72b2703bSAndreas Gohr<div> 2487*72b2703bSAndreas Gohrfoo 2488*72b2703bSAndreas Gohr</blockquote> 2489*72b2703bSAndreas Gohr<p>bar</p> 2490*72b2703bSAndreas Gohr```````````````````````````````` 2491*72b2703bSAndreas Gohr 2492*72b2703bSAndreas Gohr 2493*72b2703bSAndreas Gohr```````````````````````````````` example 2494*72b2703bSAndreas Gohr- <div> 2495*72b2703bSAndreas Gohr- foo 2496*72b2703bSAndreas Gohr. 2497*72b2703bSAndreas Gohr<ul> 2498*72b2703bSAndreas Gohr<li> 2499*72b2703bSAndreas Gohr<div> 2500*72b2703bSAndreas Gohr</li> 2501*72b2703bSAndreas Gohr<li>foo</li> 2502*72b2703bSAndreas Gohr</ul> 2503*72b2703bSAndreas Gohr```````````````````````````````` 2504*72b2703bSAndreas Gohr 2505*72b2703bSAndreas Gohr 2506*72b2703bSAndreas GohrThe end tag can occur on the same line as the start tag: 2507*72b2703bSAndreas Gohr 2508*72b2703bSAndreas Gohr```````````````````````````````` example 2509*72b2703bSAndreas Gohr<style>p{color:red;}</style> 2510*72b2703bSAndreas Gohr*foo* 2511*72b2703bSAndreas Gohr. 2512*72b2703bSAndreas Gohr<style>p{color:red;}</style> 2513*72b2703bSAndreas Gohr<p><em>foo</em></p> 2514*72b2703bSAndreas Gohr```````````````````````````````` 2515*72b2703bSAndreas Gohr 2516*72b2703bSAndreas Gohr 2517*72b2703bSAndreas Gohr```````````````````````````````` example 2518*72b2703bSAndreas Gohr<!-- foo -->*bar* 2519*72b2703bSAndreas Gohr*baz* 2520*72b2703bSAndreas Gohr. 2521*72b2703bSAndreas Gohr<!-- foo -->*bar* 2522*72b2703bSAndreas Gohr<p><em>baz</em></p> 2523*72b2703bSAndreas Gohr```````````````````````````````` 2524*72b2703bSAndreas Gohr 2525*72b2703bSAndreas Gohr 2526*72b2703bSAndreas GohrNote that anything on the last line after the 2527*72b2703bSAndreas Gohrend tag will be included in the [HTML block]: 2528*72b2703bSAndreas Gohr 2529*72b2703bSAndreas Gohr```````````````````````````````` example 2530*72b2703bSAndreas Gohr<script> 2531*72b2703bSAndreas Gohrfoo 2532*72b2703bSAndreas Gohr</script>1. *bar* 2533*72b2703bSAndreas Gohr. 2534*72b2703bSAndreas Gohr<script> 2535*72b2703bSAndreas Gohrfoo 2536*72b2703bSAndreas Gohr</script>1. *bar* 2537*72b2703bSAndreas Gohr```````````````````````````````` 2538*72b2703bSAndreas Gohr 2539*72b2703bSAndreas Gohr 2540*72b2703bSAndreas GohrA comment (type 2): 2541*72b2703bSAndreas Gohr 2542*72b2703bSAndreas Gohr```````````````````````````````` example 2543*72b2703bSAndreas Gohr<!-- Foo 2544*72b2703bSAndreas Gohr 2545*72b2703bSAndreas Gohrbar 2546*72b2703bSAndreas Gohr baz --> 2547*72b2703bSAndreas Gohrokay 2548*72b2703bSAndreas Gohr. 2549*72b2703bSAndreas Gohr<!-- Foo 2550*72b2703bSAndreas Gohr 2551*72b2703bSAndreas Gohrbar 2552*72b2703bSAndreas Gohr baz --> 2553*72b2703bSAndreas Gohr<p>okay</p> 2554*72b2703bSAndreas Gohr```````````````````````````````` 2555*72b2703bSAndreas Gohr 2556*72b2703bSAndreas Gohr 2557*72b2703bSAndreas Gohr 2558*72b2703bSAndreas GohrA processing instruction (type 3): 2559*72b2703bSAndreas Gohr 2560*72b2703bSAndreas Gohr```````````````````````````````` example 2561*72b2703bSAndreas Gohr<?php 2562*72b2703bSAndreas Gohr 2563*72b2703bSAndreas Gohr echo '>'; 2564*72b2703bSAndreas Gohr 2565*72b2703bSAndreas Gohr?> 2566*72b2703bSAndreas Gohrokay 2567*72b2703bSAndreas Gohr. 2568*72b2703bSAndreas Gohr<?php 2569*72b2703bSAndreas Gohr 2570*72b2703bSAndreas Gohr echo '>'; 2571*72b2703bSAndreas Gohr 2572*72b2703bSAndreas Gohr?> 2573*72b2703bSAndreas Gohr<p>okay</p> 2574*72b2703bSAndreas Gohr```````````````````````````````` 2575*72b2703bSAndreas Gohr 2576*72b2703bSAndreas Gohr 2577*72b2703bSAndreas GohrA declaration (type 4): 2578*72b2703bSAndreas Gohr 2579*72b2703bSAndreas Gohr```````````````````````````````` example 2580*72b2703bSAndreas Gohr<!DOCTYPE html> 2581*72b2703bSAndreas Gohr. 2582*72b2703bSAndreas Gohr<!DOCTYPE html> 2583*72b2703bSAndreas Gohr```````````````````````````````` 2584*72b2703bSAndreas Gohr 2585*72b2703bSAndreas Gohr 2586*72b2703bSAndreas GohrCDATA (type 5): 2587*72b2703bSAndreas Gohr 2588*72b2703bSAndreas Gohr```````````````````````````````` example 2589*72b2703bSAndreas Gohr<![CDATA[ 2590*72b2703bSAndreas Gohrfunction matchwo(a,b) 2591*72b2703bSAndreas Gohr{ 2592*72b2703bSAndreas Gohr if (a < b && a < 0) then { 2593*72b2703bSAndreas Gohr return 1; 2594*72b2703bSAndreas Gohr 2595*72b2703bSAndreas Gohr } else { 2596*72b2703bSAndreas Gohr 2597*72b2703bSAndreas Gohr return 0; 2598*72b2703bSAndreas Gohr } 2599*72b2703bSAndreas Gohr} 2600*72b2703bSAndreas Gohr]]> 2601*72b2703bSAndreas Gohrokay 2602*72b2703bSAndreas Gohr. 2603*72b2703bSAndreas Gohr<![CDATA[ 2604*72b2703bSAndreas Gohrfunction matchwo(a,b) 2605*72b2703bSAndreas Gohr{ 2606*72b2703bSAndreas Gohr if (a < b && a < 0) then { 2607*72b2703bSAndreas Gohr return 1; 2608*72b2703bSAndreas Gohr 2609*72b2703bSAndreas Gohr } else { 2610*72b2703bSAndreas Gohr 2611*72b2703bSAndreas Gohr return 0; 2612*72b2703bSAndreas Gohr } 2613*72b2703bSAndreas Gohr} 2614*72b2703bSAndreas Gohr]]> 2615*72b2703bSAndreas Gohr<p>okay</p> 2616*72b2703bSAndreas Gohr```````````````````````````````` 2617*72b2703bSAndreas Gohr 2618*72b2703bSAndreas Gohr 2619*72b2703bSAndreas GohrThe opening tag can be indented 1-3 spaces, but not 4: 2620*72b2703bSAndreas Gohr 2621*72b2703bSAndreas Gohr```````````````````````````````` example 2622*72b2703bSAndreas Gohr <!-- foo --> 2623*72b2703bSAndreas Gohr 2624*72b2703bSAndreas Gohr <!-- foo --> 2625*72b2703bSAndreas Gohr. 2626*72b2703bSAndreas Gohr <!-- foo --> 2627*72b2703bSAndreas Gohr<pre><code><!-- foo --> 2628*72b2703bSAndreas Gohr</code></pre> 2629*72b2703bSAndreas Gohr```````````````````````````````` 2630*72b2703bSAndreas Gohr 2631*72b2703bSAndreas Gohr 2632*72b2703bSAndreas Gohr```````````````````````````````` example 2633*72b2703bSAndreas Gohr <div> 2634*72b2703bSAndreas Gohr 2635*72b2703bSAndreas Gohr <div> 2636*72b2703bSAndreas Gohr. 2637*72b2703bSAndreas Gohr <div> 2638*72b2703bSAndreas Gohr<pre><code><div> 2639*72b2703bSAndreas Gohr</code></pre> 2640*72b2703bSAndreas Gohr```````````````````````````````` 2641*72b2703bSAndreas Gohr 2642*72b2703bSAndreas Gohr 2643*72b2703bSAndreas GohrAn HTML block of types 1--6 can interrupt a paragraph, and need not be 2644*72b2703bSAndreas Gohrpreceded by a blank line. 2645*72b2703bSAndreas Gohr 2646*72b2703bSAndreas Gohr```````````````````````````````` example 2647*72b2703bSAndreas GohrFoo 2648*72b2703bSAndreas Gohr<div> 2649*72b2703bSAndreas Gohrbar 2650*72b2703bSAndreas Gohr</div> 2651*72b2703bSAndreas Gohr. 2652*72b2703bSAndreas Gohr<p>Foo</p> 2653*72b2703bSAndreas Gohr<div> 2654*72b2703bSAndreas Gohrbar 2655*72b2703bSAndreas Gohr</div> 2656*72b2703bSAndreas Gohr```````````````````````````````` 2657*72b2703bSAndreas Gohr 2658*72b2703bSAndreas Gohr 2659*72b2703bSAndreas GohrHowever, a following blank line is needed, except at the end of 2660*72b2703bSAndreas Gohra document, and except for blocks of types 1--5, [above][HTML 2661*72b2703bSAndreas Gohrblock]: 2662*72b2703bSAndreas Gohr 2663*72b2703bSAndreas Gohr```````````````````````````````` example 2664*72b2703bSAndreas Gohr<div> 2665*72b2703bSAndreas Gohrbar 2666*72b2703bSAndreas Gohr</div> 2667*72b2703bSAndreas Gohr*foo* 2668*72b2703bSAndreas Gohr. 2669*72b2703bSAndreas Gohr<div> 2670*72b2703bSAndreas Gohrbar 2671*72b2703bSAndreas Gohr</div> 2672*72b2703bSAndreas Gohr*foo* 2673*72b2703bSAndreas Gohr```````````````````````````````` 2674*72b2703bSAndreas Gohr 2675*72b2703bSAndreas Gohr 2676*72b2703bSAndreas GohrHTML blocks of type 7 cannot interrupt a paragraph: 2677*72b2703bSAndreas Gohr 2678*72b2703bSAndreas Gohr```````````````````````````````` example 2679*72b2703bSAndreas GohrFoo 2680*72b2703bSAndreas Gohr<a href="bar"> 2681*72b2703bSAndreas Gohrbaz 2682*72b2703bSAndreas Gohr. 2683*72b2703bSAndreas Gohr<p>Foo 2684*72b2703bSAndreas Gohr<a href="bar"> 2685*72b2703bSAndreas Gohrbaz</p> 2686*72b2703bSAndreas Gohr```````````````````````````````` 2687*72b2703bSAndreas Gohr 2688*72b2703bSAndreas Gohr 2689*72b2703bSAndreas GohrThis rule differs from John Gruber's original Markdown syntax 2690*72b2703bSAndreas Gohrspecification, which says: 2691*72b2703bSAndreas Gohr 2692*72b2703bSAndreas Gohr> The only restrictions are that block-level HTML elements — 2693*72b2703bSAndreas Gohr> e.g. `<div>`, `<table>`, `<pre>`, `<p>`, etc. — must be separated from 2694*72b2703bSAndreas Gohr> surrounding content by blank lines, and the start and end tags of the 2695*72b2703bSAndreas Gohr> block should not be indented with tabs or spaces. 2696*72b2703bSAndreas Gohr 2697*72b2703bSAndreas GohrIn some ways Gruber's rule is more restrictive than the one given 2698*72b2703bSAndreas Gohrhere: 2699*72b2703bSAndreas Gohr 2700*72b2703bSAndreas Gohr- It requires that an HTML block be preceded by a blank line. 2701*72b2703bSAndreas Gohr- It does not allow the start tag to be indented. 2702*72b2703bSAndreas Gohr- It requires a matching end tag, which it also does not allow to 2703*72b2703bSAndreas Gohr be indented. 2704*72b2703bSAndreas Gohr 2705*72b2703bSAndreas GohrMost Markdown implementations (including some of Gruber's own) do not 2706*72b2703bSAndreas Gohrrespect all of these restrictions. 2707*72b2703bSAndreas Gohr 2708*72b2703bSAndreas GohrThere is one respect, however, in which Gruber's rule is more liberal 2709*72b2703bSAndreas Gohrthan the one given here, since it allows blank lines to occur inside 2710*72b2703bSAndreas Gohran HTML block. There are two reasons for disallowing them here. 2711*72b2703bSAndreas GohrFirst, it removes the need to parse balanced tags, which is 2712*72b2703bSAndreas Gohrexpensive and can require backtracking from the end of the document 2713*72b2703bSAndreas Gohrif no matching end tag is found. Second, it provides a very simple 2714*72b2703bSAndreas Gohrand flexible way of including Markdown content inside HTML tags: 2715*72b2703bSAndreas Gohrsimply separate the Markdown from the HTML using blank lines: 2716*72b2703bSAndreas Gohr 2717*72b2703bSAndreas GohrCompare: 2718*72b2703bSAndreas Gohr 2719*72b2703bSAndreas Gohr```````````````````````````````` example 2720*72b2703bSAndreas Gohr<div> 2721*72b2703bSAndreas Gohr 2722*72b2703bSAndreas Gohr*Emphasized* text. 2723*72b2703bSAndreas Gohr 2724*72b2703bSAndreas Gohr</div> 2725*72b2703bSAndreas Gohr. 2726*72b2703bSAndreas Gohr<div> 2727*72b2703bSAndreas Gohr<p><em>Emphasized</em> text.</p> 2728*72b2703bSAndreas Gohr</div> 2729*72b2703bSAndreas Gohr```````````````````````````````` 2730*72b2703bSAndreas Gohr 2731*72b2703bSAndreas Gohr 2732*72b2703bSAndreas Gohr```````````````````````````````` example 2733*72b2703bSAndreas Gohr<div> 2734*72b2703bSAndreas Gohr*Emphasized* text. 2735*72b2703bSAndreas Gohr</div> 2736*72b2703bSAndreas Gohr. 2737*72b2703bSAndreas Gohr<div> 2738*72b2703bSAndreas Gohr*Emphasized* text. 2739*72b2703bSAndreas Gohr</div> 2740*72b2703bSAndreas Gohr```````````````````````````````` 2741*72b2703bSAndreas Gohr 2742*72b2703bSAndreas Gohr 2743*72b2703bSAndreas GohrSome Markdown implementations have adopted a convention of 2744*72b2703bSAndreas Gohrinterpreting content inside tags as text if the open tag has 2745*72b2703bSAndreas Gohrthe attribute `markdown=1`. The rule given above seems a simpler and 2746*72b2703bSAndreas Gohrmore elegant way of achieving the same expressive power, which is also 2747*72b2703bSAndreas Gohrmuch simpler to parse. 2748*72b2703bSAndreas Gohr 2749*72b2703bSAndreas GohrThe main potential drawback is that one can no longer paste HTML 2750*72b2703bSAndreas Gohrblocks into Markdown documents with 100% reliability. However, 2751*72b2703bSAndreas Gohr*in most cases* this will work fine, because the blank lines in 2752*72b2703bSAndreas GohrHTML are usually followed by HTML block tags. For example: 2753*72b2703bSAndreas Gohr 2754*72b2703bSAndreas Gohr```````````````````````````````` example 2755*72b2703bSAndreas Gohr<table> 2756*72b2703bSAndreas Gohr 2757*72b2703bSAndreas Gohr<tr> 2758*72b2703bSAndreas Gohr 2759*72b2703bSAndreas Gohr<td> 2760*72b2703bSAndreas GohrHi 2761*72b2703bSAndreas Gohr</td> 2762*72b2703bSAndreas Gohr 2763*72b2703bSAndreas Gohr</tr> 2764*72b2703bSAndreas Gohr 2765*72b2703bSAndreas Gohr</table> 2766*72b2703bSAndreas Gohr. 2767*72b2703bSAndreas Gohr<table> 2768*72b2703bSAndreas Gohr<tr> 2769*72b2703bSAndreas Gohr<td> 2770*72b2703bSAndreas GohrHi 2771*72b2703bSAndreas Gohr</td> 2772*72b2703bSAndreas Gohr</tr> 2773*72b2703bSAndreas Gohr</table> 2774*72b2703bSAndreas Gohr```````````````````````````````` 2775*72b2703bSAndreas Gohr 2776*72b2703bSAndreas Gohr 2777*72b2703bSAndreas GohrThere are problems, however, if the inner tags are indented 2778*72b2703bSAndreas Gohr*and* separated by spaces, as then they will be interpreted as 2779*72b2703bSAndreas Gohran indented code block: 2780*72b2703bSAndreas Gohr 2781*72b2703bSAndreas Gohr```````````````````````````````` example 2782*72b2703bSAndreas Gohr<table> 2783*72b2703bSAndreas Gohr 2784*72b2703bSAndreas Gohr <tr> 2785*72b2703bSAndreas Gohr 2786*72b2703bSAndreas Gohr <td> 2787*72b2703bSAndreas Gohr Hi 2788*72b2703bSAndreas Gohr </td> 2789*72b2703bSAndreas Gohr 2790*72b2703bSAndreas Gohr </tr> 2791*72b2703bSAndreas Gohr 2792*72b2703bSAndreas Gohr</table> 2793*72b2703bSAndreas Gohr. 2794*72b2703bSAndreas Gohr<table> 2795*72b2703bSAndreas Gohr <tr> 2796*72b2703bSAndreas Gohr<pre><code><td> 2797*72b2703bSAndreas Gohr Hi 2798*72b2703bSAndreas Gohr</td> 2799*72b2703bSAndreas Gohr</code></pre> 2800*72b2703bSAndreas Gohr </tr> 2801*72b2703bSAndreas Gohr</table> 2802*72b2703bSAndreas Gohr```````````````````````````````` 2803*72b2703bSAndreas Gohr 2804*72b2703bSAndreas Gohr 2805*72b2703bSAndreas GohrFortunately, blank lines are usually not necessary and can be 2806*72b2703bSAndreas Gohrdeleted. The exception is inside `<pre>` tags, but as described 2807*72b2703bSAndreas Gohr[above][HTML blocks], raw HTML blocks starting with `<pre>` 2808*72b2703bSAndreas Gohr*can* contain blank lines. 2809*72b2703bSAndreas Gohr 2810*72b2703bSAndreas Gohr## Link reference definitions 2811*72b2703bSAndreas Gohr 2812*72b2703bSAndreas GohrA [link reference definition](@) 2813*72b2703bSAndreas Gohrconsists of a [link label], indented up to three spaces, followed 2814*72b2703bSAndreas Gohrby a colon (`:`), optional [whitespace] (including up to one 2815*72b2703bSAndreas Gohr[line ending]), a [link destination], 2816*72b2703bSAndreas Gohroptional [whitespace] (including up to one 2817*72b2703bSAndreas Gohr[line ending]), and an optional [link 2818*72b2703bSAndreas Gohrtitle], which if it is present must be separated 2819*72b2703bSAndreas Gohrfrom the [link destination] by [whitespace]. 2820*72b2703bSAndreas GohrNo further [non-whitespace characters] may occur on the line. 2821*72b2703bSAndreas Gohr 2822*72b2703bSAndreas GohrA [link reference definition] 2823*72b2703bSAndreas Gohrdoes not correspond to a structural element of a document. Instead, it 2824*72b2703bSAndreas Gohrdefines a label which can be used in [reference links] 2825*72b2703bSAndreas Gohrand reference-style [images] elsewhere in the document. [Link 2826*72b2703bSAndreas Gohrreference definitions] can come either before or after the links that use 2827*72b2703bSAndreas Gohrthem. 2828*72b2703bSAndreas Gohr 2829*72b2703bSAndreas Gohr```````````````````````````````` example 2830*72b2703bSAndreas Gohr[foo]: /url "title" 2831*72b2703bSAndreas Gohr 2832*72b2703bSAndreas Gohr[foo] 2833*72b2703bSAndreas Gohr. 2834*72b2703bSAndreas Gohr<p><a href="/url" title="title">foo</a></p> 2835*72b2703bSAndreas Gohr```````````````````````````````` 2836*72b2703bSAndreas Gohr 2837*72b2703bSAndreas Gohr 2838*72b2703bSAndreas Gohr```````````````````````````````` example 2839*72b2703bSAndreas Gohr [foo]: 2840*72b2703bSAndreas Gohr /url 2841*72b2703bSAndreas Gohr 'the title' 2842*72b2703bSAndreas Gohr 2843*72b2703bSAndreas Gohr[foo] 2844*72b2703bSAndreas Gohr. 2845*72b2703bSAndreas Gohr<p><a href="/url" title="the title">foo</a></p> 2846*72b2703bSAndreas Gohr```````````````````````````````` 2847*72b2703bSAndreas Gohr 2848*72b2703bSAndreas Gohr 2849*72b2703bSAndreas Gohr```````````````````````````````` example 2850*72b2703bSAndreas Gohr[Foo*bar\]]:my_(url) 'title (with parens)' 2851*72b2703bSAndreas Gohr 2852*72b2703bSAndreas Gohr[Foo*bar\]] 2853*72b2703bSAndreas Gohr. 2854*72b2703bSAndreas Gohr<p><a href="my_(url)" title="title (with parens)">Foo*bar]</a></p> 2855*72b2703bSAndreas Gohr```````````````````````````````` 2856*72b2703bSAndreas Gohr 2857*72b2703bSAndreas Gohr 2858*72b2703bSAndreas Gohr```````````````````````````````` example 2859*72b2703bSAndreas Gohr[Foo bar]: 2860*72b2703bSAndreas Gohr<my url> 2861*72b2703bSAndreas Gohr'title' 2862*72b2703bSAndreas Gohr 2863*72b2703bSAndreas Gohr[Foo bar] 2864*72b2703bSAndreas Gohr. 2865*72b2703bSAndreas Gohr<p><a href="my%20url" title="title">Foo bar</a></p> 2866*72b2703bSAndreas Gohr```````````````````````````````` 2867*72b2703bSAndreas Gohr 2868*72b2703bSAndreas Gohr 2869*72b2703bSAndreas GohrThe title may extend over multiple lines: 2870*72b2703bSAndreas Gohr 2871*72b2703bSAndreas Gohr```````````````````````````````` example 2872*72b2703bSAndreas Gohr[foo]: /url ' 2873*72b2703bSAndreas Gohrtitle 2874*72b2703bSAndreas Gohrline1 2875*72b2703bSAndreas Gohrline2 2876*72b2703bSAndreas Gohr' 2877*72b2703bSAndreas Gohr 2878*72b2703bSAndreas Gohr[foo] 2879*72b2703bSAndreas Gohr. 2880*72b2703bSAndreas Gohr<p><a href="/url" title=" 2881*72b2703bSAndreas Gohrtitle 2882*72b2703bSAndreas Gohrline1 2883*72b2703bSAndreas Gohrline2 2884*72b2703bSAndreas Gohr">foo</a></p> 2885*72b2703bSAndreas Gohr```````````````````````````````` 2886*72b2703bSAndreas Gohr 2887*72b2703bSAndreas Gohr 2888*72b2703bSAndreas GohrHowever, it may not contain a [blank line]: 2889*72b2703bSAndreas Gohr 2890*72b2703bSAndreas Gohr```````````````````````````````` example 2891*72b2703bSAndreas Gohr[foo]: /url 'title 2892*72b2703bSAndreas Gohr 2893*72b2703bSAndreas Gohrwith blank line' 2894*72b2703bSAndreas Gohr 2895*72b2703bSAndreas Gohr[foo] 2896*72b2703bSAndreas Gohr. 2897*72b2703bSAndreas Gohr<p>[foo]: /url 'title</p> 2898*72b2703bSAndreas Gohr<p>with blank line'</p> 2899*72b2703bSAndreas Gohr<p>[foo]</p> 2900*72b2703bSAndreas Gohr```````````````````````````````` 2901*72b2703bSAndreas Gohr 2902*72b2703bSAndreas Gohr 2903*72b2703bSAndreas GohrThe title may be omitted: 2904*72b2703bSAndreas Gohr 2905*72b2703bSAndreas Gohr```````````````````````````````` example 2906*72b2703bSAndreas Gohr[foo]: 2907*72b2703bSAndreas Gohr/url 2908*72b2703bSAndreas Gohr 2909*72b2703bSAndreas Gohr[foo] 2910*72b2703bSAndreas Gohr. 2911*72b2703bSAndreas Gohr<p><a href="/url">foo</a></p> 2912*72b2703bSAndreas Gohr```````````````````````````````` 2913*72b2703bSAndreas Gohr 2914*72b2703bSAndreas Gohr 2915*72b2703bSAndreas GohrThe link destination may not be omitted: 2916*72b2703bSAndreas Gohr 2917*72b2703bSAndreas Gohr```````````````````````````````` example 2918*72b2703bSAndreas Gohr[foo]: 2919*72b2703bSAndreas Gohr 2920*72b2703bSAndreas Gohr[foo] 2921*72b2703bSAndreas Gohr. 2922*72b2703bSAndreas Gohr<p>[foo]:</p> 2923*72b2703bSAndreas Gohr<p>[foo]</p> 2924*72b2703bSAndreas Gohr```````````````````````````````` 2925*72b2703bSAndreas Gohr 2926*72b2703bSAndreas Gohr However, an empty link destination may be specified using 2927*72b2703bSAndreas Gohr angle brackets: 2928*72b2703bSAndreas Gohr 2929*72b2703bSAndreas Gohr```````````````````````````````` example 2930*72b2703bSAndreas Gohr[foo]: <> 2931*72b2703bSAndreas Gohr 2932*72b2703bSAndreas Gohr[foo] 2933*72b2703bSAndreas Gohr. 2934*72b2703bSAndreas Gohr<p><a href="">foo</a></p> 2935*72b2703bSAndreas Gohr```````````````````````````````` 2936*72b2703bSAndreas Gohr 2937*72b2703bSAndreas GohrThe title must be separated from the link destination by 2938*72b2703bSAndreas Gohrwhitespace: 2939*72b2703bSAndreas Gohr 2940*72b2703bSAndreas Gohr```````````````````````````````` example 2941*72b2703bSAndreas Gohr[foo]: <bar>(baz) 2942*72b2703bSAndreas Gohr 2943*72b2703bSAndreas Gohr[foo] 2944*72b2703bSAndreas Gohr. 2945*72b2703bSAndreas Gohr<p>[foo]: <bar>(baz)</p> 2946*72b2703bSAndreas Gohr<p>[foo]</p> 2947*72b2703bSAndreas Gohr```````````````````````````````` 2948*72b2703bSAndreas Gohr 2949*72b2703bSAndreas Gohr 2950*72b2703bSAndreas GohrBoth title and destination can contain backslash escapes 2951*72b2703bSAndreas Gohrand literal backslashes: 2952*72b2703bSAndreas Gohr 2953*72b2703bSAndreas Gohr```````````````````````````````` example 2954*72b2703bSAndreas Gohr[foo]: /url\bar\*baz "foo\"bar\baz" 2955*72b2703bSAndreas Gohr 2956*72b2703bSAndreas Gohr[foo] 2957*72b2703bSAndreas Gohr. 2958*72b2703bSAndreas Gohr<p><a href="/url%5Cbar*baz" title="foo"bar\baz">foo</a></p> 2959*72b2703bSAndreas Gohr```````````````````````````````` 2960*72b2703bSAndreas Gohr 2961*72b2703bSAndreas Gohr 2962*72b2703bSAndreas GohrA link can come before its corresponding definition: 2963*72b2703bSAndreas Gohr 2964*72b2703bSAndreas Gohr```````````````````````````````` example 2965*72b2703bSAndreas Gohr[foo] 2966*72b2703bSAndreas Gohr 2967*72b2703bSAndreas Gohr[foo]: url 2968*72b2703bSAndreas Gohr. 2969*72b2703bSAndreas Gohr<p><a href="url">foo</a></p> 2970*72b2703bSAndreas Gohr```````````````````````````````` 2971*72b2703bSAndreas Gohr 2972*72b2703bSAndreas Gohr 2973*72b2703bSAndreas GohrIf there are several matching definitions, the first one takes 2974*72b2703bSAndreas Gohrprecedence: 2975*72b2703bSAndreas Gohr 2976*72b2703bSAndreas Gohr```````````````````````````````` example 2977*72b2703bSAndreas Gohr[foo] 2978*72b2703bSAndreas Gohr 2979*72b2703bSAndreas Gohr[foo]: first 2980*72b2703bSAndreas Gohr[foo]: second 2981*72b2703bSAndreas Gohr. 2982*72b2703bSAndreas Gohr<p><a href="first">foo</a></p> 2983*72b2703bSAndreas Gohr```````````````````````````````` 2984*72b2703bSAndreas Gohr 2985*72b2703bSAndreas Gohr 2986*72b2703bSAndreas GohrAs noted in the section on [Links], matching of labels is 2987*72b2703bSAndreas Gohrcase-insensitive (see [matches]). 2988*72b2703bSAndreas Gohr 2989*72b2703bSAndreas Gohr```````````````````````````````` example 2990*72b2703bSAndreas Gohr[FOO]: /url 2991*72b2703bSAndreas Gohr 2992*72b2703bSAndreas Gohr[Foo] 2993*72b2703bSAndreas Gohr. 2994*72b2703bSAndreas Gohr<p><a href="/url">Foo</a></p> 2995*72b2703bSAndreas Gohr```````````````````````````````` 2996*72b2703bSAndreas Gohr 2997*72b2703bSAndreas Gohr 2998*72b2703bSAndreas Gohr```````````````````````````````` example 2999*72b2703bSAndreas Gohr[ΑΓΩ]: /φου 3000*72b2703bSAndreas Gohr 3001*72b2703bSAndreas Gohr[αγω] 3002*72b2703bSAndreas Gohr. 3003*72b2703bSAndreas Gohr<p><a href="/%CF%86%CE%BF%CF%85">αγω</a></p> 3004*72b2703bSAndreas Gohr```````````````````````````````` 3005*72b2703bSAndreas Gohr 3006*72b2703bSAndreas Gohr 3007*72b2703bSAndreas GohrHere is a link reference definition with no corresponding link. 3008*72b2703bSAndreas GohrIt contributes nothing to the document. 3009*72b2703bSAndreas Gohr 3010*72b2703bSAndreas Gohr```````````````````````````````` example 3011*72b2703bSAndreas Gohr[foo]: /url 3012*72b2703bSAndreas Gohr. 3013*72b2703bSAndreas Gohr```````````````````````````````` 3014*72b2703bSAndreas Gohr 3015*72b2703bSAndreas Gohr 3016*72b2703bSAndreas GohrHere is another one: 3017*72b2703bSAndreas Gohr 3018*72b2703bSAndreas Gohr```````````````````````````````` example 3019*72b2703bSAndreas Gohr[ 3020*72b2703bSAndreas Gohrfoo 3021*72b2703bSAndreas Gohr]: /url 3022*72b2703bSAndreas Gohrbar 3023*72b2703bSAndreas Gohr. 3024*72b2703bSAndreas Gohr<p>bar</p> 3025*72b2703bSAndreas Gohr```````````````````````````````` 3026*72b2703bSAndreas Gohr 3027*72b2703bSAndreas Gohr 3028*72b2703bSAndreas GohrThis is not a link reference definition, because there are 3029*72b2703bSAndreas Gohr[non-whitespace characters] after the title: 3030*72b2703bSAndreas Gohr 3031*72b2703bSAndreas Gohr```````````````````````````````` example 3032*72b2703bSAndreas Gohr[foo]: /url "title" ok 3033*72b2703bSAndreas Gohr. 3034*72b2703bSAndreas Gohr<p>[foo]: /url "title" ok</p> 3035*72b2703bSAndreas Gohr```````````````````````````````` 3036*72b2703bSAndreas Gohr 3037*72b2703bSAndreas Gohr 3038*72b2703bSAndreas GohrThis is a link reference definition, but it has no title: 3039*72b2703bSAndreas Gohr 3040*72b2703bSAndreas Gohr```````````````````````````````` example 3041*72b2703bSAndreas Gohr[foo]: /url 3042*72b2703bSAndreas Gohr"title" ok 3043*72b2703bSAndreas Gohr. 3044*72b2703bSAndreas Gohr<p>"title" ok</p> 3045*72b2703bSAndreas Gohr```````````````````````````````` 3046*72b2703bSAndreas Gohr 3047*72b2703bSAndreas Gohr 3048*72b2703bSAndreas GohrThis is not a link reference definition, because it is indented 3049*72b2703bSAndreas Gohrfour spaces: 3050*72b2703bSAndreas Gohr 3051*72b2703bSAndreas Gohr```````````````````````````````` example 3052*72b2703bSAndreas Gohr [foo]: /url "title" 3053*72b2703bSAndreas Gohr 3054*72b2703bSAndreas Gohr[foo] 3055*72b2703bSAndreas Gohr. 3056*72b2703bSAndreas Gohr<pre><code>[foo]: /url "title" 3057*72b2703bSAndreas Gohr</code></pre> 3058*72b2703bSAndreas Gohr<p>[foo]</p> 3059*72b2703bSAndreas Gohr```````````````````````````````` 3060*72b2703bSAndreas Gohr 3061*72b2703bSAndreas Gohr 3062*72b2703bSAndreas GohrThis is not a link reference definition, because it occurs inside 3063*72b2703bSAndreas Gohra code block: 3064*72b2703bSAndreas Gohr 3065*72b2703bSAndreas Gohr```````````````````````````````` example 3066*72b2703bSAndreas Gohr``` 3067*72b2703bSAndreas Gohr[foo]: /url 3068*72b2703bSAndreas Gohr``` 3069*72b2703bSAndreas Gohr 3070*72b2703bSAndreas Gohr[foo] 3071*72b2703bSAndreas Gohr. 3072*72b2703bSAndreas Gohr<pre><code>[foo]: /url 3073*72b2703bSAndreas Gohr</code></pre> 3074*72b2703bSAndreas Gohr<p>[foo]</p> 3075*72b2703bSAndreas Gohr```````````````````````````````` 3076*72b2703bSAndreas Gohr 3077*72b2703bSAndreas Gohr 3078*72b2703bSAndreas GohrA [link reference definition] cannot interrupt a paragraph. 3079*72b2703bSAndreas Gohr 3080*72b2703bSAndreas Gohr```````````````````````````````` example 3081*72b2703bSAndreas GohrFoo 3082*72b2703bSAndreas Gohr[bar]: /baz 3083*72b2703bSAndreas Gohr 3084*72b2703bSAndreas Gohr[bar] 3085*72b2703bSAndreas Gohr. 3086*72b2703bSAndreas Gohr<p>Foo 3087*72b2703bSAndreas Gohr[bar]: /baz</p> 3088*72b2703bSAndreas Gohr<p>[bar]</p> 3089*72b2703bSAndreas Gohr```````````````````````````````` 3090*72b2703bSAndreas Gohr 3091*72b2703bSAndreas Gohr 3092*72b2703bSAndreas GohrHowever, it can directly follow other block elements, such as headings 3093*72b2703bSAndreas Gohrand thematic breaks, and it need not be followed by a blank line. 3094*72b2703bSAndreas Gohr 3095*72b2703bSAndreas Gohr```````````````````````````````` example 3096*72b2703bSAndreas Gohr# [Foo] 3097*72b2703bSAndreas Gohr[foo]: /url 3098*72b2703bSAndreas Gohr> bar 3099*72b2703bSAndreas Gohr. 3100*72b2703bSAndreas Gohr<h1><a href="/url">Foo</a></h1> 3101*72b2703bSAndreas Gohr<blockquote> 3102*72b2703bSAndreas Gohr<p>bar</p> 3103*72b2703bSAndreas Gohr</blockquote> 3104*72b2703bSAndreas Gohr```````````````````````````````` 3105*72b2703bSAndreas Gohr 3106*72b2703bSAndreas Gohr```````````````````````````````` example 3107*72b2703bSAndreas Gohr[foo]: /url 3108*72b2703bSAndreas Gohrbar 3109*72b2703bSAndreas Gohr=== 3110*72b2703bSAndreas Gohr[foo] 3111*72b2703bSAndreas Gohr. 3112*72b2703bSAndreas Gohr<h1>bar</h1> 3113*72b2703bSAndreas Gohr<p><a href="/url">foo</a></p> 3114*72b2703bSAndreas Gohr```````````````````````````````` 3115*72b2703bSAndreas Gohr 3116*72b2703bSAndreas Gohr```````````````````````````````` example 3117*72b2703bSAndreas Gohr[foo]: /url 3118*72b2703bSAndreas Gohr=== 3119*72b2703bSAndreas Gohr[foo] 3120*72b2703bSAndreas Gohr. 3121*72b2703bSAndreas Gohr<p>=== 3122*72b2703bSAndreas Gohr<a href="/url">foo</a></p> 3123*72b2703bSAndreas Gohr```````````````````````````````` 3124*72b2703bSAndreas Gohr 3125*72b2703bSAndreas Gohr 3126*72b2703bSAndreas GohrSeveral [link reference definitions] 3127*72b2703bSAndreas Gohrcan occur one after another, without intervening blank lines. 3128*72b2703bSAndreas Gohr 3129*72b2703bSAndreas Gohr```````````````````````````````` example 3130*72b2703bSAndreas Gohr[foo]: /foo-url "foo" 3131*72b2703bSAndreas Gohr[bar]: /bar-url 3132*72b2703bSAndreas Gohr "bar" 3133*72b2703bSAndreas Gohr[baz]: /baz-url 3134*72b2703bSAndreas Gohr 3135*72b2703bSAndreas Gohr[foo], 3136*72b2703bSAndreas Gohr[bar], 3137*72b2703bSAndreas Gohr[baz] 3138*72b2703bSAndreas Gohr. 3139*72b2703bSAndreas Gohr<p><a href="/foo-url" title="foo">foo</a>, 3140*72b2703bSAndreas Gohr<a href="/bar-url" title="bar">bar</a>, 3141*72b2703bSAndreas Gohr<a href="/baz-url">baz</a></p> 3142*72b2703bSAndreas Gohr```````````````````````````````` 3143*72b2703bSAndreas Gohr 3144*72b2703bSAndreas Gohr 3145*72b2703bSAndreas Gohr[Link reference definitions] can occur 3146*72b2703bSAndreas Gohrinside block containers, like lists and block quotations. They 3147*72b2703bSAndreas Gohraffect the entire document, not just the container in which they 3148*72b2703bSAndreas Gohrare defined: 3149*72b2703bSAndreas Gohr 3150*72b2703bSAndreas Gohr```````````````````````````````` example 3151*72b2703bSAndreas Gohr[foo] 3152*72b2703bSAndreas Gohr 3153*72b2703bSAndreas Gohr> [foo]: /url 3154*72b2703bSAndreas Gohr. 3155*72b2703bSAndreas Gohr<p><a href="/url">foo</a></p> 3156*72b2703bSAndreas Gohr<blockquote> 3157*72b2703bSAndreas Gohr</blockquote> 3158*72b2703bSAndreas Gohr```````````````````````````````` 3159*72b2703bSAndreas Gohr 3160*72b2703bSAndreas Gohr 3161*72b2703bSAndreas GohrWhether something is a [link reference definition] is 3162*72b2703bSAndreas Gohrindependent of whether the link reference it defines is 3163*72b2703bSAndreas Gohrused in the document. Thus, for example, the following 3164*72b2703bSAndreas Gohrdocument contains just a link reference definition, and 3165*72b2703bSAndreas Gohrno visible content: 3166*72b2703bSAndreas Gohr 3167*72b2703bSAndreas Gohr```````````````````````````````` example 3168*72b2703bSAndreas Gohr[foo]: /url 3169*72b2703bSAndreas Gohr. 3170*72b2703bSAndreas Gohr```````````````````````````````` 3171*72b2703bSAndreas Gohr 3172*72b2703bSAndreas Gohr 3173*72b2703bSAndreas Gohr## Paragraphs 3174*72b2703bSAndreas Gohr 3175*72b2703bSAndreas GohrA sequence of non-blank lines that cannot be interpreted as other 3176*72b2703bSAndreas Gohrkinds of blocks forms a [paragraph](@). 3177*72b2703bSAndreas GohrThe contents of the paragraph are the result of parsing the 3178*72b2703bSAndreas Gohrparagraph's raw content as inlines. The paragraph's raw content 3179*72b2703bSAndreas Gohris formed by concatenating the lines and removing initial and final 3180*72b2703bSAndreas Gohr[whitespace]. 3181*72b2703bSAndreas Gohr 3182*72b2703bSAndreas GohrA simple example with two paragraphs: 3183*72b2703bSAndreas Gohr 3184*72b2703bSAndreas Gohr```````````````````````````````` example 3185*72b2703bSAndreas Gohraaa 3186*72b2703bSAndreas Gohr 3187*72b2703bSAndreas Gohrbbb 3188*72b2703bSAndreas Gohr. 3189*72b2703bSAndreas Gohr<p>aaa</p> 3190*72b2703bSAndreas Gohr<p>bbb</p> 3191*72b2703bSAndreas Gohr```````````````````````````````` 3192*72b2703bSAndreas Gohr 3193*72b2703bSAndreas Gohr 3194*72b2703bSAndreas GohrParagraphs can contain multiple lines, but no blank lines: 3195*72b2703bSAndreas Gohr 3196*72b2703bSAndreas Gohr```````````````````````````````` example 3197*72b2703bSAndreas Gohraaa 3198*72b2703bSAndreas Gohrbbb 3199*72b2703bSAndreas Gohr 3200*72b2703bSAndreas Gohrccc 3201*72b2703bSAndreas Gohrddd 3202*72b2703bSAndreas Gohr. 3203*72b2703bSAndreas Gohr<p>aaa 3204*72b2703bSAndreas Gohrbbb</p> 3205*72b2703bSAndreas Gohr<p>ccc 3206*72b2703bSAndreas Gohrddd</p> 3207*72b2703bSAndreas Gohr```````````````````````````````` 3208*72b2703bSAndreas Gohr 3209*72b2703bSAndreas Gohr 3210*72b2703bSAndreas GohrMultiple blank lines between paragraph have no effect: 3211*72b2703bSAndreas Gohr 3212*72b2703bSAndreas Gohr```````````````````````````````` example 3213*72b2703bSAndreas Gohraaa 3214*72b2703bSAndreas Gohr 3215*72b2703bSAndreas Gohr 3216*72b2703bSAndreas Gohrbbb 3217*72b2703bSAndreas Gohr. 3218*72b2703bSAndreas Gohr<p>aaa</p> 3219*72b2703bSAndreas Gohr<p>bbb</p> 3220*72b2703bSAndreas Gohr```````````````````````````````` 3221*72b2703bSAndreas Gohr 3222*72b2703bSAndreas Gohr 3223*72b2703bSAndreas GohrLeading spaces are skipped: 3224*72b2703bSAndreas Gohr 3225*72b2703bSAndreas Gohr```````````````````````````````` example 3226*72b2703bSAndreas Gohr aaa 3227*72b2703bSAndreas Gohr bbb 3228*72b2703bSAndreas Gohr. 3229*72b2703bSAndreas Gohr<p>aaa 3230*72b2703bSAndreas Gohrbbb</p> 3231*72b2703bSAndreas Gohr```````````````````````````````` 3232*72b2703bSAndreas Gohr 3233*72b2703bSAndreas Gohr 3234*72b2703bSAndreas GohrLines after the first may be indented any amount, since indented 3235*72b2703bSAndreas Gohrcode blocks cannot interrupt paragraphs. 3236*72b2703bSAndreas Gohr 3237*72b2703bSAndreas Gohr```````````````````````````````` example 3238*72b2703bSAndreas Gohraaa 3239*72b2703bSAndreas Gohr bbb 3240*72b2703bSAndreas Gohr ccc 3241*72b2703bSAndreas Gohr. 3242*72b2703bSAndreas Gohr<p>aaa 3243*72b2703bSAndreas Gohrbbb 3244*72b2703bSAndreas Gohrccc</p> 3245*72b2703bSAndreas Gohr```````````````````````````````` 3246*72b2703bSAndreas Gohr 3247*72b2703bSAndreas Gohr 3248*72b2703bSAndreas GohrHowever, the first line may be indented at most three spaces, 3249*72b2703bSAndreas Gohror an indented code block will be triggered: 3250*72b2703bSAndreas Gohr 3251*72b2703bSAndreas Gohr```````````````````````````````` example 3252*72b2703bSAndreas Gohr aaa 3253*72b2703bSAndreas Gohrbbb 3254*72b2703bSAndreas Gohr. 3255*72b2703bSAndreas Gohr<p>aaa 3256*72b2703bSAndreas Gohrbbb</p> 3257*72b2703bSAndreas Gohr```````````````````````````````` 3258*72b2703bSAndreas Gohr 3259*72b2703bSAndreas Gohr 3260*72b2703bSAndreas Gohr```````````````````````````````` example 3261*72b2703bSAndreas Gohr aaa 3262*72b2703bSAndreas Gohrbbb 3263*72b2703bSAndreas Gohr. 3264*72b2703bSAndreas Gohr<pre><code>aaa 3265*72b2703bSAndreas Gohr</code></pre> 3266*72b2703bSAndreas Gohr<p>bbb</p> 3267*72b2703bSAndreas Gohr```````````````````````````````` 3268*72b2703bSAndreas Gohr 3269*72b2703bSAndreas Gohr 3270*72b2703bSAndreas GohrFinal spaces are stripped before inline parsing, so a paragraph 3271*72b2703bSAndreas Gohrthat ends with two or more spaces will not end with a [hard line 3272*72b2703bSAndreas Gohrbreak]: 3273*72b2703bSAndreas Gohr 3274*72b2703bSAndreas Gohr```````````````````````````````` example 3275*72b2703bSAndreas Gohraaa 3276*72b2703bSAndreas Gohrbbb 3277*72b2703bSAndreas Gohr. 3278*72b2703bSAndreas Gohr<p>aaa<br /> 3279*72b2703bSAndreas Gohrbbb</p> 3280*72b2703bSAndreas Gohr```````````````````````````````` 3281*72b2703bSAndreas Gohr 3282*72b2703bSAndreas Gohr 3283*72b2703bSAndreas Gohr## Blank lines 3284*72b2703bSAndreas Gohr 3285*72b2703bSAndreas Gohr[Blank lines] between block-level elements are ignored, 3286*72b2703bSAndreas Gohrexcept for the role they play in determining whether a [list] 3287*72b2703bSAndreas Gohris [tight] or [loose]. 3288*72b2703bSAndreas Gohr 3289*72b2703bSAndreas GohrBlank lines at the beginning and end of the document are also ignored. 3290*72b2703bSAndreas Gohr 3291*72b2703bSAndreas Gohr```````````````````````````````` example 3292*72b2703bSAndreas Gohr 3293*72b2703bSAndreas Gohr 3294*72b2703bSAndreas Gohraaa 3295*72b2703bSAndreas Gohr 3296*72b2703bSAndreas Gohr 3297*72b2703bSAndreas Gohr# aaa 3298*72b2703bSAndreas Gohr 3299*72b2703bSAndreas Gohr 3300*72b2703bSAndreas Gohr. 3301*72b2703bSAndreas Gohr<p>aaa</p> 3302*72b2703bSAndreas Gohr<h1>aaa</h1> 3303*72b2703bSAndreas Gohr```````````````````````````````` 3304*72b2703bSAndreas Gohr 3305*72b2703bSAndreas Gohr<div class="extension"> 3306*72b2703bSAndreas Gohr 3307*72b2703bSAndreas Gohr## Tables (extension) 3308*72b2703bSAndreas Gohr 3309*72b2703bSAndreas GohrGFM enables the `table` extension, where an additional leaf block type is 3310*72b2703bSAndreas Gohravailable. 3311*72b2703bSAndreas Gohr 3312*72b2703bSAndreas GohrA [table](@) is an arrangement of data with rows and columns, consisting of a 3313*72b2703bSAndreas Gohrsingle header row, a [delimiter row] separating the header from the data, and 3314*72b2703bSAndreas Gohrzero or more data rows. 3315*72b2703bSAndreas Gohr 3316*72b2703bSAndreas GohrEach row consists of cells containing arbitrary text, in which [inlines] are 3317*72b2703bSAndreas Gohrparsed, separated by pipes (`|`). A leading and trailing pipe is also 3318*72b2703bSAndreas Gohrrecommended for clarity of reading, and if there's otherwise parsing ambiguity. 3319*72b2703bSAndreas GohrSpaces between pipes and cell content are trimmed. Block-level elements cannot 3320*72b2703bSAndreas Gohrbe inserted in a table. 3321*72b2703bSAndreas Gohr 3322*72b2703bSAndreas GohrThe [delimiter row](@) consists of cells whose only content are hyphens (`-`), 3323*72b2703bSAndreas Gohrand optionally, a leading or trailing colon (`:`), or both, to indicate left, 3324*72b2703bSAndreas Gohrright, or center alignment respectively. 3325*72b2703bSAndreas Gohr 3326*72b2703bSAndreas Gohr```````````````````````````````` example table 3327*72b2703bSAndreas Gohr| foo | bar | 3328*72b2703bSAndreas Gohr| --- | --- | 3329*72b2703bSAndreas Gohr| baz | bim | 3330*72b2703bSAndreas Gohr. 3331*72b2703bSAndreas Gohr<table> 3332*72b2703bSAndreas Gohr<thead> 3333*72b2703bSAndreas Gohr<tr> 3334*72b2703bSAndreas Gohr<th>foo</th> 3335*72b2703bSAndreas Gohr<th>bar</th> 3336*72b2703bSAndreas Gohr</tr> 3337*72b2703bSAndreas Gohr</thead> 3338*72b2703bSAndreas Gohr<tbody> 3339*72b2703bSAndreas Gohr<tr> 3340*72b2703bSAndreas Gohr<td>baz</td> 3341*72b2703bSAndreas Gohr<td>bim</td> 3342*72b2703bSAndreas Gohr</tr> 3343*72b2703bSAndreas Gohr</tbody> 3344*72b2703bSAndreas Gohr</table> 3345*72b2703bSAndreas Gohr```````````````````````````````` 3346*72b2703bSAndreas Gohr 3347*72b2703bSAndreas GohrCells in one column don't need to match length, though it's easier to read if 3348*72b2703bSAndreas Gohrthey are. Likewise, use of leading and trailing pipes may be inconsistent: 3349*72b2703bSAndreas Gohr 3350*72b2703bSAndreas Gohr```````````````````````````````` example table 3351*72b2703bSAndreas Gohr| abc | defghi | 3352*72b2703bSAndreas Gohr:-: | -----------: 3353*72b2703bSAndreas Gohrbar | baz 3354*72b2703bSAndreas Gohr. 3355*72b2703bSAndreas Gohr<table> 3356*72b2703bSAndreas Gohr<thead> 3357*72b2703bSAndreas Gohr<tr> 3358*72b2703bSAndreas Gohr<th align="center">abc</th> 3359*72b2703bSAndreas Gohr<th align="right">defghi</th> 3360*72b2703bSAndreas Gohr</tr> 3361*72b2703bSAndreas Gohr</thead> 3362*72b2703bSAndreas Gohr<tbody> 3363*72b2703bSAndreas Gohr<tr> 3364*72b2703bSAndreas Gohr<td align="center">bar</td> 3365*72b2703bSAndreas Gohr<td align="right">baz</td> 3366*72b2703bSAndreas Gohr</tr> 3367*72b2703bSAndreas Gohr</tbody> 3368*72b2703bSAndreas Gohr</table> 3369*72b2703bSAndreas Gohr```````````````````````````````` 3370*72b2703bSAndreas Gohr 3371*72b2703bSAndreas GohrInclude a pipe in a cell's content by escaping it, including inside other 3372*72b2703bSAndreas Gohrinline spans: 3373*72b2703bSAndreas Gohr 3374*72b2703bSAndreas Gohr```````````````````````````````` example table 3375*72b2703bSAndreas Gohr| f\|oo | 3376*72b2703bSAndreas Gohr| ------ | 3377*72b2703bSAndreas Gohr| b `\|` az | 3378*72b2703bSAndreas Gohr| b **\|** im | 3379*72b2703bSAndreas Gohr. 3380*72b2703bSAndreas Gohr<table> 3381*72b2703bSAndreas Gohr<thead> 3382*72b2703bSAndreas Gohr<tr> 3383*72b2703bSAndreas Gohr<th>f|oo</th> 3384*72b2703bSAndreas Gohr</tr> 3385*72b2703bSAndreas Gohr</thead> 3386*72b2703bSAndreas Gohr<tbody> 3387*72b2703bSAndreas Gohr<tr> 3388*72b2703bSAndreas Gohr<td>b <code>|</code> az</td> 3389*72b2703bSAndreas Gohr</tr> 3390*72b2703bSAndreas Gohr<tr> 3391*72b2703bSAndreas Gohr<td>b <strong>|</strong> im</td> 3392*72b2703bSAndreas Gohr</tr> 3393*72b2703bSAndreas Gohr</tbody> 3394*72b2703bSAndreas Gohr</table> 3395*72b2703bSAndreas Gohr```````````````````````````````` 3396*72b2703bSAndreas Gohr 3397*72b2703bSAndreas GohrThe table is broken at the first empty line, or beginning of another 3398*72b2703bSAndreas Gohrblock-level structure: 3399*72b2703bSAndreas Gohr 3400*72b2703bSAndreas Gohr```````````````````````````````` example table 3401*72b2703bSAndreas Gohr| abc | def | 3402*72b2703bSAndreas Gohr| --- | --- | 3403*72b2703bSAndreas Gohr| bar | baz | 3404*72b2703bSAndreas Gohr> bar 3405*72b2703bSAndreas Gohr. 3406*72b2703bSAndreas Gohr<table> 3407*72b2703bSAndreas Gohr<thead> 3408*72b2703bSAndreas Gohr<tr> 3409*72b2703bSAndreas Gohr<th>abc</th> 3410*72b2703bSAndreas Gohr<th>def</th> 3411*72b2703bSAndreas Gohr</tr> 3412*72b2703bSAndreas Gohr</thead> 3413*72b2703bSAndreas Gohr<tbody> 3414*72b2703bSAndreas Gohr<tr> 3415*72b2703bSAndreas Gohr<td>bar</td> 3416*72b2703bSAndreas Gohr<td>baz</td> 3417*72b2703bSAndreas Gohr</tr> 3418*72b2703bSAndreas Gohr</tbody> 3419*72b2703bSAndreas Gohr</table> 3420*72b2703bSAndreas Gohr<blockquote> 3421*72b2703bSAndreas Gohr<p>bar</p> 3422*72b2703bSAndreas Gohr</blockquote> 3423*72b2703bSAndreas Gohr```````````````````````````````` 3424*72b2703bSAndreas Gohr 3425*72b2703bSAndreas Gohr```````````````````````````````` example table 3426*72b2703bSAndreas Gohr| abc | def | 3427*72b2703bSAndreas Gohr| --- | --- | 3428*72b2703bSAndreas Gohr| bar | baz | 3429*72b2703bSAndreas Gohrbar 3430*72b2703bSAndreas Gohr 3431*72b2703bSAndreas Gohrbar 3432*72b2703bSAndreas Gohr. 3433*72b2703bSAndreas Gohr<table> 3434*72b2703bSAndreas Gohr<thead> 3435*72b2703bSAndreas Gohr<tr> 3436*72b2703bSAndreas Gohr<th>abc</th> 3437*72b2703bSAndreas Gohr<th>def</th> 3438*72b2703bSAndreas Gohr</tr> 3439*72b2703bSAndreas Gohr</thead> 3440*72b2703bSAndreas Gohr<tbody> 3441*72b2703bSAndreas Gohr<tr> 3442*72b2703bSAndreas Gohr<td>bar</td> 3443*72b2703bSAndreas Gohr<td>baz</td> 3444*72b2703bSAndreas Gohr</tr> 3445*72b2703bSAndreas Gohr<tr> 3446*72b2703bSAndreas Gohr<td>bar</td> 3447*72b2703bSAndreas Gohr<td></td> 3448*72b2703bSAndreas Gohr</tr> 3449*72b2703bSAndreas Gohr</tbody> 3450*72b2703bSAndreas Gohr</table> 3451*72b2703bSAndreas Gohr<p>bar</p> 3452*72b2703bSAndreas Gohr```````````````````````````````` 3453*72b2703bSAndreas Gohr 3454*72b2703bSAndreas GohrThe header row must match the [delimiter row] in the number of cells. If not, 3455*72b2703bSAndreas Gohra table will not be recognized: 3456*72b2703bSAndreas Gohr 3457*72b2703bSAndreas Gohr```````````````````````````````` example table 3458*72b2703bSAndreas Gohr| abc | def | 3459*72b2703bSAndreas Gohr| --- | 3460*72b2703bSAndreas Gohr| bar | 3461*72b2703bSAndreas Gohr. 3462*72b2703bSAndreas Gohr<p>| abc | def | 3463*72b2703bSAndreas Gohr| --- | 3464*72b2703bSAndreas Gohr| bar |</p> 3465*72b2703bSAndreas Gohr```````````````````````````````` 3466*72b2703bSAndreas Gohr 3467*72b2703bSAndreas GohrThe remainder of the table's rows may vary in the number of cells. If there 3468*72b2703bSAndreas Gohrare a number of cells fewer than the number of cells in the header row, empty 3469*72b2703bSAndreas Gohrcells are inserted. If there are greater, the excess is ignored: 3470*72b2703bSAndreas Gohr 3471*72b2703bSAndreas Gohr```````````````````````````````` example table 3472*72b2703bSAndreas Gohr| abc | def | 3473*72b2703bSAndreas Gohr| --- | --- | 3474*72b2703bSAndreas Gohr| bar | 3475*72b2703bSAndreas Gohr| bar | baz | boo | 3476*72b2703bSAndreas Gohr. 3477*72b2703bSAndreas Gohr<table> 3478*72b2703bSAndreas Gohr<thead> 3479*72b2703bSAndreas Gohr<tr> 3480*72b2703bSAndreas Gohr<th>abc</th> 3481*72b2703bSAndreas Gohr<th>def</th> 3482*72b2703bSAndreas Gohr</tr> 3483*72b2703bSAndreas Gohr</thead> 3484*72b2703bSAndreas Gohr<tbody> 3485*72b2703bSAndreas Gohr<tr> 3486*72b2703bSAndreas Gohr<td>bar</td> 3487*72b2703bSAndreas Gohr<td></td> 3488*72b2703bSAndreas Gohr</tr> 3489*72b2703bSAndreas Gohr<tr> 3490*72b2703bSAndreas Gohr<td>bar</td> 3491*72b2703bSAndreas Gohr<td>baz</td> 3492*72b2703bSAndreas Gohr</tr> 3493*72b2703bSAndreas Gohr</tbody> 3494*72b2703bSAndreas Gohr</table> 3495*72b2703bSAndreas Gohr```````````````````````````````` 3496*72b2703bSAndreas Gohr 3497*72b2703bSAndreas GohrIf there are no rows in the body, no `<tbody>` is generated in HTML output: 3498*72b2703bSAndreas Gohr 3499*72b2703bSAndreas Gohr```````````````````````````````` example table 3500*72b2703bSAndreas Gohr| abc | def | 3501*72b2703bSAndreas Gohr| --- | --- | 3502*72b2703bSAndreas Gohr. 3503*72b2703bSAndreas Gohr<table> 3504*72b2703bSAndreas Gohr<thead> 3505*72b2703bSAndreas Gohr<tr> 3506*72b2703bSAndreas Gohr<th>abc</th> 3507*72b2703bSAndreas Gohr<th>def</th> 3508*72b2703bSAndreas Gohr</tr> 3509*72b2703bSAndreas Gohr</thead> 3510*72b2703bSAndreas Gohr</table> 3511*72b2703bSAndreas Gohr```````````````````````````````` 3512*72b2703bSAndreas Gohr 3513*72b2703bSAndreas Gohr</div> 3514*72b2703bSAndreas Gohr 3515*72b2703bSAndreas Gohr# Container blocks 3516*72b2703bSAndreas Gohr 3517*72b2703bSAndreas GohrA [container block](#container-blocks) is a block that has other 3518*72b2703bSAndreas Gohrblocks as its contents. There are two basic kinds of container blocks: 3519*72b2703bSAndreas Gohr[block quotes] and [list items]. 3520*72b2703bSAndreas Gohr[Lists] are meta-containers for [list items]. 3521*72b2703bSAndreas Gohr 3522*72b2703bSAndreas GohrWe define the syntax for container blocks recursively. The general 3523*72b2703bSAndreas Gohrform of the definition is: 3524*72b2703bSAndreas Gohr 3525*72b2703bSAndreas Gohr> If X is a sequence of blocks, then the result of 3526*72b2703bSAndreas Gohr> transforming X in such-and-such a way is a container of type Y 3527*72b2703bSAndreas Gohr> with these blocks as its content. 3528*72b2703bSAndreas Gohr 3529*72b2703bSAndreas GohrSo, we explain what counts as a block quote or list item by explaining 3530*72b2703bSAndreas Gohrhow these can be *generated* from their contents. This should suffice 3531*72b2703bSAndreas Gohrto define the syntax, although it does not give a recipe for *parsing* 3532*72b2703bSAndreas Gohrthese constructions. (A recipe is provided below in the section entitled 3533*72b2703bSAndreas Gohr[A parsing strategy](#appendix-a-parsing-strategy).) 3534*72b2703bSAndreas Gohr 3535*72b2703bSAndreas Gohr## Block quotes 3536*72b2703bSAndreas Gohr 3537*72b2703bSAndreas GohrA [block quote marker](@) 3538*72b2703bSAndreas Gohrconsists of 0-3 spaces of initial indent, plus (a) the character `>` together 3539*72b2703bSAndreas Gohrwith a following space, or (b) a single character `>` not followed by a space. 3540*72b2703bSAndreas Gohr 3541*72b2703bSAndreas GohrThe following rules define [block quotes]: 3542*72b2703bSAndreas Gohr 3543*72b2703bSAndreas Gohr1. **Basic case.** If a string of lines *Ls* constitute a sequence 3544*72b2703bSAndreas Gohr of blocks *Bs*, then the result of prepending a [block quote 3545*72b2703bSAndreas Gohr marker] to the beginning of each line in *Ls* 3546*72b2703bSAndreas Gohr is a [block quote](#block-quotes) containing *Bs*. 3547*72b2703bSAndreas Gohr 3548*72b2703bSAndreas Gohr2. **Laziness.** If a string of lines *Ls* constitute a [block 3549*72b2703bSAndreas Gohr quote](#block-quotes) with contents *Bs*, then the result of deleting 3550*72b2703bSAndreas Gohr the initial [block quote marker] from one or 3551*72b2703bSAndreas Gohr more lines in which the next [non-whitespace character] after the [block 3552*72b2703bSAndreas Gohr quote marker] is [paragraph continuation 3553*72b2703bSAndreas Gohr text] is a block quote with *Bs* as its content. 3554*72b2703bSAndreas Gohr [Paragraph continuation text](@) is text 3555*72b2703bSAndreas Gohr that will be parsed as part of the content of a paragraph, but does 3556*72b2703bSAndreas Gohr not occur at the beginning of the paragraph. 3557*72b2703bSAndreas Gohr 3558*72b2703bSAndreas Gohr3. **Consecutiveness.** A document cannot contain two [block 3559*72b2703bSAndreas Gohr quotes] in a row unless there is a [blank line] between them. 3560*72b2703bSAndreas Gohr 3561*72b2703bSAndreas GohrNothing else counts as a [block quote](#block-quotes). 3562*72b2703bSAndreas Gohr 3563*72b2703bSAndreas GohrHere is a simple example: 3564*72b2703bSAndreas Gohr 3565*72b2703bSAndreas Gohr```````````````````````````````` example 3566*72b2703bSAndreas Gohr> # Foo 3567*72b2703bSAndreas Gohr> bar 3568*72b2703bSAndreas Gohr> baz 3569*72b2703bSAndreas Gohr. 3570*72b2703bSAndreas Gohr<blockquote> 3571*72b2703bSAndreas Gohr<h1>Foo</h1> 3572*72b2703bSAndreas Gohr<p>bar 3573*72b2703bSAndreas Gohrbaz</p> 3574*72b2703bSAndreas Gohr</blockquote> 3575*72b2703bSAndreas Gohr```````````````````````````````` 3576*72b2703bSAndreas Gohr 3577*72b2703bSAndreas Gohr 3578*72b2703bSAndreas GohrThe spaces after the `>` characters can be omitted: 3579*72b2703bSAndreas Gohr 3580*72b2703bSAndreas Gohr```````````````````````````````` example 3581*72b2703bSAndreas Gohr># Foo 3582*72b2703bSAndreas Gohr>bar 3583*72b2703bSAndreas Gohr> baz 3584*72b2703bSAndreas Gohr. 3585*72b2703bSAndreas Gohr<blockquote> 3586*72b2703bSAndreas Gohr<h1>Foo</h1> 3587*72b2703bSAndreas Gohr<p>bar 3588*72b2703bSAndreas Gohrbaz</p> 3589*72b2703bSAndreas Gohr</blockquote> 3590*72b2703bSAndreas Gohr```````````````````````````````` 3591*72b2703bSAndreas Gohr 3592*72b2703bSAndreas Gohr 3593*72b2703bSAndreas GohrThe `>` characters can be indented 1-3 spaces: 3594*72b2703bSAndreas Gohr 3595*72b2703bSAndreas Gohr```````````````````````````````` example 3596*72b2703bSAndreas Gohr > # Foo 3597*72b2703bSAndreas Gohr > bar 3598*72b2703bSAndreas Gohr > baz 3599*72b2703bSAndreas Gohr. 3600*72b2703bSAndreas Gohr<blockquote> 3601*72b2703bSAndreas Gohr<h1>Foo</h1> 3602*72b2703bSAndreas Gohr<p>bar 3603*72b2703bSAndreas Gohrbaz</p> 3604*72b2703bSAndreas Gohr</blockquote> 3605*72b2703bSAndreas Gohr```````````````````````````````` 3606*72b2703bSAndreas Gohr 3607*72b2703bSAndreas Gohr 3608*72b2703bSAndreas GohrFour spaces gives us a code block: 3609*72b2703bSAndreas Gohr 3610*72b2703bSAndreas Gohr```````````````````````````````` example 3611*72b2703bSAndreas Gohr > # Foo 3612*72b2703bSAndreas Gohr > bar 3613*72b2703bSAndreas Gohr > baz 3614*72b2703bSAndreas Gohr. 3615*72b2703bSAndreas Gohr<pre><code>> # Foo 3616*72b2703bSAndreas Gohr> bar 3617*72b2703bSAndreas Gohr> baz 3618*72b2703bSAndreas Gohr</code></pre> 3619*72b2703bSAndreas Gohr```````````````````````````````` 3620*72b2703bSAndreas Gohr 3621*72b2703bSAndreas Gohr 3622*72b2703bSAndreas GohrThe Laziness clause allows us to omit the `>` before 3623*72b2703bSAndreas Gohr[paragraph continuation text]: 3624*72b2703bSAndreas Gohr 3625*72b2703bSAndreas Gohr```````````````````````````````` example 3626*72b2703bSAndreas Gohr> # Foo 3627*72b2703bSAndreas Gohr> bar 3628*72b2703bSAndreas Gohrbaz 3629*72b2703bSAndreas Gohr. 3630*72b2703bSAndreas Gohr<blockquote> 3631*72b2703bSAndreas Gohr<h1>Foo</h1> 3632*72b2703bSAndreas Gohr<p>bar 3633*72b2703bSAndreas Gohrbaz</p> 3634*72b2703bSAndreas Gohr</blockquote> 3635*72b2703bSAndreas Gohr```````````````````````````````` 3636*72b2703bSAndreas Gohr 3637*72b2703bSAndreas Gohr 3638*72b2703bSAndreas GohrA block quote can contain some lazy and some non-lazy 3639*72b2703bSAndreas Gohrcontinuation lines: 3640*72b2703bSAndreas Gohr 3641*72b2703bSAndreas Gohr```````````````````````````````` example 3642*72b2703bSAndreas Gohr> bar 3643*72b2703bSAndreas Gohrbaz 3644*72b2703bSAndreas Gohr> foo 3645*72b2703bSAndreas Gohr. 3646*72b2703bSAndreas Gohr<blockquote> 3647*72b2703bSAndreas Gohr<p>bar 3648*72b2703bSAndreas Gohrbaz 3649*72b2703bSAndreas Gohrfoo</p> 3650*72b2703bSAndreas Gohr</blockquote> 3651*72b2703bSAndreas Gohr```````````````````````````````` 3652*72b2703bSAndreas Gohr 3653*72b2703bSAndreas Gohr 3654*72b2703bSAndreas GohrLaziness only applies to lines that would have been continuations of 3655*72b2703bSAndreas Gohrparagraphs had they been prepended with [block quote markers]. 3656*72b2703bSAndreas GohrFor example, the `> ` cannot be omitted in the second line of 3657*72b2703bSAndreas Gohr 3658*72b2703bSAndreas Gohr``` markdown 3659*72b2703bSAndreas Gohr> foo 3660*72b2703bSAndreas Gohr> --- 3661*72b2703bSAndreas Gohr``` 3662*72b2703bSAndreas Gohr 3663*72b2703bSAndreas Gohrwithout changing the meaning: 3664*72b2703bSAndreas Gohr 3665*72b2703bSAndreas Gohr```````````````````````````````` example 3666*72b2703bSAndreas Gohr> foo 3667*72b2703bSAndreas Gohr--- 3668*72b2703bSAndreas Gohr. 3669*72b2703bSAndreas Gohr<blockquote> 3670*72b2703bSAndreas Gohr<p>foo</p> 3671*72b2703bSAndreas Gohr</blockquote> 3672*72b2703bSAndreas Gohr<hr /> 3673*72b2703bSAndreas Gohr```````````````````````````````` 3674*72b2703bSAndreas Gohr 3675*72b2703bSAndreas Gohr 3676*72b2703bSAndreas GohrSimilarly, if we omit the `> ` in the second line of 3677*72b2703bSAndreas Gohr 3678*72b2703bSAndreas Gohr``` markdown 3679*72b2703bSAndreas Gohr> - foo 3680*72b2703bSAndreas Gohr> - bar 3681*72b2703bSAndreas Gohr``` 3682*72b2703bSAndreas Gohr 3683*72b2703bSAndreas Gohrthen the block quote ends after the first line: 3684*72b2703bSAndreas Gohr 3685*72b2703bSAndreas Gohr```````````````````````````````` example 3686*72b2703bSAndreas Gohr> - foo 3687*72b2703bSAndreas Gohr- bar 3688*72b2703bSAndreas Gohr. 3689*72b2703bSAndreas Gohr<blockquote> 3690*72b2703bSAndreas Gohr<ul> 3691*72b2703bSAndreas Gohr<li>foo</li> 3692*72b2703bSAndreas Gohr</ul> 3693*72b2703bSAndreas Gohr</blockquote> 3694*72b2703bSAndreas Gohr<ul> 3695*72b2703bSAndreas Gohr<li>bar</li> 3696*72b2703bSAndreas Gohr</ul> 3697*72b2703bSAndreas Gohr```````````````````````````````` 3698*72b2703bSAndreas Gohr 3699*72b2703bSAndreas Gohr 3700*72b2703bSAndreas GohrFor the same reason, we can't omit the `> ` in front of 3701*72b2703bSAndreas Gohrsubsequent lines of an indented or fenced code block: 3702*72b2703bSAndreas Gohr 3703*72b2703bSAndreas Gohr```````````````````````````````` example 3704*72b2703bSAndreas Gohr> foo 3705*72b2703bSAndreas Gohr bar 3706*72b2703bSAndreas Gohr. 3707*72b2703bSAndreas Gohr<blockquote> 3708*72b2703bSAndreas Gohr<pre><code>foo 3709*72b2703bSAndreas Gohr</code></pre> 3710*72b2703bSAndreas Gohr</blockquote> 3711*72b2703bSAndreas Gohr<pre><code>bar 3712*72b2703bSAndreas Gohr</code></pre> 3713*72b2703bSAndreas Gohr```````````````````````````````` 3714*72b2703bSAndreas Gohr 3715*72b2703bSAndreas Gohr 3716*72b2703bSAndreas Gohr```````````````````````````````` example 3717*72b2703bSAndreas Gohr> ``` 3718*72b2703bSAndreas Gohrfoo 3719*72b2703bSAndreas Gohr``` 3720*72b2703bSAndreas Gohr. 3721*72b2703bSAndreas Gohr<blockquote> 3722*72b2703bSAndreas Gohr<pre><code></code></pre> 3723*72b2703bSAndreas Gohr</blockquote> 3724*72b2703bSAndreas Gohr<p>foo</p> 3725*72b2703bSAndreas Gohr<pre><code></code></pre> 3726*72b2703bSAndreas Gohr```````````````````````````````` 3727*72b2703bSAndreas Gohr 3728*72b2703bSAndreas Gohr 3729*72b2703bSAndreas GohrNote that in the following case, we have a [lazy 3730*72b2703bSAndreas Gohrcontinuation line]: 3731*72b2703bSAndreas Gohr 3732*72b2703bSAndreas Gohr```````````````````````````````` example 3733*72b2703bSAndreas Gohr> foo 3734*72b2703bSAndreas Gohr - bar 3735*72b2703bSAndreas Gohr. 3736*72b2703bSAndreas Gohr<blockquote> 3737*72b2703bSAndreas Gohr<p>foo 3738*72b2703bSAndreas Gohr- bar</p> 3739*72b2703bSAndreas Gohr</blockquote> 3740*72b2703bSAndreas Gohr```````````````````````````````` 3741*72b2703bSAndreas Gohr 3742*72b2703bSAndreas Gohr 3743*72b2703bSAndreas GohrTo see why, note that in 3744*72b2703bSAndreas Gohr 3745*72b2703bSAndreas Gohr```markdown 3746*72b2703bSAndreas Gohr> foo 3747*72b2703bSAndreas Gohr> - bar 3748*72b2703bSAndreas Gohr``` 3749*72b2703bSAndreas Gohr 3750*72b2703bSAndreas Gohrthe `- bar` is indented too far to start a list, and can't 3751*72b2703bSAndreas Gohrbe an indented code block because indented code blocks cannot 3752*72b2703bSAndreas Gohrinterrupt paragraphs, so it is [paragraph continuation text]. 3753*72b2703bSAndreas Gohr 3754*72b2703bSAndreas GohrA block quote can be empty: 3755*72b2703bSAndreas Gohr 3756*72b2703bSAndreas Gohr```````````````````````````````` example 3757*72b2703bSAndreas Gohr> 3758*72b2703bSAndreas Gohr. 3759*72b2703bSAndreas Gohr<blockquote> 3760*72b2703bSAndreas Gohr</blockquote> 3761*72b2703bSAndreas Gohr```````````````````````````````` 3762*72b2703bSAndreas Gohr 3763*72b2703bSAndreas Gohr 3764*72b2703bSAndreas Gohr```````````````````````````````` example 3765*72b2703bSAndreas Gohr> 3766*72b2703bSAndreas Gohr> 3767*72b2703bSAndreas Gohr> 3768*72b2703bSAndreas Gohr. 3769*72b2703bSAndreas Gohr<blockquote> 3770*72b2703bSAndreas Gohr</blockquote> 3771*72b2703bSAndreas Gohr```````````````````````````````` 3772*72b2703bSAndreas Gohr 3773*72b2703bSAndreas Gohr 3774*72b2703bSAndreas GohrA block quote can have initial or final blank lines: 3775*72b2703bSAndreas Gohr 3776*72b2703bSAndreas Gohr```````````````````````````````` example 3777*72b2703bSAndreas Gohr> 3778*72b2703bSAndreas Gohr> foo 3779*72b2703bSAndreas Gohr> 3780*72b2703bSAndreas Gohr. 3781*72b2703bSAndreas Gohr<blockquote> 3782*72b2703bSAndreas Gohr<p>foo</p> 3783*72b2703bSAndreas Gohr</blockquote> 3784*72b2703bSAndreas Gohr```````````````````````````````` 3785*72b2703bSAndreas Gohr 3786*72b2703bSAndreas Gohr 3787*72b2703bSAndreas GohrA blank line always separates block quotes: 3788*72b2703bSAndreas Gohr 3789*72b2703bSAndreas Gohr```````````````````````````````` example 3790*72b2703bSAndreas Gohr> foo 3791*72b2703bSAndreas Gohr 3792*72b2703bSAndreas Gohr> bar 3793*72b2703bSAndreas Gohr. 3794*72b2703bSAndreas Gohr<blockquote> 3795*72b2703bSAndreas Gohr<p>foo</p> 3796*72b2703bSAndreas Gohr</blockquote> 3797*72b2703bSAndreas Gohr<blockquote> 3798*72b2703bSAndreas Gohr<p>bar</p> 3799*72b2703bSAndreas Gohr</blockquote> 3800*72b2703bSAndreas Gohr```````````````````````````````` 3801*72b2703bSAndreas Gohr 3802*72b2703bSAndreas Gohr 3803*72b2703bSAndreas Gohr(Most current Markdown implementations, including John Gruber's 3804*72b2703bSAndreas Gohroriginal `Markdown.pl`, will parse this example as a single block quote 3805*72b2703bSAndreas Gohrwith two paragraphs. But it seems better to allow the author to decide 3806*72b2703bSAndreas Gohrwhether two block quotes or one are wanted.) 3807*72b2703bSAndreas Gohr 3808*72b2703bSAndreas GohrConsecutiveness means that if we put these block quotes together, 3809*72b2703bSAndreas Gohrwe get a single block quote: 3810*72b2703bSAndreas Gohr 3811*72b2703bSAndreas Gohr```````````````````````````````` example 3812*72b2703bSAndreas Gohr> foo 3813*72b2703bSAndreas Gohr> bar 3814*72b2703bSAndreas Gohr. 3815*72b2703bSAndreas Gohr<blockquote> 3816*72b2703bSAndreas Gohr<p>foo 3817*72b2703bSAndreas Gohrbar</p> 3818*72b2703bSAndreas Gohr</blockquote> 3819*72b2703bSAndreas Gohr```````````````````````````````` 3820*72b2703bSAndreas Gohr 3821*72b2703bSAndreas Gohr 3822*72b2703bSAndreas GohrTo get a block quote with two paragraphs, use: 3823*72b2703bSAndreas Gohr 3824*72b2703bSAndreas Gohr```````````````````````````````` example 3825*72b2703bSAndreas Gohr> foo 3826*72b2703bSAndreas Gohr> 3827*72b2703bSAndreas Gohr> bar 3828*72b2703bSAndreas Gohr. 3829*72b2703bSAndreas Gohr<blockquote> 3830*72b2703bSAndreas Gohr<p>foo</p> 3831*72b2703bSAndreas Gohr<p>bar</p> 3832*72b2703bSAndreas Gohr</blockquote> 3833*72b2703bSAndreas Gohr```````````````````````````````` 3834*72b2703bSAndreas Gohr 3835*72b2703bSAndreas Gohr 3836*72b2703bSAndreas GohrBlock quotes can interrupt paragraphs: 3837*72b2703bSAndreas Gohr 3838*72b2703bSAndreas Gohr```````````````````````````````` example 3839*72b2703bSAndreas Gohrfoo 3840*72b2703bSAndreas Gohr> bar 3841*72b2703bSAndreas Gohr. 3842*72b2703bSAndreas Gohr<p>foo</p> 3843*72b2703bSAndreas Gohr<blockquote> 3844*72b2703bSAndreas Gohr<p>bar</p> 3845*72b2703bSAndreas Gohr</blockquote> 3846*72b2703bSAndreas Gohr```````````````````````````````` 3847*72b2703bSAndreas Gohr 3848*72b2703bSAndreas Gohr 3849*72b2703bSAndreas GohrIn general, blank lines are not needed before or after block 3850*72b2703bSAndreas Gohrquotes: 3851*72b2703bSAndreas Gohr 3852*72b2703bSAndreas Gohr```````````````````````````````` example 3853*72b2703bSAndreas Gohr> aaa 3854*72b2703bSAndreas Gohr*** 3855*72b2703bSAndreas Gohr> bbb 3856*72b2703bSAndreas Gohr. 3857*72b2703bSAndreas Gohr<blockquote> 3858*72b2703bSAndreas Gohr<p>aaa</p> 3859*72b2703bSAndreas Gohr</blockquote> 3860*72b2703bSAndreas Gohr<hr /> 3861*72b2703bSAndreas Gohr<blockquote> 3862*72b2703bSAndreas Gohr<p>bbb</p> 3863*72b2703bSAndreas Gohr</blockquote> 3864*72b2703bSAndreas Gohr```````````````````````````````` 3865*72b2703bSAndreas Gohr 3866*72b2703bSAndreas Gohr 3867*72b2703bSAndreas GohrHowever, because of laziness, a blank line is needed between 3868*72b2703bSAndreas Gohra block quote and a following paragraph: 3869*72b2703bSAndreas Gohr 3870*72b2703bSAndreas Gohr```````````````````````````````` example 3871*72b2703bSAndreas Gohr> bar 3872*72b2703bSAndreas Gohrbaz 3873*72b2703bSAndreas Gohr. 3874*72b2703bSAndreas Gohr<blockquote> 3875*72b2703bSAndreas Gohr<p>bar 3876*72b2703bSAndreas Gohrbaz</p> 3877*72b2703bSAndreas Gohr</blockquote> 3878*72b2703bSAndreas Gohr```````````````````````````````` 3879*72b2703bSAndreas Gohr 3880*72b2703bSAndreas Gohr 3881*72b2703bSAndreas Gohr```````````````````````````````` example 3882*72b2703bSAndreas Gohr> bar 3883*72b2703bSAndreas Gohr 3884*72b2703bSAndreas Gohrbaz 3885*72b2703bSAndreas Gohr. 3886*72b2703bSAndreas Gohr<blockquote> 3887*72b2703bSAndreas Gohr<p>bar</p> 3888*72b2703bSAndreas Gohr</blockquote> 3889*72b2703bSAndreas Gohr<p>baz</p> 3890*72b2703bSAndreas Gohr```````````````````````````````` 3891*72b2703bSAndreas Gohr 3892*72b2703bSAndreas Gohr 3893*72b2703bSAndreas Gohr```````````````````````````````` example 3894*72b2703bSAndreas Gohr> bar 3895*72b2703bSAndreas Gohr> 3896*72b2703bSAndreas Gohrbaz 3897*72b2703bSAndreas Gohr. 3898*72b2703bSAndreas Gohr<blockquote> 3899*72b2703bSAndreas Gohr<p>bar</p> 3900*72b2703bSAndreas Gohr</blockquote> 3901*72b2703bSAndreas Gohr<p>baz</p> 3902*72b2703bSAndreas Gohr```````````````````````````````` 3903*72b2703bSAndreas Gohr 3904*72b2703bSAndreas Gohr 3905*72b2703bSAndreas GohrIt is a consequence of the Laziness rule that any number 3906*72b2703bSAndreas Gohrof initial `>`s may be omitted on a continuation line of a 3907*72b2703bSAndreas Gohrnested block quote: 3908*72b2703bSAndreas Gohr 3909*72b2703bSAndreas Gohr```````````````````````````````` example 3910*72b2703bSAndreas Gohr> > > foo 3911*72b2703bSAndreas Gohrbar 3912*72b2703bSAndreas Gohr. 3913*72b2703bSAndreas Gohr<blockquote> 3914*72b2703bSAndreas Gohr<blockquote> 3915*72b2703bSAndreas Gohr<blockquote> 3916*72b2703bSAndreas Gohr<p>foo 3917*72b2703bSAndreas Gohrbar</p> 3918*72b2703bSAndreas Gohr</blockquote> 3919*72b2703bSAndreas Gohr</blockquote> 3920*72b2703bSAndreas Gohr</blockquote> 3921*72b2703bSAndreas Gohr```````````````````````````````` 3922*72b2703bSAndreas Gohr 3923*72b2703bSAndreas Gohr 3924*72b2703bSAndreas Gohr```````````````````````````````` example 3925*72b2703bSAndreas Gohr>>> foo 3926*72b2703bSAndreas Gohr> bar 3927*72b2703bSAndreas Gohr>>baz 3928*72b2703bSAndreas Gohr. 3929*72b2703bSAndreas Gohr<blockquote> 3930*72b2703bSAndreas Gohr<blockquote> 3931*72b2703bSAndreas Gohr<blockquote> 3932*72b2703bSAndreas Gohr<p>foo 3933*72b2703bSAndreas Gohrbar 3934*72b2703bSAndreas Gohrbaz</p> 3935*72b2703bSAndreas Gohr</blockquote> 3936*72b2703bSAndreas Gohr</blockquote> 3937*72b2703bSAndreas Gohr</blockquote> 3938*72b2703bSAndreas Gohr```````````````````````````````` 3939*72b2703bSAndreas Gohr 3940*72b2703bSAndreas Gohr 3941*72b2703bSAndreas GohrWhen including an indented code block in a block quote, 3942*72b2703bSAndreas Gohrremember that the [block quote marker] includes 3943*72b2703bSAndreas Gohrboth the `>` and a following space. So *five spaces* are needed after 3944*72b2703bSAndreas Gohrthe `>`: 3945*72b2703bSAndreas Gohr 3946*72b2703bSAndreas Gohr```````````````````````````````` example 3947*72b2703bSAndreas Gohr> code 3948*72b2703bSAndreas Gohr 3949*72b2703bSAndreas Gohr> not code 3950*72b2703bSAndreas Gohr. 3951*72b2703bSAndreas Gohr<blockquote> 3952*72b2703bSAndreas Gohr<pre><code>code 3953*72b2703bSAndreas Gohr</code></pre> 3954*72b2703bSAndreas Gohr</blockquote> 3955*72b2703bSAndreas Gohr<blockquote> 3956*72b2703bSAndreas Gohr<p>not code</p> 3957*72b2703bSAndreas Gohr</blockquote> 3958*72b2703bSAndreas Gohr```````````````````````````````` 3959*72b2703bSAndreas Gohr 3960*72b2703bSAndreas Gohr 3961*72b2703bSAndreas Gohr 3962*72b2703bSAndreas Gohr## List items 3963*72b2703bSAndreas Gohr 3964*72b2703bSAndreas GohrA [list marker](@) is a 3965*72b2703bSAndreas Gohr[bullet list marker] or an [ordered list marker]. 3966*72b2703bSAndreas Gohr 3967*72b2703bSAndreas GohrA [bullet list marker](@) 3968*72b2703bSAndreas Gohris a `-`, `+`, or `*` character. 3969*72b2703bSAndreas Gohr 3970*72b2703bSAndreas GohrAn [ordered list marker](@) 3971*72b2703bSAndreas Gohris a sequence of 1--9 arabic digits (`0-9`), followed by either a 3972*72b2703bSAndreas Gohr`.` character or a `)` character. (The reason for the length 3973*72b2703bSAndreas Gohrlimit is that with 10 digits we start seeing integer overflows 3974*72b2703bSAndreas Gohrin some browsers.) 3975*72b2703bSAndreas Gohr 3976*72b2703bSAndreas GohrThe following rules define [list items]: 3977*72b2703bSAndreas Gohr 3978*72b2703bSAndreas Gohr1. **Basic case.** If a sequence of lines *Ls* constitute a sequence of 3979*72b2703bSAndreas Gohr blocks *Bs* starting with a [non-whitespace character], and *M* is a 3980*72b2703bSAndreas Gohr list marker of width *W* followed by 1 ≤ *N* ≤ 4 spaces, then the result 3981*72b2703bSAndreas Gohr of prepending *M* and the following spaces to the first line of 3982*72b2703bSAndreas Gohr *Ls*, and indenting subsequent lines of *Ls* by *W + N* spaces, is a 3983*72b2703bSAndreas Gohr list item with *Bs* as its contents. The type of the list item 3984*72b2703bSAndreas Gohr (bullet or ordered) is determined by the type of its list marker. 3985*72b2703bSAndreas Gohr If the list item is ordered, then it is also assigned a start 3986*72b2703bSAndreas Gohr number, based on the ordered list marker. 3987*72b2703bSAndreas Gohr 3988*72b2703bSAndreas Gohr Exceptions: 3989*72b2703bSAndreas Gohr 3990*72b2703bSAndreas Gohr 1. When the first list item in a [list] interrupts 3991*72b2703bSAndreas Gohr a paragraph---that is, when it starts on a line that would 3992*72b2703bSAndreas Gohr otherwise count as [paragraph continuation text]---then (a) 3993*72b2703bSAndreas Gohr the lines *Ls* must not begin with a blank line, and (b) if 3994*72b2703bSAndreas Gohr the list item is ordered, the start number must be 1. 3995*72b2703bSAndreas Gohr 2. If any line is a [thematic break][thematic breaks] then 3996*72b2703bSAndreas Gohr that line is not a list item. 3997*72b2703bSAndreas Gohr 3998*72b2703bSAndreas GohrFor example, let *Ls* be the lines 3999*72b2703bSAndreas Gohr 4000*72b2703bSAndreas Gohr```````````````````````````````` example 4001*72b2703bSAndreas GohrA paragraph 4002*72b2703bSAndreas Gohrwith two lines. 4003*72b2703bSAndreas Gohr 4004*72b2703bSAndreas Gohr indented code 4005*72b2703bSAndreas Gohr 4006*72b2703bSAndreas Gohr> A block quote. 4007*72b2703bSAndreas Gohr. 4008*72b2703bSAndreas Gohr<p>A paragraph 4009*72b2703bSAndreas Gohrwith two lines.</p> 4010*72b2703bSAndreas Gohr<pre><code>indented code 4011*72b2703bSAndreas Gohr</code></pre> 4012*72b2703bSAndreas Gohr<blockquote> 4013*72b2703bSAndreas Gohr<p>A block quote.</p> 4014*72b2703bSAndreas Gohr</blockquote> 4015*72b2703bSAndreas Gohr```````````````````````````````` 4016*72b2703bSAndreas Gohr 4017*72b2703bSAndreas Gohr 4018*72b2703bSAndreas GohrAnd let *M* be the marker `1.`, and *N* = 2. Then rule #1 says 4019*72b2703bSAndreas Gohrthat the following is an ordered list item with start number 1, 4020*72b2703bSAndreas Gohrand the same contents as *Ls*: 4021*72b2703bSAndreas Gohr 4022*72b2703bSAndreas Gohr```````````````````````````````` example 4023*72b2703bSAndreas Gohr1. A paragraph 4024*72b2703bSAndreas Gohr with two lines. 4025*72b2703bSAndreas Gohr 4026*72b2703bSAndreas Gohr indented code 4027*72b2703bSAndreas Gohr 4028*72b2703bSAndreas Gohr > A block quote. 4029*72b2703bSAndreas Gohr. 4030*72b2703bSAndreas Gohr<ol> 4031*72b2703bSAndreas Gohr<li> 4032*72b2703bSAndreas Gohr<p>A paragraph 4033*72b2703bSAndreas Gohrwith two lines.</p> 4034*72b2703bSAndreas Gohr<pre><code>indented code 4035*72b2703bSAndreas Gohr</code></pre> 4036*72b2703bSAndreas Gohr<blockquote> 4037*72b2703bSAndreas Gohr<p>A block quote.</p> 4038*72b2703bSAndreas Gohr</blockquote> 4039*72b2703bSAndreas Gohr</li> 4040*72b2703bSAndreas Gohr</ol> 4041*72b2703bSAndreas Gohr```````````````````````````````` 4042*72b2703bSAndreas Gohr 4043*72b2703bSAndreas Gohr 4044*72b2703bSAndreas GohrThe most important thing to notice is that the position of 4045*72b2703bSAndreas Gohrthe text after the list marker determines how much indentation 4046*72b2703bSAndreas Gohris needed in subsequent blocks in the list item. If the list 4047*72b2703bSAndreas Gohrmarker takes up two spaces, and there are three spaces between 4048*72b2703bSAndreas Gohrthe list marker and the next [non-whitespace character], then blocks 4049*72b2703bSAndreas Gohrmust be indented five spaces in order to fall under the list 4050*72b2703bSAndreas Gohritem. 4051*72b2703bSAndreas Gohr 4052*72b2703bSAndreas GohrHere are some examples showing how far content must be indented to be 4053*72b2703bSAndreas Gohrput under the list item: 4054*72b2703bSAndreas Gohr 4055*72b2703bSAndreas Gohr```````````````````````````````` example 4056*72b2703bSAndreas Gohr- one 4057*72b2703bSAndreas Gohr 4058*72b2703bSAndreas Gohr two 4059*72b2703bSAndreas Gohr. 4060*72b2703bSAndreas Gohr<ul> 4061*72b2703bSAndreas Gohr<li>one</li> 4062*72b2703bSAndreas Gohr</ul> 4063*72b2703bSAndreas Gohr<p>two</p> 4064*72b2703bSAndreas Gohr```````````````````````````````` 4065*72b2703bSAndreas Gohr 4066*72b2703bSAndreas Gohr 4067*72b2703bSAndreas Gohr```````````````````````````````` example 4068*72b2703bSAndreas Gohr- one 4069*72b2703bSAndreas Gohr 4070*72b2703bSAndreas Gohr two 4071*72b2703bSAndreas Gohr. 4072*72b2703bSAndreas Gohr<ul> 4073*72b2703bSAndreas Gohr<li> 4074*72b2703bSAndreas Gohr<p>one</p> 4075*72b2703bSAndreas Gohr<p>two</p> 4076*72b2703bSAndreas Gohr</li> 4077*72b2703bSAndreas Gohr</ul> 4078*72b2703bSAndreas Gohr```````````````````````````````` 4079*72b2703bSAndreas Gohr 4080*72b2703bSAndreas Gohr 4081*72b2703bSAndreas Gohr```````````````````````````````` example 4082*72b2703bSAndreas Gohr - one 4083*72b2703bSAndreas Gohr 4084*72b2703bSAndreas Gohr two 4085*72b2703bSAndreas Gohr. 4086*72b2703bSAndreas Gohr<ul> 4087*72b2703bSAndreas Gohr<li>one</li> 4088*72b2703bSAndreas Gohr</ul> 4089*72b2703bSAndreas Gohr<pre><code> two 4090*72b2703bSAndreas Gohr</code></pre> 4091*72b2703bSAndreas Gohr```````````````````````````````` 4092*72b2703bSAndreas Gohr 4093*72b2703bSAndreas Gohr 4094*72b2703bSAndreas Gohr```````````````````````````````` example 4095*72b2703bSAndreas Gohr - one 4096*72b2703bSAndreas Gohr 4097*72b2703bSAndreas Gohr two 4098*72b2703bSAndreas Gohr. 4099*72b2703bSAndreas Gohr<ul> 4100*72b2703bSAndreas Gohr<li> 4101*72b2703bSAndreas Gohr<p>one</p> 4102*72b2703bSAndreas Gohr<p>two</p> 4103*72b2703bSAndreas Gohr</li> 4104*72b2703bSAndreas Gohr</ul> 4105*72b2703bSAndreas Gohr```````````````````````````````` 4106*72b2703bSAndreas Gohr 4107*72b2703bSAndreas Gohr 4108*72b2703bSAndreas GohrIt is tempting to think of this in terms of columns: the continuation 4109*72b2703bSAndreas Gohrblocks must be indented at least to the column of the first 4110*72b2703bSAndreas Gohr[non-whitespace character] after the list marker. However, that is not quite right. 4111*72b2703bSAndreas GohrThe spaces after the list marker determine how much relative indentation 4112*72b2703bSAndreas Gohris needed. Which column this indentation reaches will depend on 4113*72b2703bSAndreas Gohrhow the list item is embedded in other constructions, as shown by 4114*72b2703bSAndreas Gohrthis example: 4115*72b2703bSAndreas Gohr 4116*72b2703bSAndreas Gohr```````````````````````````````` example 4117*72b2703bSAndreas Gohr > > 1. one 4118*72b2703bSAndreas Gohr>> 4119*72b2703bSAndreas Gohr>> two 4120*72b2703bSAndreas Gohr. 4121*72b2703bSAndreas Gohr<blockquote> 4122*72b2703bSAndreas Gohr<blockquote> 4123*72b2703bSAndreas Gohr<ol> 4124*72b2703bSAndreas Gohr<li> 4125*72b2703bSAndreas Gohr<p>one</p> 4126*72b2703bSAndreas Gohr<p>two</p> 4127*72b2703bSAndreas Gohr</li> 4128*72b2703bSAndreas Gohr</ol> 4129*72b2703bSAndreas Gohr</blockquote> 4130*72b2703bSAndreas Gohr</blockquote> 4131*72b2703bSAndreas Gohr```````````````````````````````` 4132*72b2703bSAndreas Gohr 4133*72b2703bSAndreas Gohr 4134*72b2703bSAndreas GohrHere `two` occurs in the same column as the list marker `1.`, 4135*72b2703bSAndreas Gohrbut is actually contained in the list item, because there is 4136*72b2703bSAndreas Gohrsufficient indentation after the last containing blockquote marker. 4137*72b2703bSAndreas Gohr 4138*72b2703bSAndreas GohrThe converse is also possible. In the following example, the word `two` 4139*72b2703bSAndreas Gohroccurs far to the right of the initial text of the list item, `one`, but 4140*72b2703bSAndreas Gohrit is not considered part of the list item, because it is not indented 4141*72b2703bSAndreas Gohrfar enough past the blockquote marker: 4142*72b2703bSAndreas Gohr 4143*72b2703bSAndreas Gohr```````````````````````````````` example 4144*72b2703bSAndreas Gohr>>- one 4145*72b2703bSAndreas Gohr>> 4146*72b2703bSAndreas Gohr > > two 4147*72b2703bSAndreas Gohr. 4148*72b2703bSAndreas Gohr<blockquote> 4149*72b2703bSAndreas Gohr<blockquote> 4150*72b2703bSAndreas Gohr<ul> 4151*72b2703bSAndreas Gohr<li>one</li> 4152*72b2703bSAndreas Gohr</ul> 4153*72b2703bSAndreas Gohr<p>two</p> 4154*72b2703bSAndreas Gohr</blockquote> 4155*72b2703bSAndreas Gohr</blockquote> 4156*72b2703bSAndreas Gohr```````````````````````````````` 4157*72b2703bSAndreas Gohr 4158*72b2703bSAndreas Gohr 4159*72b2703bSAndreas GohrNote that at least one space is needed between the list marker and 4160*72b2703bSAndreas Gohrany following content, so these are not list items: 4161*72b2703bSAndreas Gohr 4162*72b2703bSAndreas Gohr```````````````````````````````` example 4163*72b2703bSAndreas Gohr-one 4164*72b2703bSAndreas Gohr 4165*72b2703bSAndreas Gohr2.two 4166*72b2703bSAndreas Gohr. 4167*72b2703bSAndreas Gohr<p>-one</p> 4168*72b2703bSAndreas Gohr<p>2.two</p> 4169*72b2703bSAndreas Gohr```````````````````````````````` 4170*72b2703bSAndreas Gohr 4171*72b2703bSAndreas Gohr 4172*72b2703bSAndreas GohrA list item may contain blocks that are separated by more than 4173*72b2703bSAndreas Gohrone blank line. 4174*72b2703bSAndreas Gohr 4175*72b2703bSAndreas Gohr```````````````````````````````` example 4176*72b2703bSAndreas Gohr- foo 4177*72b2703bSAndreas Gohr 4178*72b2703bSAndreas Gohr 4179*72b2703bSAndreas Gohr bar 4180*72b2703bSAndreas Gohr. 4181*72b2703bSAndreas Gohr<ul> 4182*72b2703bSAndreas Gohr<li> 4183*72b2703bSAndreas Gohr<p>foo</p> 4184*72b2703bSAndreas Gohr<p>bar</p> 4185*72b2703bSAndreas Gohr</li> 4186*72b2703bSAndreas Gohr</ul> 4187*72b2703bSAndreas Gohr```````````````````````````````` 4188*72b2703bSAndreas Gohr 4189*72b2703bSAndreas Gohr 4190*72b2703bSAndreas GohrA list item may contain any kind of block: 4191*72b2703bSAndreas Gohr 4192*72b2703bSAndreas Gohr```````````````````````````````` example 4193*72b2703bSAndreas Gohr1. foo 4194*72b2703bSAndreas Gohr 4195*72b2703bSAndreas Gohr ``` 4196*72b2703bSAndreas Gohr bar 4197*72b2703bSAndreas Gohr ``` 4198*72b2703bSAndreas Gohr 4199*72b2703bSAndreas Gohr baz 4200*72b2703bSAndreas Gohr 4201*72b2703bSAndreas Gohr > bam 4202*72b2703bSAndreas Gohr. 4203*72b2703bSAndreas Gohr<ol> 4204*72b2703bSAndreas Gohr<li> 4205*72b2703bSAndreas Gohr<p>foo</p> 4206*72b2703bSAndreas Gohr<pre><code>bar 4207*72b2703bSAndreas Gohr</code></pre> 4208*72b2703bSAndreas Gohr<p>baz</p> 4209*72b2703bSAndreas Gohr<blockquote> 4210*72b2703bSAndreas Gohr<p>bam</p> 4211*72b2703bSAndreas Gohr</blockquote> 4212*72b2703bSAndreas Gohr</li> 4213*72b2703bSAndreas Gohr</ol> 4214*72b2703bSAndreas Gohr```````````````````````````````` 4215*72b2703bSAndreas Gohr 4216*72b2703bSAndreas Gohr 4217*72b2703bSAndreas GohrA list item that contains an indented code block will preserve 4218*72b2703bSAndreas Gohrempty lines within the code block verbatim. 4219*72b2703bSAndreas Gohr 4220*72b2703bSAndreas Gohr```````````````````````````````` example 4221*72b2703bSAndreas Gohr- Foo 4222*72b2703bSAndreas Gohr 4223*72b2703bSAndreas Gohr bar 4224*72b2703bSAndreas Gohr 4225*72b2703bSAndreas Gohr 4226*72b2703bSAndreas Gohr baz 4227*72b2703bSAndreas Gohr. 4228*72b2703bSAndreas Gohr<ul> 4229*72b2703bSAndreas Gohr<li> 4230*72b2703bSAndreas Gohr<p>Foo</p> 4231*72b2703bSAndreas Gohr<pre><code>bar 4232*72b2703bSAndreas Gohr 4233*72b2703bSAndreas Gohr 4234*72b2703bSAndreas Gohrbaz 4235*72b2703bSAndreas Gohr</code></pre> 4236*72b2703bSAndreas Gohr</li> 4237*72b2703bSAndreas Gohr</ul> 4238*72b2703bSAndreas Gohr```````````````````````````````` 4239*72b2703bSAndreas Gohr 4240*72b2703bSAndreas GohrNote that ordered list start numbers must be nine digits or less: 4241*72b2703bSAndreas Gohr 4242*72b2703bSAndreas Gohr```````````````````````````````` example 4243*72b2703bSAndreas Gohr123456789. ok 4244*72b2703bSAndreas Gohr. 4245*72b2703bSAndreas Gohr<ol start="123456789"> 4246*72b2703bSAndreas Gohr<li>ok</li> 4247*72b2703bSAndreas Gohr</ol> 4248*72b2703bSAndreas Gohr```````````````````````````````` 4249*72b2703bSAndreas Gohr 4250*72b2703bSAndreas Gohr 4251*72b2703bSAndreas Gohr```````````````````````````````` example 4252*72b2703bSAndreas Gohr1234567890. not ok 4253*72b2703bSAndreas Gohr. 4254*72b2703bSAndreas Gohr<p>1234567890. not ok</p> 4255*72b2703bSAndreas Gohr```````````````````````````````` 4256*72b2703bSAndreas Gohr 4257*72b2703bSAndreas Gohr 4258*72b2703bSAndreas GohrA start number may begin with 0s: 4259*72b2703bSAndreas Gohr 4260*72b2703bSAndreas Gohr```````````````````````````````` example 4261*72b2703bSAndreas Gohr0. ok 4262*72b2703bSAndreas Gohr. 4263*72b2703bSAndreas Gohr<ol start="0"> 4264*72b2703bSAndreas Gohr<li>ok</li> 4265*72b2703bSAndreas Gohr</ol> 4266*72b2703bSAndreas Gohr```````````````````````````````` 4267*72b2703bSAndreas Gohr 4268*72b2703bSAndreas Gohr 4269*72b2703bSAndreas Gohr```````````````````````````````` example 4270*72b2703bSAndreas Gohr003. ok 4271*72b2703bSAndreas Gohr. 4272*72b2703bSAndreas Gohr<ol start="3"> 4273*72b2703bSAndreas Gohr<li>ok</li> 4274*72b2703bSAndreas Gohr</ol> 4275*72b2703bSAndreas Gohr```````````````````````````````` 4276*72b2703bSAndreas Gohr 4277*72b2703bSAndreas Gohr 4278*72b2703bSAndreas GohrA start number may not be negative: 4279*72b2703bSAndreas Gohr 4280*72b2703bSAndreas Gohr```````````````````````````````` example 4281*72b2703bSAndreas Gohr-1. not ok 4282*72b2703bSAndreas Gohr. 4283*72b2703bSAndreas Gohr<p>-1. not ok</p> 4284*72b2703bSAndreas Gohr```````````````````````````````` 4285*72b2703bSAndreas Gohr 4286*72b2703bSAndreas Gohr 4287*72b2703bSAndreas Gohr 4288*72b2703bSAndreas Gohr2. **Item starting with indented code.** If a sequence of lines *Ls* 4289*72b2703bSAndreas Gohr constitute a sequence of blocks *Bs* starting with an indented code 4290*72b2703bSAndreas Gohr block, and *M* is a list marker of width *W* followed by 4291*72b2703bSAndreas Gohr one space, then the result of prepending *M* and the following 4292*72b2703bSAndreas Gohr space to the first line of *Ls*, and indenting subsequent lines of 4293*72b2703bSAndreas Gohr *Ls* by *W + 1* spaces, is a list item with *Bs* as its contents. 4294*72b2703bSAndreas Gohr If a line is empty, then it need not be indented. The type of the 4295*72b2703bSAndreas Gohr list item (bullet or ordered) is determined by the type of its list 4296*72b2703bSAndreas Gohr marker. If the list item is ordered, then it is also assigned a 4297*72b2703bSAndreas Gohr start number, based on the ordered list marker. 4298*72b2703bSAndreas Gohr 4299*72b2703bSAndreas GohrAn indented code block will have to be indented four spaces beyond 4300*72b2703bSAndreas Gohrthe edge of the region where text will be included in the list item. 4301*72b2703bSAndreas GohrIn the following case that is 6 spaces: 4302*72b2703bSAndreas Gohr 4303*72b2703bSAndreas Gohr```````````````````````````````` example 4304*72b2703bSAndreas Gohr- foo 4305*72b2703bSAndreas Gohr 4306*72b2703bSAndreas Gohr bar 4307*72b2703bSAndreas Gohr. 4308*72b2703bSAndreas Gohr<ul> 4309*72b2703bSAndreas Gohr<li> 4310*72b2703bSAndreas Gohr<p>foo</p> 4311*72b2703bSAndreas Gohr<pre><code>bar 4312*72b2703bSAndreas Gohr</code></pre> 4313*72b2703bSAndreas Gohr</li> 4314*72b2703bSAndreas Gohr</ul> 4315*72b2703bSAndreas Gohr```````````````````````````````` 4316*72b2703bSAndreas Gohr 4317*72b2703bSAndreas Gohr 4318*72b2703bSAndreas GohrAnd in this case it is 11 spaces: 4319*72b2703bSAndreas Gohr 4320*72b2703bSAndreas Gohr```````````````````````````````` example 4321*72b2703bSAndreas Gohr 10. foo 4322*72b2703bSAndreas Gohr 4323*72b2703bSAndreas Gohr bar 4324*72b2703bSAndreas Gohr. 4325*72b2703bSAndreas Gohr<ol start="10"> 4326*72b2703bSAndreas Gohr<li> 4327*72b2703bSAndreas Gohr<p>foo</p> 4328*72b2703bSAndreas Gohr<pre><code>bar 4329*72b2703bSAndreas Gohr</code></pre> 4330*72b2703bSAndreas Gohr</li> 4331*72b2703bSAndreas Gohr</ol> 4332*72b2703bSAndreas Gohr```````````````````````````````` 4333*72b2703bSAndreas Gohr 4334*72b2703bSAndreas Gohr 4335*72b2703bSAndreas GohrIf the *first* block in the list item is an indented code block, 4336*72b2703bSAndreas Gohrthen by rule #2, the contents must be indented *one* space after the 4337*72b2703bSAndreas Gohrlist marker: 4338*72b2703bSAndreas Gohr 4339*72b2703bSAndreas Gohr```````````````````````````````` example 4340*72b2703bSAndreas Gohr indented code 4341*72b2703bSAndreas Gohr 4342*72b2703bSAndreas Gohrparagraph 4343*72b2703bSAndreas Gohr 4344*72b2703bSAndreas Gohr more code 4345*72b2703bSAndreas Gohr. 4346*72b2703bSAndreas Gohr<pre><code>indented code 4347*72b2703bSAndreas Gohr</code></pre> 4348*72b2703bSAndreas Gohr<p>paragraph</p> 4349*72b2703bSAndreas Gohr<pre><code>more code 4350*72b2703bSAndreas Gohr</code></pre> 4351*72b2703bSAndreas Gohr```````````````````````````````` 4352*72b2703bSAndreas Gohr 4353*72b2703bSAndreas Gohr 4354*72b2703bSAndreas Gohr```````````````````````````````` example 4355*72b2703bSAndreas Gohr1. indented code 4356*72b2703bSAndreas Gohr 4357*72b2703bSAndreas Gohr paragraph 4358*72b2703bSAndreas Gohr 4359*72b2703bSAndreas Gohr more code 4360*72b2703bSAndreas Gohr. 4361*72b2703bSAndreas Gohr<ol> 4362*72b2703bSAndreas Gohr<li> 4363*72b2703bSAndreas Gohr<pre><code>indented code 4364*72b2703bSAndreas Gohr</code></pre> 4365*72b2703bSAndreas Gohr<p>paragraph</p> 4366*72b2703bSAndreas Gohr<pre><code>more code 4367*72b2703bSAndreas Gohr</code></pre> 4368*72b2703bSAndreas Gohr</li> 4369*72b2703bSAndreas Gohr</ol> 4370*72b2703bSAndreas Gohr```````````````````````````````` 4371*72b2703bSAndreas Gohr 4372*72b2703bSAndreas Gohr 4373*72b2703bSAndreas GohrNote that an additional space indent is interpreted as space 4374*72b2703bSAndreas Gohrinside the code block: 4375*72b2703bSAndreas Gohr 4376*72b2703bSAndreas Gohr```````````````````````````````` example 4377*72b2703bSAndreas Gohr1. indented code 4378*72b2703bSAndreas Gohr 4379*72b2703bSAndreas Gohr paragraph 4380*72b2703bSAndreas Gohr 4381*72b2703bSAndreas Gohr more code 4382*72b2703bSAndreas Gohr. 4383*72b2703bSAndreas Gohr<ol> 4384*72b2703bSAndreas Gohr<li> 4385*72b2703bSAndreas Gohr<pre><code> indented code 4386*72b2703bSAndreas Gohr</code></pre> 4387*72b2703bSAndreas Gohr<p>paragraph</p> 4388*72b2703bSAndreas Gohr<pre><code>more code 4389*72b2703bSAndreas Gohr</code></pre> 4390*72b2703bSAndreas Gohr</li> 4391*72b2703bSAndreas Gohr</ol> 4392*72b2703bSAndreas Gohr```````````````````````````````` 4393*72b2703bSAndreas Gohr 4394*72b2703bSAndreas Gohr 4395*72b2703bSAndreas GohrNote that rules #1 and #2 only apply to two cases: (a) cases 4396*72b2703bSAndreas Gohrin which the lines to be included in a list item begin with a 4397*72b2703bSAndreas Gohr[non-whitespace character], and (b) cases in which 4398*72b2703bSAndreas Gohrthey begin with an indented code 4399*72b2703bSAndreas Gohrblock. In a case like the following, where the first block begins with 4400*72b2703bSAndreas Gohra three-space indent, the rules do not allow us to form a list item by 4401*72b2703bSAndreas Gohrindenting the whole thing and prepending a list marker: 4402*72b2703bSAndreas Gohr 4403*72b2703bSAndreas Gohr```````````````````````````````` example 4404*72b2703bSAndreas Gohr foo 4405*72b2703bSAndreas Gohr 4406*72b2703bSAndreas Gohrbar 4407*72b2703bSAndreas Gohr. 4408*72b2703bSAndreas Gohr<p>foo</p> 4409*72b2703bSAndreas Gohr<p>bar</p> 4410*72b2703bSAndreas Gohr```````````````````````````````` 4411*72b2703bSAndreas Gohr 4412*72b2703bSAndreas Gohr 4413*72b2703bSAndreas Gohr```````````````````````````````` example 4414*72b2703bSAndreas Gohr- foo 4415*72b2703bSAndreas Gohr 4416*72b2703bSAndreas Gohr bar 4417*72b2703bSAndreas Gohr. 4418*72b2703bSAndreas Gohr<ul> 4419*72b2703bSAndreas Gohr<li>foo</li> 4420*72b2703bSAndreas Gohr</ul> 4421*72b2703bSAndreas Gohr<p>bar</p> 4422*72b2703bSAndreas Gohr```````````````````````````````` 4423*72b2703bSAndreas Gohr 4424*72b2703bSAndreas Gohr 4425*72b2703bSAndreas GohrThis is not a significant restriction, because when a block begins 4426*72b2703bSAndreas Gohrwith 1-3 spaces indent, the indentation can always be removed without 4427*72b2703bSAndreas Gohra change in interpretation, allowing rule #1 to be applied. So, in 4428*72b2703bSAndreas Gohrthe above case: 4429*72b2703bSAndreas Gohr 4430*72b2703bSAndreas Gohr```````````````````````````````` example 4431*72b2703bSAndreas Gohr- foo 4432*72b2703bSAndreas Gohr 4433*72b2703bSAndreas Gohr bar 4434*72b2703bSAndreas Gohr. 4435*72b2703bSAndreas Gohr<ul> 4436*72b2703bSAndreas Gohr<li> 4437*72b2703bSAndreas Gohr<p>foo</p> 4438*72b2703bSAndreas Gohr<p>bar</p> 4439*72b2703bSAndreas Gohr</li> 4440*72b2703bSAndreas Gohr</ul> 4441*72b2703bSAndreas Gohr```````````````````````````````` 4442*72b2703bSAndreas Gohr 4443*72b2703bSAndreas Gohr 4444*72b2703bSAndreas Gohr3. **Item starting with a blank line.** If a sequence of lines *Ls* 4445*72b2703bSAndreas Gohr starting with a single [blank line] constitute a (possibly empty) 4446*72b2703bSAndreas Gohr sequence of blocks *Bs*, not separated from each other by more than 4447*72b2703bSAndreas Gohr one blank line, and *M* is a list marker of width *W*, 4448*72b2703bSAndreas Gohr then the result of prepending *M* to the first line of *Ls*, and 4449*72b2703bSAndreas Gohr indenting subsequent lines of *Ls* by *W + 1* spaces, is a list 4450*72b2703bSAndreas Gohr item with *Bs* as its contents. 4451*72b2703bSAndreas Gohr If a line is empty, then it need not be indented. The type of the 4452*72b2703bSAndreas Gohr list item (bullet or ordered) is determined by the type of its list 4453*72b2703bSAndreas Gohr marker. If the list item is ordered, then it is also assigned a 4454*72b2703bSAndreas Gohr start number, based on the ordered list marker. 4455*72b2703bSAndreas Gohr 4456*72b2703bSAndreas GohrHere are some list items that start with a blank line but are not empty: 4457*72b2703bSAndreas Gohr 4458*72b2703bSAndreas Gohr```````````````````````````````` example 4459*72b2703bSAndreas Gohr- 4460*72b2703bSAndreas Gohr foo 4461*72b2703bSAndreas Gohr- 4462*72b2703bSAndreas Gohr ``` 4463*72b2703bSAndreas Gohr bar 4464*72b2703bSAndreas Gohr ``` 4465*72b2703bSAndreas Gohr- 4466*72b2703bSAndreas Gohr baz 4467*72b2703bSAndreas Gohr. 4468*72b2703bSAndreas Gohr<ul> 4469*72b2703bSAndreas Gohr<li>foo</li> 4470*72b2703bSAndreas Gohr<li> 4471*72b2703bSAndreas Gohr<pre><code>bar 4472*72b2703bSAndreas Gohr</code></pre> 4473*72b2703bSAndreas Gohr</li> 4474*72b2703bSAndreas Gohr<li> 4475*72b2703bSAndreas Gohr<pre><code>baz 4476*72b2703bSAndreas Gohr</code></pre> 4477*72b2703bSAndreas Gohr</li> 4478*72b2703bSAndreas Gohr</ul> 4479*72b2703bSAndreas Gohr```````````````````````````````` 4480*72b2703bSAndreas Gohr 4481*72b2703bSAndreas GohrWhen the list item starts with a blank line, the number of spaces 4482*72b2703bSAndreas Gohrfollowing the list marker doesn't change the required indentation: 4483*72b2703bSAndreas Gohr 4484*72b2703bSAndreas Gohr```````````````````````````````` example 4485*72b2703bSAndreas Gohr- 4486*72b2703bSAndreas Gohr foo 4487*72b2703bSAndreas Gohr. 4488*72b2703bSAndreas Gohr<ul> 4489*72b2703bSAndreas Gohr<li>foo</li> 4490*72b2703bSAndreas Gohr</ul> 4491*72b2703bSAndreas Gohr```````````````````````````````` 4492*72b2703bSAndreas Gohr 4493*72b2703bSAndreas Gohr 4494*72b2703bSAndreas GohrA list item can begin with at most one blank line. 4495*72b2703bSAndreas GohrIn the following example, `foo` is not part of the list 4496*72b2703bSAndreas Gohritem: 4497*72b2703bSAndreas Gohr 4498*72b2703bSAndreas Gohr```````````````````````````````` example 4499*72b2703bSAndreas Gohr- 4500*72b2703bSAndreas Gohr 4501*72b2703bSAndreas Gohr foo 4502*72b2703bSAndreas Gohr. 4503*72b2703bSAndreas Gohr<ul> 4504*72b2703bSAndreas Gohr<li></li> 4505*72b2703bSAndreas Gohr</ul> 4506*72b2703bSAndreas Gohr<p>foo</p> 4507*72b2703bSAndreas Gohr```````````````````````````````` 4508*72b2703bSAndreas Gohr 4509*72b2703bSAndreas Gohr 4510*72b2703bSAndreas GohrHere is an empty bullet list item: 4511*72b2703bSAndreas Gohr 4512*72b2703bSAndreas Gohr```````````````````````````````` example 4513*72b2703bSAndreas Gohr- foo 4514*72b2703bSAndreas Gohr- 4515*72b2703bSAndreas Gohr- bar 4516*72b2703bSAndreas Gohr. 4517*72b2703bSAndreas Gohr<ul> 4518*72b2703bSAndreas Gohr<li>foo</li> 4519*72b2703bSAndreas Gohr<li></li> 4520*72b2703bSAndreas Gohr<li>bar</li> 4521*72b2703bSAndreas Gohr</ul> 4522*72b2703bSAndreas Gohr```````````````````````````````` 4523*72b2703bSAndreas Gohr 4524*72b2703bSAndreas Gohr 4525*72b2703bSAndreas GohrIt does not matter whether there are spaces following the [list marker]: 4526*72b2703bSAndreas Gohr 4527*72b2703bSAndreas Gohr```````````````````````````````` example 4528*72b2703bSAndreas Gohr- foo 4529*72b2703bSAndreas Gohr- 4530*72b2703bSAndreas Gohr- bar 4531*72b2703bSAndreas Gohr. 4532*72b2703bSAndreas Gohr<ul> 4533*72b2703bSAndreas Gohr<li>foo</li> 4534*72b2703bSAndreas Gohr<li></li> 4535*72b2703bSAndreas Gohr<li>bar</li> 4536*72b2703bSAndreas Gohr</ul> 4537*72b2703bSAndreas Gohr```````````````````````````````` 4538*72b2703bSAndreas Gohr 4539*72b2703bSAndreas Gohr 4540*72b2703bSAndreas GohrHere is an empty ordered list item: 4541*72b2703bSAndreas Gohr 4542*72b2703bSAndreas Gohr```````````````````````````````` example 4543*72b2703bSAndreas Gohr1. foo 4544*72b2703bSAndreas Gohr2. 4545*72b2703bSAndreas Gohr3. bar 4546*72b2703bSAndreas Gohr. 4547*72b2703bSAndreas Gohr<ol> 4548*72b2703bSAndreas Gohr<li>foo</li> 4549*72b2703bSAndreas Gohr<li></li> 4550*72b2703bSAndreas Gohr<li>bar</li> 4551*72b2703bSAndreas Gohr</ol> 4552*72b2703bSAndreas Gohr```````````````````````````````` 4553*72b2703bSAndreas Gohr 4554*72b2703bSAndreas Gohr 4555*72b2703bSAndreas GohrA list may start or end with an empty list item: 4556*72b2703bSAndreas Gohr 4557*72b2703bSAndreas Gohr```````````````````````````````` example 4558*72b2703bSAndreas Gohr* 4559*72b2703bSAndreas Gohr. 4560*72b2703bSAndreas Gohr<ul> 4561*72b2703bSAndreas Gohr<li></li> 4562*72b2703bSAndreas Gohr</ul> 4563*72b2703bSAndreas Gohr```````````````````````````````` 4564*72b2703bSAndreas Gohr 4565*72b2703bSAndreas GohrHowever, an empty list item cannot interrupt a paragraph: 4566*72b2703bSAndreas Gohr 4567*72b2703bSAndreas Gohr```````````````````````````````` example 4568*72b2703bSAndreas Gohrfoo 4569*72b2703bSAndreas Gohr* 4570*72b2703bSAndreas Gohr 4571*72b2703bSAndreas Gohrfoo 4572*72b2703bSAndreas Gohr1. 4573*72b2703bSAndreas Gohr. 4574*72b2703bSAndreas Gohr<p>foo 4575*72b2703bSAndreas Gohr*</p> 4576*72b2703bSAndreas Gohr<p>foo 4577*72b2703bSAndreas Gohr1.</p> 4578*72b2703bSAndreas Gohr```````````````````````````````` 4579*72b2703bSAndreas Gohr 4580*72b2703bSAndreas Gohr 4581*72b2703bSAndreas Gohr4. **Indentation.** If a sequence of lines *Ls* constitutes a list item 4582*72b2703bSAndreas Gohr according to rule #1, #2, or #3, then the result of indenting each line 4583*72b2703bSAndreas Gohr of *Ls* by 1-3 spaces (the same for each line) also constitutes a 4584*72b2703bSAndreas Gohr list item with the same contents and attributes. If a line is 4585*72b2703bSAndreas Gohr empty, then it need not be indented. 4586*72b2703bSAndreas Gohr 4587*72b2703bSAndreas GohrIndented one space: 4588*72b2703bSAndreas Gohr 4589*72b2703bSAndreas Gohr```````````````````````````````` example 4590*72b2703bSAndreas Gohr 1. A paragraph 4591*72b2703bSAndreas Gohr with two lines. 4592*72b2703bSAndreas Gohr 4593*72b2703bSAndreas Gohr indented code 4594*72b2703bSAndreas Gohr 4595*72b2703bSAndreas Gohr > A block quote. 4596*72b2703bSAndreas Gohr. 4597*72b2703bSAndreas Gohr<ol> 4598*72b2703bSAndreas Gohr<li> 4599*72b2703bSAndreas Gohr<p>A paragraph 4600*72b2703bSAndreas Gohrwith two lines.</p> 4601*72b2703bSAndreas Gohr<pre><code>indented code 4602*72b2703bSAndreas Gohr</code></pre> 4603*72b2703bSAndreas Gohr<blockquote> 4604*72b2703bSAndreas Gohr<p>A block quote.</p> 4605*72b2703bSAndreas Gohr</blockquote> 4606*72b2703bSAndreas Gohr</li> 4607*72b2703bSAndreas Gohr</ol> 4608*72b2703bSAndreas Gohr```````````````````````````````` 4609*72b2703bSAndreas Gohr 4610*72b2703bSAndreas Gohr 4611*72b2703bSAndreas GohrIndented two spaces: 4612*72b2703bSAndreas Gohr 4613*72b2703bSAndreas Gohr```````````````````````````````` example 4614*72b2703bSAndreas Gohr 1. A paragraph 4615*72b2703bSAndreas Gohr with two lines. 4616*72b2703bSAndreas Gohr 4617*72b2703bSAndreas Gohr indented code 4618*72b2703bSAndreas Gohr 4619*72b2703bSAndreas Gohr > A block quote. 4620*72b2703bSAndreas Gohr. 4621*72b2703bSAndreas Gohr<ol> 4622*72b2703bSAndreas Gohr<li> 4623*72b2703bSAndreas Gohr<p>A paragraph 4624*72b2703bSAndreas Gohrwith two lines.</p> 4625*72b2703bSAndreas Gohr<pre><code>indented code 4626*72b2703bSAndreas Gohr</code></pre> 4627*72b2703bSAndreas Gohr<blockquote> 4628*72b2703bSAndreas Gohr<p>A block quote.</p> 4629*72b2703bSAndreas Gohr</blockquote> 4630*72b2703bSAndreas Gohr</li> 4631*72b2703bSAndreas Gohr</ol> 4632*72b2703bSAndreas Gohr```````````````````````````````` 4633*72b2703bSAndreas Gohr 4634*72b2703bSAndreas Gohr 4635*72b2703bSAndreas GohrIndented three spaces: 4636*72b2703bSAndreas Gohr 4637*72b2703bSAndreas Gohr```````````````````````````````` example 4638*72b2703bSAndreas Gohr 1. A paragraph 4639*72b2703bSAndreas Gohr with two lines. 4640*72b2703bSAndreas Gohr 4641*72b2703bSAndreas Gohr indented code 4642*72b2703bSAndreas Gohr 4643*72b2703bSAndreas Gohr > A block quote. 4644*72b2703bSAndreas Gohr. 4645*72b2703bSAndreas Gohr<ol> 4646*72b2703bSAndreas Gohr<li> 4647*72b2703bSAndreas Gohr<p>A paragraph 4648*72b2703bSAndreas Gohrwith two lines.</p> 4649*72b2703bSAndreas Gohr<pre><code>indented code 4650*72b2703bSAndreas Gohr</code></pre> 4651*72b2703bSAndreas Gohr<blockquote> 4652*72b2703bSAndreas Gohr<p>A block quote.</p> 4653*72b2703bSAndreas Gohr</blockquote> 4654*72b2703bSAndreas Gohr</li> 4655*72b2703bSAndreas Gohr</ol> 4656*72b2703bSAndreas Gohr```````````````````````````````` 4657*72b2703bSAndreas Gohr 4658*72b2703bSAndreas Gohr 4659*72b2703bSAndreas GohrFour spaces indent gives a code block: 4660*72b2703bSAndreas Gohr 4661*72b2703bSAndreas Gohr```````````````````````````````` example 4662*72b2703bSAndreas Gohr 1. A paragraph 4663*72b2703bSAndreas Gohr with two lines. 4664*72b2703bSAndreas Gohr 4665*72b2703bSAndreas Gohr indented code 4666*72b2703bSAndreas Gohr 4667*72b2703bSAndreas Gohr > A block quote. 4668*72b2703bSAndreas Gohr. 4669*72b2703bSAndreas Gohr<pre><code>1. A paragraph 4670*72b2703bSAndreas Gohr with two lines. 4671*72b2703bSAndreas Gohr 4672*72b2703bSAndreas Gohr indented code 4673*72b2703bSAndreas Gohr 4674*72b2703bSAndreas Gohr > A block quote. 4675*72b2703bSAndreas Gohr</code></pre> 4676*72b2703bSAndreas Gohr```````````````````````````````` 4677*72b2703bSAndreas Gohr 4678*72b2703bSAndreas Gohr 4679*72b2703bSAndreas Gohr 4680*72b2703bSAndreas Gohr5. **Laziness.** If a string of lines *Ls* constitute a [list 4681*72b2703bSAndreas Gohr item](#list-items) with contents *Bs*, then the result of deleting 4682*72b2703bSAndreas Gohr some or all of the indentation from one or more lines in which the 4683*72b2703bSAndreas Gohr next [non-whitespace character] after the indentation is 4684*72b2703bSAndreas Gohr [paragraph continuation text] is a 4685*72b2703bSAndreas Gohr list item with the same contents and attributes. The unindented 4686*72b2703bSAndreas Gohr lines are called 4687*72b2703bSAndreas Gohr [lazy continuation line](@)s. 4688*72b2703bSAndreas Gohr 4689*72b2703bSAndreas GohrHere is an example with [lazy continuation lines]: 4690*72b2703bSAndreas Gohr 4691*72b2703bSAndreas Gohr```````````````````````````````` example 4692*72b2703bSAndreas Gohr 1. A paragraph 4693*72b2703bSAndreas Gohrwith two lines. 4694*72b2703bSAndreas Gohr 4695*72b2703bSAndreas Gohr indented code 4696*72b2703bSAndreas Gohr 4697*72b2703bSAndreas Gohr > A block quote. 4698*72b2703bSAndreas Gohr. 4699*72b2703bSAndreas Gohr<ol> 4700*72b2703bSAndreas Gohr<li> 4701*72b2703bSAndreas Gohr<p>A paragraph 4702*72b2703bSAndreas Gohrwith two lines.</p> 4703*72b2703bSAndreas Gohr<pre><code>indented code 4704*72b2703bSAndreas Gohr</code></pre> 4705*72b2703bSAndreas Gohr<blockquote> 4706*72b2703bSAndreas Gohr<p>A block quote.</p> 4707*72b2703bSAndreas Gohr</blockquote> 4708*72b2703bSAndreas Gohr</li> 4709*72b2703bSAndreas Gohr</ol> 4710*72b2703bSAndreas Gohr```````````````````````````````` 4711*72b2703bSAndreas Gohr 4712*72b2703bSAndreas Gohr 4713*72b2703bSAndreas GohrIndentation can be partially deleted: 4714*72b2703bSAndreas Gohr 4715*72b2703bSAndreas Gohr```````````````````````````````` example 4716*72b2703bSAndreas Gohr 1. A paragraph 4717*72b2703bSAndreas Gohr with two lines. 4718*72b2703bSAndreas Gohr. 4719*72b2703bSAndreas Gohr<ol> 4720*72b2703bSAndreas Gohr<li>A paragraph 4721*72b2703bSAndreas Gohrwith two lines.</li> 4722*72b2703bSAndreas Gohr</ol> 4723*72b2703bSAndreas Gohr```````````````````````````````` 4724*72b2703bSAndreas Gohr 4725*72b2703bSAndreas Gohr 4726*72b2703bSAndreas GohrThese examples show how laziness can work in nested structures: 4727*72b2703bSAndreas Gohr 4728*72b2703bSAndreas Gohr```````````````````````````````` example 4729*72b2703bSAndreas Gohr> 1. > Blockquote 4730*72b2703bSAndreas Gohrcontinued here. 4731*72b2703bSAndreas Gohr. 4732*72b2703bSAndreas Gohr<blockquote> 4733*72b2703bSAndreas Gohr<ol> 4734*72b2703bSAndreas Gohr<li> 4735*72b2703bSAndreas Gohr<blockquote> 4736*72b2703bSAndreas Gohr<p>Blockquote 4737*72b2703bSAndreas Gohrcontinued here.</p> 4738*72b2703bSAndreas Gohr</blockquote> 4739*72b2703bSAndreas Gohr</li> 4740*72b2703bSAndreas Gohr</ol> 4741*72b2703bSAndreas Gohr</blockquote> 4742*72b2703bSAndreas Gohr```````````````````````````````` 4743*72b2703bSAndreas Gohr 4744*72b2703bSAndreas Gohr 4745*72b2703bSAndreas Gohr```````````````````````````````` example 4746*72b2703bSAndreas Gohr> 1. > Blockquote 4747*72b2703bSAndreas Gohr> continued here. 4748*72b2703bSAndreas Gohr. 4749*72b2703bSAndreas Gohr<blockquote> 4750*72b2703bSAndreas Gohr<ol> 4751*72b2703bSAndreas Gohr<li> 4752*72b2703bSAndreas Gohr<blockquote> 4753*72b2703bSAndreas Gohr<p>Blockquote 4754*72b2703bSAndreas Gohrcontinued here.</p> 4755*72b2703bSAndreas Gohr</blockquote> 4756*72b2703bSAndreas Gohr</li> 4757*72b2703bSAndreas Gohr</ol> 4758*72b2703bSAndreas Gohr</blockquote> 4759*72b2703bSAndreas Gohr```````````````````````````````` 4760*72b2703bSAndreas Gohr 4761*72b2703bSAndreas Gohr 4762*72b2703bSAndreas Gohr 4763*72b2703bSAndreas Gohr6. **That's all.** Nothing that is not counted as a list item by rules 4764*72b2703bSAndreas Gohr #1--5 counts as a [list item](#list-items). 4765*72b2703bSAndreas Gohr 4766*72b2703bSAndreas GohrThe rules for sublists follow from the general rules 4767*72b2703bSAndreas Gohr[above][List items]. A sublist must be indented the same number 4768*72b2703bSAndreas Gohrof spaces a paragraph would need to be in order to be included 4769*72b2703bSAndreas Gohrin the list item. 4770*72b2703bSAndreas Gohr 4771*72b2703bSAndreas GohrSo, in this case we need two spaces indent: 4772*72b2703bSAndreas Gohr 4773*72b2703bSAndreas Gohr```````````````````````````````` example 4774*72b2703bSAndreas Gohr- foo 4775*72b2703bSAndreas Gohr - bar 4776*72b2703bSAndreas Gohr - baz 4777*72b2703bSAndreas Gohr - boo 4778*72b2703bSAndreas Gohr. 4779*72b2703bSAndreas Gohr<ul> 4780*72b2703bSAndreas Gohr<li>foo 4781*72b2703bSAndreas Gohr<ul> 4782*72b2703bSAndreas Gohr<li>bar 4783*72b2703bSAndreas Gohr<ul> 4784*72b2703bSAndreas Gohr<li>baz 4785*72b2703bSAndreas Gohr<ul> 4786*72b2703bSAndreas Gohr<li>boo</li> 4787*72b2703bSAndreas Gohr</ul> 4788*72b2703bSAndreas Gohr</li> 4789*72b2703bSAndreas Gohr</ul> 4790*72b2703bSAndreas Gohr</li> 4791*72b2703bSAndreas Gohr</ul> 4792*72b2703bSAndreas Gohr</li> 4793*72b2703bSAndreas Gohr</ul> 4794*72b2703bSAndreas Gohr```````````````````````````````` 4795*72b2703bSAndreas Gohr 4796*72b2703bSAndreas Gohr 4797*72b2703bSAndreas GohrOne is not enough: 4798*72b2703bSAndreas Gohr 4799*72b2703bSAndreas Gohr```````````````````````````````` example 4800*72b2703bSAndreas Gohr- foo 4801*72b2703bSAndreas Gohr - bar 4802*72b2703bSAndreas Gohr - baz 4803*72b2703bSAndreas Gohr - boo 4804*72b2703bSAndreas Gohr. 4805*72b2703bSAndreas Gohr<ul> 4806*72b2703bSAndreas Gohr<li>foo</li> 4807*72b2703bSAndreas Gohr<li>bar</li> 4808*72b2703bSAndreas Gohr<li>baz</li> 4809*72b2703bSAndreas Gohr<li>boo</li> 4810*72b2703bSAndreas Gohr</ul> 4811*72b2703bSAndreas Gohr```````````````````````````````` 4812*72b2703bSAndreas Gohr 4813*72b2703bSAndreas Gohr 4814*72b2703bSAndreas GohrHere we need four, because the list marker is wider: 4815*72b2703bSAndreas Gohr 4816*72b2703bSAndreas Gohr```````````````````````````````` example 4817*72b2703bSAndreas Gohr10) foo 4818*72b2703bSAndreas Gohr - bar 4819*72b2703bSAndreas Gohr. 4820*72b2703bSAndreas Gohr<ol start="10"> 4821*72b2703bSAndreas Gohr<li>foo 4822*72b2703bSAndreas Gohr<ul> 4823*72b2703bSAndreas Gohr<li>bar</li> 4824*72b2703bSAndreas Gohr</ul> 4825*72b2703bSAndreas Gohr</li> 4826*72b2703bSAndreas Gohr</ol> 4827*72b2703bSAndreas Gohr```````````````````````````````` 4828*72b2703bSAndreas Gohr 4829*72b2703bSAndreas Gohr 4830*72b2703bSAndreas GohrThree is not enough: 4831*72b2703bSAndreas Gohr 4832*72b2703bSAndreas Gohr```````````````````````````````` example 4833*72b2703bSAndreas Gohr10) foo 4834*72b2703bSAndreas Gohr - bar 4835*72b2703bSAndreas Gohr. 4836*72b2703bSAndreas Gohr<ol start="10"> 4837*72b2703bSAndreas Gohr<li>foo</li> 4838*72b2703bSAndreas Gohr</ol> 4839*72b2703bSAndreas Gohr<ul> 4840*72b2703bSAndreas Gohr<li>bar</li> 4841*72b2703bSAndreas Gohr</ul> 4842*72b2703bSAndreas Gohr```````````````````````````````` 4843*72b2703bSAndreas Gohr 4844*72b2703bSAndreas Gohr 4845*72b2703bSAndreas GohrA list may be the first block in a list item: 4846*72b2703bSAndreas Gohr 4847*72b2703bSAndreas Gohr```````````````````````````````` example 4848*72b2703bSAndreas Gohr- - foo 4849*72b2703bSAndreas Gohr. 4850*72b2703bSAndreas Gohr<ul> 4851*72b2703bSAndreas Gohr<li> 4852*72b2703bSAndreas Gohr<ul> 4853*72b2703bSAndreas Gohr<li>foo</li> 4854*72b2703bSAndreas Gohr</ul> 4855*72b2703bSAndreas Gohr</li> 4856*72b2703bSAndreas Gohr</ul> 4857*72b2703bSAndreas Gohr```````````````````````````````` 4858*72b2703bSAndreas Gohr 4859*72b2703bSAndreas Gohr 4860*72b2703bSAndreas Gohr```````````````````````````````` example 4861*72b2703bSAndreas Gohr1. - 2. foo 4862*72b2703bSAndreas Gohr. 4863*72b2703bSAndreas Gohr<ol> 4864*72b2703bSAndreas Gohr<li> 4865*72b2703bSAndreas Gohr<ul> 4866*72b2703bSAndreas Gohr<li> 4867*72b2703bSAndreas Gohr<ol start="2"> 4868*72b2703bSAndreas Gohr<li>foo</li> 4869*72b2703bSAndreas Gohr</ol> 4870*72b2703bSAndreas Gohr</li> 4871*72b2703bSAndreas Gohr</ul> 4872*72b2703bSAndreas Gohr</li> 4873*72b2703bSAndreas Gohr</ol> 4874*72b2703bSAndreas Gohr```````````````````````````````` 4875*72b2703bSAndreas Gohr 4876*72b2703bSAndreas Gohr 4877*72b2703bSAndreas GohrA list item can contain a heading: 4878*72b2703bSAndreas Gohr 4879*72b2703bSAndreas Gohr```````````````````````````````` example 4880*72b2703bSAndreas Gohr- # Foo 4881*72b2703bSAndreas Gohr- Bar 4882*72b2703bSAndreas Gohr --- 4883*72b2703bSAndreas Gohr baz 4884*72b2703bSAndreas Gohr. 4885*72b2703bSAndreas Gohr<ul> 4886*72b2703bSAndreas Gohr<li> 4887*72b2703bSAndreas Gohr<h1>Foo</h1> 4888*72b2703bSAndreas Gohr</li> 4889*72b2703bSAndreas Gohr<li> 4890*72b2703bSAndreas Gohr<h2>Bar</h2> 4891*72b2703bSAndreas Gohrbaz</li> 4892*72b2703bSAndreas Gohr</ul> 4893*72b2703bSAndreas Gohr```````````````````````````````` 4894*72b2703bSAndreas Gohr 4895*72b2703bSAndreas Gohr 4896*72b2703bSAndreas Gohr### Motivation 4897*72b2703bSAndreas Gohr 4898*72b2703bSAndreas GohrJohn Gruber's Markdown spec says the following about list items: 4899*72b2703bSAndreas Gohr 4900*72b2703bSAndreas Gohr1. "List markers typically start at the left margin, but may be indented 4901*72b2703bSAndreas Gohr by up to three spaces. List markers must be followed by one or more 4902*72b2703bSAndreas Gohr spaces or a tab." 4903*72b2703bSAndreas Gohr 4904*72b2703bSAndreas Gohr2. "To make lists look nice, you can wrap items with hanging indents.... 4905*72b2703bSAndreas Gohr But if you don't want to, you don't have to." 4906*72b2703bSAndreas Gohr 4907*72b2703bSAndreas Gohr3. "List items may consist of multiple paragraphs. Each subsequent 4908*72b2703bSAndreas Gohr paragraph in a list item must be indented by either 4 spaces or one 4909*72b2703bSAndreas Gohr tab." 4910*72b2703bSAndreas Gohr 4911*72b2703bSAndreas Gohr4. "It looks nice if you indent every line of the subsequent paragraphs, 4912*72b2703bSAndreas Gohr but here again, Markdown will allow you to be lazy." 4913*72b2703bSAndreas Gohr 4914*72b2703bSAndreas Gohr5. "To put a blockquote within a list item, the blockquote's `>` 4915*72b2703bSAndreas Gohr delimiters need to be indented." 4916*72b2703bSAndreas Gohr 4917*72b2703bSAndreas Gohr6. "To put a code block within a list item, the code block needs to be 4918*72b2703bSAndreas Gohr indented twice — 8 spaces or two tabs." 4919*72b2703bSAndreas Gohr 4920*72b2703bSAndreas GohrThese rules specify that a paragraph under a list item must be indented 4921*72b2703bSAndreas Gohrfour spaces (presumably, from the left margin, rather than the start of 4922*72b2703bSAndreas Gohrthe list marker, but this is not said), and that code under a list item 4923*72b2703bSAndreas Gohrmust be indented eight spaces instead of the usual four. They also say 4924*72b2703bSAndreas Gohrthat a block quote must be indented, but not by how much; however, the 4925*72b2703bSAndreas Gohrexample given has four spaces indentation. Although nothing is said 4926*72b2703bSAndreas Gohrabout other kinds of block-level content, it is certainly reasonable to 4927*72b2703bSAndreas Gohrinfer that *all* block elements under a list item, including other 4928*72b2703bSAndreas Gohrlists, must be indented four spaces. This principle has been called the 4929*72b2703bSAndreas Gohr*four-space rule*. 4930*72b2703bSAndreas Gohr 4931*72b2703bSAndreas GohrThe four-space rule is clear and principled, and if the reference 4932*72b2703bSAndreas Gohrimplementation `Markdown.pl` had followed it, it probably would have 4933*72b2703bSAndreas Gohrbecome the standard. However, `Markdown.pl` allowed paragraphs and 4934*72b2703bSAndreas Gohrsublists to start with only two spaces indentation, at least on the 4935*72b2703bSAndreas Gohrouter level. Worse, its behavior was inconsistent: a sublist of an 4936*72b2703bSAndreas Gohrouter-level list needed two spaces indentation, but a sublist of this 4937*72b2703bSAndreas Gohrsublist needed three spaces. It is not surprising, then, that different 4938*72b2703bSAndreas Gohrimplementations of Markdown have developed very different rules for 4939*72b2703bSAndreas Gohrdetermining what comes under a list item. (Pandoc and python-Markdown, 4940*72b2703bSAndreas Gohrfor example, stuck with Gruber's syntax description and the four-space 4941*72b2703bSAndreas Gohrrule, while discount, redcarpet, marked, PHP Markdown, and others 4942*72b2703bSAndreas Gohrfollowed `Markdown.pl`'s behavior more closely.) 4943*72b2703bSAndreas Gohr 4944*72b2703bSAndreas GohrUnfortunately, given the divergences between implementations, there 4945*72b2703bSAndreas Gohris no way to give a spec for list items that will be guaranteed not 4946*72b2703bSAndreas Gohrto break any existing documents. However, the spec given here should 4947*72b2703bSAndreas Gohrcorrectly handle lists formatted with either the four-space rule or 4948*72b2703bSAndreas Gohrthe more forgiving `Markdown.pl` behavior, provided they are laid out 4949*72b2703bSAndreas Gohrin a way that is natural for a human to read. 4950*72b2703bSAndreas Gohr 4951*72b2703bSAndreas GohrThe strategy here is to let the width and indentation of the list marker 4952*72b2703bSAndreas Gohrdetermine the indentation necessary for blocks to fall under the list 4953*72b2703bSAndreas Gohritem, rather than having a fixed and arbitrary number. The writer can 4954*72b2703bSAndreas Gohrthink of the body of the list item as a unit which gets indented to the 4955*72b2703bSAndreas Gohrright enough to fit the list marker (and any indentation on the list 4956*72b2703bSAndreas Gohrmarker). (The laziness rule, #5, then allows continuation lines to be 4957*72b2703bSAndreas Gohrunindented if needed.) 4958*72b2703bSAndreas Gohr 4959*72b2703bSAndreas GohrThis rule is superior, we claim, to any rule requiring a fixed level of 4960*72b2703bSAndreas Gohrindentation from the margin. The four-space rule is clear but 4961*72b2703bSAndreas Gohrunnatural. It is quite unintuitive that 4962*72b2703bSAndreas Gohr 4963*72b2703bSAndreas Gohr``` markdown 4964*72b2703bSAndreas Gohr- foo 4965*72b2703bSAndreas Gohr 4966*72b2703bSAndreas Gohr bar 4967*72b2703bSAndreas Gohr 4968*72b2703bSAndreas Gohr - baz 4969*72b2703bSAndreas Gohr``` 4970*72b2703bSAndreas Gohr 4971*72b2703bSAndreas Gohrshould be parsed as two lists with an intervening paragraph, 4972*72b2703bSAndreas Gohr 4973*72b2703bSAndreas Gohr``` html 4974*72b2703bSAndreas Gohr<ul> 4975*72b2703bSAndreas Gohr<li>foo</li> 4976*72b2703bSAndreas Gohr</ul> 4977*72b2703bSAndreas Gohr<p>bar</p> 4978*72b2703bSAndreas Gohr<ul> 4979*72b2703bSAndreas Gohr<li>baz</li> 4980*72b2703bSAndreas Gohr</ul> 4981*72b2703bSAndreas Gohr``` 4982*72b2703bSAndreas Gohr 4983*72b2703bSAndreas Gohras the four-space rule demands, rather than a single list, 4984*72b2703bSAndreas Gohr 4985*72b2703bSAndreas Gohr``` html 4986*72b2703bSAndreas Gohr<ul> 4987*72b2703bSAndreas Gohr<li> 4988*72b2703bSAndreas Gohr<p>foo</p> 4989*72b2703bSAndreas Gohr<p>bar</p> 4990*72b2703bSAndreas Gohr<ul> 4991*72b2703bSAndreas Gohr<li>baz</li> 4992*72b2703bSAndreas Gohr</ul> 4993*72b2703bSAndreas Gohr</li> 4994*72b2703bSAndreas Gohr</ul> 4995*72b2703bSAndreas Gohr``` 4996*72b2703bSAndreas Gohr 4997*72b2703bSAndreas GohrThe choice of four spaces is arbitrary. It can be learned, but it is 4998*72b2703bSAndreas Gohrnot likely to be guessed, and it trips up beginners regularly. 4999*72b2703bSAndreas Gohr 5000*72b2703bSAndreas GohrWould it help to adopt a two-space rule? The problem is that such 5001*72b2703bSAndreas Gohra rule, together with the rule allowing 1--3 spaces indentation of the 5002*72b2703bSAndreas Gohrinitial list marker, allows text that is indented *less than* the 5003*72b2703bSAndreas Gohroriginal list marker to be included in the list item. For example, 5004*72b2703bSAndreas Gohr`Markdown.pl` parses 5005*72b2703bSAndreas Gohr 5006*72b2703bSAndreas Gohr``` markdown 5007*72b2703bSAndreas Gohr - one 5008*72b2703bSAndreas Gohr 5009*72b2703bSAndreas Gohr two 5010*72b2703bSAndreas Gohr``` 5011*72b2703bSAndreas Gohr 5012*72b2703bSAndreas Gohras a single list item, with `two` a continuation paragraph: 5013*72b2703bSAndreas Gohr 5014*72b2703bSAndreas Gohr``` html 5015*72b2703bSAndreas Gohr<ul> 5016*72b2703bSAndreas Gohr<li> 5017*72b2703bSAndreas Gohr<p>one</p> 5018*72b2703bSAndreas Gohr<p>two</p> 5019*72b2703bSAndreas Gohr</li> 5020*72b2703bSAndreas Gohr</ul> 5021*72b2703bSAndreas Gohr``` 5022*72b2703bSAndreas Gohr 5023*72b2703bSAndreas Gohrand similarly 5024*72b2703bSAndreas Gohr 5025*72b2703bSAndreas Gohr``` markdown 5026*72b2703bSAndreas Gohr> - one 5027*72b2703bSAndreas Gohr> 5028*72b2703bSAndreas Gohr> two 5029*72b2703bSAndreas Gohr``` 5030*72b2703bSAndreas Gohr 5031*72b2703bSAndreas Gohras 5032*72b2703bSAndreas Gohr 5033*72b2703bSAndreas Gohr``` html 5034*72b2703bSAndreas Gohr<blockquote> 5035*72b2703bSAndreas Gohr<ul> 5036*72b2703bSAndreas Gohr<li> 5037*72b2703bSAndreas Gohr<p>one</p> 5038*72b2703bSAndreas Gohr<p>two</p> 5039*72b2703bSAndreas Gohr</li> 5040*72b2703bSAndreas Gohr</ul> 5041*72b2703bSAndreas Gohr</blockquote> 5042*72b2703bSAndreas Gohr``` 5043*72b2703bSAndreas Gohr 5044*72b2703bSAndreas GohrThis is extremely unintuitive. 5045*72b2703bSAndreas Gohr 5046*72b2703bSAndreas GohrRather than requiring a fixed indent from the margin, we could require 5047*72b2703bSAndreas Gohra fixed indent (say, two spaces, or even one space) from the list marker (which 5048*72b2703bSAndreas Gohrmay itself be indented). This proposal would remove the last anomaly 5049*72b2703bSAndreas Gohrdiscussed. Unlike the spec presented above, it would count the following 5050*72b2703bSAndreas Gohras a list item with a subparagraph, even though the paragraph `bar` 5051*72b2703bSAndreas Gohris not indented as far as the first paragraph `foo`: 5052*72b2703bSAndreas Gohr 5053*72b2703bSAndreas Gohr``` markdown 5054*72b2703bSAndreas Gohr 10. foo 5055*72b2703bSAndreas Gohr 5056*72b2703bSAndreas Gohr bar 5057*72b2703bSAndreas Gohr``` 5058*72b2703bSAndreas Gohr 5059*72b2703bSAndreas GohrArguably this text does read like a list item with `bar` as a subparagraph, 5060*72b2703bSAndreas Gohrwhich may count in favor of the proposal. However, on this proposal indented 5061*72b2703bSAndreas Gohrcode would have to be indented six spaces after the list marker. And this 5062*72b2703bSAndreas Gohrwould break a lot of existing Markdown, which has the pattern: 5063*72b2703bSAndreas Gohr 5064*72b2703bSAndreas Gohr``` markdown 5065*72b2703bSAndreas Gohr1. foo 5066*72b2703bSAndreas Gohr 5067*72b2703bSAndreas Gohr indented code 5068*72b2703bSAndreas Gohr``` 5069*72b2703bSAndreas Gohr 5070*72b2703bSAndreas Gohrwhere the code is indented eight spaces. The spec above, by contrast, will 5071*72b2703bSAndreas Gohrparse this text as expected, since the code block's indentation is measured 5072*72b2703bSAndreas Gohrfrom the beginning of `foo`. 5073*72b2703bSAndreas Gohr 5074*72b2703bSAndreas GohrThe one case that needs special treatment is a list item that *starts* 5075*72b2703bSAndreas Gohrwith indented code. How much indentation is required in that case, since 5076*72b2703bSAndreas Gohrwe don't have a "first paragraph" to measure from? Rule #2 simply stipulates 5077*72b2703bSAndreas Gohrthat in such cases, we require one space indentation from the list marker 5078*72b2703bSAndreas Gohr(and then the normal four spaces for the indented code). This will match the 5079*72b2703bSAndreas Gohrfour-space rule in cases where the list marker plus its initial indentation 5080*72b2703bSAndreas Gohrtakes four spaces (a common case), but diverge in other cases. 5081*72b2703bSAndreas Gohr 5082*72b2703bSAndreas Gohr<div class="extension"> 5083*72b2703bSAndreas Gohr 5084*72b2703bSAndreas Gohr## Task list items (extension) 5085*72b2703bSAndreas Gohr 5086*72b2703bSAndreas GohrGFM enables the `tasklist` extension, where an additional processing step is 5087*72b2703bSAndreas Gohrperformed on [list items]. 5088*72b2703bSAndreas Gohr 5089*72b2703bSAndreas GohrA [task list item](@) is a [list item][list items] where the first block in it 5090*72b2703bSAndreas Gohris a paragraph which begins with a [task list item marker] and at least one 5091*72b2703bSAndreas Gohrwhitespace character before any other content. 5092*72b2703bSAndreas Gohr 5093*72b2703bSAndreas GohrA [task list item marker](@) consists of an optional number of spaces, a left 5094*72b2703bSAndreas Gohrbracket (`[`), either a whitespace character or the letter `x` in either 5095*72b2703bSAndreas Gohrlowercase or uppercase, and then a right bracket (`]`). 5096*72b2703bSAndreas Gohr 5097*72b2703bSAndreas GohrWhen rendered, the [task list item marker] is replaced with a semantic checkbox element; 5098*72b2703bSAndreas Gohrin an HTML output, this would be an `<input type="checkbox">` element. 5099*72b2703bSAndreas Gohr 5100*72b2703bSAndreas GohrIf the character between the brackets is a whitespace character, the checkbox 5101*72b2703bSAndreas Gohris unchecked. Otherwise, the checkbox is checked. 5102*72b2703bSAndreas Gohr 5103*72b2703bSAndreas GohrThis spec does not define how the checkbox elements are interacted with: in practice, 5104*72b2703bSAndreas Gohrimplementors are free to render the checkboxes as disabled or inmutable elements, 5105*72b2703bSAndreas Gohror they may dynamically handle dynamic interactions (i.e. checking, unchecking) in 5106*72b2703bSAndreas Gohrthe final rendered document. 5107*72b2703bSAndreas Gohr 5108*72b2703bSAndreas Gohr```````````````````````````````` example disabled 5109*72b2703bSAndreas Gohr- [ ] foo 5110*72b2703bSAndreas Gohr- [x] bar 5111*72b2703bSAndreas Gohr. 5112*72b2703bSAndreas Gohr<ul> 5113*72b2703bSAndreas Gohr<li><input disabled="" type="checkbox"> foo</li> 5114*72b2703bSAndreas Gohr<li><input checked="" disabled="" type="checkbox"> bar</li> 5115*72b2703bSAndreas Gohr</ul> 5116*72b2703bSAndreas Gohr```````````````````````````````` 5117*72b2703bSAndreas Gohr 5118*72b2703bSAndreas GohrTask lists can be arbitrarily nested: 5119*72b2703bSAndreas Gohr 5120*72b2703bSAndreas Gohr```````````````````````````````` example disabled 5121*72b2703bSAndreas Gohr- [x] foo 5122*72b2703bSAndreas Gohr - [ ] bar 5123*72b2703bSAndreas Gohr - [x] baz 5124*72b2703bSAndreas Gohr- [ ] bim 5125*72b2703bSAndreas Gohr. 5126*72b2703bSAndreas Gohr<ul> 5127*72b2703bSAndreas Gohr<li><input checked="" disabled="" type="checkbox"> foo 5128*72b2703bSAndreas Gohr<ul> 5129*72b2703bSAndreas Gohr<li><input disabled="" type="checkbox"> bar</li> 5130*72b2703bSAndreas Gohr<li><input checked="" disabled="" type="checkbox"> baz</li> 5131*72b2703bSAndreas Gohr</ul> 5132*72b2703bSAndreas Gohr</li> 5133*72b2703bSAndreas Gohr<li><input disabled="" type="checkbox"> bim</li> 5134*72b2703bSAndreas Gohr</ul> 5135*72b2703bSAndreas Gohr```````````````````````````````` 5136*72b2703bSAndreas Gohr 5137*72b2703bSAndreas Gohr</div> 5138*72b2703bSAndreas Gohr 5139*72b2703bSAndreas Gohr## Lists 5140*72b2703bSAndreas Gohr 5141*72b2703bSAndreas GohrA [list](@) is a sequence of one or more 5142*72b2703bSAndreas Gohrlist items [of the same type]. The list items 5143*72b2703bSAndreas Gohrmay be separated by any number of blank lines. 5144*72b2703bSAndreas Gohr 5145*72b2703bSAndreas GohrTwo list items are [of the same type](@) 5146*72b2703bSAndreas Gohrif they begin with a [list marker] of the same type. 5147*72b2703bSAndreas GohrTwo list markers are of the 5148*72b2703bSAndreas Gohrsame type if (a) they are bullet list markers using the same character 5149*72b2703bSAndreas Gohr(`-`, `+`, or `*`) or (b) they are ordered list numbers with the same 5150*72b2703bSAndreas Gohrdelimiter (either `.` or `)`). 5151*72b2703bSAndreas Gohr 5152*72b2703bSAndreas GohrA list is an [ordered list](@) 5153*72b2703bSAndreas Gohrif its constituent list items begin with 5154*72b2703bSAndreas Gohr[ordered list markers], and a 5155*72b2703bSAndreas Gohr[bullet list](@) if its constituent list 5156*72b2703bSAndreas Gohritems begin with [bullet list markers]. 5157*72b2703bSAndreas Gohr 5158*72b2703bSAndreas GohrThe [start number](@) 5159*72b2703bSAndreas Gohrof an [ordered list] is determined by the list number of 5160*72b2703bSAndreas Gohrits initial list item. The numbers of subsequent list items are 5161*72b2703bSAndreas Gohrdisregarded. 5162*72b2703bSAndreas Gohr 5163*72b2703bSAndreas GohrA list is [loose](@) if any of its constituent 5164*72b2703bSAndreas Gohrlist items are separated by blank lines, or if any of its constituent 5165*72b2703bSAndreas Gohrlist items directly contain two block-level elements with a blank line 5166*72b2703bSAndreas Gohrbetween them. Otherwise a list is [tight](@). 5167*72b2703bSAndreas Gohr(The difference in HTML output is that paragraphs in a loose list are 5168*72b2703bSAndreas Gohrwrapped in `<p>` tags, while paragraphs in a tight list are not.) 5169*72b2703bSAndreas Gohr 5170*72b2703bSAndreas GohrChanging the bullet or ordered list delimiter starts a new list: 5171*72b2703bSAndreas Gohr 5172*72b2703bSAndreas Gohr```````````````````````````````` example 5173*72b2703bSAndreas Gohr- foo 5174*72b2703bSAndreas Gohr- bar 5175*72b2703bSAndreas Gohr+ baz 5176*72b2703bSAndreas Gohr. 5177*72b2703bSAndreas Gohr<ul> 5178*72b2703bSAndreas Gohr<li>foo</li> 5179*72b2703bSAndreas Gohr<li>bar</li> 5180*72b2703bSAndreas Gohr</ul> 5181*72b2703bSAndreas Gohr<ul> 5182*72b2703bSAndreas Gohr<li>baz</li> 5183*72b2703bSAndreas Gohr</ul> 5184*72b2703bSAndreas Gohr```````````````````````````````` 5185*72b2703bSAndreas Gohr 5186*72b2703bSAndreas Gohr 5187*72b2703bSAndreas Gohr```````````````````````````````` example 5188*72b2703bSAndreas Gohr1. foo 5189*72b2703bSAndreas Gohr2. bar 5190*72b2703bSAndreas Gohr3) baz 5191*72b2703bSAndreas Gohr. 5192*72b2703bSAndreas Gohr<ol> 5193*72b2703bSAndreas Gohr<li>foo</li> 5194*72b2703bSAndreas Gohr<li>bar</li> 5195*72b2703bSAndreas Gohr</ol> 5196*72b2703bSAndreas Gohr<ol start="3"> 5197*72b2703bSAndreas Gohr<li>baz</li> 5198*72b2703bSAndreas Gohr</ol> 5199*72b2703bSAndreas Gohr```````````````````````````````` 5200*72b2703bSAndreas Gohr 5201*72b2703bSAndreas Gohr 5202*72b2703bSAndreas GohrIn CommonMark, a list can interrupt a paragraph. That is, 5203*72b2703bSAndreas Gohrno blank line is needed to separate a paragraph from a following 5204*72b2703bSAndreas Gohrlist: 5205*72b2703bSAndreas Gohr 5206*72b2703bSAndreas Gohr```````````````````````````````` example 5207*72b2703bSAndreas GohrFoo 5208*72b2703bSAndreas Gohr- bar 5209*72b2703bSAndreas Gohr- baz 5210*72b2703bSAndreas Gohr. 5211*72b2703bSAndreas Gohr<p>Foo</p> 5212*72b2703bSAndreas Gohr<ul> 5213*72b2703bSAndreas Gohr<li>bar</li> 5214*72b2703bSAndreas Gohr<li>baz</li> 5215*72b2703bSAndreas Gohr</ul> 5216*72b2703bSAndreas Gohr```````````````````````````````` 5217*72b2703bSAndreas Gohr 5218*72b2703bSAndreas Gohr`Markdown.pl` does not allow this, through fear of triggering a list 5219*72b2703bSAndreas Gohrvia a numeral in a hard-wrapped line: 5220*72b2703bSAndreas Gohr 5221*72b2703bSAndreas Gohr``` markdown 5222*72b2703bSAndreas GohrThe number of windows in my house is 5223*72b2703bSAndreas Gohr14. The number of doors is 6. 5224*72b2703bSAndreas Gohr``` 5225*72b2703bSAndreas Gohr 5226*72b2703bSAndreas GohrOddly, though, `Markdown.pl` *does* allow a blockquote to 5227*72b2703bSAndreas Gohrinterrupt a paragraph, even though the same considerations might 5228*72b2703bSAndreas Gohrapply. 5229*72b2703bSAndreas Gohr 5230*72b2703bSAndreas GohrIn CommonMark, we do allow lists to interrupt paragraphs, for 5231*72b2703bSAndreas Gohrtwo reasons. First, it is natural and not uncommon for people 5232*72b2703bSAndreas Gohrto start lists without blank lines: 5233*72b2703bSAndreas Gohr 5234*72b2703bSAndreas Gohr``` markdown 5235*72b2703bSAndreas GohrI need to buy 5236*72b2703bSAndreas Gohr- new shoes 5237*72b2703bSAndreas Gohr- a coat 5238*72b2703bSAndreas Gohr- a plane ticket 5239*72b2703bSAndreas Gohr``` 5240*72b2703bSAndreas Gohr 5241*72b2703bSAndreas GohrSecond, we are attracted to a 5242*72b2703bSAndreas Gohr 5243*72b2703bSAndreas Gohr> [principle of uniformity](@): 5244*72b2703bSAndreas Gohr> if a chunk of text has a certain 5245*72b2703bSAndreas Gohr> meaning, it will continue to have the same meaning when put into a 5246*72b2703bSAndreas Gohr> container block (such as a list item or blockquote). 5247*72b2703bSAndreas Gohr 5248*72b2703bSAndreas Gohr(Indeed, the spec for [list items] and [block quotes] presupposes 5249*72b2703bSAndreas Gohrthis principle.) This principle implies that if 5250*72b2703bSAndreas Gohr 5251*72b2703bSAndreas Gohr``` markdown 5252*72b2703bSAndreas Gohr * I need to buy 5253*72b2703bSAndreas Gohr - new shoes 5254*72b2703bSAndreas Gohr - a coat 5255*72b2703bSAndreas Gohr - a plane ticket 5256*72b2703bSAndreas Gohr``` 5257*72b2703bSAndreas Gohr 5258*72b2703bSAndreas Gohris a list item containing a paragraph followed by a nested sublist, 5259*72b2703bSAndreas Gohras all Markdown implementations agree it is (though the paragraph 5260*72b2703bSAndreas Gohrmay be rendered without `<p>` tags, since the list is "tight"), 5261*72b2703bSAndreas Gohrthen 5262*72b2703bSAndreas Gohr 5263*72b2703bSAndreas Gohr``` markdown 5264*72b2703bSAndreas GohrI need to buy 5265*72b2703bSAndreas Gohr- new shoes 5266*72b2703bSAndreas Gohr- a coat 5267*72b2703bSAndreas Gohr- a plane ticket 5268*72b2703bSAndreas Gohr``` 5269*72b2703bSAndreas Gohr 5270*72b2703bSAndreas Gohrby itself should be a paragraph followed by a nested sublist. 5271*72b2703bSAndreas Gohr 5272*72b2703bSAndreas GohrSince it is well established Markdown practice to allow lists to 5273*72b2703bSAndreas Gohrinterrupt paragraphs inside list items, the [principle of 5274*72b2703bSAndreas Gohruniformity] requires us to allow this outside list items as 5275*72b2703bSAndreas Gohrwell. ([reStructuredText](http://docutils.sourceforge.net/rst.html) 5276*72b2703bSAndreas Gohrtakes a different approach, requiring blank lines before lists 5277*72b2703bSAndreas Gohreven inside other list items.) 5278*72b2703bSAndreas Gohr 5279*72b2703bSAndreas GohrIn order to solve the problem of unwanted lists in paragraphs with 5280*72b2703bSAndreas Gohrhard-wrapped numerals, we allow only lists starting with `1` to 5281*72b2703bSAndreas Gohrinterrupt paragraphs. Thus, 5282*72b2703bSAndreas Gohr 5283*72b2703bSAndreas Gohr```````````````````````````````` example 5284*72b2703bSAndreas GohrThe number of windows in my house is 5285*72b2703bSAndreas Gohr14. The number of doors is 6. 5286*72b2703bSAndreas Gohr. 5287*72b2703bSAndreas Gohr<p>The number of windows in my house is 5288*72b2703bSAndreas Gohr14. The number of doors is 6.</p> 5289*72b2703bSAndreas Gohr```````````````````````````````` 5290*72b2703bSAndreas Gohr 5291*72b2703bSAndreas GohrWe may still get an unintended result in cases like 5292*72b2703bSAndreas Gohr 5293*72b2703bSAndreas Gohr```````````````````````````````` example 5294*72b2703bSAndreas GohrThe number of windows in my house is 5295*72b2703bSAndreas Gohr1. The number of doors is 6. 5296*72b2703bSAndreas Gohr. 5297*72b2703bSAndreas Gohr<p>The number of windows in my house is</p> 5298*72b2703bSAndreas Gohr<ol> 5299*72b2703bSAndreas Gohr<li>The number of doors is 6.</li> 5300*72b2703bSAndreas Gohr</ol> 5301*72b2703bSAndreas Gohr```````````````````````````````` 5302*72b2703bSAndreas Gohr 5303*72b2703bSAndreas Gohrbut this rule should prevent most spurious list captures. 5304*72b2703bSAndreas Gohr 5305*72b2703bSAndreas GohrThere can be any number of blank lines between items: 5306*72b2703bSAndreas Gohr 5307*72b2703bSAndreas Gohr```````````````````````````````` example 5308*72b2703bSAndreas Gohr- foo 5309*72b2703bSAndreas Gohr 5310*72b2703bSAndreas Gohr- bar 5311*72b2703bSAndreas Gohr 5312*72b2703bSAndreas Gohr 5313*72b2703bSAndreas Gohr- baz 5314*72b2703bSAndreas Gohr. 5315*72b2703bSAndreas Gohr<ul> 5316*72b2703bSAndreas Gohr<li> 5317*72b2703bSAndreas Gohr<p>foo</p> 5318*72b2703bSAndreas Gohr</li> 5319*72b2703bSAndreas Gohr<li> 5320*72b2703bSAndreas Gohr<p>bar</p> 5321*72b2703bSAndreas Gohr</li> 5322*72b2703bSAndreas Gohr<li> 5323*72b2703bSAndreas Gohr<p>baz</p> 5324*72b2703bSAndreas Gohr</li> 5325*72b2703bSAndreas Gohr</ul> 5326*72b2703bSAndreas Gohr```````````````````````````````` 5327*72b2703bSAndreas Gohr 5328*72b2703bSAndreas Gohr```````````````````````````````` example 5329*72b2703bSAndreas Gohr- foo 5330*72b2703bSAndreas Gohr - bar 5331*72b2703bSAndreas Gohr - baz 5332*72b2703bSAndreas Gohr 5333*72b2703bSAndreas Gohr 5334*72b2703bSAndreas Gohr bim 5335*72b2703bSAndreas Gohr. 5336*72b2703bSAndreas Gohr<ul> 5337*72b2703bSAndreas Gohr<li>foo 5338*72b2703bSAndreas Gohr<ul> 5339*72b2703bSAndreas Gohr<li>bar 5340*72b2703bSAndreas Gohr<ul> 5341*72b2703bSAndreas Gohr<li> 5342*72b2703bSAndreas Gohr<p>baz</p> 5343*72b2703bSAndreas Gohr<p>bim</p> 5344*72b2703bSAndreas Gohr</li> 5345*72b2703bSAndreas Gohr</ul> 5346*72b2703bSAndreas Gohr</li> 5347*72b2703bSAndreas Gohr</ul> 5348*72b2703bSAndreas Gohr</li> 5349*72b2703bSAndreas Gohr</ul> 5350*72b2703bSAndreas Gohr```````````````````````````````` 5351*72b2703bSAndreas Gohr 5352*72b2703bSAndreas Gohr 5353*72b2703bSAndreas GohrTo separate consecutive lists of the same type, or to separate a 5354*72b2703bSAndreas Gohrlist from an indented code block that would otherwise be parsed 5355*72b2703bSAndreas Gohras a subparagraph of the final list item, you can insert a blank HTML 5356*72b2703bSAndreas Gohrcomment: 5357*72b2703bSAndreas Gohr 5358*72b2703bSAndreas Gohr```````````````````````````````` example 5359*72b2703bSAndreas Gohr- foo 5360*72b2703bSAndreas Gohr- bar 5361*72b2703bSAndreas Gohr 5362*72b2703bSAndreas Gohr<!-- --> 5363*72b2703bSAndreas Gohr 5364*72b2703bSAndreas Gohr- baz 5365*72b2703bSAndreas Gohr- bim 5366*72b2703bSAndreas Gohr. 5367*72b2703bSAndreas Gohr<ul> 5368*72b2703bSAndreas Gohr<li>foo</li> 5369*72b2703bSAndreas Gohr<li>bar</li> 5370*72b2703bSAndreas Gohr</ul> 5371*72b2703bSAndreas Gohr<!-- --> 5372*72b2703bSAndreas Gohr<ul> 5373*72b2703bSAndreas Gohr<li>baz</li> 5374*72b2703bSAndreas Gohr<li>bim</li> 5375*72b2703bSAndreas Gohr</ul> 5376*72b2703bSAndreas Gohr```````````````````````````````` 5377*72b2703bSAndreas Gohr 5378*72b2703bSAndreas Gohr 5379*72b2703bSAndreas Gohr```````````````````````````````` example 5380*72b2703bSAndreas Gohr- foo 5381*72b2703bSAndreas Gohr 5382*72b2703bSAndreas Gohr notcode 5383*72b2703bSAndreas Gohr 5384*72b2703bSAndreas Gohr- foo 5385*72b2703bSAndreas Gohr 5386*72b2703bSAndreas Gohr<!-- --> 5387*72b2703bSAndreas Gohr 5388*72b2703bSAndreas Gohr code 5389*72b2703bSAndreas Gohr. 5390*72b2703bSAndreas Gohr<ul> 5391*72b2703bSAndreas Gohr<li> 5392*72b2703bSAndreas Gohr<p>foo</p> 5393*72b2703bSAndreas Gohr<p>notcode</p> 5394*72b2703bSAndreas Gohr</li> 5395*72b2703bSAndreas Gohr<li> 5396*72b2703bSAndreas Gohr<p>foo</p> 5397*72b2703bSAndreas Gohr</li> 5398*72b2703bSAndreas Gohr</ul> 5399*72b2703bSAndreas Gohr<!-- --> 5400*72b2703bSAndreas Gohr<pre><code>code 5401*72b2703bSAndreas Gohr</code></pre> 5402*72b2703bSAndreas Gohr```````````````````````````````` 5403*72b2703bSAndreas Gohr 5404*72b2703bSAndreas Gohr 5405*72b2703bSAndreas GohrList items need not be indented to the same level. The following 5406*72b2703bSAndreas Gohrlist items will be treated as items at the same list level, 5407*72b2703bSAndreas Gohrsince none is indented enough to belong to the previous list 5408*72b2703bSAndreas Gohritem: 5409*72b2703bSAndreas Gohr 5410*72b2703bSAndreas Gohr```````````````````````````````` example 5411*72b2703bSAndreas Gohr- a 5412*72b2703bSAndreas Gohr - b 5413*72b2703bSAndreas Gohr - c 5414*72b2703bSAndreas Gohr - d 5415*72b2703bSAndreas Gohr - e 5416*72b2703bSAndreas Gohr - f 5417*72b2703bSAndreas Gohr- g 5418*72b2703bSAndreas Gohr. 5419*72b2703bSAndreas Gohr<ul> 5420*72b2703bSAndreas Gohr<li>a</li> 5421*72b2703bSAndreas Gohr<li>b</li> 5422*72b2703bSAndreas Gohr<li>c</li> 5423*72b2703bSAndreas Gohr<li>d</li> 5424*72b2703bSAndreas Gohr<li>e</li> 5425*72b2703bSAndreas Gohr<li>f</li> 5426*72b2703bSAndreas Gohr<li>g</li> 5427*72b2703bSAndreas Gohr</ul> 5428*72b2703bSAndreas Gohr```````````````````````````````` 5429*72b2703bSAndreas Gohr 5430*72b2703bSAndreas Gohr 5431*72b2703bSAndreas Gohr```````````````````````````````` example 5432*72b2703bSAndreas Gohr1. a 5433*72b2703bSAndreas Gohr 5434*72b2703bSAndreas Gohr 2. b 5435*72b2703bSAndreas Gohr 5436*72b2703bSAndreas Gohr 3. c 5437*72b2703bSAndreas Gohr. 5438*72b2703bSAndreas Gohr<ol> 5439*72b2703bSAndreas Gohr<li> 5440*72b2703bSAndreas Gohr<p>a</p> 5441*72b2703bSAndreas Gohr</li> 5442*72b2703bSAndreas Gohr<li> 5443*72b2703bSAndreas Gohr<p>b</p> 5444*72b2703bSAndreas Gohr</li> 5445*72b2703bSAndreas Gohr<li> 5446*72b2703bSAndreas Gohr<p>c</p> 5447*72b2703bSAndreas Gohr</li> 5448*72b2703bSAndreas Gohr</ol> 5449*72b2703bSAndreas Gohr```````````````````````````````` 5450*72b2703bSAndreas Gohr 5451*72b2703bSAndreas GohrNote, however, that list items may not be indented more than 5452*72b2703bSAndreas Gohrthree spaces. Here `- e` is treated as a paragraph continuation 5453*72b2703bSAndreas Gohrline, because it is indented more than three spaces: 5454*72b2703bSAndreas Gohr 5455*72b2703bSAndreas Gohr```````````````````````````````` example 5456*72b2703bSAndreas Gohr- a 5457*72b2703bSAndreas Gohr - b 5458*72b2703bSAndreas Gohr - c 5459*72b2703bSAndreas Gohr - d 5460*72b2703bSAndreas Gohr - e 5461*72b2703bSAndreas Gohr. 5462*72b2703bSAndreas Gohr<ul> 5463*72b2703bSAndreas Gohr<li>a</li> 5464*72b2703bSAndreas Gohr<li>b</li> 5465*72b2703bSAndreas Gohr<li>c</li> 5466*72b2703bSAndreas Gohr<li>d 5467*72b2703bSAndreas Gohr- e</li> 5468*72b2703bSAndreas Gohr</ul> 5469*72b2703bSAndreas Gohr```````````````````````````````` 5470*72b2703bSAndreas Gohr 5471*72b2703bSAndreas GohrAnd here, `3. c` is treated as in indented code block, 5472*72b2703bSAndreas Gohrbecause it is indented four spaces and preceded by a 5473*72b2703bSAndreas Gohrblank line. 5474*72b2703bSAndreas Gohr 5475*72b2703bSAndreas Gohr```````````````````````````````` example 5476*72b2703bSAndreas Gohr1. a 5477*72b2703bSAndreas Gohr 5478*72b2703bSAndreas Gohr 2. b 5479*72b2703bSAndreas Gohr 5480*72b2703bSAndreas Gohr 3. c 5481*72b2703bSAndreas Gohr. 5482*72b2703bSAndreas Gohr<ol> 5483*72b2703bSAndreas Gohr<li> 5484*72b2703bSAndreas Gohr<p>a</p> 5485*72b2703bSAndreas Gohr</li> 5486*72b2703bSAndreas Gohr<li> 5487*72b2703bSAndreas Gohr<p>b</p> 5488*72b2703bSAndreas Gohr</li> 5489*72b2703bSAndreas Gohr</ol> 5490*72b2703bSAndreas Gohr<pre><code>3. c 5491*72b2703bSAndreas Gohr</code></pre> 5492*72b2703bSAndreas Gohr```````````````````````````````` 5493*72b2703bSAndreas Gohr 5494*72b2703bSAndreas Gohr 5495*72b2703bSAndreas GohrThis is a loose list, because there is a blank line between 5496*72b2703bSAndreas Gohrtwo of the list items: 5497*72b2703bSAndreas Gohr 5498*72b2703bSAndreas Gohr```````````````````````````````` example 5499*72b2703bSAndreas Gohr- a 5500*72b2703bSAndreas Gohr- b 5501*72b2703bSAndreas Gohr 5502*72b2703bSAndreas Gohr- c 5503*72b2703bSAndreas Gohr. 5504*72b2703bSAndreas Gohr<ul> 5505*72b2703bSAndreas Gohr<li> 5506*72b2703bSAndreas Gohr<p>a</p> 5507*72b2703bSAndreas Gohr</li> 5508*72b2703bSAndreas Gohr<li> 5509*72b2703bSAndreas Gohr<p>b</p> 5510*72b2703bSAndreas Gohr</li> 5511*72b2703bSAndreas Gohr<li> 5512*72b2703bSAndreas Gohr<p>c</p> 5513*72b2703bSAndreas Gohr</li> 5514*72b2703bSAndreas Gohr</ul> 5515*72b2703bSAndreas Gohr```````````````````````````````` 5516*72b2703bSAndreas Gohr 5517*72b2703bSAndreas Gohr 5518*72b2703bSAndreas GohrSo is this, with a empty second item: 5519*72b2703bSAndreas Gohr 5520*72b2703bSAndreas Gohr```````````````````````````````` example 5521*72b2703bSAndreas Gohr* a 5522*72b2703bSAndreas Gohr* 5523*72b2703bSAndreas Gohr 5524*72b2703bSAndreas Gohr* c 5525*72b2703bSAndreas Gohr. 5526*72b2703bSAndreas Gohr<ul> 5527*72b2703bSAndreas Gohr<li> 5528*72b2703bSAndreas Gohr<p>a</p> 5529*72b2703bSAndreas Gohr</li> 5530*72b2703bSAndreas Gohr<li></li> 5531*72b2703bSAndreas Gohr<li> 5532*72b2703bSAndreas Gohr<p>c</p> 5533*72b2703bSAndreas Gohr</li> 5534*72b2703bSAndreas Gohr</ul> 5535*72b2703bSAndreas Gohr```````````````````````````````` 5536*72b2703bSAndreas Gohr 5537*72b2703bSAndreas Gohr 5538*72b2703bSAndreas GohrThese are loose lists, even though there is no space between the items, 5539*72b2703bSAndreas Gohrbecause one of the items directly contains two block-level elements 5540*72b2703bSAndreas Gohrwith a blank line between them: 5541*72b2703bSAndreas Gohr 5542*72b2703bSAndreas Gohr```````````````````````````````` example 5543*72b2703bSAndreas Gohr- a 5544*72b2703bSAndreas Gohr- b 5545*72b2703bSAndreas Gohr 5546*72b2703bSAndreas Gohr c 5547*72b2703bSAndreas Gohr- d 5548*72b2703bSAndreas Gohr. 5549*72b2703bSAndreas Gohr<ul> 5550*72b2703bSAndreas Gohr<li> 5551*72b2703bSAndreas Gohr<p>a</p> 5552*72b2703bSAndreas Gohr</li> 5553*72b2703bSAndreas Gohr<li> 5554*72b2703bSAndreas Gohr<p>b</p> 5555*72b2703bSAndreas Gohr<p>c</p> 5556*72b2703bSAndreas Gohr</li> 5557*72b2703bSAndreas Gohr<li> 5558*72b2703bSAndreas Gohr<p>d</p> 5559*72b2703bSAndreas Gohr</li> 5560*72b2703bSAndreas Gohr</ul> 5561*72b2703bSAndreas Gohr```````````````````````````````` 5562*72b2703bSAndreas Gohr 5563*72b2703bSAndreas Gohr 5564*72b2703bSAndreas Gohr```````````````````````````````` example 5565*72b2703bSAndreas Gohr- a 5566*72b2703bSAndreas Gohr- b 5567*72b2703bSAndreas Gohr 5568*72b2703bSAndreas Gohr [ref]: /url 5569*72b2703bSAndreas Gohr- d 5570*72b2703bSAndreas Gohr. 5571*72b2703bSAndreas Gohr<ul> 5572*72b2703bSAndreas Gohr<li> 5573*72b2703bSAndreas Gohr<p>a</p> 5574*72b2703bSAndreas Gohr</li> 5575*72b2703bSAndreas Gohr<li> 5576*72b2703bSAndreas Gohr<p>b</p> 5577*72b2703bSAndreas Gohr</li> 5578*72b2703bSAndreas Gohr<li> 5579*72b2703bSAndreas Gohr<p>d</p> 5580*72b2703bSAndreas Gohr</li> 5581*72b2703bSAndreas Gohr</ul> 5582*72b2703bSAndreas Gohr```````````````````````````````` 5583*72b2703bSAndreas Gohr 5584*72b2703bSAndreas Gohr 5585*72b2703bSAndreas GohrThis is a tight list, because the blank lines are in a code block: 5586*72b2703bSAndreas Gohr 5587*72b2703bSAndreas Gohr```````````````````````````````` example 5588*72b2703bSAndreas Gohr- a 5589*72b2703bSAndreas Gohr- ``` 5590*72b2703bSAndreas Gohr b 5591*72b2703bSAndreas Gohr 5592*72b2703bSAndreas Gohr 5593*72b2703bSAndreas Gohr ``` 5594*72b2703bSAndreas Gohr- c 5595*72b2703bSAndreas Gohr. 5596*72b2703bSAndreas Gohr<ul> 5597*72b2703bSAndreas Gohr<li>a</li> 5598*72b2703bSAndreas Gohr<li> 5599*72b2703bSAndreas Gohr<pre><code>b 5600*72b2703bSAndreas Gohr 5601*72b2703bSAndreas Gohr 5602*72b2703bSAndreas Gohr</code></pre> 5603*72b2703bSAndreas Gohr</li> 5604*72b2703bSAndreas Gohr<li>c</li> 5605*72b2703bSAndreas Gohr</ul> 5606*72b2703bSAndreas Gohr```````````````````````````````` 5607*72b2703bSAndreas Gohr 5608*72b2703bSAndreas Gohr 5609*72b2703bSAndreas GohrThis is a tight list, because the blank line is between two 5610*72b2703bSAndreas Gohrparagraphs of a sublist. So the sublist is loose while 5611*72b2703bSAndreas Gohrthe outer list is tight: 5612*72b2703bSAndreas Gohr 5613*72b2703bSAndreas Gohr```````````````````````````````` example 5614*72b2703bSAndreas Gohr- a 5615*72b2703bSAndreas Gohr - b 5616*72b2703bSAndreas Gohr 5617*72b2703bSAndreas Gohr c 5618*72b2703bSAndreas Gohr- d 5619*72b2703bSAndreas Gohr. 5620*72b2703bSAndreas Gohr<ul> 5621*72b2703bSAndreas Gohr<li>a 5622*72b2703bSAndreas Gohr<ul> 5623*72b2703bSAndreas Gohr<li> 5624*72b2703bSAndreas Gohr<p>b</p> 5625*72b2703bSAndreas Gohr<p>c</p> 5626*72b2703bSAndreas Gohr</li> 5627*72b2703bSAndreas Gohr</ul> 5628*72b2703bSAndreas Gohr</li> 5629*72b2703bSAndreas Gohr<li>d</li> 5630*72b2703bSAndreas Gohr</ul> 5631*72b2703bSAndreas Gohr```````````````````````````````` 5632*72b2703bSAndreas Gohr 5633*72b2703bSAndreas Gohr 5634*72b2703bSAndreas GohrThis is a tight list, because the blank line is inside the 5635*72b2703bSAndreas Gohrblock quote: 5636*72b2703bSAndreas Gohr 5637*72b2703bSAndreas Gohr```````````````````````````````` example 5638*72b2703bSAndreas Gohr* a 5639*72b2703bSAndreas Gohr > b 5640*72b2703bSAndreas Gohr > 5641*72b2703bSAndreas Gohr* c 5642*72b2703bSAndreas Gohr. 5643*72b2703bSAndreas Gohr<ul> 5644*72b2703bSAndreas Gohr<li>a 5645*72b2703bSAndreas Gohr<blockquote> 5646*72b2703bSAndreas Gohr<p>b</p> 5647*72b2703bSAndreas Gohr</blockquote> 5648*72b2703bSAndreas Gohr</li> 5649*72b2703bSAndreas Gohr<li>c</li> 5650*72b2703bSAndreas Gohr</ul> 5651*72b2703bSAndreas Gohr```````````````````````````````` 5652*72b2703bSAndreas Gohr 5653*72b2703bSAndreas Gohr 5654*72b2703bSAndreas GohrThis list is tight, because the consecutive block elements 5655*72b2703bSAndreas Gohrare not separated by blank lines: 5656*72b2703bSAndreas Gohr 5657*72b2703bSAndreas Gohr```````````````````````````````` example 5658*72b2703bSAndreas Gohr- a 5659*72b2703bSAndreas Gohr > b 5660*72b2703bSAndreas Gohr ``` 5661*72b2703bSAndreas Gohr c 5662*72b2703bSAndreas Gohr ``` 5663*72b2703bSAndreas Gohr- d 5664*72b2703bSAndreas Gohr. 5665*72b2703bSAndreas Gohr<ul> 5666*72b2703bSAndreas Gohr<li>a 5667*72b2703bSAndreas Gohr<blockquote> 5668*72b2703bSAndreas Gohr<p>b</p> 5669*72b2703bSAndreas Gohr</blockquote> 5670*72b2703bSAndreas Gohr<pre><code>c 5671*72b2703bSAndreas Gohr</code></pre> 5672*72b2703bSAndreas Gohr</li> 5673*72b2703bSAndreas Gohr<li>d</li> 5674*72b2703bSAndreas Gohr</ul> 5675*72b2703bSAndreas Gohr```````````````````````````````` 5676*72b2703bSAndreas Gohr 5677*72b2703bSAndreas Gohr 5678*72b2703bSAndreas GohrA single-paragraph list is tight: 5679*72b2703bSAndreas Gohr 5680*72b2703bSAndreas Gohr```````````````````````````````` example 5681*72b2703bSAndreas Gohr- a 5682*72b2703bSAndreas Gohr. 5683*72b2703bSAndreas Gohr<ul> 5684*72b2703bSAndreas Gohr<li>a</li> 5685*72b2703bSAndreas Gohr</ul> 5686*72b2703bSAndreas Gohr```````````````````````````````` 5687*72b2703bSAndreas Gohr 5688*72b2703bSAndreas Gohr 5689*72b2703bSAndreas Gohr```````````````````````````````` example 5690*72b2703bSAndreas Gohr- a 5691*72b2703bSAndreas Gohr - b 5692*72b2703bSAndreas Gohr. 5693*72b2703bSAndreas Gohr<ul> 5694*72b2703bSAndreas Gohr<li>a 5695*72b2703bSAndreas Gohr<ul> 5696*72b2703bSAndreas Gohr<li>b</li> 5697*72b2703bSAndreas Gohr</ul> 5698*72b2703bSAndreas Gohr</li> 5699*72b2703bSAndreas Gohr</ul> 5700*72b2703bSAndreas Gohr```````````````````````````````` 5701*72b2703bSAndreas Gohr 5702*72b2703bSAndreas Gohr 5703*72b2703bSAndreas GohrThis list is loose, because of the blank line between the 5704*72b2703bSAndreas Gohrtwo block elements in the list item: 5705*72b2703bSAndreas Gohr 5706*72b2703bSAndreas Gohr```````````````````````````````` example 5707*72b2703bSAndreas Gohr1. ``` 5708*72b2703bSAndreas Gohr foo 5709*72b2703bSAndreas Gohr ``` 5710*72b2703bSAndreas Gohr 5711*72b2703bSAndreas Gohr bar 5712*72b2703bSAndreas Gohr. 5713*72b2703bSAndreas Gohr<ol> 5714*72b2703bSAndreas Gohr<li> 5715*72b2703bSAndreas Gohr<pre><code>foo 5716*72b2703bSAndreas Gohr</code></pre> 5717*72b2703bSAndreas Gohr<p>bar</p> 5718*72b2703bSAndreas Gohr</li> 5719*72b2703bSAndreas Gohr</ol> 5720*72b2703bSAndreas Gohr```````````````````````````````` 5721*72b2703bSAndreas Gohr 5722*72b2703bSAndreas Gohr 5723*72b2703bSAndreas GohrHere the outer list is loose, the inner list tight: 5724*72b2703bSAndreas Gohr 5725*72b2703bSAndreas Gohr```````````````````````````````` example 5726*72b2703bSAndreas Gohr* foo 5727*72b2703bSAndreas Gohr * bar 5728*72b2703bSAndreas Gohr 5729*72b2703bSAndreas Gohr baz 5730*72b2703bSAndreas Gohr. 5731*72b2703bSAndreas Gohr<ul> 5732*72b2703bSAndreas Gohr<li> 5733*72b2703bSAndreas Gohr<p>foo</p> 5734*72b2703bSAndreas Gohr<ul> 5735*72b2703bSAndreas Gohr<li>bar</li> 5736*72b2703bSAndreas Gohr</ul> 5737*72b2703bSAndreas Gohr<p>baz</p> 5738*72b2703bSAndreas Gohr</li> 5739*72b2703bSAndreas Gohr</ul> 5740*72b2703bSAndreas Gohr```````````````````````````````` 5741*72b2703bSAndreas Gohr 5742*72b2703bSAndreas Gohr 5743*72b2703bSAndreas Gohr```````````````````````````````` example 5744*72b2703bSAndreas Gohr- a 5745*72b2703bSAndreas Gohr - b 5746*72b2703bSAndreas Gohr - c 5747*72b2703bSAndreas Gohr 5748*72b2703bSAndreas Gohr- d 5749*72b2703bSAndreas Gohr - e 5750*72b2703bSAndreas Gohr - f 5751*72b2703bSAndreas Gohr. 5752*72b2703bSAndreas Gohr<ul> 5753*72b2703bSAndreas Gohr<li> 5754*72b2703bSAndreas Gohr<p>a</p> 5755*72b2703bSAndreas Gohr<ul> 5756*72b2703bSAndreas Gohr<li>b</li> 5757*72b2703bSAndreas Gohr<li>c</li> 5758*72b2703bSAndreas Gohr</ul> 5759*72b2703bSAndreas Gohr</li> 5760*72b2703bSAndreas Gohr<li> 5761*72b2703bSAndreas Gohr<p>d</p> 5762*72b2703bSAndreas Gohr<ul> 5763*72b2703bSAndreas Gohr<li>e</li> 5764*72b2703bSAndreas Gohr<li>f</li> 5765*72b2703bSAndreas Gohr</ul> 5766*72b2703bSAndreas Gohr</li> 5767*72b2703bSAndreas Gohr</ul> 5768*72b2703bSAndreas Gohr```````````````````````````````` 5769*72b2703bSAndreas Gohr 5770*72b2703bSAndreas Gohr 5771*72b2703bSAndreas Gohr# Inlines 5772*72b2703bSAndreas Gohr 5773*72b2703bSAndreas GohrInlines are parsed sequentially from the beginning of the character 5774*72b2703bSAndreas Gohrstream to the end (left to right, in left-to-right languages). 5775*72b2703bSAndreas GohrThus, for example, in 5776*72b2703bSAndreas Gohr 5777*72b2703bSAndreas Gohr```````````````````````````````` example 5778*72b2703bSAndreas Gohr`hi`lo` 5779*72b2703bSAndreas Gohr. 5780*72b2703bSAndreas Gohr<p><code>hi</code>lo`</p> 5781*72b2703bSAndreas Gohr```````````````````````````````` 5782*72b2703bSAndreas Gohr 5783*72b2703bSAndreas Gohr`hi` is parsed as code, leaving the backtick at the end as a literal 5784*72b2703bSAndreas Gohrbacktick. 5785*72b2703bSAndreas Gohr 5786*72b2703bSAndreas Gohr 5787*72b2703bSAndreas Gohr## Backslash escapes 5788*72b2703bSAndreas Gohr 5789*72b2703bSAndreas GohrAny ASCII punctuation character may be backslash-escaped: 5790*72b2703bSAndreas Gohr 5791*72b2703bSAndreas Gohr```````````````````````````````` example 5792*72b2703bSAndreas Gohr\!\"\#\$\%\&\'\(\)\*\+\,\-\.\/\:\;\<\=\>\?\@\[\\\]\^\_\`\{\|\}\~ 5793*72b2703bSAndreas Gohr. 5794*72b2703bSAndreas Gohr<p>!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~</p> 5795*72b2703bSAndreas Gohr```````````````````````````````` 5796*72b2703bSAndreas Gohr 5797*72b2703bSAndreas Gohr 5798*72b2703bSAndreas GohrBackslashes before other characters are treated as literal 5799*72b2703bSAndreas Gohrbackslashes: 5800*72b2703bSAndreas Gohr 5801*72b2703bSAndreas Gohr```````````````````````````````` example 5802*72b2703bSAndreas Gohr\→\A\a\ \3\φ\« 5803*72b2703bSAndreas Gohr. 5804*72b2703bSAndreas Gohr<p>\→\A\a\ \3\φ\«</p> 5805*72b2703bSAndreas Gohr```````````````````````````````` 5806*72b2703bSAndreas Gohr 5807*72b2703bSAndreas Gohr 5808*72b2703bSAndreas GohrEscaped characters are treated as regular characters and do 5809*72b2703bSAndreas Gohrnot have their usual Markdown meanings: 5810*72b2703bSAndreas Gohr 5811*72b2703bSAndreas Gohr```````````````````````````````` example 5812*72b2703bSAndreas Gohr\*not emphasized* 5813*72b2703bSAndreas Gohr\<br/> not a tag 5814*72b2703bSAndreas Gohr\[not a link](/foo) 5815*72b2703bSAndreas Gohr\`not code` 5816*72b2703bSAndreas Gohr1\. not a list 5817*72b2703bSAndreas Gohr\* not a list 5818*72b2703bSAndreas Gohr\# not a heading 5819*72b2703bSAndreas Gohr\[foo]: /url "not a reference" 5820*72b2703bSAndreas Gohr\ö not a character entity 5821*72b2703bSAndreas Gohr. 5822*72b2703bSAndreas Gohr<p>*not emphasized* 5823*72b2703bSAndreas Gohr<br/> not a tag 5824*72b2703bSAndreas Gohr[not a link](/foo) 5825*72b2703bSAndreas Gohr`not code` 5826*72b2703bSAndreas Gohr1. not a list 5827*72b2703bSAndreas Gohr* not a list 5828*72b2703bSAndreas Gohr# not a heading 5829*72b2703bSAndreas Gohr[foo]: /url "not a reference" 5830*72b2703bSAndreas Gohr&ouml; not a character entity</p> 5831*72b2703bSAndreas Gohr```````````````````````````````` 5832*72b2703bSAndreas Gohr 5833*72b2703bSAndreas Gohr 5834*72b2703bSAndreas GohrIf a backslash is itself escaped, the following character is not: 5835*72b2703bSAndreas Gohr 5836*72b2703bSAndreas Gohr```````````````````````````````` example 5837*72b2703bSAndreas Gohr\\*emphasis* 5838*72b2703bSAndreas Gohr. 5839*72b2703bSAndreas Gohr<p>\<em>emphasis</em></p> 5840*72b2703bSAndreas Gohr```````````````````````````````` 5841*72b2703bSAndreas Gohr 5842*72b2703bSAndreas Gohr 5843*72b2703bSAndreas GohrA backslash at the end of the line is a [hard line break]: 5844*72b2703bSAndreas Gohr 5845*72b2703bSAndreas Gohr```````````````````````````````` example 5846*72b2703bSAndreas Gohrfoo\ 5847*72b2703bSAndreas Gohrbar 5848*72b2703bSAndreas Gohr. 5849*72b2703bSAndreas Gohr<p>foo<br /> 5850*72b2703bSAndreas Gohrbar</p> 5851*72b2703bSAndreas Gohr```````````````````````````````` 5852*72b2703bSAndreas Gohr 5853*72b2703bSAndreas Gohr 5854*72b2703bSAndreas GohrBackslash escapes do not work in code blocks, code spans, autolinks, or 5855*72b2703bSAndreas Gohrraw HTML: 5856*72b2703bSAndreas Gohr 5857*72b2703bSAndreas Gohr```````````````````````````````` example 5858*72b2703bSAndreas Gohr`` \[\` `` 5859*72b2703bSAndreas Gohr. 5860*72b2703bSAndreas Gohr<p><code>\[\`</code></p> 5861*72b2703bSAndreas Gohr```````````````````````````````` 5862*72b2703bSAndreas Gohr 5863*72b2703bSAndreas Gohr 5864*72b2703bSAndreas Gohr```````````````````````````````` example 5865*72b2703bSAndreas Gohr \[\] 5866*72b2703bSAndreas Gohr. 5867*72b2703bSAndreas Gohr<pre><code>\[\] 5868*72b2703bSAndreas Gohr</code></pre> 5869*72b2703bSAndreas Gohr```````````````````````````````` 5870*72b2703bSAndreas Gohr 5871*72b2703bSAndreas Gohr 5872*72b2703bSAndreas Gohr```````````````````````````````` example 5873*72b2703bSAndreas Gohr~~~ 5874*72b2703bSAndreas Gohr\[\] 5875*72b2703bSAndreas Gohr~~~ 5876*72b2703bSAndreas Gohr. 5877*72b2703bSAndreas Gohr<pre><code>\[\] 5878*72b2703bSAndreas Gohr</code></pre> 5879*72b2703bSAndreas Gohr```````````````````````````````` 5880*72b2703bSAndreas Gohr 5881*72b2703bSAndreas Gohr 5882*72b2703bSAndreas Gohr```````````````````````````````` example 5883*72b2703bSAndreas Gohr<http://example.com?find=\*> 5884*72b2703bSAndreas Gohr. 5885*72b2703bSAndreas Gohr<p><a href="http://example.com?find=%5C*">http://example.com?find=\*</a></p> 5886*72b2703bSAndreas Gohr```````````````````````````````` 5887*72b2703bSAndreas Gohr 5888*72b2703bSAndreas Gohr 5889*72b2703bSAndreas Gohr```````````````````````````````` example 5890*72b2703bSAndreas Gohr<a href="/bar\/)"> 5891*72b2703bSAndreas Gohr. 5892*72b2703bSAndreas Gohr<a href="/bar\/)"> 5893*72b2703bSAndreas Gohr```````````````````````````````` 5894*72b2703bSAndreas Gohr 5895*72b2703bSAndreas Gohr 5896*72b2703bSAndreas GohrBut they work in all other contexts, including URLs and link titles, 5897*72b2703bSAndreas Gohrlink references, and [info strings] in [fenced code blocks]: 5898*72b2703bSAndreas Gohr 5899*72b2703bSAndreas Gohr```````````````````````````````` example 5900*72b2703bSAndreas Gohr[foo](/bar\* "ti\*tle") 5901*72b2703bSAndreas Gohr. 5902*72b2703bSAndreas Gohr<p><a href="/bar*" title="ti*tle">foo</a></p> 5903*72b2703bSAndreas Gohr```````````````````````````````` 5904*72b2703bSAndreas Gohr 5905*72b2703bSAndreas Gohr 5906*72b2703bSAndreas Gohr```````````````````````````````` example 5907*72b2703bSAndreas Gohr[foo] 5908*72b2703bSAndreas Gohr 5909*72b2703bSAndreas Gohr[foo]: /bar\* "ti\*tle" 5910*72b2703bSAndreas Gohr. 5911*72b2703bSAndreas Gohr<p><a href="/bar*" title="ti*tle">foo</a></p> 5912*72b2703bSAndreas Gohr```````````````````````````````` 5913*72b2703bSAndreas Gohr 5914*72b2703bSAndreas Gohr 5915*72b2703bSAndreas Gohr```````````````````````````````` example 5916*72b2703bSAndreas Gohr``` foo\+bar 5917*72b2703bSAndreas Gohrfoo 5918*72b2703bSAndreas Gohr``` 5919*72b2703bSAndreas Gohr. 5920*72b2703bSAndreas Gohr<pre><code class="language-foo+bar">foo 5921*72b2703bSAndreas Gohr</code></pre> 5922*72b2703bSAndreas Gohr```````````````````````````````` 5923*72b2703bSAndreas Gohr 5924*72b2703bSAndreas Gohr 5925*72b2703bSAndreas Gohr 5926*72b2703bSAndreas Gohr## Entity and numeric character references 5927*72b2703bSAndreas Gohr 5928*72b2703bSAndreas GohrValid HTML entity references and numeric character references 5929*72b2703bSAndreas Gohrcan be used in place of the corresponding Unicode character, 5930*72b2703bSAndreas Gohrwith the following exceptions: 5931*72b2703bSAndreas Gohr 5932*72b2703bSAndreas Gohr- Entity and character references are not recognized in code 5933*72b2703bSAndreas Gohr blocks and code spans. 5934*72b2703bSAndreas Gohr 5935*72b2703bSAndreas Gohr- Entity and character references cannot stand in place of 5936*72b2703bSAndreas Gohr special characters that define structural elements in 5937*72b2703bSAndreas Gohr CommonMark. For example, although `*` can be used 5938*72b2703bSAndreas Gohr in place of a literal `*` character, `*` cannot replace 5939*72b2703bSAndreas Gohr `*` in emphasis delimiters, bullet list markers, or thematic 5940*72b2703bSAndreas Gohr breaks. 5941*72b2703bSAndreas Gohr 5942*72b2703bSAndreas GohrConforming CommonMark parsers need not store information about 5943*72b2703bSAndreas Gohrwhether a particular character was represented in the source 5944*72b2703bSAndreas Gohrusing a Unicode character or an entity reference. 5945*72b2703bSAndreas Gohr 5946*72b2703bSAndreas Gohr[Entity references](@) consist of `&` + any of the valid 5947*72b2703bSAndreas GohrHTML5 entity names + `;`. The 5948*72b2703bSAndreas Gohrdocument <https://html.spec.whatwg.org/multipage/entities.json> 5949*72b2703bSAndreas Gohris used as an authoritative source for the valid entity 5950*72b2703bSAndreas Gohrreferences and their corresponding code points. 5951*72b2703bSAndreas Gohr 5952*72b2703bSAndreas Gohr```````````````````````````````` example 5953*72b2703bSAndreas Gohr & © Æ Ď 5954*72b2703bSAndreas Gohr¾ ℋ ⅆ 5955*72b2703bSAndreas Gohr∲ ≧̸ 5956*72b2703bSAndreas Gohr. 5957*72b2703bSAndreas Gohr<p> & © Æ Ď 5958*72b2703bSAndreas Gohr¾ ℋ ⅆ 5959*72b2703bSAndreas Gohr∲ ≧̸</p> 5960*72b2703bSAndreas Gohr```````````````````````````````` 5961*72b2703bSAndreas Gohr 5962*72b2703bSAndreas Gohr 5963*72b2703bSAndreas Gohr[Decimal numeric character 5964*72b2703bSAndreas Gohrreferences](@) 5965*72b2703bSAndreas Gohrconsist of `&#` + a string of 1--7 arabic digits + `;`. A 5966*72b2703bSAndreas Gohrnumeric character reference is parsed as the corresponding 5967*72b2703bSAndreas GohrUnicode character. Invalid Unicode code points will be replaced by 5968*72b2703bSAndreas Gohrthe REPLACEMENT CHARACTER (`U+FFFD`). For security reasons, 5969*72b2703bSAndreas Gohrthe code point `U+0000` will also be replaced by `U+FFFD`. 5970*72b2703bSAndreas Gohr 5971*72b2703bSAndreas Gohr```````````````````````````````` example 5972*72b2703bSAndreas Gohr# Ӓ Ϡ � 5973*72b2703bSAndreas Gohr. 5974*72b2703bSAndreas Gohr<p># Ӓ Ϡ �</p> 5975*72b2703bSAndreas Gohr```````````````````````````````` 5976*72b2703bSAndreas Gohr 5977*72b2703bSAndreas Gohr 5978*72b2703bSAndreas Gohr[Hexadecimal numeric character 5979*72b2703bSAndreas Gohrreferences](@) consist of `&#` + 5980*72b2703bSAndreas Gohreither `X` or `x` + a string of 1-6 hexadecimal digits + `;`. 5981*72b2703bSAndreas GohrThey too are parsed as the corresponding Unicode character (this 5982*72b2703bSAndreas Gohrtime specified with a hexadecimal numeral instead of decimal). 5983*72b2703bSAndreas Gohr 5984*72b2703bSAndreas Gohr```````````````````````````````` example 5985*72b2703bSAndreas Gohr" ആ ಫ 5986*72b2703bSAndreas Gohr. 5987*72b2703bSAndreas Gohr<p>" ആ ಫ</p> 5988*72b2703bSAndreas Gohr```````````````````````````````` 5989*72b2703bSAndreas Gohr 5990*72b2703bSAndreas Gohr 5991*72b2703bSAndreas GohrHere are some nonentities: 5992*72b2703bSAndreas Gohr 5993*72b2703bSAndreas Gohr```````````````````````````````` example 5994*72b2703bSAndreas Gohr  &x; &#; &#x; 5995*72b2703bSAndreas Gohr� 5996*72b2703bSAndreas Gohr&#abcdef0; 5997*72b2703bSAndreas Gohr&ThisIsNotDefined; &hi?; 5998*72b2703bSAndreas Gohr. 5999*72b2703bSAndreas Gohr<p>&nbsp &x; &#; &#x; 6000*72b2703bSAndreas Gohr&#987654321; 6001*72b2703bSAndreas Gohr&#abcdef0; 6002*72b2703bSAndreas Gohr&ThisIsNotDefined; &hi?;</p> 6003*72b2703bSAndreas Gohr```````````````````````````````` 6004*72b2703bSAndreas Gohr 6005*72b2703bSAndreas Gohr 6006*72b2703bSAndreas GohrAlthough HTML5 does accept some entity references 6007*72b2703bSAndreas Gohrwithout a trailing semicolon (such as `©`), these are not 6008*72b2703bSAndreas Gohrrecognized here, because it makes the grammar too ambiguous: 6009*72b2703bSAndreas Gohr 6010*72b2703bSAndreas Gohr```````````````````````````````` example 6011*72b2703bSAndreas Gohr© 6012*72b2703bSAndreas Gohr. 6013*72b2703bSAndreas Gohr<p>&copy</p> 6014*72b2703bSAndreas Gohr```````````````````````````````` 6015*72b2703bSAndreas Gohr 6016*72b2703bSAndreas Gohr 6017*72b2703bSAndreas GohrStrings that are not on the list of HTML5 named entities are not 6018*72b2703bSAndreas Gohrrecognized as entity references either: 6019*72b2703bSAndreas Gohr 6020*72b2703bSAndreas Gohr```````````````````````````````` example 6021*72b2703bSAndreas Gohr&MadeUpEntity; 6022*72b2703bSAndreas Gohr. 6023*72b2703bSAndreas Gohr<p>&MadeUpEntity;</p> 6024*72b2703bSAndreas Gohr```````````````````````````````` 6025*72b2703bSAndreas Gohr 6026*72b2703bSAndreas Gohr 6027*72b2703bSAndreas GohrEntity and numeric character references are recognized in any 6028*72b2703bSAndreas Gohrcontext besides code spans or code blocks, including 6029*72b2703bSAndreas GohrURLs, [link titles], and [fenced code block][] [info strings]: 6030*72b2703bSAndreas Gohr 6031*72b2703bSAndreas Gohr```````````````````````````````` example 6032*72b2703bSAndreas Gohr<a href="öö.html"> 6033*72b2703bSAndreas Gohr. 6034*72b2703bSAndreas Gohr<a href="öö.html"> 6035*72b2703bSAndreas Gohr```````````````````````````````` 6036*72b2703bSAndreas Gohr 6037*72b2703bSAndreas Gohr 6038*72b2703bSAndreas Gohr```````````````````````````````` example 6039*72b2703bSAndreas Gohr[foo](/föö "föö") 6040*72b2703bSAndreas Gohr. 6041*72b2703bSAndreas Gohr<p><a href="/f%C3%B6%C3%B6" title="föö">foo</a></p> 6042*72b2703bSAndreas Gohr```````````````````````````````` 6043*72b2703bSAndreas Gohr 6044*72b2703bSAndreas Gohr 6045*72b2703bSAndreas Gohr```````````````````````````````` example 6046*72b2703bSAndreas Gohr[foo] 6047*72b2703bSAndreas Gohr 6048*72b2703bSAndreas Gohr[foo]: /föö "föö" 6049*72b2703bSAndreas Gohr. 6050*72b2703bSAndreas Gohr<p><a href="/f%C3%B6%C3%B6" title="föö">foo</a></p> 6051*72b2703bSAndreas Gohr```````````````````````````````` 6052*72b2703bSAndreas Gohr 6053*72b2703bSAndreas Gohr 6054*72b2703bSAndreas Gohr```````````````````````````````` example 6055*72b2703bSAndreas Gohr``` föö 6056*72b2703bSAndreas Gohrfoo 6057*72b2703bSAndreas Gohr``` 6058*72b2703bSAndreas Gohr. 6059*72b2703bSAndreas Gohr<pre><code class="language-föö">foo 6060*72b2703bSAndreas Gohr</code></pre> 6061*72b2703bSAndreas Gohr```````````````````````````````` 6062*72b2703bSAndreas Gohr 6063*72b2703bSAndreas Gohr 6064*72b2703bSAndreas GohrEntity and numeric character references are treated as literal 6065*72b2703bSAndreas Gohrtext in code spans and code blocks: 6066*72b2703bSAndreas Gohr 6067*72b2703bSAndreas Gohr```````````````````````````````` example 6068*72b2703bSAndreas Gohr`föö` 6069*72b2703bSAndreas Gohr. 6070*72b2703bSAndreas Gohr<p><code>f&ouml;&ouml;</code></p> 6071*72b2703bSAndreas Gohr```````````````````````````````` 6072*72b2703bSAndreas Gohr 6073*72b2703bSAndreas Gohr 6074*72b2703bSAndreas Gohr```````````````````````````````` example 6075*72b2703bSAndreas Gohr föfö 6076*72b2703bSAndreas Gohr. 6077*72b2703bSAndreas Gohr<pre><code>f&ouml;f&ouml; 6078*72b2703bSAndreas Gohr</code></pre> 6079*72b2703bSAndreas Gohr```````````````````````````````` 6080*72b2703bSAndreas Gohr 6081*72b2703bSAndreas Gohr 6082*72b2703bSAndreas GohrEntity and numeric character references cannot be used 6083*72b2703bSAndreas Gohrin place of symbols indicating structure in CommonMark 6084*72b2703bSAndreas Gohrdocuments. 6085*72b2703bSAndreas Gohr 6086*72b2703bSAndreas Gohr```````````````````````````````` example 6087*72b2703bSAndreas Gohr*foo* 6088*72b2703bSAndreas Gohr*foo* 6089*72b2703bSAndreas Gohr. 6090*72b2703bSAndreas Gohr<p>*foo* 6091*72b2703bSAndreas Gohr<em>foo</em></p> 6092*72b2703bSAndreas Gohr```````````````````````````````` 6093*72b2703bSAndreas Gohr 6094*72b2703bSAndreas Gohr```````````````````````````````` example 6095*72b2703bSAndreas Gohr* foo 6096*72b2703bSAndreas Gohr 6097*72b2703bSAndreas Gohr* foo 6098*72b2703bSAndreas Gohr. 6099*72b2703bSAndreas Gohr<p>* foo</p> 6100*72b2703bSAndreas Gohr<ul> 6101*72b2703bSAndreas Gohr<li>foo</li> 6102*72b2703bSAndreas Gohr</ul> 6103*72b2703bSAndreas Gohr```````````````````````````````` 6104*72b2703bSAndreas Gohr 6105*72b2703bSAndreas Gohr```````````````````````````````` example 6106*72b2703bSAndreas Gohrfoo bar 6107*72b2703bSAndreas Gohr. 6108*72b2703bSAndreas Gohr<p>foo 6109*72b2703bSAndreas Gohr 6110*72b2703bSAndreas Gohrbar</p> 6111*72b2703bSAndreas Gohr```````````````````````````````` 6112*72b2703bSAndreas Gohr 6113*72b2703bSAndreas Gohr```````````````````````````````` example 6114*72b2703bSAndreas Gohr	foo 6115*72b2703bSAndreas Gohr. 6116*72b2703bSAndreas Gohr<p>→foo</p> 6117*72b2703bSAndreas Gohr```````````````````````````````` 6118*72b2703bSAndreas Gohr 6119*72b2703bSAndreas Gohr 6120*72b2703bSAndreas Gohr```````````````````````````````` example 6121*72b2703bSAndreas Gohr[a](url "tit") 6122*72b2703bSAndreas Gohr. 6123*72b2703bSAndreas Gohr<p>[a](url "tit")</p> 6124*72b2703bSAndreas Gohr```````````````````````````````` 6125*72b2703bSAndreas Gohr 6126*72b2703bSAndreas Gohr 6127*72b2703bSAndreas Gohr## Code spans 6128*72b2703bSAndreas Gohr 6129*72b2703bSAndreas GohrA [backtick string](@) 6130*72b2703bSAndreas Gohris a string of one or more backtick characters (`` ` ``) that is neither 6131*72b2703bSAndreas Gohrpreceded nor followed by a backtick. 6132*72b2703bSAndreas Gohr 6133*72b2703bSAndreas GohrA [code span](@) begins with a backtick string and ends with 6134*72b2703bSAndreas Gohra backtick string of equal length. The contents of the code span are 6135*72b2703bSAndreas Gohrthe characters between the two backtick strings, normalized in the 6136*72b2703bSAndreas Gohrfollowing ways: 6137*72b2703bSAndreas Gohr 6138*72b2703bSAndreas Gohr- First, [line endings] are converted to [spaces]. 6139*72b2703bSAndreas Gohr- If the resulting string both begins *and* ends with a [space] 6140*72b2703bSAndreas Gohr character, but does not consist entirely of [space] 6141*72b2703bSAndreas Gohr characters, a single [space] character is removed from the 6142*72b2703bSAndreas Gohr front and back. This allows you to include code that begins 6143*72b2703bSAndreas Gohr or ends with backtick characters, which must be separated by 6144*72b2703bSAndreas Gohr whitespace from the opening or closing backtick strings. 6145*72b2703bSAndreas Gohr 6146*72b2703bSAndreas GohrThis is a simple code span: 6147*72b2703bSAndreas Gohr 6148*72b2703bSAndreas Gohr```````````````````````````````` example 6149*72b2703bSAndreas Gohr`foo` 6150*72b2703bSAndreas Gohr. 6151*72b2703bSAndreas Gohr<p><code>foo</code></p> 6152*72b2703bSAndreas Gohr```````````````````````````````` 6153*72b2703bSAndreas Gohr 6154*72b2703bSAndreas Gohr 6155*72b2703bSAndreas GohrHere two backticks are used, because the code contains a backtick. 6156*72b2703bSAndreas GohrThis example also illustrates stripping of a single leading and 6157*72b2703bSAndreas Gohrtrailing space: 6158*72b2703bSAndreas Gohr 6159*72b2703bSAndreas Gohr```````````````````````````````` example 6160*72b2703bSAndreas Gohr`` foo ` bar `` 6161*72b2703bSAndreas Gohr. 6162*72b2703bSAndreas Gohr<p><code>foo ` bar</code></p> 6163*72b2703bSAndreas Gohr```````````````````````````````` 6164*72b2703bSAndreas Gohr 6165*72b2703bSAndreas Gohr 6166*72b2703bSAndreas GohrThis example shows the motivation for stripping leading and trailing 6167*72b2703bSAndreas Gohrspaces: 6168*72b2703bSAndreas Gohr 6169*72b2703bSAndreas Gohr```````````````````````````````` example 6170*72b2703bSAndreas Gohr` `` ` 6171*72b2703bSAndreas Gohr. 6172*72b2703bSAndreas Gohr<p><code>``</code></p> 6173*72b2703bSAndreas Gohr```````````````````````````````` 6174*72b2703bSAndreas Gohr 6175*72b2703bSAndreas GohrNote that only *one* space is stripped: 6176*72b2703bSAndreas Gohr 6177*72b2703bSAndreas Gohr```````````````````````````````` example 6178*72b2703bSAndreas Gohr` `` ` 6179*72b2703bSAndreas Gohr. 6180*72b2703bSAndreas Gohr<p><code> `` </code></p> 6181*72b2703bSAndreas Gohr```````````````````````````````` 6182*72b2703bSAndreas Gohr 6183*72b2703bSAndreas GohrThe stripping only happens if the space is on both 6184*72b2703bSAndreas Gohrsides of the string: 6185*72b2703bSAndreas Gohr 6186*72b2703bSAndreas Gohr```````````````````````````````` example 6187*72b2703bSAndreas Gohr` a` 6188*72b2703bSAndreas Gohr. 6189*72b2703bSAndreas Gohr<p><code> a</code></p> 6190*72b2703bSAndreas Gohr```````````````````````````````` 6191*72b2703bSAndreas Gohr 6192*72b2703bSAndreas GohrOnly [spaces], and not [unicode whitespace] in general, are 6193*72b2703bSAndreas Gohrstripped in this way: 6194*72b2703bSAndreas Gohr 6195*72b2703bSAndreas Gohr```````````````````````````````` example 6196*72b2703bSAndreas Gohr` b ` 6197*72b2703bSAndreas Gohr. 6198*72b2703bSAndreas Gohr<p><code> b </code></p> 6199*72b2703bSAndreas Gohr```````````````````````````````` 6200*72b2703bSAndreas Gohr 6201*72b2703bSAndreas GohrNo stripping occurs if the code span contains only spaces: 6202*72b2703bSAndreas Gohr 6203*72b2703bSAndreas Gohr```````````````````````````````` example 6204*72b2703bSAndreas Gohr` ` 6205*72b2703bSAndreas Gohr` ` 6206*72b2703bSAndreas Gohr. 6207*72b2703bSAndreas Gohr<p><code> </code> 6208*72b2703bSAndreas Gohr<code> </code></p> 6209*72b2703bSAndreas Gohr```````````````````````````````` 6210*72b2703bSAndreas Gohr 6211*72b2703bSAndreas Gohr 6212*72b2703bSAndreas Gohr[Line endings] are treated like spaces: 6213*72b2703bSAndreas Gohr 6214*72b2703bSAndreas Gohr```````````````````````````````` example 6215*72b2703bSAndreas Gohr`` 6216*72b2703bSAndreas Gohrfoo 6217*72b2703bSAndreas Gohrbar 6218*72b2703bSAndreas Gohrbaz 6219*72b2703bSAndreas Gohr`` 6220*72b2703bSAndreas Gohr. 6221*72b2703bSAndreas Gohr<p><code>foo bar baz</code></p> 6222*72b2703bSAndreas Gohr```````````````````````````````` 6223*72b2703bSAndreas Gohr 6224*72b2703bSAndreas Gohr```````````````````````````````` example 6225*72b2703bSAndreas Gohr`` 6226*72b2703bSAndreas Gohrfoo 6227*72b2703bSAndreas Gohr`` 6228*72b2703bSAndreas Gohr. 6229*72b2703bSAndreas Gohr<p><code>foo </code></p> 6230*72b2703bSAndreas Gohr```````````````````````````````` 6231*72b2703bSAndreas Gohr 6232*72b2703bSAndreas Gohr 6233*72b2703bSAndreas GohrInterior spaces are not collapsed: 6234*72b2703bSAndreas Gohr 6235*72b2703bSAndreas Gohr```````````````````````````````` example 6236*72b2703bSAndreas Gohr`foo bar 6237*72b2703bSAndreas Gohrbaz` 6238*72b2703bSAndreas Gohr. 6239*72b2703bSAndreas Gohr<p><code>foo bar baz</code></p> 6240*72b2703bSAndreas Gohr```````````````````````````````` 6241*72b2703bSAndreas Gohr 6242*72b2703bSAndreas GohrNote that browsers will typically collapse consecutive spaces 6243*72b2703bSAndreas Gohrwhen rendering `<code>` elements, so it is recommended that 6244*72b2703bSAndreas Gohrthe following CSS be used: 6245*72b2703bSAndreas Gohr 6246*72b2703bSAndreas Gohr code{white-space: pre-wrap;} 6247*72b2703bSAndreas Gohr 6248*72b2703bSAndreas Gohr 6249*72b2703bSAndreas GohrNote that backslash escapes do not work in code spans. All backslashes 6250*72b2703bSAndreas Gohrare treated literally: 6251*72b2703bSAndreas Gohr 6252*72b2703bSAndreas Gohr```````````````````````````````` example 6253*72b2703bSAndreas Gohr`foo\`bar` 6254*72b2703bSAndreas Gohr. 6255*72b2703bSAndreas Gohr<p><code>foo\</code>bar`</p> 6256*72b2703bSAndreas Gohr```````````````````````````````` 6257*72b2703bSAndreas Gohr 6258*72b2703bSAndreas Gohr 6259*72b2703bSAndreas GohrBackslash escapes are never needed, because one can always choose a 6260*72b2703bSAndreas Gohrstring of *n* backtick characters as delimiters, where the code does 6261*72b2703bSAndreas Gohrnot contain any strings of exactly *n* backtick characters. 6262*72b2703bSAndreas Gohr 6263*72b2703bSAndreas Gohr```````````````````````````````` example 6264*72b2703bSAndreas Gohr``foo`bar`` 6265*72b2703bSAndreas Gohr. 6266*72b2703bSAndreas Gohr<p><code>foo`bar</code></p> 6267*72b2703bSAndreas Gohr```````````````````````````````` 6268*72b2703bSAndreas Gohr 6269*72b2703bSAndreas Gohr```````````````````````````````` example 6270*72b2703bSAndreas Gohr` foo `` bar ` 6271*72b2703bSAndreas Gohr. 6272*72b2703bSAndreas Gohr<p><code>foo `` bar</code></p> 6273*72b2703bSAndreas Gohr```````````````````````````````` 6274*72b2703bSAndreas Gohr 6275*72b2703bSAndreas Gohr 6276*72b2703bSAndreas GohrCode span backticks have higher precedence than any other inline 6277*72b2703bSAndreas Gohrconstructs except HTML tags and autolinks. Thus, for example, this is 6278*72b2703bSAndreas Gohrnot parsed as emphasized text, since the second `*` is part of a code 6279*72b2703bSAndreas Gohrspan: 6280*72b2703bSAndreas Gohr 6281*72b2703bSAndreas Gohr```````````````````````````````` example 6282*72b2703bSAndreas Gohr*foo`*` 6283*72b2703bSAndreas Gohr. 6284*72b2703bSAndreas Gohr<p>*foo<code>*</code></p> 6285*72b2703bSAndreas Gohr```````````````````````````````` 6286*72b2703bSAndreas Gohr 6287*72b2703bSAndreas Gohr 6288*72b2703bSAndreas GohrAnd this is not parsed as a link: 6289*72b2703bSAndreas Gohr 6290*72b2703bSAndreas Gohr```````````````````````````````` example 6291*72b2703bSAndreas Gohr[not a `link](/foo`) 6292*72b2703bSAndreas Gohr. 6293*72b2703bSAndreas Gohr<p>[not a <code>link](/foo</code>)</p> 6294*72b2703bSAndreas Gohr```````````````````````````````` 6295*72b2703bSAndreas Gohr 6296*72b2703bSAndreas Gohr 6297*72b2703bSAndreas GohrCode spans, HTML tags, and autolinks have the same precedence. 6298*72b2703bSAndreas GohrThus, this is code: 6299*72b2703bSAndreas Gohr 6300*72b2703bSAndreas Gohr```````````````````````````````` example 6301*72b2703bSAndreas Gohr`<a href="`">` 6302*72b2703bSAndreas Gohr. 6303*72b2703bSAndreas Gohr<p><code><a href="</code>">`</p> 6304*72b2703bSAndreas Gohr```````````````````````````````` 6305*72b2703bSAndreas Gohr 6306*72b2703bSAndreas Gohr 6307*72b2703bSAndreas GohrBut this is an HTML tag: 6308*72b2703bSAndreas Gohr 6309*72b2703bSAndreas Gohr```````````````````````````````` example 6310*72b2703bSAndreas Gohr<a href="`">` 6311*72b2703bSAndreas Gohr. 6312*72b2703bSAndreas Gohr<p><a href="`">`</p> 6313*72b2703bSAndreas Gohr```````````````````````````````` 6314*72b2703bSAndreas Gohr 6315*72b2703bSAndreas Gohr 6316*72b2703bSAndreas GohrAnd this is code: 6317*72b2703bSAndreas Gohr 6318*72b2703bSAndreas Gohr```````````````````````````````` example 6319*72b2703bSAndreas Gohr`<http://foo.bar.`baz>` 6320*72b2703bSAndreas Gohr. 6321*72b2703bSAndreas Gohr<p><code><http://foo.bar.</code>baz>`</p> 6322*72b2703bSAndreas Gohr```````````````````````````````` 6323*72b2703bSAndreas Gohr 6324*72b2703bSAndreas Gohr 6325*72b2703bSAndreas GohrBut this is an autolink: 6326*72b2703bSAndreas Gohr 6327*72b2703bSAndreas Gohr```````````````````````````````` example 6328*72b2703bSAndreas Gohr<http://foo.bar.`baz>` 6329*72b2703bSAndreas Gohr. 6330*72b2703bSAndreas Gohr<p><a href="http://foo.bar.%60baz">http://foo.bar.`baz</a>`</p> 6331*72b2703bSAndreas Gohr```````````````````````````````` 6332*72b2703bSAndreas Gohr 6333*72b2703bSAndreas Gohr 6334*72b2703bSAndreas GohrWhen a backtick string is not closed by a matching backtick string, 6335*72b2703bSAndreas Gohrwe just have literal backticks: 6336*72b2703bSAndreas Gohr 6337*72b2703bSAndreas Gohr```````````````````````````````` example 6338*72b2703bSAndreas Gohr```foo`` 6339*72b2703bSAndreas Gohr. 6340*72b2703bSAndreas Gohr<p>```foo``</p> 6341*72b2703bSAndreas Gohr```````````````````````````````` 6342*72b2703bSAndreas Gohr 6343*72b2703bSAndreas Gohr 6344*72b2703bSAndreas Gohr```````````````````````````````` example 6345*72b2703bSAndreas Gohr`foo 6346*72b2703bSAndreas Gohr. 6347*72b2703bSAndreas Gohr<p>`foo</p> 6348*72b2703bSAndreas Gohr```````````````````````````````` 6349*72b2703bSAndreas Gohr 6350*72b2703bSAndreas GohrThe following case also illustrates the need for opening and 6351*72b2703bSAndreas Gohrclosing backtick strings to be equal in length: 6352*72b2703bSAndreas Gohr 6353*72b2703bSAndreas Gohr```````````````````````````````` example 6354*72b2703bSAndreas Gohr`foo``bar`` 6355*72b2703bSAndreas Gohr. 6356*72b2703bSAndreas Gohr<p>`foo<code>bar</code></p> 6357*72b2703bSAndreas Gohr```````````````````````````````` 6358*72b2703bSAndreas Gohr 6359*72b2703bSAndreas Gohr 6360*72b2703bSAndreas Gohr## Emphasis and strong emphasis 6361*72b2703bSAndreas Gohr 6362*72b2703bSAndreas GohrJohn Gruber's original [Markdown syntax 6363*72b2703bSAndreas Gohrdescription](http://daringfireball.net/projects/markdown/syntax#em) says: 6364*72b2703bSAndreas Gohr 6365*72b2703bSAndreas Gohr> Markdown treats asterisks (`*`) and underscores (`_`) as indicators of 6366*72b2703bSAndreas Gohr> emphasis. Text wrapped with one `*` or `_` will be wrapped with an HTML 6367*72b2703bSAndreas Gohr> `<em>` tag; double `*`'s or `_`'s will be wrapped with an HTML `<strong>` 6368*72b2703bSAndreas Gohr> tag. 6369*72b2703bSAndreas Gohr 6370*72b2703bSAndreas GohrThis is enough for most users, but these rules leave much undecided, 6371*72b2703bSAndreas Gohrespecially when it comes to nested emphasis. The original 6372*72b2703bSAndreas Gohr`Markdown.pl` test suite makes it clear that triple `***` and 6373*72b2703bSAndreas Gohr`___` delimiters can be used for strong emphasis, and most 6374*72b2703bSAndreas Gohrimplementations have also allowed the following patterns: 6375*72b2703bSAndreas Gohr 6376*72b2703bSAndreas Gohr``` markdown 6377*72b2703bSAndreas Gohr***strong emph*** 6378*72b2703bSAndreas Gohr***strong** in emph* 6379*72b2703bSAndreas Gohr***emph* in strong** 6380*72b2703bSAndreas Gohr**in strong *emph*** 6381*72b2703bSAndreas Gohr*in emph **strong*** 6382*72b2703bSAndreas Gohr``` 6383*72b2703bSAndreas Gohr 6384*72b2703bSAndreas GohrThe following patterns are less widely supported, but the intent 6385*72b2703bSAndreas Gohris clear and they are useful (especially in contexts like bibliography 6386*72b2703bSAndreas Gohrentries): 6387*72b2703bSAndreas Gohr 6388*72b2703bSAndreas Gohr``` markdown 6389*72b2703bSAndreas Gohr*emph *with emph* in it* 6390*72b2703bSAndreas Gohr**strong **with strong** in it** 6391*72b2703bSAndreas Gohr``` 6392*72b2703bSAndreas Gohr 6393*72b2703bSAndreas GohrMany implementations have also restricted intraword emphasis to 6394*72b2703bSAndreas Gohrthe `*` forms, to avoid unwanted emphasis in words containing 6395*72b2703bSAndreas Gohrinternal underscores. (It is best practice to put these in code 6396*72b2703bSAndreas Gohrspans, but users often do not.) 6397*72b2703bSAndreas Gohr 6398*72b2703bSAndreas Gohr``` markdown 6399*72b2703bSAndreas Gohrinternal emphasis: foo*bar*baz 6400*72b2703bSAndreas Gohrno emphasis: foo_bar_baz 6401*72b2703bSAndreas Gohr``` 6402*72b2703bSAndreas Gohr 6403*72b2703bSAndreas GohrThe rules given below capture all of these patterns, while allowing 6404*72b2703bSAndreas Gohrfor efficient parsing strategies that do not backtrack. 6405*72b2703bSAndreas Gohr 6406*72b2703bSAndreas GohrFirst, some definitions. A [delimiter run](@) is either 6407*72b2703bSAndreas Gohra sequence of one or more `*` characters that is not preceded or 6408*72b2703bSAndreas Gohrfollowed by a non-backslash-escaped `*` character, or a sequence 6409*72b2703bSAndreas Gohrof one or more `_` characters that is not preceded or followed by 6410*72b2703bSAndreas Gohra non-backslash-escaped `_` character. 6411*72b2703bSAndreas Gohr 6412*72b2703bSAndreas GohrA [left-flanking delimiter run](@) is 6413*72b2703bSAndreas Gohra [delimiter run] that is (1) not followed by [Unicode whitespace], 6414*72b2703bSAndreas Gohrand either (2a) not followed by a [punctuation character], or 6415*72b2703bSAndreas Gohr(2b) followed by a [punctuation character] and 6416*72b2703bSAndreas Gohrpreceded by [Unicode whitespace] or a [punctuation character]. 6417*72b2703bSAndreas GohrFor purposes of this definition, the beginning and the end of 6418*72b2703bSAndreas Gohrthe line count as Unicode whitespace. 6419*72b2703bSAndreas Gohr 6420*72b2703bSAndreas GohrA [right-flanking delimiter run](@) is 6421*72b2703bSAndreas Gohra [delimiter run] that is (1) not preceded by [Unicode whitespace], 6422*72b2703bSAndreas Gohrand either (2a) not preceded by a [punctuation character], or 6423*72b2703bSAndreas Gohr(2b) preceded by a [punctuation character] and 6424*72b2703bSAndreas Gohrfollowed by [Unicode whitespace] or a [punctuation character]. 6425*72b2703bSAndreas GohrFor purposes of this definition, the beginning and the end of 6426*72b2703bSAndreas Gohrthe line count as Unicode whitespace. 6427*72b2703bSAndreas Gohr 6428*72b2703bSAndreas GohrHere are some examples of delimiter runs. 6429*72b2703bSAndreas Gohr 6430*72b2703bSAndreas Gohr - left-flanking but not right-flanking: 6431*72b2703bSAndreas Gohr 6432*72b2703bSAndreas Gohr ``` 6433*72b2703bSAndreas Gohr ***abc 6434*72b2703bSAndreas Gohr _abc 6435*72b2703bSAndreas Gohr **"abc" 6436*72b2703bSAndreas Gohr _"abc" 6437*72b2703bSAndreas Gohr ``` 6438*72b2703bSAndreas Gohr 6439*72b2703bSAndreas Gohr - right-flanking but not left-flanking: 6440*72b2703bSAndreas Gohr 6441*72b2703bSAndreas Gohr ``` 6442*72b2703bSAndreas Gohr abc*** 6443*72b2703bSAndreas Gohr abc_ 6444*72b2703bSAndreas Gohr "abc"** 6445*72b2703bSAndreas Gohr "abc"_ 6446*72b2703bSAndreas Gohr ``` 6447*72b2703bSAndreas Gohr 6448*72b2703bSAndreas Gohr - Both left and right-flanking: 6449*72b2703bSAndreas Gohr 6450*72b2703bSAndreas Gohr ``` 6451*72b2703bSAndreas Gohr abc***def 6452*72b2703bSAndreas Gohr "abc"_"def" 6453*72b2703bSAndreas Gohr ``` 6454*72b2703bSAndreas Gohr 6455*72b2703bSAndreas Gohr - Neither left nor right-flanking: 6456*72b2703bSAndreas Gohr 6457*72b2703bSAndreas Gohr ``` 6458*72b2703bSAndreas Gohr abc *** def 6459*72b2703bSAndreas Gohr a _ b 6460*72b2703bSAndreas Gohr ``` 6461*72b2703bSAndreas Gohr 6462*72b2703bSAndreas Gohr(The idea of distinguishing left-flanking and right-flanking 6463*72b2703bSAndreas Gohrdelimiter runs based on the character before and the character 6464*72b2703bSAndreas Gohrafter comes from Roopesh Chander's 6465*72b2703bSAndreas Gohr[vfmd](http://www.vfmd.org/vfmd-spec/specification/#procedure-for-identifying-emphasis-tags). 6466*72b2703bSAndreas Gohrvfmd uses the terminology "emphasis indicator string" instead of "delimiter 6467*72b2703bSAndreas Gohrrun," and its rules for distinguishing left- and right-flanking runs 6468*72b2703bSAndreas Gohrare a bit more complex than the ones given here.) 6469*72b2703bSAndreas Gohr 6470*72b2703bSAndreas GohrThe following rules define emphasis and strong emphasis: 6471*72b2703bSAndreas Gohr 6472*72b2703bSAndreas Gohr1. A single `*` character [can open emphasis](@) 6473*72b2703bSAndreas Gohr iff (if and only if) it is part of a [left-flanking delimiter run]. 6474*72b2703bSAndreas Gohr 6475*72b2703bSAndreas Gohr2. A single `_` character [can open emphasis] iff 6476*72b2703bSAndreas Gohr it is part of a [left-flanking delimiter run] 6477*72b2703bSAndreas Gohr and either (a) not part of a [right-flanking delimiter run] 6478*72b2703bSAndreas Gohr or (b) part of a [right-flanking delimiter run] 6479*72b2703bSAndreas Gohr preceded by punctuation. 6480*72b2703bSAndreas Gohr 6481*72b2703bSAndreas Gohr3. A single `*` character [can close emphasis](@) 6482*72b2703bSAndreas Gohr iff it is part of a [right-flanking delimiter run]. 6483*72b2703bSAndreas Gohr 6484*72b2703bSAndreas Gohr4. A single `_` character [can close emphasis] iff 6485*72b2703bSAndreas Gohr it is part of a [right-flanking delimiter run] 6486*72b2703bSAndreas Gohr and either (a) not part of a [left-flanking delimiter run] 6487*72b2703bSAndreas Gohr or (b) part of a [left-flanking delimiter run] 6488*72b2703bSAndreas Gohr followed by punctuation. 6489*72b2703bSAndreas Gohr 6490*72b2703bSAndreas Gohr5. A double `**` [can open strong emphasis](@) 6491*72b2703bSAndreas Gohr iff it is part of a [left-flanking delimiter run]. 6492*72b2703bSAndreas Gohr 6493*72b2703bSAndreas Gohr6. A double `__` [can open strong emphasis] iff 6494*72b2703bSAndreas Gohr it is part of a [left-flanking delimiter run] 6495*72b2703bSAndreas Gohr and either (a) not part of a [right-flanking delimiter run] 6496*72b2703bSAndreas Gohr or (b) part of a [right-flanking delimiter run] 6497*72b2703bSAndreas Gohr preceded by punctuation. 6498*72b2703bSAndreas Gohr 6499*72b2703bSAndreas Gohr7. A double `**` [can close strong emphasis](@) 6500*72b2703bSAndreas Gohr iff it is part of a [right-flanking delimiter run]. 6501*72b2703bSAndreas Gohr 6502*72b2703bSAndreas Gohr8. A double `__` [can close strong emphasis] iff 6503*72b2703bSAndreas Gohr it is part of a [right-flanking delimiter run] 6504*72b2703bSAndreas Gohr and either (a) not part of a [left-flanking delimiter run] 6505*72b2703bSAndreas Gohr or (b) part of a [left-flanking delimiter run] 6506*72b2703bSAndreas Gohr followed by punctuation. 6507*72b2703bSAndreas Gohr 6508*72b2703bSAndreas Gohr9. Emphasis begins with a delimiter that [can open emphasis] and ends 6509*72b2703bSAndreas Gohr with a delimiter that [can close emphasis], and that uses the same 6510*72b2703bSAndreas Gohr character (`_` or `*`) as the opening delimiter. The 6511*72b2703bSAndreas Gohr opening and closing delimiters must belong to separate 6512*72b2703bSAndreas Gohr [delimiter runs]. If one of the delimiters can both 6513*72b2703bSAndreas Gohr open and close emphasis, then the sum of the lengths of the 6514*72b2703bSAndreas Gohr delimiter runs containing the opening and closing delimiters 6515*72b2703bSAndreas Gohr must not be a multiple of 3 unless both lengths are 6516*72b2703bSAndreas Gohr multiples of 3. 6517*72b2703bSAndreas Gohr 6518*72b2703bSAndreas Gohr10. Strong emphasis begins with a delimiter that 6519*72b2703bSAndreas Gohr [can open strong emphasis] and ends with a delimiter that 6520*72b2703bSAndreas Gohr [can close strong emphasis], and that uses the same character 6521*72b2703bSAndreas Gohr (`_` or `*`) as the opening delimiter. The 6522*72b2703bSAndreas Gohr opening and closing delimiters must belong to separate 6523*72b2703bSAndreas Gohr [delimiter runs]. If one of the delimiters can both open 6524*72b2703bSAndreas Gohr and close strong emphasis, then the sum of the lengths of 6525*72b2703bSAndreas Gohr the delimiter runs containing the opening and closing 6526*72b2703bSAndreas Gohr delimiters must not be a multiple of 3 unless both lengths 6527*72b2703bSAndreas Gohr are multiples of 3. 6528*72b2703bSAndreas Gohr 6529*72b2703bSAndreas Gohr11. A literal `*` character cannot occur at the beginning or end of 6530*72b2703bSAndreas Gohr `*`-delimited emphasis or `**`-delimited strong emphasis, unless it 6531*72b2703bSAndreas Gohr is backslash-escaped. 6532*72b2703bSAndreas Gohr 6533*72b2703bSAndreas Gohr12. A literal `_` character cannot occur at the beginning or end of 6534*72b2703bSAndreas Gohr `_`-delimited emphasis or `__`-delimited strong emphasis, unless it 6535*72b2703bSAndreas Gohr is backslash-escaped. 6536*72b2703bSAndreas Gohr 6537*72b2703bSAndreas GohrWhere rules 1--12 above are compatible with multiple parsings, 6538*72b2703bSAndreas Gohrthe following principles resolve ambiguity: 6539*72b2703bSAndreas Gohr 6540*72b2703bSAndreas Gohr13. The number of nestings should be minimized. Thus, for example, 6541*72b2703bSAndreas Gohr an interpretation `<strong>...</strong>` is always preferred to 6542*72b2703bSAndreas Gohr `<em><em>...</em></em>`. 6543*72b2703bSAndreas Gohr 6544*72b2703bSAndreas Gohr14. An interpretation `<em><strong>...</strong></em>` is always 6545*72b2703bSAndreas Gohr preferred to `<strong><em>...</em></strong>`. 6546*72b2703bSAndreas Gohr 6547*72b2703bSAndreas Gohr15. When two potential emphasis or strong emphasis spans overlap, 6548*72b2703bSAndreas Gohr so that the second begins before the first ends and ends after 6549*72b2703bSAndreas Gohr the first ends, the first takes precedence. Thus, for example, 6550*72b2703bSAndreas Gohr `*foo _bar* baz_` is parsed as `<em>foo _bar</em> baz_` rather 6551*72b2703bSAndreas Gohr than `*foo <em>bar* baz</em>`. 6552*72b2703bSAndreas Gohr 6553*72b2703bSAndreas Gohr16. When there are two potential emphasis or strong emphasis spans 6554*72b2703bSAndreas Gohr with the same closing delimiter, the shorter one (the one that 6555*72b2703bSAndreas Gohr opens later) takes precedence. Thus, for example, 6556*72b2703bSAndreas Gohr `**foo **bar baz**` is parsed as `**foo <strong>bar baz</strong>` 6557*72b2703bSAndreas Gohr rather than `<strong>foo **bar baz</strong>`. 6558*72b2703bSAndreas Gohr 6559*72b2703bSAndreas Gohr17. Inline code spans, links, images, and HTML tags group more tightly 6560*72b2703bSAndreas Gohr than emphasis. So, when there is a choice between an interpretation 6561*72b2703bSAndreas Gohr that contains one of these elements and one that does not, the 6562*72b2703bSAndreas Gohr former always wins. Thus, for example, `*[foo*](bar)` is 6563*72b2703bSAndreas Gohr parsed as `*<a href="bar">foo*</a>` rather than as 6564*72b2703bSAndreas Gohr `<em>[foo</em>](bar)`. 6565*72b2703bSAndreas Gohr 6566*72b2703bSAndreas GohrThese rules can be illustrated through a series of examples. 6567*72b2703bSAndreas Gohr 6568*72b2703bSAndreas GohrRule 1: 6569*72b2703bSAndreas Gohr 6570*72b2703bSAndreas Gohr```````````````````````````````` example 6571*72b2703bSAndreas Gohr*foo bar* 6572*72b2703bSAndreas Gohr. 6573*72b2703bSAndreas Gohr<p><em>foo bar</em></p> 6574*72b2703bSAndreas Gohr```````````````````````````````` 6575*72b2703bSAndreas Gohr 6576*72b2703bSAndreas Gohr 6577*72b2703bSAndreas GohrThis is not emphasis, because the opening `*` is followed by 6578*72b2703bSAndreas Gohrwhitespace, and hence not part of a [left-flanking delimiter run]: 6579*72b2703bSAndreas Gohr 6580*72b2703bSAndreas Gohr```````````````````````````````` example 6581*72b2703bSAndreas Gohra * foo bar* 6582*72b2703bSAndreas Gohr. 6583*72b2703bSAndreas Gohr<p>a * foo bar*</p> 6584*72b2703bSAndreas Gohr```````````````````````````````` 6585*72b2703bSAndreas Gohr 6586*72b2703bSAndreas Gohr 6587*72b2703bSAndreas GohrThis is not emphasis, because the opening `*` is preceded 6588*72b2703bSAndreas Gohrby an alphanumeric and followed by punctuation, and hence 6589*72b2703bSAndreas Gohrnot part of a [left-flanking delimiter run]: 6590*72b2703bSAndreas Gohr 6591*72b2703bSAndreas Gohr```````````````````````````````` example 6592*72b2703bSAndreas Gohra*"foo"* 6593*72b2703bSAndreas Gohr. 6594*72b2703bSAndreas Gohr<p>a*"foo"*</p> 6595*72b2703bSAndreas Gohr```````````````````````````````` 6596*72b2703bSAndreas Gohr 6597*72b2703bSAndreas Gohr 6598*72b2703bSAndreas GohrUnicode nonbreaking spaces count as whitespace, too: 6599*72b2703bSAndreas Gohr 6600*72b2703bSAndreas Gohr```````````````````````````````` example 6601*72b2703bSAndreas Gohr* a * 6602*72b2703bSAndreas Gohr. 6603*72b2703bSAndreas Gohr<p>* a *</p> 6604*72b2703bSAndreas Gohr```````````````````````````````` 6605*72b2703bSAndreas Gohr 6606*72b2703bSAndreas Gohr 6607*72b2703bSAndreas GohrIntraword emphasis with `*` is permitted: 6608*72b2703bSAndreas Gohr 6609*72b2703bSAndreas Gohr```````````````````````````````` example 6610*72b2703bSAndreas Gohrfoo*bar* 6611*72b2703bSAndreas Gohr. 6612*72b2703bSAndreas Gohr<p>foo<em>bar</em></p> 6613*72b2703bSAndreas Gohr```````````````````````````````` 6614*72b2703bSAndreas Gohr 6615*72b2703bSAndreas Gohr 6616*72b2703bSAndreas Gohr```````````````````````````````` example 6617*72b2703bSAndreas Gohr5*6*78 6618*72b2703bSAndreas Gohr. 6619*72b2703bSAndreas Gohr<p>5<em>6</em>78</p> 6620*72b2703bSAndreas Gohr```````````````````````````````` 6621*72b2703bSAndreas Gohr 6622*72b2703bSAndreas Gohr 6623*72b2703bSAndreas GohrRule 2: 6624*72b2703bSAndreas Gohr 6625*72b2703bSAndreas Gohr```````````````````````````````` example 6626*72b2703bSAndreas Gohr_foo bar_ 6627*72b2703bSAndreas Gohr. 6628*72b2703bSAndreas Gohr<p><em>foo bar</em></p> 6629*72b2703bSAndreas Gohr```````````````````````````````` 6630*72b2703bSAndreas Gohr 6631*72b2703bSAndreas Gohr 6632*72b2703bSAndreas GohrThis is not emphasis, because the opening `_` is followed by 6633*72b2703bSAndreas Gohrwhitespace: 6634*72b2703bSAndreas Gohr 6635*72b2703bSAndreas Gohr```````````````````````````````` example 6636*72b2703bSAndreas Gohr_ foo bar_ 6637*72b2703bSAndreas Gohr. 6638*72b2703bSAndreas Gohr<p>_ foo bar_</p> 6639*72b2703bSAndreas Gohr```````````````````````````````` 6640*72b2703bSAndreas Gohr 6641*72b2703bSAndreas Gohr 6642*72b2703bSAndreas GohrThis is not emphasis, because the opening `_` is preceded 6643*72b2703bSAndreas Gohrby an alphanumeric and followed by punctuation: 6644*72b2703bSAndreas Gohr 6645*72b2703bSAndreas Gohr```````````````````````````````` example 6646*72b2703bSAndreas Gohra_"foo"_ 6647*72b2703bSAndreas Gohr. 6648*72b2703bSAndreas Gohr<p>a_"foo"_</p> 6649*72b2703bSAndreas Gohr```````````````````````````````` 6650*72b2703bSAndreas Gohr 6651*72b2703bSAndreas Gohr 6652*72b2703bSAndreas GohrEmphasis with `_` is not allowed inside words: 6653*72b2703bSAndreas Gohr 6654*72b2703bSAndreas Gohr```````````````````````````````` example 6655*72b2703bSAndreas Gohrfoo_bar_ 6656*72b2703bSAndreas Gohr. 6657*72b2703bSAndreas Gohr<p>foo_bar_</p> 6658*72b2703bSAndreas Gohr```````````````````````````````` 6659*72b2703bSAndreas Gohr 6660*72b2703bSAndreas Gohr 6661*72b2703bSAndreas Gohr```````````````````````````````` example 6662*72b2703bSAndreas Gohr5_6_78 6663*72b2703bSAndreas Gohr. 6664*72b2703bSAndreas Gohr<p>5_6_78</p> 6665*72b2703bSAndreas Gohr```````````````````````````````` 6666*72b2703bSAndreas Gohr 6667*72b2703bSAndreas Gohr 6668*72b2703bSAndreas Gohr```````````````````````````````` example 6669*72b2703bSAndreas Gohrпристаням_стремятся_ 6670*72b2703bSAndreas Gohr. 6671*72b2703bSAndreas Gohr<p>пристаням_стремятся_</p> 6672*72b2703bSAndreas Gohr```````````````````````````````` 6673*72b2703bSAndreas Gohr 6674*72b2703bSAndreas Gohr 6675*72b2703bSAndreas GohrHere `_` does not generate emphasis, because the first delimiter run 6676*72b2703bSAndreas Gohris right-flanking and the second left-flanking: 6677*72b2703bSAndreas Gohr 6678*72b2703bSAndreas Gohr```````````````````````````````` example 6679*72b2703bSAndreas Gohraa_"bb"_cc 6680*72b2703bSAndreas Gohr. 6681*72b2703bSAndreas Gohr<p>aa_"bb"_cc</p> 6682*72b2703bSAndreas Gohr```````````````````````````````` 6683*72b2703bSAndreas Gohr 6684*72b2703bSAndreas Gohr 6685*72b2703bSAndreas GohrThis is emphasis, even though the opening delimiter is 6686*72b2703bSAndreas Gohrboth left- and right-flanking, because it is preceded by 6687*72b2703bSAndreas Gohrpunctuation: 6688*72b2703bSAndreas Gohr 6689*72b2703bSAndreas Gohr```````````````````````````````` example 6690*72b2703bSAndreas Gohrfoo-_(bar)_ 6691*72b2703bSAndreas Gohr. 6692*72b2703bSAndreas Gohr<p>foo-<em>(bar)</em></p> 6693*72b2703bSAndreas Gohr```````````````````````````````` 6694*72b2703bSAndreas Gohr 6695*72b2703bSAndreas Gohr 6696*72b2703bSAndreas GohrRule 3: 6697*72b2703bSAndreas Gohr 6698*72b2703bSAndreas GohrThis is not emphasis, because the closing delimiter does 6699*72b2703bSAndreas Gohrnot match the opening delimiter: 6700*72b2703bSAndreas Gohr 6701*72b2703bSAndreas Gohr```````````````````````````````` example 6702*72b2703bSAndreas Gohr_foo* 6703*72b2703bSAndreas Gohr. 6704*72b2703bSAndreas Gohr<p>_foo*</p> 6705*72b2703bSAndreas Gohr```````````````````````````````` 6706*72b2703bSAndreas Gohr 6707*72b2703bSAndreas Gohr 6708*72b2703bSAndreas GohrThis is not emphasis, because the closing `*` is preceded by 6709*72b2703bSAndreas Gohrwhitespace: 6710*72b2703bSAndreas Gohr 6711*72b2703bSAndreas Gohr```````````````````````````````` example 6712*72b2703bSAndreas Gohr*foo bar * 6713*72b2703bSAndreas Gohr. 6714*72b2703bSAndreas Gohr<p>*foo bar *</p> 6715*72b2703bSAndreas Gohr```````````````````````````````` 6716*72b2703bSAndreas Gohr 6717*72b2703bSAndreas Gohr 6718*72b2703bSAndreas GohrA newline also counts as whitespace: 6719*72b2703bSAndreas Gohr 6720*72b2703bSAndreas Gohr```````````````````````````````` example 6721*72b2703bSAndreas Gohr*foo bar 6722*72b2703bSAndreas Gohr* 6723*72b2703bSAndreas Gohr. 6724*72b2703bSAndreas Gohr<p>*foo bar 6725*72b2703bSAndreas Gohr*</p> 6726*72b2703bSAndreas Gohr```````````````````````````````` 6727*72b2703bSAndreas Gohr 6728*72b2703bSAndreas Gohr 6729*72b2703bSAndreas GohrThis is not emphasis, because the second `*` is 6730*72b2703bSAndreas Gohrpreceded by punctuation and followed by an alphanumeric 6731*72b2703bSAndreas Gohr(hence it is not part of a [right-flanking delimiter run]: 6732*72b2703bSAndreas Gohr 6733*72b2703bSAndreas Gohr```````````````````````````````` example 6734*72b2703bSAndreas Gohr*(*foo) 6735*72b2703bSAndreas Gohr. 6736*72b2703bSAndreas Gohr<p>*(*foo)</p> 6737*72b2703bSAndreas Gohr```````````````````````````````` 6738*72b2703bSAndreas Gohr 6739*72b2703bSAndreas Gohr 6740*72b2703bSAndreas GohrThe point of this restriction is more easily appreciated 6741*72b2703bSAndreas Gohrwith this example: 6742*72b2703bSAndreas Gohr 6743*72b2703bSAndreas Gohr```````````````````````````````` example 6744*72b2703bSAndreas Gohr*(*foo*)* 6745*72b2703bSAndreas Gohr. 6746*72b2703bSAndreas Gohr<p><em>(<em>foo</em>)</em></p> 6747*72b2703bSAndreas Gohr```````````````````````````````` 6748*72b2703bSAndreas Gohr 6749*72b2703bSAndreas Gohr 6750*72b2703bSAndreas GohrIntraword emphasis with `*` is allowed: 6751*72b2703bSAndreas Gohr 6752*72b2703bSAndreas Gohr```````````````````````````````` example 6753*72b2703bSAndreas Gohr*foo*bar 6754*72b2703bSAndreas Gohr. 6755*72b2703bSAndreas Gohr<p><em>foo</em>bar</p> 6756*72b2703bSAndreas Gohr```````````````````````````````` 6757*72b2703bSAndreas Gohr 6758*72b2703bSAndreas Gohr 6759*72b2703bSAndreas Gohr 6760*72b2703bSAndreas GohrRule 4: 6761*72b2703bSAndreas Gohr 6762*72b2703bSAndreas GohrThis is not emphasis, because the closing `_` is preceded by 6763*72b2703bSAndreas Gohrwhitespace: 6764*72b2703bSAndreas Gohr 6765*72b2703bSAndreas Gohr```````````````````````````````` example 6766*72b2703bSAndreas Gohr_foo bar _ 6767*72b2703bSAndreas Gohr. 6768*72b2703bSAndreas Gohr<p>_foo bar _</p> 6769*72b2703bSAndreas Gohr```````````````````````````````` 6770*72b2703bSAndreas Gohr 6771*72b2703bSAndreas Gohr 6772*72b2703bSAndreas GohrThis is not emphasis, because the second `_` is 6773*72b2703bSAndreas Gohrpreceded by punctuation and followed by an alphanumeric: 6774*72b2703bSAndreas Gohr 6775*72b2703bSAndreas Gohr```````````````````````````````` example 6776*72b2703bSAndreas Gohr_(_foo) 6777*72b2703bSAndreas Gohr. 6778*72b2703bSAndreas Gohr<p>_(_foo)</p> 6779*72b2703bSAndreas Gohr```````````````````````````````` 6780*72b2703bSAndreas Gohr 6781*72b2703bSAndreas Gohr 6782*72b2703bSAndreas GohrThis is emphasis within emphasis: 6783*72b2703bSAndreas Gohr 6784*72b2703bSAndreas Gohr```````````````````````````````` example 6785*72b2703bSAndreas Gohr_(_foo_)_ 6786*72b2703bSAndreas Gohr. 6787*72b2703bSAndreas Gohr<p><em>(<em>foo</em>)</em></p> 6788*72b2703bSAndreas Gohr```````````````````````````````` 6789*72b2703bSAndreas Gohr 6790*72b2703bSAndreas Gohr 6791*72b2703bSAndreas GohrIntraword emphasis is disallowed for `_`: 6792*72b2703bSAndreas Gohr 6793*72b2703bSAndreas Gohr```````````````````````````````` example 6794*72b2703bSAndreas Gohr_foo_bar 6795*72b2703bSAndreas Gohr. 6796*72b2703bSAndreas Gohr<p>_foo_bar</p> 6797*72b2703bSAndreas Gohr```````````````````````````````` 6798*72b2703bSAndreas Gohr 6799*72b2703bSAndreas Gohr 6800*72b2703bSAndreas Gohr```````````````````````````````` example 6801*72b2703bSAndreas Gohr_пристаням_стремятся 6802*72b2703bSAndreas Gohr. 6803*72b2703bSAndreas Gohr<p>_пристаням_стремятся</p> 6804*72b2703bSAndreas Gohr```````````````````````````````` 6805*72b2703bSAndreas Gohr 6806*72b2703bSAndreas Gohr 6807*72b2703bSAndreas Gohr```````````````````````````````` example 6808*72b2703bSAndreas Gohr_foo_bar_baz_ 6809*72b2703bSAndreas Gohr. 6810*72b2703bSAndreas Gohr<p><em>foo_bar_baz</em></p> 6811*72b2703bSAndreas Gohr```````````````````````````````` 6812*72b2703bSAndreas Gohr 6813*72b2703bSAndreas Gohr 6814*72b2703bSAndreas GohrThis is emphasis, even though the closing delimiter is 6815*72b2703bSAndreas Gohrboth left- and right-flanking, because it is followed by 6816*72b2703bSAndreas Gohrpunctuation: 6817*72b2703bSAndreas Gohr 6818*72b2703bSAndreas Gohr```````````````````````````````` example 6819*72b2703bSAndreas Gohr_(bar)_. 6820*72b2703bSAndreas Gohr. 6821*72b2703bSAndreas Gohr<p><em>(bar)</em>.</p> 6822*72b2703bSAndreas Gohr```````````````````````````````` 6823*72b2703bSAndreas Gohr 6824*72b2703bSAndreas Gohr 6825*72b2703bSAndreas GohrRule 5: 6826*72b2703bSAndreas Gohr 6827*72b2703bSAndreas Gohr```````````````````````````````` example 6828*72b2703bSAndreas Gohr**foo bar** 6829*72b2703bSAndreas Gohr. 6830*72b2703bSAndreas Gohr<p><strong>foo bar</strong></p> 6831*72b2703bSAndreas Gohr```````````````````````````````` 6832*72b2703bSAndreas Gohr 6833*72b2703bSAndreas Gohr 6834*72b2703bSAndreas GohrThis is not strong emphasis, because the opening delimiter is 6835*72b2703bSAndreas Gohrfollowed by whitespace: 6836*72b2703bSAndreas Gohr 6837*72b2703bSAndreas Gohr```````````````````````````````` example 6838*72b2703bSAndreas Gohr** foo bar** 6839*72b2703bSAndreas Gohr. 6840*72b2703bSAndreas Gohr<p>** foo bar**</p> 6841*72b2703bSAndreas Gohr```````````````````````````````` 6842*72b2703bSAndreas Gohr 6843*72b2703bSAndreas Gohr 6844*72b2703bSAndreas GohrThis is not strong emphasis, because the opening `**` is preceded 6845*72b2703bSAndreas Gohrby an alphanumeric and followed by punctuation, and hence 6846*72b2703bSAndreas Gohrnot part of a [left-flanking delimiter run]: 6847*72b2703bSAndreas Gohr 6848*72b2703bSAndreas Gohr```````````````````````````````` example 6849*72b2703bSAndreas Gohra**"foo"** 6850*72b2703bSAndreas Gohr. 6851*72b2703bSAndreas Gohr<p>a**"foo"**</p> 6852*72b2703bSAndreas Gohr```````````````````````````````` 6853*72b2703bSAndreas Gohr 6854*72b2703bSAndreas Gohr 6855*72b2703bSAndreas GohrIntraword strong emphasis with `**` is permitted: 6856*72b2703bSAndreas Gohr 6857*72b2703bSAndreas Gohr```````````````````````````````` example 6858*72b2703bSAndreas Gohrfoo**bar** 6859*72b2703bSAndreas Gohr. 6860*72b2703bSAndreas Gohr<p>foo<strong>bar</strong></p> 6861*72b2703bSAndreas Gohr```````````````````````````````` 6862*72b2703bSAndreas Gohr 6863*72b2703bSAndreas Gohr 6864*72b2703bSAndreas GohrRule 6: 6865*72b2703bSAndreas Gohr 6866*72b2703bSAndreas Gohr```````````````````````````````` example 6867*72b2703bSAndreas Gohr__foo bar__ 6868*72b2703bSAndreas Gohr. 6869*72b2703bSAndreas Gohr<p><strong>foo bar</strong></p> 6870*72b2703bSAndreas Gohr```````````````````````````````` 6871*72b2703bSAndreas Gohr 6872*72b2703bSAndreas Gohr 6873*72b2703bSAndreas GohrThis is not strong emphasis, because the opening delimiter is 6874*72b2703bSAndreas Gohrfollowed by whitespace: 6875*72b2703bSAndreas Gohr 6876*72b2703bSAndreas Gohr```````````````````````````````` example 6877*72b2703bSAndreas Gohr__ foo bar__ 6878*72b2703bSAndreas Gohr. 6879*72b2703bSAndreas Gohr<p>__ foo bar__</p> 6880*72b2703bSAndreas Gohr```````````````````````````````` 6881*72b2703bSAndreas Gohr 6882*72b2703bSAndreas Gohr 6883*72b2703bSAndreas GohrA newline counts as whitespace: 6884*72b2703bSAndreas Gohr```````````````````````````````` example 6885*72b2703bSAndreas Gohr__ 6886*72b2703bSAndreas Gohrfoo bar__ 6887*72b2703bSAndreas Gohr. 6888*72b2703bSAndreas Gohr<p>__ 6889*72b2703bSAndreas Gohrfoo bar__</p> 6890*72b2703bSAndreas Gohr```````````````````````````````` 6891*72b2703bSAndreas Gohr 6892*72b2703bSAndreas Gohr 6893*72b2703bSAndreas GohrThis is not strong emphasis, because the opening `__` is preceded 6894*72b2703bSAndreas Gohrby an alphanumeric and followed by punctuation: 6895*72b2703bSAndreas Gohr 6896*72b2703bSAndreas Gohr```````````````````````````````` example 6897*72b2703bSAndreas Gohra__"foo"__ 6898*72b2703bSAndreas Gohr. 6899*72b2703bSAndreas Gohr<p>a__"foo"__</p> 6900*72b2703bSAndreas Gohr```````````````````````````````` 6901*72b2703bSAndreas Gohr 6902*72b2703bSAndreas Gohr 6903*72b2703bSAndreas GohrIntraword strong emphasis is forbidden with `__`: 6904*72b2703bSAndreas Gohr 6905*72b2703bSAndreas Gohr```````````````````````````````` example 6906*72b2703bSAndreas Gohrfoo__bar__ 6907*72b2703bSAndreas Gohr. 6908*72b2703bSAndreas Gohr<p>foo__bar__</p> 6909*72b2703bSAndreas Gohr```````````````````````````````` 6910*72b2703bSAndreas Gohr 6911*72b2703bSAndreas Gohr 6912*72b2703bSAndreas Gohr```````````````````````````````` example 6913*72b2703bSAndreas Gohr5__6__78 6914*72b2703bSAndreas Gohr. 6915*72b2703bSAndreas Gohr<p>5__6__78</p> 6916*72b2703bSAndreas Gohr```````````````````````````````` 6917*72b2703bSAndreas Gohr 6918*72b2703bSAndreas Gohr 6919*72b2703bSAndreas Gohr```````````````````````````````` example 6920*72b2703bSAndreas Gohrпристаням__стремятся__ 6921*72b2703bSAndreas Gohr. 6922*72b2703bSAndreas Gohr<p>пристаням__стремятся__</p> 6923*72b2703bSAndreas Gohr```````````````````````````````` 6924*72b2703bSAndreas Gohr 6925*72b2703bSAndreas Gohr 6926*72b2703bSAndreas Gohr```````````````````````````````` example 6927*72b2703bSAndreas Gohr__foo, __bar__, baz__ 6928*72b2703bSAndreas Gohr. 6929*72b2703bSAndreas Gohr<p><strong>foo, bar, baz</strong></p> 6930*72b2703bSAndreas Gohr```````````````````````````````` 6931*72b2703bSAndreas Gohr 6932*72b2703bSAndreas Gohr 6933*72b2703bSAndreas GohrThis is strong emphasis, even though the opening delimiter is 6934*72b2703bSAndreas Gohrboth left- and right-flanking, because it is preceded by 6935*72b2703bSAndreas Gohrpunctuation: 6936*72b2703bSAndreas Gohr 6937*72b2703bSAndreas Gohr```````````````````````````````` example 6938*72b2703bSAndreas Gohrfoo-__(bar)__ 6939*72b2703bSAndreas Gohr. 6940*72b2703bSAndreas Gohr<p>foo-<strong>(bar)</strong></p> 6941*72b2703bSAndreas Gohr```````````````````````````````` 6942*72b2703bSAndreas Gohr 6943*72b2703bSAndreas Gohr 6944*72b2703bSAndreas Gohr 6945*72b2703bSAndreas GohrRule 7: 6946*72b2703bSAndreas Gohr 6947*72b2703bSAndreas GohrThis is not strong emphasis, because the closing delimiter is preceded 6948*72b2703bSAndreas Gohrby whitespace: 6949*72b2703bSAndreas Gohr 6950*72b2703bSAndreas Gohr```````````````````````````````` example 6951*72b2703bSAndreas Gohr**foo bar ** 6952*72b2703bSAndreas Gohr. 6953*72b2703bSAndreas Gohr<p>**foo bar **</p> 6954*72b2703bSAndreas Gohr```````````````````````````````` 6955*72b2703bSAndreas Gohr 6956*72b2703bSAndreas Gohr 6957*72b2703bSAndreas Gohr(Nor can it be interpreted as an emphasized `*foo bar *`, because of 6958*72b2703bSAndreas GohrRule 11.) 6959*72b2703bSAndreas Gohr 6960*72b2703bSAndreas GohrThis is not strong emphasis, because the second `**` is 6961*72b2703bSAndreas Gohrpreceded by punctuation and followed by an alphanumeric: 6962*72b2703bSAndreas Gohr 6963*72b2703bSAndreas Gohr```````````````````````````````` example 6964*72b2703bSAndreas Gohr**(**foo) 6965*72b2703bSAndreas Gohr. 6966*72b2703bSAndreas Gohr<p>**(**foo)</p> 6967*72b2703bSAndreas Gohr```````````````````````````````` 6968*72b2703bSAndreas Gohr 6969*72b2703bSAndreas Gohr 6970*72b2703bSAndreas GohrThe point of this restriction is more easily appreciated 6971*72b2703bSAndreas Gohrwith these examples: 6972*72b2703bSAndreas Gohr 6973*72b2703bSAndreas Gohr```````````````````````````````` example 6974*72b2703bSAndreas Gohr*(**foo**)* 6975*72b2703bSAndreas Gohr. 6976*72b2703bSAndreas Gohr<p><em>(<strong>foo</strong>)</em></p> 6977*72b2703bSAndreas Gohr```````````````````````````````` 6978*72b2703bSAndreas Gohr 6979*72b2703bSAndreas Gohr 6980*72b2703bSAndreas Gohr```````````````````````````````` example 6981*72b2703bSAndreas Gohr**Gomphocarpus (*Gomphocarpus physocarpus*, syn. 6982*72b2703bSAndreas Gohr*Asclepias physocarpa*)** 6983*72b2703bSAndreas Gohr. 6984*72b2703bSAndreas Gohr<p><strong>Gomphocarpus (<em>Gomphocarpus physocarpus</em>, syn. 6985*72b2703bSAndreas Gohr<em>Asclepias physocarpa</em>)</strong></p> 6986*72b2703bSAndreas Gohr```````````````````````````````` 6987*72b2703bSAndreas Gohr 6988*72b2703bSAndreas Gohr 6989*72b2703bSAndreas Gohr```````````````````````````````` example 6990*72b2703bSAndreas Gohr**foo "*bar*" foo** 6991*72b2703bSAndreas Gohr. 6992*72b2703bSAndreas Gohr<p><strong>foo "<em>bar</em>" foo</strong></p> 6993*72b2703bSAndreas Gohr```````````````````````````````` 6994*72b2703bSAndreas Gohr 6995*72b2703bSAndreas Gohr 6996*72b2703bSAndreas GohrIntraword emphasis: 6997*72b2703bSAndreas Gohr 6998*72b2703bSAndreas Gohr```````````````````````````````` example 6999*72b2703bSAndreas Gohr**foo**bar 7000*72b2703bSAndreas Gohr. 7001*72b2703bSAndreas Gohr<p><strong>foo</strong>bar</p> 7002*72b2703bSAndreas Gohr```````````````````````````````` 7003*72b2703bSAndreas Gohr 7004*72b2703bSAndreas Gohr 7005*72b2703bSAndreas GohrRule 8: 7006*72b2703bSAndreas Gohr 7007*72b2703bSAndreas GohrThis is not strong emphasis, because the closing delimiter is 7008*72b2703bSAndreas Gohrpreceded by whitespace: 7009*72b2703bSAndreas Gohr 7010*72b2703bSAndreas Gohr```````````````````````````````` example 7011*72b2703bSAndreas Gohr__foo bar __ 7012*72b2703bSAndreas Gohr. 7013*72b2703bSAndreas Gohr<p>__foo bar __</p> 7014*72b2703bSAndreas Gohr```````````````````````````````` 7015*72b2703bSAndreas Gohr 7016*72b2703bSAndreas Gohr 7017*72b2703bSAndreas GohrThis is not strong emphasis, because the second `__` is 7018*72b2703bSAndreas Gohrpreceded by punctuation and followed by an alphanumeric: 7019*72b2703bSAndreas Gohr 7020*72b2703bSAndreas Gohr```````````````````````````````` example 7021*72b2703bSAndreas Gohr__(__foo) 7022*72b2703bSAndreas Gohr. 7023*72b2703bSAndreas Gohr<p>__(__foo)</p> 7024*72b2703bSAndreas Gohr```````````````````````````````` 7025*72b2703bSAndreas Gohr 7026*72b2703bSAndreas Gohr 7027*72b2703bSAndreas GohrThe point of this restriction is more easily appreciated 7028*72b2703bSAndreas Gohrwith this example: 7029*72b2703bSAndreas Gohr 7030*72b2703bSAndreas Gohr```````````````````````````````` example 7031*72b2703bSAndreas Gohr_(__foo__)_ 7032*72b2703bSAndreas Gohr. 7033*72b2703bSAndreas Gohr<p><em>(<strong>foo</strong>)</em></p> 7034*72b2703bSAndreas Gohr```````````````````````````````` 7035*72b2703bSAndreas Gohr 7036*72b2703bSAndreas Gohr 7037*72b2703bSAndreas GohrIntraword strong emphasis is forbidden with `__`: 7038*72b2703bSAndreas Gohr 7039*72b2703bSAndreas Gohr```````````````````````````````` example 7040*72b2703bSAndreas Gohr__foo__bar 7041*72b2703bSAndreas Gohr. 7042*72b2703bSAndreas Gohr<p>__foo__bar</p> 7043*72b2703bSAndreas Gohr```````````````````````````````` 7044*72b2703bSAndreas Gohr 7045*72b2703bSAndreas Gohr 7046*72b2703bSAndreas Gohr```````````````````````````````` example 7047*72b2703bSAndreas Gohr__пристаням__стремятся 7048*72b2703bSAndreas Gohr. 7049*72b2703bSAndreas Gohr<p>__пристаням__стремятся</p> 7050*72b2703bSAndreas Gohr```````````````````````````````` 7051*72b2703bSAndreas Gohr 7052*72b2703bSAndreas Gohr 7053*72b2703bSAndreas Gohr```````````````````````````````` example 7054*72b2703bSAndreas Gohr__foo__bar__baz__ 7055*72b2703bSAndreas Gohr. 7056*72b2703bSAndreas Gohr<p><strong>foo__bar__baz</strong></p> 7057*72b2703bSAndreas Gohr```````````````````````````````` 7058*72b2703bSAndreas Gohr 7059*72b2703bSAndreas Gohr 7060*72b2703bSAndreas GohrThis is strong emphasis, even though the closing delimiter is 7061*72b2703bSAndreas Gohrboth left- and right-flanking, because it is followed by 7062*72b2703bSAndreas Gohrpunctuation: 7063*72b2703bSAndreas Gohr 7064*72b2703bSAndreas Gohr```````````````````````````````` example 7065*72b2703bSAndreas Gohr__(bar)__. 7066*72b2703bSAndreas Gohr. 7067*72b2703bSAndreas Gohr<p><strong>(bar)</strong>.</p> 7068*72b2703bSAndreas Gohr```````````````````````````````` 7069*72b2703bSAndreas Gohr 7070*72b2703bSAndreas Gohr 7071*72b2703bSAndreas GohrRule 9: 7072*72b2703bSAndreas Gohr 7073*72b2703bSAndreas GohrAny nonempty sequence of inline elements can be the contents of an 7074*72b2703bSAndreas Gohremphasized span. 7075*72b2703bSAndreas Gohr 7076*72b2703bSAndreas Gohr```````````````````````````````` example 7077*72b2703bSAndreas Gohr*foo [bar](/url)* 7078*72b2703bSAndreas Gohr. 7079*72b2703bSAndreas Gohr<p><em>foo <a href="/url">bar</a></em></p> 7080*72b2703bSAndreas Gohr```````````````````````````````` 7081*72b2703bSAndreas Gohr 7082*72b2703bSAndreas Gohr 7083*72b2703bSAndreas Gohr```````````````````````````````` example 7084*72b2703bSAndreas Gohr*foo 7085*72b2703bSAndreas Gohrbar* 7086*72b2703bSAndreas Gohr. 7087*72b2703bSAndreas Gohr<p><em>foo 7088*72b2703bSAndreas Gohrbar</em></p> 7089*72b2703bSAndreas Gohr```````````````````````````````` 7090*72b2703bSAndreas Gohr 7091*72b2703bSAndreas Gohr 7092*72b2703bSAndreas GohrIn particular, emphasis and strong emphasis can be nested 7093*72b2703bSAndreas Gohrinside emphasis: 7094*72b2703bSAndreas Gohr 7095*72b2703bSAndreas Gohr```````````````````````````````` example 7096*72b2703bSAndreas Gohr_foo __bar__ baz_ 7097*72b2703bSAndreas Gohr. 7098*72b2703bSAndreas Gohr<p><em>foo <strong>bar</strong> baz</em></p> 7099*72b2703bSAndreas Gohr```````````````````````````````` 7100*72b2703bSAndreas Gohr 7101*72b2703bSAndreas Gohr 7102*72b2703bSAndreas Gohr```````````````````````````````` example 7103*72b2703bSAndreas Gohr_foo _bar_ baz_ 7104*72b2703bSAndreas Gohr. 7105*72b2703bSAndreas Gohr<p><em>foo <em>bar</em> baz</em></p> 7106*72b2703bSAndreas Gohr```````````````````````````````` 7107*72b2703bSAndreas Gohr 7108*72b2703bSAndreas Gohr 7109*72b2703bSAndreas Gohr```````````````````````````````` example 7110*72b2703bSAndreas Gohr__foo_ bar_ 7111*72b2703bSAndreas Gohr. 7112*72b2703bSAndreas Gohr<p><em><em>foo</em> bar</em></p> 7113*72b2703bSAndreas Gohr```````````````````````````````` 7114*72b2703bSAndreas Gohr 7115*72b2703bSAndreas Gohr 7116*72b2703bSAndreas Gohr```````````````````````````````` example 7117*72b2703bSAndreas Gohr*foo *bar** 7118*72b2703bSAndreas Gohr. 7119*72b2703bSAndreas Gohr<p><em>foo <em>bar</em></em></p> 7120*72b2703bSAndreas Gohr```````````````````````````````` 7121*72b2703bSAndreas Gohr 7122*72b2703bSAndreas Gohr 7123*72b2703bSAndreas Gohr```````````````````````````````` example 7124*72b2703bSAndreas Gohr*foo **bar** baz* 7125*72b2703bSAndreas Gohr. 7126*72b2703bSAndreas Gohr<p><em>foo <strong>bar</strong> baz</em></p> 7127*72b2703bSAndreas Gohr```````````````````````````````` 7128*72b2703bSAndreas Gohr 7129*72b2703bSAndreas Gohr```````````````````````````````` example 7130*72b2703bSAndreas Gohr*foo**bar**baz* 7131*72b2703bSAndreas Gohr. 7132*72b2703bSAndreas Gohr<p><em>foo<strong>bar</strong>baz</em></p> 7133*72b2703bSAndreas Gohr```````````````````````````````` 7134*72b2703bSAndreas Gohr 7135*72b2703bSAndreas GohrNote that in the preceding case, the interpretation 7136*72b2703bSAndreas Gohr 7137*72b2703bSAndreas Gohr``` markdown 7138*72b2703bSAndreas Gohr<p><em>foo</em><em>bar<em></em>baz</em></p> 7139*72b2703bSAndreas Gohr``` 7140*72b2703bSAndreas Gohr 7141*72b2703bSAndreas Gohr 7142*72b2703bSAndreas Gohris precluded by the condition that a delimiter that 7143*72b2703bSAndreas Gohrcan both open and close (like the `*` after `foo`) 7144*72b2703bSAndreas Gohrcannot form emphasis if the sum of the lengths of 7145*72b2703bSAndreas Gohrthe delimiter runs containing the opening and 7146*72b2703bSAndreas Gohrclosing delimiters is a multiple of 3 unless 7147*72b2703bSAndreas Gohrboth lengths are multiples of 3. 7148*72b2703bSAndreas Gohr 7149*72b2703bSAndreas Gohr 7150*72b2703bSAndreas GohrFor the same reason, we don't get two consecutive 7151*72b2703bSAndreas Gohremphasis sections in this example: 7152*72b2703bSAndreas Gohr 7153*72b2703bSAndreas Gohr```````````````````````````````` example 7154*72b2703bSAndreas Gohr*foo**bar* 7155*72b2703bSAndreas Gohr. 7156*72b2703bSAndreas Gohr<p><em>foo**bar</em></p> 7157*72b2703bSAndreas Gohr```````````````````````````````` 7158*72b2703bSAndreas Gohr 7159*72b2703bSAndreas Gohr 7160*72b2703bSAndreas GohrThe same condition ensures that the following 7161*72b2703bSAndreas Gohrcases are all strong emphasis nested inside 7162*72b2703bSAndreas Gohremphasis, even when the interior spaces are 7163*72b2703bSAndreas Gohromitted: 7164*72b2703bSAndreas Gohr 7165*72b2703bSAndreas Gohr 7166*72b2703bSAndreas Gohr```````````````````````````````` example 7167*72b2703bSAndreas Gohr***foo** bar* 7168*72b2703bSAndreas Gohr. 7169*72b2703bSAndreas Gohr<p><em><strong>foo</strong> bar</em></p> 7170*72b2703bSAndreas Gohr```````````````````````````````` 7171*72b2703bSAndreas Gohr 7172*72b2703bSAndreas Gohr 7173*72b2703bSAndreas Gohr```````````````````````````````` example 7174*72b2703bSAndreas Gohr*foo **bar*** 7175*72b2703bSAndreas Gohr. 7176*72b2703bSAndreas Gohr<p><em>foo <strong>bar</strong></em></p> 7177*72b2703bSAndreas Gohr```````````````````````````````` 7178*72b2703bSAndreas Gohr 7179*72b2703bSAndreas Gohr 7180*72b2703bSAndreas Gohr```````````````````````````````` example 7181*72b2703bSAndreas Gohr*foo**bar*** 7182*72b2703bSAndreas Gohr. 7183*72b2703bSAndreas Gohr<p><em>foo<strong>bar</strong></em></p> 7184*72b2703bSAndreas Gohr```````````````````````````````` 7185*72b2703bSAndreas Gohr 7186*72b2703bSAndreas Gohr 7187*72b2703bSAndreas GohrWhen the lengths of the interior closing and opening 7188*72b2703bSAndreas Gohrdelimiter runs are *both* multiples of 3, though, 7189*72b2703bSAndreas Gohrthey can match to create emphasis: 7190*72b2703bSAndreas Gohr 7191*72b2703bSAndreas Gohr```````````````````````````````` example 7192*72b2703bSAndreas Gohrfoo***bar***baz 7193*72b2703bSAndreas Gohr. 7194*72b2703bSAndreas Gohr<p>foo<em><strong>bar</strong></em>baz</p> 7195*72b2703bSAndreas Gohr```````````````````````````````` 7196*72b2703bSAndreas Gohr 7197*72b2703bSAndreas Gohr```````````````````````````````` example 7198*72b2703bSAndreas Gohrfoo******bar*********baz 7199*72b2703bSAndreas Gohr. 7200*72b2703bSAndreas Gohr<p>foo<strong>bar</strong>***baz</p> 7201*72b2703bSAndreas Gohr```````````````````````````````` 7202*72b2703bSAndreas Gohr 7203*72b2703bSAndreas Gohr 7204*72b2703bSAndreas GohrIndefinite levels of nesting are possible: 7205*72b2703bSAndreas Gohr 7206*72b2703bSAndreas Gohr```````````````````````````````` example 7207*72b2703bSAndreas Gohr*foo **bar *baz* bim** bop* 7208*72b2703bSAndreas Gohr. 7209*72b2703bSAndreas Gohr<p><em>foo <strong>bar <em>baz</em> bim</strong> bop</em></p> 7210*72b2703bSAndreas Gohr```````````````````````````````` 7211*72b2703bSAndreas Gohr 7212*72b2703bSAndreas Gohr 7213*72b2703bSAndreas Gohr```````````````````````````````` example 7214*72b2703bSAndreas Gohr*foo [*bar*](/url)* 7215*72b2703bSAndreas Gohr. 7216*72b2703bSAndreas Gohr<p><em>foo <a href="/url"><em>bar</em></a></em></p> 7217*72b2703bSAndreas Gohr```````````````````````````````` 7218*72b2703bSAndreas Gohr 7219*72b2703bSAndreas Gohr 7220*72b2703bSAndreas GohrThere can be no empty emphasis or strong emphasis: 7221*72b2703bSAndreas Gohr 7222*72b2703bSAndreas Gohr```````````````````````````````` example 7223*72b2703bSAndreas Gohr** is not an empty emphasis 7224*72b2703bSAndreas Gohr. 7225*72b2703bSAndreas Gohr<p>** is not an empty emphasis</p> 7226*72b2703bSAndreas Gohr```````````````````````````````` 7227*72b2703bSAndreas Gohr 7228*72b2703bSAndreas Gohr 7229*72b2703bSAndreas Gohr```````````````````````````````` example 7230*72b2703bSAndreas Gohr**** is not an empty strong emphasis 7231*72b2703bSAndreas Gohr. 7232*72b2703bSAndreas Gohr<p>**** is not an empty strong emphasis</p> 7233*72b2703bSAndreas Gohr```````````````````````````````` 7234*72b2703bSAndreas Gohr 7235*72b2703bSAndreas Gohr 7236*72b2703bSAndreas Gohr 7237*72b2703bSAndreas GohrRule 10: 7238*72b2703bSAndreas Gohr 7239*72b2703bSAndreas GohrAny nonempty sequence of inline elements can be the contents of an 7240*72b2703bSAndreas Gohrstrongly emphasized span. 7241*72b2703bSAndreas Gohr 7242*72b2703bSAndreas Gohr```````````````````````````````` example 7243*72b2703bSAndreas Gohr**foo [bar](/url)** 7244*72b2703bSAndreas Gohr. 7245*72b2703bSAndreas Gohr<p><strong>foo <a href="/url">bar</a></strong></p> 7246*72b2703bSAndreas Gohr```````````````````````````````` 7247*72b2703bSAndreas Gohr 7248*72b2703bSAndreas Gohr 7249*72b2703bSAndreas Gohr```````````````````````````````` example 7250*72b2703bSAndreas Gohr**foo 7251*72b2703bSAndreas Gohrbar** 7252*72b2703bSAndreas Gohr. 7253*72b2703bSAndreas Gohr<p><strong>foo 7254*72b2703bSAndreas Gohrbar</strong></p> 7255*72b2703bSAndreas Gohr```````````````````````````````` 7256*72b2703bSAndreas Gohr 7257*72b2703bSAndreas Gohr 7258*72b2703bSAndreas GohrIn particular, emphasis and strong emphasis can be nested 7259*72b2703bSAndreas Gohrinside strong emphasis: 7260*72b2703bSAndreas Gohr 7261*72b2703bSAndreas Gohr```````````````````````````````` example 7262*72b2703bSAndreas Gohr__foo _bar_ baz__ 7263*72b2703bSAndreas Gohr. 7264*72b2703bSAndreas Gohr<p><strong>foo <em>bar</em> baz</strong></p> 7265*72b2703bSAndreas Gohr```````````````````````````````` 7266*72b2703bSAndreas Gohr 7267*72b2703bSAndreas Gohr 7268*72b2703bSAndreas Gohr```````````````````````````````` example 7269*72b2703bSAndreas Gohr__foo __bar__ baz__ 7270*72b2703bSAndreas Gohr. 7271*72b2703bSAndreas Gohr<p><strong>foo bar baz</strong></p> 7272*72b2703bSAndreas Gohr```````````````````````````````` 7273*72b2703bSAndreas Gohr 7274*72b2703bSAndreas Gohr 7275*72b2703bSAndreas Gohr```````````````````````````````` example 7276*72b2703bSAndreas Gohr____foo__ bar__ 7277*72b2703bSAndreas Gohr. 7278*72b2703bSAndreas Gohr<p><strong>foo bar</strong></p> 7279*72b2703bSAndreas Gohr```````````````````````````````` 7280*72b2703bSAndreas Gohr 7281*72b2703bSAndreas Gohr 7282*72b2703bSAndreas Gohr```````````````````````````````` example 7283*72b2703bSAndreas Gohr**foo **bar**** 7284*72b2703bSAndreas Gohr. 7285*72b2703bSAndreas Gohr<p><strong>foo bar</strong></p> 7286*72b2703bSAndreas Gohr```````````````````````````````` 7287*72b2703bSAndreas Gohr 7288*72b2703bSAndreas Gohr 7289*72b2703bSAndreas Gohr```````````````````````````````` example 7290*72b2703bSAndreas Gohr**foo *bar* baz** 7291*72b2703bSAndreas Gohr. 7292*72b2703bSAndreas Gohr<p><strong>foo <em>bar</em> baz</strong></p> 7293*72b2703bSAndreas Gohr```````````````````````````````` 7294*72b2703bSAndreas Gohr 7295*72b2703bSAndreas Gohr 7296*72b2703bSAndreas Gohr```````````````````````````````` example 7297*72b2703bSAndreas Gohr**foo*bar*baz** 7298*72b2703bSAndreas Gohr. 7299*72b2703bSAndreas Gohr<p><strong>foo<em>bar</em>baz</strong></p> 7300*72b2703bSAndreas Gohr```````````````````````````````` 7301*72b2703bSAndreas Gohr 7302*72b2703bSAndreas Gohr 7303*72b2703bSAndreas Gohr```````````````````````````````` example 7304*72b2703bSAndreas Gohr***foo* bar** 7305*72b2703bSAndreas Gohr. 7306*72b2703bSAndreas Gohr<p><strong><em>foo</em> bar</strong></p> 7307*72b2703bSAndreas Gohr```````````````````````````````` 7308*72b2703bSAndreas Gohr 7309*72b2703bSAndreas Gohr 7310*72b2703bSAndreas Gohr```````````````````````````````` example 7311*72b2703bSAndreas Gohr**foo *bar*** 7312*72b2703bSAndreas Gohr. 7313*72b2703bSAndreas Gohr<p><strong>foo <em>bar</em></strong></p> 7314*72b2703bSAndreas Gohr```````````````````````````````` 7315*72b2703bSAndreas Gohr 7316*72b2703bSAndreas Gohr 7317*72b2703bSAndreas GohrIndefinite levels of nesting are possible: 7318*72b2703bSAndreas Gohr 7319*72b2703bSAndreas Gohr```````````````````````````````` example 7320*72b2703bSAndreas Gohr**foo *bar **baz** 7321*72b2703bSAndreas Gohrbim* bop** 7322*72b2703bSAndreas Gohr. 7323*72b2703bSAndreas Gohr<p><strong>foo <em>bar <strong>baz</strong> 7324*72b2703bSAndreas Gohrbim</em> bop</strong></p> 7325*72b2703bSAndreas Gohr```````````````````````````````` 7326*72b2703bSAndreas Gohr 7327*72b2703bSAndreas Gohr 7328*72b2703bSAndreas Gohr```````````````````````````````` example 7329*72b2703bSAndreas Gohr**foo [*bar*](/url)** 7330*72b2703bSAndreas Gohr. 7331*72b2703bSAndreas Gohr<p><strong>foo <a href="/url"><em>bar</em></a></strong></p> 7332*72b2703bSAndreas Gohr```````````````````````````````` 7333*72b2703bSAndreas Gohr 7334*72b2703bSAndreas Gohr 7335*72b2703bSAndreas GohrThere can be no empty emphasis or strong emphasis: 7336*72b2703bSAndreas Gohr 7337*72b2703bSAndreas Gohr```````````````````````````````` example 7338*72b2703bSAndreas Gohr__ is not an empty emphasis 7339*72b2703bSAndreas Gohr. 7340*72b2703bSAndreas Gohr<p>__ is not an empty emphasis</p> 7341*72b2703bSAndreas Gohr```````````````````````````````` 7342*72b2703bSAndreas Gohr 7343*72b2703bSAndreas Gohr 7344*72b2703bSAndreas Gohr```````````````````````````````` example 7345*72b2703bSAndreas Gohr____ is not an empty strong emphasis 7346*72b2703bSAndreas Gohr. 7347*72b2703bSAndreas Gohr<p>____ is not an empty strong emphasis</p> 7348*72b2703bSAndreas Gohr```````````````````````````````` 7349*72b2703bSAndreas Gohr 7350*72b2703bSAndreas Gohr 7351*72b2703bSAndreas Gohr 7352*72b2703bSAndreas GohrRule 11: 7353*72b2703bSAndreas Gohr 7354*72b2703bSAndreas Gohr```````````````````````````````` example 7355*72b2703bSAndreas Gohrfoo *** 7356*72b2703bSAndreas Gohr. 7357*72b2703bSAndreas Gohr<p>foo ***</p> 7358*72b2703bSAndreas Gohr```````````````````````````````` 7359*72b2703bSAndreas Gohr 7360*72b2703bSAndreas Gohr 7361*72b2703bSAndreas Gohr```````````````````````````````` example 7362*72b2703bSAndreas Gohrfoo *\** 7363*72b2703bSAndreas Gohr. 7364*72b2703bSAndreas Gohr<p>foo <em>*</em></p> 7365*72b2703bSAndreas Gohr```````````````````````````````` 7366*72b2703bSAndreas Gohr 7367*72b2703bSAndreas Gohr 7368*72b2703bSAndreas Gohr```````````````````````````````` example 7369*72b2703bSAndreas Gohrfoo *_* 7370*72b2703bSAndreas Gohr. 7371*72b2703bSAndreas Gohr<p>foo <em>_</em></p> 7372*72b2703bSAndreas Gohr```````````````````````````````` 7373*72b2703bSAndreas Gohr 7374*72b2703bSAndreas Gohr 7375*72b2703bSAndreas Gohr```````````````````````````````` example 7376*72b2703bSAndreas Gohrfoo ***** 7377*72b2703bSAndreas Gohr. 7378*72b2703bSAndreas Gohr<p>foo *****</p> 7379*72b2703bSAndreas Gohr```````````````````````````````` 7380*72b2703bSAndreas Gohr 7381*72b2703bSAndreas Gohr 7382*72b2703bSAndreas Gohr```````````````````````````````` example 7383*72b2703bSAndreas Gohrfoo **\*** 7384*72b2703bSAndreas Gohr. 7385*72b2703bSAndreas Gohr<p>foo <strong>*</strong></p> 7386*72b2703bSAndreas Gohr```````````````````````````````` 7387*72b2703bSAndreas Gohr 7388*72b2703bSAndreas Gohr 7389*72b2703bSAndreas Gohr```````````````````````````````` example 7390*72b2703bSAndreas Gohrfoo **_** 7391*72b2703bSAndreas Gohr. 7392*72b2703bSAndreas Gohr<p>foo <strong>_</strong></p> 7393*72b2703bSAndreas Gohr```````````````````````````````` 7394*72b2703bSAndreas Gohr 7395*72b2703bSAndreas Gohr 7396*72b2703bSAndreas GohrNote that when delimiters do not match evenly, Rule 11 determines 7397*72b2703bSAndreas Gohrthat the excess literal `*` characters will appear outside of the 7398*72b2703bSAndreas Gohremphasis, rather than inside it: 7399*72b2703bSAndreas Gohr 7400*72b2703bSAndreas Gohr```````````````````````````````` example 7401*72b2703bSAndreas Gohr**foo* 7402*72b2703bSAndreas Gohr. 7403*72b2703bSAndreas Gohr<p>*<em>foo</em></p> 7404*72b2703bSAndreas Gohr```````````````````````````````` 7405*72b2703bSAndreas Gohr 7406*72b2703bSAndreas Gohr 7407*72b2703bSAndreas Gohr```````````````````````````````` example 7408*72b2703bSAndreas Gohr*foo** 7409*72b2703bSAndreas Gohr. 7410*72b2703bSAndreas Gohr<p><em>foo</em>*</p> 7411*72b2703bSAndreas Gohr```````````````````````````````` 7412*72b2703bSAndreas Gohr 7413*72b2703bSAndreas Gohr 7414*72b2703bSAndreas Gohr```````````````````````````````` example 7415*72b2703bSAndreas Gohr***foo** 7416*72b2703bSAndreas Gohr. 7417*72b2703bSAndreas Gohr<p>*<strong>foo</strong></p> 7418*72b2703bSAndreas Gohr```````````````````````````````` 7419*72b2703bSAndreas Gohr 7420*72b2703bSAndreas Gohr 7421*72b2703bSAndreas Gohr```````````````````````````````` example 7422*72b2703bSAndreas Gohr****foo* 7423*72b2703bSAndreas Gohr. 7424*72b2703bSAndreas Gohr<p>***<em>foo</em></p> 7425*72b2703bSAndreas Gohr```````````````````````````````` 7426*72b2703bSAndreas Gohr 7427*72b2703bSAndreas Gohr 7428*72b2703bSAndreas Gohr```````````````````````````````` example 7429*72b2703bSAndreas Gohr**foo*** 7430*72b2703bSAndreas Gohr. 7431*72b2703bSAndreas Gohr<p><strong>foo</strong>*</p> 7432*72b2703bSAndreas Gohr```````````````````````````````` 7433*72b2703bSAndreas Gohr 7434*72b2703bSAndreas Gohr 7435*72b2703bSAndreas Gohr```````````````````````````````` example 7436*72b2703bSAndreas Gohr*foo**** 7437*72b2703bSAndreas Gohr. 7438*72b2703bSAndreas Gohr<p><em>foo</em>***</p> 7439*72b2703bSAndreas Gohr```````````````````````````````` 7440*72b2703bSAndreas Gohr 7441*72b2703bSAndreas Gohr 7442*72b2703bSAndreas Gohr 7443*72b2703bSAndreas GohrRule 12: 7444*72b2703bSAndreas Gohr 7445*72b2703bSAndreas Gohr```````````````````````````````` example 7446*72b2703bSAndreas Gohrfoo ___ 7447*72b2703bSAndreas Gohr. 7448*72b2703bSAndreas Gohr<p>foo ___</p> 7449*72b2703bSAndreas Gohr```````````````````````````````` 7450*72b2703bSAndreas Gohr 7451*72b2703bSAndreas Gohr 7452*72b2703bSAndreas Gohr```````````````````````````````` example 7453*72b2703bSAndreas Gohrfoo _\__ 7454*72b2703bSAndreas Gohr. 7455*72b2703bSAndreas Gohr<p>foo <em>_</em></p> 7456*72b2703bSAndreas Gohr```````````````````````````````` 7457*72b2703bSAndreas Gohr 7458*72b2703bSAndreas Gohr 7459*72b2703bSAndreas Gohr```````````````````````````````` example 7460*72b2703bSAndreas Gohrfoo _*_ 7461*72b2703bSAndreas Gohr. 7462*72b2703bSAndreas Gohr<p>foo <em>*</em></p> 7463*72b2703bSAndreas Gohr```````````````````````````````` 7464*72b2703bSAndreas Gohr 7465*72b2703bSAndreas Gohr 7466*72b2703bSAndreas Gohr```````````````````````````````` example 7467*72b2703bSAndreas Gohrfoo _____ 7468*72b2703bSAndreas Gohr. 7469*72b2703bSAndreas Gohr<p>foo _____</p> 7470*72b2703bSAndreas Gohr```````````````````````````````` 7471*72b2703bSAndreas Gohr 7472*72b2703bSAndreas Gohr 7473*72b2703bSAndreas Gohr```````````````````````````````` example 7474*72b2703bSAndreas Gohrfoo __\___ 7475*72b2703bSAndreas Gohr. 7476*72b2703bSAndreas Gohr<p>foo <strong>_</strong></p> 7477*72b2703bSAndreas Gohr```````````````````````````````` 7478*72b2703bSAndreas Gohr 7479*72b2703bSAndreas Gohr 7480*72b2703bSAndreas Gohr```````````````````````````````` example 7481*72b2703bSAndreas Gohrfoo __*__ 7482*72b2703bSAndreas Gohr. 7483*72b2703bSAndreas Gohr<p>foo <strong>*</strong></p> 7484*72b2703bSAndreas Gohr```````````````````````````````` 7485*72b2703bSAndreas Gohr 7486*72b2703bSAndreas Gohr 7487*72b2703bSAndreas Gohr```````````````````````````````` example 7488*72b2703bSAndreas Gohr__foo_ 7489*72b2703bSAndreas Gohr. 7490*72b2703bSAndreas Gohr<p>_<em>foo</em></p> 7491*72b2703bSAndreas Gohr```````````````````````````````` 7492*72b2703bSAndreas Gohr 7493*72b2703bSAndreas Gohr 7494*72b2703bSAndreas GohrNote that when delimiters do not match evenly, Rule 12 determines 7495*72b2703bSAndreas Gohrthat the excess literal `_` characters will appear outside of the 7496*72b2703bSAndreas Gohremphasis, rather than inside it: 7497*72b2703bSAndreas Gohr 7498*72b2703bSAndreas Gohr```````````````````````````````` example 7499*72b2703bSAndreas Gohr_foo__ 7500*72b2703bSAndreas Gohr. 7501*72b2703bSAndreas Gohr<p><em>foo</em>_</p> 7502*72b2703bSAndreas Gohr```````````````````````````````` 7503*72b2703bSAndreas Gohr 7504*72b2703bSAndreas Gohr 7505*72b2703bSAndreas Gohr```````````````````````````````` example 7506*72b2703bSAndreas Gohr___foo__ 7507*72b2703bSAndreas Gohr. 7508*72b2703bSAndreas Gohr<p>_<strong>foo</strong></p> 7509*72b2703bSAndreas Gohr```````````````````````````````` 7510*72b2703bSAndreas Gohr 7511*72b2703bSAndreas Gohr 7512*72b2703bSAndreas Gohr```````````````````````````````` example 7513*72b2703bSAndreas Gohr____foo_ 7514*72b2703bSAndreas Gohr. 7515*72b2703bSAndreas Gohr<p>___<em>foo</em></p> 7516*72b2703bSAndreas Gohr```````````````````````````````` 7517*72b2703bSAndreas Gohr 7518*72b2703bSAndreas Gohr 7519*72b2703bSAndreas Gohr```````````````````````````````` example 7520*72b2703bSAndreas Gohr__foo___ 7521*72b2703bSAndreas Gohr. 7522*72b2703bSAndreas Gohr<p><strong>foo</strong>_</p> 7523*72b2703bSAndreas Gohr```````````````````````````````` 7524*72b2703bSAndreas Gohr 7525*72b2703bSAndreas Gohr 7526*72b2703bSAndreas Gohr```````````````````````````````` example 7527*72b2703bSAndreas Gohr_foo____ 7528*72b2703bSAndreas Gohr. 7529*72b2703bSAndreas Gohr<p><em>foo</em>___</p> 7530*72b2703bSAndreas Gohr```````````````````````````````` 7531*72b2703bSAndreas Gohr 7532*72b2703bSAndreas Gohr 7533*72b2703bSAndreas GohrRule 13 implies that if you want emphasis nested directly inside 7534*72b2703bSAndreas Gohremphasis, you must use different delimiters: 7535*72b2703bSAndreas Gohr 7536*72b2703bSAndreas Gohr```````````````````````````````` example 7537*72b2703bSAndreas Gohr**foo** 7538*72b2703bSAndreas Gohr. 7539*72b2703bSAndreas Gohr<p><strong>foo</strong></p> 7540*72b2703bSAndreas Gohr```````````````````````````````` 7541*72b2703bSAndreas Gohr 7542*72b2703bSAndreas Gohr 7543*72b2703bSAndreas Gohr```````````````````````````````` example 7544*72b2703bSAndreas Gohr*_foo_* 7545*72b2703bSAndreas Gohr. 7546*72b2703bSAndreas Gohr<p><em><em>foo</em></em></p> 7547*72b2703bSAndreas Gohr```````````````````````````````` 7548*72b2703bSAndreas Gohr 7549*72b2703bSAndreas Gohr 7550*72b2703bSAndreas Gohr```````````````````````````````` example 7551*72b2703bSAndreas Gohr__foo__ 7552*72b2703bSAndreas Gohr. 7553*72b2703bSAndreas Gohr<p><strong>foo</strong></p> 7554*72b2703bSAndreas Gohr```````````````````````````````` 7555*72b2703bSAndreas Gohr 7556*72b2703bSAndreas Gohr 7557*72b2703bSAndreas Gohr```````````````````````````````` example 7558*72b2703bSAndreas Gohr_*foo*_ 7559*72b2703bSAndreas Gohr. 7560*72b2703bSAndreas Gohr<p><em><em>foo</em></em></p> 7561*72b2703bSAndreas Gohr```````````````````````````````` 7562*72b2703bSAndreas Gohr 7563*72b2703bSAndreas Gohr 7564*72b2703bSAndreas GohrHowever, strong emphasis within strong emphasis is possible without 7565*72b2703bSAndreas Gohrswitching delimiters: 7566*72b2703bSAndreas Gohr 7567*72b2703bSAndreas Gohr```````````````````````````````` example 7568*72b2703bSAndreas Gohr****foo**** 7569*72b2703bSAndreas Gohr. 7570*72b2703bSAndreas Gohr<p><strong>foo</strong></p> 7571*72b2703bSAndreas Gohr```````````````````````````````` 7572*72b2703bSAndreas Gohr 7573*72b2703bSAndreas Gohr 7574*72b2703bSAndreas Gohr```````````````````````````````` example 7575*72b2703bSAndreas Gohr____foo____ 7576*72b2703bSAndreas Gohr. 7577*72b2703bSAndreas Gohr<p><strong>foo</strong></p> 7578*72b2703bSAndreas Gohr```````````````````````````````` 7579*72b2703bSAndreas Gohr 7580*72b2703bSAndreas Gohr 7581*72b2703bSAndreas Gohr 7582*72b2703bSAndreas GohrRule 13 can be applied to arbitrarily long sequences of 7583*72b2703bSAndreas Gohrdelimiters: 7584*72b2703bSAndreas Gohr 7585*72b2703bSAndreas Gohr```````````````````````````````` example 7586*72b2703bSAndreas Gohr******foo****** 7587*72b2703bSAndreas Gohr. 7588*72b2703bSAndreas Gohr<p><strong>foo</strong></p> 7589*72b2703bSAndreas Gohr```````````````````````````````` 7590*72b2703bSAndreas Gohr 7591*72b2703bSAndreas Gohr 7592*72b2703bSAndreas GohrRule 14: 7593*72b2703bSAndreas Gohr 7594*72b2703bSAndreas Gohr```````````````````````````````` example 7595*72b2703bSAndreas Gohr***foo*** 7596*72b2703bSAndreas Gohr. 7597*72b2703bSAndreas Gohr<p><em><strong>foo</strong></em></p> 7598*72b2703bSAndreas Gohr```````````````````````````````` 7599*72b2703bSAndreas Gohr 7600*72b2703bSAndreas Gohr 7601*72b2703bSAndreas Gohr```````````````````````````````` example 7602*72b2703bSAndreas Gohr_____foo_____ 7603*72b2703bSAndreas Gohr. 7604*72b2703bSAndreas Gohr<p><em><strong>foo</strong></em></p> 7605*72b2703bSAndreas Gohr```````````````````````````````` 7606*72b2703bSAndreas Gohr 7607*72b2703bSAndreas Gohr 7608*72b2703bSAndreas GohrRule 15: 7609*72b2703bSAndreas Gohr 7610*72b2703bSAndreas Gohr```````````````````````````````` example 7611*72b2703bSAndreas Gohr*foo _bar* baz_ 7612*72b2703bSAndreas Gohr. 7613*72b2703bSAndreas Gohr<p><em>foo _bar</em> baz_</p> 7614*72b2703bSAndreas Gohr```````````````````````````````` 7615*72b2703bSAndreas Gohr 7616*72b2703bSAndreas Gohr 7617*72b2703bSAndreas Gohr```````````````````````````````` example 7618*72b2703bSAndreas Gohr*foo __bar *baz bim__ bam* 7619*72b2703bSAndreas Gohr. 7620*72b2703bSAndreas Gohr<p><em>foo <strong>bar *baz bim</strong> bam</em></p> 7621*72b2703bSAndreas Gohr```````````````````````````````` 7622*72b2703bSAndreas Gohr 7623*72b2703bSAndreas Gohr 7624*72b2703bSAndreas GohrRule 16: 7625*72b2703bSAndreas Gohr 7626*72b2703bSAndreas Gohr```````````````````````````````` example 7627*72b2703bSAndreas Gohr**foo **bar baz** 7628*72b2703bSAndreas Gohr. 7629*72b2703bSAndreas Gohr<p>**foo <strong>bar baz</strong></p> 7630*72b2703bSAndreas Gohr```````````````````````````````` 7631*72b2703bSAndreas Gohr 7632*72b2703bSAndreas Gohr 7633*72b2703bSAndreas Gohr```````````````````````````````` example 7634*72b2703bSAndreas Gohr*foo *bar baz* 7635*72b2703bSAndreas Gohr. 7636*72b2703bSAndreas Gohr<p>*foo <em>bar baz</em></p> 7637*72b2703bSAndreas Gohr```````````````````````````````` 7638*72b2703bSAndreas Gohr 7639*72b2703bSAndreas Gohr 7640*72b2703bSAndreas GohrRule 17: 7641*72b2703bSAndreas Gohr 7642*72b2703bSAndreas Gohr```````````````````````````````` example 7643*72b2703bSAndreas Gohr*[bar*](/url) 7644*72b2703bSAndreas Gohr. 7645*72b2703bSAndreas Gohr<p>*<a href="/url">bar*</a></p> 7646*72b2703bSAndreas Gohr```````````````````````````````` 7647*72b2703bSAndreas Gohr 7648*72b2703bSAndreas Gohr 7649*72b2703bSAndreas Gohr```````````````````````````````` example 7650*72b2703bSAndreas Gohr_foo [bar_](/url) 7651*72b2703bSAndreas Gohr. 7652*72b2703bSAndreas Gohr<p>_foo <a href="/url">bar_</a></p> 7653*72b2703bSAndreas Gohr```````````````````````````````` 7654*72b2703bSAndreas Gohr 7655*72b2703bSAndreas Gohr 7656*72b2703bSAndreas Gohr```````````````````````````````` example 7657*72b2703bSAndreas Gohr*<img src="foo" title="*"/> 7658*72b2703bSAndreas Gohr. 7659*72b2703bSAndreas Gohr<p>*<img src="foo" title="*"/></p> 7660*72b2703bSAndreas Gohr```````````````````````````````` 7661*72b2703bSAndreas Gohr 7662*72b2703bSAndreas Gohr 7663*72b2703bSAndreas Gohr```````````````````````````````` example 7664*72b2703bSAndreas Gohr**<a href="**"> 7665*72b2703bSAndreas Gohr. 7666*72b2703bSAndreas Gohr<p>**<a href="**"></p> 7667*72b2703bSAndreas Gohr```````````````````````````````` 7668*72b2703bSAndreas Gohr 7669*72b2703bSAndreas Gohr 7670*72b2703bSAndreas Gohr```````````````````````````````` example 7671*72b2703bSAndreas Gohr__<a href="__"> 7672*72b2703bSAndreas Gohr. 7673*72b2703bSAndreas Gohr<p>__<a href="__"></p> 7674*72b2703bSAndreas Gohr```````````````````````````````` 7675*72b2703bSAndreas Gohr 7676*72b2703bSAndreas Gohr 7677*72b2703bSAndreas Gohr```````````````````````````````` example 7678*72b2703bSAndreas Gohr*a `*`* 7679*72b2703bSAndreas Gohr. 7680*72b2703bSAndreas Gohr<p><em>a <code>*</code></em></p> 7681*72b2703bSAndreas Gohr```````````````````````````````` 7682*72b2703bSAndreas Gohr 7683*72b2703bSAndreas Gohr 7684*72b2703bSAndreas Gohr```````````````````````````````` example 7685*72b2703bSAndreas Gohr_a `_`_ 7686*72b2703bSAndreas Gohr. 7687*72b2703bSAndreas Gohr<p><em>a <code>_</code></em></p> 7688*72b2703bSAndreas Gohr```````````````````````````````` 7689*72b2703bSAndreas Gohr 7690*72b2703bSAndreas Gohr 7691*72b2703bSAndreas Gohr```````````````````````````````` example 7692*72b2703bSAndreas Gohr**a<http://foo.bar/?q=**> 7693*72b2703bSAndreas Gohr. 7694*72b2703bSAndreas Gohr<p>**a<a href="http://foo.bar/?q=**">http://foo.bar/?q=**</a></p> 7695*72b2703bSAndreas Gohr```````````````````````````````` 7696*72b2703bSAndreas Gohr 7697*72b2703bSAndreas Gohr 7698*72b2703bSAndreas Gohr```````````````````````````````` example 7699*72b2703bSAndreas Gohr__a<http://foo.bar/?q=__> 7700*72b2703bSAndreas Gohr. 7701*72b2703bSAndreas Gohr<p>__a<a href="http://foo.bar/?q=__">http://foo.bar/?q=__</a></p> 7702*72b2703bSAndreas Gohr```````````````````````````````` 7703*72b2703bSAndreas Gohr 7704*72b2703bSAndreas Gohr 7705*72b2703bSAndreas Gohr<div class="extension"> 7706*72b2703bSAndreas Gohr 7707*72b2703bSAndreas Gohr## Strikethrough (extension) 7708*72b2703bSAndreas Gohr 7709*72b2703bSAndreas GohrGFM enables the `strikethrough` extension, where an additional emphasis type is 7710*72b2703bSAndreas Gohravailable. 7711*72b2703bSAndreas Gohr 7712*72b2703bSAndreas GohrStrikethrough text is any text wrapped in two tildes (`~`). 7713*72b2703bSAndreas Gohr 7714*72b2703bSAndreas Gohr```````````````````````````````` example strikethrough 7715*72b2703bSAndreas Gohr~~Hi~~ Hello, world! 7716*72b2703bSAndreas Gohr. 7717*72b2703bSAndreas Gohr<p><del>Hi</del> Hello, world!</p> 7718*72b2703bSAndreas Gohr```````````````````````````````` 7719*72b2703bSAndreas Gohr 7720*72b2703bSAndreas GohrAs with regular emphasis delimiters, a new paragraph will cause strikethrough 7721*72b2703bSAndreas Gohrparsing to cease: 7722*72b2703bSAndreas Gohr 7723*72b2703bSAndreas Gohr```````````````````````````````` example strikethrough 7724*72b2703bSAndreas GohrThis ~~has a 7725*72b2703bSAndreas Gohr 7726*72b2703bSAndreas Gohrnew paragraph~~. 7727*72b2703bSAndreas Gohr. 7728*72b2703bSAndreas Gohr<p>This ~~has a</p> 7729*72b2703bSAndreas Gohr<p>new paragraph~~.</p> 7730*72b2703bSAndreas Gohr```````````````````````````````` 7731*72b2703bSAndreas Gohr 7732*72b2703bSAndreas Gohr</div> 7733*72b2703bSAndreas Gohr 7734*72b2703bSAndreas Gohr## Links 7735*72b2703bSAndreas Gohr 7736*72b2703bSAndreas GohrA link contains [link text] (the visible text), a [link destination] 7737*72b2703bSAndreas Gohr(the URI that is the link destination), and optionally a [link title]. 7738*72b2703bSAndreas GohrThere are two basic kinds of links in Markdown. In [inline links] the 7739*72b2703bSAndreas Gohrdestination and title are given immediately after the link text. In 7740*72b2703bSAndreas Gohr[reference links] the destination and title are defined elsewhere in 7741*72b2703bSAndreas Gohrthe document. 7742*72b2703bSAndreas Gohr 7743*72b2703bSAndreas GohrA [link text](@) consists of a sequence of zero or more 7744*72b2703bSAndreas Gohrinline elements enclosed by square brackets (`[` and `]`). The 7745*72b2703bSAndreas Gohrfollowing rules apply: 7746*72b2703bSAndreas Gohr 7747*72b2703bSAndreas Gohr- Links may not contain other links, at any level of nesting. If 7748*72b2703bSAndreas Gohr multiple otherwise valid link definitions appear nested inside each 7749*72b2703bSAndreas Gohr other, the inner-most definition is used. 7750*72b2703bSAndreas Gohr 7751*72b2703bSAndreas Gohr- Brackets are allowed in the [link text] only if (a) they 7752*72b2703bSAndreas Gohr are backslash-escaped or (b) they appear as a matched pair of brackets, 7753*72b2703bSAndreas Gohr with an open bracket `[`, a sequence of zero or more inlines, and 7754*72b2703bSAndreas Gohr a close bracket `]`. 7755*72b2703bSAndreas Gohr 7756*72b2703bSAndreas Gohr- Backtick [code spans], [autolinks], and raw [HTML tags] bind more tightly 7757*72b2703bSAndreas Gohr than the brackets in link text. Thus, for example, 7758*72b2703bSAndreas Gohr `` [foo`]` `` could not be a link text, since the second `]` 7759*72b2703bSAndreas Gohr is part of a code span. 7760*72b2703bSAndreas Gohr 7761*72b2703bSAndreas Gohr- The brackets in link text bind more tightly than markers for 7762*72b2703bSAndreas Gohr [emphasis and strong emphasis]. Thus, for example, `*[foo*](url)` is a link. 7763*72b2703bSAndreas Gohr 7764*72b2703bSAndreas GohrA [link destination](@) consists of either 7765*72b2703bSAndreas Gohr 7766*72b2703bSAndreas Gohr- a sequence of zero or more characters between an opening `<` and a 7767*72b2703bSAndreas Gohr closing `>` that contains no line breaks or unescaped 7768*72b2703bSAndreas Gohr `<` or `>` characters, or 7769*72b2703bSAndreas Gohr 7770*72b2703bSAndreas Gohr- a nonempty sequence of characters that does not start with 7771*72b2703bSAndreas Gohr `<`, does not include ASCII space or control characters, and 7772*72b2703bSAndreas Gohr includes parentheses only if (a) they are backslash-escaped or 7773*72b2703bSAndreas Gohr (b) they are part of a balanced pair of unescaped parentheses. 7774*72b2703bSAndreas Gohr (Implementations may impose limits on parentheses nesting to 7775*72b2703bSAndreas Gohr avoid performance issues, but at least three levels of nesting 7776*72b2703bSAndreas Gohr should be supported.) 7777*72b2703bSAndreas Gohr 7778*72b2703bSAndreas GohrA [link title](@) consists of either 7779*72b2703bSAndreas Gohr 7780*72b2703bSAndreas Gohr- a sequence of zero or more characters between straight double-quote 7781*72b2703bSAndreas Gohr characters (`"`), including a `"` character only if it is 7782*72b2703bSAndreas Gohr backslash-escaped, or 7783*72b2703bSAndreas Gohr 7784*72b2703bSAndreas Gohr- a sequence of zero or more characters between straight single-quote 7785*72b2703bSAndreas Gohr characters (`'`), including a `'` character only if it is 7786*72b2703bSAndreas Gohr backslash-escaped, or 7787*72b2703bSAndreas Gohr 7788*72b2703bSAndreas Gohr- a sequence of zero or more characters between matching parentheses 7789*72b2703bSAndreas Gohr (`(...)`), including a `(` or `)` character only if it is 7790*72b2703bSAndreas Gohr backslash-escaped. 7791*72b2703bSAndreas Gohr 7792*72b2703bSAndreas GohrAlthough [link titles] may span multiple lines, they may not contain 7793*72b2703bSAndreas Gohra [blank line]. 7794*72b2703bSAndreas Gohr 7795*72b2703bSAndreas GohrAn [inline link](@) consists of a [link text] followed immediately 7796*72b2703bSAndreas Gohrby a left parenthesis `(`, optional [whitespace], an optional 7797*72b2703bSAndreas Gohr[link destination], an optional [link title] separated from the link 7798*72b2703bSAndreas Gohrdestination by [whitespace], optional [whitespace], and a right 7799*72b2703bSAndreas Gohrparenthesis `)`. The link's text consists of the inlines contained 7800*72b2703bSAndreas Gohrin the [link text] (excluding the enclosing square brackets). 7801*72b2703bSAndreas GohrThe link's URI consists of the link destination, excluding enclosing 7802*72b2703bSAndreas Gohr`<...>` if present, with backslash-escapes in effect as described 7803*72b2703bSAndreas Gohrabove. The link's title consists of the link title, excluding its 7804*72b2703bSAndreas Gohrenclosing delimiters, with backslash-escapes in effect as described 7805*72b2703bSAndreas Gohrabove. 7806*72b2703bSAndreas Gohr 7807*72b2703bSAndreas GohrHere is a simple inline link: 7808*72b2703bSAndreas Gohr 7809*72b2703bSAndreas Gohr```````````````````````````````` example 7810*72b2703bSAndreas Gohr[link](/uri "title") 7811*72b2703bSAndreas Gohr. 7812*72b2703bSAndreas Gohr<p><a href="/uri" title="title">link</a></p> 7813*72b2703bSAndreas Gohr```````````````````````````````` 7814*72b2703bSAndreas Gohr 7815*72b2703bSAndreas Gohr 7816*72b2703bSAndreas GohrThe title may be omitted: 7817*72b2703bSAndreas Gohr 7818*72b2703bSAndreas Gohr```````````````````````````````` example 7819*72b2703bSAndreas Gohr[link](/uri) 7820*72b2703bSAndreas Gohr. 7821*72b2703bSAndreas Gohr<p><a href="/uri">link</a></p> 7822*72b2703bSAndreas Gohr```````````````````````````````` 7823*72b2703bSAndreas Gohr 7824*72b2703bSAndreas Gohr 7825*72b2703bSAndreas GohrBoth the title and the destination may be omitted: 7826*72b2703bSAndreas Gohr 7827*72b2703bSAndreas Gohr```````````````````````````````` example 7828*72b2703bSAndreas Gohr[link]() 7829*72b2703bSAndreas Gohr. 7830*72b2703bSAndreas Gohr<p><a href="">link</a></p> 7831*72b2703bSAndreas Gohr```````````````````````````````` 7832*72b2703bSAndreas Gohr 7833*72b2703bSAndreas Gohr 7834*72b2703bSAndreas Gohr```````````````````````````````` example 7835*72b2703bSAndreas Gohr[link](<>) 7836*72b2703bSAndreas Gohr. 7837*72b2703bSAndreas Gohr<p><a href="">link</a></p> 7838*72b2703bSAndreas Gohr```````````````````````````````` 7839*72b2703bSAndreas Gohr 7840*72b2703bSAndreas GohrThe destination can only contain spaces if it is 7841*72b2703bSAndreas Gohrenclosed in pointy brackets: 7842*72b2703bSAndreas Gohr 7843*72b2703bSAndreas Gohr```````````````````````````````` example 7844*72b2703bSAndreas Gohr[link](/my uri) 7845*72b2703bSAndreas Gohr. 7846*72b2703bSAndreas Gohr<p>[link](/my uri)</p> 7847*72b2703bSAndreas Gohr```````````````````````````````` 7848*72b2703bSAndreas Gohr 7849*72b2703bSAndreas Gohr```````````````````````````````` example 7850*72b2703bSAndreas Gohr[link](</my uri>) 7851*72b2703bSAndreas Gohr. 7852*72b2703bSAndreas Gohr<p><a href="/my%20uri">link</a></p> 7853*72b2703bSAndreas Gohr```````````````````````````````` 7854*72b2703bSAndreas Gohr 7855*72b2703bSAndreas GohrThe destination cannot contain line breaks, 7856*72b2703bSAndreas Gohreven if enclosed in pointy brackets: 7857*72b2703bSAndreas Gohr 7858*72b2703bSAndreas Gohr```````````````````````````````` example 7859*72b2703bSAndreas Gohr[link](foo 7860*72b2703bSAndreas Gohrbar) 7861*72b2703bSAndreas Gohr. 7862*72b2703bSAndreas Gohr<p>[link](foo 7863*72b2703bSAndreas Gohrbar)</p> 7864*72b2703bSAndreas Gohr```````````````````````````````` 7865*72b2703bSAndreas Gohr 7866*72b2703bSAndreas Gohr```````````````````````````````` example 7867*72b2703bSAndreas Gohr[link](<foo 7868*72b2703bSAndreas Gohrbar>) 7869*72b2703bSAndreas Gohr. 7870*72b2703bSAndreas Gohr<p>[link](<foo 7871*72b2703bSAndreas Gohrbar>)</p> 7872*72b2703bSAndreas Gohr```````````````````````````````` 7873*72b2703bSAndreas Gohr 7874*72b2703bSAndreas GohrThe destination can contain `)` if it is enclosed 7875*72b2703bSAndreas Gohrin pointy brackets: 7876*72b2703bSAndreas Gohr 7877*72b2703bSAndreas Gohr```````````````````````````````` example 7878*72b2703bSAndreas Gohr[a](<b)c>) 7879*72b2703bSAndreas Gohr. 7880*72b2703bSAndreas Gohr<p><a href="b)c">a</a></p> 7881*72b2703bSAndreas Gohr```````````````````````````````` 7882*72b2703bSAndreas Gohr 7883*72b2703bSAndreas GohrPointy brackets that enclose links must be unescaped: 7884*72b2703bSAndreas Gohr 7885*72b2703bSAndreas Gohr```````````````````````````````` example 7886*72b2703bSAndreas Gohr[link](<foo\>) 7887*72b2703bSAndreas Gohr. 7888*72b2703bSAndreas Gohr<p>[link](<foo>)</p> 7889*72b2703bSAndreas Gohr```````````````````````````````` 7890*72b2703bSAndreas Gohr 7891*72b2703bSAndreas GohrThese are not links, because the opening pointy bracket 7892*72b2703bSAndreas Gohris not matched properly: 7893*72b2703bSAndreas Gohr 7894*72b2703bSAndreas Gohr```````````````````````````````` example 7895*72b2703bSAndreas Gohr[a](<b)c 7896*72b2703bSAndreas Gohr[a](<b)c> 7897*72b2703bSAndreas Gohr[a](<b>c) 7898*72b2703bSAndreas Gohr. 7899*72b2703bSAndreas Gohr<p>[a](<b)c 7900*72b2703bSAndreas Gohr[a](<b)c> 7901*72b2703bSAndreas Gohr[a](<b>c)</p> 7902*72b2703bSAndreas Gohr```````````````````````````````` 7903*72b2703bSAndreas Gohr 7904*72b2703bSAndreas GohrParentheses inside the link destination may be escaped: 7905*72b2703bSAndreas Gohr 7906*72b2703bSAndreas Gohr```````````````````````````````` example 7907*72b2703bSAndreas Gohr[link](\(foo\)) 7908*72b2703bSAndreas Gohr. 7909*72b2703bSAndreas Gohr<p><a href="(foo)">link</a></p> 7910*72b2703bSAndreas Gohr```````````````````````````````` 7911*72b2703bSAndreas Gohr 7912*72b2703bSAndreas GohrAny number of parentheses are allowed without escaping, as long as they are 7913*72b2703bSAndreas Gohrbalanced: 7914*72b2703bSAndreas Gohr 7915*72b2703bSAndreas Gohr```````````````````````````````` example 7916*72b2703bSAndreas Gohr[link](foo(and(bar))) 7917*72b2703bSAndreas Gohr. 7918*72b2703bSAndreas Gohr<p><a href="foo(and(bar))">link</a></p> 7919*72b2703bSAndreas Gohr```````````````````````````````` 7920*72b2703bSAndreas Gohr 7921*72b2703bSAndreas GohrHowever, if you have unbalanced parentheses, you need to escape or use the 7922*72b2703bSAndreas Gohr`<...>` form: 7923*72b2703bSAndreas Gohr 7924*72b2703bSAndreas Gohr```````````````````````````````` example 7925*72b2703bSAndreas Gohr[link](foo\(and\(bar\)) 7926*72b2703bSAndreas Gohr. 7927*72b2703bSAndreas Gohr<p><a href="foo(and(bar)">link</a></p> 7928*72b2703bSAndreas Gohr```````````````````````````````` 7929*72b2703bSAndreas Gohr 7930*72b2703bSAndreas Gohr 7931*72b2703bSAndreas Gohr```````````````````````````````` example 7932*72b2703bSAndreas Gohr[link](<foo(and(bar)>) 7933*72b2703bSAndreas Gohr. 7934*72b2703bSAndreas Gohr<p><a href="foo(and(bar)">link</a></p> 7935*72b2703bSAndreas Gohr```````````````````````````````` 7936*72b2703bSAndreas Gohr 7937*72b2703bSAndreas Gohr 7938*72b2703bSAndreas GohrParentheses and other symbols can also be escaped, as usual 7939*72b2703bSAndreas Gohrin Markdown: 7940*72b2703bSAndreas Gohr 7941*72b2703bSAndreas Gohr```````````````````````````````` example 7942*72b2703bSAndreas Gohr[link](foo\)\:) 7943*72b2703bSAndreas Gohr. 7944*72b2703bSAndreas Gohr<p><a href="foo):">link</a></p> 7945*72b2703bSAndreas Gohr```````````````````````````````` 7946*72b2703bSAndreas Gohr 7947*72b2703bSAndreas Gohr 7948*72b2703bSAndreas GohrA link can contain fragment identifiers and queries: 7949*72b2703bSAndreas Gohr 7950*72b2703bSAndreas Gohr```````````````````````````````` example 7951*72b2703bSAndreas Gohr[link](#fragment) 7952*72b2703bSAndreas Gohr 7953*72b2703bSAndreas Gohr[link](http://example.com#fragment) 7954*72b2703bSAndreas Gohr 7955*72b2703bSAndreas Gohr[link](http://example.com?foo=3#frag) 7956*72b2703bSAndreas Gohr. 7957*72b2703bSAndreas Gohr<p><a href="#fragment">link</a></p> 7958*72b2703bSAndreas Gohr<p><a href="http://example.com#fragment">link</a></p> 7959*72b2703bSAndreas Gohr<p><a href="http://example.com?foo=3#frag">link</a></p> 7960*72b2703bSAndreas Gohr```````````````````````````````` 7961*72b2703bSAndreas Gohr 7962*72b2703bSAndreas Gohr 7963*72b2703bSAndreas GohrNote that a backslash before a non-escapable character is 7964*72b2703bSAndreas Gohrjust a backslash: 7965*72b2703bSAndreas Gohr 7966*72b2703bSAndreas Gohr```````````````````````````````` example 7967*72b2703bSAndreas Gohr[link](foo\bar) 7968*72b2703bSAndreas Gohr. 7969*72b2703bSAndreas Gohr<p><a href="foo%5Cbar">link</a></p> 7970*72b2703bSAndreas Gohr```````````````````````````````` 7971*72b2703bSAndreas Gohr 7972*72b2703bSAndreas Gohr 7973*72b2703bSAndreas GohrURL-escaping should be left alone inside the destination, as all 7974*72b2703bSAndreas GohrURL-escaped characters are also valid URL characters. Entity and 7975*72b2703bSAndreas Gohrnumerical character references in the destination will be parsed 7976*72b2703bSAndreas Gohrinto the corresponding Unicode code points, as usual. These may 7977*72b2703bSAndreas Gohrbe optionally URL-escaped when written as HTML, but this spec 7978*72b2703bSAndreas Gohrdoes not enforce any particular policy for rendering URLs in 7979*72b2703bSAndreas GohrHTML or other formats. Renderers may make different decisions 7980*72b2703bSAndreas Gohrabout how to escape or normalize URLs in the output. 7981*72b2703bSAndreas Gohr 7982*72b2703bSAndreas Gohr```````````````````````````````` example 7983*72b2703bSAndreas Gohr[link](foo%20bä) 7984*72b2703bSAndreas Gohr. 7985*72b2703bSAndreas Gohr<p><a href="foo%20b%C3%A4">link</a></p> 7986*72b2703bSAndreas Gohr```````````````````````````````` 7987*72b2703bSAndreas Gohr 7988*72b2703bSAndreas Gohr 7989*72b2703bSAndreas GohrNote that, because titles can often be parsed as destinations, 7990*72b2703bSAndreas Gohrif you try to omit the destination and keep the title, you'll 7991*72b2703bSAndreas Gohrget unexpected results: 7992*72b2703bSAndreas Gohr 7993*72b2703bSAndreas Gohr```````````````````````````````` example 7994*72b2703bSAndreas Gohr[link]("title") 7995*72b2703bSAndreas Gohr. 7996*72b2703bSAndreas Gohr<p><a href="%22title%22">link</a></p> 7997*72b2703bSAndreas Gohr```````````````````````````````` 7998*72b2703bSAndreas Gohr 7999*72b2703bSAndreas Gohr 8000*72b2703bSAndreas GohrTitles may be in single quotes, double quotes, or parentheses: 8001*72b2703bSAndreas Gohr 8002*72b2703bSAndreas Gohr```````````````````````````````` example 8003*72b2703bSAndreas Gohr[link](/url "title") 8004*72b2703bSAndreas Gohr[link](/url 'title') 8005*72b2703bSAndreas Gohr[link](/url (title)) 8006*72b2703bSAndreas Gohr. 8007*72b2703bSAndreas Gohr<p><a href="/url" title="title">link</a> 8008*72b2703bSAndreas Gohr<a href="/url" title="title">link</a> 8009*72b2703bSAndreas Gohr<a href="/url" title="title">link</a></p> 8010*72b2703bSAndreas Gohr```````````````````````````````` 8011*72b2703bSAndreas Gohr 8012*72b2703bSAndreas Gohr 8013*72b2703bSAndreas GohrBackslash escapes and entity and numeric character references 8014*72b2703bSAndreas Gohrmay be used in titles: 8015*72b2703bSAndreas Gohr 8016*72b2703bSAndreas Gohr```````````````````````````````` example 8017*72b2703bSAndreas Gohr[link](/url "title \""") 8018*72b2703bSAndreas Gohr. 8019*72b2703bSAndreas Gohr<p><a href="/url" title="title """>link</a></p> 8020*72b2703bSAndreas Gohr```````````````````````````````` 8021*72b2703bSAndreas Gohr 8022*72b2703bSAndreas Gohr 8023*72b2703bSAndreas GohrTitles must be separated from the link using a [whitespace]. 8024*72b2703bSAndreas GohrOther [Unicode whitespace] like non-breaking space doesn't work. 8025*72b2703bSAndreas Gohr 8026*72b2703bSAndreas Gohr```````````````````````````````` example 8027*72b2703bSAndreas Gohr[link](/url "title") 8028*72b2703bSAndreas Gohr. 8029*72b2703bSAndreas Gohr<p><a href="/url%C2%A0%22title%22">link</a></p> 8030*72b2703bSAndreas Gohr```````````````````````````````` 8031*72b2703bSAndreas Gohr 8032*72b2703bSAndreas Gohr 8033*72b2703bSAndreas GohrNested balanced quotes are not allowed without escaping: 8034*72b2703bSAndreas Gohr 8035*72b2703bSAndreas Gohr```````````````````````````````` example 8036*72b2703bSAndreas Gohr[link](/url "title "and" title") 8037*72b2703bSAndreas Gohr. 8038*72b2703bSAndreas Gohr<p>[link](/url "title "and" title")</p> 8039*72b2703bSAndreas Gohr```````````````````````````````` 8040*72b2703bSAndreas Gohr 8041*72b2703bSAndreas Gohr 8042*72b2703bSAndreas GohrBut it is easy to work around this by using a different quote type: 8043*72b2703bSAndreas Gohr 8044*72b2703bSAndreas Gohr```````````````````````````````` example 8045*72b2703bSAndreas Gohr[link](/url 'title "and" title') 8046*72b2703bSAndreas Gohr. 8047*72b2703bSAndreas Gohr<p><a href="/url" title="title "and" title">link</a></p> 8048*72b2703bSAndreas Gohr```````````````````````````````` 8049*72b2703bSAndreas Gohr 8050*72b2703bSAndreas Gohr 8051*72b2703bSAndreas Gohr(Note: `Markdown.pl` did allow double quotes inside a double-quoted 8052*72b2703bSAndreas Gohrtitle, and its test suite included a test demonstrating this. 8053*72b2703bSAndreas GohrBut it is hard to see a good rationale for the extra complexity this 8054*72b2703bSAndreas Gohrbrings, since there are already many ways---backslash escaping, 8055*72b2703bSAndreas Gohrentity and numeric character references, or using a different 8056*72b2703bSAndreas Gohrquote type for the enclosing title---to write titles containing 8057*72b2703bSAndreas Gohrdouble quotes. `Markdown.pl`'s handling of titles has a number 8058*72b2703bSAndreas Gohrof other strange features. For example, it allows single-quoted 8059*72b2703bSAndreas Gohrtitles in inline links, but not reference links. And, in 8060*72b2703bSAndreas Gohrreference links but not inline links, it allows a title to begin 8061*72b2703bSAndreas Gohrwith `"` and end with `)`. `Markdown.pl` 1.0.1 even allows 8062*72b2703bSAndreas Gohrtitles with no closing quotation mark, though 1.0.2b8 does not. 8063*72b2703bSAndreas GohrIt seems preferable to adopt a simple, rational rule that works 8064*72b2703bSAndreas Gohrthe same way in inline links and link reference definitions.) 8065*72b2703bSAndreas Gohr 8066*72b2703bSAndreas Gohr[Whitespace] is allowed around the destination and title: 8067*72b2703bSAndreas Gohr 8068*72b2703bSAndreas Gohr```````````````````````````````` example 8069*72b2703bSAndreas Gohr[link]( /uri 8070*72b2703bSAndreas Gohr "title" ) 8071*72b2703bSAndreas Gohr. 8072*72b2703bSAndreas Gohr<p><a href="/uri" title="title">link</a></p> 8073*72b2703bSAndreas Gohr```````````````````````````````` 8074*72b2703bSAndreas Gohr 8075*72b2703bSAndreas Gohr 8076*72b2703bSAndreas GohrBut it is not allowed between the link text and the 8077*72b2703bSAndreas Gohrfollowing parenthesis: 8078*72b2703bSAndreas Gohr 8079*72b2703bSAndreas Gohr```````````````````````````````` example 8080*72b2703bSAndreas Gohr[link] (/uri) 8081*72b2703bSAndreas Gohr. 8082*72b2703bSAndreas Gohr<p>[link] (/uri)</p> 8083*72b2703bSAndreas Gohr```````````````````````````````` 8084*72b2703bSAndreas Gohr 8085*72b2703bSAndreas Gohr 8086*72b2703bSAndreas GohrThe link text may contain balanced brackets, but not unbalanced ones, 8087*72b2703bSAndreas Gohrunless they are escaped: 8088*72b2703bSAndreas Gohr 8089*72b2703bSAndreas Gohr```````````````````````````````` example 8090*72b2703bSAndreas Gohr[link [foo [bar]]](/uri) 8091*72b2703bSAndreas Gohr. 8092*72b2703bSAndreas Gohr<p><a href="/uri">link [foo [bar]]</a></p> 8093*72b2703bSAndreas Gohr```````````````````````````````` 8094*72b2703bSAndreas Gohr 8095*72b2703bSAndreas Gohr 8096*72b2703bSAndreas Gohr```````````````````````````````` example 8097*72b2703bSAndreas Gohr[link] bar](/uri) 8098*72b2703bSAndreas Gohr. 8099*72b2703bSAndreas Gohr<p>[link] bar](/uri)</p> 8100*72b2703bSAndreas Gohr```````````````````````````````` 8101*72b2703bSAndreas Gohr 8102*72b2703bSAndreas Gohr 8103*72b2703bSAndreas Gohr```````````````````````````````` example 8104*72b2703bSAndreas Gohr[link [bar](/uri) 8105*72b2703bSAndreas Gohr. 8106*72b2703bSAndreas Gohr<p>[link <a href="/uri">bar</a></p> 8107*72b2703bSAndreas Gohr```````````````````````````````` 8108*72b2703bSAndreas Gohr 8109*72b2703bSAndreas Gohr 8110*72b2703bSAndreas Gohr```````````````````````````````` example 8111*72b2703bSAndreas Gohr[link \[bar](/uri) 8112*72b2703bSAndreas Gohr. 8113*72b2703bSAndreas Gohr<p><a href="/uri">link [bar</a></p> 8114*72b2703bSAndreas Gohr```````````````````````````````` 8115*72b2703bSAndreas Gohr 8116*72b2703bSAndreas Gohr 8117*72b2703bSAndreas GohrThe link text may contain inline content: 8118*72b2703bSAndreas Gohr 8119*72b2703bSAndreas Gohr```````````````````````````````` example 8120*72b2703bSAndreas Gohr[link *foo **bar** `#`*](/uri) 8121*72b2703bSAndreas Gohr. 8122*72b2703bSAndreas Gohr<p><a href="/uri">link <em>foo <strong>bar</strong> <code>#</code></em></a></p> 8123*72b2703bSAndreas Gohr```````````````````````````````` 8124*72b2703bSAndreas Gohr 8125*72b2703bSAndreas Gohr 8126*72b2703bSAndreas Gohr```````````````````````````````` example 8127*72b2703bSAndreas Gohr[](/uri) 8128*72b2703bSAndreas Gohr. 8129*72b2703bSAndreas Gohr<p><a href="/uri"><img src="moon.jpg" alt="moon" /></a></p> 8130*72b2703bSAndreas Gohr```````````````````````````````` 8131*72b2703bSAndreas Gohr 8132*72b2703bSAndreas Gohr 8133*72b2703bSAndreas GohrHowever, links may not contain other links, at any level of nesting. 8134*72b2703bSAndreas Gohr 8135*72b2703bSAndreas Gohr```````````````````````````````` example 8136*72b2703bSAndreas Gohr[foo [bar](/uri)](/uri) 8137*72b2703bSAndreas Gohr. 8138*72b2703bSAndreas Gohr<p>[foo <a href="/uri">bar</a>](/uri)</p> 8139*72b2703bSAndreas Gohr```````````````````````````````` 8140*72b2703bSAndreas Gohr 8141*72b2703bSAndreas Gohr 8142*72b2703bSAndreas Gohr```````````````````````````````` example 8143*72b2703bSAndreas Gohr[foo *[bar [baz](/uri)](/uri)*](/uri) 8144*72b2703bSAndreas Gohr. 8145*72b2703bSAndreas Gohr<p>[foo <em>[bar <a href="/uri">baz</a>](/uri)</em>](/uri)</p> 8146*72b2703bSAndreas Gohr```````````````````````````````` 8147*72b2703bSAndreas Gohr 8148*72b2703bSAndreas Gohr 8149*72b2703bSAndreas Gohr```````````````````````````````` example 8150*72b2703bSAndreas Gohr](uri2)](uri3) 8151*72b2703bSAndreas Gohr. 8152*72b2703bSAndreas Gohr<p><img src="uri3" alt="[foo](uri2)" /></p> 8153*72b2703bSAndreas Gohr```````````````````````````````` 8154*72b2703bSAndreas Gohr 8155*72b2703bSAndreas Gohr 8156*72b2703bSAndreas GohrThese cases illustrate the precedence of link text grouping over 8157*72b2703bSAndreas Gohremphasis grouping: 8158*72b2703bSAndreas Gohr 8159*72b2703bSAndreas Gohr```````````````````````````````` example 8160*72b2703bSAndreas Gohr*[foo*](/uri) 8161*72b2703bSAndreas Gohr. 8162*72b2703bSAndreas Gohr<p>*<a href="/uri">foo*</a></p> 8163*72b2703bSAndreas Gohr```````````````````````````````` 8164*72b2703bSAndreas Gohr 8165*72b2703bSAndreas Gohr 8166*72b2703bSAndreas Gohr```````````````````````````````` example 8167*72b2703bSAndreas Gohr[foo *bar](baz*) 8168*72b2703bSAndreas Gohr. 8169*72b2703bSAndreas Gohr<p><a href="baz*">foo *bar</a></p> 8170*72b2703bSAndreas Gohr```````````````````````````````` 8171*72b2703bSAndreas Gohr 8172*72b2703bSAndreas Gohr 8173*72b2703bSAndreas GohrNote that brackets that *aren't* part of links do not take 8174*72b2703bSAndreas Gohrprecedence: 8175*72b2703bSAndreas Gohr 8176*72b2703bSAndreas Gohr```````````````````````````````` example 8177*72b2703bSAndreas Gohr*foo [bar* baz] 8178*72b2703bSAndreas Gohr. 8179*72b2703bSAndreas Gohr<p><em>foo [bar</em> baz]</p> 8180*72b2703bSAndreas Gohr```````````````````````````````` 8181*72b2703bSAndreas Gohr 8182*72b2703bSAndreas Gohr 8183*72b2703bSAndreas GohrThese cases illustrate the precedence of HTML tags, code spans, 8184*72b2703bSAndreas Gohrand autolinks over link grouping: 8185*72b2703bSAndreas Gohr 8186*72b2703bSAndreas Gohr```````````````````````````````` example 8187*72b2703bSAndreas Gohr[foo <bar attr="](baz)"> 8188*72b2703bSAndreas Gohr. 8189*72b2703bSAndreas Gohr<p>[foo <bar attr="](baz)"></p> 8190*72b2703bSAndreas Gohr```````````````````````````````` 8191*72b2703bSAndreas Gohr 8192*72b2703bSAndreas Gohr 8193*72b2703bSAndreas Gohr```````````````````````````````` example 8194*72b2703bSAndreas Gohr[foo`](/uri)` 8195*72b2703bSAndreas Gohr. 8196*72b2703bSAndreas Gohr<p>[foo<code>](/uri)</code></p> 8197*72b2703bSAndreas Gohr```````````````````````````````` 8198*72b2703bSAndreas Gohr 8199*72b2703bSAndreas Gohr 8200*72b2703bSAndreas Gohr```````````````````````````````` example 8201*72b2703bSAndreas Gohr[foo<http://example.com/?search=](uri)> 8202*72b2703bSAndreas Gohr. 8203*72b2703bSAndreas Gohr<p>[foo<a href="http://example.com/?search=%5D(uri)">http://example.com/?search=](uri)</a></p> 8204*72b2703bSAndreas Gohr```````````````````````````````` 8205*72b2703bSAndreas Gohr 8206*72b2703bSAndreas Gohr 8207*72b2703bSAndreas GohrThere are three kinds of [reference link](@)s: 8208*72b2703bSAndreas Gohr[full](#full-reference-link), [collapsed](#collapsed-reference-link), 8209*72b2703bSAndreas Gohrand [shortcut](#shortcut-reference-link). 8210*72b2703bSAndreas Gohr 8211*72b2703bSAndreas GohrA [full reference link](@) 8212*72b2703bSAndreas Gohrconsists of a [link text] immediately followed by a [link label] 8213*72b2703bSAndreas Gohrthat [matches] a [link reference definition] elsewhere in the document. 8214*72b2703bSAndreas Gohr 8215*72b2703bSAndreas GohrA [link label](@) begins with a left bracket (`[`) and ends 8216*72b2703bSAndreas Gohrwith the first right bracket (`]`) that is not backslash-escaped. 8217*72b2703bSAndreas GohrBetween these brackets there must be at least one [non-whitespace character]. 8218*72b2703bSAndreas GohrUnescaped square bracket characters are not allowed inside the 8219*72b2703bSAndreas Gohropening and closing square brackets of [link labels]. A link 8220*72b2703bSAndreas Gohrlabel can have at most 999 characters inside the square 8221*72b2703bSAndreas Gohrbrackets. 8222*72b2703bSAndreas Gohr 8223*72b2703bSAndreas GohrOne label [matches](@) 8224*72b2703bSAndreas Gohranother just in case their normalized forms are equal. To normalize a 8225*72b2703bSAndreas Gohrlabel, strip off the opening and closing brackets, 8226*72b2703bSAndreas Gohrperform the *Unicode case fold*, strip leading and trailing 8227*72b2703bSAndreas Gohr[whitespace] and collapse consecutive internal 8228*72b2703bSAndreas Gohr[whitespace] to a single space. If there are multiple 8229*72b2703bSAndreas Gohrmatching reference link definitions, the one that comes first in the 8230*72b2703bSAndreas Gohrdocument is used. (It is desirable in such cases to emit a warning.) 8231*72b2703bSAndreas Gohr 8232*72b2703bSAndreas GohrThe contents of the first link label are parsed as inlines, which are 8233*72b2703bSAndreas Gohrused as the link's text. The link's URI and title are provided by the 8234*72b2703bSAndreas Gohrmatching [link reference definition]. 8235*72b2703bSAndreas Gohr 8236*72b2703bSAndreas GohrHere is a simple example: 8237*72b2703bSAndreas Gohr 8238*72b2703bSAndreas Gohr```````````````````````````````` example 8239*72b2703bSAndreas Gohr[foo][bar] 8240*72b2703bSAndreas Gohr 8241*72b2703bSAndreas Gohr[bar]: /url "title" 8242*72b2703bSAndreas Gohr. 8243*72b2703bSAndreas Gohr<p><a href="/url" title="title">foo</a></p> 8244*72b2703bSAndreas Gohr```````````````````````````````` 8245*72b2703bSAndreas Gohr 8246*72b2703bSAndreas Gohr 8247*72b2703bSAndreas GohrThe rules for the [link text] are the same as with 8248*72b2703bSAndreas Gohr[inline links]. Thus: 8249*72b2703bSAndreas Gohr 8250*72b2703bSAndreas GohrThe link text may contain balanced brackets, but not unbalanced ones, 8251*72b2703bSAndreas Gohrunless they are escaped: 8252*72b2703bSAndreas Gohr 8253*72b2703bSAndreas Gohr```````````````````````````````` example 8254*72b2703bSAndreas Gohr[link [foo [bar]]][ref] 8255*72b2703bSAndreas Gohr 8256*72b2703bSAndreas Gohr[ref]: /uri 8257*72b2703bSAndreas Gohr. 8258*72b2703bSAndreas Gohr<p><a href="/uri">link [foo [bar]]</a></p> 8259*72b2703bSAndreas Gohr```````````````````````````````` 8260*72b2703bSAndreas Gohr 8261*72b2703bSAndreas Gohr 8262*72b2703bSAndreas Gohr```````````````````````````````` example 8263*72b2703bSAndreas Gohr[link \[bar][ref] 8264*72b2703bSAndreas Gohr 8265*72b2703bSAndreas Gohr[ref]: /uri 8266*72b2703bSAndreas Gohr. 8267*72b2703bSAndreas Gohr<p><a href="/uri">link [bar</a></p> 8268*72b2703bSAndreas Gohr```````````````````````````````` 8269*72b2703bSAndreas Gohr 8270*72b2703bSAndreas Gohr 8271*72b2703bSAndreas GohrThe link text may contain inline content: 8272*72b2703bSAndreas Gohr 8273*72b2703bSAndreas Gohr```````````````````````````````` example 8274*72b2703bSAndreas Gohr[link *foo **bar** `#`*][ref] 8275*72b2703bSAndreas Gohr 8276*72b2703bSAndreas Gohr[ref]: /uri 8277*72b2703bSAndreas Gohr. 8278*72b2703bSAndreas Gohr<p><a href="/uri">link <em>foo <strong>bar</strong> <code>#</code></em></a></p> 8279*72b2703bSAndreas Gohr```````````````````````````````` 8280*72b2703bSAndreas Gohr 8281*72b2703bSAndreas Gohr 8282*72b2703bSAndreas Gohr```````````````````````````````` example 8283*72b2703bSAndreas Gohr[][ref] 8284*72b2703bSAndreas Gohr 8285*72b2703bSAndreas Gohr[ref]: /uri 8286*72b2703bSAndreas Gohr. 8287*72b2703bSAndreas Gohr<p><a href="/uri"><img src="moon.jpg" alt="moon" /></a></p> 8288*72b2703bSAndreas Gohr```````````````````````````````` 8289*72b2703bSAndreas Gohr 8290*72b2703bSAndreas Gohr 8291*72b2703bSAndreas GohrHowever, links may not contain other links, at any level of nesting. 8292*72b2703bSAndreas Gohr 8293*72b2703bSAndreas Gohr```````````````````````````````` example 8294*72b2703bSAndreas Gohr[foo [bar](/uri)][ref] 8295*72b2703bSAndreas Gohr 8296*72b2703bSAndreas Gohr[ref]: /uri 8297*72b2703bSAndreas Gohr. 8298*72b2703bSAndreas Gohr<p>[foo <a href="/uri">bar</a>]<a href="/uri">ref</a></p> 8299*72b2703bSAndreas Gohr```````````````````````````````` 8300*72b2703bSAndreas Gohr 8301*72b2703bSAndreas Gohr 8302*72b2703bSAndreas Gohr```````````````````````````````` example 8303*72b2703bSAndreas Gohr[foo *bar [baz][ref]*][ref] 8304*72b2703bSAndreas Gohr 8305*72b2703bSAndreas Gohr[ref]: /uri 8306*72b2703bSAndreas Gohr. 8307*72b2703bSAndreas Gohr<p>[foo <em>bar <a href="/uri">baz</a></em>]<a href="/uri">ref</a></p> 8308*72b2703bSAndreas Gohr```````````````````````````````` 8309*72b2703bSAndreas Gohr 8310*72b2703bSAndreas Gohr 8311*72b2703bSAndreas Gohr(In the examples above, we have two [shortcut reference links] 8312*72b2703bSAndreas Gohrinstead of one [full reference link].) 8313*72b2703bSAndreas Gohr 8314*72b2703bSAndreas GohrThe following cases illustrate the precedence of link text grouping over 8315*72b2703bSAndreas Gohremphasis grouping: 8316*72b2703bSAndreas Gohr 8317*72b2703bSAndreas Gohr```````````````````````````````` example 8318*72b2703bSAndreas Gohr*[foo*][ref] 8319*72b2703bSAndreas Gohr 8320*72b2703bSAndreas Gohr[ref]: /uri 8321*72b2703bSAndreas Gohr. 8322*72b2703bSAndreas Gohr<p>*<a href="/uri">foo*</a></p> 8323*72b2703bSAndreas Gohr```````````````````````````````` 8324*72b2703bSAndreas Gohr 8325*72b2703bSAndreas Gohr 8326*72b2703bSAndreas Gohr```````````````````````````````` example 8327*72b2703bSAndreas Gohr[foo *bar][ref] 8328*72b2703bSAndreas Gohr 8329*72b2703bSAndreas Gohr[ref]: /uri 8330*72b2703bSAndreas Gohr. 8331*72b2703bSAndreas Gohr<p><a href="/uri">foo *bar</a></p> 8332*72b2703bSAndreas Gohr```````````````````````````````` 8333*72b2703bSAndreas Gohr 8334*72b2703bSAndreas Gohr 8335*72b2703bSAndreas GohrThese cases illustrate the precedence of HTML tags, code spans, 8336*72b2703bSAndreas Gohrand autolinks over link grouping: 8337*72b2703bSAndreas Gohr 8338*72b2703bSAndreas Gohr```````````````````````````````` example 8339*72b2703bSAndreas Gohr[foo <bar attr="][ref]"> 8340*72b2703bSAndreas Gohr 8341*72b2703bSAndreas Gohr[ref]: /uri 8342*72b2703bSAndreas Gohr. 8343*72b2703bSAndreas Gohr<p>[foo <bar attr="][ref]"></p> 8344*72b2703bSAndreas Gohr```````````````````````````````` 8345*72b2703bSAndreas Gohr 8346*72b2703bSAndreas Gohr 8347*72b2703bSAndreas Gohr```````````````````````````````` example 8348*72b2703bSAndreas Gohr[foo`][ref]` 8349*72b2703bSAndreas Gohr 8350*72b2703bSAndreas Gohr[ref]: /uri 8351*72b2703bSAndreas Gohr. 8352*72b2703bSAndreas Gohr<p>[foo<code>][ref]</code></p> 8353*72b2703bSAndreas Gohr```````````````````````````````` 8354*72b2703bSAndreas Gohr 8355*72b2703bSAndreas Gohr 8356*72b2703bSAndreas Gohr```````````````````````````````` example 8357*72b2703bSAndreas Gohr[foo<http://example.com/?search=][ref]> 8358*72b2703bSAndreas Gohr 8359*72b2703bSAndreas Gohr[ref]: /uri 8360*72b2703bSAndreas Gohr. 8361*72b2703bSAndreas Gohr<p>[foo<a href="http://example.com/?search=%5D%5Bref%5D">http://example.com/?search=][ref]</a></p> 8362*72b2703bSAndreas Gohr```````````````````````````````` 8363*72b2703bSAndreas Gohr 8364*72b2703bSAndreas Gohr 8365*72b2703bSAndreas GohrMatching is case-insensitive: 8366*72b2703bSAndreas Gohr 8367*72b2703bSAndreas Gohr```````````````````````````````` example 8368*72b2703bSAndreas Gohr[foo][BaR] 8369*72b2703bSAndreas Gohr 8370*72b2703bSAndreas Gohr[bar]: /url "title" 8371*72b2703bSAndreas Gohr. 8372*72b2703bSAndreas Gohr<p><a href="/url" title="title">foo</a></p> 8373*72b2703bSAndreas Gohr```````````````````````````````` 8374*72b2703bSAndreas Gohr 8375*72b2703bSAndreas Gohr 8376*72b2703bSAndreas GohrUnicode case fold is used: 8377*72b2703bSAndreas Gohr 8378*72b2703bSAndreas Gohr```````````````````````````````` example 8379*72b2703bSAndreas Gohr[Толпой][Толпой] is a Russian word. 8380*72b2703bSAndreas Gohr 8381*72b2703bSAndreas Gohr[ТОЛПОЙ]: /url 8382*72b2703bSAndreas Gohr. 8383*72b2703bSAndreas Gohr<p><a href="/url">Толпой</a> is a Russian word.</p> 8384*72b2703bSAndreas Gohr```````````````````````````````` 8385*72b2703bSAndreas Gohr 8386*72b2703bSAndreas Gohr 8387*72b2703bSAndreas GohrConsecutive internal [whitespace] is treated as one space for 8388*72b2703bSAndreas Gohrpurposes of determining matching: 8389*72b2703bSAndreas Gohr 8390*72b2703bSAndreas Gohr```````````````````````````````` example 8391*72b2703bSAndreas Gohr[Foo 8392*72b2703bSAndreas Gohr bar]: /url 8393*72b2703bSAndreas Gohr 8394*72b2703bSAndreas Gohr[Baz][Foo bar] 8395*72b2703bSAndreas Gohr. 8396*72b2703bSAndreas Gohr<p><a href="/url">Baz</a></p> 8397*72b2703bSAndreas Gohr```````````````````````````````` 8398*72b2703bSAndreas Gohr 8399*72b2703bSAndreas Gohr 8400*72b2703bSAndreas GohrNo [whitespace] is allowed between the [link text] and the 8401*72b2703bSAndreas Gohr[link label]: 8402*72b2703bSAndreas Gohr 8403*72b2703bSAndreas Gohr```````````````````````````````` example 8404*72b2703bSAndreas Gohr[foo] [bar] 8405*72b2703bSAndreas Gohr 8406*72b2703bSAndreas Gohr[bar]: /url "title" 8407*72b2703bSAndreas Gohr. 8408*72b2703bSAndreas Gohr<p>[foo] <a href="/url" title="title">bar</a></p> 8409*72b2703bSAndreas Gohr```````````````````````````````` 8410*72b2703bSAndreas Gohr 8411*72b2703bSAndreas Gohr 8412*72b2703bSAndreas Gohr```````````````````````````````` example 8413*72b2703bSAndreas Gohr[foo] 8414*72b2703bSAndreas Gohr[bar] 8415*72b2703bSAndreas Gohr 8416*72b2703bSAndreas Gohr[bar]: /url "title" 8417*72b2703bSAndreas Gohr. 8418*72b2703bSAndreas Gohr<p>[foo] 8419*72b2703bSAndreas Gohr<a href="/url" title="title">bar</a></p> 8420*72b2703bSAndreas Gohr```````````````````````````````` 8421*72b2703bSAndreas Gohr 8422*72b2703bSAndreas Gohr 8423*72b2703bSAndreas GohrThis is a departure from John Gruber's original Markdown syntax 8424*72b2703bSAndreas Gohrdescription, which explicitly allows whitespace between the link 8425*72b2703bSAndreas Gohrtext and the link label. It brings reference links in line with 8426*72b2703bSAndreas Gohr[inline links], which (according to both original Markdown and 8427*72b2703bSAndreas Gohrthis spec) cannot have whitespace after the link text. More 8428*72b2703bSAndreas Gohrimportantly, it prevents inadvertent capture of consecutive 8429*72b2703bSAndreas Gohr[shortcut reference links]. If whitespace is allowed between the 8430*72b2703bSAndreas Gohrlink text and the link label, then in the following we will have 8431*72b2703bSAndreas Gohra single reference link, not two shortcut reference links, as 8432*72b2703bSAndreas Gohrintended: 8433*72b2703bSAndreas Gohr 8434*72b2703bSAndreas Gohr``` markdown 8435*72b2703bSAndreas Gohr[foo] 8436*72b2703bSAndreas Gohr[bar] 8437*72b2703bSAndreas Gohr 8438*72b2703bSAndreas Gohr[foo]: /url1 8439*72b2703bSAndreas Gohr[bar]: /url2 8440*72b2703bSAndreas Gohr``` 8441*72b2703bSAndreas Gohr 8442*72b2703bSAndreas Gohr(Note that [shortcut reference links] were introduced by Gruber 8443*72b2703bSAndreas Gohrhimself in a beta version of `Markdown.pl`, but never included 8444*72b2703bSAndreas Gohrin the official syntax description. Without shortcut reference 8445*72b2703bSAndreas Gohrlinks, it is harmless to allow space between the link text and 8446*72b2703bSAndreas Gohrlink label; but once shortcut references are introduced, it is 8447*72b2703bSAndreas Gohrtoo dangerous to allow this, as it frequently leads to 8448*72b2703bSAndreas Gohrunintended results.) 8449*72b2703bSAndreas Gohr 8450*72b2703bSAndreas GohrWhen there are multiple matching [link reference definitions], 8451*72b2703bSAndreas Gohrthe first is used: 8452*72b2703bSAndreas Gohr 8453*72b2703bSAndreas Gohr```````````````````````````````` example 8454*72b2703bSAndreas Gohr[foo]: /url1 8455*72b2703bSAndreas Gohr 8456*72b2703bSAndreas Gohr[foo]: /url2 8457*72b2703bSAndreas Gohr 8458*72b2703bSAndreas Gohr[bar][foo] 8459*72b2703bSAndreas Gohr. 8460*72b2703bSAndreas Gohr<p><a href="/url1">bar</a></p> 8461*72b2703bSAndreas Gohr```````````````````````````````` 8462*72b2703bSAndreas Gohr 8463*72b2703bSAndreas Gohr 8464*72b2703bSAndreas GohrNote that matching is performed on normalized strings, not parsed 8465*72b2703bSAndreas Gohrinline content. So the following does not match, even though the 8466*72b2703bSAndreas Gohrlabels define equivalent inline content: 8467*72b2703bSAndreas Gohr 8468*72b2703bSAndreas Gohr```````````````````````````````` example 8469*72b2703bSAndreas Gohr[bar][foo\!] 8470*72b2703bSAndreas Gohr 8471*72b2703bSAndreas Gohr[foo!]: /url 8472*72b2703bSAndreas Gohr. 8473*72b2703bSAndreas Gohr<p>[bar][foo!]</p> 8474*72b2703bSAndreas Gohr```````````````````````````````` 8475*72b2703bSAndreas Gohr 8476*72b2703bSAndreas Gohr 8477*72b2703bSAndreas Gohr[Link labels] cannot contain brackets, unless they are 8478*72b2703bSAndreas Gohrbackslash-escaped: 8479*72b2703bSAndreas Gohr 8480*72b2703bSAndreas Gohr```````````````````````````````` example 8481*72b2703bSAndreas Gohr[foo][ref[] 8482*72b2703bSAndreas Gohr 8483*72b2703bSAndreas Gohr[ref[]: /uri 8484*72b2703bSAndreas Gohr. 8485*72b2703bSAndreas Gohr<p>[foo][ref[]</p> 8486*72b2703bSAndreas Gohr<p>[ref[]: /uri</p> 8487*72b2703bSAndreas Gohr```````````````````````````````` 8488*72b2703bSAndreas Gohr 8489*72b2703bSAndreas Gohr 8490*72b2703bSAndreas Gohr```````````````````````````````` example 8491*72b2703bSAndreas Gohr[foo][ref[bar]] 8492*72b2703bSAndreas Gohr 8493*72b2703bSAndreas Gohr[ref[bar]]: /uri 8494*72b2703bSAndreas Gohr. 8495*72b2703bSAndreas Gohr<p>[foo][ref[bar]]</p> 8496*72b2703bSAndreas Gohr<p>[ref[bar]]: /uri</p> 8497*72b2703bSAndreas Gohr```````````````````````````````` 8498*72b2703bSAndreas Gohr 8499*72b2703bSAndreas Gohr 8500*72b2703bSAndreas Gohr```````````````````````````````` example 8501*72b2703bSAndreas Gohr[[[foo]]] 8502*72b2703bSAndreas Gohr 8503*72b2703bSAndreas Gohr[[[foo]]]: /url 8504*72b2703bSAndreas Gohr. 8505*72b2703bSAndreas Gohr<p>[[[foo]]]</p> 8506*72b2703bSAndreas Gohr<p>[[[foo]]]: /url</p> 8507*72b2703bSAndreas Gohr```````````````````````````````` 8508*72b2703bSAndreas Gohr 8509*72b2703bSAndreas Gohr 8510*72b2703bSAndreas Gohr```````````````````````````````` example 8511*72b2703bSAndreas Gohr[foo][ref\[] 8512*72b2703bSAndreas Gohr 8513*72b2703bSAndreas Gohr[ref\[]: /uri 8514*72b2703bSAndreas Gohr. 8515*72b2703bSAndreas Gohr<p><a href="/uri">foo</a></p> 8516*72b2703bSAndreas Gohr```````````````````````````````` 8517*72b2703bSAndreas Gohr 8518*72b2703bSAndreas Gohr 8519*72b2703bSAndreas GohrNote that in this example `]` is not backslash-escaped: 8520*72b2703bSAndreas Gohr 8521*72b2703bSAndreas Gohr```````````````````````````````` example 8522*72b2703bSAndreas Gohr[bar\\]: /uri 8523*72b2703bSAndreas Gohr 8524*72b2703bSAndreas Gohr[bar\\] 8525*72b2703bSAndreas Gohr. 8526*72b2703bSAndreas Gohr<p><a href="/uri">bar\</a></p> 8527*72b2703bSAndreas Gohr```````````````````````````````` 8528*72b2703bSAndreas Gohr 8529*72b2703bSAndreas Gohr 8530*72b2703bSAndreas GohrA [link label] must contain at least one [non-whitespace character]: 8531*72b2703bSAndreas Gohr 8532*72b2703bSAndreas Gohr```````````````````````````````` example 8533*72b2703bSAndreas Gohr[] 8534*72b2703bSAndreas Gohr 8535*72b2703bSAndreas Gohr[]: /uri 8536*72b2703bSAndreas Gohr. 8537*72b2703bSAndreas Gohr<p>[]</p> 8538*72b2703bSAndreas Gohr<p>[]: /uri</p> 8539*72b2703bSAndreas Gohr```````````````````````````````` 8540*72b2703bSAndreas Gohr 8541*72b2703bSAndreas Gohr 8542*72b2703bSAndreas Gohr```````````````````````````````` example 8543*72b2703bSAndreas Gohr[ 8544*72b2703bSAndreas Gohr ] 8545*72b2703bSAndreas Gohr 8546*72b2703bSAndreas Gohr[ 8547*72b2703bSAndreas Gohr ]: /uri 8548*72b2703bSAndreas Gohr. 8549*72b2703bSAndreas Gohr<p>[ 8550*72b2703bSAndreas Gohr]</p> 8551*72b2703bSAndreas Gohr<p>[ 8552*72b2703bSAndreas Gohr]: /uri</p> 8553*72b2703bSAndreas Gohr```````````````````````````````` 8554*72b2703bSAndreas Gohr 8555*72b2703bSAndreas Gohr 8556*72b2703bSAndreas GohrA [collapsed reference link](@) 8557*72b2703bSAndreas Gohrconsists of a [link label] that [matches] a 8558*72b2703bSAndreas Gohr[link reference definition] elsewhere in the 8559*72b2703bSAndreas Gohrdocument, followed by the string `[]`. 8560*72b2703bSAndreas GohrThe contents of the first link label are parsed as inlines, 8561*72b2703bSAndreas Gohrwhich are used as the link's text. The link's URI and title are 8562*72b2703bSAndreas Gohrprovided by the matching reference link definition. Thus, 8563*72b2703bSAndreas Gohr`[foo][]` is equivalent to `[foo][foo]`. 8564*72b2703bSAndreas Gohr 8565*72b2703bSAndreas Gohr```````````````````````````````` example 8566*72b2703bSAndreas Gohr[foo][] 8567*72b2703bSAndreas Gohr 8568*72b2703bSAndreas Gohr[foo]: /url "title" 8569*72b2703bSAndreas Gohr. 8570*72b2703bSAndreas Gohr<p><a href="/url" title="title">foo</a></p> 8571*72b2703bSAndreas Gohr```````````````````````````````` 8572*72b2703bSAndreas Gohr 8573*72b2703bSAndreas Gohr 8574*72b2703bSAndreas Gohr```````````````````````````````` example 8575*72b2703bSAndreas Gohr[*foo* bar][] 8576*72b2703bSAndreas Gohr 8577*72b2703bSAndreas Gohr[*foo* bar]: /url "title" 8578*72b2703bSAndreas Gohr. 8579*72b2703bSAndreas Gohr<p><a href="/url" title="title"><em>foo</em> bar</a></p> 8580*72b2703bSAndreas Gohr```````````````````````````````` 8581*72b2703bSAndreas Gohr 8582*72b2703bSAndreas Gohr 8583*72b2703bSAndreas GohrThe link labels are case-insensitive: 8584*72b2703bSAndreas Gohr 8585*72b2703bSAndreas Gohr```````````````````````````````` example 8586*72b2703bSAndreas Gohr[Foo][] 8587*72b2703bSAndreas Gohr 8588*72b2703bSAndreas Gohr[foo]: /url "title" 8589*72b2703bSAndreas Gohr. 8590*72b2703bSAndreas Gohr<p><a href="/url" title="title">Foo</a></p> 8591*72b2703bSAndreas Gohr```````````````````````````````` 8592*72b2703bSAndreas Gohr 8593*72b2703bSAndreas Gohr 8594*72b2703bSAndreas Gohr 8595*72b2703bSAndreas GohrAs with full reference links, [whitespace] is not 8596*72b2703bSAndreas Gohrallowed between the two sets of brackets: 8597*72b2703bSAndreas Gohr 8598*72b2703bSAndreas Gohr```````````````````````````````` example 8599*72b2703bSAndreas Gohr[foo] 8600*72b2703bSAndreas Gohr[] 8601*72b2703bSAndreas Gohr 8602*72b2703bSAndreas Gohr[foo]: /url "title" 8603*72b2703bSAndreas Gohr. 8604*72b2703bSAndreas Gohr<p><a href="/url" title="title">foo</a> 8605*72b2703bSAndreas Gohr[]</p> 8606*72b2703bSAndreas Gohr```````````````````````````````` 8607*72b2703bSAndreas Gohr 8608*72b2703bSAndreas Gohr 8609*72b2703bSAndreas GohrA [shortcut reference link](@) 8610*72b2703bSAndreas Gohrconsists of a [link label] that [matches] a 8611*72b2703bSAndreas Gohr[link reference definition] elsewhere in the 8612*72b2703bSAndreas Gohrdocument and is not followed by `[]` or a link label. 8613*72b2703bSAndreas GohrThe contents of the first link label are parsed as inlines, 8614*72b2703bSAndreas Gohrwhich are used as the link's text. The link's URI and title 8615*72b2703bSAndreas Gohrare provided by the matching link reference definition. 8616*72b2703bSAndreas GohrThus, `[foo]` is equivalent to `[foo][]`. 8617*72b2703bSAndreas Gohr 8618*72b2703bSAndreas Gohr```````````````````````````````` example 8619*72b2703bSAndreas Gohr[foo] 8620*72b2703bSAndreas Gohr 8621*72b2703bSAndreas Gohr[foo]: /url "title" 8622*72b2703bSAndreas Gohr. 8623*72b2703bSAndreas Gohr<p><a href="/url" title="title">foo</a></p> 8624*72b2703bSAndreas Gohr```````````````````````````````` 8625*72b2703bSAndreas Gohr 8626*72b2703bSAndreas Gohr 8627*72b2703bSAndreas Gohr```````````````````````````````` example 8628*72b2703bSAndreas Gohr[*foo* bar] 8629*72b2703bSAndreas Gohr 8630*72b2703bSAndreas Gohr[*foo* bar]: /url "title" 8631*72b2703bSAndreas Gohr. 8632*72b2703bSAndreas Gohr<p><a href="/url" title="title"><em>foo</em> bar</a></p> 8633*72b2703bSAndreas Gohr```````````````````````````````` 8634*72b2703bSAndreas Gohr 8635*72b2703bSAndreas Gohr 8636*72b2703bSAndreas Gohr```````````````````````````````` example 8637*72b2703bSAndreas Gohr[[*foo* bar]] 8638*72b2703bSAndreas Gohr 8639*72b2703bSAndreas Gohr[*foo* bar]: /url "title" 8640*72b2703bSAndreas Gohr. 8641*72b2703bSAndreas Gohr<p>[<a href="/url" title="title"><em>foo</em> bar</a>]</p> 8642*72b2703bSAndreas Gohr```````````````````````````````` 8643*72b2703bSAndreas Gohr 8644*72b2703bSAndreas Gohr 8645*72b2703bSAndreas Gohr```````````````````````````````` example 8646*72b2703bSAndreas Gohr[[bar [foo] 8647*72b2703bSAndreas Gohr 8648*72b2703bSAndreas Gohr[foo]: /url 8649*72b2703bSAndreas Gohr. 8650*72b2703bSAndreas Gohr<p>[[bar <a href="/url">foo</a></p> 8651*72b2703bSAndreas Gohr```````````````````````````````` 8652*72b2703bSAndreas Gohr 8653*72b2703bSAndreas Gohr 8654*72b2703bSAndreas GohrThe link labels are case-insensitive: 8655*72b2703bSAndreas Gohr 8656*72b2703bSAndreas Gohr```````````````````````````````` example 8657*72b2703bSAndreas Gohr[Foo] 8658*72b2703bSAndreas Gohr 8659*72b2703bSAndreas Gohr[foo]: /url "title" 8660*72b2703bSAndreas Gohr. 8661*72b2703bSAndreas Gohr<p><a href="/url" title="title">Foo</a></p> 8662*72b2703bSAndreas Gohr```````````````````````````````` 8663*72b2703bSAndreas Gohr 8664*72b2703bSAndreas Gohr 8665*72b2703bSAndreas GohrA space after the link text should be preserved: 8666*72b2703bSAndreas Gohr 8667*72b2703bSAndreas Gohr```````````````````````````````` example 8668*72b2703bSAndreas Gohr[foo] bar 8669*72b2703bSAndreas Gohr 8670*72b2703bSAndreas Gohr[foo]: /url 8671*72b2703bSAndreas Gohr. 8672*72b2703bSAndreas Gohr<p><a href="/url">foo</a> bar</p> 8673*72b2703bSAndreas Gohr```````````````````````````````` 8674*72b2703bSAndreas Gohr 8675*72b2703bSAndreas Gohr 8676*72b2703bSAndreas GohrIf you just want bracketed text, you can backslash-escape the 8677*72b2703bSAndreas Gohropening bracket to avoid links: 8678*72b2703bSAndreas Gohr 8679*72b2703bSAndreas Gohr```````````````````````````````` example 8680*72b2703bSAndreas Gohr\[foo] 8681*72b2703bSAndreas Gohr 8682*72b2703bSAndreas Gohr[foo]: /url "title" 8683*72b2703bSAndreas Gohr. 8684*72b2703bSAndreas Gohr<p>[foo]</p> 8685*72b2703bSAndreas Gohr```````````````````````````````` 8686*72b2703bSAndreas Gohr 8687*72b2703bSAndreas Gohr 8688*72b2703bSAndreas GohrNote that this is a link, because a link label ends with the first 8689*72b2703bSAndreas Gohrfollowing closing bracket: 8690*72b2703bSAndreas Gohr 8691*72b2703bSAndreas Gohr```````````````````````````````` example 8692*72b2703bSAndreas Gohr[foo*]: /url 8693*72b2703bSAndreas Gohr 8694*72b2703bSAndreas Gohr*[foo*] 8695*72b2703bSAndreas Gohr. 8696*72b2703bSAndreas Gohr<p>*<a href="/url">foo*</a></p> 8697*72b2703bSAndreas Gohr```````````````````````````````` 8698*72b2703bSAndreas Gohr 8699*72b2703bSAndreas Gohr 8700*72b2703bSAndreas GohrFull and compact references take precedence over shortcut 8701*72b2703bSAndreas Gohrreferences: 8702*72b2703bSAndreas Gohr 8703*72b2703bSAndreas Gohr```````````````````````````````` example 8704*72b2703bSAndreas Gohr[foo][bar] 8705*72b2703bSAndreas Gohr 8706*72b2703bSAndreas Gohr[foo]: /url1 8707*72b2703bSAndreas Gohr[bar]: /url2 8708*72b2703bSAndreas Gohr. 8709*72b2703bSAndreas Gohr<p><a href="/url2">foo</a></p> 8710*72b2703bSAndreas Gohr```````````````````````````````` 8711*72b2703bSAndreas Gohr 8712*72b2703bSAndreas Gohr```````````````````````````````` example 8713*72b2703bSAndreas Gohr[foo][] 8714*72b2703bSAndreas Gohr 8715*72b2703bSAndreas Gohr[foo]: /url1 8716*72b2703bSAndreas Gohr. 8717*72b2703bSAndreas Gohr<p><a href="/url1">foo</a></p> 8718*72b2703bSAndreas Gohr```````````````````````````````` 8719*72b2703bSAndreas Gohr 8720*72b2703bSAndreas GohrInline links also take precedence: 8721*72b2703bSAndreas Gohr 8722*72b2703bSAndreas Gohr```````````````````````````````` example 8723*72b2703bSAndreas Gohr[foo]() 8724*72b2703bSAndreas Gohr 8725*72b2703bSAndreas Gohr[foo]: /url1 8726*72b2703bSAndreas Gohr. 8727*72b2703bSAndreas Gohr<p><a href="">foo</a></p> 8728*72b2703bSAndreas Gohr```````````````````````````````` 8729*72b2703bSAndreas Gohr 8730*72b2703bSAndreas Gohr```````````````````````````````` example 8731*72b2703bSAndreas Gohr[foo](not a link) 8732*72b2703bSAndreas Gohr 8733*72b2703bSAndreas Gohr[foo]: /url1 8734*72b2703bSAndreas Gohr. 8735*72b2703bSAndreas Gohr<p><a href="/url1">foo</a>(not a link)</p> 8736*72b2703bSAndreas Gohr```````````````````````````````` 8737*72b2703bSAndreas Gohr 8738*72b2703bSAndreas GohrIn the following case `[bar][baz]` is parsed as a reference, 8739*72b2703bSAndreas Gohr`[foo]` as normal text: 8740*72b2703bSAndreas Gohr 8741*72b2703bSAndreas Gohr```````````````````````````````` example 8742*72b2703bSAndreas Gohr[foo][bar][baz] 8743*72b2703bSAndreas Gohr 8744*72b2703bSAndreas Gohr[baz]: /url 8745*72b2703bSAndreas Gohr. 8746*72b2703bSAndreas Gohr<p>[foo]<a href="/url">bar</a></p> 8747*72b2703bSAndreas Gohr```````````````````````````````` 8748*72b2703bSAndreas Gohr 8749*72b2703bSAndreas Gohr 8750*72b2703bSAndreas GohrHere, though, `[foo][bar]` is parsed as a reference, since 8751*72b2703bSAndreas Gohr`[bar]` is defined: 8752*72b2703bSAndreas Gohr 8753*72b2703bSAndreas Gohr```````````````````````````````` example 8754*72b2703bSAndreas Gohr[foo][bar][baz] 8755*72b2703bSAndreas Gohr 8756*72b2703bSAndreas Gohr[baz]: /url1 8757*72b2703bSAndreas Gohr[bar]: /url2 8758*72b2703bSAndreas Gohr. 8759*72b2703bSAndreas Gohr<p><a href="/url2">foo</a><a href="/url1">baz</a></p> 8760*72b2703bSAndreas Gohr```````````````````````````````` 8761*72b2703bSAndreas Gohr 8762*72b2703bSAndreas Gohr 8763*72b2703bSAndreas GohrHere `[foo]` is not parsed as a shortcut reference, because it 8764*72b2703bSAndreas Gohris followed by a link label (even though `[bar]` is not defined): 8765*72b2703bSAndreas Gohr 8766*72b2703bSAndreas Gohr```````````````````````````````` example 8767*72b2703bSAndreas Gohr[foo][bar][baz] 8768*72b2703bSAndreas Gohr 8769*72b2703bSAndreas Gohr[baz]: /url1 8770*72b2703bSAndreas Gohr[foo]: /url2 8771*72b2703bSAndreas Gohr. 8772*72b2703bSAndreas Gohr<p>[foo]<a href="/url1">bar</a></p> 8773*72b2703bSAndreas Gohr```````````````````````````````` 8774*72b2703bSAndreas Gohr 8775*72b2703bSAndreas Gohr 8776*72b2703bSAndreas Gohr 8777*72b2703bSAndreas Gohr## Images 8778*72b2703bSAndreas Gohr 8779*72b2703bSAndreas GohrSyntax for images is like the syntax for links, with one 8780*72b2703bSAndreas Gohrdifference. Instead of [link text], we have an 8781*72b2703bSAndreas Gohr[image description](@). The rules for this are the 8782*72b2703bSAndreas Gohrsame as for [link text], except that (a) an 8783*72b2703bSAndreas Gohrimage description starts with ` 8791*72b2703bSAndreas Gohr. 8792*72b2703bSAndreas Gohr<p><img src="/url" alt="foo" title="title" /></p> 8793*72b2703bSAndreas Gohr```````````````````````````````` 8794*72b2703bSAndreas Gohr 8795*72b2703bSAndreas Gohr 8796*72b2703bSAndreas Gohr```````````````````````````````` example 8797*72b2703bSAndreas Gohr![foo *bar*] 8798*72b2703bSAndreas Gohr 8799*72b2703bSAndreas Gohr[foo *bar*]: train.jpg "train & tracks" 8800*72b2703bSAndreas Gohr. 8801*72b2703bSAndreas Gohr<p><img src="train.jpg" alt="foo bar" title="train & tracks" /></p> 8802*72b2703bSAndreas Gohr```````````````````````````````` 8803*72b2703bSAndreas Gohr 8804*72b2703bSAndreas Gohr 8805*72b2703bSAndreas Gohr```````````````````````````````` example 8806*72b2703bSAndreas Gohr](/url2) 8807*72b2703bSAndreas Gohr. 8808*72b2703bSAndreas Gohr<p><img src="/url2" alt="foo bar" /></p> 8809*72b2703bSAndreas Gohr```````````````````````````````` 8810*72b2703bSAndreas Gohr 8811*72b2703bSAndreas Gohr 8812*72b2703bSAndreas Gohr```````````````````````````````` example 8813*72b2703bSAndreas Gohr](/url2) 8814*72b2703bSAndreas Gohr. 8815*72b2703bSAndreas Gohr<p><img src="/url2" alt="foo bar" /></p> 8816*72b2703bSAndreas Gohr```````````````````````````````` 8817*72b2703bSAndreas Gohr 8818*72b2703bSAndreas Gohr 8819*72b2703bSAndreas GohrThough this spec is concerned with parsing, not rendering, it is 8820*72b2703bSAndreas Gohrrecommended that in rendering to HTML, only the plain string content 8821*72b2703bSAndreas Gohrof the [image description] be used. Note that in 8822*72b2703bSAndreas Gohrthe above example, the alt attribute's value is `foo bar`, not `foo 8823*72b2703bSAndreas Gohr[bar](/url)` or `foo <a href="/url">bar</a>`. Only the plain string 8824*72b2703bSAndreas Gohrcontent is rendered, without formatting. 8825*72b2703bSAndreas Gohr 8826*72b2703bSAndreas Gohr```````````````````````````````` example 8827*72b2703bSAndreas Gohr![foo *bar*][] 8828*72b2703bSAndreas Gohr 8829*72b2703bSAndreas Gohr[foo *bar*]: train.jpg "train & tracks" 8830*72b2703bSAndreas Gohr. 8831*72b2703bSAndreas Gohr<p><img src="train.jpg" alt="foo bar" title="train & tracks" /></p> 8832*72b2703bSAndreas Gohr```````````````````````````````` 8833*72b2703bSAndreas Gohr 8834*72b2703bSAndreas Gohr 8835*72b2703bSAndreas Gohr```````````````````````````````` example 8836*72b2703bSAndreas Gohr![foo *bar*][foobar] 8837*72b2703bSAndreas Gohr 8838*72b2703bSAndreas Gohr[FOOBAR]: train.jpg "train & tracks" 8839*72b2703bSAndreas Gohr. 8840*72b2703bSAndreas Gohr<p><img src="train.jpg" alt="foo bar" title="train & tracks" /></p> 8841*72b2703bSAndreas Gohr```````````````````````````````` 8842*72b2703bSAndreas Gohr 8843*72b2703bSAndreas Gohr 8844*72b2703bSAndreas Gohr```````````````````````````````` example 8845*72b2703bSAndreas Gohr 8846*72b2703bSAndreas Gohr. 8847*72b2703bSAndreas Gohr<p><img src="train.jpg" alt="foo" /></p> 8848*72b2703bSAndreas Gohr```````````````````````````````` 8849*72b2703bSAndreas Gohr 8850*72b2703bSAndreas Gohr 8851*72b2703bSAndreas Gohr```````````````````````````````` example 8852*72b2703bSAndreas GohrMy  8853*72b2703bSAndreas Gohr. 8854*72b2703bSAndreas Gohr<p>My <img src="/path/to/train.jpg" alt="foo bar" title="title" /></p> 8855*72b2703bSAndreas Gohr```````````````````````````````` 8856*72b2703bSAndreas Gohr 8857*72b2703bSAndreas Gohr 8858*72b2703bSAndreas Gohr```````````````````````````````` example 8859*72b2703bSAndreas Gohr 8860*72b2703bSAndreas Gohr. 8861*72b2703bSAndreas Gohr<p><img src="url" alt="foo" /></p> 8862*72b2703bSAndreas Gohr```````````````````````````````` 8863*72b2703bSAndreas Gohr 8864*72b2703bSAndreas Gohr 8865*72b2703bSAndreas Gohr```````````````````````````````` example 8866*72b2703bSAndreas Gohr 8867*72b2703bSAndreas Gohr. 8868*72b2703bSAndreas Gohr<p><img src="/url" alt="" /></p> 8869*72b2703bSAndreas Gohr```````````````````````````````` 8870*72b2703bSAndreas Gohr 8871*72b2703bSAndreas Gohr 8872*72b2703bSAndreas GohrReference-style: 8873*72b2703bSAndreas Gohr 8874*72b2703bSAndreas Gohr```````````````````````````````` example 8875*72b2703bSAndreas Gohr![foo][bar] 8876*72b2703bSAndreas Gohr 8877*72b2703bSAndreas Gohr[bar]: /url 8878*72b2703bSAndreas Gohr. 8879*72b2703bSAndreas Gohr<p><img src="/url" alt="foo" /></p> 8880*72b2703bSAndreas Gohr```````````````````````````````` 8881*72b2703bSAndreas Gohr 8882*72b2703bSAndreas Gohr 8883*72b2703bSAndreas Gohr```````````````````````````````` example 8884*72b2703bSAndreas Gohr![foo][bar] 8885*72b2703bSAndreas Gohr 8886*72b2703bSAndreas Gohr[BAR]: /url 8887*72b2703bSAndreas Gohr. 8888*72b2703bSAndreas Gohr<p><img src="/url" alt="foo" /></p> 8889*72b2703bSAndreas Gohr```````````````````````````````` 8890*72b2703bSAndreas Gohr 8891*72b2703bSAndreas Gohr 8892*72b2703bSAndreas GohrCollapsed: 8893*72b2703bSAndreas Gohr 8894*72b2703bSAndreas Gohr```````````````````````````````` example 8895*72b2703bSAndreas Gohr![foo][] 8896*72b2703bSAndreas Gohr 8897*72b2703bSAndreas Gohr[foo]: /url "title" 8898*72b2703bSAndreas Gohr. 8899*72b2703bSAndreas Gohr<p><img src="/url" alt="foo" title="title" /></p> 8900*72b2703bSAndreas Gohr```````````````````````````````` 8901*72b2703bSAndreas Gohr 8902*72b2703bSAndreas Gohr 8903*72b2703bSAndreas Gohr```````````````````````````````` example 8904*72b2703bSAndreas Gohr![*foo* bar][] 8905*72b2703bSAndreas Gohr 8906*72b2703bSAndreas Gohr[*foo* bar]: /url "title" 8907*72b2703bSAndreas Gohr. 8908*72b2703bSAndreas Gohr<p><img src="/url" alt="foo bar" title="title" /></p> 8909*72b2703bSAndreas Gohr```````````````````````````````` 8910*72b2703bSAndreas Gohr 8911*72b2703bSAndreas Gohr 8912*72b2703bSAndreas GohrThe labels are case-insensitive: 8913*72b2703bSAndreas Gohr 8914*72b2703bSAndreas Gohr```````````````````````````````` example 8915*72b2703bSAndreas Gohr![Foo][] 8916*72b2703bSAndreas Gohr 8917*72b2703bSAndreas Gohr[foo]: /url "title" 8918*72b2703bSAndreas Gohr. 8919*72b2703bSAndreas Gohr<p><img src="/url" alt="Foo" title="title" /></p> 8920*72b2703bSAndreas Gohr```````````````````````````````` 8921*72b2703bSAndreas Gohr 8922*72b2703bSAndreas Gohr 8923*72b2703bSAndreas GohrAs with reference links, [whitespace] is not allowed 8924*72b2703bSAndreas Gohrbetween the two sets of brackets: 8925*72b2703bSAndreas Gohr 8926*72b2703bSAndreas Gohr```````````````````````````````` example 8927*72b2703bSAndreas Gohr![foo] 8928*72b2703bSAndreas Gohr[] 8929*72b2703bSAndreas Gohr 8930*72b2703bSAndreas Gohr[foo]: /url "title" 8931*72b2703bSAndreas Gohr. 8932*72b2703bSAndreas Gohr<p><img src="/url" alt="foo" title="title" /> 8933*72b2703bSAndreas Gohr[]</p> 8934*72b2703bSAndreas Gohr```````````````````````````````` 8935*72b2703bSAndreas Gohr 8936*72b2703bSAndreas Gohr 8937*72b2703bSAndreas GohrShortcut: 8938*72b2703bSAndreas Gohr 8939*72b2703bSAndreas Gohr```````````````````````````````` example 8940*72b2703bSAndreas Gohr![foo] 8941*72b2703bSAndreas Gohr 8942*72b2703bSAndreas Gohr[foo]: /url "title" 8943*72b2703bSAndreas Gohr. 8944*72b2703bSAndreas Gohr<p><img src="/url" alt="foo" title="title" /></p> 8945*72b2703bSAndreas Gohr```````````````````````````````` 8946*72b2703bSAndreas Gohr 8947*72b2703bSAndreas Gohr 8948*72b2703bSAndreas Gohr```````````````````````````````` example 8949*72b2703bSAndreas Gohr![*foo* bar] 8950*72b2703bSAndreas Gohr 8951*72b2703bSAndreas Gohr[*foo* bar]: /url "title" 8952*72b2703bSAndreas Gohr. 8953*72b2703bSAndreas Gohr<p><img src="/url" alt="foo bar" title="title" /></p> 8954*72b2703bSAndreas Gohr```````````````````````````````` 8955*72b2703bSAndreas Gohr 8956*72b2703bSAndreas Gohr 8957*72b2703bSAndreas GohrNote that link labels cannot contain unescaped brackets: 8958*72b2703bSAndreas Gohr 8959*72b2703bSAndreas Gohr```````````````````````````````` example 8960*72b2703bSAndreas Gohr![[foo]] 8961*72b2703bSAndreas Gohr 8962*72b2703bSAndreas Gohr[[foo]]: /url "title" 8963*72b2703bSAndreas Gohr. 8964*72b2703bSAndreas Gohr<p>![[foo]]</p> 8965*72b2703bSAndreas Gohr<p>[[foo]]: /url "title"</p> 8966*72b2703bSAndreas Gohr```````````````````````````````` 8967*72b2703bSAndreas Gohr 8968*72b2703bSAndreas Gohr 8969*72b2703bSAndreas GohrThe link labels are case-insensitive: 8970*72b2703bSAndreas Gohr 8971*72b2703bSAndreas Gohr```````````````````````````````` example 8972*72b2703bSAndreas Gohr![Foo] 8973*72b2703bSAndreas Gohr 8974*72b2703bSAndreas Gohr[foo]: /url "title" 8975*72b2703bSAndreas Gohr. 8976*72b2703bSAndreas Gohr<p><img src="/url" alt="Foo" title="title" /></p> 8977*72b2703bSAndreas Gohr```````````````````````````````` 8978*72b2703bSAndreas Gohr 8979*72b2703bSAndreas Gohr 8980*72b2703bSAndreas GohrIf you just want a literal `!` followed by bracketed text, you can 8981*72b2703bSAndreas Gohrbackslash-escape the opening `[`: 8982*72b2703bSAndreas Gohr 8983*72b2703bSAndreas Gohr```````````````````````````````` example 8984*72b2703bSAndreas Gohr!\[foo] 8985*72b2703bSAndreas Gohr 8986*72b2703bSAndreas Gohr[foo]: /url "title" 8987*72b2703bSAndreas Gohr. 8988*72b2703bSAndreas Gohr<p>![foo]</p> 8989*72b2703bSAndreas Gohr```````````````````````````````` 8990*72b2703bSAndreas Gohr 8991*72b2703bSAndreas Gohr 8992*72b2703bSAndreas GohrIf you want a link after a literal `!`, backslash-escape the 8993*72b2703bSAndreas Gohr`!`: 8994*72b2703bSAndreas Gohr 8995*72b2703bSAndreas Gohr```````````````````````````````` example 8996*72b2703bSAndreas Gohr\![foo] 8997*72b2703bSAndreas Gohr 8998*72b2703bSAndreas Gohr[foo]: /url "title" 8999*72b2703bSAndreas Gohr. 9000*72b2703bSAndreas Gohr<p>!<a href="/url" title="title">foo</a></p> 9001*72b2703bSAndreas Gohr```````````````````````````````` 9002*72b2703bSAndreas Gohr 9003*72b2703bSAndreas Gohr 9004*72b2703bSAndreas Gohr## Autolinks 9005*72b2703bSAndreas Gohr 9006*72b2703bSAndreas Gohr[Autolink](@)s are absolute URIs and email addresses inside 9007*72b2703bSAndreas Gohr`<` and `>`. They are parsed as links, with the URL or email address 9008*72b2703bSAndreas Gohras the link label. 9009*72b2703bSAndreas Gohr 9010*72b2703bSAndreas GohrA [URI autolink](@) consists of `<`, followed by an 9011*72b2703bSAndreas Gohr[absolute URI] followed by `>`. It is parsed as 9012*72b2703bSAndreas Gohra link to the URI, with the URI as the link's label. 9013*72b2703bSAndreas Gohr 9014*72b2703bSAndreas GohrAn [absolute URI](@), 9015*72b2703bSAndreas Gohrfor these purposes, consists of a [scheme] followed by a colon (`:`) 9016*72b2703bSAndreas Gohrfollowed by zero or more characters other than ASCII 9017*72b2703bSAndreas Gohr[whitespace] and control characters, `<`, and `>`. If 9018*72b2703bSAndreas Gohrthe URI includes these characters, they must be percent-encoded 9019*72b2703bSAndreas Gohr(e.g. `%20` for a space). 9020*72b2703bSAndreas Gohr 9021*72b2703bSAndreas GohrFor purposes of this spec, a [scheme](@) is any sequence 9022*72b2703bSAndreas Gohrof 2--32 characters beginning with an ASCII letter and followed 9023*72b2703bSAndreas Gohrby any combination of ASCII letters, digits, or the symbols plus 9024*72b2703bSAndreas Gohr("+"), period ("."), or hyphen ("-"). 9025*72b2703bSAndreas Gohr 9026*72b2703bSAndreas GohrHere are some valid autolinks: 9027*72b2703bSAndreas Gohr 9028*72b2703bSAndreas Gohr```````````````````````````````` example 9029*72b2703bSAndreas Gohr<http://foo.bar.baz> 9030*72b2703bSAndreas Gohr. 9031*72b2703bSAndreas Gohr<p><a href="http://foo.bar.baz">http://foo.bar.baz</a></p> 9032*72b2703bSAndreas Gohr```````````````````````````````` 9033*72b2703bSAndreas Gohr 9034*72b2703bSAndreas Gohr 9035*72b2703bSAndreas Gohr```````````````````````````````` example 9036*72b2703bSAndreas Gohr<http://foo.bar.baz/test?q=hello&id=22&boolean> 9037*72b2703bSAndreas Gohr. 9038*72b2703bSAndreas Gohr<p><a href="http://foo.bar.baz/test?q=hello&id=22&boolean">http://foo.bar.baz/test?q=hello&id=22&boolean</a></p> 9039*72b2703bSAndreas Gohr```````````````````````````````` 9040*72b2703bSAndreas Gohr 9041*72b2703bSAndreas Gohr 9042*72b2703bSAndreas Gohr```````````````````````````````` example 9043*72b2703bSAndreas Gohr<irc://foo.bar:2233/baz> 9044*72b2703bSAndreas Gohr. 9045*72b2703bSAndreas Gohr<p><a href="irc://foo.bar:2233/baz">irc://foo.bar:2233/baz</a></p> 9046*72b2703bSAndreas Gohr```````````````````````````````` 9047*72b2703bSAndreas Gohr 9048*72b2703bSAndreas Gohr 9049*72b2703bSAndreas GohrUppercase is also fine: 9050*72b2703bSAndreas Gohr 9051*72b2703bSAndreas Gohr```````````````````````````````` example 9052*72b2703bSAndreas Gohr<MAILTO:FOO@BAR.BAZ> 9053*72b2703bSAndreas Gohr. 9054*72b2703bSAndreas Gohr<p><a href="MAILTO:FOO@BAR.BAZ">MAILTO:FOO@BAR.BAZ</a></p> 9055*72b2703bSAndreas Gohr```````````````````````````````` 9056*72b2703bSAndreas Gohr 9057*72b2703bSAndreas Gohr 9058*72b2703bSAndreas GohrNote that many strings that count as [absolute URIs] for 9059*72b2703bSAndreas Gohrpurposes of this spec are not valid URIs, because their 9060*72b2703bSAndreas Gohrschemes are not registered or because of other problems 9061*72b2703bSAndreas Gohrwith their syntax: 9062*72b2703bSAndreas Gohr 9063*72b2703bSAndreas Gohr```````````````````````````````` example 9064*72b2703bSAndreas Gohr<a+b+c:d> 9065*72b2703bSAndreas Gohr. 9066*72b2703bSAndreas Gohr<p><a href="a+b+c:d">a+b+c:d</a></p> 9067*72b2703bSAndreas Gohr```````````````````````````````` 9068*72b2703bSAndreas Gohr 9069*72b2703bSAndreas Gohr 9070*72b2703bSAndreas Gohr```````````````````````````````` example 9071*72b2703bSAndreas Gohr<made-up-scheme://foo,bar> 9072*72b2703bSAndreas Gohr. 9073*72b2703bSAndreas Gohr<p><a href="made-up-scheme://foo,bar">made-up-scheme://foo,bar</a></p> 9074*72b2703bSAndreas Gohr```````````````````````````````` 9075*72b2703bSAndreas Gohr 9076*72b2703bSAndreas Gohr 9077*72b2703bSAndreas Gohr```````````````````````````````` example 9078*72b2703bSAndreas Gohr<http://../> 9079*72b2703bSAndreas Gohr. 9080*72b2703bSAndreas Gohr<p><a href="http://../">http://../</a></p> 9081*72b2703bSAndreas Gohr```````````````````````````````` 9082*72b2703bSAndreas Gohr 9083*72b2703bSAndreas Gohr 9084*72b2703bSAndreas Gohr```````````````````````````````` example 9085*72b2703bSAndreas Gohr<localhost:5001/foo> 9086*72b2703bSAndreas Gohr. 9087*72b2703bSAndreas Gohr<p><a href="localhost:5001/foo">localhost:5001/foo</a></p> 9088*72b2703bSAndreas Gohr```````````````````````````````` 9089*72b2703bSAndreas Gohr 9090*72b2703bSAndreas Gohr 9091*72b2703bSAndreas GohrSpaces are not allowed in autolinks: 9092*72b2703bSAndreas Gohr 9093*72b2703bSAndreas Gohr```````````````````````````````` example 9094*72b2703bSAndreas Gohr<http://foo.bar/baz bim> 9095*72b2703bSAndreas Gohr. 9096*72b2703bSAndreas Gohr<p><http://foo.bar/baz bim></p> 9097*72b2703bSAndreas Gohr```````````````````````````````` 9098*72b2703bSAndreas Gohr 9099*72b2703bSAndreas Gohr 9100*72b2703bSAndreas GohrBackslash-escapes do not work inside autolinks: 9101*72b2703bSAndreas Gohr 9102*72b2703bSAndreas Gohr```````````````````````````````` example 9103*72b2703bSAndreas Gohr<http://example.com/\[\> 9104*72b2703bSAndreas Gohr. 9105*72b2703bSAndreas Gohr<p><a href="http://example.com/%5C%5B%5C">http://example.com/\[\</a></p> 9106*72b2703bSAndreas Gohr```````````````````````````````` 9107*72b2703bSAndreas Gohr 9108*72b2703bSAndreas Gohr 9109*72b2703bSAndreas GohrAn [email autolink](@) 9110*72b2703bSAndreas Gohrconsists of `<`, followed by an [email address], 9111*72b2703bSAndreas Gohrfollowed by `>`. The link's label is the email address, 9112*72b2703bSAndreas Gohrand the URL is `mailto:` followed by the email address. 9113*72b2703bSAndreas Gohr 9114*72b2703bSAndreas GohrAn [email address](@), 9115*72b2703bSAndreas Gohrfor these purposes, is anything that matches 9116*72b2703bSAndreas Gohrthe [non-normative regex from the HTML5 9117*72b2703bSAndreas Gohrspec](https://html.spec.whatwg.org/multipage/forms.html#e-mail-state-(type=email)): 9118*72b2703bSAndreas Gohr 9119*72b2703bSAndreas Gohr /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])? 9120*72b2703bSAndreas Gohr (?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/ 9121*72b2703bSAndreas Gohr 9122*72b2703bSAndreas GohrExamples of email autolinks: 9123*72b2703bSAndreas Gohr 9124*72b2703bSAndreas Gohr```````````````````````````````` example 9125*72b2703bSAndreas Gohr<foo@bar.example.com> 9126*72b2703bSAndreas Gohr. 9127*72b2703bSAndreas Gohr<p><a href="mailto:foo@bar.example.com">foo@bar.example.com</a></p> 9128*72b2703bSAndreas Gohr```````````````````````````````` 9129*72b2703bSAndreas Gohr 9130*72b2703bSAndreas Gohr 9131*72b2703bSAndreas Gohr```````````````````````````````` example 9132*72b2703bSAndreas Gohr<foo+special@Bar.baz-bar0.com> 9133*72b2703bSAndreas Gohr. 9134*72b2703bSAndreas Gohr<p><a href="mailto:foo+special@Bar.baz-bar0.com">foo+special@Bar.baz-bar0.com</a></p> 9135*72b2703bSAndreas Gohr```````````````````````````````` 9136*72b2703bSAndreas Gohr 9137*72b2703bSAndreas Gohr 9138*72b2703bSAndreas GohrBackslash-escapes do not work inside email autolinks: 9139*72b2703bSAndreas Gohr 9140*72b2703bSAndreas Gohr```````````````````````````````` example 9141*72b2703bSAndreas Gohr<foo\+@bar.example.com> 9142*72b2703bSAndreas Gohr. 9143*72b2703bSAndreas Gohr<p><foo+@bar.example.com></p> 9144*72b2703bSAndreas Gohr```````````````````````````````` 9145*72b2703bSAndreas Gohr 9146*72b2703bSAndreas Gohr 9147*72b2703bSAndreas GohrThese are not autolinks: 9148*72b2703bSAndreas Gohr 9149*72b2703bSAndreas Gohr```````````````````````````````` example 9150*72b2703bSAndreas Gohr<> 9151*72b2703bSAndreas Gohr. 9152*72b2703bSAndreas Gohr<p><></p> 9153*72b2703bSAndreas Gohr```````````````````````````````` 9154*72b2703bSAndreas Gohr 9155*72b2703bSAndreas Gohr 9156*72b2703bSAndreas Gohr```````````````````````````````` example 9157*72b2703bSAndreas Gohr< http://foo.bar > 9158*72b2703bSAndreas Gohr. 9159*72b2703bSAndreas Gohr<p>< http://foo.bar ></p> 9160*72b2703bSAndreas Gohr```````````````````````````````` 9161*72b2703bSAndreas Gohr 9162*72b2703bSAndreas Gohr 9163*72b2703bSAndreas Gohr```````````````````````````````` example 9164*72b2703bSAndreas Gohr<m:abc> 9165*72b2703bSAndreas Gohr. 9166*72b2703bSAndreas Gohr<p><m:abc></p> 9167*72b2703bSAndreas Gohr```````````````````````````````` 9168*72b2703bSAndreas Gohr 9169*72b2703bSAndreas Gohr 9170*72b2703bSAndreas Gohr```````````````````````````````` example 9171*72b2703bSAndreas Gohr<foo.bar.baz> 9172*72b2703bSAndreas Gohr. 9173*72b2703bSAndreas Gohr<p><foo.bar.baz></p> 9174*72b2703bSAndreas Gohr```````````````````````````````` 9175*72b2703bSAndreas Gohr 9176*72b2703bSAndreas Gohr 9177*72b2703bSAndreas Gohr```````````````````````````````` example 9178*72b2703bSAndreas Gohrhttp://example.com 9179*72b2703bSAndreas Gohr. 9180*72b2703bSAndreas Gohr<p>http://example.com</p> 9181*72b2703bSAndreas Gohr```````````````````````````````` 9182*72b2703bSAndreas Gohr 9183*72b2703bSAndreas Gohr 9184*72b2703bSAndreas Gohr```````````````````````````````` example 9185*72b2703bSAndreas Gohrfoo@bar.example.com 9186*72b2703bSAndreas Gohr. 9187*72b2703bSAndreas Gohr<p>foo@bar.example.com</p> 9188*72b2703bSAndreas Gohr```````````````````````````````` 9189*72b2703bSAndreas Gohr 9190*72b2703bSAndreas Gohr<div class="extension"> 9191*72b2703bSAndreas Gohr 9192*72b2703bSAndreas Gohr## Autolinks (extension) 9193*72b2703bSAndreas Gohr 9194*72b2703bSAndreas GohrGFM enables the `autolink` extension, where autolinks will be recognised in a 9195*72b2703bSAndreas Gohrgreater number of conditions. 9196*72b2703bSAndreas Gohr 9197*72b2703bSAndreas Gohr[Autolink]s can also be constructed without requiring the use of `<` and to `>` 9198*72b2703bSAndreas Gohrto delimit them, although they will be recognized under a smaller set of 9199*72b2703bSAndreas Gohrcircumstances. All such recognized autolinks can only come at the beginning of 9200*72b2703bSAndreas Gohra line, after whitespace, or any of the delimiting characters `*`, `_`, `~`, 9201*72b2703bSAndreas Gohrand `(`. 9202*72b2703bSAndreas Gohr 9203*72b2703bSAndreas GohrAn [extended www autolink](@) will be recognized 9204*72b2703bSAndreas Gohrwhen the text `www.` is found followed by a [valid domain]. 9205*72b2703bSAndreas GohrA [valid domain](@) consists of segments 9206*72b2703bSAndreas Gohrof alphanumeric characters, underscores (`_`) and hyphens (`-`) 9207*72b2703bSAndreas Gohrseparated by periods (`.`). 9208*72b2703bSAndreas GohrThere must be at least one period, 9209*72b2703bSAndreas Gohrand no underscores may be present in the last two segments of the domain. 9210*72b2703bSAndreas Gohr 9211*72b2703bSAndreas GohrThe scheme `http` will be inserted automatically: 9212*72b2703bSAndreas Gohr 9213*72b2703bSAndreas Gohr```````````````````````````````` example autolink 9214*72b2703bSAndreas Gohrwww.commonmark.org 9215*72b2703bSAndreas Gohr. 9216*72b2703bSAndreas Gohr<p><a href="http://www.commonmark.org">www.commonmark.org</a></p> 9217*72b2703bSAndreas Gohr```````````````````````````````` 9218*72b2703bSAndreas Gohr 9219*72b2703bSAndreas GohrAfter a [valid domain], zero or more non-space non-`<` characters may follow: 9220*72b2703bSAndreas Gohr 9221*72b2703bSAndreas Gohr```````````````````````````````` example autolink 9222*72b2703bSAndreas GohrVisit www.commonmark.org/help for more information. 9223*72b2703bSAndreas Gohr. 9224*72b2703bSAndreas Gohr<p>Visit <a href="http://www.commonmark.org/help">www.commonmark.org/help</a> for more information.</p> 9225*72b2703bSAndreas Gohr```````````````````````````````` 9226*72b2703bSAndreas Gohr 9227*72b2703bSAndreas GohrWe then apply [extended autolink path validation](@) as follows: 9228*72b2703bSAndreas Gohr 9229*72b2703bSAndreas GohrTrailing punctuation (specifically, `?`, `!`, `.`, `,`, `:`, `*`, `_`, and `~`) 9230*72b2703bSAndreas Gohrwill not be considered part of the autolink, though they may be included in the 9231*72b2703bSAndreas Gohrinterior of the link: 9232*72b2703bSAndreas Gohr 9233*72b2703bSAndreas Gohr```````````````````````````````` example autolink 9234*72b2703bSAndreas GohrVisit www.commonmark.org. 9235*72b2703bSAndreas Gohr 9236*72b2703bSAndreas GohrVisit www.commonmark.org/a.b. 9237*72b2703bSAndreas Gohr. 9238*72b2703bSAndreas Gohr<p>Visit <a href="http://www.commonmark.org">www.commonmark.org</a>.</p> 9239*72b2703bSAndreas Gohr<p>Visit <a href="http://www.commonmark.org/a.b">www.commonmark.org/a.b</a>.</p> 9240*72b2703bSAndreas Gohr```````````````````````````````` 9241*72b2703bSAndreas Gohr 9242*72b2703bSAndreas GohrWhen an autolink ends in `)`, we scan the entire autolink for the total number 9243*72b2703bSAndreas Gohrof parentheses. If there is a greater number of closing parentheses than 9244*72b2703bSAndreas Gohropening ones, we don't consider the unmatched trailing parentheses part of the 9245*72b2703bSAndreas Gohrautolink, in order to facilitate including an autolink inside a parenthesis: 9246*72b2703bSAndreas Gohr 9247*72b2703bSAndreas Gohr```````````````````````````````` example autolink 9248*72b2703bSAndreas Gohrwww.google.com/search?q=Markup+(business) 9249*72b2703bSAndreas Gohr 9250*72b2703bSAndreas Gohrwww.google.com/search?q=Markup+(business))) 9251*72b2703bSAndreas Gohr 9252*72b2703bSAndreas Gohr(www.google.com/search?q=Markup+(business)) 9253*72b2703bSAndreas Gohr 9254*72b2703bSAndreas Gohr(www.google.com/search?q=Markup+(business) 9255*72b2703bSAndreas Gohr. 9256*72b2703bSAndreas Gohr<p><a href="http://www.google.com/search?q=Markup+(business)">www.google.com/search?q=Markup+(business)</a></p> 9257*72b2703bSAndreas Gohr<p><a href="http://www.google.com/search?q=Markup+(business)">www.google.com/search?q=Markup+(business)</a>))</p> 9258*72b2703bSAndreas Gohr<p>(<a href="http://www.google.com/search?q=Markup+(business)">www.google.com/search?q=Markup+(business)</a>)</p> 9259*72b2703bSAndreas Gohr<p>(<a href="http://www.google.com/search?q=Markup+(business)">www.google.com/search?q=Markup+(business)</a></p> 9260*72b2703bSAndreas Gohr```````````````````````````````` 9261*72b2703bSAndreas Gohr 9262*72b2703bSAndreas GohrThis check is only done when the link ends in a closing parentheses `)`, so if 9263*72b2703bSAndreas Gohrthe only parentheses are in the interior of the autolink, no special rules are 9264*72b2703bSAndreas Gohrapplied: 9265*72b2703bSAndreas Gohr 9266*72b2703bSAndreas Gohr```````````````````````````````` example autolink 9267*72b2703bSAndreas Gohrwww.google.com/search?q=(business))+ok 9268*72b2703bSAndreas Gohr. 9269*72b2703bSAndreas Gohr<p><a href="http://www.google.com/search?q=(business))+ok">www.google.com/search?q=(business))+ok</a></p> 9270*72b2703bSAndreas Gohr```````````````````````````````` 9271*72b2703bSAndreas Gohr 9272*72b2703bSAndreas GohrIf an autolink ends in a semicolon (`;`), we check to see if it appears to 9273*72b2703bSAndreas Gohrresemble an [entity reference][entity references]; if the preceding text is `&` 9274*72b2703bSAndreas Gohrfollowed by one or more alphanumeric characters. If so, it is excluded from 9275*72b2703bSAndreas Gohrthe autolink: 9276*72b2703bSAndreas Gohr 9277*72b2703bSAndreas Gohr```````````````````````````````` example autolink 9278*72b2703bSAndreas Gohrwww.google.com/search?q=commonmark&hl=en 9279*72b2703bSAndreas Gohr 9280*72b2703bSAndreas Gohrwww.google.com/search?q=commonmark&hl; 9281*72b2703bSAndreas Gohr. 9282*72b2703bSAndreas Gohr<p><a href="http://www.google.com/search?q=commonmark&hl=en">www.google.com/search?q=commonmark&hl=en</a></p> 9283*72b2703bSAndreas Gohr<p><a href="http://www.google.com/search?q=commonmark">www.google.com/search?q=commonmark</a>&hl;</p> 9284*72b2703bSAndreas Gohr```````````````````````````````` 9285*72b2703bSAndreas Gohr 9286*72b2703bSAndreas Gohr`<` immediately ends an autolink. 9287*72b2703bSAndreas Gohr 9288*72b2703bSAndreas Gohr```````````````````````````````` example autolink 9289*72b2703bSAndreas Gohrwww.commonmark.org/he<lp 9290*72b2703bSAndreas Gohr. 9291*72b2703bSAndreas Gohr<p><a href="http://www.commonmark.org/he">www.commonmark.org/he</a><lp</p> 9292*72b2703bSAndreas Gohr```````````````````````````````` 9293*72b2703bSAndreas Gohr 9294*72b2703bSAndreas GohrAn [extended url autolink](@) will be recognised when one of the schemes 9295*72b2703bSAndreas Gohr`http://`, `https://`, or `ftp://`, followed by a [valid domain], then zero or 9296*72b2703bSAndreas Gohrmore non-space non-`<` characters according to 9297*72b2703bSAndreas Gohr[extended autolink path validation]: 9298*72b2703bSAndreas Gohr 9299*72b2703bSAndreas Gohr```````````````````````````````` example autolink 9300*72b2703bSAndreas Gohrhttp://commonmark.org 9301*72b2703bSAndreas Gohr 9302*72b2703bSAndreas Gohr(Visit https://encrypted.google.com/search?q=Markup+(business)) 9303*72b2703bSAndreas Gohr 9304*72b2703bSAndreas GohrAnonymous FTP is available at ftp://foo.bar.baz. 9305*72b2703bSAndreas Gohr. 9306*72b2703bSAndreas Gohr<p><a href="http://commonmark.org">http://commonmark.org</a></p> 9307*72b2703bSAndreas Gohr<p>(Visit <a href="https://encrypted.google.com/search?q=Markup+(business)">https://encrypted.google.com/search?q=Markup+(business)</a>)</p> 9308*72b2703bSAndreas Gohr<p>Anonymous FTP is available at <a href="ftp://foo.bar.baz">ftp://foo.bar.baz</a>.</p> 9309*72b2703bSAndreas Gohr```````````````````````````````` 9310*72b2703bSAndreas Gohr 9311*72b2703bSAndreas Gohr 9312*72b2703bSAndreas GohrAn [extended email autolink](@) will be recognised when an email address is 9313*72b2703bSAndreas Gohrrecognised within any text node. Email addresses are recognised according to 9314*72b2703bSAndreas Gohrthe following rules: 9315*72b2703bSAndreas Gohr 9316*72b2703bSAndreas Gohr* One ore more characters which are alphanumeric, or `.`, `-`, `_`, or `+`. 9317*72b2703bSAndreas Gohr* An `@` symbol. 9318*72b2703bSAndreas Gohr* One or more characters which are alphanumeric, or `-` or `_`, 9319*72b2703bSAndreas Gohr separated by periods (`.`). 9320*72b2703bSAndreas Gohr There must be at least one period. 9321*72b2703bSAndreas Gohr The last character must not be one of `-` or `_`. 9322*72b2703bSAndreas Gohr 9323*72b2703bSAndreas GohrThe scheme `mailto:` will automatically be added to the generated link: 9324*72b2703bSAndreas Gohr 9325*72b2703bSAndreas Gohr```````````````````````````````` example autolink 9326*72b2703bSAndreas Gohrfoo@bar.baz 9327*72b2703bSAndreas Gohr. 9328*72b2703bSAndreas Gohr<p><a href="mailto:foo@bar.baz">foo@bar.baz</a></p> 9329*72b2703bSAndreas Gohr```````````````````````````````` 9330*72b2703bSAndreas Gohr 9331*72b2703bSAndreas Gohr`+` can occur before the `@`, but not after. 9332*72b2703bSAndreas Gohr 9333*72b2703bSAndreas Gohr```````````````````````````````` example autolink 9334*72b2703bSAndreas Gohrhello@mail+xyz.example isn't valid, but hello+xyz@mail.example is. 9335*72b2703bSAndreas Gohr. 9336*72b2703bSAndreas Gohr<p>hello@mail+xyz.example isn't valid, but <a href="mailto:hello+xyz@mail.example">hello+xyz@mail.example</a> is.</p> 9337*72b2703bSAndreas Gohr```````````````````````````````` 9338*72b2703bSAndreas Gohr 9339*72b2703bSAndreas Gohr`.`, `-`, and `_` can occur on both sides of the `@`, but only `.` may occur at 9340*72b2703bSAndreas Gohrthe end of the email address, in which case it will not be considered part of 9341*72b2703bSAndreas Gohrthe address: 9342*72b2703bSAndreas Gohr 9343*72b2703bSAndreas Gohr```````````````````````````````` example autolink 9344*72b2703bSAndreas Gohra.b-c_d@a.b 9345*72b2703bSAndreas Gohr 9346*72b2703bSAndreas Gohra.b-c_d@a.b. 9347*72b2703bSAndreas Gohr 9348*72b2703bSAndreas Gohra.b-c_d@a.b- 9349*72b2703bSAndreas Gohr 9350*72b2703bSAndreas Gohra.b-c_d@a.b_ 9351*72b2703bSAndreas Gohr. 9352*72b2703bSAndreas Gohr<p><a href="mailto:a.b-c_d@a.b">a.b-c_d@a.b</a></p> 9353*72b2703bSAndreas Gohr<p><a href="mailto:a.b-c_d@a.b">a.b-c_d@a.b</a>.</p> 9354*72b2703bSAndreas Gohr<p>a.b-c_d@a.b-</p> 9355*72b2703bSAndreas Gohr<p>a.b-c_d@a.b_</p> 9356*72b2703bSAndreas Gohr```````````````````````````````` 9357*72b2703bSAndreas Gohr 9358*72b2703bSAndreas Gohr</div> 9359*72b2703bSAndreas Gohr 9360*72b2703bSAndreas Gohr## Raw HTML 9361*72b2703bSAndreas Gohr 9362*72b2703bSAndreas GohrText between `<` and `>` that looks like an HTML tag is parsed as a 9363*72b2703bSAndreas Gohrraw HTML tag and will be rendered in HTML without escaping. 9364*72b2703bSAndreas GohrTag and attribute names are not limited to current HTML tags, 9365*72b2703bSAndreas Gohrso custom tags (and even, say, DocBook tags) may be used. 9366*72b2703bSAndreas Gohr 9367*72b2703bSAndreas GohrHere is the grammar for tags: 9368*72b2703bSAndreas Gohr 9369*72b2703bSAndreas GohrA [tag name](@) consists of an ASCII letter 9370*72b2703bSAndreas Gohrfollowed by zero or more ASCII letters, digits, or 9371*72b2703bSAndreas Gohrhyphens (`-`). 9372*72b2703bSAndreas Gohr 9373*72b2703bSAndreas GohrAn [attribute](@) consists of [whitespace], 9374*72b2703bSAndreas Gohran [attribute name], and an optional 9375*72b2703bSAndreas Gohr[attribute value specification]. 9376*72b2703bSAndreas Gohr 9377*72b2703bSAndreas GohrAn [attribute name](@) 9378*72b2703bSAndreas Gohrconsists of an ASCII letter, `_`, or `:`, followed by zero or more ASCII 9379*72b2703bSAndreas Gohrletters, digits, `_`, `.`, `:`, or `-`. (Note: This is the XML 9380*72b2703bSAndreas Gohrspecification restricted to ASCII. HTML5 is laxer.) 9381*72b2703bSAndreas Gohr 9382*72b2703bSAndreas GohrAn [attribute value specification](@) 9383*72b2703bSAndreas Gohrconsists of optional [whitespace], 9384*72b2703bSAndreas Gohra `=` character, optional [whitespace], and an [attribute 9385*72b2703bSAndreas Gohrvalue]. 9386*72b2703bSAndreas Gohr 9387*72b2703bSAndreas GohrAn [attribute value](@) 9388*72b2703bSAndreas Gohrconsists of an [unquoted attribute value], 9389*72b2703bSAndreas Gohra [single-quoted attribute value], or a [double-quoted attribute value]. 9390*72b2703bSAndreas Gohr 9391*72b2703bSAndreas GohrAn [unquoted attribute value](@) 9392*72b2703bSAndreas Gohris a nonempty string of characters not 9393*72b2703bSAndreas Gohrincluding [whitespace], `"`, `'`, `=`, `<`, `>`, or `` ` ``. 9394*72b2703bSAndreas Gohr 9395*72b2703bSAndreas GohrA [single-quoted attribute value](@) 9396*72b2703bSAndreas Gohrconsists of `'`, zero or more 9397*72b2703bSAndreas Gohrcharacters not including `'`, and a final `'`. 9398*72b2703bSAndreas Gohr 9399*72b2703bSAndreas GohrA [double-quoted attribute value](@) 9400*72b2703bSAndreas Gohrconsists of `"`, zero or more 9401*72b2703bSAndreas Gohrcharacters not including `"`, and a final `"`. 9402*72b2703bSAndreas Gohr 9403*72b2703bSAndreas GohrAn [open tag](@) consists of a `<` character, a [tag name], 9404*72b2703bSAndreas Gohrzero or more [attributes], optional [whitespace], an optional `/` 9405*72b2703bSAndreas Gohrcharacter, and a `>` character. 9406*72b2703bSAndreas Gohr 9407*72b2703bSAndreas GohrA [closing tag](@) consists of the string `</`, a 9408*72b2703bSAndreas Gohr[tag name], optional [whitespace], and the character `>`. 9409*72b2703bSAndreas Gohr 9410*72b2703bSAndreas GohrAn [HTML comment](@) consists of `<!-->`, `<!--->`, or `<!--`, a string of 9411*72b2703bSAndreas Gohrcharacters not including the string `-->`, and `-->` (see the 9412*72b2703bSAndreas Gohr[HTML spec](https://html.spec.whatwg.org/multipage/parsing.html#markup-declaration-open-state)). 9413*72b2703bSAndreas Gohr 9414*72b2703bSAndreas GohrA [processing instruction](@) 9415*72b2703bSAndreas Gohrconsists of the string `<?`, a string 9416*72b2703bSAndreas Gohrof characters not including the string `?>`, and the string 9417*72b2703bSAndreas Gohr`?>`. 9418*72b2703bSAndreas Gohr 9419*72b2703bSAndreas GohrA [declaration](@) consists of the 9420*72b2703bSAndreas Gohrstring `<!`, a name consisting of one or more uppercase ASCII letters, 9421*72b2703bSAndreas Gohr[whitespace], a string of characters not including the 9422*72b2703bSAndreas Gohrcharacter `>`, and the character `>`. 9423*72b2703bSAndreas Gohr 9424*72b2703bSAndreas GohrA [CDATA section](@) consists of 9425*72b2703bSAndreas Gohrthe string `<![CDATA[`, a string of characters not including the string 9426*72b2703bSAndreas Gohr`]]>`, and the string `]]>`. 9427*72b2703bSAndreas Gohr 9428*72b2703bSAndreas GohrAn [HTML tag](@) consists of an [open tag], a [closing tag], 9429*72b2703bSAndreas Gohran [HTML comment], a [processing instruction], a [declaration], 9430*72b2703bSAndreas Gohror a [CDATA section]. 9431*72b2703bSAndreas Gohr 9432*72b2703bSAndreas GohrHere are some simple open tags: 9433*72b2703bSAndreas Gohr 9434*72b2703bSAndreas Gohr```````````````````````````````` example 9435*72b2703bSAndreas Gohr<a><bab><c2c> 9436*72b2703bSAndreas Gohr. 9437*72b2703bSAndreas Gohr<p><a><bab><c2c></p> 9438*72b2703bSAndreas Gohr```````````````````````````````` 9439*72b2703bSAndreas Gohr 9440*72b2703bSAndreas Gohr 9441*72b2703bSAndreas GohrEmpty elements: 9442*72b2703bSAndreas Gohr 9443*72b2703bSAndreas Gohr```````````````````````````````` example 9444*72b2703bSAndreas Gohr<a/><b2/> 9445*72b2703bSAndreas Gohr. 9446*72b2703bSAndreas Gohr<p><a/><b2/></p> 9447*72b2703bSAndreas Gohr```````````````````````````````` 9448*72b2703bSAndreas Gohr 9449*72b2703bSAndreas Gohr 9450*72b2703bSAndreas Gohr[Whitespace] is allowed: 9451*72b2703bSAndreas Gohr 9452*72b2703bSAndreas Gohr```````````````````````````````` example 9453*72b2703bSAndreas Gohr<a /><b2 9454*72b2703bSAndreas Gohrdata="foo" > 9455*72b2703bSAndreas Gohr. 9456*72b2703bSAndreas Gohr<p><a /><b2 9457*72b2703bSAndreas Gohrdata="foo" ></p> 9458*72b2703bSAndreas Gohr```````````````````````````````` 9459*72b2703bSAndreas Gohr 9460*72b2703bSAndreas Gohr 9461*72b2703bSAndreas GohrWith attributes: 9462*72b2703bSAndreas Gohr 9463*72b2703bSAndreas Gohr```````````````````````````````` example 9464*72b2703bSAndreas Gohr<a foo="bar" bam = 'baz <em>"</em>' 9465*72b2703bSAndreas Gohr_boolean zoop:33=zoop:33 /> 9466*72b2703bSAndreas Gohr. 9467*72b2703bSAndreas Gohr<p><a foo="bar" bam = 'baz <em>"</em>' 9468*72b2703bSAndreas Gohr_boolean zoop:33=zoop:33 /></p> 9469*72b2703bSAndreas Gohr```````````````````````````````` 9470*72b2703bSAndreas Gohr 9471*72b2703bSAndreas Gohr 9472*72b2703bSAndreas GohrCustom tag names can be used: 9473*72b2703bSAndreas Gohr 9474*72b2703bSAndreas Gohr```````````````````````````````` example 9475*72b2703bSAndreas GohrFoo <responsive-image src="foo.jpg" /> 9476*72b2703bSAndreas Gohr. 9477*72b2703bSAndreas Gohr<p>Foo <responsive-image src="foo.jpg" /></p> 9478*72b2703bSAndreas Gohr```````````````````````````````` 9479*72b2703bSAndreas Gohr 9480*72b2703bSAndreas Gohr 9481*72b2703bSAndreas GohrIllegal tag names, not parsed as HTML: 9482*72b2703bSAndreas Gohr 9483*72b2703bSAndreas Gohr```````````````````````````````` example 9484*72b2703bSAndreas Gohr<33> <__> 9485*72b2703bSAndreas Gohr. 9486*72b2703bSAndreas Gohr<p><33> <__></p> 9487*72b2703bSAndreas Gohr```````````````````````````````` 9488*72b2703bSAndreas Gohr 9489*72b2703bSAndreas Gohr 9490*72b2703bSAndreas GohrIllegal attribute names: 9491*72b2703bSAndreas Gohr 9492*72b2703bSAndreas Gohr```````````````````````````````` example 9493*72b2703bSAndreas Gohr<a h*#ref="hi"> 9494*72b2703bSAndreas Gohr. 9495*72b2703bSAndreas Gohr<p><a h*#ref="hi"></p> 9496*72b2703bSAndreas Gohr```````````````````````````````` 9497*72b2703bSAndreas Gohr 9498*72b2703bSAndreas Gohr 9499*72b2703bSAndreas GohrIllegal attribute values: 9500*72b2703bSAndreas Gohr 9501*72b2703bSAndreas Gohr```````````````````````````````` example 9502*72b2703bSAndreas Gohr<a href="hi'> <a href=hi'> 9503*72b2703bSAndreas Gohr. 9504*72b2703bSAndreas Gohr<p><a href="hi'> <a href=hi'></p> 9505*72b2703bSAndreas Gohr```````````````````````````````` 9506*72b2703bSAndreas Gohr 9507*72b2703bSAndreas Gohr 9508*72b2703bSAndreas GohrIllegal [whitespace]: 9509*72b2703bSAndreas Gohr 9510*72b2703bSAndreas Gohr```````````````````````````````` example 9511*72b2703bSAndreas Gohr< a>< 9512*72b2703bSAndreas Gohrfoo><bar/ > 9513*72b2703bSAndreas Gohr<foo bar=baz 9514*72b2703bSAndreas Gohrbim!bop /> 9515*72b2703bSAndreas Gohr. 9516*72b2703bSAndreas Gohr<p>< a>< 9517*72b2703bSAndreas Gohrfoo><bar/ > 9518*72b2703bSAndreas Gohr<foo bar=baz 9519*72b2703bSAndreas Gohrbim!bop /></p> 9520*72b2703bSAndreas Gohr```````````````````````````````` 9521*72b2703bSAndreas Gohr 9522*72b2703bSAndreas Gohr 9523*72b2703bSAndreas GohrMissing [whitespace]: 9524*72b2703bSAndreas Gohr 9525*72b2703bSAndreas Gohr```````````````````````````````` example 9526*72b2703bSAndreas Gohr<a href='bar'title=title> 9527*72b2703bSAndreas Gohr. 9528*72b2703bSAndreas Gohr<p><a href='bar'title=title></p> 9529*72b2703bSAndreas Gohr```````````````````````````````` 9530*72b2703bSAndreas Gohr 9531*72b2703bSAndreas Gohr 9532*72b2703bSAndreas GohrClosing tags: 9533*72b2703bSAndreas Gohr 9534*72b2703bSAndreas Gohr```````````````````````````````` example 9535*72b2703bSAndreas Gohr</a></foo > 9536*72b2703bSAndreas Gohr. 9537*72b2703bSAndreas Gohr<p></a></foo ></p> 9538*72b2703bSAndreas Gohr```````````````````````````````` 9539*72b2703bSAndreas Gohr 9540*72b2703bSAndreas Gohr 9541*72b2703bSAndreas GohrIllegal attributes in closing tag: 9542*72b2703bSAndreas Gohr 9543*72b2703bSAndreas Gohr```````````````````````````````` example 9544*72b2703bSAndreas Gohr</a href="foo"> 9545*72b2703bSAndreas Gohr. 9546*72b2703bSAndreas Gohr<p></a href="foo"></p> 9547*72b2703bSAndreas Gohr```````````````````````````````` 9548*72b2703bSAndreas Gohr 9549*72b2703bSAndreas Gohr 9550*72b2703bSAndreas GohrComments: 9551*72b2703bSAndreas Gohr 9552*72b2703bSAndreas Gohr```````````````````````````````` example 9553*72b2703bSAndreas Gohrfoo <!-- this is a -- 9554*72b2703bSAndreas Gohrcomment - with hyphens --> 9555*72b2703bSAndreas Gohr. 9556*72b2703bSAndreas Gohr<p>foo <!-- this is a -- 9557*72b2703bSAndreas Gohrcomment - with hyphens --></p> 9558*72b2703bSAndreas Gohr```````````````````````````````` 9559*72b2703bSAndreas Gohr 9560*72b2703bSAndreas Gohr```````````````````````````````` example 9561*72b2703bSAndreas Gohrfoo <!--> foo --> 9562*72b2703bSAndreas Gohr 9563*72b2703bSAndreas Gohrfoo <!---> foo --> 9564*72b2703bSAndreas Gohr. 9565*72b2703bSAndreas Gohr<p>foo <!--> foo --></p> 9566*72b2703bSAndreas Gohr<p>foo <!---> foo --></p> 9567*72b2703bSAndreas Gohr```````````````````````````````` 9568*72b2703bSAndreas Gohr 9569*72b2703bSAndreas Gohr 9570*72b2703bSAndreas GohrProcessing instructions: 9571*72b2703bSAndreas Gohr 9572*72b2703bSAndreas Gohr```````````````````````````````` example 9573*72b2703bSAndreas Gohrfoo <?php echo $a; ?> 9574*72b2703bSAndreas Gohr. 9575*72b2703bSAndreas Gohr<p>foo <?php echo $a; ?></p> 9576*72b2703bSAndreas Gohr```````````````````````````````` 9577*72b2703bSAndreas Gohr 9578*72b2703bSAndreas Gohr 9579*72b2703bSAndreas GohrDeclarations: 9580*72b2703bSAndreas Gohr 9581*72b2703bSAndreas Gohr```````````````````````````````` example 9582*72b2703bSAndreas Gohrfoo <!ELEMENT br EMPTY> 9583*72b2703bSAndreas Gohr. 9584*72b2703bSAndreas Gohr<p>foo <!ELEMENT br EMPTY></p> 9585*72b2703bSAndreas Gohr```````````````````````````````` 9586*72b2703bSAndreas Gohr 9587*72b2703bSAndreas Gohr 9588*72b2703bSAndreas GohrCDATA sections: 9589*72b2703bSAndreas Gohr 9590*72b2703bSAndreas Gohr```````````````````````````````` example 9591*72b2703bSAndreas Gohrfoo <![CDATA[>&<]]> 9592*72b2703bSAndreas Gohr. 9593*72b2703bSAndreas Gohr<p>foo <![CDATA[>&<]]></p> 9594*72b2703bSAndreas Gohr```````````````````````````````` 9595*72b2703bSAndreas Gohr 9596*72b2703bSAndreas Gohr 9597*72b2703bSAndreas GohrEntity and numeric character references are preserved in HTML 9598*72b2703bSAndreas Gohrattributes: 9599*72b2703bSAndreas Gohr 9600*72b2703bSAndreas Gohr```````````````````````````````` example 9601*72b2703bSAndreas Gohrfoo <a href="ö"> 9602*72b2703bSAndreas Gohr. 9603*72b2703bSAndreas Gohr<p>foo <a href="ö"></p> 9604*72b2703bSAndreas Gohr```````````````````````````````` 9605*72b2703bSAndreas Gohr 9606*72b2703bSAndreas Gohr 9607*72b2703bSAndreas GohrBackslash escapes do not work in HTML attributes: 9608*72b2703bSAndreas Gohr 9609*72b2703bSAndreas Gohr```````````````````````````````` example 9610*72b2703bSAndreas Gohrfoo <a href="\*"> 9611*72b2703bSAndreas Gohr. 9612*72b2703bSAndreas Gohr<p>foo <a href="\*"></p> 9613*72b2703bSAndreas Gohr```````````````````````````````` 9614*72b2703bSAndreas Gohr 9615*72b2703bSAndreas Gohr 9616*72b2703bSAndreas Gohr```````````````````````````````` example 9617*72b2703bSAndreas Gohr<a href="\""> 9618*72b2703bSAndreas Gohr. 9619*72b2703bSAndreas Gohr<p><a href="""></p> 9620*72b2703bSAndreas Gohr```````````````````````````````` 9621*72b2703bSAndreas Gohr 9622*72b2703bSAndreas Gohr 9623*72b2703bSAndreas Gohr<div class="extension"> 9624*72b2703bSAndreas Gohr 9625*72b2703bSAndreas Gohr## Disallowed Raw HTML (extension) 9626*72b2703bSAndreas Gohr 9627*72b2703bSAndreas GohrGFM enables the `tagfilter` extension, where the following HTML tags will be 9628*72b2703bSAndreas Gohrfiltered when rendering HTML output: 9629*72b2703bSAndreas Gohr 9630*72b2703bSAndreas Gohr* `<title>` 9631*72b2703bSAndreas Gohr* `<textarea>` 9632*72b2703bSAndreas Gohr* `<style>` 9633*72b2703bSAndreas Gohr* `<xmp>` 9634*72b2703bSAndreas Gohr* `<iframe>` 9635*72b2703bSAndreas Gohr* `<noembed>` 9636*72b2703bSAndreas Gohr* `<noframes>` 9637*72b2703bSAndreas Gohr* `<script>` 9638*72b2703bSAndreas Gohr* `<plaintext>` 9639*72b2703bSAndreas Gohr 9640*72b2703bSAndreas GohrFiltering is done by replacing the leading `<` with the entity `<`. These 9641*72b2703bSAndreas Gohrtags are chosen in particular as they change how HTML is interpreted in a way 9642*72b2703bSAndreas Gohrunique to them (i.e. nested HTML is interpreted differently), and this is 9643*72b2703bSAndreas Gohrusually undesireable in the context of other rendered Markdown content. 9644*72b2703bSAndreas Gohr 9645*72b2703bSAndreas GohrAll other HTML tags are left untouched. 9646*72b2703bSAndreas Gohr 9647*72b2703bSAndreas Gohr```````````````````````````````` example tagfilter 9648*72b2703bSAndreas Gohr<strong> <title> <style> <em> 9649*72b2703bSAndreas Gohr 9650*72b2703bSAndreas Gohr<blockquote> 9651*72b2703bSAndreas Gohr <xmp> is disallowed. <XMP> is also disallowed. 9652*72b2703bSAndreas Gohr</blockquote> 9653*72b2703bSAndreas Gohr. 9654*72b2703bSAndreas Gohr<p><strong> <title> <style> <em></p> 9655*72b2703bSAndreas Gohr<blockquote> 9656*72b2703bSAndreas Gohr <xmp> is disallowed. <XMP> is also disallowed. 9657*72b2703bSAndreas Gohr</blockquote> 9658*72b2703bSAndreas Gohr```````````````````````````````` 9659*72b2703bSAndreas Gohr 9660*72b2703bSAndreas Gohr</div> 9661*72b2703bSAndreas Gohr 9662*72b2703bSAndreas Gohr## Hard line breaks 9663*72b2703bSAndreas Gohr 9664*72b2703bSAndreas GohrA line break (not in a code span or HTML tag) that is preceded 9665*72b2703bSAndreas Gohrby two or more spaces and does not occur at the end of a block 9666*72b2703bSAndreas Gohris parsed as a [hard line break](@) (rendered 9667*72b2703bSAndreas Gohrin HTML as a `<br />` tag): 9668*72b2703bSAndreas Gohr 9669*72b2703bSAndreas Gohr```````````````````````````````` example 9670*72b2703bSAndreas Gohrfoo 9671*72b2703bSAndreas Gohrbaz 9672*72b2703bSAndreas Gohr. 9673*72b2703bSAndreas Gohr<p>foo<br /> 9674*72b2703bSAndreas Gohrbaz</p> 9675*72b2703bSAndreas Gohr```````````````````````````````` 9676*72b2703bSAndreas Gohr 9677*72b2703bSAndreas Gohr 9678*72b2703bSAndreas GohrFor a more visible alternative, a backslash before the 9679*72b2703bSAndreas Gohr[line ending] may be used instead of two spaces: 9680*72b2703bSAndreas Gohr 9681*72b2703bSAndreas Gohr```````````````````````````````` example 9682*72b2703bSAndreas Gohrfoo\ 9683*72b2703bSAndreas Gohrbaz 9684*72b2703bSAndreas Gohr. 9685*72b2703bSAndreas Gohr<p>foo<br /> 9686*72b2703bSAndreas Gohrbaz</p> 9687*72b2703bSAndreas Gohr```````````````````````````````` 9688*72b2703bSAndreas Gohr 9689*72b2703bSAndreas Gohr 9690*72b2703bSAndreas GohrMore than two spaces can be used: 9691*72b2703bSAndreas Gohr 9692*72b2703bSAndreas Gohr```````````````````````````````` example 9693*72b2703bSAndreas Gohrfoo 9694*72b2703bSAndreas Gohrbaz 9695*72b2703bSAndreas Gohr. 9696*72b2703bSAndreas Gohr<p>foo<br /> 9697*72b2703bSAndreas Gohrbaz</p> 9698*72b2703bSAndreas Gohr```````````````````````````````` 9699*72b2703bSAndreas Gohr 9700*72b2703bSAndreas Gohr 9701*72b2703bSAndreas GohrLeading spaces at the beginning of the next line are ignored: 9702*72b2703bSAndreas Gohr 9703*72b2703bSAndreas Gohr```````````````````````````````` example 9704*72b2703bSAndreas Gohrfoo 9705*72b2703bSAndreas Gohr bar 9706*72b2703bSAndreas Gohr. 9707*72b2703bSAndreas Gohr<p>foo<br /> 9708*72b2703bSAndreas Gohrbar</p> 9709*72b2703bSAndreas Gohr```````````````````````````````` 9710*72b2703bSAndreas Gohr 9711*72b2703bSAndreas Gohr 9712*72b2703bSAndreas Gohr```````````````````````````````` example 9713*72b2703bSAndreas Gohrfoo\ 9714*72b2703bSAndreas Gohr bar 9715*72b2703bSAndreas Gohr. 9716*72b2703bSAndreas Gohr<p>foo<br /> 9717*72b2703bSAndreas Gohrbar</p> 9718*72b2703bSAndreas Gohr```````````````````````````````` 9719*72b2703bSAndreas Gohr 9720*72b2703bSAndreas Gohr 9721*72b2703bSAndreas GohrLine breaks can occur inside emphasis, links, and other constructs 9722*72b2703bSAndreas Gohrthat allow inline content: 9723*72b2703bSAndreas Gohr 9724*72b2703bSAndreas Gohr```````````````````````````````` example 9725*72b2703bSAndreas Gohr*foo 9726*72b2703bSAndreas Gohrbar* 9727*72b2703bSAndreas Gohr. 9728*72b2703bSAndreas Gohr<p><em>foo<br /> 9729*72b2703bSAndreas Gohrbar</em></p> 9730*72b2703bSAndreas Gohr```````````````````````````````` 9731*72b2703bSAndreas Gohr 9732*72b2703bSAndreas Gohr 9733*72b2703bSAndreas Gohr```````````````````````````````` example 9734*72b2703bSAndreas Gohr*foo\ 9735*72b2703bSAndreas Gohrbar* 9736*72b2703bSAndreas Gohr. 9737*72b2703bSAndreas Gohr<p><em>foo<br /> 9738*72b2703bSAndreas Gohrbar</em></p> 9739*72b2703bSAndreas Gohr```````````````````````````````` 9740*72b2703bSAndreas Gohr 9741*72b2703bSAndreas Gohr 9742*72b2703bSAndreas GohrLine breaks do not occur inside code spans 9743*72b2703bSAndreas Gohr 9744*72b2703bSAndreas Gohr```````````````````````````````` example 9745*72b2703bSAndreas Gohr`code 9746*72b2703bSAndreas Gohrspan` 9747*72b2703bSAndreas Gohr. 9748*72b2703bSAndreas Gohr<p><code>code span</code></p> 9749*72b2703bSAndreas Gohr```````````````````````````````` 9750*72b2703bSAndreas Gohr 9751*72b2703bSAndreas Gohr 9752*72b2703bSAndreas Gohr```````````````````````````````` example 9753*72b2703bSAndreas Gohr`code\ 9754*72b2703bSAndreas Gohrspan` 9755*72b2703bSAndreas Gohr. 9756*72b2703bSAndreas Gohr<p><code>code\ span</code></p> 9757*72b2703bSAndreas Gohr```````````````````````````````` 9758*72b2703bSAndreas Gohr 9759*72b2703bSAndreas Gohr 9760*72b2703bSAndreas Gohror HTML tags: 9761*72b2703bSAndreas Gohr 9762*72b2703bSAndreas Gohr```````````````````````````````` example 9763*72b2703bSAndreas Gohr<a href="foo 9764*72b2703bSAndreas Gohrbar"> 9765*72b2703bSAndreas Gohr. 9766*72b2703bSAndreas Gohr<p><a href="foo 9767*72b2703bSAndreas Gohrbar"></p> 9768*72b2703bSAndreas Gohr```````````````````````````````` 9769*72b2703bSAndreas Gohr 9770*72b2703bSAndreas Gohr 9771*72b2703bSAndreas Gohr```````````````````````````````` example 9772*72b2703bSAndreas Gohr<a href="foo\ 9773*72b2703bSAndreas Gohrbar"> 9774*72b2703bSAndreas Gohr. 9775*72b2703bSAndreas Gohr<p><a href="foo\ 9776*72b2703bSAndreas Gohrbar"></p> 9777*72b2703bSAndreas Gohr```````````````````````````````` 9778*72b2703bSAndreas Gohr 9779*72b2703bSAndreas Gohr 9780*72b2703bSAndreas GohrHard line breaks are for separating inline content within a block. 9781*72b2703bSAndreas GohrNeither syntax for hard line breaks works at the end of a paragraph or 9782*72b2703bSAndreas Gohrother block element: 9783*72b2703bSAndreas Gohr 9784*72b2703bSAndreas Gohr```````````````````````````````` example 9785*72b2703bSAndreas Gohrfoo\ 9786*72b2703bSAndreas Gohr. 9787*72b2703bSAndreas Gohr<p>foo\</p> 9788*72b2703bSAndreas Gohr```````````````````````````````` 9789*72b2703bSAndreas Gohr 9790*72b2703bSAndreas Gohr 9791*72b2703bSAndreas Gohr```````````````````````````````` example 9792*72b2703bSAndreas Gohrfoo 9793*72b2703bSAndreas Gohr. 9794*72b2703bSAndreas Gohr<p>foo</p> 9795*72b2703bSAndreas Gohr```````````````````````````````` 9796*72b2703bSAndreas Gohr 9797*72b2703bSAndreas Gohr 9798*72b2703bSAndreas Gohr```````````````````````````````` example 9799*72b2703bSAndreas Gohr### foo\ 9800*72b2703bSAndreas Gohr. 9801*72b2703bSAndreas Gohr<h3>foo\</h3> 9802*72b2703bSAndreas Gohr```````````````````````````````` 9803*72b2703bSAndreas Gohr 9804*72b2703bSAndreas Gohr 9805*72b2703bSAndreas Gohr```````````````````````````````` example 9806*72b2703bSAndreas Gohr### foo 9807*72b2703bSAndreas Gohr. 9808*72b2703bSAndreas Gohr<h3>foo</h3> 9809*72b2703bSAndreas Gohr```````````````````````````````` 9810*72b2703bSAndreas Gohr 9811*72b2703bSAndreas Gohr 9812*72b2703bSAndreas Gohr## Soft line breaks 9813*72b2703bSAndreas Gohr 9814*72b2703bSAndreas GohrA regular line break (not in a code span or HTML tag) that is not 9815*72b2703bSAndreas Gohrpreceded by two or more spaces or a backslash is parsed as a 9816*72b2703bSAndreas Gohr[softbreak](@). (A softbreak may be rendered in HTML either as a 9817*72b2703bSAndreas Gohr[line ending] or as a space. The result will be the same in 9818*72b2703bSAndreas Gohrbrowsers. In the examples here, a [line ending] will be used.) 9819*72b2703bSAndreas Gohr 9820*72b2703bSAndreas Gohr```````````````````````````````` example 9821*72b2703bSAndreas Gohrfoo 9822*72b2703bSAndreas Gohrbaz 9823*72b2703bSAndreas Gohr. 9824*72b2703bSAndreas Gohr<p>foo 9825*72b2703bSAndreas Gohrbaz</p> 9826*72b2703bSAndreas Gohr```````````````````````````````` 9827*72b2703bSAndreas Gohr 9828*72b2703bSAndreas Gohr 9829*72b2703bSAndreas GohrSpaces at the end of the line and beginning of the next line are 9830*72b2703bSAndreas Gohrremoved: 9831*72b2703bSAndreas Gohr 9832*72b2703bSAndreas Gohr```````````````````````````````` example 9833*72b2703bSAndreas Gohrfoo 9834*72b2703bSAndreas Gohr baz 9835*72b2703bSAndreas Gohr. 9836*72b2703bSAndreas Gohr<p>foo 9837*72b2703bSAndreas Gohrbaz</p> 9838*72b2703bSAndreas Gohr```````````````````````````````` 9839*72b2703bSAndreas Gohr 9840*72b2703bSAndreas Gohr 9841*72b2703bSAndreas GohrA conforming parser may render a soft line break in HTML either as a 9842*72b2703bSAndreas Gohrline break or as a space. 9843*72b2703bSAndreas Gohr 9844*72b2703bSAndreas GohrA renderer may also provide an option to render soft line breaks 9845*72b2703bSAndreas Gohras hard line breaks. 9846*72b2703bSAndreas Gohr 9847*72b2703bSAndreas Gohr## Textual content 9848*72b2703bSAndreas Gohr 9849*72b2703bSAndreas GohrAny characters not given an interpretation by the above rules will 9850*72b2703bSAndreas Gohrbe parsed as plain textual content. 9851*72b2703bSAndreas Gohr 9852*72b2703bSAndreas Gohr```````````````````````````````` example 9853*72b2703bSAndreas Gohrhello $.;'there 9854*72b2703bSAndreas Gohr. 9855*72b2703bSAndreas Gohr<p>hello $.;'there</p> 9856*72b2703bSAndreas Gohr```````````````````````````````` 9857*72b2703bSAndreas Gohr 9858*72b2703bSAndreas Gohr 9859*72b2703bSAndreas Gohr```````````````````````````````` example 9860*72b2703bSAndreas GohrFoo χρῆν 9861*72b2703bSAndreas Gohr. 9862*72b2703bSAndreas Gohr<p>Foo χρῆν</p> 9863*72b2703bSAndreas Gohr```````````````````````````````` 9864*72b2703bSAndreas Gohr 9865*72b2703bSAndreas Gohr 9866*72b2703bSAndreas GohrInternal spaces are preserved verbatim: 9867*72b2703bSAndreas Gohr 9868*72b2703bSAndreas Gohr```````````````````````````````` example 9869*72b2703bSAndreas GohrMultiple spaces 9870*72b2703bSAndreas Gohr. 9871*72b2703bSAndreas Gohr<p>Multiple spaces</p> 9872*72b2703bSAndreas Gohr```````````````````````````````` 9873*72b2703bSAndreas Gohr 9874*72b2703bSAndreas Gohr 9875*72b2703bSAndreas Gohr<!-- END TESTS --> 9876*72b2703bSAndreas Gohr 9877*72b2703bSAndreas Gohr# Appendix: A parsing strategy 9878*72b2703bSAndreas Gohr 9879*72b2703bSAndreas GohrIn this appendix we describe some features of the parsing strategy 9880*72b2703bSAndreas Gohrused in the CommonMark reference implementations. 9881*72b2703bSAndreas Gohr 9882*72b2703bSAndreas Gohr## Overview 9883*72b2703bSAndreas Gohr 9884*72b2703bSAndreas GohrParsing has two phases: 9885*72b2703bSAndreas Gohr 9886*72b2703bSAndreas Gohr1. In the first phase, lines of input are consumed and the block 9887*72b2703bSAndreas Gohrstructure of the document---its division into paragraphs, block quotes, 9888*72b2703bSAndreas Gohrlist items, and so on---is constructed. Text is assigned to these 9889*72b2703bSAndreas Gohrblocks but not parsed. Link reference definitions are parsed and a 9890*72b2703bSAndreas Gohrmap of links is constructed. 9891*72b2703bSAndreas Gohr 9892*72b2703bSAndreas Gohr2. In the second phase, the raw text contents of paragraphs and headings 9893*72b2703bSAndreas Gohrare parsed into sequences of Markdown inline elements (strings, 9894*72b2703bSAndreas Gohrcode spans, links, emphasis, and so on), using the map of link 9895*72b2703bSAndreas Gohrreferences constructed in phase 1. 9896*72b2703bSAndreas Gohr 9897*72b2703bSAndreas GohrAt each point in processing, the document is represented as a tree of 9898*72b2703bSAndreas Gohr**blocks**. The root of the tree is a `document` block. The `document` 9899*72b2703bSAndreas Gohrmay have any number of other blocks as **children**. These children 9900*72b2703bSAndreas Gohrmay, in turn, have other blocks as children. The last child of a block 9901*72b2703bSAndreas Gohris normally considered **open**, meaning that subsequent lines of input 9902*72b2703bSAndreas Gohrcan alter its contents. (Blocks that are not open are **closed**.) 9903*72b2703bSAndreas GohrHere, for example, is a possible document tree, with the open blocks 9904*72b2703bSAndreas Gohrmarked by arrows: 9905*72b2703bSAndreas Gohr 9906*72b2703bSAndreas Gohr``` tree 9907*72b2703bSAndreas Gohr-> document 9908*72b2703bSAndreas Gohr -> block_quote 9909*72b2703bSAndreas Gohr paragraph 9910*72b2703bSAndreas Gohr "Lorem ipsum dolor\nsit amet." 9911*72b2703bSAndreas Gohr -> list (type=bullet tight=true bullet_char=-) 9912*72b2703bSAndreas Gohr list_item 9913*72b2703bSAndreas Gohr paragraph 9914*72b2703bSAndreas Gohr "Qui *quodsi iracundia*" 9915*72b2703bSAndreas Gohr -> list_item 9916*72b2703bSAndreas Gohr -> paragraph 9917*72b2703bSAndreas Gohr "aliquando id" 9918*72b2703bSAndreas Gohr``` 9919*72b2703bSAndreas Gohr 9920*72b2703bSAndreas Gohr## Phase 1: block structure 9921*72b2703bSAndreas Gohr 9922*72b2703bSAndreas GohrEach line that is processed has an effect on this tree. The line is 9923*72b2703bSAndreas Gohranalyzed and, depending on its contents, the document may be altered 9924*72b2703bSAndreas Gohrin one or more of the following ways: 9925*72b2703bSAndreas Gohr 9926*72b2703bSAndreas Gohr1. One or more open blocks may be closed. 9927*72b2703bSAndreas Gohr2. One or more new blocks may be created as children of the 9928*72b2703bSAndreas Gohr last open block. 9929*72b2703bSAndreas Gohr3. Text may be added to the last (deepest) open block remaining 9930*72b2703bSAndreas Gohr on the tree. 9931*72b2703bSAndreas Gohr 9932*72b2703bSAndreas GohrOnce a line has been incorporated into the tree in this way, 9933*72b2703bSAndreas Gohrit can be discarded, so input can be read in a stream. 9934*72b2703bSAndreas Gohr 9935*72b2703bSAndreas GohrFor each line, we follow this procedure: 9936*72b2703bSAndreas Gohr 9937*72b2703bSAndreas Gohr1. First we iterate through the open blocks, starting with the 9938*72b2703bSAndreas Gohrroot document, and descending through last children down to the last 9939*72b2703bSAndreas Gohropen block. Each block imposes a condition that the line must satisfy 9940*72b2703bSAndreas Gohrif the block is to remain open. For example, a block quote requires a 9941*72b2703bSAndreas Gohr`>` character. A paragraph requires a non-blank line. 9942*72b2703bSAndreas GohrIn this phase we may match all or just some of the open 9943*72b2703bSAndreas Gohrblocks. But we cannot close unmatched blocks yet, because we may have a 9944*72b2703bSAndreas Gohr[lazy continuation line]. 9945*72b2703bSAndreas Gohr 9946*72b2703bSAndreas Gohr2. Next, after consuming the continuation markers for existing 9947*72b2703bSAndreas Gohrblocks, we look for new block starts (e.g. `>` for a block quote). 9948*72b2703bSAndreas GohrIf we encounter a new block start, we close any blocks unmatched 9949*72b2703bSAndreas Gohrin step 1 before creating the new block as a child of the last 9950*72b2703bSAndreas Gohrmatched block. 9951*72b2703bSAndreas Gohr 9952*72b2703bSAndreas Gohr3. Finally, we look at the remainder of the line (after block 9953*72b2703bSAndreas Gohrmarkers like `>`, list markers, and indentation have been consumed). 9954*72b2703bSAndreas GohrThis is text that can be incorporated into the last open 9955*72b2703bSAndreas Gohrblock (a paragraph, code block, heading, or raw HTML). 9956*72b2703bSAndreas Gohr 9957*72b2703bSAndreas GohrSetext headings are formed when we see a line of a paragraph 9958*72b2703bSAndreas Gohrthat is a [setext heading underline]. 9959*72b2703bSAndreas Gohr 9960*72b2703bSAndreas GohrReference link definitions are detected when a paragraph is closed; 9961*72b2703bSAndreas Gohrthe accumulated text lines are parsed to see if they begin with 9962*72b2703bSAndreas Gohrone or more reference link definitions. Any remainder becomes a 9963*72b2703bSAndreas Gohrnormal paragraph. 9964*72b2703bSAndreas Gohr 9965*72b2703bSAndreas GohrWe can see how this works by considering how the tree above is 9966*72b2703bSAndreas Gohrgenerated by four lines of Markdown: 9967*72b2703bSAndreas Gohr 9968*72b2703bSAndreas Gohr``` markdown 9969*72b2703bSAndreas Gohr> Lorem ipsum dolor 9970*72b2703bSAndreas Gohrsit amet. 9971*72b2703bSAndreas Gohr> - Qui *quodsi iracundia* 9972*72b2703bSAndreas Gohr> - aliquando id 9973*72b2703bSAndreas Gohr``` 9974*72b2703bSAndreas Gohr 9975*72b2703bSAndreas GohrAt the outset, our document model is just 9976*72b2703bSAndreas Gohr 9977*72b2703bSAndreas Gohr``` tree 9978*72b2703bSAndreas Gohr-> document 9979*72b2703bSAndreas Gohr``` 9980*72b2703bSAndreas Gohr 9981*72b2703bSAndreas GohrThe first line of our text, 9982*72b2703bSAndreas Gohr 9983*72b2703bSAndreas Gohr``` markdown 9984*72b2703bSAndreas Gohr> Lorem ipsum dolor 9985*72b2703bSAndreas Gohr``` 9986*72b2703bSAndreas Gohr 9987*72b2703bSAndreas Gohrcauses a `block_quote` block to be created as a child of our 9988*72b2703bSAndreas Gohropen `document` block, and a `paragraph` block as a child of 9989*72b2703bSAndreas Gohrthe `block_quote`. Then the text is added to the last open 9990*72b2703bSAndreas Gohrblock, the `paragraph`: 9991*72b2703bSAndreas Gohr 9992*72b2703bSAndreas Gohr``` tree 9993*72b2703bSAndreas Gohr-> document 9994*72b2703bSAndreas Gohr -> block_quote 9995*72b2703bSAndreas Gohr -> paragraph 9996*72b2703bSAndreas Gohr "Lorem ipsum dolor" 9997*72b2703bSAndreas Gohr``` 9998*72b2703bSAndreas Gohr 9999*72b2703bSAndreas GohrThe next line, 10000*72b2703bSAndreas Gohr 10001*72b2703bSAndreas Gohr``` markdown 10002*72b2703bSAndreas Gohrsit amet. 10003*72b2703bSAndreas Gohr``` 10004*72b2703bSAndreas Gohr 10005*72b2703bSAndreas Gohris a "lazy continuation" of the open `paragraph`, so it gets added 10006*72b2703bSAndreas Gohrto the paragraph's text: 10007*72b2703bSAndreas Gohr 10008*72b2703bSAndreas Gohr``` tree 10009*72b2703bSAndreas Gohr-> document 10010*72b2703bSAndreas Gohr -> block_quote 10011*72b2703bSAndreas Gohr -> paragraph 10012*72b2703bSAndreas Gohr "Lorem ipsum dolor\nsit amet." 10013*72b2703bSAndreas Gohr``` 10014*72b2703bSAndreas Gohr 10015*72b2703bSAndreas GohrThe third line, 10016*72b2703bSAndreas Gohr 10017*72b2703bSAndreas Gohr``` markdown 10018*72b2703bSAndreas Gohr> - Qui *quodsi iracundia* 10019*72b2703bSAndreas Gohr``` 10020*72b2703bSAndreas Gohr 10021*72b2703bSAndreas Gohrcauses the `paragraph` block to be closed, and a new `list` block 10022*72b2703bSAndreas Gohropened as a child of the `block_quote`. A `list_item` is also 10023*72b2703bSAndreas Gohradded as a child of the `list`, and a `paragraph` as a child of 10024*72b2703bSAndreas Gohrthe `list_item`. The text is then added to the new `paragraph`: 10025*72b2703bSAndreas Gohr 10026*72b2703bSAndreas Gohr``` tree 10027*72b2703bSAndreas Gohr-> document 10028*72b2703bSAndreas Gohr -> block_quote 10029*72b2703bSAndreas Gohr paragraph 10030*72b2703bSAndreas Gohr "Lorem ipsum dolor\nsit amet." 10031*72b2703bSAndreas Gohr -> list (type=bullet tight=true bullet_char=-) 10032*72b2703bSAndreas Gohr -> list_item 10033*72b2703bSAndreas Gohr -> paragraph 10034*72b2703bSAndreas Gohr "Qui *quodsi iracundia*" 10035*72b2703bSAndreas Gohr``` 10036*72b2703bSAndreas Gohr 10037*72b2703bSAndreas GohrThe fourth line, 10038*72b2703bSAndreas Gohr 10039*72b2703bSAndreas Gohr``` markdown 10040*72b2703bSAndreas Gohr> - aliquando id 10041*72b2703bSAndreas Gohr``` 10042*72b2703bSAndreas Gohr 10043*72b2703bSAndreas Gohrcauses the `list_item` (and its child the `paragraph`) to be closed, 10044*72b2703bSAndreas Gohrand a new `list_item` opened up as child of the `list`. A `paragraph` 10045*72b2703bSAndreas Gohris added as a child of the new `list_item`, to contain the text. 10046*72b2703bSAndreas GohrWe thus obtain the final tree: 10047*72b2703bSAndreas Gohr 10048*72b2703bSAndreas Gohr``` tree 10049*72b2703bSAndreas Gohr-> document 10050*72b2703bSAndreas Gohr -> block_quote 10051*72b2703bSAndreas Gohr paragraph 10052*72b2703bSAndreas Gohr "Lorem ipsum dolor\nsit amet." 10053*72b2703bSAndreas Gohr -> list (type=bullet tight=true bullet_char=-) 10054*72b2703bSAndreas Gohr list_item 10055*72b2703bSAndreas Gohr paragraph 10056*72b2703bSAndreas Gohr "Qui *quodsi iracundia*" 10057*72b2703bSAndreas Gohr -> list_item 10058*72b2703bSAndreas Gohr -> paragraph 10059*72b2703bSAndreas Gohr "aliquando id" 10060*72b2703bSAndreas Gohr``` 10061*72b2703bSAndreas Gohr 10062*72b2703bSAndreas Gohr## Phase 2: inline structure 10063*72b2703bSAndreas Gohr 10064*72b2703bSAndreas GohrOnce all of the input has been parsed, all open blocks are closed. 10065*72b2703bSAndreas Gohr 10066*72b2703bSAndreas GohrWe then "walk the tree," visiting every node, and parse raw 10067*72b2703bSAndreas Gohrstring contents of paragraphs and headings as inlines. At this 10068*72b2703bSAndreas Gohrpoint we have seen all the link reference definitions, so we can 10069*72b2703bSAndreas Gohrresolve reference links as we go. 10070*72b2703bSAndreas Gohr 10071*72b2703bSAndreas Gohr``` tree 10072*72b2703bSAndreas Gohrdocument 10073*72b2703bSAndreas Gohr block_quote 10074*72b2703bSAndreas Gohr paragraph 10075*72b2703bSAndreas Gohr str "Lorem ipsum dolor" 10076*72b2703bSAndreas Gohr softbreak 10077*72b2703bSAndreas Gohr str "sit amet." 10078*72b2703bSAndreas Gohr list (type=bullet tight=true bullet_char=-) 10079*72b2703bSAndreas Gohr list_item 10080*72b2703bSAndreas Gohr paragraph 10081*72b2703bSAndreas Gohr str "Qui " 10082*72b2703bSAndreas Gohr emph 10083*72b2703bSAndreas Gohr str "quodsi iracundia" 10084*72b2703bSAndreas Gohr list_item 10085*72b2703bSAndreas Gohr paragraph 10086*72b2703bSAndreas Gohr str "aliquando id" 10087*72b2703bSAndreas Gohr``` 10088*72b2703bSAndreas Gohr 10089*72b2703bSAndreas GohrNotice how the [line ending] in the first paragraph has 10090*72b2703bSAndreas Gohrbeen parsed as a `softbreak`, and the asterisks in the first list item 10091*72b2703bSAndreas Gohrhave become an `emph`. 10092*72b2703bSAndreas Gohr 10093*72b2703bSAndreas Gohr### An algorithm for parsing nested emphasis and links 10094*72b2703bSAndreas Gohr 10095*72b2703bSAndreas GohrBy far the trickiest part of inline parsing is handling emphasis, 10096*72b2703bSAndreas Gohrstrong emphasis, links, and images. This is done using the following 10097*72b2703bSAndreas Gohralgorithm. 10098*72b2703bSAndreas Gohr 10099*72b2703bSAndreas GohrWhen we're parsing inlines and we hit either 10100*72b2703bSAndreas Gohr 10101*72b2703bSAndreas Gohr- a run of `*` or `_` characters, or 10102*72b2703bSAndreas Gohr- a `[` or `. 10106*72b2703bSAndreas Gohr 10107*72b2703bSAndreas GohrThe [delimiter stack] is a doubly linked list. Each 10108*72b2703bSAndreas Gohrelement contains a pointer to a text node, plus information about 10109*72b2703bSAndreas Gohr 10110*72b2703bSAndreas Gohr- the type of delimiter (`[`, `![`, `*`, `_`) 10111*72b2703bSAndreas Gohr- the number of delimiters, 10112*72b2703bSAndreas Gohr- whether the delimiter is "active" (all are active to start), and 10113*72b2703bSAndreas Gohr- whether the delimiter is a potential opener, a potential closer, 10114*72b2703bSAndreas Gohr or both (which depends on what sort of characters precede 10115*72b2703bSAndreas Gohr and follow the delimiters). 10116*72b2703bSAndreas Gohr 10117*72b2703bSAndreas GohrWhen we hit a `]` character, we call the *look for link or image* 10118*72b2703bSAndreas Gohrprocedure (see below). 10119*72b2703bSAndreas Gohr 10120*72b2703bSAndreas GohrWhen we hit the end of the input, we call the *process emphasis* 10121*72b2703bSAndreas Gohrprocedure (see below), with `stack_bottom` = NULL. 10122*72b2703bSAndreas Gohr 10123*72b2703bSAndreas Gohr#### *look for link or image* 10124*72b2703bSAndreas Gohr 10125*72b2703bSAndreas GohrStarting at the top of the delimiter stack, we look backwards 10126*72b2703bSAndreas Gohrthrough the stack for an opening `[` or `![` delimiter. 10127*72b2703bSAndreas Gohr 10128*72b2703bSAndreas Gohr- If we don't find one, we return a literal text node `]`. 10129*72b2703bSAndreas Gohr 10130*72b2703bSAndreas Gohr- If we do find one, but it's not *active*, we remove the inactive 10131*72b2703bSAndreas Gohr delimiter from the stack, and return a literal text node `]`. 10132*72b2703bSAndreas Gohr 10133*72b2703bSAndreas Gohr- If we find one and it's active, then we parse ahead to see if 10134*72b2703bSAndreas Gohr we have an inline link/image, reference link/image, compact reference 10135*72b2703bSAndreas Gohr link/image, or shortcut reference link/image. 10136*72b2703bSAndreas Gohr 10137*72b2703bSAndreas Gohr + If we don't, then we remove the opening delimiter from the 10138*72b2703bSAndreas Gohr delimiter stack and return a literal text node `]`. 10139*72b2703bSAndreas Gohr 10140*72b2703bSAndreas Gohr + If we do, then 10141*72b2703bSAndreas Gohr 10142*72b2703bSAndreas Gohr * We return a link or image node whose children are the inlines 10143*72b2703bSAndreas Gohr after the text node pointed to by the opening delimiter. 10144*72b2703bSAndreas Gohr 10145*72b2703bSAndreas Gohr * We run *process emphasis* on these inlines, with the `[` opener 10146*72b2703bSAndreas Gohr as `stack_bottom`. 10147*72b2703bSAndreas Gohr 10148*72b2703bSAndreas Gohr * We remove the opening delimiter. 10149*72b2703bSAndreas Gohr 10150*72b2703bSAndreas Gohr * If we have a link (and not an image), we also set all 10151*72b2703bSAndreas Gohr `[` delimiters before the opening delimiter to *inactive*. (This 10152*72b2703bSAndreas Gohr will prevent us from getting links within links.) 10153*72b2703bSAndreas Gohr 10154*72b2703bSAndreas Gohr#### *process emphasis* 10155*72b2703bSAndreas Gohr 10156*72b2703bSAndreas GohrParameter `stack_bottom` sets a lower bound to how far we 10157*72b2703bSAndreas Gohrdescend in the [delimiter stack]. If it is NULL, we can 10158*72b2703bSAndreas Gohrgo all the way to the bottom. Otherwise, we stop before 10159*72b2703bSAndreas Gohrvisiting `stack_bottom`. 10160*72b2703bSAndreas Gohr 10161*72b2703bSAndreas GohrLet `current_position` point to the element on the [delimiter stack] 10162*72b2703bSAndreas Gohrjust above `stack_bottom` (or the first element if `stack_bottom` 10163*72b2703bSAndreas Gohris NULL). 10164*72b2703bSAndreas Gohr 10165*72b2703bSAndreas GohrWe keep track of the `openers_bottom` for each delimiter 10166*72b2703bSAndreas Gohrtype (`*`, `_`) and each length of the closing delimiter run 10167*72b2703bSAndreas Gohr(modulo 3). Initialize this to `stack_bottom`. 10168*72b2703bSAndreas Gohr 10169*72b2703bSAndreas GohrThen we repeat the following until we run out of potential 10170*72b2703bSAndreas Gohrclosers: 10171*72b2703bSAndreas Gohr 10172*72b2703bSAndreas Gohr- Move `current_position` forward in the delimiter stack (if needed) 10173*72b2703bSAndreas Gohr until we find the first potential closer with delimiter `*` or `_`. 10174*72b2703bSAndreas Gohr (This will be the potential closer closest 10175*72b2703bSAndreas Gohr to the beginning of the input -- the first one in parse order.) 10176*72b2703bSAndreas Gohr 10177*72b2703bSAndreas Gohr- Now, look back in the stack (staying above `stack_bottom` and 10178*72b2703bSAndreas Gohr the `openers_bottom` for this delimiter type) for the 10179*72b2703bSAndreas Gohr first matching potential opener ("matching" means same delimiter). 10180*72b2703bSAndreas Gohr 10181*72b2703bSAndreas Gohr- If one is found: 10182*72b2703bSAndreas Gohr 10183*72b2703bSAndreas Gohr + Figure out whether we have emphasis or strong emphasis: 10184*72b2703bSAndreas Gohr if both closer and opener spans have length >= 2, we have 10185*72b2703bSAndreas Gohr strong, otherwise regular. 10186*72b2703bSAndreas Gohr 10187*72b2703bSAndreas Gohr + Insert an emph or strong emph node accordingly, after 10188*72b2703bSAndreas Gohr the text node corresponding to the opener. 10189*72b2703bSAndreas Gohr 10190*72b2703bSAndreas Gohr + Remove any delimiters between the opener and closer from 10191*72b2703bSAndreas Gohr the delimiter stack. 10192*72b2703bSAndreas Gohr 10193*72b2703bSAndreas Gohr + Remove 1 (for regular emph) or 2 (for strong emph) delimiters 10194*72b2703bSAndreas Gohr from the opening and closing text nodes. If they become empty 10195*72b2703bSAndreas Gohr as a result, remove them and remove the corresponding element 10196*72b2703bSAndreas Gohr of the delimiter stack. If the closing node is removed, reset 10197*72b2703bSAndreas Gohr `current_position` to the next element in the stack. 10198*72b2703bSAndreas Gohr 10199*72b2703bSAndreas Gohr- If none is found: 10200*72b2703bSAndreas Gohr 10201*72b2703bSAndreas Gohr + Set `openers_bottom` to the element before `current_position`. 10202*72b2703bSAndreas Gohr (We know that there are no openers for this kind of closer up to and 10203*72b2703bSAndreas Gohr including this point, so this puts a lower bound on future searches.) 10204*72b2703bSAndreas Gohr 10205*72b2703bSAndreas Gohr + If the closer at `current_position` is not a potential opener, 10206*72b2703bSAndreas Gohr remove it from the delimiter stack (since we know it can't 10207*72b2703bSAndreas Gohr be a closer either). 10208*72b2703bSAndreas Gohr 10209*72b2703bSAndreas Gohr + Advance `current_position` to the next element in the stack. 10210*72b2703bSAndreas Gohr 10211*72b2703bSAndreas GohrAfter we're done, we remove all delimiters above `stack_bottom` from the 10212*72b2703bSAndreas Gohrdelimiter stack. 10213