NativeElixirPdfUtilities.HtmlToPdf.HtmlParser (native_elixir_pdf_utilities v0.3.0)

View Source

Strict HTML parser for the native HTML-to-PDF renderer.

Supports a strict subset of document-oriented HTML: structural html/head/body/style tags, paragraphs, headings, inline emphasis/color containers, div containers for flex/grid layouts, lists, links, tables, images, and CSS-targeting attributes. Unsupported or malformed markup returns an error instead of guessing at browser behavior.

Summary

Functions

Parses an HTML binary into a renderer DOM tree.

Parses an HTML binary and returns source-location details when parsing fails.

Types

dom_tree()

@type dom_tree() :: %{type: :document, children: [element_node()]}

element_node()

@type element_node() :: %{
  type: :element,
  tag: String.t(),
  attributes: map(),
  children: [text_node() | element_node()]
}

text_node()

@type text_node() :: %{type: :text, text: String.t()}

Functions

parse(html)

@spec parse(String.t()) ::
  {:ok, dom_tree()} | {:error, :invalid_html | :unsupported_html}

Parses an HTML binary into a renderer DOM tree.

parse_detailed(html)

@spec parse_detailed(String.t()) ::
  {:ok, dom_tree()} | {:error, {:invalid_html | :unsupported_html, map()}}

Parses an HTML binary and returns source-location details when parsing fails.