forked from niemingzhao/hexo-renderer-markdown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
47 lines (42 loc) · 1.46 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
'use strict';
const def_main_conf = {
html: true,
xhtmlOut: false,
breaks: true,
linkify: true,
typographer: true,
quotes: '“”‘’'
};
let renderer = function (data, options) {
let merge = require('lodash.merge');
let keys = require('lodash.keys');
let config = merge({}, this.config.markdown);
let main_conf = merge({}, def_main_conf, config.render);
let pugs_conf = config.plugins;
let pugs_list = keys(pugs_conf);
let parser = require('markdown-it')(main_conf);
parser = pugs_list.reduce(function (parser, pugs) {
let pugs_opt = merge({}, pugs_conf[pugs]);
for (let item in pugs_opt) {
if (
typeof pugs_opt[item] === 'string' &&
pugs_opt[item].startsWith('function (') &&
pugs_opt[item].endsWith('}')
) {
pugs_opt[item] = eval('(' + pugs_opt[item] + ')');
}
}
if (pugs_opt._parser) {
return eval('(' + pugs_opt._parser + ')');
}
return parser.use(require(pugs), pugs_opt);
}, parser);
return parser.render(data.text);
};
hexo.extend.renderer.register('md', 'html', renderer, true);
hexo.extend.renderer.register('markdown', 'html', renderer, true);
hexo.extend.renderer.register('mkd', 'html', renderer, true);
hexo.extend.renderer.register('mkdn', 'html', renderer, true);
hexo.extend.renderer.register('mdwn', 'html', renderer, true);
hexo.extend.renderer.register('mdtxt', 'html', renderer, true);
hexo.extend.renderer.register('mdtext', 'html', renderer, true);