md-editor-v3 5.0.0-0 → 5.0.0-2
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 +14 -953
- package/lib/cjs/MdEditor.cjs +14 -8
- package/lib/cjs/ModalToolbar.cjs +6 -1
- package/lib/cjs/NormalToolbar.cjs +18 -5
- package/lib/cjs/chunks/config.cjs +178 -178
- package/lib/cjs/chunks/dom.cjs +64 -52
- package/lib/cjs/chunks/index.cjs +28 -35
- package/lib/cjs/chunks/index2.cjs +4 -0
- package/lib/cjs/chunks/index3.cjs +1 -1
- package/lib/cjs/chunks/index4.cjs +35 -513
- package/lib/es/MdEditor.mjs +14 -8
- package/lib/es/ModalToolbar.mjs +6 -1
- package/lib/es/NormalToolbar.mjs +18 -5
- package/lib/es/chunks/config.mjs +178 -178
- package/lib/es/chunks/dom.mjs +64 -52
- package/lib/es/chunks/index.mjs +28 -35
- package/lib/es/chunks/index2.mjs +4 -0
- package/lib/es/chunks/index3.mjs +1 -1
- package/lib/es/chunks/index4.mjs +2 -480
- package/lib/preview.css +4 -0
- package/lib/style.css +4 -0
- package/lib/types/DropdownToolbar/DropdownToolbar.d.ts +3 -0
- package/lib/types/MdEditor/Editor.d.ts +12 -15
- package/lib/types/MdEditor/config.d.ts +7 -7
- package/lib/types/MdEditor/layouts/Toolbar/index.d.ts +2 -0
- package/lib/types/MdEditor/layouts/Toolbar/props.d.ts +3 -0
- package/lib/types/MdEditor/props.d.ts +6 -24
- package/lib/types/MdPreview/MdPreview.d.ts +0 -3
- package/lib/types/ModalToolbar/ModalToolbar.d.ts +4 -0
- package/lib/types/NormalToolbar/NormalToolbar.d.ts +13 -0
- package/lib/umd/index.js +81 -81
- package/package.json +1 -1
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
|
+
|  |  |  |
|
|
32
|
+
|
|
33
|
+
Inputing prompt and mark, emoji extensions
|
|
34
|
+
|
|
35
|
+

|
|
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 :
|
|
83
|
+
<MdPreview :id="id" :modelValue="text" />
|
|
76
84
|
<MdCatalog :editorId="id" :scrollElement="scrollElement" />
|
|
77
85
|
</template>
|
|
78
86
|
|
|
@@ -87,955 +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
|
-
|  |  |  |
|
|
97
|
-
|
|
98
|
-
Inputing prompt and mark, emoji extensions
|
|
99
|
-
|
|
100
|
-

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