Skip to content

Commit

Permalink
Fix for print page footnote links
Browse files Browse the repository at this point in the history
By adding the path id prefix

Signed-off-by: Hollow Man <hollowman@opensuse.org>
  • Loading branch information
HollowMan6 committed Feb 9, 2022
1 parent 67cd8ae commit d06af86
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/renderer/html_handlebars/hbs_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -779,22 +779,36 @@ 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##"(<sup [^>]*?class="footnote-reference"[^>]*?>[^<]*?<a [^>]*?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);
fixed.push_str("-");
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()
}

Expand Down

0 comments on commit d06af86

Please sign in to comment.