From b511a1a64e9076a040baf3c02a1587c40d0ec172 Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Wed, 22 Jan 2025 12:47:06 +1300 Subject: Remove 'appendix' from the links of appendix headings If a heading is prefixed with 'Appendix #:', the link to that heading will not include that prefix. This is to make it possible to rearrange appendices in a document without breaking existing links. --- src/collect_files.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/collect_files.rs') diff --git a/src/collect_files.rs b/src/collect_files.rs index 14bf0c3..de577cf 100644 --- a/src/collect_files.rs +++ b/src/collect_files.rs @@ -167,7 +167,7 @@ impl Website { let headings = document.blocks.iter() .filter_map(|block| if let Block::Heading { line, level } = block { let name = line.to_string(); - let url = make_url_safe(&name); + let url = make_url_safe(strip_appendix(&name)); let level = level.to_owned(); if !heading_set.insert(url.clone()) { duplicates.insert(url.clone()); @@ -281,7 +281,8 @@ impl Website { if page.full_url == path { let root = from.root(); if let Some(heading) = heading { - if !page.headings.iter().any(|h| h.url == make_url_safe(heading)) { + let heading = make_url_safe(strip_appendix(heading)); + if !page.headings.iter().any(|h| h.url == heading) { warn!("Page {:?} contains link to nonexistent heading {heading:?} on page {path:?}", from.name()); } return Some(format!("{root}{path}.{ext}#{heading}")); -- cgit v1.2.3-70-g09d2