satteri-pulldown-cmark 0.3.2

A fork of the pulldown-cmark crate with MDX extensions, used in the satteri project.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
Run this with `cargo test --features gen-tests suite::footnotes`.

Parts of this test case are based on
<https://github.com/github/cmark-gfm/blob/1e230827a584ebc9938c3eadc5059c55ef3c9abf/test/extensions.txt#L702>.
Other parts were based on trial-and-error with GitHub's issue comment preview.

This spec describes nearly identical *parsing* to GFM, but not identical *rendering*. The HTML
outputting module may be extended with features such as backreferences, but these are not built
into the parser, and are unrelated to the syntax in any case. Alternative footnote rendering
styles can be found in `/examples/footnote-rewrite.rs`.

```````````````````````````````` example
Lorem ipsum.[^a] [^missing]

[^a]: Cool.
.
<p>Lorem ipsum.<sup><a href="#user-content-fn-a" id="user-content-fnref-a" data-footnote-ref aria-describedby="footnote-label">1</a></sup> [^missing]</p>
<section data-footnotes class="footnotes"><h2 class="sr-only" id="footnote-label">Footnotes</h2>
<ol>
<li id="user-content-fn-a">
<p>Cool. <a href="#user-content-fnref-a" data-footnote-backref="" aria-label="Back to reference 1" class="data-footnote-backref">↩</a></p>
</li>
</ol>
</section>
````````````````````````````````


Footnotes can be used inside blockquotes:

```````````````````````````````` example
> This is the song that never ends.\
> Yes it goes on and on my friends.[^lambchops]
>
> [^lambchops]: <https://www.youtube.com/watch?v=0U2zJOryHKQ>
.
<blockquote>
<p>This is the song that never ends.<br>
Yes it goes on and on my friends.<sup><a href="#user-content-fn-lambchops" id="user-content-fnref-lambchops" data-footnote-ref aria-describedby="footnote-label">1</a></sup></p>
</blockquote>
<section data-footnotes class="footnotes"><h2 class="sr-only" id="footnote-label">Footnotes</h2>
<ol>
<li id="user-content-fn-lambchops">
<p><a href="https://www.youtube.com/watch?v=0U2zJOryHKQ">https://www.youtube.com/watch?v=0U2zJOryHKQ</a> <a href="#user-content-fnref-lambchops" data-footnote-backref="" aria-label="Back to reference 1" class="data-footnote-backref">↩</a></p>
</li>
</ol>
</section>
````````````````````````````````


Footnotes can be complex block structures, but their contents must be indented first!

Without four spaces of indentation, no nesting:

```````````````````````````````` example
Songs that simply loop are a popular way to annoy people. [^examples]

