Files
natter/src/intermediate/footnote_definition.rs

72 lines
2.3 KiB
Rust
Raw Normal View History

use super::macros::intermediate;
use super::registry::register_footnote_definition;
use super::IAstNode;
2023-12-21 14:56:58 -05:00
use super::IntermediateContext;
use crate::error::CustomError;
2023-12-21 14:56:58 -05:00
use organic::types::StandardProperties;
2023-10-27 17:08:58 -04:00
2023-10-29 15:36:15 -04:00
#[derive(Debug, Clone)]
2023-12-21 14:56:58 -05:00
pub(crate) struct IFootnoteDefinition {
pub(crate) post_blank: organic::types::PostBlank,
}
2023-10-27 17:08:58 -04:00
intermediate!(
IFootnoteDefinition,
&'orig organic::types::FootnoteDefinition<'parse>,
original,
intermediate_context,
{
register_footnote_definition(intermediate_context, original.label, &original.children)
.await?;
2023-12-21 14:56:58 -05:00
Ok(IFootnoteDefinition {
post_blank: original.get_post_blank(),
})
2023-10-27 17:08:58 -04:00
}
);
2023-10-29 13:51:32 -04:00
#[derive(Debug)]
pub(crate) struct IRealFootnoteDefinition {
2023-12-21 14:56:58 -05:00
// TODO: Do I need post_blank for the real footnote definitions?
2023-10-29 15:36:15 -04:00
pub(crate) footnote_id: usize,
pub(crate) contents: Vec<IAstNode>,
2023-10-29 13:51:32 -04:00
}
impl IRealFootnoteDefinition {
pub(crate) async fn new<'orig, 'parse>(
_intermediate_context: IntermediateContext<'orig, 'parse>,
2023-10-29 13:51:32 -04:00
footnote_id: usize,
2023-10-29 14:14:10 -04:00
contents: Vec<IAstNode>,
2023-10-29 13:51:32 -04:00
) -> Result<IRealFootnoteDefinition, CustomError> {
Ok(IRealFootnoteDefinition {
footnote_id,
contents,
})
}
2023-10-29 15:36:15 -04: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, id_addition: Option<&str>) -> String {
let id_addition = id_addition
.map(|id_addition| format!("sec{}.", id_addition))
.unwrap_or(String::default());
format!("{}fnr.{}", id_addition, self.get_display_label())
2023-10-29 15:36:15 -04:00
}
/// 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(String::default());
format!("{}fn.{}", id_addition, self.get_display_label())
2023-10-29 15:36:15 -04:00
}
2023-10-29 13:51:32 -04:00
}