aboutsummaryrefslogtreecommitdiffstats
path: root/src/dsb/html.rs
blob: 51e85802861b8df4e398c1b7118f39e8fd41a4ad (plain)
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
51
52
53
54
55
56
use crate::types::*;
use crate::Error;
use super::DSB;

//use html5ever::rcdom::{Handle, Node, NodeData};
use markup5ever_rcdom::{Handle, Node, NodeData};
use html5ever::tendril::Tendril;

pub(crate) fn parse(handle: &Handle) -> Result<Vec<DSB>, Error> {
    let mut dsb_ret = Vec::new();
    let node: &Node = handle;
    let nodeVec = node.children.borrow();
    let node: &Node = &nodeVec[0];

    for v in node.children.borrow().iter() {
        let v: &Node = v;
        if let NodeData::Element { ref name, .. } = v.data {
            let name: &html5ever::QualName = name;
            if name.local.to_string() == "body" {
                let mut found_head = false;
                for w in v.children.borrow().iter() {
                    if let NodeData::Element { ref name, ref attrs, .. } = w.data {
                        let name: &html5ever::QualName = name;
                        let attrs = &attrs.borrow();
                        println!("name: {}", name.local.to_string());
                        if name.local.to_string() == "table" {
                            for attrs in attrs.iter() {
                                if attrs.name.local.to_string() == "class" && attrs.value.to_string() == "mon_head" {
                                    dsb_ret.push(new_mon_head(w)?);
                                    found_head = true;
                                }
                            }
                        } else if name.local.to_string() == "center" && found_head {
                            if let Some(mut dsb) = dsb_ret.last_mut() {
                                parse_center(w, &mut dsb)?;
                            } else {
                                panic!("should get mutable");
                            }
                        }
                    }
                }
            }
        }
    }

    Ok(dsb_ret)
}

fn new_mon_head(handle: &Handle) -> Result<DSB, Error> {

    todo!()
}

fn parse_center(handle: &Handle, dsb: &mut DSB) -> Result<(), Error> {
    todo!()
}