Skip to content

html-to-markdown

Convert HTML to Markdown, Djot, or plain text. One Rust core plus 15 generated packages, identical output on every runtime. Part of the xberg.io document intelligence ecosystem.


Why html-to-markdown

  • Rust core

Single-pass DOM walk written in Rust. The same code path runs from Python, the browser, and the CLI — no per-language conversion logic.

  • 16 language surfaces

Rust plus generated packages for Python, TypeScript, Go, Ruby, PHP, Java, C#, Elixir, R, C, WebAssembly, Swift, Dart, Kotlin Android, and Zig.

  • Three output formats Available by v3.6

Markdown (CommonMark) by default, plus Djot and plain text via output_format. The same options apply to every format.

  • Metadata extraction Available by v3.6

Document title, Open Graph, Twitter Card, JSON-LD, links, and images in one pass. Enabled by default — disable with extract_metadata: false.

  • Table extraction Available by v3.6

HTML tables into result.tables with structured cells, row/column spans, and header flags, alongside the rendered Markdown.

  • Visitor pattern Available by v3.6

40 callbacks on the HtmlVisitor trait to skip, replace, or preserve nodes. Kotlin Android excludes visitor support. Zero cost when unused.


Language Support

Language Install API Reference
Rust cargo add html-to-markdown-rs Reference
Python pip install html-to-markdown Reference
TypeScript / Node npm install @xberg-io/html-to-markdown Reference
Go go get github.com/xberg-io/html-to-markdown/packages/go/v3 Reference
Ruby gem install html-to-markdown Reference
PHP pie install xberg-io/html-to-markdown Reference
Java Maven io.xberg:html-to-markdown Reference
C# dotnet add package XbergIo.HtmlToMarkdown Reference
Elixir {:html_to_markdown, "~> 3.4"} Reference
R install.packages("htmltomarkdown") Reference
C (FFI) Shared library + header Reference
WebAssembly npm install @xberg-io/html-to-markdown-wasm Reference
Swift Swift Package HtmlToMarkdown Reference
Dart dart pub add h2m Reference
Kotlin Android Maven io.xberg:html-to-markdown-android Reference
Zig Zig package html_to_markdown_rs Reference
CLI cargo install html-to-markdown-cli CLI Guide

Quick Example

main.py
from html_to_markdown import convert

result = convert("<h1>Hello</h1><p>World</p>")
print(result.content)
print(result.metadata)
index.ts
import { convert } from "@xberg-io/html-to-markdown";

const result = convert("<h1>Hello</h1><p>World</p>");
console.log(result.content);
console.log(result.metadata);
src/main.rs
use html_to_markdown_rs::convert;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let result = convert("<h1>Hello</h1><p>World</p>", None)?;
    println!("{}", result.content.unwrap_or_default());
    Ok(())
}

Part of Xberg.dev

html-to-markdown ships as a standalone library and as the HTML pipeline inside the Xberg document intelligence stack.

Document intelligence core — text, tables, and metadata from 91+ file formats. Uses html-to-markdown for every HTML input.

Managed SaaS API for document extraction. Same engine, no infrastructure.

Web crawler that pairs with html-to-markdown for crawl-then-convert pipelines.

Universal LLM client — feed it the Markdown out of html-to-markdown.

306 Tree-sitter grammars on demand for code intelligence.

Community chat for xberg.io users and contributors.


Explore the Docs

  • Get Started

Install a binding and run your first convert() call.

Installation

  • Guides

Visitor pattern, table extraction, error handling.

Visitor pattern

  • Concepts

Architecture, conversion pipeline, plugin system.

Architecture

  • Reference

Options reference, generated API docs, per-language guides.

Configuration

  • CLI

Every conversion option as a command-line flag.

CLI Guide

  • Migration

Upgrading from earlier versions.

Migration


Getting Help

Edit this page on GitHub