const md = require('markdown-it') const mdAttrs = require('markdown-it-attrs') const mdDecorate = require('markdown-it-decorate') const _ = require('lodash') const underline = require('./underline') const quoteStyles = { Chinese: '””‘’', English: '“”‘’', French: ['«\xA0', '\xA0»', '‹\xA0', '\xA0›'], German: '„“‚‘', Greek: '«»‘’', Japanese: '「」「」', Hungarian: '„”’’', Polish: '„”‚‘', Portuguese: '«»‘’', Russian: '«»„“', Spanish: '«»‘’', Swedish: '””’’' } module.exports = { async render() { const mkdown = md({ html: this.config.allowHTML, breaks: this.config.linebreaks, linkify: this.config.linkify, typographer: this.config.typographer, quotes: _.get(quoteStyles, this.config.quotes, quoteStyles.English), highlight(str, lang) { if (lang === 'diagram') { return `
` + Buffer.from(str, 'base64').toString() + `
` } else { return `
${_.escape(str)}
` } } }) if (this.config.underline) { mkdown.use(underline) } mkdown.use(mdAttrs, { allowedAttributes: ['id', 'class', 'target'] }) mkdown.use(mdDecorate) for (let child of this.children) { const renderer = require(`../${_.kebabCase(child.key)}/renderer.js`) await renderer.init(mkdown, child.config) } return mkdown.render(this.input) } }