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 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
- - codeMirrorExtensions: Customize new extensions based on theme and default extensions f codeMirror.
497
+ ### codeMirrorExtensions
497
498
 
498
- Example: Editor does not render the line number of textarea by default, this extension needs to be manually added
499
+ Customize new extensions based on theme and default extensions f codeMirror.
499
500
 
500
- ```js
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
- - markdownItConfig: Customize extensions, attributes of `markdown-it`, etc.
503
+ ```js
504
+ import { config } from 'md-editor-v3';
505
+ import { lineNumbers } from '@codemirror/view';
512
506
 
513
- Example: Use `markdown-it-anchor` to render a hyperlink symbol to the right of the title
507
+ config({
508
+ codeMirrorExtensions(_theme, extensions) {
509
+ return [...extensions, lineNumbers()];
510
+ }
511
+ });
512
+ ```
514
513
 
515
- ```js
516
- import { config } from 'md-editor-v3';
517
- import ancher from 'markdown-it-anchor';
514
+ ### markdownItConfig
518
515
 
519
- config({
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
- - markdownItPlugins: Select and add built-in plugins to `markdown-it`.
518
+ Example: Use `markdown-it-anchor` to render a hyperlink symbol to the right of the title
529
519
 
530
- Example: Modify the class name of the image.
520
+ ```js
521
+ import { config } from 'md-editor-v3';
522
+ import ancher from 'markdown-it-anchor';
531
523
 
532
- ```js
533
- import { config } from 'md-editor-v3';
534
-
535
- config({
536
- markdownItPlugins(plugins) {
537
- return plugins.map((p) => {
538
- if (p.type === 'image') {
539
- return {
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
- return p;
549
- });
550
- }
551
- });
552
- ```
533
+ ### markdownItPlugins
553
534
 
554
- - editorConfig: Add more languages, reset `mermaid` template or delay rendering time:
535
+ Select and add built-in plugins to `markdown-it`.
555
536
 
556
- ```js
557
- import { config } from 'md-editor-v3';
558
-
559
- config({
560
- editorConfig: {
561
- languageUserDefined: { lang: StaticTextDefaultValue },
562
- mermaidTemplate: {
563
- flow: `flow tempalte`,
564
- ...more
565
- },
566
- // Default 500ms. It is set to 0ms when preview only and not set.
567
- renderDelay: 500
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
- - editorExtensions: Config some dependency libraries, like highlight..
555
+ return p;
556
+ });
557
+ }
558
+ });
559
+ ```
573
560
 
574
- ```typescript
575
- import { config } from 'md-editor-v3';
561
+ ### editorConfig
576
562
 
577
- config({
578
- editorExtensions: { iconfont: 'https://xxx.cc' }
579
- });
580
- ```
563
+ Add more languages, reset `mermaid` template or delay rendering time:
581
564
 
582
- <details>
583
- <summary>『EditorExtensions』</summary>
584
-
585
- ```ts
586
- export interface EditorExtensions {
587
- highlight?: {
588
- instance?: any;
589
- js?: string;
590
- css?: {
591
- [key: string]: {
592
- light: string;
593
- dark: string;
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
- prettier?: {
598
- standaloneJs?: string;
599
- parserMarkdownJs?: string;
600
- };
601
- cropper?: {
602
- instance?: any;
603
- js?: string;
604
- css?: string;
605
- };
606
- iconfont?: string;
607
- screenfull?: {
608
- instance?: any;
609
- js?: string;
610
- };
611
- mermaid?: {
612
- instance?: any;
613
- js?: string;
614
- };
615
- katex?: {
616
- instance?: any;
617
- js?: string;
618
- css?: string;
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
- </details>
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
 
@@ -1 +1 @@
1
- "use strict";const o=require("vue"),C=require("@vavt/util"),h=require("./chunks/config.cjs"),T=require("./chunks/index3.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;
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;