diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index 30d4c84b..1de1325f 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -56,10 +56,11 @@ impl HtmlHandlebars { let content = utils::render_markdown(&ch.content, ctx.html_config.smart_punctuation()); - let fixed_content = utils::render_markdown_with_path( + let printed_item = utils::render_markdown_with_path_and_redirects( &ch.content, ctx.html_config.smart_punctuation(), Some(path), + &ctx.html_config.redirect, ); if !ctx.is_index && ctx.html_config.print.page_break { // Add page break between chapters @@ -68,7 +69,25 @@ impl HtmlHandlebars { print_content .push_str(r#"
"#); } - print_content.push_str(&fixed_content); + let print_page_id = { + let mut base = path.display().to_string(); + if base.ends_with(".md") { + base.truncate(base.len() - 3); + } + &base + .replace("/", "-") + .replace("\\", "-") + .to_ascii_lowercase() + }; + + // We have to build header links in advance so that we can know the ranges + // for the headers in one page. + // Insert a dummy div to make sure that we can locate the specific page. + print_content.push_str(&(format!(r#""#))); + print_content.push_str(&build_header_links( + &build_print_element_id(&printed_item, &print_page_id), + Some(print_page_id), + )); // Update the context with data for this file let ctx_path = path @@ -214,7 +233,23 @@ impl HtmlHandlebars { code_config: &Code, edition: Option