md-editor-v3 1.11.12 → 2.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +530 -371
- package/package.json +132 -126
- package/lib/MdEditor/DropdownToolbar.d.ts +0 -42
- package/lib/MdEditor/Editor.d.ts +0 -428
- package/lib/MdEditor/NormalToolbar.d.ts +0 -30
- package/lib/MdEditor/index.d.ts +0 -941
- package/lib/MdEditor/layouts/Catalog/index.d.ts +0 -51
- package/lib/MdEditor/type.d.ts +0 -115
- package/lib/md-editor-v3.es.js +0 -5825
- package/lib/md-editor-v3.umd.js +0 -84
- package/lib/style.css +0 -1
package/README.md
CHANGED
|
@@ -1,371 +1,530 @@
|
|
|
1
|
-
# md-editor-v3
|
|
2
|
-
|
|
3
|
-
    
|
|
4
|
-
|
|
5
|
-
English \| [中文](https://github.com/imzbf/md-editor-v3/blob/dev/README-CN.md)
|
|
6
|
-
|
|
7
|
-
Markdown editor for vue3, developed in `jsx` and `typescript`.
|
|
8
|
-
|
|
9
|
-
- Documentation and example:[Go](https://imzbf.github.io/md-editor-v3)
|
|
10
|
-
|
|
11
|
-
- Use it online:[Go](https://codesandbox.io/s/epic-bird-2znqo)
|
|
12
|
-
|
|
13
|
-
- The same series editor for react:[md-editor-rt](https://github.com/imzbf/md-editor-rt)
|
|
14
|
-
|
|
15
|
-
## Features
|
|
16
|
-
|
|
17
|
-
- Toolbar, screenfull or screenfull in web pages and so on.
|
|
18
|
-
- Themes, Built-in default and dark themes.
|
|
19
|
-
- Shortcut key for editor.
|
|
20
|
-
- Beautify your content by `prettier`(only for markdown content, not the code and other text).
|
|
21
|
-
- Multi-language, build-in Chinese and English(default: Chinese).
|
|
22
|
-
- Upload picture, paste or clip the picture and upload it.
|
|
23
|
-
- Render article directly(no editor, no event listener, only preview content).
|
|
24
|
-
- Preview themes,
|
|
25
|
-
- `mermaid`(>=1.8.0).
|
|
26
|
-
-
|
|
27
|
-
|
|
28
|
-
## Preview
|
|
29
|
-
|
|
30
|
-
| Default theme | Dark theme | Preview only |
|
|
31
|
-
| --- | --- | --- |
|
|
32
|
-
|  |  |  |
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
|
43
|
-
|
|
|
44
|
-
|
|
|
45
|
-
|
|
|
46
|
-
|
|
|
47
|
-
|
|
|
48
|
-
|
|
|
49
|
-
|
|
|
50
|
-
|
|
|
51
|
-
|
|
|
52
|
-
|
|
|
53
|
-
| toolbars | Array | [toolbars] | Show some item of toolbars, all keys<sup>see `toolbars` below</sup> |
|
|
54
|
-
| toolbarsExclude | Array | [] | Don't show some item of toolbars, all keys`toolbars` |
|
|
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
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
//
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
};
|
|
199
|
-
// 1.
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
|
245
|
-
|
|
|
246
|
-
|
|
|
247
|
-
|
|
|
248
|
-
|
|
|
249
|
-
|
|
|
250
|
-
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
- `
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
<
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
};
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
1
|
+
# md-editor-v3
|
|
2
|
+
|
|
3
|
+
    
|
|
4
|
+
|
|
5
|
+
English \| [中文](https://github.com/imzbf/md-editor-v3/blob/dev/README-CN.md)
|
|
6
|
+
|
|
7
|
+
Markdown editor for vue3, developed in `jsx` and `typescript`.
|
|
8
|
+
|
|
9
|
+
- Documentation and example:[Go](https://imzbf.github.io/md-editor-v3)
|
|
10
|
+
|
|
11
|
+
- Use it online:[Go](https://codesandbox.io/s/epic-bird-2znqo)
|
|
12
|
+
|
|
13
|
+
- The same series editor for react:[md-editor-rt](https://github.com/imzbf/md-editor-rt)
|
|
14
|
+
|
|
15
|
+
## Features
|
|
16
|
+
|
|
17
|
+
- Toolbar, screenfull or screenfull in web pages and so on.
|
|
18
|
+
- Themes, Built-in default and dark themes.
|
|
19
|
+
- Shortcut key for editor.
|
|
20
|
+
- Beautify your content by `prettier`(only for markdown content, not the code and other text).
|
|
21
|
+
- Multi-language, build-in Chinese and English(default: Chinese).
|
|
22
|
+
- Upload picture, paste or clip the picture and upload it.
|
|
23
|
+
- Render article directly(no editor, no event listener, only preview content).
|
|
24
|
+
- Preview themes, `defalut`, `vuepress`, `github`, `cyanosis`, `mk-cute`, `smart-blue` styles(not identical). It can be customized also(Get the demo page).
|
|
25
|
+
- `mermaid`(>=1.8.0), `katex` mathematical formula(>=1.9.0).
|
|
26
|
+
- Customize the toolbar as you like.
|
|
27
|
+
|
|
28
|
+
## Preview
|
|
29
|
+
|
|
30
|
+
| Default theme | Dark theme | Preview only |
|
|
31
|
+
| --- | --- | --- |
|
|
32
|
+
|  |  |  |
|
|
33
|
+
|
|
34
|
+
mark and emoji extensions
|
|
35
|
+
|
|
36
|
+

|
|
37
|
+
|
|
38
|
+
## Apis
|
|
39
|
+
|
|
40
|
+
### Props
|
|
41
|
+
|
|
42
|
+
| name | type | default | description |
|
|
43
|
+
| --- | --- | --- | --- |
|
|
44
|
+
| modelValue | string | '' | Markdown content, use `v-model` in vue template |
|
|
45
|
+
| theme | 'light' \| 'dark' | 'light' | Editor theme |
|
|
46
|
+
| class | string | '' | |
|
|
47
|
+
| historyLength | number | 10 | The max length of history(if it is too big, editor will use more `RAM`) |
|
|
48
|
+
| pageFullScreen | boolean | false | Screenfull in web page |
|
|
49
|
+
| preview | boolean | true | Preview content in editor |
|
|
50
|
+
| htmlPreview | boolean | false | Preview html in editor |
|
|
51
|
+
| previewOnly | boolean | false | Only render article content, no toolbar, no edit area |
|
|
52
|
+
| language | string | 'zh-CN' | Build-in language('zh-CN','en-US') |
|
|
53
|
+
| toolbars | Array | [toolbars] | Show some item of toolbars, all keys<sup>see `toolbars` below</sup> |
|
|
54
|
+
| toolbarsExclude | Array | [] | Don't show some item of toolbars, all keys`toolbars` |
|
|
55
|
+
| noPrettier | boolean | false | Use prettier to beautify content or not |
|
|
56
|
+
| editorId | string | md-editor-v3 | Editor id, it is used when there are more than two editors in the same page. |
|
|
57
|
+
| tabWidth | number | 2 | One tab eq some spaces |
|
|
58
|
+
| showCodeRowNumber | boolean | false | Show row number for code block or not |
|
|
59
|
+
| previewTheme | 'default' \| 'github' \| 'vuepress' \| 'mk-cute' \| 'smart-blue' \| 'cyanosis' | 'default' | Preview theme, can be customized |
|
|
60
|
+
| style | string \| CSSProperties | {} | Editor inline style |
|
|
61
|
+
| tableShape | [number, number] | [6, 4] | Preset the size of the table, [columns, rows] |
|
|
62
|
+
| noMermaid | boolean | false | Use mermaid or not |
|
|
63
|
+
| placeholder | string | '' | |
|
|
64
|
+
| noKatex | boolean | false | Use katex or not |
|
|
65
|
+
| codeCssName | 'atom' \| 'a11y' \| 'github' \| 'gradient' \| 'kimbie' \| 'paraiso' \| 'qtcreator' \| 'stackoverflow' | 'atom' | [Highlight](https://www.jsdelivr.com/package/npm/highlight.js?path=styles) code style, can be customized also |
|
|
66
|
+
| markedHeadingId | (text: string, level: number) => string | (text) => text | H1-H6 `ID` generator |
|
|
67
|
+
| sanitize | (html: string) => string | (html) => html | Sanitize the html, prevent XSS |
|
|
68
|
+
|
|
69
|
+
<details>
|
|
70
|
+
<summary>[toolbars]</summary>
|
|
71
|
+
|
|
72
|
+
```js
|
|
73
|
+
[
|
|
74
|
+
'bold',
|
|
75
|
+
'underline',
|
|
76
|
+
'italic',
|
|
77
|
+
'-',
|
|
78
|
+
'strikeThrough',
|
|
79
|
+
'title',
|
|
80
|
+
'sub',
|
|
81
|
+
'sup',
|
|
82
|
+
'quote',
|
|
83
|
+
'unorderedList',
|
|
84
|
+
'orderedList',
|
|
85
|
+
'-',
|
|
86
|
+
'codeRow',
|
|
87
|
+
'code',
|
|
88
|
+
'link',
|
|
89
|
+
'image',
|
|
90
|
+
'table',
|
|
91
|
+
'mermaid',
|
|
92
|
+
'katex',
|
|
93
|
+
'-',
|
|
94
|
+
'revoke',
|
|
95
|
+
'next',
|
|
96
|
+
'save',
|
|
97
|
+
'=',
|
|
98
|
+
'pageFullscreen',
|
|
99
|
+
'fullscreen',
|
|
100
|
+
'preview',
|
|
101
|
+
'htmlPreview',
|
|
102
|
+
'catalog',
|
|
103
|
+
'github'
|
|
104
|
+
];
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
</details>
|
|
108
|
+
|
|
109
|
+
> After v1.6.0, You can sort the toolbar as you like, split tools by `'-'`, the left and right toolbars are divided by `'='`!
|
|
110
|
+
|
|
111
|
+
> After v1.10.0, you can customize the toolbar. To display them, put index of `defToolbars` into `toolbars`(this is not standard), for more usage, please refer to[docs]().
|
|
112
|
+
|
|
113
|
+
<details>
|
|
114
|
+
<summary>[StaticTextDefaultValue]</summary>
|
|
115
|
+
|
|
116
|
+
Expand language, you need to replace all the content here:
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
export interface ToolbarTips {
|
|
120
|
+
bold?: string;
|
|
121
|
+
underline?: string;
|
|
122
|
+
italic?: string;
|
|
123
|
+
strikeThrough?: string;
|
|
124
|
+
title?: string;
|
|
125
|
+
sub?: string;
|
|
126
|
+
sup?: string;
|
|
127
|
+
quote?: string;
|
|
128
|
+
unorderedList?: string;
|
|
129
|
+
orderedList?: string;
|
|
130
|
+
codeRow?: string;
|
|
131
|
+
code?: string;
|
|
132
|
+
link?: string;
|
|
133
|
+
image?: string;
|
|
134
|
+
table?: string;
|
|
135
|
+
mermaid?: string;
|
|
136
|
+
katex?: string;
|
|
137
|
+
revoke?: string;
|
|
138
|
+
next?: string;
|
|
139
|
+
save?: string;
|
|
140
|
+
prettier?: string;
|
|
141
|
+
pageFullscreen?: string;
|
|
142
|
+
fullscreen?: string;
|
|
143
|
+
catalog?: string;
|
|
144
|
+
preview?: string;
|
|
145
|
+
htmlPreview?: string;
|
|
146
|
+
github?: string;
|
|
147
|
+
'-'?: string;
|
|
148
|
+
'='?: string;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export interface StaticTextDefaultValue {
|
|
152
|
+
// Toolbar hover tips(html title)
|
|
153
|
+
toolbarTips?: ToolbarTips;
|
|
154
|
+
// h1-h6 dropdown menu item
|
|
155
|
+
titleItem?: {
|
|
156
|
+
h1?: string;
|
|
157
|
+
h2?: string;
|
|
158
|
+
h3?: string;
|
|
159
|
+
h4?: string;
|
|
160
|
+
h5?: string;
|
|
161
|
+
h6?: string;
|
|
162
|
+
};
|
|
163
|
+
// v1.6.0
|
|
164
|
+
imgTitleItem?: {
|
|
165
|
+
link: string;
|
|
166
|
+
upload: string;
|
|
167
|
+
clip2upload: string;
|
|
168
|
+
};
|
|
169
|
+
// The modal tips of add link or upload picture
|
|
170
|
+
linkModalTips?: {
|
|
171
|
+
title?: string;
|
|
172
|
+
descLable?: string;
|
|
173
|
+
descLablePlaceHolder?: string;
|
|
174
|
+
urlLable?: string;
|
|
175
|
+
UrlLablePlaceHolder?: string;
|
|
176
|
+
buttonOK?: string;
|
|
177
|
+
};
|
|
178
|
+
// The modal tips of clip the picture, v1.2.0
|
|
179
|
+
clipModalTips?: {
|
|
180
|
+
title?: string;
|
|
181
|
+
buttonUpload?: string;
|
|
182
|
+
};
|
|
183
|
+
// Copy code tips, v1.1.4
|
|
184
|
+
copyCode?: {
|
|
185
|
+
text?: string;
|
|
186
|
+
tips?: string;
|
|
187
|
+
};
|
|
188
|
+
// 1.8.0
|
|
189
|
+
mermaid?: {
|
|
190
|
+
flow?: string;
|
|
191
|
+
sequence?: string;
|
|
192
|
+
gantt?: string;
|
|
193
|
+
class?: string;
|
|
194
|
+
state?: string;
|
|
195
|
+
pie?: string;
|
|
196
|
+
relationship?: string;
|
|
197
|
+
journey?: string;
|
|
198
|
+
};
|
|
199
|
+
// 1.9.0
|
|
200
|
+
katex?: {
|
|
201
|
+
// formula inline
|
|
202
|
+
inline: string;
|
|
203
|
+
// formula block
|
|
204
|
+
block: string;
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
</details>
|
|
210
|
+
|
|
211
|
+
### Slots
|
|
212
|
+
|
|
213
|
+
| name | type | default | description |
|
|
214
|
+
| --- | --- | --- | --- |
|
|
215
|
+
| defToolbars | Array<DropdownToolbar \| NormalToolbar \| ModalToolbar> | null | Customize Toolbar, for more usage, please refer to [docs](https://imzbf.github.io/md-editor-v3/docs/index#%F0%9F%92%AA%20defToolbars) and [emoji](https://imzbf.github.io/md-editor-v3/demo/index#💪%20Customize%20Toolbar) |
|
|
216
|
+
|
|
217
|
+
`NormalToolbar` component example:
|
|
218
|
+
|
|
219
|
+
```js
|
|
220
|
+
<template>
|
|
221
|
+
<md-editor>
|
|
222
|
+
<template #defToolbars>
|
|
223
|
+
<normal-toolbar title="mark" @click="handler">
|
|
224
|
+
<template #trigger>
|
|
225
|
+
<svg class="md-icon" aria-hidden="true">
|
|
226
|
+
<use xlink:href="#icon-mark"></use>
|
|
227
|
+
</svg>
|
|
228
|
+
</template>
|
|
229
|
+
</normal-toolbar>
|
|
230
|
+
</template>
|
|
231
|
+
</md-editor>
|
|
232
|
+
</template>
|
|
233
|
+
<script setup>
|
|
234
|
+
import MdEditor from 'md-editor-v3';
|
|
235
|
+
|
|
236
|
+
const NormalToolbar = MdEditor.NormalToolbar;
|
|
237
|
+
|
|
238
|
+
const handler = () => { console.log('NormalToolbar clicked!') }
|
|
239
|
+
</script>
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### Events
|
|
243
|
+
|
|
244
|
+
| name | param | description |
|
|
245
|
+
| --- | --- | --- |
|
|
246
|
+
| onChange | v:string | Content changed event(bind to `oninput` of `textarea`) |
|
|
247
|
+
| onSave | v:string | Save content event, `ctrl+s`and click button will be triggered also |
|
|
248
|
+
| onUploadImg | files:Array<File>, callback:Function | Upload picture event, when picture is uploading the modal will not close, please provide right urls to the callback function |
|
|
249
|
+
| onHtmlChanged | h:string | Compile markdown successful event, you can use it to get the html code |
|
|
250
|
+
| onGetCatalog | list: HeadList[] | Get catalogue of article |
|
|
251
|
+
|
|
252
|
+
## Config
|
|
253
|
+
|
|
254
|
+
Use `MdEditor.config(option: ConfigOption)` to reconfigure `renderer`.
|
|
255
|
+
|
|
256
|
+
- markedRenderer: `(renderer: Renderer) => Renderer`, 🌰(Open target page in a new browser window):
|
|
257
|
+
|
|
258
|
+
```js
|
|
259
|
+
MdEditor.config({
|
|
260
|
+
markedRenderer(renderer) {
|
|
261
|
+
renderer.link = (href, title, text) => {
|
|
262
|
+
return `<a href="${href}" title="${title}" target="_blank">${text}</a>`;
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
return renderer;
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
> Reference: https://marked.js.org/using_pro#renderer
|
|
271
|
+
|
|
272
|
+
- markedExtensions: `Array<marked.TokenizerExtension & marked.RendererExtension>`
|
|
273
|
+
|
|
274
|
+
```js
|
|
275
|
+
import MdEditor from 'md-editor-v3';
|
|
276
|
+
|
|
277
|
+
MdEditor.config({
|
|
278
|
+
markedExtensions: [your extension]
|
|
279
|
+
});
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
> Reference: https://marked.js.org/using_pro#extensions
|
|
283
|
+
|
|
284
|
+
- markedOptions: `marked.MarkedOptions`, 🌰(do not render `<br>` on a single line break):
|
|
285
|
+
|
|
286
|
+
```js
|
|
287
|
+
import MdEditor from 'md-editor-v3';
|
|
288
|
+
|
|
289
|
+
MdEditor.config({
|
|
290
|
+
markedOptions: { breaks: false }
|
|
291
|
+
});
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
> Reference: https://marked.js.org/using_advanced#options
|
|
295
|
+
|
|
296
|
+
- editorConfig: Add more languages,reset `mermaid` template:
|
|
297
|
+
|
|
298
|
+
```js
|
|
299
|
+
import MdEditor from 'md-editor-v3';
|
|
300
|
+
|
|
301
|
+
MdEditor.config({
|
|
302
|
+
markedOptions: {
|
|
303
|
+
languageUserDefined: { 'lang': StaticTextDefaultValue };
|
|
304
|
+
mermaidTemplate: {
|
|
305
|
+
flow: `flow tempalte`;
|
|
306
|
+
...more
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
- editorExtensions: Config some dependency libraries, like highlight..
|
|
313
|
+
|
|
314
|
+
```typescript
|
|
315
|
+
import MdEditor from 'md-editor-v3';
|
|
316
|
+
|
|
317
|
+
MdEditor.config({
|
|
318
|
+
editorExtensions: { iconfont: 'https://xxx.cc' }
|
|
319
|
+
});
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
<details>
|
|
323
|
+
<summary>[EditorExtensions]</summary>
|
|
324
|
+
|
|
325
|
+
```ts
|
|
326
|
+
import MdEditor from 'md-editor-v3';
|
|
327
|
+
|
|
328
|
+
interface EditorExtensions {
|
|
329
|
+
highlight?: {
|
|
330
|
+
instance?: any;
|
|
331
|
+
js?: string;
|
|
332
|
+
css?: {
|
|
333
|
+
[key: string]: {
|
|
334
|
+
light: string;
|
|
335
|
+
dark: string;
|
|
336
|
+
};
|
|
337
|
+
};
|
|
338
|
+
};
|
|
339
|
+
prettier?: {
|
|
340
|
+
standaloneJs?: string;
|
|
341
|
+
parserMarkdownJs?: string;
|
|
342
|
+
};
|
|
343
|
+
cropper?: {
|
|
344
|
+
instance?: any;
|
|
345
|
+
js?: string;
|
|
346
|
+
css?: string;
|
|
347
|
+
};
|
|
348
|
+
iconfont?: string;
|
|
349
|
+
screenfull?: {
|
|
350
|
+
instance?: any;
|
|
351
|
+
js?: string;
|
|
352
|
+
};
|
|
353
|
+
mermaid?: {
|
|
354
|
+
instance?: any;
|
|
355
|
+
js?: string;
|
|
356
|
+
};
|
|
357
|
+
katex?: {
|
|
358
|
+
instance?: any;
|
|
359
|
+
js?: string;
|
|
360
|
+
css?: string;
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
</details>
|
|
366
|
+
|
|
367
|
+
## Shortcut key
|
|
368
|
+
|
|
369
|
+
| key | function | description |
|
|
370
|
+
| --- | --- | --- |
|
|
371
|
+
| TAB | insert space | Insert space, the length eq `tabWidth`, default: 2, support multiline |
|
|
372
|
+
| SHIFT + TAB | delete space, setting is the same as Tab | |
|
|
373
|
+
| CTRL + C | copy | When selected, copy the selected content. When not selected, copy the content of the current line |
|
|
374
|
+
| CTRL + X | shear | When selected, cut the selected content. When not selected, cut the current line |
|
|
375
|
+
| CTRL + D | delete | When selected, delete the selected content. When not selected, delete the current line |
|
|
376
|
+
| CTRL + S | save | Trigger `onSave` event |
|
|
377
|
+
| CTRL + B | bold text | `**bold**` |
|
|
378
|
+
| CTRL + U | underline | `<u>underline</u>` |
|
|
379
|
+
| CTRL + I | italic | `*italic*` |
|
|
380
|
+
| CTRL + 1-6 | h1-h6 | `# title` |
|
|
381
|
+
| CTRL + ↑ | superscript | `<sup>superscript</sup>` |
|
|
382
|
+
| CTRL + ↓ | subscript | `<sub>subscript</sub>` |
|
|
383
|
+
| CTRL + Q | quote | `> quote` |
|
|
384
|
+
| CTRL + O | ordered list | `1. ordered list` |
|
|
385
|
+
| CTRL + L | link | `[link](https://github.com/imzbf/md-editor-v3)` |
|
|
386
|
+
| CTRL + Z | withdraw | Withdraw history in editor, not the function of system |
|
|
387
|
+
| CTRL + SHIFT + S | line-through | `~line-through~` |
|
|
388
|
+
| CTRL + SHIFT + U | unordered list | `- unordered list` |
|
|
389
|
+
| CTRL + SHIFT + C | code block | |
|
|
390
|
+
| CTRL + SHIFT + I | picture | `` |
|
|
391
|
+
| CTRL + SHIFT + Z | forward | Forward history in editor, not the function of system |
|
|
392
|
+
| CTRL + SHIFT + F | Beautify | |
|
|
393
|
+
| CTRL + ALT + C | code row | |
|
|
394
|
+
| CTRL + SHIFT + ALT + T | table | `\|table\|` |
|
|
395
|
+
|
|
396
|
+
## Components
|
|
397
|
+
|
|
398
|
+
They are used as attributes of the editor component, eg: `Editor.DropdownToolbar`. For more examples, refer to [document](https://imzbf.github.io/md-editor-v3).
|
|
399
|
+
|
|
400
|
+
### NormalToolbar
|
|
401
|
+
|
|
402
|
+
`Editor.NormalToolbar`
|
|
403
|
+
|
|
404
|
+
- **props**
|
|
405
|
+
|
|
406
|
+
- `title`: `string`, not necessary, title of toolbar.
|
|
407
|
+
|
|
408
|
+
- **events**
|
|
409
|
+
|
|
410
|
+
- `onClick`: `(e: MouseEvent) => void`, necessary.
|
|
411
|
+
|
|
412
|
+
- **slots**
|
|
413
|
+
- `trigger`: `string | JSX.Element`, necessary, it is usually an icon, which is displayed on the toolbar.
|
|
414
|
+
|
|
415
|
+
### DropdownToolbar
|
|
416
|
+
|
|
417
|
+
`Editor.DropdownToolbar`
|
|
418
|
+
|
|
419
|
+
- **props**
|
|
420
|
+
|
|
421
|
+
- `title`: `string`, not necessary, title of toolbar.
|
|
422
|
+
- `visible`: `boolean`, necessary.
|
|
423
|
+
|
|
424
|
+
- **events**
|
|
425
|
+
|
|
426
|
+
- `onChange`: `(visible: boolean) => void`, necessary.
|
|
427
|
+
|
|
428
|
+
- **slots**
|
|
429
|
+
- `trigger`: `string | JSX.Element`, necessary, it is usually an icon, which is displayed on the toolbar.
|
|
430
|
+
- `overlay`: `string | JSX.Element`, necessary, content of dropdown box.
|
|
431
|
+
|
|
432
|
+
### ModalToolbar
|
|
433
|
+
|
|
434
|
+
`Editor.ModalToolbar`
|
|
435
|
+
|
|
436
|
+
- **props**
|
|
437
|
+
|
|
438
|
+
- `title`: `string`, not necessary, title of toolbar.
|
|
439
|
+
- `modalTitle`: `string`, not necessary, title of the Modal.
|
|
440
|
+
- `visible`: `boolean`, necessary, visibility of Modal.
|
|
441
|
+
- `width`: `string`, not necessary, width of Modal, default `auto`.
|
|
442
|
+
- `height`:`string`, same as `width`.
|
|
443
|
+
- `showAdjust`: `boolean`, not necessary, visibility of fullscreen button.
|
|
444
|
+
- `isFullscreen`: `boolean`, necessary when `showAdjust = true`, status of fullscreen.
|
|
445
|
+
|
|
446
|
+
- **events**
|
|
447
|
+
|
|
448
|
+
- `onClick`: `() => void`, necessary.
|
|
449
|
+
- `onClose`:`() => void`, necessary, close event.
|
|
450
|
+
- `onAdjust`:`(val: boolean) => void`, fullscreen button click event.
|
|
451
|
+
|
|
452
|
+
- **slots**
|
|
453
|
+
- `trigger`: `string | JSX.Element`, necessary, it is usually an icon, which is displayed on the toolbar.
|
|
454
|
+
- `overlay`: `string | JSX.Element`, necessary, content of Modal.
|
|
455
|
+
|
|
456
|
+
### Catalogue
|
|
457
|
+
|
|
458
|
+
`Editor.Catalog`
|
|
459
|
+
|
|
460
|
+
- **props**
|
|
461
|
+
- `editorId`: `string`, necessary, same as editor's `editorId`, used to register listening events.
|
|
462
|
+
- `class`: `string`, not necessary.
|
|
463
|
+
- `markedHeadingId`: `MarkedHeadingId`, not necessary, same as editor.
|
|
464
|
+
- `scrollElement`: `string | HTMLElement`, not necessary, it is an element selector when its type is string. When `previewOnly` eq `true`, it is usually set to `document.documentElement`.
|
|
465
|
+
- `theme`: `'light' | 'dark'`, not necessary, provide it when you want to change theme online, it is the same as Editor `theme`.
|
|
466
|
+
|
|
467
|
+
## Examples
|
|
468
|
+
|
|
469
|
+
### Jsx module
|
|
470
|
+
|
|
471
|
+
```js
|
|
472
|
+
import { defineComponent, reactive } from 'vue';
|
|
473
|
+
import MdEditor from 'md-editor-v3';
|
|
474
|
+
import 'md-editor-v3/lib/style.css';
|
|
475
|
+
|
|
476
|
+
export default defineComponent({
|
|
477
|
+
setup() {
|
|
478
|
+
const md = reactive({
|
|
479
|
+
text: '# Hello Editor'
|
|
480
|
+
});
|
|
481
|
+
return () => (
|
|
482
|
+
<MdEditor modelValue={md.text} onChange={(value) => (md.text = value)} />
|
|
483
|
+
);
|
|
484
|
+
}
|
|
485
|
+
});
|
|
486
|
+
```
|
|
487
|
+
|
|
488
|
+
### Vue template
|
|
489
|
+
|
|
490
|
+
```js
|
|
491
|
+
<template>
|
|
492
|
+
<md-editor v-model="text" pageFullScreen></md-editor>
|
|
493
|
+
</template>
|
|
494
|
+
|
|
495
|
+
<script setup>
|
|
496
|
+
import { ref } from 'vue';
|
|
497
|
+
import MdEditor from 'md-editor-v3';
|
|
498
|
+
import 'md-editor-v3/lib/style.css';
|
|
499
|
+
|
|
500
|
+
const text = ref('# Hello Editor')
|
|
501
|
+
</script>
|
|
502
|
+
```
|
|
503
|
+
|
|
504
|
+
### Upload picture
|
|
505
|
+
|
|
506
|
+
> Tips:When you paste and upload GIF, it will upload a static picture. So you should upload it by file system!
|
|
507
|
+
|
|
508
|
+
```js
|
|
509
|
+
async onUploadImg(files: Array<File>, callback: (urls: string[]) => void) {
|
|
510
|
+
const res = await Promise.all(
|
|
511
|
+
files.map((file) => {
|
|
512
|
+
return new Promise((rev, rej) => {
|
|
513
|
+
const form = new FormData();
|
|
514
|
+
form.append('file', file);
|
|
515
|
+
|
|
516
|
+
axios
|
|
517
|
+
.post('/api/img/upload', form, {
|
|
518
|
+
headers: {
|
|
519
|
+
'Content-Type': 'multipart/form-data'
|
|
520
|
+
}
|
|
521
|
+
})
|
|
522
|
+
.then((res) => rev(res))
|
|
523
|
+
.catch((error) => rej(error));
|
|
524
|
+
});
|
|
525
|
+
})
|
|
526
|
+
);
|
|
527
|
+
|
|
528
|
+
callback(res.map((item: any) => item.data.url));
|
|
529
|
+
}
|
|
530
|
+
```
|