Skip to content

Commit ac0ff7c

Browse files
krishanjmistryehuss
authored andcommitted
Warn on duplicate footnote definition and ignore subsequent definitions
1 parent d2235ff commit ac0ff7c

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/utils/mod.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,10 @@ pub fn render_markdown_with_path(
235235
// `count` is the number of references to this footnote (used for multiple
236236
// linkbacks, and checking for unused footnotes).
237237
let mut footnote_numbers = HashMap::new();
238-
// This is a list of (name, Vec<Event>)
238+
// This is a map of name -> Vec<Event>
239239
// `name` is the name of the footnote.
240240
// The events list is the list of events needed to build the footnote definition.
241-
let mut footnote_defs = Vec::new();
241+
let mut footnote_defs = HashMap::new();
242242

243243
// The following are used when currently processing a footnote definition.
244244
//
@@ -268,7 +268,16 @@ pub fn render_markdown_with_path(
268268
Event::End(TagEnd::FootnoteDefinition) => {
269269
let def_events = std::mem::take(&mut in_footnote);
270270
let name = std::mem::take(&mut in_footnote_name);
271-
footnote_defs.push((name, def_events));
271+
272+
if footnote_defs.contains_key(&name) {
273+
log::warn!(
274+
"footnote `{name}` in {} defined multiple times - \
275+
not updating to new definition",
276+
path.map_or_else(|| Cow::from("<unknown>"), |p| p.to_string_lossy())
277+
);
278+
} else {
279+
footnote_defs.insert(name, def_events);
280+
}
272281
None
273282
}
274283
Event::FootnoteReference(name) => {
@@ -304,7 +313,12 @@ pub fn render_markdown_with_path(
304313
html::push_html(&mut body, events);
305314

306315
if !footnote_defs.is_empty() {
307-
add_footnote_defs(&mut body, path, footnote_defs, &footnote_numbers);
316+
add_footnote_defs(
317+
&mut body,
318+
path,
319+
footnote_defs.into_iter().collect(),
320+
&footnote_numbers,
321+
);
308322
}
309323

310324
body

0 commit comments

Comments
 (0)