Html2md
Node-JS library to convert HTML to Markdown, using cheerio
Install / Use
/learn @mofux/Html2mdREADME
HTML 2 Markdown
A simple NodeJS library to convert HTML to Markdown.
How it works
The given HTML string is transformed into a virtual DOM using cheerio and afterwards minified using html-minifier. The resulting DOM-Nodes are then run though (extendable) rules and deconstructed into Markdown text.
Each DOM-Node replaces itself with the transformed output text. The end result is a <body> with only text nodes inside. The resulting innerHTML() of the body is then sanitized (removing more then 2 linkbreaks in a row etc.) and its content given back.
Why yet another lib?
I was trying serveral other libs before and none was a perfect fit. Often they didn't escape correctly, so that a <div># Hello World</div> would result in # Hello World as Markdown, which is not correct. Also, some libs did not work in newer NodeJS versions.
Feature support
Not everything has a coverage yet, but most things work quite well:
Support | Feature | Notes
:---------: | ----------------------------------------- | :---------------------
✓ | Line Breaks |
✓ | Images |
✓ | Anchors |
✓ | Lists (ordered, unordered) |
✓ | Strong text |
✓ | Italic text |
✓ | Strikethrough text |
✓ | Headings |
✓ | Horizontal line |
✓ | Paragraphs |
✓ | Inline Code |
✓ | Code Blocks |
✓ | Blockquotes |
✓ | Tables (Markdown Extra Feature) | colspan is buggy. rowspan is unsupported.
Usage
const html2md = require('html2md');
console.log(html2md('<h1>Hello World</h1>')); // # Hello World
Some features of the converter might be disabled. Currently only table is supported to be disabled:
html2md(html, {
disable: ['table']
});
Demo
- Clone this repository and move into the
demofolder. - Add your own sites to
sites.json. - Run
node demo.jsand watch the newly written files under demodemo/outputfolder.
You might also want to have a look into the *.sample files within the test/samples folder of this repository.
Related Skills
node-connect
345.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
104.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
345.4kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
345.4kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。

