2018-09-10 00:33:10 +00:00
|
|
|
|
const md = require('markdown-it')
|
2018-09-17 04:36:44 +00:00
|
|
|
|
const mdAnchor = require('markdown-it-anchor')
|
2018-09-10 00:33:10 +00:00
|
|
|
|
const _ = require('lodash')
|
2018-09-17 04:36:44 +00:00
|
|
|
|
const uslug = require('uslug')
|
2018-09-10 00:33:10 +00:00
|
|
|
|
|
|
|
|
|
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) {
|
2018-09-17 02:30:24 +00:00
|
|
|
|
return `<pre><code class="language-${lang}">${_.escape(str)}</code></pre>`
|
2018-09-10 00:33:10 +00:00
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2018-09-17 04:36:44 +00:00
|
|
|
|
mkdown.use(mdAnchor, {
|
|
|
|
|
slugify: s => uslug(s),
|
|
|
|
|
permalink: true,
|
|
|
|
|
permalinkClass: 'toc-anchor',
|
|
|
|
|
permalinkSymbol: '¶',
|
|
|
|
|
permalinkBefore: true
|
|
|
|
|
})
|
|
|
|
|
|
2018-09-10 03:19:46 +00:00
|
|
|
|
for (let child of this.children) {
|
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
}
|