natter/src/intermediate/footnote_definition.rs
2023-10-29 22:31:29 -04:00

58 lines
1.6 KiB
Rust

use super::macros::intermediate;
use super::registry::register_footnote_definition;
use super::IAstNode;
use crate::error::CustomError;
use crate::intermediate::RefRegistry;
#[derive(Debug, Clone)]
pub(crate) struct IFootnoteDefinition {}
intermediate!(
IFootnoteDefinition,
FootnoteDefinition,
original,
registry,
{
register_footnote_definition(registry, original.label, &original.children).await?;
Ok(IFootnoteDefinition {})
}
);
#[derive(Debug)]
pub(crate) struct IRealFootnoteDefinition {
pub(crate) footnote_id: usize,
pub(crate) contents: Vec<IAstNode>,
}
impl IRealFootnoteDefinition {
pub(crate) async fn new<'orig, 'parse>(
_registry: RefRegistry<'orig, 'parse>,
footnote_id: usize,
contents: Vec<IAstNode>,
) -> Result<IRealFootnoteDefinition, CustomError> {
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) -> String {
format!("fnr.{}", 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) -> String {
format!("fn.{}", self.get_display_label())
}
}