mellie
Values
pub fn attr(
el: element.ElementTree,
key: String,
) -> Result(String, Nil)
pub fn attrs(
tree: element.ElementTree,
) -> List(#(String, String))
Gets attributes of the given element. TextNodes will return []
pub fn children(
tree: element.ElementTree,
) -> List(element.ElementTree)
Gets the children of an element. TextNodes will return []
pub fn data_attr(
el: element.ElementTree,
data_key: String,
) -> Result(String, Nil)
pub fn element(
tag: String,
attributes: List(#(String, String)),
children: List(element.ElementTree),
) -> element.ElementTree
pub fn element_to_string(el: element.ElementTree) -> String
pub fn element_to_string_pretty(
el: element.ElementTree,
) -> String
This is useful for tests but is not context dependant and may be incorrect in cases where internal HTML depends on formatting (e.g. pre > span). Uses presentable_soup under the hood
pub fn element_to_xml_document_string(
el: element.ElementTree,
) -> String
pub fn element_to_xml_string(el: element.ElementTree) -> String
pub fn elements_to_string(
el: List(element.ElementTree),
) -> String
pub fn elements_to_string_pretty(
el: List(element.ElementTree),
) -> String
This is useful for tests but is not context dependant and may be incorrect in cases where internal HTML depends on formatting (e.g. pre > span). Uses presentable_soup under the hood
pub fn find_all(
from in: a,
with fun: fn(a) -> List(a),
) -> List(a)
Runs the given function recursively over the result until it no longer results in items. Returns the found nodes from every level
pub fn find_leaf(
from in: a,
with fun: fn(a) -> List(a),
) -> List(a)
Runs the given function recursively over the result until it no longer returns items. Returns only the deepest matching nodes
pub fn get_child_by_tag(
tree: element.ElementTree,
tag: String,
) -> Result(element.ElementTree, Nil)
pub fn get_children_by_tag(
tree: element.ElementTree,
tag: String,
) -> List(element.ElementTree)
Gets children with the given tag up to one level of results. Use with find_all to recurse further into returned elements
pub fn has_tag(tree: element.ElementTree, tag: String) -> Bool
pub fn inner_text(el: element.ElementTree) -> String
Recursively get all text from given element
pub fn parse(
html str: String,
) -> Result(element.ElementTree, String)
Parses the given HTML into a full document (containing html, head, and body tags)
If the given HTML does not contain an html or head, they will be automatically added
and the given content will be put into the body
pub fn remove_attribute(
el: element.ElementTree,
attr: String,
) -> element.ElementTree
Removes attribute on an ElementNode, does not modify a TextNode
pub fn remove_attributes(
el: element.ElementTree,
attrs: List(String),
) -> element.ElementTree
Removes attributes on an ElementNode, does not modify a TextNode
pub fn set_attribute(
el: element.ElementTree,
attr: #(String, String),
) -> element.ElementTree
Sets attributes on an ElementNode, does not modify a TextNode
pub fn set_attributes(
el: element.ElementTree,
attr: List(#(String, String)),
) -> element.ElementTree
Sets attributes on an ElementNode, does not modify a TextNode
pub fn tag(tree: element.ElementTree) -> option.Option(String)
Gets tag of the given element. TextNodes will return None
pub fn text(text: String) -> element.ElementTree
pub fn to_document_string(el: element.ElementTree) -> String
pub fn transform_tree(
tree: element.ElementTree,
elem: fn(String, List(#(String, String)), List(a)) -> a,
text: fn(String) -> a,
) -> a
Transforms a tree recursively using the given element and text conversion functions
pub fn update_where(
from in: element.ElementTree,
where should_visit: fn(element.ElementTree) -> Bool,
with update: fn(element.ElementTree) -> element.ElementTree,
) -> element.ElementTree
pub fn update_where_tag(
from in: element.ElementTree,
tag tag: String,
with update: fn(element.ElementTree) -> element.ElementTree,
) -> element.ElementTree