diff --git a/src/intermediate/registry.rs b/src/intermediate/registry.rs index 05dac3a..a835283 100644 --- a/src/intermediate/registry.rs +++ b/src/intermediate/registry.rs @@ -60,6 +60,10 @@ pub(crate) async fn get_footnote_reference_id<'orig, 'parse>( return Ok(pos); } + if let Some(label) = label { + promote_footnote_definition(registry.clone(), label).await?; + } + let existing_index = registry .lock() .unwrap() @@ -147,3 +151,21 @@ async fn convert_definition_contents<'orig, 'parse>( Ok(contents) } + +/// Take a footnote definition that has not yet received a reference and move it into the active footnotes. +pub(crate) async fn promote_footnote_definition<'orig, 'parse>( + registry: RefRegistry<'orig, 'parse>, + label: &'parse str, +) -> Result<(), CustomError> { + let definition = { + let mut registry = registry.lock().unwrap(); + let definition = registry.on_deck_footnote_ids.remove(label); + definition + }; + if let Some(elements) = definition { + let contents = convert_definition_contents(registry.clone(), elements).await?; + let mut registry = registry.lock().unwrap(); + registry.footnote_ids.push((Some(label), contents)); + } + Ok(()) +}