a11y-static
Browser-free audit of static HTML: HTML text plus fetched stylesheet texts in, one Report out.
Turns “HTML text and the stylesheet texts the host fetched” into an a11y-report Report,
so a host only fetches and prints. It replaces the glue that tools otherwise write by hand:
parse tree to Semantics via accname, Rendering over style-cascade, stylesheet
discovery, and the right order of run_full and run_stylesheets.
Status
0.1.0, not yet published. barrierlab-cli will adopt it once it is on crates.io; it does
not yet. The crate is the third place the same chain exists, and astro-post-audit
(casoon/astro-post-audit#115) is the second consumer of the cascade.
Structure
Public surface
| Item | Purpose |
|---|---|
audit(html, sheets, env) | one call: parse and audit, English texts |
Page::parse(html) | the parsed document |
Page::stylesheet_refs() | StylesheetRef::Link { href, media } and Inline { css, media }, in document order |
Page::audit(sheets, env, locale) | runs all rule tiers and the stylesheet rules, adds input notes |
Sheet::new(source, css) | a fetched sheet; source is the href of the link, verbatim |
Sheet::failed(source, reason) | a sheet the host could not fetch; reason becomes the note detail |
Sheet::inert(source) | a sheet the host declares as without effect on styles (a web-font stylesheet); an @import it answers is dropped, nothing stays undetermined |
Sheet::with_media(m), Sheet::with_imports(v) | the media of the link it answers; the sheets it @imports |
Sheet { source, css, media, failure, imports, inert } | the fields behind these; #[non_exhaustive], build through the constructors |
Environment, Locale | re-exported from style-cascade and a11y-rules |
feature de | German finding texts |
Behaviour
- Discovery.
<link>counts with thereltokenstylesheet, withoutalternate, withoutdisabled, with a non-emptyhref. Every<style>counts. Elements inside<template>do not. - Media. A
mediaattribute wraps the sheet’s rules in@media; the cascade decides against theEnvironment. - Matching. A
<link>is answered by theSheetwith the samehrefandmedia(media compared trimmed, ASCII case-insensitive). ASheetwithoutmediaanswers any link with thathref; an exact match wins over it. Two links with the samehrefand differentmediaeach need their ownSheet. - URLs.
sourceis the URL as written; resolving it against the page URL, fetching, and policy (size, scheme, redirects) are the host’s job. The crate does no I/O and no URL resolution. - Imports. The crate does not follow
@import. A host that loads imported sheets puts them inSheet::imports(matched bysourceequal to the URL in the@import, nested to any depth, cycles stop at 16 levels or on repetition); the import is then replaced by the imported rules, in place, wrapped as the import says:layer/layer(x)puts the rules in that cascade layer (Cascade 5 §6.4.1),supports()and a media list become@supportsand@media(seestyle_cascade::Import). For an@importin an inline<style>the top-levelsheetsare searched. - Web-font imports.
@import url(https://fonts.googleapis.com/…)of a sheet that only holds@font-facewould leave every colour undetermined. The host, which knows (or decides), answers it withSheet::inert(url)inSheet::imports(or the top-levelsheetsfor an inline<style>): the import is dropped, noStylesheetUnresolvednote, the contrast rules decide. The crate never infers this from a URL.style_cascade::imports_in(css)lists the imports of a text, if the host needs to see them first. The expansion itself isstyle_cascade::expand_imports, public for hosts with their own adapter. - Missing input. A
<link>without a usableSheetgivesInputKind::StylesheetUnavailable, withSheet::failureas detail if the host gave a reason; so does a qualifying<link>with empty or missinghref(no subject; it is not instylesheet_refs, there is nothing to fetch). An@importthat stays unresolved givesInputKind::StylesheetUnresolved(detail: the import’s failure reason, if any). While either note is present, the internal host claims no colour or background (displayandvisibilitystay), so the contrast rules reportuntested, never pass or fail on an unstyled page. - Not rendered.
aria-hidden="true"andinert(node or ancestor) make a node ignored;display: none(including thehiddenattribute through the UA rules),visibility: hiddenandcollapsemake it not rendered.
Source positions
Page::audit fills Location::position (SourcePosition: line and column from 1, byte offset
from 0) on every finding whose Location::node names a node, after the rules ran; no rule is
involved. The values come from html5-parser: the offset is a byte offset into the text handed to
parse, and for an element it is the < of its start tag. The column counts characters (not
bytes) since the last line break; CRLF and lone CR count as one line break, and the offset still
refers to the original text. Tests over a document with multi-byte text and with CRLF check that
the offset points at the offending tag for images/alt-missing, links/name-missing and
buttons/name-missing.
Location::end is filled from the same source: for an element it is the position just past the
closing > of its start tag (exclusive), so position..end spans the start tag. It is not
the end of the whole element: the content and the end tag are not covered. It stays empty for a
finding on a text node. A node the parser synthesized takes the end of the same ancestor it takes
its position from. An end is only set together with the position this pass writes.
Findings that get no position:
- Findings on a node the parser synthesized (implied
<html>,<head>,<body>,<tbody>) take the position of the nearest ancestor that exists in the source (an implied<tbody>points at its<table>); with no such ancestor (an implied<html>) they stay empty. - Findings without a node (none seen from the current rules; the stylesheet and page rules name the root element).
Page-level findings (document language, title, stylesheet rules) name the root element, so
their position is that of an explicit <html> tag and empty when the source has none. A finding
on a text node points at the start of the text, not at a tag. A position already present is not
overwritten.
Dependencies
Downward: html5-parser, a11y-dom (feature html5-parser), a11y-report, a11y-rules,
accname, style-cascade, stylesheet-parse. Upward: hosts.
Limits
- No layout: no box geometry, so rules that need it do not decide.
- A sheet supplied for no
<link>(and no import) is ignored; the host fetches whatstylesheet_refsnames. - Imports are not followed, only the ones the host hands over are applied (
Sheet::imports,Sheet::inert). - An unresolved
@importin a sheet that has amediacondition is treated as unconditional.