Schema¶
JSON Schema validation helpers for PrairieLearn element attributes and structure.
Attribute schema error messages intentionally mirror the wording produced by
the @prairielearn/tree-sitter-htmlmustache linter. Tree validation adds
Python-side selector context for parent/child paths.
validate_element ¶
validate_element(
element: HtmlElement,
schema_path: Path,
*,
parent_tag: str | None = None,
) -> None
Validate an element's attributes against a PrairieLearn element schema.
parent_tag, when provided, is woven into the message the same way the
linter does for nested elements (e.g. <pl-answer> inside <pl-multiple-choice>).
validate_element_tree ¶
validate_element_tree(
element: HtmlElement,
manifest_path: Path,
*,
allow_legacy_underscore_tags: bool = False,
) -> None
Validate an element subtree against an element schema manifest.
This is a lightweight first pass for local structure: the root tag, contextual child tags, and each declared tag's attributes. Element Python code remains responsible for semantic validation.