Skip to main content

Module parser

Module parser 

Source
Expand description

Parses a pragmatic HTML subset into a custom Node tree; this is not an HTML5 parser.

Tags are never implicitly closed. When input ends with open tags, remaining stack entries are returned as top-level nodes. Whitespace-only ordinary text nodes are omitted; raw-text element bodies are preserved. Supported element names map to their NodeType variants; all others become NodeType::Unknown. Closing-tag names are not matched: any closing tag closes the most recently opened node. A single top-level node is returned directly; zero or multiple top-level nodes are wrapped in a synthetic Node whose tag_name is None.

safe_parse_html returns a structured error for malformed input.

Enums§

MalformedAttributeError
Errors reported for malformed HTML attributes.
MalformedTagError
Errors reported for malformed HTML tags.
ParseHTMLError
Errors that can occur while parsing HTML.

Functions§

safe_parse_html
Consumes an owned HTML string and returns a Node tree.