@@ -235,10 +235,10 @@ pub fn render_markdown_with_path(
235
235
// `count` is the number of references to this footnote (used for multiple
236
236
// linkbacks, and checking for unused footnotes).
237
237
let mut footnote_numbers = HashMap :: new ( ) ;
238
- // This is a list of ( name, Vec<Event>)
238
+ // This is a map of name -> Vec<Event>
239
239
// `name` is the name of the footnote.
240
240
// 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 ( ) ;
242
242
243
243
// The following are used when currently processing a footnote definition.
244
244
//
@@ -268,7 +268,13 @@ pub fn render_markdown_with_path(
268
268
Event :: End ( TagEnd :: FootnoteDefinition ) => {
269
269
let def_events = std:: mem:: take ( & mut in_footnote) ;
270
270
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
+ }
272
278
None
273
279
}
274
280
Event :: FootnoteReference ( name) => {
@@ -304,7 +310,12 @@ pub fn render_markdown_with_path(
304
310
html:: push_html ( & mut body, events) ;
305
311
306
312
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
+ ) ;
308
319
}
309
320
310
321
body
0 commit comments