Premailex.HTMLParser behaviour (Premailex v0.3.11) View Source

Module that provide HTML parsing API using an underlying HTML parser library.

Link to this section Summary

Functions

Searches an HTML tree for the selector.

Filters elements matching the selector from the HTML tree.

Parses a HTML string into an HTML tree.

Extracts text elements from the HTML tree.

Turns an HTML tree into a string.

Link to this section Types

Specs

html_tree() :: tuple() | list()

Specs

selector() :: binary()

Link to this section Functions

Specs

all(html_tree(), selector()) :: [html_tree()]

Searches an HTML tree for the selector.

Examples

iex> Premailex.HTMLParser.all({"html", [], [{"head", [], []}, {"body", [], [{"h1", [], ["Title"]}]}]}, "h1")
[{"h1", [], ["Title"]}]

Specs

filter(html_tree(), selector()) :: [html_tree()]

Filters elements matching the selector from the HTML tree.

Examples

iex> Premailex.HTMLParser.filter([{"html", [], [{"head", [], []}, {"body", [], [{"h1", [], ["Title"]}]}]}], "h1")
[{"html", [], [{"head", [], []}, {"body", [], []}]}]

Specs

parse(binary()) :: html_tree()

Parses a HTML string into an HTML tree.

Examples

iex> Premailex.HTMLParser.parse("<html><head></head><body><h1>Title</h1></body></html>")
{"html", [], [{"head", [], []}, {"body", [], [{"h1", [], ["Title"]}]}]}

Specs

text(html_tree()) :: binary()

Extracts text elements from the HTML tree.

Examples

iex> Premailex.HTMLParser.text({"html", [], [{"head", [], []}, {"body", [], [{"h1", [], ["Title"]}]}]})
"Title"

Specs

to_string(html_tree()) :: binary()

Turns an HTML tree into a string.

Examples

iex> Premailex.HTMLParser.to_string({"html", [], [{"head", [], []}, {"body", [], [{"h1", [], ["Title"]}]}]})
"<html><head></head><body><h1>Title</h1></body></html>"

Link to this section Callbacks

Link to this callback

all(html_tree, selector)

View Source

Specs

all(html_tree(), selector()) :: [html_tree()]
Link to this callback

filter(html_tree, selector)

View Source

Specs

filter(html_tree(), selector()) :: [html_tree()]

Specs

parse(binary()) :: html_tree()

Specs

text(html_tree()) :: binary()

Specs

to_string(html_tree()) :: binary()