Skip to content

The design language that makes your AI harness better at design.

JavaScript

The static engine applies the footer column-title rule the same way

Paul Bakaus1e6a202308cb
diff --git a/crates/html/src/quality.rs b/crates/html/src/quality.rs
index 43399428a..885dd5e2f 100644
--- a/crates/html/src/quality.rs
+++ b/crates/html/src/quality.rs
@@ -849,7 +849,8 @@ pub fn check_page_quality_from_doc(doc: &crate::dom::StaticDocument) -> Vec<Rule
.map(|f| f.id());
let opens_footer = footer.is_some() && footer != prev_footer;
let into_footer = footer.is_some() && (opens_footer || prev_opens_footer);
- if prev_level > 0 && level > prev_level + 1 && !into_footer {
+ let skips = prev_level > 0 && level > prev_level + 1;
+ if skips && !into_footer {
findings.push(RuleHit::new(
"skipped-heading",
format!(
@@ -865,7 +866,9 @@ pub fn check_page_quality_from_doc(doc: &crate::dom::StaticDocument) -> Vec<Rule
prev_level = level;
prev_text = text;
prev_footer = footer;
- prev_opens_footer = opens_footer;
+ // As in the URL engine: a footer's first heading that skipped in is
+ // a column title, and excuses nothing after it.
+ prev_opens_footer = opens_footer && !skips;
}
findings
}
diff --git a/crates/html/tests/footer_headings.rs b/crates/html/tests/footer_headings.rs
new file mode 100644
index 000000000..947e8b4fa
--- /dev/null
+++ b/crates/html/tests/footer_headings.rs
@@ -0,0 +1,27 @@
+//! `skipped-heading` and footer column titles in the static engine
+//! (r5-p29-skipped-heading-footer-titles), as in the URL engine: a skip into
+//! a footer is chrome; a skip after a footer's first heading reports when
+//! that heading itself skipped in (a column title, not a closing call to
+//! action).
+
+use impeccable_html::{detect_html_source, DetectHtmlOptions};
+use std::path::Path;
+
+fn skips(body: &str) -> Vec<String> {
+ let html = format!("<!DOCTYPE html><html><head></head><body>{body}</body></html>");
+ detect_html_source(&html, Path::new("/tmp/footer-headings.html"), &DetectHtmlOptions::default())
+ .into_iter()
+ .filter(|f| f.antipattern == "skipped-heading")
+ .map(|f| f.snippet)
+ .collect()
+}
+
+#[test]
+fn a_footer_that_opens_on_a_column_title_reports_the_next_skip() {
+ assert_eq!(
+ skips("<h2>Ready to start?</h2><footer><h4>Company</h4><h6>Legal</h6></footer>"),
+ vec!["<h4> \"Company\" followed by <h6> \"Legal\" (missing h5)"]
+ );
+ // A closing call to action inside the footer still excuses the titles.
+ assert!(skips("<h1>Energy</h1><footer><h2>Ready to level up?</h2><h4>Products</h4><h4>Company</h4></footer>").is_empty());
+}