pub fn safe_parse_html(input: String) -> Result<Node, ParseHTMLError>
Expand description
Safely parses a string of HTML into a Node struct
§Arguments
input
- A string slice that holds the HTML to be parsed
§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 {
tag_name: Some(Div),
value: None,
within_special_tag: None,
attributes: None,
children: vec![Node {
tag_name: Some(Text),
value: Some("hello".to_string()),
attributes: None,
within_special_tag: None,
children: Vec::new(),
}],
};
assert_eq!(parsed, Ok(expected));