2023-10-29 17:29:16 -04:00
|
|
|
use super::macros::intermediate;
|
2023-10-29 21:19:30 -04:00
|
|
|
use super::registry::register_footnote_definition;
|
2023-10-29 17:29:16 -04:00
|
|
|
use super::IAstNode;
|
2023-12-21 14:56:58 -05:00
|
|
|
use super::IntermediateContext;
|
2023-10-29 17:29:16 -04:00
|
|
|
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
|
|
|
|
2023-10-29 17:29:16 -04:00
|
|
|
intermediate!(
|
|
|
|
|
IFootnoteDefinition,
|
2023-12-19 17:09:11 -05:00
|
|
|
&'orig organic::types::FootnoteDefinition<'parse>,
|
2023-10-29 18:35:42 -04:00
|
|
|
original,
|
2023-12-21 13:53:56 -05:00
|
|
|
intermediate_context,
|
2023-10-29 18:35:42 -04:00
|
|
|
{
|
2023-12-21 13:53:56 -05:00
|
|
|
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 17:29:16 -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 {
|
2023-10-29 21:19:30 -04:00
|
|
|
pub(crate) async fn new<'orig, 'parse>(
|
2023-12-21 13:53:56 -05:00
|
|
|
_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.
|
2023-12-19 17:51:35 -05:00
|
|
|
pub(crate) fn get_reference_id(&self, id_addition: Option<&str>) -> String {
|
|
|
|
|
let id_addition = id_addition
|
|
|
|
|
.map(|id_addition| format!("sec{}.", id_addition))
|
2023-12-23 06:38:23 -05:00
|
|
|
.unwrap_or_default();
|
2023-12-19 17:51:35 -05:00
|
|
|
|
|
|
|
|
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.
|
2023-12-19 17:51:35 -05:00
|
|
|
pub(crate) fn get_definition_id(&self, id_addition: Option<&str>) -> String {
|
|
|
|
|
let id_addition = id_addition
|
|
|
|
|
.map(|id_addition| format!("sec{}.", id_addition))
|
2023-12-23 06:38:23 -05:00
|
|
|
.unwrap_or_default();
|
2023-12-19 17:51:35 -05:00
|
|
|
|
|
|
|
|
format!("{}fn.{}", id_addition, self.get_display_label())
|
2023-10-29 15:36:15 -04:00
|
|
|
}
|
2023-10-29 13:51:32 -04:00
|
|
|
}
|