Skip to content

Commit d06af86

Browse files
committed
Fix for print page footnote links
By adding the path id prefix Signed-off-by: Hollow Man <[email protected]>
1 parent 67cd8ae commit d06af86

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/renderer/html_handlebars/hbs_renderer.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -779,22 +779,36 @@ fn make_data(
779779
}
780780

781781
/// Goes through part of the rendered print page HTML,
782-
/// add path id prefix to all the elements id.
782+
/// add path id prefix to all the elements id as well as footnote links.
783783
fn build_print_element_id(html: &str, path_id: &str) -> String {
784-
let regex = Regex::new(r#"(<[^>]*?id=")([^"]+?)""#).unwrap();
784+
let all_id = Regex::new(r#"(<[^>]*?id=")([^"]+?)""#).unwrap();
785+
let footnote_id = Regex::new(
786+
r##"(<sup [^>]*?class="footnote-reference"[^>]*?>[^<]*?<a [^>]*?href="#)([^"]+?)""##,
787+
)
788+
.unwrap();
785789

786790
if path_id.is_empty() {
787791
return html.to_string();
788792
}
789793

790-
regex
794+
let temp_html = all_id
791795
.replace_all(html, |caps: &Captures<'_>| {
792796
let mut fixed = String::new();
793797
fixed.push_str(&path_id);
794798
fixed.push_str("-");
795799
fixed.push_str(&caps[2]);
796800
format!("{}{}\"", &caps[1], fixed)
797801
})
802+
.into_owned();
803+
804+
footnote_id
805+
.replace_all(&temp_html, |caps: &Captures<'_>| {
806+
let mut fixed = String::new();
807+
fixed.push_str(&path_id);
808+
fixed.push_str("-");
809+
fixed.push_str(&caps[2]);
810+
format!("{}{}\"", &caps[1], fixed)
811+
})
798812
.into_owned()
799813
}
800814

0 commit comments

Comments
 (0)