forked from schrodinger/fixed-data-table-2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
markdownLoader.js
56 lines (47 loc) · 1.26 KB
/
markdownLoader.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
48
49
50
51
52
53
54
55
56
"use strict";
var marked = require('marked');
var prism = require('./prism');
// functions come before keywords
prism.languages.insertBefore('javascript', 'keyword', {
'var': /\b(this)\b/g,
'block-keyword': /\b(if|else|while|for|function)\b/g,
'primitive': /\b(true|false|null|undefined)\b/g,
'function': prism.languages.function,
});
prism.languages.insertBefore('javascript', {
'qualifier': /\b[A-Z][a-z0-9_]+/g,
});
marked.setOptions({
xhtml: true,
highlight: function(code) {
return prism.highlight(code, prism.languages.javascript);
}
});
var renderer = new marked.Renderer();
renderer.code = function(code, lang, escaped) {
if (this.options.highlight) {
var out = this.options.highlight(code, lang);
if (out != null && out !== code) {
escaped = true;
code = out;
}
}
return '<code class="codeBlock">' +
(escaped ? code : escapeCode(code, true)) +
'</code>';
};
function escapeCode(code) {
return code
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
.replace(/'/g, ''');
}
module.exports = function(markdown) {
if (this && this.cacheable) {
// Webpack specific call
this.cacheable();
}
return marked(markdown, { renderer: renderer });
};