md-editor-v3 2.0.0-beta.1 → 2.0.0-beta.10

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/README.md CHANGED
@@ -1,530 +1,551 @@
1
- # md-editor-v3
2
-
3
- ![](https://img.shields.io/github/package-json/v/imzbf/md-editor-v3) ![](https://img.shields.io/npm/dm/md-editor-v3) ![](https://img.shields.io/bundlephobia/min/md-editor-v3) ![](https://img.shields.io/github/license/imzbf/md-editor-v3) ![](https://img.shields.io/badge/ssr-%3E1.6.0-brightgreen)
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
- | ![](https://imzbf.github.io/md-editor-v3/imgs/preview-light.png) | ![](https://imzbf.github.io/md-editor-v3/imgs/preview-dark.png) | ![](https://imzbf.github.io/md-editor-v3/imgs/preview-previewOnly.png) |
33
-
34
- mark and emoji extensions
35
-
36
- ![mark and emoji extension](https://imzbf.github.io/md-editor-v3/imgs/mark_emoji.gif)
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 | `![picture](https://imbf.cc)` |
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
- ```
1
+ # md-editor-v3
2
+
3
+ ![](https://img.shields.io/github/package-json/v/imzbf/md-editor-v3) ![](https://img.shields.io/npm/dm/md-editor-v3) ![](https://img.shields.io/bundlephobia/min/md-editor-v3) ![](https://img.shields.io/github/license/imzbf/md-editor-v3) ![](https://img.shields.io/badge/ssr-%3E1.6.0-brightgreen)
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
+ | ![](https://imzbf.github.io/md-editor-v3/imgs/preview-light.png) | ![](https://imzbf.github.io/md-editor-v3/imgs/preview-dark.png) | ![](https://imzbf.github.io/md-editor-v3/imgs/preview-previewOnly.png) |
33
+
34
+ mark and emoji extensions
35
+
36
+ ![mark and emoji extension](https://imzbf.github.io/md-editor-v3/imgs/mark_emoji.gif)
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
+ | codeTheme | '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](https://imzbf.github.io/md-editor-v3/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
+ successTips?: string;
187
+ failTips?: string;
188
+ };
189
+ // 1.8.0
190
+ mermaid?: {
191
+ flow?: string;
192
+ sequence?: string;
193
+ gantt?: string;
194
+ class?: string;
195
+ state?: string;
196
+ pie?: string;
197
+ relationship?: string;
198
+ journey?: string;
199
+ };
200
+ // 1.9.0
201
+ katex?: {
202
+ // formula inline
203
+ inline: string;
204
+ // formula block
205
+ block: string;
206
+ };
207
+ }
208
+ ```
209
+
210
+ </details>
211
+
212
+ ### Slots
213
+
214
+ | name | type | default | description |
215
+ | --- | --- | --- | --- |
216
+ | 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) |
217
+
218
+ `NormalToolbar` component example:
219
+
220
+ ```vue
221
+ <template>
222
+ <md-editor>
223
+ <template #defToolbars>
224
+ <normal-toolbar title="mark" @click="handler">
225
+ <template #trigger>
226
+ <svg class="md-icon" aria-hidden="true">
227
+ <use xlink:href="#icon-mark"></use>
228
+ </svg>
229
+ </template>
230
+ </normal-toolbar>
231
+ </template>
232
+ </md-editor>
233
+ </template>
234
+
235
+ <script setup>
236
+ import MdEditor from 'md-editor-v3';
237
+
238
+ const NormalToolbar = MdEditor.NormalToolbar;
239
+
240
+ const handler = () => {
241
+ console.log('NormalToolbar clicked!');
242
+ };
243
+ </script>
244
+ ```
245
+
246
+ ### Events
247
+
248
+ | name | param | description |
249
+ | --- | --- | --- |
250
+ | onChange | v:string | Content changed event(bind to `oninput` of `textarea`) |
251
+ | onSave | v:string | Save content event, `ctrl+s`and click button will be triggered also |
252
+ | 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 |
253
+ | onHtmlChanged | h:string | Compile markdown successful event, you can use it to get the html code |
254
+ | onGetCatalog | list: HeadList[] | Get catalog of article |
255
+ | onError | err: { name: string; message: string } | Catch run-time error, `Cropper`,`fullScreen` and `prettier` are used when they are not loaded |
256
+
257
+ ## Config
258
+
259
+ Use `MdEditor.config(option: ConfigOption)` to reconfigure `renderer`.
260
+
261
+ - markedRenderer: `(renderer: Renderer) => Renderer`, 🌰(Open target page in a new browser window):
262
+
263
+ ```js
264
+ MdEditor.config({
265
+ markedRenderer(renderer) {
266
+ renderer.link = (href, title, text) => {
267
+ return `<a href="${href}" title="${title}" target="_blank">${text}</a>`;
268
+ };
269
+
270
+ return renderer;
271
+ }
272
+ });
273
+ ```
274
+
275
+ > Reference: https://marked.js.org/using_pro#renderer
276
+
277
+ - markedExtensions: `Array<marked.TokenizerExtension & marked.RendererExtension>`
278
+
279
+ ```js
280
+ import MdEditor from 'md-editor-v3';
281
+
282
+ MdEditor.config({
283
+ markedExtensions: [your extension]
284
+ });
285
+ ```
286
+
287
+ > Reference: https://marked.js.org/using_pro#extensions
288
+
289
+ - markedOptions: `marked.MarkedOptions`, 🌰(do not render `<br>` on a single line break):
290
+
291
+ ```js
292
+ import MdEditor from 'md-editor-v3';
293
+
294
+ MdEditor.config({
295
+ markedOptions: { breaks: false }
296
+ });
297
+ ```
298
+
299
+ > Reference: https://marked.js.org/using_advanced#options
300
+
301
+ - editorConfig: Add more languages,reset `mermaid` template:
302
+
303
+ ```js
304
+ import MdEditor from 'md-editor-v3';
305
+
306
+ MdEditor.config({
307
+ editorConfig: {
308
+ languageUserDefined: { lang: StaticTextDefaultValue },
309
+ mermaidTemplate: {
310
+ flow: `flow tempalte`,
311
+ ...more
312
+ },
313
+ // ms
314
+ renderDelay: 500
315
+ }
316
+ });
317
+ ```
318
+
319
+ - editorExtensions: Config some dependency libraries, like highlight..
320
+
321
+ ```typescript
322
+ import MdEditor from 'md-editor-v3';
323
+
324
+ MdEditor.config({
325
+ editorExtensions: { iconfont: 'https://xxx.cc' }
326
+ });
327
+ ```
328
+
329
+ <details>
330
+ <summary>[EditorExtensions]</summary>
331
+
332
+ ```ts
333
+ import MdEditor from 'md-editor-v3';
334
+
335
+ interface EditorExtensions {
336
+ highlight?: {
337
+ instance?: any;
338
+ js?: string;
339
+ css?: {
340
+ [key: string]: {
341
+ light: string;
342
+ dark: string;
343
+ };
344
+ };
345
+ };
346
+ prettier?: {
347
+ standaloneJs?: string;
348
+ parserMarkdownJs?: string;
349
+ };
350
+ cropper?: {
351
+ instance?: any;
352
+ js?: string;
353
+ css?: string;
354
+ };
355
+ iconfont?: string;
356
+ screenfull?: {
357
+ instance?: any;
358
+ js?: string;
359
+ };
360
+ mermaid?: {
361
+ instance?: any;
362
+ js?: string;
363
+ };
364
+ katex?: {
365
+ instance?: any;
366
+ js?: string;
367
+ css?: string;
368
+ };
369
+ }
370
+ ```
371
+
372
+ </details>
373
+
374
+ ## Shortcut key
375
+
376
+ | key | function | description |
377
+ | --- | --- | --- |
378
+ | TAB | insert space | Insert space, the length eq `tabWidth`, default: 2, support multiline |
379
+ | SHIFT + TAB | delete space, setting is the same as Tab | |
380
+ | CTRL + C | copy | When selected, copy the selected content. When not selected, copy the content of the current line |
381
+ | CTRL + X | shear | When selected, cut the selected content. When not selected, cut the current line |
382
+ | CTRL + D | delete | When selected, delete the selected content. When not selected, delete the current line |
383
+ | CTRL + S | save | Trigger `onSave` event |
384
+ | CTRL + B | bold text | `**bold**` |
385
+ | CTRL + U | underline | `<u>underline</u>` |
386
+ | CTRL + I | italic | `*italic*` |
387
+ | CTRL + 1-6 | h1-h6 | `# title` |
388
+ | CTRL + ↑ | superscript | `<sup>superscript</sup>` |
389
+ | CTRL + ↓ | subscript | `<sub>subscript</sub>` |
390
+ | CTRL + Q | quote | `> quote` |
391
+ | CTRL + O | ordered list | `1. ordered list` |
392
+ | CTRL + L | link | `[link](https://github.com/imzbf/md-editor-v3)` |
393
+ | CTRL + Z | withdraw | Withdraw history in editor, not the function of system |
394
+ | CTRL + SHIFT + S | line-through | `~line-through~` |
395
+ | CTRL + SHIFT + U | unordered list | `- unordered list` |
396
+ | CTRL + SHIFT + C | code block | |
397
+ | CTRL + SHIFT + I | picture | `![picture](https://imbf.cc)` |
398
+ | CTRL + SHIFT + Z | forward | Forward history in editor, not the function of system |
399
+ | CTRL + SHIFT + F | Beautify | |
400
+ | CTRL + ALT + C | code row | |
401
+ | CTRL + SHIFT + ALT + T | table | `\|table\|` |
402
+
403
+ ## Components
404
+
405
+ 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).
406
+
407
+ ### NormalToolbar
408
+
409
+ `Editor.NormalToolbar`
410
+
411
+ - **props**
412
+
413
+ - `title`: `string`, not necessary, title of toolbar.
414
+
415
+ - **events**
416
+
417
+ - `onClick`: `(e: MouseEvent) => void`, necessary.
418
+
419
+ - **slots**
420
+
421
+ - `trigger`: `string | JSX.Element`, necessary, it is usually an icon, which is displayed on the toolbar.
422
+
423
+ ### DropdownToolbar
424
+
425
+ `Editor.DropdownToolbar`
426
+
427
+ - **props**
428
+
429
+ - `title`: `string`, not necessary, title of toolbar.
430
+ - `visible`: `boolean`, necessary.
431
+
432
+ - **events**
433
+
434
+ - `onChange`: `(visible: boolean) => void`, necessary.
435
+
436
+ - **slots**
437
+
438
+ - `trigger`: `string | JSX.Element`, necessary, it is usually an icon, which is displayed on the toolbar.
439
+ - `overlay`: `string | JSX.Element`, necessary, content of dropdown box.
440
+
441
+ ### ModalToolbar
442
+
443
+ `Editor.ModalToolbar`
444
+
445
+ - **props**
446
+
447
+ - `title`: `string`, not necessary, title of toolbar.
448
+ - `modalTitle`: `string`, not necessary, title of the Modal.
449
+ - `visible`: `boolean`, necessary, visibility of Modal.
450
+ - `width`: `string`, not necessary, width of Modal, default `auto`.
451
+ - `height`:`string`, same as `width`.
452
+ - `showAdjust`: `boolean`, not necessary, visibility of fullscreen button.
453
+ - `isFullscreen`: `boolean`, necessary when `showAdjust = true`, status of fullscreen.
454
+
455
+ - **events**
456
+
457
+ - `onClick`: `() => void`, necessary.
458
+ - `onClose`:`() => void`, necessary, close event.
459
+ - `onAdjust`:`(val: boolean) => void`, fullscreen button click event.
460
+
461
+ - **slots**
462
+
463
+ - `trigger`: `string | JSX.Element`, necessary, it is usually an icon, which is displayed on the toolbar.
464
+ - `overlay`: `string | JSX.Element`, necessary, content of Modal.
465
+
466
+ ### Catalog
467
+
468
+ `Editor.MdCatalog`
469
+
470
+ - **props**
471
+
472
+ - `editorId`: `string`, necessary, same as editor's `editorId`, used to register listening events.
473
+ - `class`: `string`, not necessary.
474
+ - `markedHeadingId`: `MarkedHeadingId`, not necessary, same as editor.
475
+ - `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`.
476
+ - `theme`: `'light' | 'dark'`, not necessary, provide it when you want to change theme online, it is the same as Editor `theme`.
477
+
478
+ ## Examples
479
+
480
+ ### Jsx module
481
+
482
+ ```js
483
+ import { defineComponent, reactive } from 'vue';
484
+ import MdEditor from 'md-editor-v3';
485
+ import 'md-editor-v3/lib/style.css';
486
+
487
+ export default defineComponent({
488
+ setup() {
489
+ const md = reactive({
490
+ text: '# Hello Editor'
491
+ });
492
+ return () => (
493
+ <MdEditor modelValue={md.text} onChange={(value) => (md.text = value)} />
494
+ );
495
+ }
496
+ });
497
+ ```
498
+
499
+ ### Vue template
500
+
501
+ ```vue
502
+ <template>
503
+ <md-editor v-model="text" preview-only />
504
+ </template>
505
+
506
+ <script setup>
507
+ import { ref } from 'vue';
508
+ import MdEditor from 'md-editor-v3';
509
+ import 'md-editor-v3/lib/style.css';
510
+
511
+ const text = ref('# Hello Editor');
512
+ </script>
513
+ ```
514
+
515
+ ### Upload picture
516
+
517
+ > Tips:When you paste and upload GIF, it will upload a static picture. So you should upload it by file system!
518
+
519
+ <template>
520
+ <md-editor v-model="text" @onUploadImg="onUploadImg" />
521
+ </template>
522
+
523
+ <script setup>
524
+ import { ref } from 'vue';
525
+ import MdEditor from 'md-editor-v3';
526
+ import 'md-editor-v3/lib/style.css';
527
+
528
+ const text = ref('# Hello Editor');
529
+
530
+ const onUploadImg = async (files, callback) => {
531
+ const res = await Promise.all(
532
+ files.map((file) => {
533
+ return new Promise((rev, rej) => {
534
+ const form = new FormData();
535
+ form.append('file', file);
536
+
537
+ axios
538
+ .post('/api/img/upload', form, {
539
+ headers: {
540
+ 'Content-Type': 'multipart/form-data'
541
+ }
542
+ })
543
+ .then((res) => rev(res))
544
+ .catch((error) => rej(error));
545
+ });
546
+ })
547
+ );
548
+
549
+ callback(res.map((item) => item.data.url));
550
+ };
551
+ </script>