Skip to main content

parse

Function parse 

Source
pub fn parse(input: &str) -> Document
Expand description

The driver loop (§13.2 “Parsing HTML documents”, the “tokenization and tree construction” step): parses input into a Document tree with per-node source positions, feeding it through the tokenizer and handing each token to the tree builder, applying the two pieces of feedback tree construction sends back to the tokenizer — a state switch (Tokenizer::switch_to, for RCDATA/RAWTEXT/script-data/PLAINTEXT elements) and the foreign-content flag (Tokenizer::set_in_foreign_content, consulted only by CDATA-section handling).

The tokenizer’s iterator yields exactly one Eof token and then ends (None) on the next call, so the loop needs no separate condition for when to stop feeding it tokens. TreeBuilder::stop_parsing (§13.2.7 “The end”) still runs once, explicitly, right after — its one tree-shape-relevant step (“pop all the nodes off the stack of open elements”) isn’t implied by the loop simply ending.