natter/src/intermediate/footnote_definition.rs

59 lines
1.7 KiB
Rust
Raw Normal View History

2023-10-27 21:08:58 +00:00
use crate::error::CustomError;
2023-10-29 17:51:32 +00:00
use super::ast_node::IAstNode;
2023-10-27 21:08:58 +00:00
use super::registry::Registry;
2023-10-29 17:51:32 +00:00
use super::IElement;
use super::IObject;
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 {}
impl IFootnoteDefinition {
2023-10-29 18:14:10 +00:00
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::FootnoteDefinition<'parse>,
2023-10-27 21:08:58 +00:00
) -> Result<IFootnoteDefinition, CustomError> {
2023-10-29 18:14:10 +00:00
registry
.register_footnote_definition(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 {
2023-10-29 18:14:10 +00:00
pub(crate) async fn new<'b, 'parse>(
registry: &'b mut Registry<'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
}