html-to-markdown-rs
High-performance HTML to Markdown converter built with Rust.
This crate is the core engine compiled into the Python wheels, Ruby gem, Node.js NAPI bindings, WebAssembly package, and CLI, ensuring identical Markdown output across every language.
Fast, reliable HTML to Markdown conversion with full CommonMark compliance. Built with html5ever for correctness and ammonia for safe HTML preprocessing.
Installation
[]
= "2.3"
Basic Usage
use ;
Configuration
use ;
let options = ConversionOptions ;
let markdown = convert?;
Preserving HTML Tags
The preserve_tags option allows you to keep specific HTML tags in their original form instead of converting them to Markdown. This is useful for complex elements like tables that may not convert well:
use ;
let html = r#"
<p>Before table</p>
<table class="data">
<tr><th>Name</th><th>Value</th></tr>
<tr><td>Item 1</td><td>100</td></tr>
</table>
<p>After table</p>
"#;
let options = ConversionOptions ;
let markdown = convert?;
// Result: "Before table\n\n<table class=\"data\">...</table>\n\nAfter table\n"
You can preserve multiple tag types and combine with strip_tags:
let options = ConversionOptions ;
Web Scraping with Preprocessing
use ;
let mut options = default;
options.preprocessing.enabled = true;
options.preprocessing.preset = Aggressive;
options.preprocessing.remove_navigation = true;
options.preprocessing.remove_forms = true;
let markdown = convert?;
hOCR Table Extraction
use convert;
// hOCR documents (from Tesseract, etc.) are detected automatically.
// Tables and spatial layout are reconstructed without additional options.
let markdown = convert?;
Inline Image Extraction
use ;
let config = new // 5MB max
.with_infer_dimensions
.with_filename_prefix;
let extraction = convert_with_inline_images?;
println!;
for in extraction.inline_images.iter.enumerate
Other Language Bindings
This is the core Rust library. For other languages:
- JavaScript/TypeScript: @html-to-markdown/node (NAPI-RS) or @html-to-markdown/wasm (WebAssembly)
- Python: html-to-markdown (PyO3)
- Ruby: html-to-markdown (Magnus + rb-sys)
- CLI: html-to-markdown-cli
Documentation
Performance
10-30x faster than pure Python/JavaScript implementations, delivering 150-210 MB/s throughput.
License
MIT