Conformance¶
check() runs the HTML5 authoring-conformance rules over a document parsed with turbohtml.parse() and returns
a ConformanceReport – a valid verdict plus every ConformanceMessage, each with a stable code,
a Severity, a description, and a source line and column. The document is valid exactly when nothing is an error.
The whole walk runs in the C core; the Python layer only wraps the findings. check_html() parses a markup string
first.
- turbohtml.conformance.check(document)[source]¶
Check a parsed document (or any subtree) against the HTML5 authoring rules.
The document-level rules (a missing title or
lang) apply only whendocumentis a wholeDocument; on a fragment or a subtree only the per-element rules run.- Parameters:
document (
Document|Node) – a tree parsed withturbohtml.parse()(or an element within one).- Return type:
- Returns:
the
ConformanceReportwith the verdict and every message.
- turbohtml.conformance.check_html(markup)[source]¶
Parse a markup string with
turbohtml.parse()and check the resulting document.- Parameters:
markup (
str) – the HTML to parse and check.- Return type:
- Returns:
the
ConformanceReportfor the parsed document.
- class turbohtml.conformance.ConformanceReport(valid: bool, messages: tuple[ConformanceMessage, ...])[source]¶
The outcome of a conformance check: a
validverdict and every message found.The report is truthy exactly when the document is valid (no message is an error), so
if check(doc):reads naturally. Warnings and info messages never affect the verdict.- Parameters:
valid (
bool)messages (
tuple[ConformanceMessage,...])
- messages: tuple[ConformanceMessage, ...]¶
Alias for field number 1
- property errors: tuple[ConformanceMessage, ...]¶
Only the
"error"messages – the findings that make the document invalid.
- property warnings: tuple[ConformanceMessage, ...]¶
Only the
"warning"messages – the authoring recommendations.
- property infos: tuple[ConformanceMessage, ...]¶
Only the
"info"messages – the advisory notes.
- class turbohtml.conformance.ConformanceMessage(code: str, severity: Severity, message: str, line: int, column: int)[source]¶
One conformance finding.
- Parameters:
code (
str) – a stable machine-readable identifier for the rule, such as"img-missing-alt".severity (
Literal['error','warning','info']) –"error"for a violated requirement,"warning"for an authoring recommendation,"info"for an advisory note.message (
str) – a human-readable description of what was found.line (
int) – the 1-based source line of the offending node, or0when unknown.column (
int) – the 0-based source column of the offending node, or0when unknown.
- turbohtml.conformance.Severity¶
The three severities a
ConformanceMessagecarries, ordered most to least serious.alias of
Literal[‘error’, ‘warning’, ‘info’]