[^examples]:
 * [The song that never ends](https://www.youtube.com/watch?v=0U2zJOryHKQ)
 * [I know a song that gets on everybody's nerves](https://www.youtube.com/watch?v=TehWI09qxls)
 * [Ninety-nine bottles of beer on the wall](https://www.youtube.com/watch?v=qVjCag8XoHQ)
.
<p>Songs that simply loop are a popular way to annoy people. <sup><a href="#user-content-fn-examples" id="user-content-fnref-examples" data-footnote-ref aria-describedby="footnote-label">1</a></sup></p>
<ul>
<li><a href="https://www.youtube.com/watch?v=0U2zJOryHKQ">The song that never ends</a></li>
<li><a href="https://www.youtube.com/watch?v=TehWI09qxls">I know a song that gets on everybody's nerves</a></li>
<li><a href="https://www.youtube.com/watch?v=qVjCag8XoHQ">Ninety-nine bottles of beer on the wall</a></li>
</ul>
<section data-footnotes class="footnotes"><h2 class="sr-only" id="footnote-label">Footnotes</h2>
<ol>
<li id="user-content-fn-examples">
<a href="#user-content-fnref-examples" data-footnote-backref="" aria-label="Back to reference 1" class="data-footnote-backref">↩</a>
</li>
</ol>
</section>
````````````````````````````````


Yes, nesting:

```````````````````````````````` example
Songs that simply loop are a popular way to annoy people. [^examples]

[^examples]:
    * [The song that never ends](https://www.youtube.com/watch?v=0U2zJOryHKQ)
    * [I know a song that gets on everybody's nerves](https://www.youtube.com/watch?v=TehWI09qxls)
    * [Ninety-nine bottles of beer on the wall](https://www.youtube.com/watch?v=qVjCag8XoHQ)
.
<p>Songs that simply loop are a popular way to annoy people. <sup><a href="#user-content-fn-examples" id="user-content-fnref-examples" data-footnote-ref aria-describedby="footnote-label">1</a></sup></p>
<section data-footnotes class="footnotes"><h2 class="sr-only" id="footnote-label">Footnotes</h2>
<ol>
<li id="user-content-fn-examples">
<ul>
<li><a href="https://www.youtube.com/watch?v=0U2zJOryHKQ">The song that never ends</a></li>
<li><a href="https://www.youtube.com/watch?v=TehWI09qxls">I know a song that gets on everybody's nerves</a></li>
<li><a href="https://www.youtube.com/watch?v=qVjCag8XoHQ">Ninety-nine bottles of beer on the wall</a></li>
</ul>
<a href="#user-content-fnref-examples" data-footnote-backref="" aria-label="Back to reference 1" class="data-footnote-backref">↩</a>
</li>
</ol>
</section>
````````````````````````````````


How this works with indented code blocks, blockquotes:

```````````````````````````````` example
[^not-code] [^code] [^quote] [^not-quote] [^indented-quote]

[^not-code]:         not code

[^code]:
        code

[^quote]: > quote

[^not-quote]:
 > external quote

[^indented-quote]:
    > indented quote
.
<p><sup><a href="#user-content-fn-not-code" id="user-content-fnref-not-code" data-footnote-ref aria-describedby="footnote-label">1</a></sup> <sup><a href="#user-content-fn-code" id="user-content-fnref-code" data-footnote-ref aria-describedby="footnote-label">2</a></sup> <sup><a href="#user-content-fn-quote" id="user-content-fnref-quote" data-footnote-ref aria-describedby="footnote-label">3</a></sup> <sup><a href="#user-content-fn-not-quote" id="user-content-fnref-not-quote" data-footnote-ref aria-describedby="footnote-label">4</a></sup> <sup><a href="#user-content-fn-indented-quote" id="user-content-fnref-indented-quote" data-footnote-ref aria-describedby="footnote-label">5</a></sup></p>
<blockquote>
<p>external quote</p>
</blockquote>
<section data-footnotes class="footnotes"><h2 class="sr-only" id="footnote-label">Footnotes</h2>
<ol>
<li id="user-content-fn-not-code">
<p>not code <a href="#user-content-fnref-not-code" data-footnote-backref="" aria-label="Back to reference 1" class="data-footnote-backref">↩</a></p>
</li>
<li id="user-content-fn-code">
<pre><code>code
</code></pre>
<a href="#user-content-fnref-code" data-footnote-backref="" aria-label="Back to reference 2" class="data-footnote-backref">↩</a>
</li>
<li id="user-content-fn-quote">
<blockquote>
<p>quote</p>
</blockquote>
<a href="#user-content-fnref-quote" data-footnote-backref="" aria-label="Back to reference 3" class="data-footnote-backref">↩</a>
</li>
<li id="user-content-fn-not-quote">
<a href="#user-content-fnref-not-quote" data-footnote-backref="" aria-label="Back to reference 4" class="data-footnote-backref">↩</a>
</li>
<li id="user-content-fn-indented-quote">
<blockquote>
<p>indented quote</p>
</blockquote>
<a href="#user-content-fnref-indented-quote" data-footnote-backref="" aria-label="Back to reference 5" class="data-footnote-backref">↩</a>
</li>
</ol>
</section>
````````````````````````````````


Line breaks in paragraphs, however, are okay. Note that GitHub *comments* have hard line breaks without escapes, while *Gists* don't.
To see compatible rendering with the examples in this file, try the code in a GitHub Gist file with a `.md` extension.

```````````````````````````````` example
[^ab] [^cd]

[^ab]: a
b

[^cd]: c\
d
.
<p><sup><a href="#user-content-fn-ab" id="user-content-fnref-ab" data-footnote-ref aria-describedby="footnote-label">1</a></sup> <sup><a href="#user-content-fn-cd" id="user-content-fnref-cd" data-footnote-ref aria-describedby="footnote-label">2</a></sup></p>
<section data-footnotes class="footnotes"><h2 class="sr-only" id="footnote-label">Footnotes</h2>
<ol>
<li id="user-content-fn-ab">
<p>a
b <a href="#user-content-fnref-ab" data-footnote-backref="" aria-label="Back to reference 1" class="data-footnote-backref">↩</a></p>
</li>
<li id="user-content-fn-cd">
<p>c<br>
d <a href="#user-content-fnref-cd" data-footnote-backref="" aria-label="Back to reference 2" class="data-footnote-backref">↩</a></p>
</li>
</ol>
</section>
````````````````````````````````


Footnotes can even have multiple paragraphs. You need to indent, though.

```````````````````````````````` example
[^lorem]: If heaven ever wishes to grant me a boon, it will be a total effacing of the results of a mere chance which fixed my eye on a certain stray piece of shelf-paper. It was nothing on which I would naturally have stumbled in the course of my daily round, for it was an old number of an Australian journal, the Sydney Bulletin for April 18, 1925. It had escaped even the cutting bureau which had at the time of its issuance been avidly collecting material for my uncle's research.

I had largely given over my inquiries into what Professor Angell called the "Cthulhu Cult", and was visiting a learned friend in Paterson, New Jersey; the curator of a local museum and a mineralogist of note. Examining one day the reserve specimens roughly set on the storage shelves in a rear room of the museum, my eye was caught by an odd picture in one of the old papers spread beneath the stones. It was the Sydney Bulletin I have mentioned, for my friend had wide affiliations in all conceivable foreign parts; and the picture was a half-tone cut of a hideous stone image almost identical with that which Legrasse had found in the swamp.

[^ipsum]: If heaven ever wishes to grant me a boon, it will be a total effacing of the results of a mere chance which fixed my eye on a certain stray piece of shelf-paper. It was nothing on which I would naturally have stumbled in the course of my daily round, for it was an old number of an Australian journal, the Sydney Bulletin for April 18, 1925. It had escaped even the cutting bureau which had at the time of its issuance been avidly collecting material for my uncle's research.

    I had largely given over my inquiries into what Professor Angell called the "Cthulhu Cult", and was visiting a learned friend in Paterson, New Jersey; the curator of a local museum and a mineralogist of note. Examining one day the reserve specimens roughly set on the storage shelves in a rear room of the museum, my eye was caught by an odd picture in one of the old papers spread beneath the stones. It was the Sydney Bulletin I have mentioned, for my friend had wide affiliations in all conceivable foreign parts; and the picture was a half-tone cut of a hideous stone image almost identical with that which Legrasse had found in the swamp.
.
<p>I had largely given over my inquiries into what Professor Angell called the "Cthulhu Cult", and was visiting a learned friend in Paterson, New Jersey; the curator of a local museum and a mineralogist of note. Examining one day the reserve specimens roughly set on the storage shelves in a rear room of the museum, my eye was caught by an odd picture in one of the old papers spread beneath the stones. It was the Sydney Bulletin I have mentioned, for my friend had wide affiliations in all conceivable foreign parts; and the picture was a half-tone cut of a hideous stone image almost identical with that which Legrasse had found in the swamp.</p>
````````````````````````````````


A footnote will end on a single line break if the following paragraph isn't indented. Note that
this behavior changed in version 0.1.0, to become more like hoedown. See issue #21.

```````````````````````````````` example
[^ipsum]: How much wood would a woodchuck chuck.

If a woodchuck could chuck wood.


# Forms of entertainment that aren't childish
.
<p>If a woodchuck could chuck wood.</p>
<h1>Forms of entertainment that aren't childish</h1>
````````````````````````````````


If the following footnote is indented, however, then it'll be included, regardless of how many
blank lines separate it from the footnote definition. See
<https://gist.github.com/notriddle/39ffd52799604bc2cf923fe21a1ea0a9>.

```````````````````````````````` example
Footnotes [^one] [^many].

[^one]:





    first paragraph inside footnote

[^many]: first paragraph inside footnote





    second paragraph still inside footnote
.
<p>Footnotes <sup><a href="#user-content-fn-one" id="user-content-fnref-one" data-footnote-ref aria-describedby="footnote-label">1</a></sup> <sup><a href="#user-content-fn-many" id="user-content-fnref-many" data-footnote-ref aria-describedby="footnote-label">2</a></sup>.</p>
<section data-footnotes class="footnotes"><h2 class="sr-only" id="footnote-label">Footnotes</h2>
<ol>
<li id="user-content-fn-one">
<p>first paragraph inside footnote <a href="#user-content-fnref-one" data-footnote-backref="" aria-label="Back to reference 1" class="data-footnote-backref">↩</a></p>
</li>
<li id="user-content-fn-many">
<p>first paragraph inside footnote</p>
<p>second paragraph still inside footnote <a href="#user-content-fnref-many" data-footnote-backref="" aria-label="Back to reference 2" class="data-footnote-backref">↩</a></p>
</li>
</ol>
</section>
````````````````````````````````


A footnote will also break if it's inside another container.

```````````````````````````````` example
> He's also really stupid. [^why]
>
> [^why]: Because your mamma!

As such, we can guarantee that the non-childish forms of entertainment are probably more entertaining to adults, since, having had a whole childhood doing the childish ones, the non-childish ones are merely the ones that haven't gotten boring yet.
.
<blockquote>
<p>He's also really stupid. <sup><a href="#user-content-fn-why" id="user-content-fnref-why" data-footnote-ref aria-describedby="footnote-label">1</a></sup></p>
</blockquote>
<p>As such, we can guarantee that the non-childish forms of entertainment are probably more entertaining to adults, since, having had a whole childhood doing the childish ones, the non-childish ones are merely the ones that haven't gotten boring yet.</p>
<section data-footnotes class="footnotes"><h2 class="sr-only" id="footnote-label">Footnotes</h2>
<ol>
<li id="user-content-fn-why">
<p>Because your mamma! <a href="#user-content-fnref-why" data-footnote-backref="" aria-label="Back to reference 1" class="data-footnote-backref">↩</a></p>
</li>
</ol>
</section>
````````````````````````````````


As a special exception, footnotes cannot be nested directly inside each other.
If they are, they act like they're declared beside each other.

```````````````````````````````` example
Nested footnotes are considered poor style. [^a] [^xkcd] [^indent1] [^indent2]

[^a]: This does not mean that footnotes cannot reference each other. [^b]

[^b]: This means that a footnote definition cannot be directly inside another footnote definition.
> This means that a footnote cannot be directly inside another footnote's body. [^e]
>
> [^e]: They can, however, be inside anything else.

[^xkcd]: [The other kind of nested footnote is, however, considered poor style.](https://xkcd.com/1208/)

[^indent1]: indent1

    [^indent2]: indent2
.
<p>Nested footnotes are considered poor style. <sup><a href="#user-content-fn-a" id="user-content-fnref-a" data-footnote-ref aria-describedby="footnote-label">1</a></sup> <sup><a href="#user-content-fn-xkcd" id="user-content-fnref-xkcd" data-footnote-ref aria-describedby="footnote-label">2</a></sup> <sup><a href="#user-content-fn-indent1" id="user-content-fnref-indent1" data-footnote-ref aria-describedby="footnote-label">3</a></sup> <sup><a href="#user-content-fn-indent2" id="user-content-fnref-indent2" data-footnote-ref aria-describedby="footnote-label">4</a></sup></p>
<blockquote>
<p>This means that a footnote cannot be directly inside another footnote's body. <sup><a href="#user-content-fn-e" id="user-content-fnref-e" data-footnote-ref aria-describedby="footnote-label">5</a></sup></p>
</blockquote>
<section data-footnotes class="footnotes"><h2 class="sr-only" id="footnote-label">Footnotes</h2>
<ol>
<li id="user-content-fn-a">
<p>This does not mean that footnotes cannot reference each other. <sup><a href="#user-content-fn-b" id="user-content-fnref-b" data-footnote-ref aria-describedby="footnote-label">6</a></sup> <a href="#user-content-fnref-a" data-footnote-backref="" aria-label="Back to reference 1" class="data-footnote-backref">↩</a></p>
</li>
<li id="user-content-fn-xkcd">
<p><a href="https://xkcd.com/1208/">The other kind of nested footnote is, however, considered poor style.</a> <a href="#user-content-fnref-xkcd" data-footnote-backref="" aria-label="Back to reference 2" class="data-footnote-backref">↩</a></p>
</li>
<li id="user-content-fn-indent1">
<p>indent1 <a href="#user-content-fnref-indent1" data-footnote-backref="" aria-label="Back to reference 3" class="data-footnote-backref">↩</a></p>
</li>
<li id="user-content-fn-indent2">
<p>indent2 <a href="#user-content-fnref-indent2" data-footnote-backref="" aria-label="Back to reference 4" class="data-footnote-backref">↩</a></p>
</li>
<li id="user-content-fn-e">
<p>They can, however, be inside anything else. <a href="#user-content-fnref-e" data-footnote-backref="" aria-label="Back to reference 5" class="data-footnote-backref">↩</a></p>
</li>
<li id="user-content-fn-b">
<p>This means that a footnote definition cannot be directly inside another footnote definition. <a href="#user-content-fnref-b" data-footnote-backref="" aria-label="Back to reference 6" class="data-footnote-backref">↩</a></p>
</li>
</ol>
</section>
````````````````````````````````

```````````````````````````````` example
[^foo] [^bar]

[^foo]: [^bar]: 1
.
<p><sup><a href="#user-content-fn-foo" id="user-content-fnref-foo" data-footnote-ref aria-describedby="footnote-label">1</a></sup> <sup><a href="#user-content-fn-bar" id="user-content-fnref-bar" data-footnote-ref aria-describedby="footnote-label">2</a></sup></p>
<section data-footnotes class="footnotes"><h2 class="sr-only" id="footnote-label">Footnotes</h2>
<ol>
<li id="user-content-fn-foo">
<a href="#user-content-fnref-foo" data-footnote-backref="" aria-label="Back to reference 1" class="data-footnote-backref">↩</a>
</li>
<li id="user-content-fn-bar">
<p>1 <a href="#user-content-fnref-bar" data-footnote-backref="" aria-label="Back to reference 2" class="data-footnote-backref">↩</a></p>
</li>
</ol>
</section>
````````````````````````````````

They do **not** need one line between each other.

```````````````````````````````` example
[^Doh] Ray Me Fa So La Te Do! [^1]

[^Doh]: I know. Wrong Doe. And it won't render right.
[^1]: Common for people practicing music.
.
<p><sup><a href="#user-content-fn-doh" id="user-content-fnref-doh" data-footnote-ref aria-describedby="footnote-label">1</a></sup> Ray Me Fa So La Te Do! <sup><a href="#user-content-fn-1" id="user-content-fnref-1" data-footnote-ref aria-describedby="footnote-label">2</a></sup></p>
<section data-footnotes class="footnotes"><h2 class="sr-only" id="footnote-label">Footnotes</h2>
<ol>
<li id="user-content-fn-doh">
<p>I know. Wrong Doe. And it won't render right. <a href="#user-content-fnref-doh" data-footnote-backref="" aria-label="Back to reference 1" class="data-footnote-backref">↩</a></p>
</li>
<li id="user-content-fn-1">
<p>Common for people practicing music. <a href="#user-content-fnref-1" data-footnote-backref="" aria-label="Back to reference 2" class="data-footnote-backref">↩</a></p>
</li>
</ol>
</section>
````````````````````````````````

ISSUE 413

```````````````````````````````` example
Lorem ipsum.[^a]

An unordered list before the footnotes:
* Ipsum
* Lorem

[^a]: Cool.
.
<p>Lorem ipsum.<sup><a href="#user-content-fn-a" id="user-content-fnref-a" data-footnote-ref aria-describedby="footnote-label">1</a></sup></p>
<p>An unordered list before the footnotes:</p>
<ul>
<li>Ipsum</li>
<li>Lorem</li>
</ul>
<section data-footnotes class="footnotes"><h2 class="sr-only" id="footnote-label">Footnotes</h2>
<ol>
<li id="user-content-fn-a">
<p>Cool. <a href="#user-content-fnref-a" data-footnote-backref="" aria-label="Back to reference 1" class="data-footnote-backref">↩</a></p>
</li>
</ol>
</section>
````````````````````````````````


Test case for more footnotes with list. Note that, while the DOM produced here is similar to
GitHub's DOM (except GitHub reorders all footnotes to the end), they have a weird flexbox setup
that causes lists nested inside footnotes to look really weird.

<https://gist.github.com/notriddle/07360ab169c650b72ab8921089b12456>

```````````````````````````````` example
Songs that simply loop are a popular way to annoy people. [^examples]

[^examples]: * [The song that never ends](https://www.youtube.com/watch?v=0U2zJOryHKQ)
* [I know a song that gets on everybody's nerves](https://www.youtube.com/watch?v=TehWI09qxls)
* [Ninety-nine bottles of beer on the wall](https://www.youtube.com/watch?v=qVjCag8XoHQ)


Songs that simply loop are a popular way to annoy people. [^examples2]

[^examples2]: * [The song that never ends](https://www.youtube.com/watch?v=0U2zJOryHKQ) 2
    * [I know a song that gets on everybody's nerves](https://www.youtube.com/watch?v=TehWI09qxls) 2
    - [Ninety-nine bottles of beer on the wall](https://www.youtube.com/watch?v=qVjCag8XoHQ) 2


Songs that simply loop are a popular way to annoy people. [^examples3]

[^examples3]: * [The song that never ends](https://www.youtube.com/watch?v=0U2zJOryHKQ) 3

    * [I know a song that gets on everybody's nerves](https://www.youtube.com/watch?v=TehWI09qxls) 3

    * [Ninety-nine bottles of beer on the wall](https://www.youtube.com/watch?v=qVjCag8XoHQ) 3
.
<p>Songs that simply loop are a popular way to annoy people. <sup><a href="#user-content-fn-examples" id="user-content-fnref-examples" data-footnote-ref aria-describedby="footnote-label">1</a></sup></p>
<ul>
<li><a href="https://www.youtube.com/watch?v=TehWI09qxls">I know a song that gets on everybody's nerves</a></li>
<li><a href="https://www.youtube.com/watch?v=qVjCag8XoHQ">Ninety-nine bottles of beer on the wall</a></li>
</ul>
<p>Songs that simply loop are a popular way to annoy people. <sup><a href="#user-content-fn-examples2" id="user-content-fnref-examples2" data-footnote-ref aria-describedby="footnote-label">2</a></sup></p>
<p>Songs that simply loop are a popular way to annoy people. <sup><a href="#user-content-fn-examples3" id="user-content-fnref-examples3" data-footnote-ref aria-describedby="footnote-label">3</a></sup></p>
<section data-footnotes class="footnotes"><h2 class="sr-only" id="footnote-label">Footnotes</h2>
<ol>
<li id="user-content-fn-examples">
<ul>
<li><a href="https://www.youtube.com/watch?v=0U2zJOryHKQ">The song that never ends</a></li>
</ul>
<a href="#user-content-fnref-examples" data-footnote-backref="" aria-label="Back to reference 1" class="data-footnote-backref">↩</a>
</li>
<li id="user-content-fn-examples2">
<ul>
<li><a href="https://www.youtube.com/watch?v=0U2zJOryHKQ">The song that never ends</a> 2</li>
<li><a href="https://www.youtube.com/watch?v=TehWI09qxls">I know a song that gets on everybody's nerves</a> 2</li>
</ul>
<ul>
<li><a href="https://www.youtube.com/watch?v=qVjCag8XoHQ">Ninety-nine bottles of beer on the wall</a> 2</li>
</ul>
<a href="#user-content-fnref-examples2" data-footnote-backref="" aria-label="Back to reference 2" class="data-footnote-backref">↩</a>
</li>
<li id="user-content-fn-examples3">
<ul>
<li>
<p><a href="https://www.youtube.com/watch?v=0U2zJOryHKQ">The song that never ends</a> 3</p>
</li>
<li>
<p><a href="https://www.youtube.com/watch?v=TehWI09qxls">I know a song that gets on everybody's nerves</a> 3</p>
</li>
<li>
<p><a href="https://www.youtube.com/watch?v=qVjCag8XoHQ">Ninety-nine bottles of beer on the wall</a> 3</p>
</li>
</ul>
<a href="#user-content-fnref-examples3" data-footnote-backref="" aria-label="Back to reference 3" class="data-footnote-backref">↩</a>
</li>
</ol>
</section>
````````````````````````````````


Test case for the relationship between link references and footnotes.
 <https://gist.github.com/notriddle/5625a3c1cb70b3067a01d7465f9d10f1>

GitHub writes
`My [cmark-gfm]<sup class="footnote-reference"><a href="#examples">1</a></sup>.`
in the first paragraph. This seems like a bug, and it's easier to fix it than
to remain compatible with it <https://github.com/pulldown-cmark/pulldown-cmark/pull/929>.

```````````````````````````````` example
My [cmark-gfm][^c].

My [cmark-gfm][cmark-gfm][^c].

My [cmark-gfm][][^c].

My [cmark-gfm] [^c].

My [cmark-gfm[^c]].

[cmark-gfm]: https://github.com/github/cmark-gfm/blob/1e230827a584ebc9938c3eadc5059c55ef3c9abf/test/extensions.txt#L702

[^c]: cmark-gfm is under the MIT license, so incorporating parts of its
    test suite into pulldown-cmark should be fine.


My [otherlink[^c]].

[otherlink[^c]]: https://github.com/github/cmark-gfm/blob/1e230827a584ebc9938c3eadc5059c55ef3c9abf/test/extensions.txt#L702
.
<p>My [cmark-gfm]<sup><a href="#user-content-fn-c" id="user-content-fnref-c" data-footnote-ref aria-describedby="footnote-label">1</a></sup>.</p>
<p>My <a href="https://github.com/github/cmark-gfm/blob/1e230827a584ebc9938c3eadc5059c55ef3c9abf/test/extensions.txt#L702">cmark-gfm</a><sup><a href="#user-content-fn-c" id="user-content-fnref-c-2" data-footnote-ref aria-describedby="footnote-label">1</a></sup>.</p>
<p>My <a href="https://github.com/github/cmark-gfm/blob/1e230827a584ebc9938c3eadc5059c55ef3c9abf/test/extensions.txt#L702">cmark-gfm</a><sup><a href="#user-content-fn-c" id="user-content-fnref-c-3" data-footnote-ref aria-describedby="footnote-label">1</a></sup>.</p>
<p>My <a href="https://github.com/github/cmark-gfm/blob/1e230827a584ebc9938c3eadc5059c55ef3c9abf/test/extensions.txt#L702">cmark-gfm</a> <sup><a href="#user-content-fn-c" id="user-content-fnref-c-4" data-footnote-ref aria-describedby="footnote-label">1</a></sup>.</p>
<p>My [cmark-gfm<sup><a href="#user-content-fn-c" id="user-content-fnref-c-5" data-footnote-ref aria-describedby="footnote-label">1</a></sup>].</p>
<p>My [otherlink<sup><a href="#user-content-fn-c" id="user-content-fnref-c-6" data-footnote-ref aria-describedby="footnote-label">1</a></sup>].</p>
<p>[otherlink<sup><a href="#user-content-fn-c" id="user-content-fnref-c-7" data-footnote-ref aria-describedby="footnote-label">1</a></sup>]: <a href="https://github.com/github/cmark-gfm/blob/1e230827a584ebc9938c3eadc5059c55ef3c9abf/test/extensions.txt#L702">https://github.com/github/cmark-gfm/blob/1e230827a584ebc9938c3eadc5059c55ef3c9abf/test/extensions.txt#L702</a></p>
<section data-footnotes class="footnotes"><h2 class="sr-only" id="footnote-label">Footnotes</h2>
<ol>
<li id="user-content-fn-c">
<p>cmark-gfm is under the MIT license, so incorporating parts of its
test suite into pulldown-cmark should be fine. <a href="#user-content-fnref-c" data-footnote-backref="" aria-label="Back to reference 1" class="data-footnote-backref">↩</a> <a href="#user-content-fnref-c-2" data-footnote-backref="" aria-label="Back to reference 1-2" class="data-footnote-backref">↩<sup>2</sup></a> <a href="#user-content-fnref-c-3" data-footnote-backref="" aria-label="Back to reference 1-3" class="data-footnote-backref">↩<sup>3</sup></a> <a href="#user-content-fnref-c-4" data-footnote-backref="" aria-label="Back to reference 1-4" class="data-footnote-backref">↩<sup>4</sup></a> <a href="#user-content-fnref-c-5" data-footnote-backref="" aria-label="Back to reference 1-5" class="data-footnote-backref">↩<sup>5</sup></a> <a href="#user-content-fnref-c-6" data-footnote-backref="" aria-label="Back to reference 1-6" class="data-footnote-backref">↩<sup>6</sup></a> <a href="#user-content-fnref-c-7" data-footnote-backref="" aria-label="Back to reference 1-7" class="data-footnote-backref">↩<sup>7</sup></a></p>
</li>
</ol>
</section>
````````````````````````````````


If a footnote definition is followed by text indented four spaces or one tab, that text will be treated as part of the footnote instead of being an indented code block. To preserve the current behavior, writing code that will be interpreted the same way under both editions, separate the code block from the footnote using an un-indented HTML comment:

```````````````````````````````` example
[^1]: footnote definition text

<!-- -->

    // indented code block
    fn main() {
        println!("hello world!");
    }
.
<!-- -->
<pre><code>// indented code block
fn main() {
    println!("hello world!");
}
</code></pre>
````````````````````````````````


Footnote definitions no longer need to be separated by blank lines. To preserve the current behavior, if you intentionally want to write a footnote reference followed by a colon at the start of a line, use a backslash escape:

```````````````````````````````` example
[^1]: footnote definition text
[^1]\: this is a reference, rather than a definition
.
````````````````````````````````


If a footnote definition is immediately followed by a list, block quote, or table, it needs to be indented by four spaces to be considered part of the footnote. To preserve the current behavior, writing code that will be interpreted the same way in either edition, you'll need to fall back to HTML syntax, since there's no easy way to write code that the *new* syntax will accept as part of the footnote without the *old* syntax considering it a code block.

When migrating to the new Edition, a table within a footnote can be written like this (under the old Edition, the table is treated as source code):

```````````````````````````````` example
[^1]:

    | column1 | column2 |
    |---------|---------|
    | row1a   | row1b   |
    | row2a   | row2b   |
.
````````````````````````````````


While [Markdown Guide] claims that you can't put footnote definitions inside lists, block quotes,
or tables. When [I try it][nesttest] in GitHub, footnote definitions are parsed when nested within
lists and blockquotes, but not tables. A footnote definition will interrupt a table if it's at the
start of a line, or just not be parsed if the table has a pipe at the start of the line.

[Markdown Guide]: https://www.markdownguide.org/extended-syntax/#footnotes
[nesttest]: https://gist.github.com/notriddle/169e8735d79639cdf6b5c4b5ba643861

```````````````````````````````` example
* First
  [^1]: test
* Second [^1] test


> first
> [^2]: test
> Second [^2] test


   First   | Second
-----------|----------
first      | second
[^3]: test | test [^3]


|    First   | Second    |
|------------|-----------|
| first      | second    |
| [^4]: test | test [^4] |

> [^5]: * test [^5]
.
<ul>
<li>First</li>
<li>Second <sup><a href="#user-content-fn-1" id="user-content-fnref-1" data-footnote-ref aria-describedby="footnote-label">1</a></sup> test</li>
</ul>
<blockquote>
<p>first</p>
</blockquote>
<table>
<thead>
<tr>
<th>First</th>
<th>Second</th>
</tr>
</thead>
<tbody>
<tr>
<td>first</td>
<td>second</td>
</tr>
</tbody>
</table>
<table>
<thead>
<tr>
<th>First</th>
<th>Second</th>
</tr>
</thead>
<tbody>
<tr>
<td>first</td>
<td>second</td>
</tr>
<tr>
<td>[^4]: test</td>
<td>test [^4]</td>
</tr>
</tbody>
</table>
<blockquote>
</blockquote>
<section data-footnotes class="footnotes"><h2 class="sr-only" id="footnote-label">Footnotes</h2>
<ol>
<li id="user-content-fn-1">
<p>test <a href="#user-content-fnref-1" data-footnote-backref="" aria-label="Back to reference 1" class="data-footnote-backref">↩</a></p>
</li>
</ol>
</section>
````````````````````````````````

Footnote labels cannot be empty.

```````````````````````````````` example
Test [^] link

[^]: https://rust-lang.org
.
<p>Test <a href="https://rust-lang.org">^</a> link</p>
````````````````````````````````

Footnote labels cannot contain line breaks, even where link labels can.

```````````````````````````````` example
[^foo\
bar]: not a footnote definition

[baz\
quux]: https://rust-lang.org

[first
second]: https://rust-lang.org

[^third
fourth]: not a footnote definition

[baz\
quux]
[^foo\
bar]
[first
second]
[^third
fourth]
.
<p>[^foo<br>
bar]: not a footnote definition</p>
<p>[^third
fourth]: not a footnote definition</p>
<p><a href="https://rust-lang.org">baz<br>
quux</a>
[^foo<br>
bar]
<a href="https://rust-lang.org">first
second</a>
[^third
fourth]</p>
````````````````````````````````

The above rules imply a few cases where something starts with `^`, but actually
parses as a link definition.

```````````````````````````````` example
[^foo
]: https://rust-lang.org

[^foo
]
.
<p><a href="https://rust-lang.org">^foo
</a></p>
````````````````````````````````

Footnote definitions can be indented up to three spaces.
At four spaces, it becomes a code block.

```````````````````````````````` example
footnote [^baz]
footnote [^quux]

    [^quux]: x

   [^baz]: x
.
<p>footnote <sup><a href="#user-content-fn-baz" id="user-content-fnref-baz" data-footnote-ref aria-describedby="footnote-label">1</a></sup>
footnote [^quux]</p>
<pre><code>[^quux]: x
</code></pre>
<section data-footnotes class="footnotes"><h2 class="sr-only" id="footnote-label">Footnotes</h2>
<ol>
<li id="user-content-fn-baz">
<p>x <a href="#user-content-fnref-baz" data-footnote-backref="" aria-label="Back to reference 1" class="data-footnote-backref">↩</a></p>
</li>
</ol>
</section>
````````````````````````````````

Multiple footnotes should be able without needing whitespace in between.

```````````````````````````````` example
Lorem ipsum.[^a][^b]

[^a]: Foo
[^b]: Bar
.
<p>Lorem ipsum.<sup><a href="#user-content-fn-a" id="user-content-fnref-a" data-footnote-ref aria-describedby="footnote-label">1</a></sup><sup><a href="#user-content-fn-b" id="user-content-fnref-b" data-footnote-ref aria-describedby="footnote-label">2</a></sup></p>
<section data-footnotes class="footnotes"><h2 class="sr-only" id="footnote-label">Footnotes</h2>
<ol>
<li id="user-content-fn-a">
<p>Foo <a href="#user-content-fnref-a" data-footnote-backref="" aria-label="Back to reference 1" class="data-footnote-backref">↩</a></p>
</li>
<li id="user-content-fn-b">
<p>Bar <a href="#user-content-fnref-b" data-footnote-backref="" aria-label="Back to reference 2" class="data-footnote-backref">↩</a></p>
</li>
</ol>
</section>
````````````````````````````````

This does work already:

```````````````````````````````` example
Lorem ipsum.[^a] [^b]

[^a]: Foo
[^b]: Bar
.
<p>Lorem ipsum.<sup><a href="#user-content-fn-a" id="user-content-fnref-a" data-footnote-ref aria-describedby="footnote-label">1</a></sup> <sup><a href="#user-content-fn-b" id="user-content-fnref-b" data-footnote-ref aria-describedby="footnote-label">2</a></sup></p>
<section data-footnotes class="footnotes"><h2 class="sr-only" id="footnote-label">Footnotes</h2>
<ol>
<li id="user-content-fn-a">
<p>Foo <a href="#user-content-fnref-a" data-footnote-backref="" aria-label="Back to reference 1" class="data-footnote-backref">↩</a></p>
</li>
<li id="user-content-fn-b">
<p>Bar <a href="#user-content-fnref-b" data-footnote-backref="" aria-label="Back to reference 2" class="data-footnote-backref">↩</a></p>
</li>
</ol>
</section>
````````````````````````````````