Parent: #21
Goal
Implement the TreeBuilder scaffold and the basic insertion modes that handle a typical HTML document: Initial, BeforeHtml, BeforeHead, InHead, AfterHead, InBody (basic elements only), Text, AfterBody, AfterAfterBody. No adoption agency, no tables, no templates.
File Changes
crates/ie-html/src/tree_builder.rs — rewrite with TreeBuilder struct
crates/ie-html/src/insertion_mode.rs — new file, mode enum + basic modes
crates/ie-html/src/lib.rs — update parse() signature
Implementation
TreeBuilder struct
- Document, tokenizer, insertion_mode, open_elements stack
- head_pointer, form_pointer, frameset_ok
- ParseResult { document, errors, style_elements, link_stylesheets }
Core operations
- insert_element, insert_character, insert_comment
- generate_implied_end_tags, close_element
- Switch tokenizer state for script/style/title/textarea
Insertion modes (basic)
- Initial: doctype handling
- BeforeHtml: insert
- BeforeHead: insert
- InHead: <title>, <style>, <script>, , ,
- AfterHead: insert
- InBody: basic block/inline/void elements,
closing, heading nesting
- Text: raw text for style/script
- AfterBody, AfterAfterBody
Tests
Acceptance Criteria
- cargo test -p ie-html passes
- Clippy clean
- parse("
Hello
") produces correct DOM
Parent: #21
Goal
Implement the TreeBuilder scaffold and the basic insertion modes that handle a typical HTML document: Initial, BeforeHtml, BeforeHead, InHead, AfterHead, InBody (basic elements only), Text, AfterBody, AfterAfterBody. No adoption agency, no tables, no templates.
File Changes
crates/ie-html/src/tree_builder.rs— rewrite with TreeBuilder structcrates/ie-html/src/insertion_mode.rs— new file, mode enum + basic modescrates/ie-html/src/lib.rs— update parse() signatureImplementation
TreeBuilder struct
Core operations
Insertion modes (basic)
closing, heading nesting
Tests
text → html/head/body/p created
,
text
Acceptance Criteria
Hello
") produces correct DOM