Don't Draw Hidden Sections (#24)

* added a simple snippet for hiding sections that are marked as display none

* updated the displaynone to work with the new implementation
master
Malcolm Diller 3 years ago committed by GitHub
parent aaa5c2e3fc
commit 21358c663a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -4,15 +4,19 @@ pub trait XmlVisitor {
fn visit(&mut self, node: Node); fn visit(&mut self, node: Node);
} }
pub fn is_valid_node(node: &Node) -> bool {
return node.is_element() && !node.attribute("style").unwrap_or_default().contains("display:none");
}
pub fn depth_first_visit(doc: &Document, visitor: &mut impl XmlVisitor) { pub fn depth_first_visit(doc: &Document, visitor: &mut impl XmlVisitor) {
let mut stack = doc let mut stack = doc
.root() .root()
.children() .children()
.rev() .rev()
.filter(|x| x.is_element()) .filter(|x| is_valid_node(x))
.collect::<Vec<_>>(); .collect::<Vec<_>>();
while let Some(node) = stack.pop() { while let Some(node) = stack.pop() {
visitor.visit(node); visitor.visit(node);
stack.extend(node.children().rev().filter(|x| x.is_element())); stack.extend(node.children().rev().filter(|x| is_valid_node(x)));
} }
} }

Loading…
Cancel
Save