Skip to content

Step 2a: Tree builder — core scaffold and basic insertion modes #57

@thomasnemer

Description

@thomasnemer

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

  • Minimal document → correct structure
  • Implicit elements:

    text → html/head/body/p created

  • Void elements:
    ,
  • Style/link extraction
  • Nested elements:

    text

  • Heading and paragraph handling

Acceptance Criteria

  • cargo test -p ie-html passes
  • Clippy clean
  • parse("

    Hello

    ") produces correct DOM

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions