presentable_soup
Types
A HTML element, queried from a HTML document.
pub type Element {
Element(
tag: String,
attributes: List(#(String, String)),
children: List(Element),
)
Text(String)
}
Constructors
-
Element( tag: String, attributes: List(#(String, String)), children: List(Element), )
A HTML element
-
Text(String)
Some text
A Matcher
describes how to match a specific element in an Element
tree.
It might be the element’s tag name, a class name, an attribute, or some
combination of these.
pub opaque type Matcher
Values
pub fn aria(name: String, value: String) -> Matcher
Match elements that have the given aria-*
attribute.
pub fn attribute(name: String, value: String) -> Matcher
Matches elements that have the specified attribute with the given value. If the value is left blank, this matcher will match any element that has the attribute, regardless of its value.
pub fn class(name: String) -> Matcher
Matches elements that include the given space-separated class name(s).
If you need to match the class attribute exactly, you can use the attribute
matcher instead.
pub fn data(name: String, value: String) -> Matcher
Matches elements that have the given data-*
attribute.
pub fn descendant(
of parent: Query,
matching matcher: List(Matcher),
) -> Query
Given a Query
that finds an element, find any of that element’s descendants
that match the given Matcher
. This will walk the entire tree
from the matching parent.
pub fn element(matching matcher: List(Matcher)) -> Query
Find any elements in a view that match the given Matcher
.
pub fn elements_to_string(html: List(Element)) -> String
Convert elements into a pretty-printed HTML string.
Examples
let elements = [
soup.Element("h1", [], soup.Text("Hello, Joe! <3"))
]
assert soup.elements_to_string(elements)
== "<h1>Hello, Joe! <3</h1>"
pub fn find(
in html: String,
matching query: Query,
) -> Result(Element, Nil)
Find the first element in a view that matches the given Query
.
pub fn find_all(
in html: String,
matching query: Query,
) -> Result(List(Element), Nil)
Find all elements in a view that matches the given Query
.
pub fn id(name: String) -> Matcher
Matches an element based on its id
attribute. Well-formed HTML means that
only one element should have a given id.
pub fn math_ml(value: String) -> Matcher
Matches MathML elements based on their tag name.
pub fn tag(value: String) -> Matcher
Matches elements based on their tag name, like "div"
, "span"
, or "a"
.