html2md-rs
Parses HTML and converts it to Markdown.
Usage
use safe_from_html_to_md;
let html = "<h1>Hello, World!</h1>".to_string;
let markdown = safe_from_html_to_md?;
assert_eq!;
# Ok::
Markdown Convention
Output targets the CommonMark specification.
Supported HTML tags
See NodeType for supported tags. Unsupported tags are retained as NodeType::Unknown(String).
Scope and limitations
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.
License
Licensed under the MIT License. See LICENSE.