use super::macros::intermediate; use super::registry::register_footnote_definition; use super::IntermediateContext; use super::IAstNode; use crate::error::CustomError; #[derive(Debug, Clone)] pub(crate) struct IFootnoteDefinition {} intermediate!( IFootnoteDefinition, &'orig organic::types::FootnoteDefinition<'parse>, original, intermediate_context, { register_footnote_definition(intermediate_context, original.label, &original.children) .await?; Ok(IFootnoteDefinition {}) } ); #[derive(Debug)] pub(crate) struct IRealFootnoteDefinition { pub(crate) footnote_id: usize, pub(crate) contents: Vec, } impl IRealFootnoteDefinition { pub(crate) async fn new<'orig, 'parse>( _intermediate_context: IntermediateContext<'orig, 'parse>, footnote_id: usize, contents: Vec, ) -> Result { Ok(IRealFootnoteDefinition { footnote_id, contents, }) } pub(crate) fn get_display_label(&self) -> String { format!("{}", self.footnote_id + 1) } /// Get an ID to refer to the first reference to this footnote definition. /// /// This ID could, for example, be used for the id attribute in HTML for the reference anchor tag. pub(crate) fn get_reference_id(&self, id_addition: Option<&str>) -> String { let id_addition = id_addition .map(|id_addition| format!("sec{}.", id_addition)) .unwrap_or(String::default()); format!("{}fnr.{}", id_addition, self.get_display_label()) } /// Get an ID to refer to the footnote definition. /// /// This ID could, for example, be used for the id attribute in HTML for the definition anchor tag. pub(crate) fn get_definition_id(&self, id_addition: Option<&str>) -> String { let id_addition = id_addition .map(|id_addition| format!("sec{}.", id_addition)) .unwrap_or(String::default()); format!("{}fn.{}", id_addition, self.get_display_label()) } }