{"repo":"stonehank/html-to-md","free":true,"listed":false,"github":"https://github.com/stonehank/html-to-md","clone":"git clone https://github.com/stonehank/html-to-md.git","description":"A JS library for convert HTML<String> to markdown<String>, gzip 10kb","language":"JavaScript","stars":159,"topics":["markdown","html","javascript","nodejs"],"license":"MIT","category":"productivity","readme_excerpt":"一个用于转换 HTML 为 Markdown 的工具。English --- 特点 - 快速，小巧，无任何依赖， gzip 10kb - 支持 nodeJS ，参数(html 文本)为字符串 - 200+单元测试和模块测试，覆盖率 97% 注意：只有有效规范的 HTML 文本才能准确显示结果，如 abc abc 等都是 无效 文本 效果 live-demo 为什么做这个工具 最初的动机是希望将 leetcode-cn 上的题目和自己的解答搬到 github ， 但是获取的介绍都是 html 格式文本，因此有了将 html 转换为 markdown 的需求。 找了几个工具，结果并不是很合胃口，有的不支持 nodejs ，有的并不能很好的转换，最终决定自己写一个来用。 刚开始只是写了一个比较简单的，但已经能够处理我的需求。 但后来偶尔一次使用，面对更复杂的 html 格式，就会出现混乱，这个库也就是一个重构版， 当然，它可能还存在很多 bug 没有发现，但希望能在后续不断完善，如果有发现 bug ，请提 issue 或 PR ，我会第一时间进行处理。 使用说明 安装 npm -i html-to-md 使用 参数(可选)： options: 名称 数据类型 默认值 说明 skipTags Array [ 'div', 'html', 'body', 'nav', 'section', 'footer', 'main', 'aside', 'article', 'header' ] 需要忽略的标签名 emptyTags Array [] 不仅忽略它本身，它内部所有标签名全部忽略 ignoreTags Array [ '', 'style', 'head', '!doctype', 'form', 'svg', 'noscript', 'script', 'meta' ] 忽视标签及其内部所有内容 aliasTags Object { figure :'p', figcaption:'p', dl:'p', dd:'p', dt:'p' } 为标签定义一个别名(通常作用于一些不常用标签) renderCustomTags &nbsp;&nbsp; Boolean 'SKIP' 'EMPTY' 'IGNORE' true 定义是否渲染自定义标签（非HTML标签）， true ：渲染 false SKIP ：添加至 skipTags EMPTY ：添加至 emptyTags IGNORE ：添加至 ignoreTags tagListener Function (tagName: String, props: TagListenerProps ): TagListenerReturnProps = props 自定义当前标签部分属性配置 优先权：skipTags emptyTags ignoreTags aliasTags 例： force(Boolean)(默认 false) 值 说明 :---: :---------------------------------: true 表示强制使用自定义配置 false 对自定义配置使用 Object.assign 操作 例： TagListenerProps key 说明 ------------- ----------------------------------------------------------------- parentTag 父标签名，没有则为 null prevTagName 上一个标","default_branch":null,"files":null,"tree":[],"storefront":"/r/stonehank","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/stonehank/html-to-md/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}