wikijs-fork/server/modules/rendering/markdown-core/renderer.js

41 lines
1.0 KiB
JavaScript
Raw Normal View History

2018-09-10 00:33:10 +00:00
const md = require('markdown-it')
const _ = require('lodash')
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) {
return '<pre><code>' + _.escape(str) + '</code></pre>'
}
})
for (let child of this.children) {
console.info(child)
const renderer = require(`../${_.kebabCase(child.key)}/renderer.js`)
renderer.init(mkdown, child.config)
}
2018-09-10 00:33:10 +00:00
return mkdown.render(this.input)
}
}