in rust/src/main.rs [209:234]
fn remove_empty_nodes(node: NodeRef) -> bool {
// Post order traversal
for child in node.children() {
remove_empty_nodes(child.clone());
}
// Remove nodes without children that are not part of the item* family
if let kuchiki::NodeData::Element(x) = node.data() {
let local_attrs = x.clone().attributes.into_inner();
if &node.children().count() == &0
// If no content inside, it needs a content attribute with data or be a <br> tag
&& !(local_attrs.contains("itemprop") && local_attrs.contains("content"))
&& !(local_attrs.contains("itemtype") && local_attrs.contains("content"))
&& !(x.name.local == "br".to_string())
{
node.detach();
return false;
}
} else if let kuchiki::NodeData::Text(x) = node.data() {
let text: String = x.borrow().to_string();
if &text.len() < &1 || &text == &"~" || &text == &" " {
node.detach();
return false;
}
}
return true;
}