-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
28 lines (25 loc) · 792 Bytes
/
Copy pathindex.js
File metadata and controls
28 lines (25 loc) · 792 Bytes
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
var _ = require('lodash');
var marked = require('marked');
var markdownAttr = / data-markdown[ >]/;
function replaceContent(src) {
var nodes = marked.lexer(src);
_.each(nodes, function(n) {
if (n.type === 'html' && markdownAttr.test(n.text.substring(0, n.text.indexOf('>') + 1))) {
var bodyStart = n.text.indexOf('>') + 1;
var bodyEnd = n.text.lastIndexOf('<');
var body = marked(replaceContent(n.text.substring(bodyStart, bodyEnd)));
var content = n.text.substring(0, bodyStart) + body + n.text.substring(bodyEnd);
src = src.replace(n.text, content);
}
});
return src;
}
function processContent(_page) {
_page.content = replaceContent(_page.content);
return _page;
}
module.exports = {
hooks: {
'page:before': processContent
}
};