-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
36 lines (30 loc) · 956 Bytes
/
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
var fs = require("fs"),
path = require("path"),
_ = require("underscore");
var filePath = path.join(__dirname, 'mermaid-template.html');
function mermaid(args, content) {
var template = fs.readFileSync(filePath).toString();
return _.template(template)({
content: content
});
}
hexo.extend.tag.register('mermaid', mermaid, {
async: true,
ends: true
});
var r = /\n*(`{3,}|~{3,}) *(.+)? *\n([\s\S]+?)\s*\1\n*/g
hexo.extend.filter.register('before_post_render', function(data){
if((matches = r.exec(data.content)) != null) {
data.raw = data.content = data.content.replace(r, function(match, ticks, lang, code, offset, str) {
try{
if (lang.trim() == 'mermaid') {
return "\n{% mermaid %}\n" + code + "{% endmermaid %}\n";
}
return match;
}catch(err){
return match;
}
});
}
return data;
}, 1);