use scraper::Html;
#[must_use]
pub fn select(html: &str, selector: &str) -> String {
select_doc(&Html::parse_document(html), html, selector)
}
pub(crate) fn select_doc(doc: &Html, original: &str, selector: &str) -> String {
collect_inner_html(doc, selector).unwrap_or_else(|| original.to_owned())
}
pub(super) fn collect_inner_html(doc: &Html, selector: &str) -> Option<String> {
let sel = scraper::Selector::parse(selector).ok()?;
let mut buf = String::new();
for el in doc.select(&sel) {
buf.push_str(&el.inner_html());
}
if buf.trim().is_empty() {
None
} else {
Some(buf)
}
}