This commit is contained in:
Robin Appelman 2024-11-08 23:09:09 +01:00
commit 5e034d7bef
2 changed files with 6 additions and 17 deletions

View file

@ -33,23 +33,12 @@ pub trait Parser {
trait ElementExt<'a> {
fn first_text(&self) -> Option<&'a str>;
fn nth_text(&self, n: usize) -> Option<&'a str>;
fn last_text(&self) -> Option<&'a str>;
}
impl<'a> ElementExt<'a> for ElementRef<'a> {
fn first_text(&self) -> Option<&'a str> {
self.text().map(str::trim).find(|s| !s.is_empty())
}
fn nth_text(&self, n: usize) -> Option<&'a str> {
self.text()
.filter(|s| !s.trim().is_empty())
.nth(n - 1)
.map(str::trim)
}
fn last_text(&self) -> Option<&'a str> {
self.text().map(str::trim).filter(|s| !s.is_empty()).last()
}
}
fn select_text<'a>(el: ElementRef<'a>, selector: &Selector) -> Option<&'a str> {