A lenient HTML fragment parser.
It produces the same mutable DOM the WordML side uses, so the AST builder can navigate and rewrite HTML exactly the way it does markup from the template.
Parsing follows the parts of the HTML rules that matter for document content:
tag and attribute names are case insensitive, attribute values may be
unquoted or absent, void elements never nest, and tags with optional end tags
(p, li, tr, td, ...) are closed implicitly. Whitespace is preserved
everywhere - a space between two inline tags is content, and dropping it
would silently run two words together in the rendered document.
Summary
Functions
Decodes HTML character references.
The name given to the fragment's root element.
Parses html and returns the fragment's root element.
Parses html into a tree of {:element, name, attrs, children},
{:text, binary} and {:comment, binary} tuples. Exposed for testing the
parser on its own.
Functions
Decodes HTML character references.
Numeric references are always decoded; named ones are decoded when they are in the supported table and otherwise left as written, which keeps unknown markup intact rather than mangling it.
@spec fragment_name() :: binary()
The name given to the fragment's root element.
@spec parse_fragment(binary()) :: Sablon.XML.Node.t()
Parses html and returns the fragment's root element.
The root is named #document-fragment, matching the tag the configuration
registers for top level content.
Parses html into a tree of {:element, name, attrs, children},
{:text, binary} and {:comment, binary} tuples. Exposed for testing the
parser on its own.