diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index b6be764f..aa7c7ee7 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -410,7 +410,7 @@ fn build_header_links(html: String, filename: &str) -> String { .into_owned() } -/// Wraps a single header tag with a link, making sure each tag gets its own +/// Wraps a single header tag with a link, making sure each tag gets its own /// unique ID by appending an auto-incremented number (if necessary). fn wrap_header_with_link(level: usize, content: &str, id_counter: &mut HashMap, filename: &str) -> String { @@ -434,6 +434,8 @@ fn wrap_header_with_link(level: usize, content: &str, id_counter: &mut HashMap String { let mut content = content.to_string(); @@ -455,19 +457,17 @@ fn id_from_content(content: &str) -> String { content = content.replace(sub, ""); } - content.chars() - .filter_map(|c| if c.is_alphanumeric() || c == '-' || c == '_' { - if c.is_ascii() { - Some(c.to_ascii_lowercase()) - } else { - Some(c) - } - } else if c.is_whitespace() && c.is_ascii() { - Some('-') - } else { - None - }) - .collect() + let mut id = String::new(); + + for c in content.chars() { + if c.is_alphanumeric() || c == '-' || c == '_' { + id.push(c.to_ascii_lowercase()); + } else if c.is_whitespace() { + id.push(c); + } + } + + id } // anchors to the same page (href="#anchor") do not work because of @@ -509,7 +509,7 @@ fn fix_code_blocks(html: String) -> String { let classes = &caps[2].replace(",", " "); let after = &caps[3]; - format!("", before = before, classes = classes, after = after) + format!(r#""#, before = before, classes = classes, after = after) }) .into_owned() } @@ -593,7 +593,8 @@ mod tests { ("

Foo^bar

", r#"

Foo^bar

"#), ("

", r#"

"#), ("

", r#"

"#), - ("

Foo

Foo

", r#"

Foo

Foo

"#), + ("

Foo

Foo

", + r#"

Foo

Foo

"#), ]; for (src, should_be) in inputs {