-
Notifications
You must be signed in to change notification settings - Fork 963
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add heuristic checking for HTML anchors
Previously only anchors specified or generated in markdown could be linked to, without complaint from the link checker. We now use a simple heuristic check for `name` or `id` attributes. Duplicate code has been refactored and all XML anchor checks updated to use regex rather than substring match.
- Loading branch information
Showing
11 changed files
with
71 additions
and
24 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
pub mod de; | ||
pub mod fs; | ||
pub mod links; | ||
pub mod minify; | ||
pub mod net; | ||
pub mod site; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use regex::Regex; | ||
|
||
|
||
pub fn anchor_id_checks(anchor:&str) -> Regex { | ||
Regex::new( | ||
&format!(r#" (?i)(id|ID|name|NAME) *= *("|')*{}("|'| |>)+"#, anchor) | ||
).unwrap() | ||
} | ||
|
||
|
||
#[cfg(test)] | ||
mod tests{ | ||
use super::anchor_id_checks; | ||
|
||
fn check(anchor:&str, content:&str) -> bool { | ||
anchor_id_checks(anchor).is_match(content) | ||
} | ||
|
||
#[test] | ||
fn matchers () { | ||
let m = |content| {check("fred", content)}; | ||
|
||
// Canonical match/non match | ||
assert!(m(r#"<a name="fred">"#)); | ||
assert!(m(r#"<a id="fred">"#)); | ||
assert!(!m(r#"<a name="george">"#)); | ||
|
||
// Whitespace variants | ||
assert!(m(r#"<a id ="fred">"#)); | ||
assert!(m(r#"<a id = "fred">"#)); | ||
assert!(m(r#"<a id="fred" >"#)); | ||
assert!(m(r#"<a id="fred" >"#)); | ||
|
||
// Quote variants | ||
assert!(m(r#"<a id='fred'>"#)); | ||
assert!(m(r#"<a id=fred>"#)); | ||
|
||
// Case variants | ||
assert!(m(r#"<a ID="fred">"#)); | ||
assert!(m(r#"<a iD="fred">"#)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters