-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
43 lines (36 loc) · 985 Bytes
/
index.js
File metadata and controls
43 lines (36 loc) · 985 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const fs = require('fs')
const path = require('path')
var marked = require('marked')
const parser = require('posthtml-parser')
module.exports = function (config = {}) {
const { root = './', encoding = 'utf-8' } = config
marked.setOptions(Object.assign({
headerPrefix: 'header-',
gfm: true,
highlight: function (code) {
return require('highlight.js').highlightAuto(code).value
}
}, config))
return function includeMD (tree) {
tree.match({ tag: 'markdown' }, function (node) {
let src = node.attrs.src || false
let content = ''
if (src) {
src = path.resolve(root, src)
const parsedContent = marked(fs.readFileSync(src, encoding))
content = parser(parsedContent)
if (tree.messages) {
tree.messages.push({
type: 'dependency',
file: src
})
}
}
return {
tag: false,
content: content
}
})
return tree
}
}