UNPKG

qing-markdown-reader

Version:

Markdown string tool, input markdown string, return html string

31 lines (25 loc) 681 B
const marked = require("marked") const hljs = require("highlight.js") const ObjectUtils = require("qing-utils/src/ObjectUtils") const renderer = new marked.Renderer() const defaultOptions = { renderer: renderer, gfm: true, smartLists: true, smartypants: true, highlight(code) { return hljs.highlightAuto(code).value } } class MdReader { static read(text, options) { let assignOptions = defaultOptions if (options) { assignOptions = ObjectUtils.deepClone(defaultOptions).assign(options) } marked.setOptions(assignOptions) return marked(text) } } MdReader.renderer = renderer module.exports = MdReader