View Source Unfurl.Parser behaviour (Unfurl v0.6.0)

Summary

Callbacks

Parses the given HTML, returning a map structure of structured data keys mapping to their respective values, or an error.

Functions

Extracts the given tags from the given raw html according to the given match function

Extracts a canonical url from the given raw HTML

Groups colon-separated keys into dynamic map structures

Callbacks

@callback parse(html :: String.t()) :: {:ok, Map.t()} | {:error, Atom.t()}

Parses the given HTML, returning a map structure of structured data keys mapping to their respective values, or an error.

Functions

Link to this function

extract(tag, html, match, extract_attr \\ "content")

View Source

Extracts the given tags from the given raw html according to the given match function

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

Extracts a canonical url from the given raw HTML

@spec maybe_group_keys(Map.t()) :: Map.t()

Groups colon-separated keys into dynamic map structures

Examples

iex> Application.put_env(:unfurl, :group_keys?, false)
iex> Unfurl.Parser.maybe_group_keys %{"twitter:app:id" => 123, "twitter:app:name" => "YouTube"}
%{"twitter:app:id" => 123, "twitter:app:name" => "YouTube"}

iex> Application.put_env(:unfurl, :group_keys?, true)
iex> Unfurl.Parser.maybe_group_keys %{"twitter:app:id" => 123, "twitter:app:name" => "YouTube"}
%{
  "twitter" => %{
    "app" => %{
      "id" => 123,
      "name" => "YouTube"
    }
  }
}