parse_html/
node.rs

1use crate::dom::search::search_node_attr;
2
3#[derive(Debug, PartialEq)]
4pub enum Node {
5    Element(ElementNode),
6    Text(String),
7}
8
9#[derive(Debug, PartialEq)]
10pub struct ElementNode {
11    pub tag_name: String,
12    pub attributes: Vec<(String, String)>,
13    pub children: Vec<Node>,
14}
15
16impl ElementNode {
17    pub fn get_by_id(&self, id_value: &str) -> Option<&ElementNode> {
18        for node in &self.children {
19            if let Some(found) = search_node_attr(node, "id", id_value) {
20                return Some(found);
21            }
22        }
23        None
24    }
25
26    pub fn get_by_class(&self, value: &str) -> Option<&ElementNode> {
27        for node in &self.children {
28            if let Some(found) = search_node_attr(node, "class", value) {
29                return Some(found);
30            }
31        }
32        None
33    }
34}