2020-08-13 15:18:26 +08:00
|
|
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
|
|
const Config = require('markdown-it-chain')
|
|
|
|
const anchorPlugin = require('markdown-it-anchor')
|
|
|
|
const slugify = require('transliteration').slugify
|
2020-09-16 08:27:46 +08:00
|
|
|
const hljs = require('highlight.js')
|
2020-08-13 15:18:26 +08:00
|
|
|
const containers = require('./containers')
|
|
|
|
const overWriteFenceRule = require('./fence')
|
|
|
|
|
|
|
|
const config = new Config()
|
|
|
|
|
2020-09-16 08:27:46 +08:00
|
|
|
const highlight = (str, lang) => {
|
|
|
|
if (!lang || !hljs.getLanguage(lang)) {
|
|
|
|
return '<pre><code class="hljs">' + str + '</code></pre>'
|
|
|
|
}
|
|
|
|
const html = hljs.highlight(lang, str, true, undefined).value
|
|
|
|
return `<pre><code class="hljs language-${lang}">${html}</code></pre>`
|
|
|
|
}
|
|
|
|
|
2020-08-13 15:18:26 +08:00
|
|
|
config
|
2020-09-16 08:27:46 +08:00
|
|
|
.options.html(true).highlight(highlight).end()
|
2020-08-13 15:18:26 +08:00
|
|
|
|
|
|
|
.plugin('anchor').use(anchorPlugin, [
|
|
|
|
{
|
|
|
|
level: 2,
|
|
|
|
slugify: slugify,
|
|
|
|
permalink: true,
|
|
|
|
permalinkBefore: true,
|
|
|
|
},
|
|
|
|
]).end()
|
|
|
|
|
|
|
|
.plugin('containers').use(containers).end()
|
|
|
|
|
|
|
|
const md = config.toMd()
|
|
|
|
overWriteFenceRule(md)
|
|
|
|
|
|
|
|
module.exports = md
|