-
-
Notifications
You must be signed in to change notification settings - Fork 877
/
index.js
140 lines (138 loc) · 4.01 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
132
133
134
135
136
137
138
139
140
import Vditor from '../src/index'
import '../src/assets/less/index.less'
// new VConsole()
let toolbar
if (window.innerWidth < 768) {
toolbar = [
'emoji',
'headings',
'bold',
'italic',
'strike',
'link',
'|',
'list',
'ordered-list',
'check',
'outdent',
'indent',
'|',
'quote',
'line',
'code',
'inline-code',
'insert-before',
'insert-after',
'|',
'upload',
'record',
'table',
'|',
'undo',
'redo',
'|',
'edit-mode',
'content-theme',
'code-theme',
'export',
{
name: 'more',
toolbar: [
'fullscreen',
'both',
'preview',
'info',
'help',
],
}]
}
const initVditor = (language) => {
window.vditor = new Vditor('vditor', {
// _lutePath: `http://192.168.31.194:9090/lute.min.js?${new Date().getTime()}`,
_lutePath: 'src/js/lute/lute.min.js',
cdn: '',
toolbar,
lang: language,
mode: 'wysiwyg',
height: window.innerHeight + 100,
outline: {
enable: true,
position: 'right',
},
debugger: true,
typewriterMode: true,
placeholder: 'Hello, Vditor!',
preview: {
markdown: {
toc: true,
mark: true,
footnotes: true,
autoSpace: true,
},
math: {
engine: 'KaTeX',
inlineDigit: true,
},
},
toolbarConfig: {
pin: true,
},
counter: {
enable: true,
type: 'text',
},
hint: {
emojiPath: 'https://cdn.jsdelivr.net/npm/[email protected]/dist/images/emoji',
emojiTail: '<a href="https://ld246.com/settings/function" target="_blank">设置常用表情</a>',
emoji: {
'sd': '💔',
'j': 'https://cdn.jsdelivr.net/npm/[email protected]/dist/images/emoji/j.png',
},
parse: false,
extend: [
{
key: '@',
hint: (key) => {
console.log(key)
if ('vanessa'.indexOf(key.toLocaleLowerCase()) > -1) {
return [
{
value: '@Vanessa',
html: '<img src="https://avatars0.githubusercontent.com/u/970828?s=60&v=4"/> Vanessa',
}]
}
return []
},
},
{
key: '#',
hint: (key) => {
console.log(key)
if ('vditor'.indexOf(key.toLocaleLowerCase()) > -1) {
return [
{
value: '#Vditor',
html: '<span style="color: #999;">#Vditor</span> ♏ 一款浏览器端的 Markdown 编辑器,支持所见即所得(富文本)、即时渲染(类似 Typora)和分屏预览模式。',
}]
}
return []
},
}],
},
tab: '\t',
upload: {
accept: 'image/*,.mp3, .wav, .rar',
token: 'test',
url: '/api/upload/editor',
linkToImgUrl: '/api/upload/fetch',
filename(name) {
return name.replace(/[^(a-zA-Z0-9\u4e00-\u9fa5\.)]/g, '').replace(/[\?\\/:|<>\*\[\]\(\)\$%\{\}@~]/g, '').replace('/\\s/g', '')
},
},
})
}
initVditor('zh_CN')
window.setLang = (language) => {
window.vditor.destroy()
initVditor(language)
}