html-to-markdown
High-performance HTML โ Markdown conversion powered by Rust. Shipping as a Rust crate, Python package, PHP extension, Ruby gem, Elixir Rustler NIF, Node.js bindings, WebAssembly, and standalone CLI with identical rendering behaviour.
๐ฎ Try the Live Demo โ
Experience WebAssembly-powered HTML to Markdown conversion instantly in your browser. No installation needed!
Why html-to-markdown?
- Blazing Fast: Rust-powered core delivers 10-80ร faster conversion than pure Python alternatives
- Universal: Works everywhere - Node.js, Bun, Deno, browsers, Python, Rust, and standalone CLI
- Smart Conversion: Handles complex documents including nested tables, code blocks, task lists, and hOCR OCR output
- Metadata Extraction: Extract document metadata (title, description, headers, links, images) alongside conversion
- Highly Configurable: Control heading styles, code block fences, list formatting, whitespace handling, and HTML sanitization
- Tag Preservation: Keep specific HTML tags unconverted when markdown isn't expressive enough
- Secure by Default: Built-in HTML sanitization prevents malicious content
- Consistent Output: Identical markdown rendering across all language bindings
Documentation
Language Guides & API References:
- Python โ README with metadata extraction, inline images, hOCR workflows
- JavaScript/TypeScript โ Node.js | TypeScript | WASM
- Ruby โ README with RBS types, Steep type checking
- PHP โ Package | Extension (PIE)
- Go โ README with FFI bindings
- Java โ README with Panama FFI, Maven/Gradle setup
- C#/.NET โ README with NuGet distribution
- Elixir โ README with Rustler NIF bindings
- Rust โ README with core API, error handling, advanced features
Project Resources:
- Contributing โ CONTRIBUTING.md โญ Start here for development
- Changelog โ CHANGELOG.md โ Version history and breaking changes
Installation
| Target | Command(s) |
|---|---|
| Node.js/Bun (native) | npm install html-to-markdown-node |
| WebAssembly (universal) | npm install html-to-markdown-wasm |
| Deno | import { convert } from "npm:html-to-markdown-wasm" |
| Python (bindings + CLI) | pip install html-to-markdown |
| PHP (extension + helpers) | PHP_EXTENSION_DIR=$(php-config --extension-dir) pie install goldziher/html-to-markdowncomposer require goldziher/html-to-markdown |
| Ruby gem | bundle add html-to-markdown or gem install html-to-markdown |
| Elixir (Rustler NIF) | {:html_to_markdown, "~> 2.8"} |
| Rust crate | cargo add html-to-markdown-rs |
| Rust CLI (crates.io) | cargo install html-to-markdown-cli |
| Homebrew CLI | brew install html-to-markdown (core) |
| Releases | GitHub Releases |
Quick Start
JavaScript/TypeScript
Node.js / Bun (Native - Fastest):
import { convert } from 'html-to-markdown-node';
const html = '<h1>Hello</h1><p>Rust โค๏ธ Markdown</p>';
const markdown = convert(html, {
headingStyle: 'Atx',
codeBlockStyle: 'Backticks',
wrap: true,
preserveTags: ['table'], // NEW in v2.5: Keep complex HTML as-is
});
Deno / Browsers / Edge (Universal):
import { convert } from "npm:html-to-markdown-wasm"; // Deno
// or: import { convert } from 'html-to-markdown-wasm'; // Bundlers
const markdown = convert(html, {
headingStyle: 'atx',
listIndentWidth: 2,
});
Performance: The shared fixture harness now lives in tools/benchmark-harness and is used to track Rust + binding throughput over time.
See the JavaScript guides for full API documentation:
Metadata extraction (all languages)
import { convertWithMetadata } from 'html-to-markdown-node';
const html = `
Example
Welcome
Example link
`;
const { markdown, metadata } = await convertWithMetadata(
html,
{ headingStyle: 'Atx' },
{ extract_links: true, extract_images: true, extract_headers: true },
);
console.log(markdown);
// metadata.document.title === 'Example'
// metadata.links[0].rel === ['nofollow', 'external']
// metadata.images[0].dimensions === [640, 480]
Equivalent APIs are available in every binding:
- Python:
convert_with_metadata(html, options=None, metadata_config=None) - Ruby:
HtmlToMarkdown.convert_with_metadata(html, options = nil, metadata_config = nil) - PHP:
convert_with_metadata(string $html, ?array $options = null, ?array $metadataConfig = null)
CLI
# Convert a file
# Stream from stdin
|
# Apply options
# Fetch a remote page (HTTP) with optional custom User-Agent
Metadata Extraction
Extract document metadata alongside HTML-to-Markdown conversion. All bindings support identical APIs:
CLI Examples
# Basic metadata extraction with conversion
# Extract document metadata (title, description, language, etc.)
# Extract headers and links
# Extract all metadata types with conversion
# Fetch and extract from remote URL
# Web scraping with preprocessing and metadata
Output format (JSON):
Python Example
=
, =
TypeScript/Node.js Example
import { convertWithMetadata } from 'html-to-markdown-node';
const html = `
Article
Web Performance
Read our blog for tips.
`;
const { markdown, metadata } = await convertWithMetadata(html, {
headingStyle: 'Atx',
}, {
extract_document: true,
extract_headers: true,
extract_links: true,
extract_images: true,
});
console.log(markdown);
console.log(`Found ${metadata.headers.length} headers`);
console.log(`Found ${metadata.links.length} links`);
Ruby Example
html =
markdown, metadata = HtmlToMarkdown.convert_with_metadata(
html,
options: { heading_style: :atx },
metadata_config: {
extract_document: true,
extract_headers: true,
extract_links: true,
extract_images: true,
}
)
puts markdown
puts
puts
PHP Example
Go Example
package main
import (
"encoding/json"
"fmt"
"log"
"github.com/Goldziher/html-to-markdown/packages/go/v2/htmltomarkdown"
)
func main()
Java Example
;
;
;
;
C# Example
using HtmlToMarkdown;
using System.Text.Json;
var html = @"
C# Guide
Introduction
See our repository.
";
try
{
var result = HtmlToMarkdownConverter.ConvertWithMetadata(
html,
new MetadataConfig
{
ExtractDocument = true,
ExtractHeaders = true,
ExtractLinks = true,
ExtractImages = true,
}
);
Console.WriteLine("Markdown:");
Console.WriteLine(result.Markdown);
Console.WriteLine($"Title: {result.Metadata.Document.Title}");
Console.WriteLine($"Links found: {result.Metadata.Links.Count}");
// Serialize metadata to JSON
var options = new JsonSerializerOptions { WriteIndented = true };
var json = JsonSerializer.Serialize(result.Metadata, options);
Console.WriteLine(json);
}
catch (HtmlToMarkdownException ex)
{
Console.Error.WriteLine($"Conversion failed: {ex.Message}");
}
See the individual binding READMEs for detailed metadata extraction options:
- Python โ Python README
- TypeScript/Node.js โ Node.js README | TypeScript README
- Ruby โ Ruby README
- PHP โ PHP README
- Go โ Go README
- Java โ Java README
- C#/.NET โ C# README
- WebAssembly โ WASM README
- Rust โ Rust README
Python (v2 API)
=
=
, , =
Elixir
{:ok, markdown} = HtmlToMarkdown.convert("<h1>Hello</h1>")
# Keyword options are supported (internally mapped to the Rust ConversionOptions struct)
HtmlToMarkdown.convert!("<p>Wrap me</p>", wrap: true, wrap_width: 32, preprocessing: %{enabled: true})
Rust
use ;
let html = "<h1>Welcome</h1><p>Fast conversion</p>";
let markdown = convert?;
let options = ConversionOptions ;
let markdown = convert?;
See the language-specific READMEs for complete configuration, hOCR workflows, and inline image extraction.
Performance
Benchmarked on Apple M4 using the shared fixture harness in tools/benchmark-harness (latest consolidated run: 20409971461).
Comparative Throughput (Median Across Fixtures)
| Runtime | Median ops/sec | Median throughput (MB/s) | Peak memory (MB) | Successes |
|---|---|---|---|---|
| Rust | 1,060.3 | 116.4 | 171.3 | 56/56 |
| Go | 1,496.3 | 131.1 | 22.9 | 16/16 |
| Ruby | 2,155.5 | 300.4 | 280.3 | 48/48 |
| PHP | 2,357.7 | 308.0 | 223.5 | 48/48 |
| Elixir | 1,564.1 | 269.1 | 384.7 | 48/48 |
| C# | 1,234.2 | 272.4 | 187.8 | 16/16 |
| Java | 1,298.7 | 167.1 | 527.2 | 16/16 |
| WASM | 1,485.8 | 157.6 | 95.3 | 48/48 |
| Node.js (NAPI) | 2,054.2 | 306.5 | 95.4 | 48/48 |
| Python (PyO3) | 3,120.3 | 307.5 | 83.5 | 48/48 |
Use task bench:harness to regenerate throughput numbers across the bindings, task bench:harness:memory for CPU/memory samples, and task bench:harness:rust for flamegraphs.
Compatibility (v1 โ v2)
Testing
Use the task runner to execute the entire matrix locally:
# All core test suites (Rust, Python, Ruby, Node, PHP, Go, C#, Elixir, Java)
# Run the Wasmtime-backed WASM integration tests
The Wasmtime suite builds the html-to-markdown-wasm artifact with the same flags used in CI and drives it through Wasmtime to ensure the non-JS runtime behaves exactly like the browser/Deno builds.
- V2โs Rust core sustains 150โ210โฏMB/s throughput; V1 averaged โโฏ2.5โฏMB/s in its Python/BeautifulSoup implementation (60โ80ร faster).
- The Python package offers a compatibility shim in
html_to_markdown.v1_compat(convert_to_markdown,convert_to_markdown_stream,markdownify). The shim is deprecated, emitsDeprecationWarningon every call, and will be removed in v3.0โplan migrations now. Details and keyword mappings live in Python README. - CLI flag changes, option renames, and other breaking updates are summarised in CHANGELOG.
Community
- Chat with us on Discord
- Explore the broader Kreuzberg document-processing ecosystem
- Sponsor development via GitHub Sponsors
Ruby
html =
markdown = HtmlToMarkdown.convert(html, heading_style: :atx, wrap: true)
puts markdown
# # Hello
#
# Rust โค๏ธ Markdown
See the language-specific READMEs for complete configuration, hOCR workflows, and inline image extraction.