-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (42 loc) · 1.05 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
/*
* fis
* http://fis.baidu.com/
*/
'use strict';
var marked = require('marked');
var hljs = require('highlight.js');
marked.defaults.renderer.heading = function(text, level, raw){
if(typeof this.options.heading === 'function'){
return this.options.heading.call(this, text, level, raw);
} else {
return '<h'
+ level
+ ' id="'
+ this.options.headerPrefix
+ encodeURIComponent(text.toLowerCase())
+ '">'
+ text
+ '</h'
+ level
+ '>\n';
}
};
module.exports = function(content, file, conf){
hljs.configure(conf.hljs || {
tabReplace: ' '
});
marked.setOptions(conf);
return marked(content);
};
module.exports.defaultOptions = {
gfm: true,
breaks: true,
langPrefix: 'hljs ',
highlight : function(code, lang){
if(lang && hljs.getLanguage(lang)){
return hljs.highlight(lang, code).value;
} else {
return hljs.highlightAuto(code).value;
}
}
};