PureHTML.TreeBuilder.InsertionMode behaviour (PureHTML v0.4.0)

View Source

Behavior for HTML5 insertion mode handlers.

Each insertion mode module implements this behavior to handle tokens according to the HTML5 tree construction algorithm.

See: https://html.spec.whatwg.org/multipage/parsing.html#the-insertion-mode

Summary

Callbacks

Process a token in this insertion mode.

Types

result()

@type result() ::
  {:ok, PureHTML.TreeBuilder.State.t()}
  | {:reprocess, PureHTML.TreeBuilder.State.t()}

token()

@type token() ::
  {:doctype, String.t(), String.t() | nil, String.t() | nil, boolean()}
  | {:start_tag, String.t(), map(), boolean()}
  | {:end_tag, String.t()}
  | {:character, String.t()}
  | {:comment, String.t()}
  | :eof

Callbacks

process(token, t)

@callback process(token(), PureHTML.TreeBuilder.State.t()) :: result()

Process a token in this insertion mode.

Returns either:

  • {:ok, state} - Token fully processed, continue with next token
  • {:reprocess, state} - Token should be reprocessed in the new mode

The state may include a mode transition.