-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
68 lines (55 loc) · 2.1 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
'use strict';
var marked = require('marked'),
highlight = require('highlight.js'),
getRenderer = function (options) {
return new marked.Renderer();
},
registerLanguageDefinitions = function () {
highlight.registerLanguage('plain', function() {
return { case_insensitive: true };
});
highlight.registerLanguage('cli', function() {
return { case_insensitive: true };
});
};
registerLanguageDefinitions();
exports.enableHighlighting = function () {
marked.setOptions({
highlight: function (code, lang) {
if (lang) {
return highlight.highlight(lang, code).value;
}
return highlight.highlightAuto(code).value;
}
});
};
exports.enableBootstrapCompatibility = function () {
getRenderer = function (options) {
var renderer = new marked.Renderer(),
existingTableRenderer = renderer.table,
existingImageRenderer = renderer.image;
renderer.table = function (header, body) {
var content = existingTableRenderer(header, body);
return content.replace('<table>', '<table class="table table-bordered table-striped table-hover">');
};
renderer.image = function (href, title, text) {
var hrefIncludingBaseImageUrl = require('url').parse(href).protocol
? href
: options.marked.imageUrl.replace('{imageUrl}', href),
content = existingImageRenderer(hrefIncludingBaseImageUrl, title, text);
return content.replace('<img src=', '<img class="img-thumbnail" src=');
};
return renderer;
};
};
exports.parseMarkdownContent = function (markdownContent, options, callback) {
marked(markdownContent, { renderer: getRenderer(options) }, function (err, content) {
if (err) { throw err; }
callback(content);
});
};
exports.init = function (engine) {
engine.loadContent = function (entry, content, callback) {
exports.parseMarkdownContent(content, engine.getOptions(), callback);
};
};