-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.js
131 lines (107 loc) · 2.87 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/* eslint-disable import/no-extraneous-dependencies */
import cliHtml from 'cli-html';
import markdownit from 'markdown-it';
import markdownItFootnote from 'markdown-it-footnote';
import markdownItIns from 'markdown-it-ins';
import markdownItMark from 'markdown-it-mark';
import markdownItDeflist from 'markdown-it-deflist';
import markdownItContainer from 'markdown-it-container';
import markdownItAbbr from 'markdown-it-abbr';
import markdownItSup from 'markdown-it-sup';
import markdownItSub from 'markdown-it-sub';
import markdownItTaskList from 'markdown-it-task-lists';
import { alert } from '@mdit/plugin-alert';
const md = markdownit({
html: true,
langPrefix: 'language-',
linkify: true,
})
.use(markdownItFootnote)
.use(markdownItIns)
.use(markdownItMark)
.use(markdownItDeflist)
.use(markdownItAbbr)
.use(markdownItContainer)
.use(markdownItSup)
.use(markdownItSub)
.use(markdownItTaskList)
.use(alert, {
deep: false,
openRender(tokens, index, options, environment, self) {
const token = tokens[index];
let color = null;
// Case token.markup in ['important', 'note', 'tip', 'warning', 'caution']
switch (token?.markup) {
case 'important': {
color = 'red';
break;
}
case 'note': {
color = 'blue';
break;
}
case 'tip': {
color = 'green';
break;
}
case 'warning': {
color = 'yellow';
break;
}
case 'caution': {
color = 'yellow light';
break;
}
default: {
color = 'blue';
}
}
return `<blockquote class="x-cli-color-${color}">`;
},
closeRender(tokens, index, options, environment, self) {
return '</blockquote>';
},
titleRender: (tokens, index) => {
const token = tokens[index];
// console.log(token)
let color = null;
let icon = null;
switch (token?.markup) {
case 'important': {
color = 'red';
icon = '•';
break;
}
case 'note': {
color = 'blue';
icon = '•';
break;
}
case 'tip': {
color = 'green';
icon = '•';
break;
}
case 'warning': {
color = 'yellow';
icon = '•';
break;
}
case 'caution': {
color = 'yellow light';
icon = '•';
break;
}
default: {
color = 'blue';
icon = '•';
}
}
return `<p><span class="x-cli-color-${color}"> ${
token.content[0].toUpperCase() + token.content.slice(1).toLowerCase()
}</span></p>\n`;
},
});
md.renderer.rules.footnote_anchor = () => '';
const markdownToCli = (markdown) => cliHtml(md.render(markdown));
export default markdownToCli;