INNER CODE UNIT · Rust
parse
aome510/spotify-player · lyric_finder/src/lib.rs:216
pub fn parse(html: &str) -> anyhow::Result<String> {
// parse HTML content into DOM node(s)
let dom = parse_document(RcDom::default(), ParseOpts::default())
.from_utf8()
.read_from(&mut (html.as_bytes()))?;
let filter = |data: &NodeData| match data {
NodeData::Element { ref attrs, .. } => attrs
.borrow()
.iter()
.any(|attr| attr.name.local.to_string() == LYRIC_CONTAINER_ATTR),
_ => false,
};
Ok(parse_dom_node(&dom.document, Some(&filter), false))
}
/// Parse a dom node and extract the text of children nodes satisfying a requirement.