-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
42 lines (41 loc) · 1001 Bytes
/
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
var Markdownit = require('markdown-it')
function Marli (presetName, opts) {
if (typeof presetName === 'object') {
opts = presetName
presetName = 'default'
}
var rules
if (opts && opts.rules) {
rules = opts.rules
delete opts.rules
}
var md = Markdownit(presetName, opts)
if (opts && opts.plugins && Array.isArray(opts.plugins)) {
opts.plugins.forEach(plugin => {
md.use(plugin)
})
}
if (typeof rules === 'object') {
for (var rule in rules) {
md.renderer.rules[rule] = rules[rule]
}
}
function _md (strings) {
var arglen = arguments.length
var result = ''
for (var i = 0; i < arglen; i++) {
var arg = arguments[ i + 1 ] || ''
result += strings[i] + arg
}
if (typeof document !== 'undefined') {
var div = document.createElement('div')
div.innerHTML = md.render(result)
return div
} else {
return md.render(result)
}
}
_md._md = md
return _md
}
module.exports = Marli