diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs
index 2eeb946fe4..9e2c70d634 100644
--- a/src/renderer/html_handlebars/hbs_renderer.rs
+++ b/src/renderer/html_handlebars/hbs_renderer.rs
@@ -779,15 +779,19 @@ fn make_data(
}
/// Goes through part of the rendered print page HTML,
-/// add path id prefix to all the elements id.
+/// add path id prefix to all the elements id as well as footnote links.
fn build_print_element_id(html: &str, path_id: &str) -> String {
- let regex = Regex::new(r#"(<[^>]*?id=")([^"]+?)""#).unwrap();
+ let all_id = Regex::new(r#"(<[^>]*?id=")([^"]+?)""#).unwrap();
+ let footnote_id = Regex::new(
+ r##"(]*?class="footnote-reference"[^>]*?>[^<]*?]*?href="#)([^"]+?)""##,
+ )
+ .unwrap();
if path_id.is_empty() {
return html.to_string();
}
- regex
+ let temp_html = all_id
.replace_all(html, |caps: &Captures<'_>| {
let mut fixed = String::new();
fixed.push_str(&path_id);
@@ -795,6 +799,16 @@ fn build_print_element_id(html: &str, path_id: &str) -> String {
fixed.push_str(&caps[2]);
format!("{}{}\"", &caps[1], fixed)
})
+ .into_owned();
+
+ footnote_id
+ .replace_all(&temp_html, |caps: &Captures<'_>| {
+ let mut fixed = String::new();
+ fixed.push_str(&path_id);
+ fixed.push_str("-");
+ fixed.push_str(&caps[2]);
+ format!("{}{}\"", &caps[1], fixed)
+ })
.into_owned()
}