class

HTML5::StreamingParser

Inherits HTML5::Parser < Reference < Object

StreamingParser wraps the standard HTML5 parser and emits SAX-style events via a StreamingHandler as the document tree is constructed.

It works by subclassing Parser and intercepting the tree-building methods (add_child, add_text) to emit events while preserving correct HTML5 parsing behavior. Element close events are emitted via a custom NodeStack that intercepts pop operations.

Constructors

new(r : IO, handler : StreamingHandler, **opts)
Source

Instance methods

add_child(n : Node)

Override add_child to emit events when nodes are added to the tree.

Source
add_text(text : String)

Override add_text to emit text events correctly for all three code paths:

  1. Foster parenting (bypasses add_child)
  2. Appending to existing text node (bypasses add_child)
  3. New text node (goes through add_child)
Source
oe=(arr : Array(Node))

Override oe= to emit close events for elements removed by stack slicing. Many insertion modes do p.oe = p.oe[...i] to pop multiple elements.

Source
parse

Run the parse loop.

Source