
Product
Introducing Repository Access Permissions and Custom Roles
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.
一个用于转换
HTML为Markdown的工具。English
最初的动机是希望将leetcode-cn上的题目和自己的解答搬到github,
但是获取的介绍都是html格式文本,因此有了将html转换为markdown的需求。
找了几个工具,结果并不是很合胃口,有的不支持nodejs,有的并不能很好的转换,最终决定自己写一个来用。
刚开始只是写了一个比较简单的,但已经能够处理我的需求。
但后来偶尔一次使用,面对更复杂的html格式,就会出现混乱,这个库也就是一个重构版,
当然,它可能还存在很多bug没有发现,但希望能在后续不断完善,如果有发现bug,请提issue或PR,我会第一时间进行处理。
npm -i html-to-md
const html2md=require('html-to-md')
console.log(html2md('<strong><em>strong and italic</em></strong>',options,force))
// ***strong and italic***
options:
| 名称 | 数据类型 | 默认值 | 说明 |
|---|---|---|---|
| skipTags | Array | | 需要忽略的标签名 |
| emptyTags | Array | [] | 不仅忽略它本身,它内部所有标签名全部忽略 |
| ignoreTags | Array |
| 忽视标签及其内部所有内容 |
| aliasTags | Object |
| 为标签定义一个别名(通常作用于一些不常用标签) |
优先权:skipTags > emptyTags > ignoreTags > aliasTags
例:
html2md('<><b><i>abc</i></b></>',{ignoreTags:['']})
// ''
html2md('<><b><i>abc</i></b></>',{skipTags:['']})
// ***abc***
html2md('<><b><i>abc</i></b></>',{emptyTags:['']})
// abc
html2md('<><b><i>abc</i></b></>',{skipTags:[''],aliasTags:{b:'ul',i:'li'}})
// * abc
force(Boolean)(默认false)
| 值 | 说明 |
|---|---|
| true | 表示强制使用自定义配置 |
| false | 对自定义配置使用Object.assign操作 |
例:
// 默认 skipTags 为 ['div','html','body']
// 配置一:
html2md('<div><b><i>abc</i></b></div>',{skipTags :['b']},false)
// skipTags 为 ['div','html','body','b']
// 配置二:
html2md('<div><b><i>abc</i></b></div>',{skipTags :['b']},true)
// 经过配置后 skipTags 为 ['b']
快速,小巧,无任何依赖,gzip 7kb
支持nodeJS,参数(html文本)为字符串
100+单元测试和模块测试,覆盖率98%
注意:只有有效规范的HTML文本才能准确显示结果,如
<p>abc<,<i>abc</>等都是无效文本
abblockquotecodedelemh1~h6hriimginputliolppresstrongtabletbodytdththeadtrulFAQs
A JS library for convert HTML<String> to markdown<String>, gzip 9kb
We found that html-22-md demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.

Product
Socket MCP now lets AI assistants review org alerts, investigate threats using the Socket threat feed, and inspect package files in addition to dependency scoring.

Product
Socket Firewall blocks malicious VS Code and Open VSX extensions before install, protecting developers from compromised editor marketplaces.