mirror of
https://github.com/027xiguapi/code-box.git
synced 2026-05-04 18:48:36 +00:00
30 lines
752 B
TypeScript
30 lines
752 B
TypeScript
import TurndownService from "@joplin/turndown"
|
|
|
|
var turndownPluginGfm = require("@joplin/turndown-plugin-gfm")
|
|
|
|
export default function Turndown(options?) {
|
|
const gfm = turndownPluginGfm.gfm
|
|
const tables = turndownPluginGfm.tables
|
|
const strikethrough = turndownPluginGfm.strikethrough
|
|
const turndownService = new TurndownService({
|
|
headingStyle: "atx",
|
|
codeBlockStyle: "fenced"
|
|
})
|
|
|
|
turndownService.use(gfm)
|
|
turndownService.use(tables, strikethrough)
|
|
|
|
// turndownService.keep(["h1", "h2"])
|
|
turndownService.remove(["script", "style"])
|
|
|
|
const addRules = options?.addRules
|
|
for (let key in addRules) {
|
|
const rule = addRules[key]
|
|
if (rule) {
|
|
turndownService.addRule(key, rule)
|
|
}
|
|
}
|
|
|
|
return turndownService
|
|
}
|