Skip to main content

apply

Function apply 

Source
pub fn apply<F>(root_node: &NodeRef, selectors: &[&str], func: F)
where F: Fn(&NodeRef, &str),
Expand description

Apply func(node, selector) to every descendant of root_node that matches any selector in selectors. Each selector’s matches are visited in reverse document order (safe for detach). Invalid CSS selectors are silently skipped.

§Examples

use std::cell::Cell;
use readable_rs::parser::parse_html;
use readable_rs::shared_utils::apply;

let doc = parse_html("<div><p>one</p><p>two</p></div>");
let count = Cell::new(0usize);
apply(&doc, &["p"], |_node, _sel| { count.set(count.get() + 1); });
assert_eq!(count.get(), 2);