Gathering detailed insights and metrics for html-to-md
Gathering detailed insights and metrics for html-to-md
Gathering detailed insights and metrics for html-to-md
Gathering detailed insights and metrics for html-to-md
A JS library for convert HTML<String> to markdown<String>, gzip 10kb
npm install html-to-md
Typescript
Module System
Node Version
NPM Version
98.8
Supply Chain
99.6
Quality
78.5
Maintenance
100
Vulnerability
100
License
JavaScript (60.43%)
TypeScript (29.51%)
HTML (10.06%)
Total Downloads
1,397,567
Last Day
10,627
Last Week
75,656
Last Month
312,918
Last Year
889,678
MIT License
143 Stars
196 Commits
17 Forks
1 Watchers
7 Branches
6 Contributors
Updated on Jul 19, 2025
Latest Version
0.8.8
Package Id
html-to-md@0.8.8
Unpacked Size
483.79 kB
Size
128.86 kB
File Count
118
NPM Version
8.19.4
Node Version
16.20.1
Published on
Apr 27, 2025
Cumulative downloads
Total Downloads
Last Day
-7%
10,627
Compared to previous day
Last Week
-3.3%
75,656
Compared to previous week
Last Month
7.7%
312,918
Compared to previous month
Last Year
463.6%
889,678
Compared to previous year
35
一个用于转换
HTML
为Markdown
的工具。English
快速,小巧,无任何依赖,gzip
10kb
支持nodeJS
,参数(html 文本)为字符串
200+单元测试和模块测试,覆盖率97%
注意:只有有效规范的 HTML 文本才能准确显示结果,如
<p>abc<
,<i>abc</>
等都是无效文本
最初的动机是希望将leetcode-cn
上的题目和自己的解答搬到github
,
但是获取的介绍都是html
格式文本,因此有了将html
转换为markdown
的需求。
找了几个工具,结果并不是很合胃口,有的不支持nodejs
,有的并不能很好的转换,最终决定自己写一个来用。
刚开始只是写了一个比较简单的,但已经能够处理我的需求。
但后来偶尔一次使用,面对更复杂的html
格式,就会出现混乱,这个库也就是一个重构版,
当然,它可能还存在很多bug
没有发现,但希望能在后续不断完善,如果有发现bug
,请提issue
或PR
,我会第一时间进行处理。
npm -i html-to-md
1const html2md = require('html-to-md') 2// or if you're using ES6 3import html2md from 'html-to-md' 4 5console.log( 6 html2md('<strong><em>strong and italic</em></strong>', options, force) 7) 8// ***strong and italic***
名称 | 数据类型 | 默认值 | 说明 |
---|---|---|---|
skipTags | Array |
| 需要忽略的标签名 |
emptyTags | Array | [] | 不仅忽略它本身,它内部所有标签名全部忽略 |
ignoreTags | Array |
| 忽视标签及其内部所有内容 |
aliasTags | Object |
| 为标签定义一个别名(通常作用于一些不常用标签) |
renderCustomTags | Boolean | 'SKIP' | 'EMPTY' | 'IGNORE' |
true | 定义是否渲染自定义标签(非HTML标签),
|
tagListener | Function | (tagName: String, props: TagListenerProps): TagListenerReturnProps => props | 自定义当前标签部分属性配置 |
优先权:skipTags > emptyTags > ignoreTags > aliasTags
例:
1html2md('<><b><i>abc</i></b></>', { ignoreTags: [''] }) 2// '' 3 4html2md('<><b><i>abc</i></b></>', { skipTags: [''] }) 5// ***abc*** 6 7html2md('<><b><i>abc</i></b></>', { emptyTags: [''] }) 8// abc 9 10html2md('<><b><i>abc</i></b></>', { 11 skipTags: [''], 12 aliasTags: { b: 'ul', i: 'li' }, 13}) 14// * abc 15 16html2md('<test><b><i>abc</i></b></test>', { renderCustomTags: 'SKIP' }) 17// ***abc***
值 | 说明 |
---|---|
true | 表示强制使用自定义配置 |
false | 对自定义配置使用Object.assign 操作 |
例:
1// 默认 skipTags 为 ['div','html','body'] 2 3// 配置一: 4html2md('<div><b><i>abc</i></b></div>', { skipTags: ['b'] }, false) 5// skipTags 为 ['div','html','body','b'] 6 7// 配置二: 8html2md('<div><b><i>abc</i></b></div>', { skipTags: ['b'] }, true) 9// 经过配置后 skipTags 为 ['b']
key | 说明 |
---|---|
parentTag | 父标签名,没有则为 null |
prevTagName | 上一个标签名,没有则为 null |
nextTagName | 下一个标签名,没有则为 null |
isFirstSubTag | 是否当前父标签内部的第一个子标签 |
attrs | 当前标签的 attributes,以 object 集合方式,例如 { src, href ... } |
innerHTML | 内部 HTML 字符串 |
match | 当前的 HTML 对应 Markdown 的匹配符号 |
language? | 当前标签语言,只在 pre 标签中出现 |
isSelfClosing | 是否自闭和标签 |
key | 说明 |
---|---|
attrs | 当前标签的 attributes,以 object 集合方式,例如 { src, href ... } |
match | 返回一个新的自定义匹配符号 |
language? | 返回自定义 pre 标签的 language |
a
b
blockquote
code
del
em
h1~h6
hr
i
img
input
li
ol
p
pre
s
strong
table
tbody
td
th
thead
tr
ul
No vulnerabilities found.