npm package: @kitmodule/kitmarkdown
Description: Convert HTML to Markdown in vanilla JavaScript — lightweight, dependency-free, and easy to use.
Author: Huỳnh Nhân Quốc
Latest version: 1.0.8

# 📝 KitMarkdown by Kitmodule

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

[English](#) | [Tiếng Việt](https://github.com/kitmodule/kitmarkdown-js/blob/master/README.vi.md)

[![npm version](https://img.shields.io/npm/v/@kitmodule/kitmarkdown.svg)](https://www.npmjs.com/package/@kitmodule/kitmarkdown)
[![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/kitmodule/kitmarkdown-js/blob/master/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

```bash
npm install @kitmodule/kitmarkdown
```

### Using CDN

```html
<script src="https://unpkg.com/@kitmodule/kitmarkdown"></script>
```
or

```html
<script src="https://cdn.jsdelivr.net/gh/kitmodule/kitmarkdown-js/src/index.js"></script>
```

## 💡 Usage

### Browser (CDN)

```html
<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)

```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

```js
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](https://img.shields.io/badge/Ko--fi-FF5E5B?style=for-the-badge\&logo=ko-fi\&logoColor=white)](https://ko-fi.com/huynhnhanquoc)
[![Buy Me a Coffee](https://img.shields.io/badge/Buy_Me_a_Coffee-FFDD00?style=for-the-badge\&logo=buy-me-a-coffee\&logoColor=black)](https://buymeacoffee.com/huynhnhanquoc)
[![GitHub Sponsors](https://img.shields.io/badge/GitHub_Sponsors-f7f7f7?style=for-the-badge\&logo=githubsponsors\&logoColor=ff69b4\&color=f7f7f7)](https://github.com/sponsors/huynhnhanquoc)
[![Patreon](https://img.shields.io/badge/Patreon-F96854?style=for-the-badge\&logo=patreon\&logoColor=white)](https://patreon.com/huynhnhanquoc)
[![PayPal](https://img.shields.io/badge/PayPal-00457C?style=for-the-badge\&logo=paypal\&logoColor=white)](https://paypal.me/huynhnhanquoc)


## 🧾 License

Released under the [MIT License](https://github.com/kitmodule/kitmarkdown-js/blob/master/LICENSE)
© 2025 [Huỳnh Nhân Quốc](https://github.com/huynhnhanquoc) · Open Source [@Kit Module](https://github.com/kitmodule)