natter/src/intermediate/footnote_definition.rs

58 lines
1.6 KiB
Rust
Raw Normal View History

use super::macros::intermediate;
use super::registry::register_footnote_definition;
2023-10-27 21:08:58 +00:00
use super::registry::Registry;
use super::IAstNode;
use crate::error::CustomError;
use crate::intermediate::RefRegistry;
2023-10-27 21:08:58 +00:00
2023-10-29 19:36:15 +00:00
#[derive(Debug, Clone)]
2023-10-27 21:08:58 +00:00
pub(crate) struct IFootnoteDefinition {}
intermediate!(
IFootnoteDefinition,
FootnoteDefinition,
original,
registry,
{
register_footnote_definition(registry, original.label, &original.children).await?;
2023-10-27 21:08:58 +00:00
Ok(IFootnoteDefinition {})
}
);
2023-10-29 17:51:32 +00:00
#[derive(Debug)]
pub(crate) struct IRealFootnoteDefinition {
2023-10-29 19:36:15 +00:00
pub(crate) footnote_id: usize,
pub(crate) contents: Vec<IAstNode>,
2023-10-29 17:51:32 +00:00
}
impl IRealFootnoteDefinition {
pub(crate) async fn new<'orig, 'parse>(
registry: RefRegistry<'orig, 'parse>,
2023-10-29 17:51:32 +00:00
footnote_id: usize,
2023-10-29 18:14:10 +00:00
contents: Vec<IAstNode>,
2023-10-29 17:51:32 +00:00
) -> Result<IRealFootnoteDefinition, CustomError> {
Ok(IRealFootnoteDefinition {
footnote_id,
contents,
})
}
2023-10-29 19:36:15 +00:00
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())
}
2023-10-29 17:51:32 +00:00
}