= if let Some(path) = opt.output {
let file = File::create(&path)?;
Box::new(file)
} else {
Box::new(stdout())
};
let css_selector = opt.selector;
let document = kuchiki::parse_html().one(html);
for css_match in document.select(&css_selector).unwrap() {
// css_match is a NodeDataRef, but most of the interesting methods are
// on NodeRef. Let's get the underlying NodeRef.
let as_node = css_match.as_node();
// In this example, as_node represents an HTML node like
//
// Hello world!
"
//
// Which is distinct from just 'Hello world!'. To get rid of that
// tag, we're going to get each element's first child, which will be
// a "text" node.
//
// There are other kinds of nodes, of course. The possibilities are all
// listed in the `NodeData` enum in this crate.
//let text_node = as_node.first_child().unwrap();
// Let's get the actual text in this text node. A text node wraps around
// a RefCell, so we need to call borrow() to get a &str out.
//let text = text_node.as_text().unwrap().borrow();
out.write_all(serialize_node(as_node)?.as_bytes())?;
/*if let Some(child) = as_node.first_child() {
//TODO: Convert Nodes to String, as this only works for Nodes containing plain text
if let Some(text) = child.as_text() {
// Prints:
//
// "Hello, world!"
// "I love HTML"
println!("{:?}", text.borrow());
}
}*/
}
Ok(())
}