diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index 3e12d39a..e47173d6 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -95,14 +95,15 @@ impl Renderer for HtmlHandlebars { debug!("[*]: Render template"); let rendered = try!(handlebars.render("index", &data)); + let filename = Path::new(&ch.path).with_extension("html"); + // create links for headers - let rendered = build_header_links(rendered); + let rendered = build_header_links(rendered, filename.to_str().unwrap_or("")); // fix code blocks let rendered = fix_code_blocks(rendered); // Write to file - let filename = Path::new(&ch.path).with_extension("html"); info!("[*] Creating {:?} ✓", filename.display()); try!(book.write_file(filename, &rendered.into_bytes())); @@ -144,7 +145,7 @@ impl Renderer for HtmlHandlebars { debug!("[*]: Render template"); let rendered = try!(handlebars.render("index", &data)); - let rendered = build_header_links(rendered); + let rendered = build_header_links(rendered, "print.html"); // fix code blocks let rendered = fix_code_blocks(rendered); @@ -224,7 +225,7 @@ fn make_data(book: &MDBook) -> Result Ok(data) } -fn build_header_links(html: String) -> String { +fn build_header_links(html: String, filename: &str) -> String { let regex = Regex::new(r"(.*?)").unwrap(); regex.replace_all(&html, |caps: &Captures| { @@ -251,7 +252,8 @@ fn build_header_links(html: String) -> String { } }).collect::(); - format!("{text}", level=level, id=id, text=text) + format!("{text}", + level=level, id=id, text=text, filename=filename) }).into_owned() }