ModestEx v0.0.10-dev ModestEx

Serialization scope. Possible values are: :html html will be serialized to complete document …

:head html will be reduced only to the head fragment …

:body html will be reduced only to the body fragment …

:body_children html will be reduced to the children of the body

Link to this section Summary

Functions

Append new html as a child at the end of selected node. Returns updated html string

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

Get all attributes with key. Returns list of strings

Get all text. Returns list of strings

Insert new html after selected node. Returns updated html string

Insert new html before selected node. Returns updated html string

Get position of selected nodes in in relation to its parent. Returns list of positions

Prepend new html as a child at the beginning of selected node. Returns updated html string

Remove nodes with a CSS selector. Returns updated html string

Replace selected node with new html Returns updated html string

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

Set value for all attributes with key. Returns single html string or returns list of strings

Set text for all nodes. Returns single html string or returns list of strings

Slice selected set into subset. Returns single html string or returns list of strings

Link to this section Types

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

Link to this section Functions

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

Append new html as a child at the end of selected node. Returns updated html string

Examples

iex> ModestEx.append(“

Hello

”, “div”, “

World

”) “

Hello

World

Link to this function find(bin, selector)
find(input(), 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(input(), String.t()) :: success() | error()

Get all attributes with key. Returns list of strings.

Examples

iex> ModestEx.get_attribute(“Hello”, “href”) “https://elixir-lang.org”

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

Get all text. Returns list of strings.

Examples

iex> ModestEx.get_text(“

Hello World
”) “Hello World”

Link to this function get_text(bin, selector)
get_text(input(), String.t()) :: success() | error()
Link to this function insert_after(bin, selector, new_bin)
insert_after(input(), String.t(), String.t()) :: success() | error()

Insert new html after selected node. Returns updated html string

Examples

iex> ModestEx.insert_after(“

Hello

”, “div p”, “

World

”) “

Hello

World

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

Insert new html before selected node. Returns updated html string

Examples

iex> ModestEx.insert_before(“

World

”, “div p”, “

Hello

”) “

Hello

World

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

Get position of selected nodes in in relation to its parent. Returns list of positions.

Examples

iex> ModestEx.position(“

Hello

World

”, “p”) [1, 3]

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

Prepend new html as a child at the beginning of selected node. Returns updated html string

Examples

iex> ModestEx.prepend(“

World

”, “div”, “

Hello

”) “

Hello

World

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

Remove nodes with a CSS selector. Returns updated html string

Examples

iex> ModestEx.remove(“

Hello

World
”, “div p”) “
World

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

Replace selected node with new html Returns updated html string

Examples

iex> ModestEx.replace(“

Hello

”, “div p”, “

World

”) “

World

Link to this function serialize(bin, scope \\ :html)
serialize(input(), Atom.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, selector, key, value)
set_attribute(input(), String.t(), String.t(), input()) :: success() | error()

Set value for all attributes with key. Returns single html string or returns list of strings.

Examples

iex> ModestEx.set_attribute(“Hello”, “a”, “href”, “https://elixir-lang.org”) “Hello

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

Set text for all nodes. Returns single html string or returns list of strings.

Examples

iex> ModestEx.set_text(“

”, “div p”, “Hello World”) “

Hello World

Link to this function slice(bin, selector, start_index, end_index)
slice(input(), String.t(), Integer.t(), Integer.t()) :: success() | error()

Slice selected set into subset. Returns single html string or returns list of strings.

Examples

iex> ModestEx.slice(“

Lorem ipsum

dolor sit amet

  • Coffee
  • Tea
  • Milk

Sed ut perspiciatis

unde omnis iste natus

”, “> *”, 0, -1) [“

Lorem ipsum

”, “

dolor sit amet

”, “
  • Coffee
  • Tea
  • Milk
”, “

Sed ut perspiciatis

”, “

unde omnis iste natus

”]