2023-10-29 21:29:16 +00:00
|
|
|
use super::macros::intermediate;
|
2023-10-30 01:19:30 +00:00
|
|
|
use super::registry::register_footnote_definition;
|
2023-10-30 02:31:29 +00:00
|
|
|
|
2023-10-29 21:29:16 +00:00
|
|
|
use super::IAstNode;
|
|
|
|
use crate::error::CustomError;
|
2023-10-30 01:19:30 +00:00
|
|
|
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 {}
|
|
|
|
|
2023-10-29 21:29:16 +00:00
|
|
|
intermediate!(
|
|
|
|
IFootnoteDefinition,
|
|
|
|
FootnoteDefinition,
|
2023-10-29 22:35:42 +00:00
|
|
|
original,
|
|
|
|
registry,
|
|
|
|
{
|
2023-10-30 01:19:30 +00:00
|
|
|
register_footnote_definition(registry, original.label, &original.children).await?;
|
2023-10-27 21:08:58 +00:00
|
|
|
Ok(IFootnoteDefinition {})
|
|
|
|
}
|
2023-10-29 21:29:16 +00:00
|
|
|
);
|
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-30 01:19:30 +00:00
|
|
|
pub(crate) async fn new<'orig, 'parse>(
|
2023-10-30 02:31:29 +00:00
|
|
|
_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
|
|
|
}
|