md-editor-v3 4.4.0 → 4.5.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +129 -109
- package/lib/cjs/MdCatalog.cjs +1 -1
- package/lib/cjs/MdEditor.cjs +18 -18
- package/lib/cjs/MdModal.cjs +1 -1
- package/lib/cjs/MdPreview.cjs +1 -1
- package/lib/cjs/ModalToolbar.cjs +1 -1
- package/lib/cjs/chunks/config.cjs +1 -1
- package/lib/cjs/chunks/index.cjs +6 -6
- package/lib/cjs/chunks/index3.cjs +1 -2
- package/lib/cjs/chunks/index4.cjs +2 -0
- package/lib/cjs/index.cjs +1 -1
- package/lib/es/MdCatalog.mjs +1 -1
- package/lib/es/MdEditor.mjs +967 -1058
- package/lib/es/MdModal.mjs +6 -139
- package/lib/es/MdPreview.mjs +1 -1
- package/lib/es/ModalToolbar.mjs +1 -1
- package/lib/es/chunks/config.mjs +25 -26
- package/lib/es/chunks/index.mjs +230 -204
- package/lib/es/chunks/index3.mjs +163 -61
- package/lib/es/chunks/index4.mjs +69 -0
- package/lib/es/index.mjs +18 -17
- package/lib/preview.css +1 -1
- package/lib/style.css +1 -1
- package/lib/types/MdEditor/Editor.d.ts +10 -1
- package/lib/types/MdEditor/components/Icon/Icon.d.ts +16 -0
- package/lib/types/MdEditor/components/Icon/Str.d.ts +3 -0
- package/lib/types/MdEditor/components/Icon/index.d.ts +16 -0
- package/lib/types/MdEditor/config.d.ts +2 -1
- package/lib/types/MdEditor/index.d.ts +23 -4
- package/lib/types/MdEditor/props.d.ts +15 -1
- package/lib/types/MdEditor/type.d.ts +37 -8
- package/lib/types/MdPreview/MdPreview.d.ts +9 -0
- package/lib/types/MdPreview/index.d.ts +20 -1
- package/lib/umd/index.js +43 -43
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -116,6 +116,7 @@ Inputing prompt and mark, emoji extensions
|
|
|
116
116
|
| codeStyleReverseList | `Array<string>` | ['default', 'mk-cute'] | Themes to be reversed |
|
|
117
117
|
| noHighlight | `boolean` | false | Highlight code or not |
|
|
118
118
|
| noImgZoomIn | `boolean` | false | Enable the function of enlarging images |
|
|
119
|
+
| customIcon | `CustomIcon` | {} | Customized icons |
|
|
119
120
|
|
|
120
121
|
### 🔩 MdEditor Props
|
|
121
122
|
|
|
@@ -493,134 +494,153 @@ editorRef.value?.focus(option);
|
|
|
493
494
|
|
|
494
495
|
Use `config(option: ConfigOption)` to reconfigure `markdown-it` and so on.
|
|
495
496
|
|
|
496
|
-
|
|
497
|
+
### codeMirrorExtensions
|
|
497
498
|
|
|
498
|
-
|
|
499
|
+
Customize new extensions based on theme and default extensions f codeMirror.
|
|
499
500
|
|
|
500
|
-
|
|
501
|
-
import { config } from 'md-editor-v3';
|
|
502
|
-
import { lineNumbers } from '@codemirror/view';
|
|
503
|
-
|
|
504
|
-
config({
|
|
505
|
-
codeMirrorExtensions(_theme, extensions) {
|
|
506
|
-
return [...extensions, lineNumbers()];
|
|
507
|
-
}
|
|
508
|
-
});
|
|
509
|
-
```
|
|
501
|
+
Example: Editor does not render the line number of textarea by default, this extension needs to be manually added
|
|
510
502
|
|
|
511
|
-
|
|
503
|
+
```js
|
|
504
|
+
import { config } from 'md-editor-v3';
|
|
505
|
+
import { lineNumbers } from '@codemirror/view';
|
|
512
506
|
|
|
513
|
-
|
|
507
|
+
config({
|
|
508
|
+
codeMirrorExtensions(_theme, extensions) {
|
|
509
|
+
return [...extensions, lineNumbers()];
|
|
510
|
+
}
|
|
511
|
+
});
|
|
512
|
+
```
|
|
514
513
|
|
|
515
|
-
|
|
516
|
-
import { config } from 'md-editor-v3';
|
|
517
|
-
import ancher from 'markdown-it-anchor';
|
|
514
|
+
### markdownItConfig
|
|
518
515
|
|
|
519
|
-
|
|
520
|
-
markdownItConfig(mdit) {
|
|
521
|
-
mdit.use(ancher, {
|
|
522
|
-
permalink: true
|
|
523
|
-
});
|
|
524
|
-
}
|
|
525
|
-
});
|
|
526
|
-
```
|
|
516
|
+
Customize extensions, attributes of `markdown-it`, etc.
|
|
527
517
|
|
|
528
|
-
-
|
|
518
|
+
Example: Use `markdown-it-anchor` to render a hyperlink symbol to the right of the title
|
|
529
519
|
|
|
530
|
-
|
|
520
|
+
```js
|
|
521
|
+
import { config } from 'md-editor-v3';
|
|
522
|
+
import ancher from 'markdown-it-anchor';
|
|
531
523
|
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
...p,
|
|
541
|
-
options: {
|
|
542
|
-
...p.options,
|
|
543
|
-
classes: 'my-class'
|
|
544
|
-
}
|
|
545
|
-
};
|
|
546
|
-
}
|
|
524
|
+
config({
|
|
525
|
+
markdownItConfig(mdit) {
|
|
526
|
+
mdit.use(ancher, {
|
|
527
|
+
permalink: true
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
});
|
|
531
|
+
```
|
|
547
532
|
|
|
548
|
-
|
|
549
|
-
});
|
|
550
|
-
}
|
|
551
|
-
});
|
|
552
|
-
```
|
|
533
|
+
### markdownItPlugins
|
|
553
534
|
|
|
554
|
-
|
|
535
|
+
Select and add built-in plugins to `markdown-it`.
|
|
555
536
|
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
537
|
+
Example: Modify the class name of the image.
|
|
538
|
+
|
|
539
|
+
```js
|
|
540
|
+
import { config } from 'md-editor-v3';
|
|
541
|
+
|
|
542
|
+
config({
|
|
543
|
+
markdownItPlugins(plugins) {
|
|
544
|
+
return plugins.map((p) => {
|
|
545
|
+
if (p.type === 'image') {
|
|
546
|
+
return {
|
|
547
|
+
...p,
|
|
548
|
+
options: {
|
|
549
|
+
...p.options,
|
|
550
|
+
classes: 'my-class'
|
|
551
|
+
}
|
|
552
|
+
};
|
|
553
|
+
}
|
|
571
554
|
|
|
572
|
-
|
|
555
|
+
return p;
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
});
|
|
559
|
+
```
|
|
573
560
|
|
|
574
|
-
|
|
575
|
-
import { config } from 'md-editor-v3';
|
|
561
|
+
### editorConfig
|
|
576
562
|
|
|
577
|
-
|
|
578
|
-
editorExtensions: { iconfont: 'https://xxx.cc' }
|
|
579
|
-
});
|
|
580
|
-
```
|
|
563
|
+
Add more languages, reset `mermaid` template or delay rendering time:
|
|
581
564
|
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
565
|
+
```js
|
|
566
|
+
import { config } from 'md-editor-v3';
|
|
567
|
+
|
|
568
|
+
config({
|
|
569
|
+
editorConfig: {
|
|
570
|
+
languageUserDefined: { lang: StaticTextDefaultValue },
|
|
571
|
+
mermaidTemplate: {
|
|
572
|
+
flow: `flow tempalte`,
|
|
573
|
+
...more
|
|
574
|
+
},
|
|
575
|
+
// Default 500ms. It is set to 0ms when preview only and not set.
|
|
576
|
+
renderDelay: 500
|
|
577
|
+
}
|
|
578
|
+
});
|
|
579
|
+
```
|
|
580
|
+
|
|
581
|
+
### editorExtensions
|
|
582
|
+
|
|
583
|
+
Config some dependency libraries, like highlight..
|
|
584
|
+
|
|
585
|
+
```typescript
|
|
586
|
+
import { config } from 'md-editor-v3';
|
|
587
|
+
|
|
588
|
+
config({
|
|
589
|
+
editorExtensions: { iconfont: 'https://xxx.cc' }
|
|
590
|
+
});
|
|
591
|
+
```
|
|
592
|
+
|
|
593
|
+
<details>
|
|
594
|
+
<summary>『EditorExtensions』</summary>
|
|
595
|
+
|
|
596
|
+
```ts
|
|
597
|
+
export interface EditorExtensions {
|
|
598
|
+
highlight?: {
|
|
599
|
+
instance?: any;
|
|
600
|
+
js?: string;
|
|
601
|
+
css?: {
|
|
602
|
+
[key: string]: {
|
|
603
|
+
light: string;
|
|
604
|
+
dark: string;
|
|
595
605
|
};
|
|
596
606
|
};
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
}
|
|
621
|
-
|
|
607
|
+
};
|
|
608
|
+
prettier?: {
|
|
609
|
+
standaloneJs?: string;
|
|
610
|
+
parserMarkdownJs?: string;
|
|
611
|
+
};
|
|
612
|
+
cropper?: {
|
|
613
|
+
instance?: any;
|
|
614
|
+
js?: string;
|
|
615
|
+
css?: string;
|
|
616
|
+
};
|
|
617
|
+
iconfont?: string;
|
|
618
|
+
screenfull?: {
|
|
619
|
+
instance?: any;
|
|
620
|
+
js?: string;
|
|
621
|
+
};
|
|
622
|
+
mermaid?: {
|
|
623
|
+
instance?: any;
|
|
624
|
+
js?: string;
|
|
625
|
+
};
|
|
626
|
+
katex?: {
|
|
627
|
+
instance?: any;
|
|
628
|
+
js?: string;
|
|
629
|
+
css?: string;
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
```
|
|
633
|
+
|
|
634
|
+
</details>
|
|
635
|
+
|
|
636
|
+
### iconfontType
|
|
637
|
+
|
|
638
|
+
Set the way to display icons:
|
|
639
|
+
|
|
640
|
+
- `svg`: with symbol
|
|
641
|
+
- `class`: with font-class
|
|
622
642
|
|
|
623
|
-
|
|
643
|
+
If the icon is customized through the attribute `customIcon`, the customized icon will be used first.
|
|
624
644
|
|
|
625
645
|
## 🪡 Shortcut Key
|
|
626
646
|
|
package/lib/cjs/MdCatalog.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const o=require("vue"),C=require("@vavt/util"),h=require("./chunks/config.cjs"),T=require("./chunks/
|
|
1
|
+
"use strict";const o=require("vue"),C=require("@vavt/util"),h=require("./chunks/config.cjs"),T=require("./chunks/index4.cjs"),x={tocItem:{type:Object,default:()=>({})},mdHeadingId:{type:Function,default:()=>{}},scrollElement:{type:[String,Object],default:""},onClick:{type:Function,default:()=>{}},scrollElementOffsetTop:{type:Number,default:0}},y=o.defineComponent({props:x,setup(l){return()=>{const{tocItem:c,mdHeadingId:d,scrollElement:n,onClick:u,scrollElementOffsetTop:p}=l;return o.createVNode("div",{class:[`${h.prefix}-catalog-link`,c.active&&`${h.prefix}-catalog-active`],onClick:r=>{u(r,c),r.stopPropagation();const E=d(c.text,c.level,c.index),m=document.getElementById(E),e=n instanceof Element?n:document.querySelector(n);if(m&&e){let t=m.offsetParent,s=m.offsetTop;if(e.contains(t))for(;t&&e!=t;)s+=t==null?void 0:t.offsetTop,t=t==null?void 0:t.offsetParent;e==null||e.scrollTo({top:s-p,behavior:"smooth"})}}},[o.createVNode("span",{title:c.text},[c.text]),o.createVNode("div",{class:`${h.prefix}-catalog-wrapper`},[c.children&&c.children.map(r=>o.createVNode(y,{mdHeadingId:d,key:`${c.text}-link-${r.level}-${r.text}`,tocItem:r,scrollElement:n,onClick:u,scrollElementOffsetTop:p},null))])])}}}),H=y,$={editorId:{type:String},class:{type:String,default:""},mdHeadingId:{type:Function,default:l=>l},scrollElement:{type:[String,Object]},theme:{type:String,default:"light"},offsetTop:{type:Number,default:20},scrollElementOffsetTop:{type:Number,default:0},onClick:{type:Function}},b=o.defineComponent({name:"MdCatalog",props:$,emits:["onClick"],setup(l,c){const d=l.editorId,n=o.reactive({list:[],show:!1,scrollElement:l.scrollElement||`#${d}-preview-wrapper`}),u=o.shallowRef(),p=o.computed(()=>{const e=[];return n.list.forEach((t,s)=>{const{text:g,level:I}=t,i={level:I,text:g,index:s+1,active:u.value===t};if(e.length===0)e.push(i);else{let a=e[e.length-1];if(i.level>a.level)for(let f=a.level+1;f<=6;f++){const{children:v}=a;if(!v){a.children=[i];break}if(a=v[v.length-1],i.level<=a.level){v.push(i);break}}else e.push(i)}}),e}),r=()=>n.scrollElement instanceof HTMLElement?n.scrollElement:document.querySelector(n.scrollElement),E=C.throttle(e=>{if(e.length===0)return n.list=[],!1;const{activeHead:t}=e.reduce((s,g,I)=>{const i=document.getElementById(l.mdHeadingId(g.text,g.level,I+1));if(i instanceof HTMLElement){const a=r(),f=T.getRelativeTop(i,a);if(f<l.offsetTop&&f>s.minTop)return{activeHead:g,minTop:f}}return s},{activeHead:e[0],minTop:Number.MIN_SAFE_INTEGER});u.value=t,n.list=e}),m=()=>{E(n.list)};return o.onMounted(()=>{var t;const e=r();(t=e===document.documentElement?window:e)==null||t.addEventListener("scroll",m),T.bus.on(d,{name:"catalogChanged",callback:s=>{E(s)}}),T.bus.emit(d,"pushCatalog")}),o.onBeforeUnmount(()=>{var t;const e=r();(t=e===document.documentElement?window:e)==null||t.removeEventListener("scroll",m)}),()=>o.createVNode("div",{class:`${h.prefix}-catalog${l.theme==="dark"?"-dark":""} ${l.class}`},[p.value.map(e=>o.createVNode(H,{mdHeadingId:l.mdHeadingId,tocItem:e,key:`link-${e.level}-${e.text}`,scrollElement:n.scrollElement,onClick:(t,s)=>{l.onClick?l.onClick(t,s):c.emit("onClick",t,s)},scrollElementOffsetTop:l.scrollElementOffsetTop},null))])}}),k=b;k.install=l=>(l.component(k.name,k),l);module.exports=k;
|