diff --git a/guide/src/misc/contributors.md b/guide/src/misc/contributors.md index 362a21fe4f..ff3549091f 100644 --- a/guide/src/misc/contributors.md +++ b/guide/src/misc/contributors.md @@ -20,5 +20,6 @@ shout-out to them! - Vivek Akupatni ([apatniv](https://github.com/apatniv)) - Eric Huss ([ehuss](https://github.com/ehuss)) - Josh Rotenberg ([joshrotenberg](https://github.com/joshrotenberg)) +- Songlin Jiang ([HollowMan6](https://github.com/HollowMan6)) If you feel you're missing from this list, feel free to add yourself in a PR. diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index 155b0ffd21..d8a480440a 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -59,10 +59,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 @@ -71,7 +72,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 @@ -216,7 +235,23 @@ impl HtmlHandlebars { code_config: &Code, edition: OptionWhen we link to the first section, it should work on +
When we link to the first section, it should work on both the print page and the non-print page.
-A fragment link should work.
+A fragment link should work.
Link outside.