ModestEx v0.0.2-dev ModestEx

This module exposes features to do pipeable transformations on html strings with CSS selectors, e.g. find(), prepend(), append(), replace() etc.

Credits:

The package implements bindings to Alexander Borisov’s Modest. The binding is implemented as a C-Node based on the excellent example of Lukas Rieder’s cnodex and myhtmlex.

Example

iex> ModestEx.find(“

Hello World

”, “p a”) [“Hello”]

Link to this section Summary

Functions

Find nodes with a CSS selector. Returns the outer html of each node as a list of strings

Get all attributes with key for each html string in list. Returns list of strings

Get all attributes with key for each html string in list. Returns list of strings

Serialize any string with valid or broken html. Returns valid html string

Set coresponding value for all attributes with key for each html string in list. Returns list of html strings

Set coresponding value for all selected attributes with key for each html string in list. Returns list of html strings

Link to this section Types

Link to this type error()
error() :: {:error, String.t()}
Link to this type success()
success() :: String.t() | [String.t()]

Link to this section Functions

Link to this function find(bin, selector)
find(String.t(), String.t()) :: success() | error()

Find nodes with a CSS selector. Returns the outer html of each node as a list of strings.

Examples

iex> ModestEx.find(“

Hello World

”, “p a”) [“Hello”]

iex> ModestEx.find(“

Hello World

”, “span”) [“Hello”, “World”]

Link to this function get_attribute(bin, key)
get_attribute(String.t(), String.t()) :: success() | error()
get_attribute([String.t()], String.t()) :: success() | error()

Get all attributes with key for each html string in list. Returns list of strings.

Examples

iex> ModestEx.get_attribute([“Hello”, “World”], “href”) [“https://elixir-lang.org”, “https://google.de”]

Link to this function get_attribute(bin, selector, key)
get_attribute(String.t(), String.t(), String.t()) :: success() | error()
get_attribute([String.t()], String.t(), String.t()) :: success() | error()

Get all attributes with key for each html string in list. Returns list of strings.

Examples

iex> ModestEx.get_attribute([“Hello”, “World”], “href”) [“https://elixir-lang.org”, “https://google.de”]

Link to this function serialize(bin)
serialize(String.t()) :: success() | error()

Serialize any string with valid or broken html. Returns valid html string.

Examples

iex> ModestEx.serialize(“

HelloWorld”) “
HelloWorld

Link to this function set_attribute(bin, key, value)
set_attribute(String.t(), String.t(), String.t()) :: success() | error()
set_attribute([String.t()], String.t(), String.t()) :: success() | error()
set_attribute([String.t()], String.t(), [String.t()]) :: success() | error()
set_attribute([String.t()], String.t(), [String.t()]) :: success() | error()

Set coresponding value for all attributes with key for each html string in list. Returns list of html strings.

Examples

iex> ModestEx.set_attribute([“Hello”, “World”], “href”, [“https://elixir-lang.org”, “https://google.de”]) [“Hello”, “World”]

Link to this function set_attribute(bin, selector, key, value)
set_attribute(String.t(), String.t(), String.t(), String.t()) ::
  success() | error()
set_attribute([String.t()], String.t(), String.t(), String.t()) ::
  success() | error()

Set coresponding value for all selected attributes with key for each html string in list. Returns list of html strings.

Examples

iex> ModestEx.set_attribute([“

Hello

”, “

World

”], “p a”, “href”, [“https://elixir-lang.org”, “https://google.de”]) [“

Hello

”, “

World

”]