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
//! Footnote normalization utilities.
//!
//! Converts bare numeric references in text to GitHub-flavoured Markdown
//! footnote links and normalizes footnote numbering and ordering by
//! orchestrating specialised submodules.
use ;
use convert_block;
use ;
use debug;
use crate;
/// Rewrite bare numeric references as Markdown footnote references.
///
/// This is the length-changing half of [`convert_footnotes`]: a reference such
/// as `docs.1` grows into `docs.[^1]`, so any pass that measures text — the table
/// reflow and the paragraph wrap — has to run after it rather than before. It is
/// separate from the rest so the caller can place the two halves either side of
/// those passes; see `process_stream_inner`.
/// Rewrites bare numeric references while preserving Setext heading text.
///
/// `process_stream_inner` invokes this when it will subsequently convert Setext
/// headings, so a line the heading pass will read as heading text keeps its bare
/// references: `docs.1` above an underline is heading text, not a reference.
/// Standalone callers keep the historical behaviour of
/// [`convert_inline_footnotes`], which has no heading-conversion context.
pub
/// Applies token-aware inline conversion while preserving protected heading
/// text.
///
/// `setext_text_lines` identifies lines whose numeric text will later become a
/// Setext heading; those lines must pass through unchanged in this stage.
/// Rewrite footnote labels to their sequential numbers.
///
/// This is the second length-changing half of [`convert_footnotes`]: a reference
/// such as `[^10]` becomes `[^1]` once the distinct references are numbered by
/// first encounter, and a definition header is rewritten from the same mapping,
/// so both narrow the line they sit on and any pass that measures text has to
/// run after them. The same scan promotes a trailing ordered-list item that a
/// reference shares its number with into a definition header, which widens the
/// line instead, and for the same reason belongs on this side of those passes.
/// It is separate from [`convert_footnote_definitions`], which settles the
/// block structure — converting a trailing ordered list that no reference
/// reaches, and reordering the definitions — so the caller can place the two
/// halves either side of those passes; see `process_stream_inner`.
///
/// Lines inside fenced code blocks are left alone.
/// Fold a trailing ordered list into definitions and reorder the block.
///
/// This is the structural half of [`convert_footnotes`]: it settles the block
/// and keeps the number each header already carries, because those are
/// [`renumber_footnote_labels`]'s work. Numbering them here as well would take
/// fresh numbers from the pool for the definitions no reference points at, in
/// line order, which moves a definition the label stage had placed earlier to
/// the end of the block.
///
/// The one list it does number is the one it folds itself, and it numbers that
/// from one: `convert_block` converts a heading-led trailing list only when no
/// reference and no definition has claimed a number, so the items are the only
/// definitions in the document and the list's own marker numbers say nothing
/// about where they belong. It reads the block structure around that list, so
/// it runs after the heading pass has settled the structure, and it rewrites
/// list items as definition headers, so it runs after the passes that lay lines
/// out.
/// Convert bare numeric footnote references to Markdown footnote syntax.
///
/// Equivalent to running [`convert_inline_footnotes`],
/// [`renumber_footnote_labels`], and [`convert_footnote_definitions`] in that
/// order; the CLI splits the three around its layout passes, and this
/// whole-document form stays for callers that need them in one step.