md-editor-v3 5.0.0-1 → 5.0.0-3

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
@@ -8,8 +8,6 @@ Markdown editor for vue3, developed in `jsx` and `typescript`.
8
8
 
9
9
  - Documentation and example: [Go](https://imzbf.github.io/md-editor-v3)
10
10
 
11
- - Use it online: [Go](https://codesandbox.io/s/epic-bird-2znqo)
12
-
13
11
  - The same series editor for react: [md-editor-rt](https://github.com/imzbf/md-editor-rt)
14
12
 
15
13
  ## ⭐️ Features
@@ -26,6 +24,16 @@ Markdown editor for vue3, developed in `jsx` and `typescript`.
26
24
  - Customize the toolbar as you like.
27
25
  - On-demand Import(>=4.0.0).
28
26
 
27
+ ## 🗺 Preview
28
+
29
+ | Default theme | Dark theme | Preview only |
30
+ | --- | --- | --- |
31
+ | ![](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) |
32
+
33
+ Inputing prompt and mark, emoji extensions
34
+
35
+ ![](https://imzbf.github.io/md-editor-v3/imgs/mark_emoji.gif)
36
+
29
37
  ## 📦 Install
30
38
 
31
39
  ```shell
@@ -72,7 +80,7 @@ const text = ref('# Hello Editor');
72
80
 
73
81
  ```vue
74
82
  <template>
75
- <MdPreview :editorId="id" :modelValue="text" />
83
+ <MdPreview :id="id" :modelValue="text" />
76
84
  <MdCatalog :editorId="id" :scrollElement="scrollElement" />
77
85
  </template>
78
86
 
@@ -87,954 +95,8 @@ const scrollElement = document.documentElement;
87
95
  </script>
88
96
  ```
89
97
 
90
- When using server-side rendering, `scrollElement` should be of string type, eg: `body`, `#id`, `.class`.
91
-
92
- ## 🗺 Preview
93
-
94
- | Default theme | Dark theme | Preview only |
95
- | --- | --- | --- |
96
- | ![](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) |
97
-
98
- Inputing prompt and mark, emoji extensions
99
-
100
- ![](https://imzbf.github.io/md-editor-v3/imgs/mark_emoji.gif)
101
-
102
- ## 🎁 Apis
103
-
104
- ### 🔖 MdPreivew Props
105
-
106
- | name | type | default | description |
107
- | --- | --- | --- | --- |
108
- | modelValue | `string` | '' | Markdown content, use `v-model` in vue template |
109
- | theme | `'light' \| 'dark'` | 'light' | Editor theme |
110
- | class | `string` | '' | |
111
- | style | `string \| CSSProperties` | {} | Inline style |
112
- | language | `string` | 'zh-CN' | Build-in language('zh-CN','en-US') |
113
- | editorId | `string` | 'md-editor-v3\_[\d]' | Editor's id, default incrementing by number. When using server-side rendering, make sure to set this attribute to a constant value |
114
- | showCodeRowNumber | `boolean` | true | Show row number for code block or not |
115
- | previewTheme | `'default' \| 'github' \| 'vuepress' \| 'mk-cute' \| 'smart-blue' \| 'cyanosis'` | 'default' | Theme of preview, can be customized |
116
- | noMermaid | `boolean` | false | Use mermaid or not |
117
- | noKatex | `boolean` | false | Use katex or not |
118
- | codeTheme | `'atom' \| 'a11y' \| 'github' \| 'gradient' \| 'kimbie' \| 'paraiso' \| 'qtcreator' \| 'stackoverflow'` | 'atom' | Highlight code style, can be customized also |
119
- | mdHeadingId | `(text: string, level: number, index: number) => string` | (text) => text | H1-H6 `ID` generator |
120
- | sanitize | `(html: string) => string` | (html) => html | This attribute is used to alter the compiled HTML content |
121
- | formatCopiedText | `(text: string) => string` | (text: string) => text | Format copied code |
122
- | codeStyleReverse | `boolean` | true | Code style will be reversed to dark while code block of the theme has a dark background |
123
- | codeStyleReverseList | `Array<string>` | ['default', 'mk-cute'] | Themes to be reversed |
124
- | noHighlight | `boolean` | false | Highlight code or not |
125
- | noImgZoomIn | `boolean` | false | Enable the function of enlarging images |
126
- | customIcon | `CustomIcon` | {} | Customized icons |
127
- | sanitizeMermaid | `(h: string) => Promise<string>` | (h: string) => Promise.resolve(h) | Convert the generated mermaid code |
128
- | codeFoldable | `boolean` | true | Whether to enable code folding feature |
129
- | autoFoldThreshold | `number` | 30 | Threshold for triggering automatic code folding by line count |
130
-
131
- ### 🔩 MdEditor Props
132
-
133
- Except for the same as `MdPreview`:
134
-
135
- | name | type | default | description |
136
- | --- | --- | --- | --- |
137
- | pageFullscreen | `boolean` | false | Screenfull in web page |
138
- | preview | `boolean` | true | Preview content in editor |
139
- | htmlPreview | `boolean` | false | Preview html in editor(If true, preview must be false) |
140
- | toolbars | `Array<ToolbarNames \| number>` | [toolbars] | Show contents of toolbar, all keys<sup>see `toolbars` below</sup> |
141
- | toolbarsExclude | `Array<ToolbarNames \| number>` | [] | Don't show contents of toolbar, all keys`toolbars` |
142
- | noPrettier | `boolean` | false | Use prettier to beautify content or not |
143
- | tabWidth | `number` | 2 | One tab eq some spaces |
144
- | tableShape | `[number, number] \| [number, number, number, number]` | [6, 4] | Preset the size of the table, [columns, rows, Maximum number of columns, Maximum number of rows] |
145
- | placeholder | `string` | '' | |
146
- | footers | `Array<'markdownTotal' \| '=' \| 'scrollSwitch' \| number>` | ['markdownTotal', '=', 'scrollSwitch'] | Show contents of footer, they are divided by `'='`. Set it to `[]` to hidden footer |
147
- | scrollAuto | `boolean` | true | Scroll default setting |
148
- | noUploadImg | `boolean` | false | Not show the entrance to upload pictures |
149
- | autoFocus | `boolean` | false | same as `autofocus` in native textarea |
150
- | disabled | `boolean` | false | same as `disabled` in native textarea |
151
- | readOnly | `boolean` | false | same as `readonly` in native textarea |
152
- | maxLength | `number` | | same as `maxlength` in native textarea |
153
- | autoDetectCode | `boolean` | false | auto detect the type of pasted code, only support that copied from `vscode` |
154
- | completions | `Array<CompletionSource>` | [] | `@codemirror/autocomplete` List of function to match keywords |
155
- | showToolbarName | `boolean` | false | Show toolbar name or not |
156
- | inputBoxWidth | `string` | '50%' | Default width of input box |
157
- | transformImgUrl | `(imgUrl: string) => string \| Promise<string>` | t => t | Transform image links |
158
-
159
- <details>
160
- <summary>『toolbars』</summary>
161
-
162
- ```js
163
- [
164
- 'bold',
165
- 'underline',
166
- 'italic',
167
- '-',
168
- 'strikeThrough',
169
- 'title',
170
- 'sub',
171
- 'sup',
172
- 'quote',
173
- 'unorderedList',
174
- 'orderedList',
175
- 'task', // ^2.4.0
176
- '-',
177
- 'codeRow',
178
- 'code',
179
- 'link',
180
- 'image',
181
- 'table',
182
- 'mermaid',
183
- 'katex',
184
- '-',
185
- 'revoke',
186
- 'next',
187
- 'save',
188
- '=',
189
- 'pageFullscreen',
190
- 'fullscreen',
191
- 'preview',
192
- 'previewOnly',
193
- 'htmlPreview',
194
- 'catalog',
195
- 'github'
196
- ];
197
- ```
198
-
199
- </details>
200
-
201
- > You can sort the toolbar as you like, split tools by `'-'`, the left and right toolbars are divided by `'='`!
202
-
203
- > 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).
204
-
205
- <details>
206
- <summary>『StaticTextDefaultValue』</summary>
207
-
208
- Expand language, you need to replace all the content here:
209
-
210
- ```ts
211
- export interface ToolbarTips {
212
- bold?: string;
213
- underline?: string;
214
- italic?: string;
215
- strikeThrough?: string;
216
- title?: string;
217
- sub?: string;
218
- sup?: string;
219
- quote?: string;
220
- unorderedList?: string;
221
- orderedList?: string;
222
- task?: string; // ^2.4.0
223
- codeRow?: string;
224
- code?: string;
225
- link?: string;
226
- image?: string;
227
- table?: string;
228
- mermaid?: string;
229
- katex?: string;
230
- revoke?: string;
231
- next?: string;
232
- save?: string;
233
- prettier?: string;
234
- pageFullscreen?: string;
235
- fullscreen?: string;
236
- catalog?: string;
237
- preview?: string;
238
- previewOnly?: string;
239
- htmlPreview?: string;
240
- github?: string;
241
- '-'?: string;
242
- '='?: string;
243
- }
244
-
245
- export interface StaticTextDefaultValue {
246
- // Toolbar hover tips(html title)
247
- toolbarTips?: ToolbarTips;
248
- // H1-H6 dropdown menu item
249
- titleItem?: {
250
- h1?: string;
251
- h2?: string;
252
- h3?: string;
253
- h4?: string;
254
- h5?: string;
255
- h6?: string;
256
- };
257
- imgTitleItem?: {
258
- link: string;
259
- upload: string;
260
- clip2upload: string;
261
- };
262
- // The modal tips of add link or upload picture
263
- linkModalTips?: {
264
- linkTitle?: string;
265
- imageTitle?: string;
266
- descLabel?: string;
267
- descLabelPlaceHolder?: string;
268
- urlLabel?: string;
269
- urlLabelPlaceHolder?: string;
270
- buttonOK?: string;
271
- };
272
- // The modal tips of clip the picture, v1.2.0
273
- clipModalTips?: {
274
- title?: string;
275
- buttonUpload?: string;
276
- };
277
- copyCode?: {
278
- text?: string;
279
- successTips?: string;
280
- failTips?: string;
281
- };
282
- mermaid?: {
283
- flow?: string;
284
- sequence?: string;
285
- gantt?: string;
286
- class?: string;
287
- state?: string;
288
- pie?: string;
289
- relationship?: string;
290
- journey?: string;
291
- };
292
- katex?: {
293
- // formula inline
294
- inline: string;
295
- // formula block
296
- block: string;
297
- };
298
- footer?: {
299
- markdownTotal: string;
300
- scrollAuto: string;
301
- };
302
- }
303
- ```
304
-
305
- </details>
306
-
307
- ### 🧵 MdPreview Events
308
-
309
- | name | type | description |
310
- | --- | --- | --- |
311
- | onChange | `value: string` | Content changed(bind to `oninput` of `textarea`) |
312
- | onHtmlChanged | `html: string` | Compile markdown successful event, you can use it to get the html code |
313
- | onGetCatalog | `list: Array<HeadList>` | Get catalog of article |
314
-
315
- ### 🪢 MdEditor Events
316
-
317
- Except for the same as `MdPreview`:
318
-
319
- | name | type | description |
320
- | --- | --- | --- |
321
- | onSave | `value: string, html: Promise<string>` | Saving content, `ctrl+s` and clicking button will trigger it |
322
- | onUploadImg | `files: Array<File>, callback: (urls: string[] \| { url: string; alt: string; title: string }[]) => void` | Uploading picture, when picture is uploading the modal will not close, please provide right urls to the callback function |
323
- | onError | `err: { name: 'Cropper' \| 'fullscreen' \| 'prettier' \| 'overlength'; message: string }` | Catch run-time error, `Cropper`, `fullscreen` and `prettier` are used when they are not loaded. And content exceeds the length limit error |
324
- | onBlur | `event: FocusEvent` | Textarea has lost focus |
325
- | onFocus | `event: FocusEvent` | Textarea has received focus |
326
- | onInput | `event: Event` | Element gets input |
327
- | onDrop | `event: DragEvent` | Selection is being dragged |
328
- | oninputBoxWidthChange | `(width: string) => void` | Width of input box has been changed |
329
-
330
- ### 🎍 Slots
331
-
332
- | name | type | default | description |
333
- | --- | --- | --- | --- |
334
- | defToolbars | `Array<DropdownToolbar \| NormalToolbar \| ModalToolbar>` | null | Custom toolbar in `DropdownToolbar`, `NormalToolbar` or `ModalToolbar` |
335
- | defFooters | `Array<string \| VNode \| JSX.Element>` | null | Custom footer |
336
-
337
- `NormalToolbar` example:
338
-
339
- ```vue
340
- <template>
341
- <MdEditor>
342
- <template #defToolbars>
343
- <NormalToolbar title="mark" @onClick="handler">
344
- <template #trigger>
345
- <svg class="md-editor-icon" aria-hidden="true">
346
- <use xlink:href="#md-editor-icon-mark"></use>
347
- </svg>
348
- </template>
349
- </NormalToolbar>
350
- </template>
351
- </MdEditor>
352
- </template>
353
-
354
- <script setup lang="ts">
355
- import { MdEditor, NormalToolbar } from 'md-editor-v3';
356
- import 'md-editor-v3/lib/style.css';
357
-
358
- const handler = () => {
359
- console.log('NormalToolbar clicked!');
360
- };
361
- </script>
362
- ```
363
-
364
- ## 🤱🏼 Expose
365
-
366
- After 2.5.0, Editor exposes several methods on the instance, used to get or change the internal status of the editor.
367
-
368
- ```vue
369
- <template>
370
- <MdEditor ref="editorRef" />
371
- </template>
372
-
373
- <script setup lang="ts">
374
- import { ref, onMounted } from 'vue';
375
- import { MdEditor } from 'md-editor-v3';
376
- import type { ExposeParam } from 'md-editor-v3';
377
- import 'md-editor-v3/lib/style.css';
378
-
379
- const editorRef = ref<ExposeParam>();
380
-
381
- onMounted(() => {
382
- editorRef.value?.on('catalog', console.log);
383
- editorRef.value?.toggleCatalog(true);
384
- });
385
- </script>
386
- ```
387
-
388
- > Switched to the opposite status, if toggle without input parameter.
389
-
390
- ### 👂🏼 on
391
-
392
- Get the internal state of the editor, including pageFullscreen, fullscreen, preview, htmlPreview, catalog, etc.
393
-
394
- ```ts
395
- type Keys =
396
- | 'pageFullscreen'
397
- | 'fullscreen'
398
- | 'preview'
399
- | 'previewOnly'
400
- | 'htmlPreview'
401
- | 'catalog';
402
- ```
403
-
404
- ```js
405
- editorRef.value?.on('pageFullscreen', (status) => console.log(status));
406
- ```
407
-
408
- ### 💻 togglePageFullscreen
409
-
410
- Toggle status of fullscreen within the page.
411
-
412
- ```js
413
- editorRef.value?.togglePageFullscreen(true);
414
- ```
415
-
416
- ### 🖥 toggleFullscreen
417
-
418
- Toggle status of fullscreen widthin browser.
419
-
420
- ```js
421
- editorRef.value?.toggleFullscreen(true);
422
- ```
423
-
424
- ### 📖 togglePreview
425
-
426
- Toggle status of preview.
427
-
428
- ```js
429
- editorRef.value?.togglePreview(true);
430
- ```
431
-
432
- ### 📖 togglePreviewOnly
433
-
434
- Toggle into Preview Only Mode.
435
-
436
- ```js
437
- editorRef.value?.togglePreviewOnly(true);
438
- ```
439
-
440
- ### 📼 toggleHtmlPreview
441
-
442
- Toggle status of htmlPreview.
443
-
444
- ```js
445
- editorRef.value?.toggleHtmlPreview(true);
446
- ```
447
-
448
- ### 🧬 toggleCatalog
449
-
450
- Toggle status of catalog.
451
-
452
- ```js
453
- editorRef.value?.toggleCatalog(true);
454
- ```
455
-
456
- ### 💾 triggerSave
457
-
458
- Save actions will be triggered.
459
-
460
- ### 💉 insert
461
-
462
- Manually insert content into textarea.
463
-
464
- ```js
465
- /**
466
- * @params selectedText
467
- */
468
- editorRef.value?.insert((selectedText) => {
469
- /**
470
- * @return targetValue Content to be inserted
471
- * @return select Automatically select content, default: true
472
- * @return deviationStart Start position of the selected content, default: 0
473
- * @return deviationEnd End position of the selected content, default: 0
474
- */
475
- return {
476
- targetValue: `${selectedText}`,
477
- select: true,
478
- deviationStart: 0,
479
- deviationEnd: 0
480
- };
481
- });
482
- ```
483
-
484
- For more examples, refer to source code of [extension component](https://github.com/imzbf/md-editor-v3/blob/dev-docs/src/components/MarkExtension/index.vue)
485
-
486
- ### 🎯 focus
487
-
488
- Focus on textarea.
489
-
490
- ```ts
491
- import type { FocusOption } from 'md-editor-v3';
492
-
493
- const option: FocusOption | undefined = 'start';
494
-
495
- // Cursor position when focusing on textarea, default: position when it last lost focus
496
- editorRef.value?.focus(option);
497
- ```
498
-
499
- ### ✒️ rerender
500
-
501
- Re render the content.
502
-
503
- ### 🔍 getSelectedText
504
-
505
- Get the currently selected text.
506
-
507
- ### 🗑 resetHistory
508
-
509
- Clear current history.
510
-
511
- ### 🎛 domEventHandlers
512
-
513
- Supports listening to all DOM events.
514
-
515
- ```js
516
- editorRef.value?.domEventHandlers({
517
- compositionstart: () => {
518
- console.log('compositionstart');
519
- }
520
- });
521
- ```
522
-
523
- ### 🎛 execCommand
524
-
525
- Insert content into the editor via trigger.
526
-
527
- ```js
528
- editorRef.value?.execCommand('bold');
529
- ```
530
-
531
- ### 🔖 getEditorView
532
-
533
- Get codemirror instance.
534
-
535
- ## 💴 Config Editor
536
-
537
- Use `config(option: ConfigOption)` to reconfigure `markdown-it` and so on.
538
-
539
- > [!WARNING]
540
- >
541
- > We recommend configuring it at the project entry point, such as in `main.js` for projects created with Vite. Avoid calling `config` within components!
542
-
543
- ### codeMirrorExtensions
544
-
545
- Customize new extensions based on theme and default extensions f codeMirror.
546
-
547
- Example: Editor does not render the line number of textarea by default, this extension needs to be manually added
548
-
549
- ```js
550
- import { config } from 'md-editor-v3';
551
- import { lineNumbers } from '@codemirror/view';
552
-
553
- config({
554
- codeMirrorExtensions(_theme, extensions) {
555
- return [...extensions, lineNumbers()];
556
- }
557
- });
558
- ```
559
-
560
- ### markdownItConfig
98
+ When using server-side rendering, `scrollElement` should be of string type, eg: `html`, `body`, `#id`, `.class`.
561
99
 
562
- Customize extensions, attributes of `markdown-it`, etc.
100
+ ---
563
101
 
564
- ```ts
565
- type MarkdownItConfig = (
566
- md: markdownit,
567
- options: {
568
- editorId: string;
569
- }
570
- ) => void;
571
- ```
572
-
573
- Example: Use `markdown-it-anchor` to render a hyperlink symbol to the right of the title
574
-
575
- ```js
576
- import { config } from 'md-editor-v3';
577
- import ancher from 'markdown-it-anchor';
578
-
579
- config({
580
- markdownItConfig(mdit) {
581
- mdit.use(ancher, {
582
- permalink: true
583
- });
584
- }
585
- });
586
- ```
587
-
588
- ### markdownItPlugins
589
-
590
- Select and add built-in plugins to `markdown-it`.
591
-
592
- ```ts
593
- type MarkdownItPlugins = (
594
- plugins: Array<MarkdownItConfigPlugin>,
595
- options: {
596
- editorId: string;
597
- }
598
- ) => Array<MarkdownItConfigPlugin>;
599
- ```
600
-
601
- Example: Modify the class name of the image.
602
-
603
- ```js
604
- import { config } from 'md-editor-v3';
605
-
606
- config({
607
- markdownItPlugins(plugins) {
608
- return plugins.map((p) => {
609
- if (p.type === 'image') {
610
- return {
611
- ...p,
612
- options: {
613
- ...p.options,
614
- classes: 'my-class'
615
- }
616
- };
617
- }
618
-
619
- return p;
620
- });
621
- }
622
- });
623
- ```
624
-
625
- ### editorConfig
626
-
627
- Add more languages, reset `mermaid` template or delay rendering time:
628
-
629
- ```js
630
- import { config } from 'md-editor-v3';
631
-
632
- config({
633
- editorConfig: {
634
- languageUserDefined: { lang: StaticTextDefaultValue },
635
- mermaidTemplate: {
636
- flow: `flow tempalte`,
637
- ...more
638
- },
639
- // Default 500ms. It is set to 0ms when preview only and not set.
640
- renderDelay: 500,
641
- // for modal component
642
- zIndex: 2000
643
- }
644
- });
645
- ```
646
-
647
- ### editorExtensions
648
-
649
- Config some dependency libraries, like highlight..
650
-
651
- ```typescript
652
- import { config } from 'md-editor-v3';
653
-
654
- config({
655
- editorExtensions: { iconfont: 'https://xxx.cc' }
656
- });
657
- ```
658
-
659
- <details>
660
- <summary>『EditorExtensions』</summary>
661
-
662
- ```ts
663
- export interface EditorExtensions {
664
- highlight?: {
665
- instance?: any;
666
- js?: string;
667
- css?: {
668
- [key: string]: {
669
- light: string;
670
- dark: string;
671
- };
672
- };
673
- };
674
- prettier?: {
675
- standaloneJs?: string;
676
- parserMarkdownJs?: string;
677
- };
678
- cropper?: {
679
- instance?: any;
680
- js?: string;
681
- css?: string;
682
- };
683
- iconfont?: string;
684
- screenfull?: {
685
- instance?: any;
686
- js?: string;
687
- };
688
- mermaid?: {
689
- instance?: any;
690
- js?: string;
691
- };
692
- katex?: {
693
- instance?: any;
694
- js?: string;
695
- css?: string;
696
- };
697
- }
698
- ```
699
-
700
- </details>
701
-
702
- ### editorExtensionsAttrs
703
-
704
- Synchronously add attributes to the CDN link tags, consistent with the type of `editorExtensions`, with a value type of `HTMLElementTagNameMap['tagName']`.
705
-
706
- ```js
707
- import { config, editorExtensionsAttrs } from 'md-editor-v3';
708
-
709
- config({
710
- editorExtensionsAttrs
711
- });
712
- ```
713
-
714
- Do not attempt to define the src \ onload \ id of the script and rel \ href \ id of the link in editorExtensionsAttrs, as they will be overwritten by default values
715
-
716
- ### 🫨 iconfontType
717
-
718
- Set the way to display icons:
719
-
720
- - `svg`: with symbol
721
- - `class`: with font-class
722
-
723
- If the icon is customized through the attribute `customIcon`, the customized icon will be used first.
724
-
725
- ### 🎨 mermaidConfig
726
-
727
- Configure `mermaid`, [Details](https://mermaid.js.org/config/schema-docs/config.html)
728
-
729
- ```js
730
- import { config } from 'md-editor-v3';
731
-
732
- config({
733
- mermaidConfig(base: any) {
734
- return {
735
- ...base,
736
- logLevel: 'error'
737
- };
738
- }
739
- });
740
- ```
741
-
742
- ### 🔧 katexConfig
743
-
744
- Configure `katex`, [Details](https://katex.org/docs/options)
745
-
746
- ```js
747
- import { config } from 'md-editor-v3';
748
-
749
- config({
750
- katexConfig(base: any) {
751
- return {
752
- ...base,
753
- strict: false
754
- };
755
- }
756
- });
757
- ```
758
-
759
- ## 🪡 Shortcut Key
760
-
761
- _Pay attention: shortcut keys are only available when the textarea has received focus!_
762
-
763
- | key | function | description |
764
- | --- | --- | --- |
765
- | TAB | insert space | Insert space, the length eq `tabWidth`, default: 2, support multiline |
766
- | SHIFT + TAB | delete space, setting is the same as Tab | |
767
- | CTRL + C | copy | When selected, copy the selected content. When not selected, copy the content of the current line |
768
- | CTRL + X | shear | When selected, cut the selected content. When not selected, cut the current line |
769
- | CTRL + D | delete | When selected, delete the selected content. When not selected, delete the current line |
770
- | CTRL + S | save | Trigger `onSave` event |
771
- | CTRL + B | bold text | `**bold**` |
772
- | CTRL + U | underline | `<u>underline</u>` |
773
- | CTRL + I | italic | `*italic*` |
774
- | CTRL + 1-6 | h1-h6 | `# title` |
775
- | CTRL + ↑ | superscript | `<sup>superscript</sup>` |
776
- | CTRL + ↓ | subscript | `<sub>subscript</sub>` |
777
- | CTRL + O | ordered list | `1. ordered list` |
778
- | CTRL + L | link | `[link](https://github.com/imzbf/md-editor-v3)` |
779
- | CTRL + Z | withdraw | Withdraw history in editor, not the function of system |
780
- | CTRL + SHIFT + S | line-through | `~line-through~` |
781
- | CTRL + SHIFT + U | unordered list | `- unordered list` |
782
- | CTRL + SHIFT + C | code block | |
783
- | CTRL + SHIFT + I | picture | `![picture](https://imzbf.github.io/md-editor-v3/imgs/preview-light.png)` |
784
- | CTRL + SHIFT + Z | forward | Forward history in editor, not the function of system |
785
- | CTRL + SHIFT + F | Beautify | |
786
- | CTRL + ALT + C | code row | |
787
- | CTRL + SHIFT + ALT + T | table | `\|table\|` |
788
-
789
- ## 🪤 Internal Components
790
-
791
- ```vue
792
- <script lang="ts" setup>
793
- import { NormalToolbar } from 'md-editor-v3';
794
- </script>
795
- ```
796
-
797
- On-demand import. For more examples, refer to [document](https://imzbf.github.io/md-editor-v3).
798
-
799
- ### 🐣 NormalToolbar
800
-
801
- `NormalToolbar`
802
-
803
- - **props**
804
-
805
- - `title`: `string`, not required, title of toolbar.
806
-
807
- - **events**
808
-
809
- - `onClick`: `(e: MouseEvent) => void`, required.
810
-
811
- - **slots**
812
-
813
- - `trigger`: `VNode | JSX.Element`, required, it is usually an icon, which is displayed on the toolbar.
814
-
815
- ### 🐼 DropdownToolbar
816
-
817
- `DropdownToolbar`
818
-
819
- - **props**
820
-
821
- - `title`: `string`, not required, title of toolbar.
822
- - `visible`: `boolean`, required.
823
-
824
- - **events**
825
-
826
- - `onChange`: `(visible: boolean) => void`, required.
827
-
828
- - **slots**
829
-
830
- - `trigger`: `VNode | JSX.Element`, required, it is usually an icon, which is displayed on the toolbar.
831
- - `overlay`: `VNode | JSX.Element`, required, content of dropdown box.
832
-
833
- ### 🦉 ModalToolbar
834
-
835
- `ModalToolbar`
836
-
837
- - **props**
838
-
839
- - `title`: `string`, not required, title of toolbar.
840
- - `modalTitle`: `string`, not required, title of the Modal.
841
- - `visible`: `boolean`, required, visibility of Modal.
842
- - `width`: `string`, not required, width of Modal, default `auto`.
843
- - `height`: `string`, same as `width`.
844
- - `showAdjust`: `boolean`, not required, visibility of fullscreen button.
845
- - `isFullscreen`: `boolean`, required when `showAdjust = true`, status of fullscreen.
846
- - `class`: `string`, not required.
847
- - `style`: `CSSProperties | string`, not required.
848
- - `showMask`: `boolean`, not required, whether to display the mask layer, default `true`.
849
-
850
- - **events**
851
-
852
- - `onClick`: `() => void`, required.
853
- - `onClose`: `() => void`, required, closed event.
854
- - `onAdjust`: `(val: boolean) => void`, fullscreen button was clicked.
855
-
856
- - **slots**
857
-
858
- - `trigger`: `VNode | JSX.Element`, required, it is usually an icon, which is displayed on the toolbar.
859
- - `default`: `VNode | JSX.Element`, required, content of Modal.
860
-
861
- ### 🐻 MdCatalog
862
-
863
- `MdCatalog`
864
-
865
- - **props**
866
-
867
- - `editorId`: `string`, required, same as editor's `editorId`, used to register listening events.
868
- - `class`: `string`, not required.
869
- - `mdHeadingId`: `MdHeadingId`, not required, same as editor.
870
- - `scrollElement`: `string | HTMLElement`, not required, it is an element selector when its type is string. When `previewOnly` eq `true`, it is usually set to `document.documentElement`.
871
- - `theme`: `'light' | 'dark'`, not required, provide it when you want to change theme online, it is the same as Editor `theme`.
872
- - `offsetTop`: `number`, not required, highlight current item of catalogs when title is `offsetTop` pixels from the top, default 20.
873
- - `scrollElementOffsetTop`: `number`, not required, offsetTop of the scroll container,default 0.
874
- - `isScrollElementInShadow`: `boolean`, whether the scroll container is in web component, default false.
875
-
876
- - **events**
877
-
878
- - `onClick`: `(e: MouseEvent, t: TocItem) => void`, not required, heading was clicked.
879
- - `onActive`: `(heading: HeadList | undefined, activeElement: HTMLDivElement) => void`, not required, heading was highlighted.
880
-
881
- ### 🛸 MdModal
882
-
883
- `MdModal`
884
-
885
- - **props**
886
-
887
- - `title`: `string`, not required, title of Modal.
888
- - `visible`: `boolean`, required, visibility of Modal.
889
- - `width`: `string`, not required, width of Modal, default `auto`.
890
- - `height`: `string`, same as `width`.
891
- - `showAdjust`: `boolean`, not required, visibility of fullscreen button.
892
- - `isFullscreen`: `boolean`, required when `showAdjust = true`, status of fullscreen.
893
- - `class`: `string`, not required.
894
- - `style`: `CSSProperties | string`, not required.
895
- - `showMask`: `boolean`, not required, whether to display the mask layer, default `true`.
896
-
897
- - **events**
898
-
899
- - `onClose`: `() => void`, required, closed event.
900
- - `onAdjust`: `(val: boolean) => void`, fullscreen button was clicked.
901
-
902
- - **slots**
903
-
904
- - `default`: `VNode | JSX.Element`, required, content of Modal.
905
-
906
- ### 🛸 NormalFooterToolbar
907
-
908
- `NormalFooterToolbar`
909
-
910
- - **events**
911
-
912
- - `onClick`: `(e: MouseEvent) => void`, not required, toolbar was clicked.
913
-
914
- - **slots**
915
-
916
- - `default`: `VNode | JSX.Element`, required, content.
917
-
918
- ## 🪤 Internal Configuration
919
-
920
- ```js
921
- import {
922
- iconfontClassUrl,
923
- iconfontSvgUrl,
924
- allToolbar,
925
- allFooter,
926
- zh_CN,
927
- en_US
928
- } from 'md-editor-v3';
929
-
930
- console.log(iconfontClassUrl, iconfontSvgUrl, allToolbar, allFooter, zh_CN, en_US);
931
- ```
932
-
933
- ## 🗂 Examples
934
-
935
- ### 🎸 Jsx Template
936
-
937
- ```jsx
938
- import { defineComponent, reactive } from 'vue';
939
- import { MdEditor } from 'md-editor-v3';
940
- import 'md-editor-v3/lib/style.css';
941
-
942
- export default defineComponent({
943
- setup() {
944
- const md = reactive({
945
- text: '# Hello Editor'
946
- });
947
- return () => (
948
- <MdEditor modelValue={md.text} onChange={(value) => (md.text = value)} />
949
- );
950
- }
951
- });
952
- ```
953
-
954
- ### 🥹 Upload Picture
955
-
956
- > Tips: When you paste and upload GIF, it will upload a static picture. So you should upload it by file system!
957
-
958
- ```vue
959
- <template>
960
- <MdEditor v-model="text" @onUploadImg="onUploadImg" />
961
- </template>
962
-
963
- <script setup>
964
- import { ref } from 'vue';
965
- import axios from 'axios';
966
- import { MdEditor } from 'md-editor-v3';
967
- import 'md-editor-v3/lib/style.css';
968
-
969
- const text = ref('# Hello Editor');
970
-
971
- const onUploadImg = async (files, callback) => {
972
- const res = await Promise.all(
973
- files.map((file) => {
974
- return new Promise((rev, rej) => {
975
- const form = new FormData();
976
- form.append('file', file);
977
-
978
- axios
979
- .post('/api/img/upload', form, {
980
- headers: {
981
- 'Content-Type': 'multipart/form-data'
982
- }
983
- })
984
- .then((res) => rev(res))
985
- .catch((error) => rej(error));
986
- });
987
- })
988
- );
989
-
990
- // Approach 1
991
- callback(res.map((item) => item.data.url));
992
-
993
- // Approach 2
994
- // callback(
995
- // res.map((item: any) => ({
996
- // url: item.data.url,
997
- // alt: 'alt',
998
- // title: 'title'
999
- // }))
1000
- // );
1001
- };
1002
- </script>
1003
- ```
1004
-
1005
- ### 🧙‍♂️ Change Styles
1006
-
1007
- ```less
1008
- .css-vars(@isDark) {
1009
- --md-color: if(@isDark, #999, #222);
1010
- --md-hover-color: if(@isDark, #bbb, #000);
1011
- --md-bk-color: if(@isDark, #000, #fff);
1012
- --md-bk-color-outstand: if(@isDark, #333, #f2f2f2);
1013
- --md-bk-hover-color: if(@isDark, #1b1a1a, #f5f7fa);
1014
- --md-border-color: if(@isDark, #2d2d2d, #e6e6e6);
1015
- --md-border-hover-color: if(@isDark, #636262, #b9b9b9);
1016
- --md-border-active-color: if(@isDark, #777, #999);
1017
- --md-modal-mask: #00000073;
1018
- --md-modal-shadow: if(@isDark, 0px 6px 24px 2px #00000066, 0px 6px 24px 2px #00000019);
1019
- --md-scrollbar-bg-color: if(@isDark, #0f0f0f, #e2e2e2);
1020
- --md-scrollbar-thumb-color: if(@isDark, #2d2d2d, #0000004d);
1021
- --md-scrollbar-thumb-hover-color: if(@isDark, #3a3a3a, #00000059);
1022
- --md-scrollbar-thumb-active-color: if(@isDark, #3a3a3a, #00000061);
1023
- }
1024
-
1025
- .md-editor {
1026
- .css-vars(false);
1027
- }
1028
-
1029
- .md-editor-dark {
1030
- .css-vars(true);
1031
- }
1032
- ```
1033
-
1034
- Change background color in dark mode:
1035
-
1036
- ```css
1037
- .md-editor-dark {
1038
- --md-bk-color: #333 !important;
1039
- }
1040
- ```
102
+ For more usage, please visit the [document](https://imzbf.github.io/md-editor-v3).