Skip to content

Convert HTML to Markdown in vanilla JavaScript lightweight, dependency-free, and easy to use.

License

Notifications You must be signed in to change notification settings

kitmodule/kitmarkdown-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📝 KitMarkdown by Kitmodule

Convert HTML to Markdown in vanilla JavaScript — lightweight, dependency-free, and easy to use.

English | Tiếng Việt

npm version license

✨ 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/kitmarkdown

Using 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:

Ko-fi Buy Me a Coffee GitHub Sponsors Patreon PayPal

🧾 License

Released under the MIT License © 2025 Huỳnh Nhân Quốc · Open Source @Kit Module

About

Convert HTML to Markdown in vanilla JavaScript lightweight, dependency-free, and easy to use.

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published