Skip to main content

AccessibilityReport

Struct AccessibilityReport 

Source
pub struct AccessibilityReport {
    pub issues: Vec<Issue>,
    pub wcag_level: WcagLevel,
    pub elements_checked: usize,
    pub issue_count: usize,
    pub check_duration_ms: u64,
}
Expand description

A comprehensive accessibility check result.

§Examples

use html_generator::accessibility::{
    validate_wcag, AccessibilityConfig,
};

let html = r#"<html lang="en"><body><h1>Hi</h1></body></html>"#;
let report = validate_wcag(html, &AccessibilityConfig::default(), None).unwrap();
assert_eq!(report.issue_count, report.issues.len());

Fields§

§issues: Vec<Issue>

List of accessibility issues found

§wcag_level: WcagLevel

WCAG conformance level checked

§elements_checked: usize

Total number of elements checked

§issue_count: usize

Number of issues found

§check_duration_ms: u64

Time taken for the check (in milliseconds)

Implementations§

Source§

impl AccessibilityReport

Helper functions for WCAG validation

Source

pub fn check_keyboard_navigation( document: &Html, issues: &mut Vec<Issue>, ) -> Result<()>

Check keyboard navigation.

Walks all interactive elements (a, button, input, select, textarea, [tabindex]) and pushes a KeyboardNavigation Issue for negative tabindex values or click handlers without keyboard equivalents.

§Examples
use html_generator::accessibility::{AccessibilityReport, Issue};
use scraper::Html;

let doc = Html::parse_document(
    r#"<html><body><button tabindex="-1">x</button></body></html>"#,
);
let mut issues: Vec<Issue> = Vec::new();
AccessibilityReport::check_keyboard_navigation(&doc, &mut issues).unwrap();
assert!(issues.iter().any(|i| i.message.contains("Negative tabindex")));
§Errors

Returns Error::HtmlProcessingError if internal selector dispatch fails (none of the static selectors used here can fail in practice).

Source

pub fn check_language_attributes( document: &Html, issues: &mut Vec<Issue>, ) -> Result<()>

Check language attributes.

Verifies that the root <html> element carries a lang attribute and that any element-level lang="..." overrides are valid BCP 47 codes. Each violation is pushed to issues.

§Examples
use html_generator::accessibility::{AccessibilityReport, Issue};
use scraper::Html;

let doc = Html::parse_document(r#"<html><body><p>x</p></body></html>"#);
let mut issues: Vec<Issue> = Vec::new();
AccessibilityReport::check_language_attributes(&doc, &mut issues).unwrap();
assert!(issues.iter().any(|i| i.message.contains("Missing language")));
§Errors

Returns Error::HtmlProcessingError for internal selector dispatch failures (not reachable in practice).

Source

pub fn check_advanced_aria( document: &Html, issues: &mut Vec<Issue>, ) -> Result<()>

Check advanced ARIA usage.

Verifies that any role="..." attributes are valid for the element they appear on, and that elements with ARIA roles carry all required companion properties (e.g. a slider requires aria-valuenow).

§Examples
use html_generator::accessibility::{AccessibilityReport, Issue};
use scraper::Html;

// The `aria-label` is what makes the element match the
// `aria-*` selector that `check_advanced_aria` walks; `slider`
// requires `aria-valuenow` plus min/max, which are absent here.
let doc = Html::parse_fragment(
    r#"<div role="slider" aria-label="vol"></div>"#,
);
let mut issues: Vec<Issue> = Vec::new();
AccessibilityReport::check_advanced_aria(&doc, &mut issues).unwrap();
assert!(
    issues
        .iter()
        .any(|i| i.message.contains("required ARIA properties"))
);
§Errors

Returns Error::HtmlProcessingError for internal selector dispatch failures (not reachable in practice).

Trait Implementations§

Source§

impl Clone for AccessibilityReport

Source§

fn clone(&self) -> AccessibilityReport

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AccessibilityReport

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more