Debian Codegraph @

docs/extensions/footnotes.md

raw
1 title: Footnotes Extension
2
3 Footnotes
4 =========
5
6 Summary
7 -------
8
9 The Footnotes extension adds syntax for defining footnotes in Markdown
10 documents.
11
12 This extension is included in the standard Markdown library.
13
14 !!! Note
15
16 This extension is in __maintenance mode__. We will continue to fix bugs
17 and keep it up-to-date with the core parser, but no new features or
18 changes in behavior will be made. If you need a feature that this
19 extension does not offer, then you have three options (1) find an
20 existing [third-party extension] which meets your needs, (2) [build your
21 own extension], or (3) fork this extension (pursuant to its licensing
22 requirements) and maintain it as a third-party extension.
23
24 [third-party extension]: index.md#third-party-extensions
25 [build your own extension]: api.md
26
27 Syntax
28 ------
29
30 Python-Markdown's Footnote syntax follows the generally accepted syntax of the
31 Markdown community at large and almost exactly matches [PHP Markdown Extra][]'s
32 implementation of footnotes. The only differences involve a few subtleties in
33 the output.
34
35 [PHP Markdown Extra]: http://michelf.com/projects/php-markdown/extra/#footnotes
36
37 Example:
38
39 ```md
40 Footnotes have a name, a reference[^1], and a definition[^word].
41
42 [^1]: This is a footnote definition.
43 [^word]: A footnote with the name "word".
44 ```
45
46 A **footnote name** is a string that uniquely identifies a footnote within the
47 document. It may contain any character which is valid for an HTML id attribute
48 (including spaces). Examples: `1` in `[^1]`, `word` in `[^word]`,
49 and `@#$%` in `[^@#$%]`.
50
51 A **footnote reference** is a link within the text body to a footnote definition.
52 A footnote reference contains the footnote name prefixed by a caret `^` and enclosed
53 in square brackets `[]`. Examples: `[^1]` and `[^@#$%]`. In the output, footnote
54 references are replaced by a superscript number that links to the footnote definition.
55
56 A **footnote definition** must start with the corresponding footnote reference
57 followed by a colon and at least one space. The reference must exactly match
58 the reference used in the body (including capitalization and white space).
59 The content of the definition would then follow either on the same line
60 (`[^1]: This is a footnote definition.`) or on the next line.
61 Footnote definitions may contain multiple lines, paragraphs, code blocks,
62 blockquotes and most any other markdown syntax. The additional lines must be
63 indented one level (four spaces or one tab).
64
65 When working with multiple blocks, it may be helpful to start the definition on a
66 separate line from the reference which defines the content. This way the entire block
67 is indented consistently and any errors are more easily discernible by the author.
68
69 ```md
70 [^1]:
71 The first paragraph of the definition.
72
73 Paragraph two of the definition.
74
75 > A blockquote with
76 > multiple lines.
77
78 a code block
79
80 A final paragraph.
81 ```
82
83 Usage
84 -----
85
86 See [Extensions](index.md) for general extension usage. Use `footnotes` as the
87 name of the extension.
88
89 See the [Library Reference](../reference.md#extensions) for information about
90 configuring extensions.
91
92 The following options are provided to configure the output:
93
94 * **`PLACE_MARKER`**:
95 A text string used to mark the position where the footnotes are rendered.
96 Defaults to `///Footnotes Go Here///`.
97
98 If the place marker text is not found in the document, the footnote
99 definitions are placed at the end of the resulting HTML document.
100
101 * **`UNIQUE_IDS`**:
102 Whether to avoid collisions across multiple calls to `reset()`. Defaults to
103 `False`.
104
105 * **`BACKLINK_TEXT`**:
106 The text string that links from the footnote definition back to the position
107 in the document. Defaults to `↩`.
108
109 * **`SUPERSCRIPT_TEXT`**:
110 The text string that links from the position in the document to the footnote
111 definition. Defaults to `{}`, i.e. only the footnote's number.
112
113 * **`BACKLINK_TITLE`**:
114 The text string for the `title` HTML attribute of the footnote definition link.
115 The placeholder `{}` will be replaced by the footnote number. Defaults to
116 `Jump back to footnote {} in the text`.
117
118 * **`SEPARATOR`**:
119 The text string used to set the footnote separator. Defaults to `:`.
120
121 * **`USE_DEFINITION_ORDER`**:
122 Order footnotes by definition order (`True`) or by document order (`False`).
123 Defaults to `True`.
124
125 The default behavior matches the behavior prior to this option being added.
126 Disabling this option (setting to `False`) is experimental and results may not
127 be consistent.
128
129 A trivial example:
130
131 ```python
132 markdown.markdown(some_text, extensions=['footnotes'])
133 ```
134
135 Resetting Instance State
136 -----
137
138 Footnote definitions are stored within the `markdown.Markdown` class instance between
139 multiple runs of the class. This allows footnotes from all runs to be included in
140 output, with links and references that are unique, even though the class has been
141 called multiple times.
142
143 However, if needed, the definitions can be cleared between runs by calling `reset`.
144
145 For instance, the home page of a blog might include the content from multiple documents.
146 By not calling `reset`, all of the footnotes will be rendered, and they will all have
147 unique links and references.
148
149 On the other hand, individual blog post pages might need the content from only one
150 document, and should have footnotes pertaining only to that page. By calling `reset`
151 between runs, the footnote definitions from the first document will be cleared before
152 the second document is rendered.
153
154 An example of calling `reset`:
155
156 ```python
157 md = markdown.Markdown(extensions=['footnotes'])
158 html1 = md.convert(text_with_footnote)
159 md.reset()
160 html2 = md.convert(text_without_footnote)
161 ```