Convert HTML to Markdown in vanilla JavaScript — lightweight, dependency-free, and easy to use.
- 🏷️ Convert HTML headings, paragraphs, and text styles (bold, italic, underline, strikethrough, mark, code).
- 🔗 Convert links, images, audio, video.
- 📋 Convert lists (
ul,ol) and tables. - 🧾 Support blockquotes, horizontal rules, figures, figcaptions.
- ⚡ Pure vanilla JavaScript, zero dependencies.
- 💨 Quick conversion with a single function
HTML2Markdown(html).
npm install @kitmodule/kitmarkdown<script src="https://unpkg.com/@kitmodule/kitmarkdown"></script>or
<script src="https://cdn.jsdelivr.net/gh/kitmodule/kitmarkdown-js/src/index.js"></script><script src="https://unpkg.com/@kitmodule/kitmarkdown"></script>
<script>
const html = "<h1>Hello</h1><p>This is a test.</p>";
const md = HTML2Markdown(html);
console.log(md);
</script>import { KitMarkdown, HTML2Markdown } from "@kitmodule/kitmarkdown";
// Quick conversion
const html = "<h1>Hello</h1><p>This is a test.</p>";
console.log(HTML2Markdown(html));
// Using class instance
const converter = new KitMarkdown("<h2>Subtitle</h2><p>Some text</p>");
const markdown = converter.convert();
console.log(markdown);Create a new instance for HTML → Markdown conversion.
| Param | Type | Description |
|---|---|---|
| html | string | HTML string to convert |
| Method | Description |
|---|---|
.convert() |
Convert HTML to Markdown and return as string |
| Function | Description |
|---|---|
HTML2Markdown(html) |
Quick convert HTML string to Markdown |
const md = HTML2Markdown(`
<h1>Title</h1>
<p>Hello <strong>world</strong>!</p>
<ul><li>Item 1</li><li>Item 2</li></ul>
`);
console.log(md);Output:
# Title
Hello **world**!
- Item 1
- Item 2
If you find this library useful, you can support me:
Released under the MIT License © 2025 Huỳnh Nhân Quốc · Open Source @Kit Module