preserve dashes when generating anchors and trim whitespace
This commit is contained in:
parent
6f0b67f44f
commit
84ef4d2617
|
@ -488,7 +488,10 @@ fn id_from_content(content: &str) -> String {
|
||||||
content = content.replace(sub, "");
|
content = content.replace(sub, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
normalize_id(&content)
|
// Remove spaces and hastags indicating a header
|
||||||
|
let trimmed = content.trim().trim_left_matches("#").trim();
|
||||||
|
|
||||||
|
normalize_id(trimmed)
|
||||||
}
|
}
|
||||||
|
|
||||||
// anchors to the same page (href="#anchor") do not work because of
|
// anchors to the same page (href="#anchor") do not work because of
|
||||||
|
@ -606,7 +609,7 @@ pub fn normalize_path(path: &str) -> String {
|
||||||
pub fn normalize_id(content: &str) -> String {
|
pub fn normalize_id(content: &str) -> String {
|
||||||
content.chars()
|
content.chars()
|
||||||
.filter_map(|ch|
|
.filter_map(|ch|
|
||||||
if ch.is_alphanumeric() || ch == '_' {
|
if ch.is_alphanumeric() || ch == '_' || ch == '-' {
|
||||||
Some(ch.to_ascii_lowercase())
|
Some(ch.to_ascii_lowercase())
|
||||||
} else if ch.is_whitespace() {
|
} else if ch.is_whitespace() {
|
||||||
Some('-')
|
Some('-')
|
||||||
|
@ -661,4 +664,10 @@ mod tests {
|
||||||
assert_eq!(got, should_be);
|
assert_eq!(got, should_be);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn anchor_generation() {
|
||||||
|
assert_eq!(id_from_content("## `--passes`: add more rustdoc passes"), "--passes-add-more-rustdoc-passes");
|
||||||
|
assert_eq!(id_from_content("## Method-call expressions"), "method-call-expressions");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue