Function parsercher::parse[][src]

pub fn parse(doc: &str) -> Result<Dom, String>
Expand description

Parses the tag document and returns a Dom structure tree.

Arguments

  • doc - tag document

Errors

  • If the document ends in the middle of a tag or double quote.

Examples

let html = r#"
<body>
  <h1 class="h1">Hello</h1>
</body>
}"#;

if let Ok(dom) = parsercher::parse(&html) {
    println!("{:#?}", dom);
}

output:

Dom {
    dom_type: Tag,
    tag: Some(
        Tag {
            name: "root",
            attr: None,
            terminated: false,
            terminator: false,
        },
    ),
    text: None,
    comment: None,
    children: Some(
        [
            Dom {
                dom_type: Tag,
                tag: Some(
                    Tag {
                        name: "body",
                        attr: None,
                        terminated: false,
                        terminator: false,
                    },
                ),
                text: None,
                comment: None,
                children: Some(
                    [
                        Dom {
                            dom_type: Tag,
                            tag: Some(
                                Tag {
                                    name: "h1",
                                    attr: Some(
                                        {
                                            "class": "h1",
                                        },
                                    ),
                                    terminated: false,
                                    terminator: false,
                                },
                            ),
                            text: None,
                            comment: None,
                            children: Some(
                                [
                                    Dom {
                                        dom_type: Text,
                                        tag: None,
                                        text: Some(
                                            Text {
                                                text: "Hello",
                                            },
                                        ),
                                        comment: None,
                                        children: None,
                                    },
                                ],
                            ),
                        },
                    ],
                ),
            },
        ],
    ),
}