ZealDocsets.HTML (zeal_docsets v0.1.7)

Copy Markdown View Source

Utility helpers for extracting text and attributes from Floki-parsed HTML.

Summary

Functions

Returns the value of name attribute from a single Floki node.

Returns nil for nil or empty string; passes other values through unchanged.

Extracts and normalises the text content of a list of Floki nodes.

Types

text_opts()

@type text_opts() :: [{:sep, String.t()}]

Functions

attr(node, name)

@spec attr(Floki.html_node(), String.t()) :: String.t() | nil

Returns the value of name attribute from a single Floki node.

Returns nil when the attribute is absent or its value is blank.

blank_to_nil(value)

@spec blank_to_nil(String.t() | nil) :: String.t() | nil

Returns nil for nil or empty string; passes other values through unchanged.

text(maybe_nodes, opts \\ [])

@spec text(Floki.html_tree() | nil, text_opts()) :: String.t() | nil

Extracts and normalises the text content of a list of Floki nodes.

Collapses consecutive whitespace into a single space, trims leading/trailing whitespace, and returns nil for empty or blank results.

Returns nil when nodes is nil.

Options:

  • :sep - the separator between text nodes. Defaults to a single space (" ").