1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use std::collections::HashMap;

#[derive(Debug, PartialEq, Eq, Clone)]
pub enum NodeType {
    H1,
    H2,
    H3,
    H4,
    H5,
    H6,
    P,
    Div,
    Strong,
    Em,
    A,
    Ul,
    Ol,
    Li,
    Text,
}

impl NodeType {
    pub fn from_str(input: &str) -> NodeType {
        match input {
            "h1" => NodeType::H1,
            "h2" => NodeType::H2,
            "h3" => NodeType::H3,
            "h4" => NodeType::H4,
            "h5" => NodeType::H5,
            "h6" => NodeType::H6,
            "p" => NodeType::P,
            "div" => NodeType::Div,
            "strong" => NodeType::Strong,
            "em" => NodeType::Em,
            "a" => NodeType::A,
            "ul" => NodeType::Ul,
            "ol" => NodeType::Ol,
            "li" => NodeType::Li,
            _ => NodeType::Text,
        }
    }
}

#[derive(Debug, PartialEq, Eq, Clone)]
pub struct Node {
    pub tag_name: Option<NodeType>,
    pub value: Option<String>,
    pub attributes: Option<HashMap<String, String>>,
    pub children: Vec<Node>,
}