@kitmodule/kitmarkdown
v1.0.8
Published
Convert HTML to Markdown in vanilla JavaScript — lightweight, dependency-free, and easy to use.
Maintainers
Readme
📝 KitMarkdown by Kitmodule
Convert HTML to Markdown in vanilla JavaScript — lightweight, dependency-free, and easy to use.
✨ Features
- 🏷️ 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).
🚀 Installation
Using npm
npm install @kitmodule/kitmarkdownUsing CDN
<script src="https://unpkg.com/@kitmodule/kitmarkdown"></script>or
<script src="https://cdn.jsdelivr.net/gh/kitmodule/kitmarkdown-js/src/index.js"></script>💡 Usage
Browser (CDN)
<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>Using the KitMarkdown class (ES Module / Node.js)
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);🧩 API Reference
new KitMarkdown(html)
Create a new instance for HTML → Markdown conversion.
| Param | Type | Description | | ----- | ------ | ---------------------- | | html | string | HTML string to convert |
Instance method
| Method | Description |
| ------------ | --------------------------------------------- |
| .convert() | Convert HTML to Markdown and return as string |
Shortcut function
| Function | Description |
| ------------------------ | ------------------------------------- |
| HTML2Markdown(html) | Quick convert HTML string to Markdown |
🧪 Example Output
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☕ Support the Author
If you find this library useful, you can support me:
🧾 License
Released under the MIT License © 2025 Huỳnh Nhân Quốc · Open Source @Kit Module
