From afc6a71a79346a4a21ca5d0c6c410397c6adddf5 Mon Sep 17 00:00:00 2001 From: Phil Lord Date: Tue, 21 Jun 2022 14:53:07 +0100 Subject: [PATCH] Allow new lines before anchor (#1905) Previously the heuristic check for links required spaces before the attribute to ensure that attributes suffixed with `id` were not identified. This has now been expanded to any white space character to enable the `id` attribute to start on a new line. --- components/utils/src/anchors.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/components/utils/src/anchors.rs b/components/utils/src/anchors.rs index 642e58937f..06af56b47b 100644 --- a/components/utils/src/anchors.rs +++ b/components/utils/src/anchors.rs @@ -6,7 +6,7 @@ pub fn has_anchor_id(content: &str, anchor: &str) -> bool { } fn anchor_id_checks(anchor: &str) -> Regex { - Regex::new(&format!(r#" (?i)(id|name) *= *("|')*{}("|'| |>)+"#, anchor)).unwrap() + Regex::new(&format!(r#"\s(?i)(id|name) *= *("|')*{}("|'| |>)+"#, anchor)).unwrap() } #[cfg(test)] @@ -39,5 +39,12 @@ mod tests { // Case variants assert!(m(r#""#)); assert!(m(r#""#)); + + // Newline variants + assert!(m(r#""#)); + + // Non matchers + assert!(!m(r#""#)) } }