Skip to main content

safe_parse_html

Function safe_parse_html 

Source
pub fn safe_parse_html(input: String) -> Result<Node, ParseHTMLError>
Expand description

Consumes an owned HTML string and returns a Node tree.

§Arguments

  • input - HTML source to parse.

§Errors

Returns ParseHTMLError for malformed tags or attributes recognized by this parser. See the module documentation for accepted subset and root-shape rules.

§Examples

use html2md_rs::{
    parser::safe_parse_html,
    structs::{
        Node,
        NodeType::{Div, Text},
    },
};

let input = "<div>hello</div>".to_string();
let parsed = safe_parse_html(input);
let expected = Node::new(
    Some(Div),
    None,
    None,
    None,
    vec![Node::new(
        Some(Text),
        Some("hello".to_string()),
        None,
        None,
        Vec::new(),
    )],
);

assert_eq!(parsed, Ok(expected));