2023-10-29 21:29:16 +00:00
|
|
|
use super::macros::intermediate;
|
2023-10-30 01:19:30 +00:00
|
|
|
use super::registry::get_footnote_reference_id;
|
2023-10-27 21:48:19 +00:00
|
|
|
use super::registry::Registry;
|
2023-10-29 21:29:16 +00:00
|
|
|
use crate::error::CustomError;
|
2023-10-27 21:48:19 +00:00
|
|
|
|
2023-10-29 19:36:15 +00:00
|
|
|
#[derive(Debug, Clone)]
|
2023-10-29 16:06:40 +00:00
|
|
|
pub(crate) struct IFootnoteReference {
|
|
|
|
footnote_id: usize,
|
2023-10-29 16:53:28 +00:00
|
|
|
duplicate_offset: usize,
|
2023-10-29 16:06:40 +00:00
|
|
|
}
|
2023-10-27 21:48:19 +00:00
|
|
|
|
2023-10-29 22:35:42 +00:00
|
|
|
intermediate!(IFootnoteReference, FootnoteReference, original, registry, {
|
2023-10-30 02:27:47 +00:00
|
|
|
let (footnote_id, reference_count) =
|
2023-10-30 01:19:30 +00:00
|
|
|
get_footnote_reference_id(registry, original.label, &original.definition).await?;
|
2023-10-29 22:35:42 +00:00
|
|
|
Ok(IFootnoteReference {
|
|
|
|
footnote_id,
|
2023-10-30 02:27:47 +00:00
|
|
|
duplicate_offset: reference_count,
|
2023-10-29 22:35:42 +00:00
|
|
|
})
|
|
|
|
});
|
2023-10-29 16:53:28 +00:00
|
|
|
|
2023-10-29 21:29:16 +00:00
|
|
|
impl IFootnoteReference {
|
2023-10-29 16:53:28 +00:00
|
|
|
pub(crate) fn get_display_label(&self) -> String {
|
|
|
|
format!("{}", self.footnote_id + 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Get an ID to refer to this footnote reference.
|
|
|
|
///
|
|
|
|
/// 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 {
|
|
|
|
if self.duplicate_offset == 0 {
|
|
|
|
format!("fnr.{}", self.get_display_label())
|
|
|
|
} else {
|
|
|
|
// Org-mode makes all duplicates use "100" but I figure there is no harm in giving each a unique ID.
|
2023-10-30 02:27:47 +00:00
|
|
|
let append = 100 + self.duplicate_offset - 1;
|
2023-10-29 16:53:28 +00:00
|
|
|
format!("fnr.{}.{}", self.get_display_label(), append)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Get an ID to refer to the footnote definition this footnote reference references.
|
|
|
|
///
|
|
|
|
/// 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-27 21:48:19 +00:00
|
|
|
}
|
|
|
|
}
|