Skip to main content

Crate html2md_rs

Crate html2md_rs 

Source
Expand description

§html2md-rs

Parses HTML and converts it to Markdown.

§Usage

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");

§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 ParseHTMLError by 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, and nbsp; 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.

Modules§

parser
Parses a pragmatic HTML subset into a custom Node tree; this is not an HTML5 parser.
structs
HTML tree and Markdown rendering configuration types.
to_md
Functions for rendering parsed HTML nodes as Markdown.