Merge pull request #1683 from abdnh/strip-html-from-anchor-ids
Strip HTML tags from anchor IDs
This commit is contained in:
commit
857acb9759
|
@ -48,19 +48,11 @@ pub fn id_from_content(content: &str) -> String {
|
||||||
let mut content = content.to_string();
|
let mut content = content.to_string();
|
||||||
|
|
||||||
// Skip any tags or html-encoded stuff
|
// Skip any tags or html-encoded stuff
|
||||||
const REPL_SUB: &[&str] = &[
|
lazy_static! {
|
||||||
"<em>",
|
static ref HTML: Regex = Regex::new(r"(<.*?>)").unwrap();
|
||||||
"</em>",
|
}
|
||||||
"<code>",
|
content = HTML.replace_all(&content, "").into();
|
||||||
"</code>",
|
const REPL_SUB: &[&str] = &["<", ">", "&", "'", """];
|
||||||
"<strong>",
|
|
||||||
"</strong>",
|
|
||||||
"<",
|
|
||||||
">",
|
|
||||||
"&",
|
|
||||||
"'",
|
|
||||||
""",
|
|
||||||
];
|
|
||||||
for sub in REPL_SUB {
|
for sub in REPL_SUB {
|
||||||
content = content.replace(sub, "");
|
content = content.replace(sub, "");
|
||||||
}
|
}
|
||||||
|
@ -351,6 +343,10 @@ more text with spaces
|
||||||
);
|
);
|
||||||
assert_eq!(id_from_content("## **Bold** title"), "bold-title");
|
assert_eq!(id_from_content("## **Bold** title"), "bold-title");
|
||||||
assert_eq!(id_from_content("## `Code` title"), "code-title");
|
assert_eq!(id_from_content("## `Code` title"), "code-title");
|
||||||
|
assert_eq!(
|
||||||
|
id_from_content("## title <span dir=rtl>foo</span>"),
|
||||||
|
"title-foo"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in New Issue