-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathengine.js
74 lines (71 loc) · 2.41 KB
/
engine.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
69
70
71
72
73
74
import markdownIt from 'markdown-it'
import markdownitIcons from 'markdown-it-icons'
import markdownItHighlight from 'markdown-it-highlight'
import markdownItLatex from 'markdown-it-latex'
import markdownItMark from 'markdown-it-mark'
import markdownItIns from 'markdown-it-ins'
import markdownItSub from 'markdown-it-sub'
import markdownItSup from 'markdown-it-sup'
import markdownitContainer from 'markdown-it-container'
import markdownItDeflist from 'markdown-it-deflist'
import markdownItAbbr from 'markdown-it-abbr'
import markdownItFootnote from 'markdown-it-footnote'
import markdownItGithubToc from 'markdown-it-github-toc'
import markdownItTaskList from 'markdown-it-task-list'
import markdownItSourceMap from 'markdown-it-source-map'
import markdownItChart from 'markdown-it-chart'
import markdownItMermaid from 'markdown-it-mermaid'
const pluginMap = {
'mark': markdownItMark,
'ins': markdownItIns,
'sub': markdownItSub,
'sup': markdownItSup,
'deflist': markdownItDeflist,
'abbr': markdownItAbbr,
'footnote': markdownItFootnote,
'task-list': markdownItTaskList,
'source-map': markdownItSourceMap,
'highlight': markdownItHighlight,
'latex': markdownItLatex,
'chart': markdownItChart,
'mermaid': markdownItMermaid
}
class Engine {
constructor (options = {}, plugins = []) {
this.mdc = markdownIt(options)
if (options.linkify === true) {
this.mdc.linkify.set({ fuzzyLink: false })
}
plugins.filter((plugin) => pluginMap[plugin]).forEach((plugin) => {
this.mdc.use(pluginMap[plugin])
})
plugins.filter((plugin) => !pluginMap[plugin]).forEach((plugin) => {
switch (plugin) {
case 'container':
this.mdc.use(markdownitContainer, 'success')
this.mdc.use(markdownitContainer, 'info')
this.mdc.use(markdownitContainer, 'warning')
this.mdc.use(markdownitContainer, 'danger')
break
case 'github-toc':
this.mdc.use(markdownItGithubToc, {
tocFirstLevel: 2,
tocLastLevel: 3,
tocClassName: 'toc',
anchorLinkSymbol: '',
anchorLinkSpace: false,
anchorClassName: 'anchor',
anchorLinkSymbolClassName: 'octicon octicon-link'
})
break
case 'emoji':
case 'font-awesome':
this.mdc.use(markdownitIcons, plugin)
break
default:
break
}
})
}
}
export default Engine