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 when document is a whole Document; on a fragment or a subtree only the per-element rules run.

Parameters:

document (Document | Node) – a tree parsed with turbohtml.parse() (or an element within one).

Return type:

ConformanceReport

Returns:

the ConformanceReport with 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:

ConformanceReport

Returns:

the ConformanceReport for the parsed document.

class turbohtml.conformance.ConformanceReport(valid: bool, messages: tuple[ConformanceMessage, ...])[source]

The outcome of a conformance check: a valid verdict 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

Alias for field number 0

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, or 0 when unknown.

  • column (int) – the 0-based source column of the offending node, or 0 when unknown.

code: str

Alias for field number 0

severity: Literal['error', 'warning', 'info']

Alias for field number 1

message: str

Alias for field number 2

line: int

Alias for field number 3

column: int

Alias for field number 4

turbohtml.conformance.Severity

The three severities a ConformanceMessage carries, ordered most to least serious.

alias of Literal[‘error’, ‘warning’, ‘info’]