use super::prelude::*;
pub fn render_footnote(ctx: &mut HtmlContext) {
debug!("Rendering footnote reference");
let index = ctx.next_footnote_index();
let id = str!(index);
let footnote_string = ctx.handle().get_message(ctx.language(), "footnote");
let label = format!("{footnote_string} {index}.");
let contents = ctx
.get_footnote(index)
.expect("Footnote index out of bounds from gathered footnote list");
ctx.html()
.span()
.attr(attr!("class" => "wj-footnote-ref"))
.inner(|ctx| {
ctx.html()
.element("wj-footnote-ref-marker")
.attr(attr!(
"class" => "wj-footnote-ref-marker",
"role" => "link",
"aria-label" => &label,
"data-id" => &id,
))
.contents(&id);
ctx.html()
.span()
.attr(attr!(
"class" => "wj-footnote-ref-tooltip",
"aria-hidden" => "true",
))
.inner(|ctx| {
ctx.html()
.span()
.attr(attr!("class" => "wj-footnote-ref-tooltip-label"))
.contents(&label);
ctx.html()
.span()
.attr(attr!("class" => "wj-footnote-ref-contents"))
.contents(contents);
});
});
}
pub fn render_footnote_block(ctx: &mut HtmlContext, title: Option<&str>) {
debug!(
"Rendering footnote block (title {})",
title.unwrap_or("<default>"),
);
let title_default;
let title: &str = match title {
Some(title) => title,
None => {
title_default = ctx
.handle()
.get_message(ctx.language(), "footnote-block-title");
title_default
}
};
ctx.html()
.div()
.attr(attr!("class" => "wj-footnote-list"))
.inner(|ctx| {
ctx.html()
.div()
.attr(attr!("class" => "wj-title"))
.contents(title);
ctx.html().ol().inner(|ctx| {
for (index, contents) in ctx.footnotes().iter().enumerate() {
let index = index + 1;
let id = &format!("{index}");
ctx.html()
.li()
.attr(attr!(
"class" => "wj-footnote-list-item",
"data-id" => id,
))
.inner(|ctx| {
ctx.html()
.element("wj-footnote-list-item-marker")
.attr(attr!(
"class" => "wj-footnote-list-item-marker",
"type" => "button",
"role" => "link",
))
.inner(|ctx| {
str_write!(ctx, "{index}");
ctx.html()
.span()
.attr(attr!("class" => "wj-footnote-sep"))
.contents(".");
});
ctx.html()
.span()
.attr(attr!("class" => "wj-footnote-list-item-contents"))
.contents(contents);
});
}
});
});
}