turndown
用JavaScript将HTML转换为Markdown
最后更新时间:2023-12-04
Markdown

安装

npm:

npm install turndown
npm install turndown-plugin-gfm

Browser:

<script src="https://unpkg.com/turndown/dist/turndown.js"></script>
<script src="https://unpkg.com/turndown-plugin-gfm/dist/turndown-plugin-gfm.js"></script>

使用

import TurndownService from 'turndown';
import { gfm, tables, strikethrough } from "turndown-plugin-gfm";

const turndownService = new TurndownService({
      headingStyle: "atx",
      bulletListMarker: "-",
      preformattedCode: true,
})
turndownService.use([gfm, tables, strikethrough])
let markdown = turndownService.turndown("<h1>Hello world!</h1>")