Statifier.Parser.DOM (Statifier v2.0.0)

Copy Markdown View Source

The generic document tree Statifier.Parser.parse/1 produces, and the three accessors every lowering builder would otherwise re-implement.

A tree is Statifier.Parser.DOM.Element structs whose children interleave further elements with Statifier.Parser.DOM.Text runs in document order, each carrying a Statifier.Parser.Location span.

The tree is deliberately unvalidated: unknown names, duplicate attributes, missing namespace declarations, and structurally nonsensical documents all parse successfully. The DOM reports what was written and lets the validator object.

Summary

Functions

The first attribute of element named name, or nil.

element's children, filtered to elements.

The concatenated decoded value of element's direct text children.

Functions

attribute(element, name)

@spec attribute(element :: Statifier.Parser.DOM.Element.t(), name :: binary()) ::
  Statifier.Parser.DOM.Attribute.t() | nil

The first attribute of element named name, or nil.

First, not only: duplicates are preserved in attributes, so a caller that wants to report one has the whole list to look at.

elements(element)

@spec elements(element :: Statifier.Parser.DOM.Element.t()) :: [
  Statifier.Parser.DOM.Element.t()
]

element's children, filtered to elements.

The whitespace filter for readers that want structure rather than markup: text runs between child elements are kept in the tree (the parser cannot know which of them are significant without knowing the vocabulary), and this is where a caller drops them.

text(element)

@spec text(element :: Statifier.Parser.DOM.Element.t()) :: binary()

The concatenated decoded value of element's direct text children.

Child elements contribute nothing - this is the text of element itself, not of the subtree.