Skip to content

Commit

Permalink
Allow new lines before anchor (#1905)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
phillord authored Jun 21, 2022
1 parent 72243d9 commit afc6a71
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion components/utils/src/anchors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -39,5 +39,12 @@ mod tests {
// Case variants
assert!(m(r#"<a ID="fred">"#));
assert!(m(r#"<a iD="fred">"#));

// Newline variants
assert!(m(r#"<a
id="fred">"#));

// Non matchers
assert!(!m(r#"<a notid="fred">"#))
}
}

0 comments on commit afc6a71

Please sign in to comment.