Skip to content

Commit

Permalink
add a method to tell between node types
Browse files Browse the repository at this point in the history
  • Loading branch information
shouya committed Feb 7, 2024
1 parent d471546 commit cbb2979
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/js/dom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,16 @@ impl<'js> Node<'js> {
Ok(parent)
}

fn node_type(&self) -> String {
let dom = self.dom.borrow();
let node = self.node_ref(&dom).unwrap();
let val = node.value();
match val {
scraper::Node::Text(_) => "text".to_string(),
scraper::Node::Element(_) => "element".to_string(),
_ => "other".to_string(),
}
}

fn remove(&self) {
self.node_mut(&mut self.dom.borrow_mut()).unwrap().detach();
Expand Down

0 comments on commit cbb2979

Please sign in to comment.