Files
natter/src/intermediate/footnote_definition.rs
Tom Alexander 397d4ea0bc
All checks were successful
rust-test Build rust-test has succeeded
rust-clippy Build rust-clippy has succeeded
build-natter Build build-natter has succeeded
format Build format has succeeded
Fix clippy issues.
2023-12-23 07:08:06 -05:00

72 lines
2.3 KiB
Rust

use super::macros::intermediate;
use super::registry::register_footnote_definition;
use super::IAstNode;
use super::IntermediateContext;
use crate::error::CustomError;
use organic::types::StandardProperties;
#[derive(Debug, Clone)]
pub(crate) struct IFootnoteDefinition {
pub(crate) post_blank: organic::types::PostBlank,
}
intermediate!(
IFootnoteDefinition,
&'orig organic::types::FootnoteDefinition<'parse>,
original,
intermediate_context,
{
register_footnote_definition(intermediate_context, original.label, &original.children)
.await?;
Ok(IFootnoteDefinition {
post_blank: original.get_post_blank(),
})
}
);
#[derive(Debug)]
pub(crate) struct IRealFootnoteDefinition {
// TODO: Do I need post_blank for the real footnote definitions?
pub(crate) footnote_id: usize,
pub(crate) contents: Vec<IAstNode>,
}
impl IRealFootnoteDefinition {
pub(crate) async fn new<'orig, 'parse>(
_intermediate_context: IntermediateContext<'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, id_addition: Option<&str>) -> String {
let id_addition = id_addition
.map(|id_addition| format!("sec{}.", id_addition))
.unwrap_or_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_default();
format!("{}fn.{}", id_addition, self.get_display_label())
}
}