JSPM

  • Created
  • Published
  • Downloads 78274
  • Score
    100M100P100Q151503F
  • License MIT

A JS library for convert HTML<String> to markdown<String>, gzip 6kb

Package Exports

  • html-to-md

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (html-to-md) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

一个用于转换HTMLMarkdown的工具。


Build Status npm codecov

效果

live-demo

为什么要做个

最初的动机是希望将leetcode-cn上的题目和自己的解答搬到github, 但是获取的介绍都是html格式文本,因此有了将html转换为markdown的需求。

找了几个工具,结果并不是很合胃口,有的不支持nodejs,有的并不能很好的转换,最终决定自己写一个来用。

刚开始只是写了一个比较简单的,但已经能够处理我的需求。

但后来偶尔一次使用,面对更复杂的html格式,就会出现混乱,这个库也就是一个重构版, 当然,它可能还存在很多bug没有发现,但希望能在后续不断完善,如果有发现bug,请提issuePR,我会第一时间进行处理。

使用说明

安装

npm -i html-to-md

使用
const html2md=require('html-to-md')

console.log(html2md('<strong><em>strong and italic</em></strong>'))

特点

  • 快速,小巧,无任何依赖,gzip 6kb

  • 支持nodeJS,参数(html文本)为字符串

  • 100+单元测试和模块测试,覆盖率97.7%

注意:只有有效规范的HTML文本才能准确显示结果,如<p>abc<<i>abc</>等都是无效文本

支持标签

  • a
  • b
  • blockquote
  • code
  • del
  • em
  • h1~h6
  • hr
  • i
  • img
  • li
  • ol
  • p
  • pre
  • s
  • strong
  • table
  • tbody
  • td
  • th
  • thead
  • tr
  • ul

待完成事项

  • 添加input的支持
  • 添加参数,以便适应更多自定义需求
  • 增加测试