Skip to content

footnote reference specification

Zhiguang Chen edited this page Jul 14, 2022 · 1 revision

A footnote reference consists of a label, optionally preceded by up to three spaces of indentation, followed by a colon (:), optional spaces or tabs(including up to one line ending), followed by a note content.

The reverse link should be attached immediately at the end of the last text or inline element.

There cannot be whitespaces between (]) and (:)

INPUT:

Foo[^1]

[^1] : not a note

OUTPUT:

<p>Foo[^1]</p>
<p>[^1] : not a note</p>

The whitespaces between (:) and content is optional

INPUT:

Foo[^1]

[^1]:this is a note

OUTPUT:

<p>Foo<sup id="fnref:1" class="footnote"><a href="#fn:1">1</a></sup></p>
<ol class="footnotes">
<li id="fn:1">this is a note<a class="footnote-reverse" href="#fnref:1"></a></li>
</ol>

The leading whitespaces and trailing whitespaces will be removed from note content

INPUT:

Foo[^1]

[^1]:    bar    

OUTPUT:

<p>Foo<sup id="fnref:1" class="footnote"><a href="#fn:1">1</a></sup></p>
<ol class="footnotes">
<li id="fn:1">bar<a class="footnote-reverse" href="#fnref:1"></a></li>
</ol>

INPUT:

Foo[^1]

[^1]:    bar    
baz  

OUTPUT:

<p>Foo<sup id="fnref:1" class="footnote"><a href="#fn:1">1</a></sup></p>
<ol class="footnotes">
<li id="fn:1">bar<br />
baz<a class="footnote-reverse" href="#fnref:1"></a></li>
</ol>

A footnote reference cannot interrupt a paragraph

INPUT:

Foo[^1]

Bar
[^1]: This is not a footnote reference.

OUTPUT:

<p>Foo[^1]</p>
<p>Bar
[^1]: This is not a footnote reference.</p>

The continuation after a blank line needs to have an indentation with at least two whitespaces or with a tab

This example will produce two paragraphs because of the blank line.

INPUT:

Foo[^1]

[^1]: line 1

  this is a continuation of line 1

OUTPUT:

<p>Foo<sup id="fnref:1" class="footnote"><a href="#fn:1">1</a></sup></p>
<ol class="footnotes">
<li id="fn:1">
<p>line 1</p>
<p>this is a continuation of line 1</p><a class="footnote-reverse" href="#fnref:1"></a></li>
</ol>

INPUT:

Foo[^1]

[^1]: line 1

Not part of the note

OUTPUT:

<p>Foo<sup id="fnref:1" class="footnote"><a href="#fn:1">1</a></sup></p>
<p>Not part of the note</p>
<ol class="footnotes">
<li id="fn:1">line 1<a class="footnote-reverse" href="#fnref:1"></a></li>
</ol>

The indention of each line will be removed from note content

INPUT:

Foo[^1]

[^1]:
  bar
  baz

  zoo

OUTPUT:

<p>Foo<sup id="fnref:1" class="footnote"><a href="#fn:1">1</a></sup></p>
<ol class="footnotes">
<li id="fn:1">
<p>bar
baz</p>
<p>zoo</p><a class="footnote-reverse" href="#fnref:1"></a></li>
</ol>

A note can start with one blank line, but the indentation is also required

INPUT:

Foo[^1]

[^1]:
  bar

OUTPUT:

<p>Foo<sup id="fnref:1" class="footnote"><a href="#fn:1">1</a></sup></p>
<ol class="footnotes">
<li id="fn:1">bar<a class="footnote-reverse" href="#fnref:1"></a></li>
</ol>

INPUT:

Foo[^1]

[^1]:
not a note

OUTPUT:

<p>Foo[^1]</p>
<p>[^1]:
not a note</p>

INPUT:

Foo[^1]

[^1]:

  not a note

OUTPUT:

<p>Foo[^1]</p>
<p>[^1]:</p>
<p>not a note</p>

Several footnote references can occur one after another, without intervening blank lines

INPUT:

Foo[^one]bar[^2]

[^one]: note 1
[^2]: note 2

OUTPUT:

<p>Foo<sup id="fnref:one" class="footnote"><a href="#fn:one">1</a></sup>bar<sup id="fnref:2" class="footnote"><a href="#fn:2">2</a></sup></p>
<ol class="footnotes">
<li id="fn:one">note 1<a class="footnote-reverse" href="#fnref:one"></a></li>
<li id="fn:2">note 2<a class="footnote-reverse" href="#fnref:2"></a></li>
</ol>

Directly followed block elements cannot interrupt a footnote reference

It means a footnote reference can contain only inline elements.

INPUT:

Foo[^1]

[^1]: foo
1. bar
> biz
***
    note is continue

OUTPUT:

<p>Foo<sup id="fnref:1" class="footnote"><a href="#fn:1">1</a></sup></p>
<ol class="footnotes">
<li id="fn:1">foo
1. bar
&gt; biz
***
note is continue<a class="footnote-reverse" href="#fnref:1"></a></li>
</ol>

A footnote reference cannot be nested in other elements

INPUT:

Foo[^1]

> [^1]: not a note

OUTPUT:

<p>Foo[^1]</p>
<blockquote>
<p>[^1]: not a note</p>
</blockquote>

It does not matter whether the footnote references have the same order as footnotes

INPUT:

Foo[^1]bar[^2]

[^2]: note 2
[^3]: note 3

Biz[^3]

[^1]: note 1

OUTPUT:

<p>Foo<sup id="fnref:1" class="footnote"><a href="#fn:1">1</a></sup>bar<sup id="fnref:2" class="footnote"><a href="#fn:2">2</a></sup></p>
<p>Biz<sup id="fnref:3" class="footnote"><a href="#fn:3">3</a></sup></p>
<ol class="footnotes">
<li id="fn:1">note 1<a class="footnote-reverse" href="#fnref:1"></a></li>
<li id="fn:2">note 2<a class="footnote-reverse" href="#fnref:2"></a></li>
<li id="fn:3">note 3<a class="footnote-reverse" href="#fnref:3"></a></li>
</ol>

The footnote references do not match a footnote will be ignored

INPUT:

Foo[^1]

[^2]: biz
[^1]: bar

OUTPUT:

<p>Foo<sup id="fnref:1" class="footnote"><a href="#fn:1">1</a></sup></p>
<ol class="footnotes">
<li id="fn:1">bar<a class="footnote-reverse" href="#fnref:1"></a></li>
</ol>