Quick Start¶
This guide walks you through your first HTML-to-Markdown conversion, then shows how to customize the output with options.
Basic Conversion¶
Convert an HTML string to Markdown with a single function call.
Conversion with Options¶
Customize the Markdown output by passing configuration options. Every binding exposes the same set of options through language-idiomatic APIs.
package main
import (
"fmt"
"log"
"github.com/kreuzberg-dev/html-to-markdown/packages/go/v2/htmltomarkdown"
)
func main() {
// Check library version
version := htmltomarkdown.Version()
fmt.Printf("html-to-markdown version: %s\n", version)
html := "<h1>Hello</h1><p>Welcome</p>"
// Convert with error handling
markdown, err := htmltomarkdown.Convert(html)
if err != nil {
log.Fatalf("Conversion failed: %v", err)
}
fmt.Println(markdown)
// Alternative: Use MustConvert for panicking on error
anotherMarkdown := htmltomarkdown.MustConvert("<p>Safe HTML</p>")
fmt.Println(anotherMarkdown)
}
import dev.kreuzberg.htmltomarkdown.HtmlToMarkdown;
import dev.kreuzberg.htmltomarkdown.metadata.MetadataExtraction;
public class MetadataExample {
public static void main(String[] args) {
String html = "<html><head><title>My Page</title></head>"
+ "<body><h1>Welcome</h1><a href=\"https://example.com\">Link</a></body></html>";
MetadataExtraction result = HtmlToMarkdown.convertWithMetadata(html);
System.out.println("Markdown: " + result.markdown());
System.out.println("Title: " + result.metadata().document().title());
System.out.println("Headers: " + result.metadata().headers().size());
System.out.println("Links: " + result.metadata().links().size());
}
}
What Gets Converted¶
html-to-markdown handles the full range of HTML elements you would encounter in web content:
| HTML | Markdown |
|---|---|
<h1> through <h6> | # through ###### headings |
<p> | Paragraphs separated by blank lines |
<strong>, <b> | **bold** |
<em>, <i> | *italic* |
<a href="..."> | [text](url) links |
<img src="..."> |  images |
<ul>, <ol> | Bulleted and numbered lists |
<pre><code> | Fenced code blocks |
<blockquote> | > block quotes |
<table> | Markdown tables with alignment |
<hr> | --- thematic breaks |
<del>, <s> | ~~strikethrough~~ |
<input type="checkbox"> | - [ ] / - [x] task lists |
Next Steps¶
- Configuration Options -- Full reference for all conversion options
- Metadata Extraction -- Extract document metadata alongside conversion
- Visitor Pattern -- Customize conversion with callbacks
- CLI Usage -- Convert files from the command line
- Features -- Complete feature overview
Using kreuzberg?
If you are processing diverse document types (PDFs, DOCX, images) and need Markdown output, consider kreuzberg which uses html-to-markdown internally and adds OCR, format detection, and multi-format extraction.