Newsletter
Join the Community
Subscribe to our newsletter for the latest news and updates
A Go library and CLI that converts HTML — even entire websites — into clean Markdown, with plugin support for customization.
HTML-to-Markdown is an open-source Go library and command-line tool that converts HTML input — including entire websites — into clean, readable Markdown, with plugin support for customizing the conversion.
HTML-to-Markdown is an open-source Go project maintained by Johannes Kaufmann, available on GitHub. It provides a v2 Golang library (github.com/JohannesKaufmann/html-to-markdown/v2) and a CLI executable called html2markdown. The converter takes HTML as input — from a string, a file, or piped stdin — and outputs Markdown text. It implements the CommonMark specification for core formatting and the GitHub Flavored Markdown spec for its table plugin. The library's main entry point is htmltomarkdown.ConvertString(), a wrapper around converter.NewConverter() with the base and commonmark plugins registered.
TagType and RendererFor registration, with a priority system (e.g. PriorityEarly) to override defaults like the removal of <style>.<strike>, <s>, and <del> to ~~; Table implements GFM tables with alignment, rowspan, and colspan) or write custom plugins and publish them.ConvertString() or the lower-level converter.NewConverter() with the base and commonmark plugins for full control over conversion.--input and --output flags, including glob patterns and selectors like --include-selector and --exclude-selector.--domain.echo "<strong>important</strong>" | html2markdown.curl --no-progress-meter http://example.com | html2markdown to get a clean Markdown version for personal notes or archiving.html2markdown --input "src/*.html" --output "dist/" to convert a folder of HTML files to Markdown, preserving relative links with --domain.--plugin-table to convert HTML tables with rowspan and colspan, or write a custom Go plugin and register it to handle web components or custom elements.The library parses HTML with Go's html.Parse() and walks the resulting DOM, applying registered converters and plugins. The CLI reads input from stdin, a file, or a glob pattern, converts it using the same engine, and writes to stdout or a file. Relative URLs can be made absolute with WithDomain in the library or --domain in the CLI.
Converter usable from multiple goroutines.Yes, the project is open source and licensed under the MIT license, and the source code is available on GitHub.
The tool accepts any HTML, including entire web pages. Internally it uses Go's html.Parse() and requires the input to be UTF-8 encoded; it does not handle charset detection or conversion.
No. The library does not sanitize untrusted content. If you render the resulting Markdown back to HTML for display, you should pass it through an HTML sanitizer like bluemonday to prevent malicious content from being shown.
Yes, the Converter type is safe for concurrent use because a mutex protects internal state, and the project includes a test covering this behavior.
You can write custom logic and register it with conv.Register (for example, TagType, RendererFor, or a custom plugin). The documentation includes a WRITING_PLUGINS.md guide, and the repo has example code for registration.
