Exquery

A simple Elixir DOM library for building a tree from an HTML string and then selecting elements that lurk within.

Build Status

full documentation at hex.pm

Example

select by elements with `css/2`

"""
<div class="red-fish">
  <ul class="blue-fish">
    <li class="one-fish">Hello</li>
    <li class="two-fish">World</li>
  </ul>
</div>
"""
|> Exquery.tree
|> Exquery.Query.css(".two-fish")

Evaluates to:

[{{:tag, "li", [{"class", "two-fish"}]}, [{:text, "World", []}]}]

select an element with `one/2`

Selecting an li :tag with specific attrs using one/2

"""
<div class="red-fish">
  <ul class="blue-fish">
    <li class="one-fish">Hello</li>
    <li class="two-fish">World</li>
  </ul>
</div>
"""
|> Exquery.tree
|> Exquery.Query.one({:tag, "li", [{"class", "one-fish"}]})

This evaluates to:

{{:tag, "li", [{"class", "one-fish"}]}, [{:text, "Hello", []}]}

select all elements with `all/2`

Similarly, you can select all elements using all/2

"""
<div class="red-fish">
  <ul class="blue-fish">
    <li class="one-fish">Hello</li>
    <li class="two-fish">World</li>
  </ul>
</div>
"""
|> Exquery.tree
|> Exquery.Query.all({:tag, "li", []})

This evaluates to:

[{{:tag, "li", [{"class", "one-fish"}]}, [{:text, "Hello", []}]},
 {{:tag, "li", [{"class", "two-fish"}]}, [{:text, "World", []}]}]

select siblings with `before/3` and `next/3`

You can select a sibling using before/3 andnext/3`

"""
<div class="red-fish">
  <ul class="blue-fish">
    <li class="one-fish">Hello</li>
    <li class="two-fish">World</li>
  </ul>
</div>
"""
|> Exquery.tree
|> Exquery.Query.next({:tag, "li", []})

This evaluates to:

{{:tag, "li", [{"class", "two-fish"}]}, [{:text, "World", []}]}

or

"""
<div class="red-fish">
  <ul class="blue-fish">
    <li class="one-fish">Hello</li>
    <li class="two-fish">World</li>
  </ul>
</div>
"""
|> Exquery.tree
|> Exquery.Query.before({:tag, "li", [{"class", "two-fish"}]})

This evaluates to:

{{:tag, "li", [{"class", "one-fish"}]}, [{:text, "Hello", []}]}

Todo: