46 lines
1.6 KiB
Rust
46 lines
1.6 KiB
Rust
use super::macros::intermediate;
|
|
use super::registry::get_footnote_reference_id;
|
|
use super::registry::Registry;
|
|
use crate::error::CustomError;
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub(crate) struct IFootnoteReference {
|
|
footnote_id: usize,
|
|
duplicate_offset: usize,
|
|
}
|
|
|
|
intermediate!(IFootnoteReference, FootnoteReference, original, registry, {
|
|
let (footnote_id, reference_count) =
|
|
get_footnote_reference_id(registry, original.label, &original.definition).await?;
|
|
Ok(IFootnoteReference {
|
|
footnote_id,
|
|
duplicate_offset: reference_count,
|
|
})
|
|
});
|
|
|
|
impl IFootnoteReference {
|
|
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.
|
|
let append = 100 + self.duplicate_offset - 1;
|
|
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())
|
|
}
|
|
}
|