Parses HTML and converts it to Markdown.
use html2md_rs::to_md::safe_from_html_to_md;
let html = "<h1>Hello, World!</h1>".to_string();
let markdown = safe_from_html_to_md(html)?;
assert_eq!(markdown, "# Hello, World\\!\n");
# Ok::<(), html2md_rs::parser::ParseHTMLError>(())Output targets the CommonMark specification.
See NodeType for supported tags. Unsupported tags are retained as NodeType::Unknown(String).
This crate implements a pragmatic HTML subset, not a browser-grade HTML5 parser.
- Recognized malformed input is returned as
ParseHTMLErrorby the safe APIs instead of panicking. - HTML5 implied end-tag rules are not implemented; explicit source nesting determines the tree.
- Supported named character references are
amp,lt,gt,quot,apos, andnbsp; valid decimal and hexadecimal numeric references are also decoded. Unknown entities are preserved. Entity-derived<and&are Markdown-escaped to preserve literal text. - Markdown-significant punctuation in ordinary text is escaped. Text inside code and unknown elements is kept literal.
Licensed under the MIT License. See LICENSE.