Skip to content

Commit 1c0a676

Browse files
Warn on duplicate footnote definition and ignore subsequent definitions
1 parent d2235ff commit 1c0a676

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/utils/mod.rs

Lines changed: 15 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,13 @@ 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!("footnote `{name}` in {} defined multiple times - not updating to new definition",
274+
path.map_or_else(|| Cow::from("<unknown>"), |p| p.to_string_lossy()));
275+
} else {
276+
footnote_defs.insert(name, def_events);
277+
}
272278
None
273279
}
274280
Event::FootnoteReference(name) => {
@@ -304,7 +310,12 @@ pub fn render_markdown_with_path(
304310
html::push_html(&mut body, events);
305311

306312
if !footnote_defs.is_empty() {
307-
add_footnote_defs(&mut body, path, footnote_defs, &footnote_numbers);
313+
add_footnote_defs(
314+
&mut body,
315+
path,
316+
footnote_defs.into_iter().collect(),
317+
&footnote_numbers,
318+
);
308319
}
309320

310321
body

0 commit comments

Comments
 (0)