View Source Microformats2 (microformats2 v1.0.1)
A microformats2 parser for Elixir.
Summary
Functions
Parse a document either by URL or by content. Returns a microformats2 parsing structure or :error
.
Functions
Parse a document either by URL or by content. Returns a microformats2 parsing structure or :error
.
Parameters
content_or_url
is either the HTML document or a URLbase_url_or_opts
is either the base URL of the document (if the first argument is a HTML string) or a keyword list of optionsopts
is an option list when the first argument is an HTML string
Options
Valid options are:
:atomize_keys
:true
orfalse
, defaults tofalse
. Convert keys to atoms when true, e.g."rels"
to:rels
:underscore_keys
:true
orfalse
,false
by default. Convert dashed keys to underscored keys when true, e.g."rel-urls"
to"rel_urls"
or:"rel-urls"
to:rel_urls
Examples
iex> Microformats2.parse("http://example.org/")
%{"rels" => [], "rel-urls" => [], "items" => []}
iex> Microformats2.parse("http://example.org/", atomize_keys: true, underscore_keys: true)
%{rels: [], rel_urls: [], items: []}
iex> Microformats2.parse("""
<div class="h-card">
<img class="u-photo" alt="photo of Mitchell"
src="https://webfwd.org/content/about-experts/300.mitchellbaker/mentor_mbaker.jpg"/>
<a class="p-name u-url" href="http://blog.lizardwrangler.com/">Mitchell Baker</a>
(<a class="u-url" href="https://twitter.com/MitchellBaker">@MitchellBaker</a>)
<span class="p-org">Mozilla Foundation</span>
<p class="p-note">
Mitchell is responsible for setting the direction and scope of the Mozilla Foundation and its activities.
</p>
<span class="p-category">Strategy</span>
<span class="p-category">Leadership</span>
</div>
""", "http://example.org")
%{
"items" => [
%{
"properties" => %{
"category" => ["Strategy", "Leadership"],
"name" => ["Mitchell Baker"],
"note" => ["Mitchell is responsible for setting the direction and scope of the Mozilla Foundation and its activities."],
"org" => ["Mozilla Foundation"],
"photo" => [
%{
"alt" => "photo of Mitchell",
"value" => "https://webfwd.org/content/about-experts/300.mitchellbaker/mentor_mbaker.jpg"
}
],
"url" => ["http://blog.lizardwrangler.com/",
"https://twitter.com/MitchellBaker"]
},
"type" => ["h-card"]
}
],
"rel-urls" => %{},
"rels" => %{}
}