md-editor-v3 5.4.5 → 5.5.0-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.
@@ -2916,7 +2916,8 @@ const Content = /* @__PURE__ */ vue.defineComponent({
2916
2916
  smoothScroll(scroller, top);
2917
2917
  }
2918
2918
  }
2919
- }
2919
+ },
2920
+ "catalogMaxDepth": props2.catalogMaxDepth
2920
2921
  }, null)]);
2921
2922
  };
2922
2923
  }
@@ -3239,7 +3240,8 @@ const Editor = /* @__PURE__ */ vue.defineComponent({
3239
3240
  (_a = props2.onRemount) == null ? void 0 : _a.call(props2);
3240
3241
  ctx.emit("onRemount");
3241
3242
  },
3242
- "catalogLayout": props2.catalogLayout
3243
+ "catalogLayout": props2.catalogLayout,
3244
+ "catalogMaxDepth": props2.catalogMaxDepth
3243
3245
  }, null), props2.footers.length > 0 && vue.createVNode(Footer, {
3244
3246
  "modelValue": props2.modelValue,
3245
3247
  "footers": props2.footers,
@@ -323,15 +323,22 @@ const mergeAttrs = (token, addAttrs) => {
323
323
  });
324
324
  return tmpAttrs;
325
325
  };
326
- const math_inline = (state, silent) => {
327
- const delimiters = [
326
+ const delimiters = {
327
+ block: [
328
+ { open: "$$", close: "$$" },
329
+ { open: "\\[", close: "\\]" }
330
+ ],
331
+ inline: [
328
332
  { open: "$$", close: "$$" },
329
333
  { open: "$", close: "$" },
330
334
  { open: "\\[", close: "\\]" },
331
335
  { open: "\\(", close: "\\)" }
332
- ];
336
+ ]
337
+ };
338
+ const create_math_inline = (options) => (state, silent) => {
339
+ const delimiters2 = options.delimiters;
333
340
  let match, token, pos;
334
- for (const delim of delimiters) {
341
+ for (const delim of delimiters2) {
335
342
  if (state.src.startsWith(delim.open, state.pos)) {
336
343
  const start = state.pos + delim.open.length;
337
344
  match = start;
@@ -371,15 +378,12 @@ const math_inline = (state, silent) => {
371
378
  }
372
379
  return false;
373
380
  };
374
- const math_block = (state, start, end, silent) => {
375
- const delimiters = [
376
- { open: "$$", close: "$$" },
377
- { open: "\\[", close: "\\]" }
378
- ];
381
+ const create_math_block = (options) => (state, start, end, silent) => {
382
+ const delimiters2 = options.delimiters;
379
383
  let firstLine, lastLine, next, lastPos, found = false;
380
384
  let pos = state.bMarks[start] + state.tShift[start];
381
385
  let max = state.eMarks[start];
382
- for (const delim of delimiters) {
386
+ for (const delim of delimiters2) {
383
387
  if (state.src.slice(pos, pos + delim.open.length) === delim.open && state.src.slice(max - delim.close.length, max) === delim.close) {
384
388
  pos += delim.open.length;
385
389
  firstLine = state.src.slice(pos, max);
@@ -417,7 +421,7 @@ const math_block = (state, start, end, silent) => {
417
421
  }
418
422
  return false;
419
423
  };
420
- const KatexPlugin = (md, { katexRef }) => {
424
+ const KatexPlugin = (md, { katexRef, inlineDelimiters, blockDelimiters }) => {
421
425
  const katexInline = (tokens, idx, options, env, slf) => {
422
426
  const token = tokens[idx];
423
427
  const tmpToken = {
@@ -453,10 +457,23 @@ const KatexPlugin = (md, { katexRef }) => {
453
457
  return `<p ${slf.renderAttrs(tmpToken)}>${token.content}</p>`;
454
458
  }
455
459
  };
456
- md.inline.ruler.before("escape", "math_inline", math_inline);
457
- md.block.ruler.after("blockquote", "math_block", math_block, {
458
- alt: ["paragraph", "reference", "blockquote", "list"]
459
- });
460
+ md.inline.ruler.before(
461
+ "escape",
462
+ "math_inline",
463
+ create_math_inline({
464
+ delimiters: inlineDelimiters || delimiters.inline
465
+ })
466
+ );
467
+ md.block.ruler.after(
468
+ "blockquote",
469
+ "math_block",
470
+ create_math_block({
471
+ delimiters: blockDelimiters || delimiters.block
472
+ }),
473
+ {
474
+ alt: ["paragraph", "reference", "blockquote", "list"]
475
+ }
476
+ );
460
477
  md.renderer.rules.math_inline = katexInline;
461
478
  md.renderer.rules.math_block = katexBlock;
462
479
  };
@@ -1265,6 +1282,9 @@ const contentProps = {
1265
1282
  },
1266
1283
  catalogLayout: {
1267
1284
  type: String
1285
+ },
1286
+ catalogMaxDepth: {
1287
+ type: Number
1268
1288
  }
1269
1289
  };
1270
1290
  const splitNodes = (html) => {
@@ -2308,6 +2328,13 @@ const editorProps = {
2308
2328
  catalogLayout: {
2309
2329
  type: String,
2310
2330
  default: "fixed"
2331
+ },
2332
+ /**
2333
+ * 控制最大显示的目录层级
2334
+ */
2335
+ catalogMaxDepth: {
2336
+ type: Number,
2337
+ default: void 0
2311
2338
  }
2312
2339
  };
2313
2340
  const mdPreviewEmits = [
@@ -446,6 +446,13 @@ const props = {
446
446
  syncWith: {
447
447
  type: String,
448
448
  default: "preview"
449
+ },
450
+ /**
451
+ * 控制最大显示的目录层级
452
+ */
453
+ catalogMaxDepth: {
454
+ type: Number,
455
+ default: void 0
449
456
  }
450
457
  };
451
458
  const MdCatalog = /* @__PURE__ */ vue.defineComponent({
@@ -472,6 +479,9 @@ const MdCatalog = /* @__PURE__ */ vue.defineComponent({
472
479
  const catalogs = vue.computed(() => {
473
480
  const tocItems = [];
474
481
  state.list.forEach((listItem, index2) => {
482
+ if (props2.catalogMaxDepth && listItem.level > props2.catalogMaxDepth) {
483
+ return;
484
+ }
475
485
  const {
476
486
  text,
477
487
  level,
@@ -584,7 +594,7 @@ const MdCatalog = /* @__PURE__ */ vue.defineComponent({
584
594
  const getEditorView = (view) => {
585
595
  editorViewRef.value = view;
586
596
  };
587
- vue.watch([() => props2.syncWith, editorViewRef], () => {
597
+ vue.watch([() => props2.syncWith, editorViewRef, () => props2.catalogMaxDepth], () => {
588
598
  catalogChangedHandler(state.list);
589
599
  });
590
600
  vue.onMounted(() => {
@@ -2915,7 +2915,8 @@ const Content = /* @__PURE__ */ defineComponent({
2915
2915
  smoothScroll(scroller, top);
2916
2916
  }
2917
2917
  }
2918
- }
2918
+ },
2919
+ "catalogMaxDepth": props2.catalogMaxDepth
2919
2920
  }, null)]);
2920
2921
  };
2921
2922
  }
@@ -3238,7 +3239,8 @@ const Editor = /* @__PURE__ */ defineComponent({
3238
3239
  (_a = props2.onRemount) == null ? void 0 : _a.call(props2);
3239
3240
  ctx.emit("onRemount");
3240
3241
  },
3241
- "catalogLayout": props2.catalogLayout
3242
+ "catalogLayout": props2.catalogLayout,
3243
+ "catalogMaxDepth": props2.catalogMaxDepth
3242
3244
  }, null), props2.footers.length > 0 && createVNode(Footer, {
3243
3245
  "modelValue": props2.modelValue,
3244
3246
  "footers": props2.footers,
@@ -322,15 +322,22 @@ const mergeAttrs = (token, addAttrs) => {
322
322
  });
323
323
  return tmpAttrs;
324
324
  };
325
- const math_inline = (state, silent) => {
326
- const delimiters = [
325
+ const delimiters = {
326
+ block: [
327
+ { open: "$$", close: "$$" },
328
+ { open: "\\[", close: "\\]" }
329
+ ],
330
+ inline: [
327
331
  { open: "$$", close: "$$" },
328
332
  { open: "$", close: "$" },
329
333
  { open: "\\[", close: "\\]" },
330
334
  { open: "\\(", close: "\\)" }
331
- ];
335
+ ]
336
+ };
337
+ const create_math_inline = (options) => (state, silent) => {
338
+ const delimiters2 = options.delimiters;
332
339
  let match, token, pos;
333
- for (const delim of delimiters) {
340
+ for (const delim of delimiters2) {
334
341
  if (state.src.startsWith(delim.open, state.pos)) {
335
342
  const start = state.pos + delim.open.length;
336
343
  match = start;
@@ -370,15 +377,12 @@ const math_inline = (state, silent) => {
370
377
  }
371
378
  return false;
372
379
  };
373
- const math_block = (state, start, end, silent) => {
374
- const delimiters = [
375
- { open: "$$", close: "$$" },
376
- { open: "\\[", close: "\\]" }
377
- ];
380
+ const create_math_block = (options) => (state, start, end, silent) => {
381
+ const delimiters2 = options.delimiters;
378
382
  let firstLine, lastLine, next, lastPos, found = false;
379
383
  let pos = state.bMarks[start] + state.tShift[start];
380
384
  let max = state.eMarks[start];
381
- for (const delim of delimiters) {
385
+ for (const delim of delimiters2) {
382
386
  if (state.src.slice(pos, pos + delim.open.length) === delim.open && state.src.slice(max - delim.close.length, max) === delim.close) {
383
387
  pos += delim.open.length;
384
388
  firstLine = state.src.slice(pos, max);
@@ -416,7 +420,7 @@ const math_block = (state, start, end, silent) => {
416
420
  }
417
421
  return false;
418
422
  };
419
- const KatexPlugin = (md, { katexRef }) => {
423
+ const KatexPlugin = (md, { katexRef, inlineDelimiters, blockDelimiters }) => {
420
424
  const katexInline = (tokens, idx, options, env, slf) => {
421
425
  const token = tokens[idx];
422
426
  const tmpToken = {
@@ -452,10 +456,23 @@ const KatexPlugin = (md, { katexRef }) => {
452
456
  return `<p ${slf.renderAttrs(tmpToken)}>${token.content}</p>`;
453
457
  }
454
458
  };
455
- md.inline.ruler.before("escape", "math_inline", math_inline);
456
- md.block.ruler.after("blockquote", "math_block", math_block, {
457
- alt: ["paragraph", "reference", "blockquote", "list"]
458
- });
459
+ md.inline.ruler.before(
460
+ "escape",
461
+ "math_inline",
462
+ create_math_inline({
463
+ delimiters: inlineDelimiters || delimiters.inline
464
+ })
465
+ );
466
+ md.block.ruler.after(
467
+ "blockquote",
468
+ "math_block",
469
+ create_math_block({
470
+ delimiters: blockDelimiters || delimiters.block
471
+ }),
472
+ {
473
+ alt: ["paragraph", "reference", "blockquote", "list"]
474
+ }
475
+ );
459
476
  md.renderer.rules.math_inline = katexInline;
460
477
  md.renderer.rules.math_block = katexBlock;
461
478
  };
@@ -1264,6 +1281,9 @@ const contentProps = {
1264
1281
  },
1265
1282
  catalogLayout: {
1266
1283
  type: String
1284
+ },
1285
+ catalogMaxDepth: {
1286
+ type: Number
1267
1287
  }
1268
1288
  };
1269
1289
  const splitNodes = (html) => {
@@ -2307,6 +2327,13 @@ const editorProps = {
2307
2327
  catalogLayout: {
2308
2328
  type: String,
2309
2329
  default: "fixed"
2330
+ },
2331
+ /**
2332
+ * 控制最大显示的目录层级
2333
+ */
2334
+ catalogMaxDepth: {
2335
+ type: Number,
2336
+ default: void 0
2310
2337
  }
2311
2338
  };
2312
2339
  const mdPreviewEmits = [
@@ -445,6 +445,13 @@ const props = {
445
445
  syncWith: {
446
446
  type: String,
447
447
  default: "preview"
448
+ },
449
+ /**
450
+ * 控制最大显示的目录层级
451
+ */
452
+ catalogMaxDepth: {
453
+ type: Number,
454
+ default: void 0
448
455
  }
449
456
  };
450
457
  const MdCatalog = /* @__PURE__ */ defineComponent({
@@ -471,6 +478,9 @@ const MdCatalog = /* @__PURE__ */ defineComponent({
471
478
  const catalogs = computed(() => {
472
479
  const tocItems = [];
473
480
  state.list.forEach((listItem, index) => {
481
+ if (props2.catalogMaxDepth && listItem.level > props2.catalogMaxDepth) {
482
+ return;
483
+ }
474
484
  const {
475
485
  text,
476
486
  level,
@@ -583,7 +593,7 @@ const MdCatalog = /* @__PURE__ */ defineComponent({
583
593
  const getEditorView = (view) => {
584
594
  editorViewRef.value = view;
585
595
  };
586
- watch([() => props2.syncWith, editorViewRef], () => {
596
+ watch([() => props2.syncWith, editorViewRef, () => props2.catalogMaxDepth], () => {
587
597
  catalogChangedHandler(state.list);
588
598
  });
589
599
  onMounted(() => {
package/lib/preview.css CHANGED
@@ -142,6 +142,7 @@
142
142
  fill: none;
143
143
  overflow: hidden;
144
144
  display: block;
145
+ box-sizing: content-box;
145
146
  }.md-editor .lucide-list-icon,
146
147
  .md-editor .lucide-list-ordered-icon,
147
148
  .md-editor .lucide-list-todo-icon {
package/lib/style.css CHANGED
@@ -592,6 +592,7 @@
592
592
  fill: none;
593
593
  overflow: hidden;
594
594
  display: block;
595
+ box-sizing: content-box;
595
596
  }.md-editor .lucide-list-icon,
596
597
  .md-editor .lucide-list-ordered-icon,
597
598
  .md-editor .lucide-list-todo-icon {
@@ -12,6 +12,7 @@ declare const MdCatalog: import("vue").DefineComponent<{
12
12
  readonly isScrollElementInShadow: boolean;
13
13
  readonly syncWith: "preview" | "editor";
14
14
  readonly onClick: ((e: MouseEvent, t: TocItem) => void) | undefined;
15
+ readonly catalogMaxDepth: number | undefined;
15
16
  readonly editorId: string | undefined;
16
17
  readonly onActive: ((heading: HeadList | undefined, activeElement: HTMLDivElement) => void) | undefined;
17
18
  readonly scrollElement: string | HTMLElement | undefined;
@@ -24,6 +25,7 @@ declare const MdCatalog: import("vue").DefineComponent<{
24
25
  readonly isScrollElementInShadow: boolean;
25
26
  readonly syncWith: "preview" | "editor";
26
27
  readonly onClick: ((e: MouseEvent, t: TocItem) => void) | undefined;
28
+ readonly catalogMaxDepth: number | undefined;
27
29
  readonly editorId: string | undefined;
28
30
  readonly onActive: ((heading: HeadList | undefined, activeElement: HTMLDivElement) => void) | undefined;
29
31
  readonly scrollElement: string | HTMLElement | undefined;
@@ -33,6 +35,7 @@ declare const MdCatalog: import("vue").DefineComponent<{
33
35
  }>, {
34
36
  onClick: (e: MouseEvent, t: TocItem) => void;
35
37
  class: string;
38
+ catalogMaxDepth: number;
36
39
  theme: Themes;
37
40
  editorId: string;
38
41
  mdHeadingId: MdHeadingId;
@@ -266,6 +266,7 @@ declare const Editor: import("vue").DefineComponent<{
266
266
  }> | undefined;
267
267
  readonly maxLength: number | undefined;
268
268
  readonly completions: import("@codemirror/autocomplete").CompletionSource[] | undefined;
269
+ readonly catalogMaxDepth: number | undefined;
269
270
  readonly editorId: string | undefined;
270
271
  }, () => import("vue/jsx-runtime").JSX.Element, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, import("./type").EditorEmits, "onChange" | "onSave" | "onUploadImg" | "onHtmlChanged" | "onGetCatalog" | "onError" | "update:modelValue" | "onBlur" | "onFocus" | "onInput" | "onDrop" | "oninputBoxWidthChange" | "onRemount", import("vue").PublicProps, Readonly<{
271
272
  readonly preview: boolean;
@@ -535,6 +536,7 @@ declare const Editor: import("vue").DefineComponent<{
535
536
  }> | undefined;
536
537
  readonly maxLength: number | undefined;
537
538
  readonly completions: import("@codemirror/autocomplete").CompletionSource[] | undefined;
539
+ readonly catalogMaxDepth: number | undefined;
538
540
  readonly editorId: string | undefined;
539
541
  }> & Readonly<{
540
542
  onOnChange?: ((...args: any[]) => any) | undefined;
@@ -595,6 +597,7 @@ declare const Editor: import("vue").DefineComponent<{
595
597
  inputBoxWidth: string;
596
598
  transformImgUrl: (t: string) => string | Promise<string>;
597
599
  catalogLayout: "fixed" | "flat";
600
+ catalogMaxDepth: number;
598
601
  modelValue: string;
599
602
  theme: import("./type").Themes;
600
603
  editorId: string;
@@ -28,6 +28,7 @@ declare const _default: import("vue").DefineComponent<{
28
28
  readonly completions: import("@codemirror/autocomplete").CompletionSource[] | undefined;
29
29
  readonly inputBoxWidth: string | undefined;
30
30
  readonly catalogLayout: "fixed" | "flat" | undefined;
31
+ readonly catalogMaxDepth: number | undefined;
31
32
  readonly noImgZoomIn: boolean | undefined;
32
33
  readonly sanitizeMermaid: ((h: string) => Promise<string>) | undefined;
33
34
  readonly codeFoldable: boolean | undefined;
@@ -66,6 +67,7 @@ declare const _default: import("vue").DefineComponent<{
66
67
  readonly completions: import("@codemirror/autocomplete").CompletionSource[] | undefined;
67
68
  readonly inputBoxWidth: string | undefined;
68
69
  readonly catalogLayout: "fixed" | "flat" | undefined;
70
+ readonly catalogMaxDepth: number | undefined;
69
71
  readonly noImgZoomIn: boolean | undefined;
70
72
  readonly sanitizeMermaid: ((h: string) => Promise<string>) | undefined;
71
73
  readonly codeFoldable: boolean | undefined;
@@ -5,7 +5,16 @@
5
5
  */
6
6
  import { ShallowRef } from 'vue';
7
7
  import markdownit from 'markdown-it';
8
- declare const KatexPlugin: (md: markdownit, { katexRef }: {
8
+ interface KatexOptions {
9
9
  katexRef: ShallowRef;
10
- }) => void;
10
+ inlineDelimiters?: Array<{
11
+ open: string;
12
+ close: string;
13
+ }>;
14
+ blockDelimiters?: Array<{
15
+ open: string;
16
+ close: string;
17
+ }>;
18
+ }
19
+ declare const KatexPlugin: (md: markdownit, { katexRef, inlineDelimiters, blockDelimiters }: KatexOptions) => void;
11
20
  export default KatexPlugin;
@@ -143,6 +143,9 @@ export declare const contentProps: {
143
143
  catalogLayout: {
144
144
  type: PropType<"fixed" | "flat">;
145
145
  };
146
+ catalogMaxDepth: {
147
+ type: PropType<number>;
148
+ };
146
149
  modelValue: {
147
150
  type: PropType<string>;
148
151
  default: string;
@@ -514,6 +514,13 @@ export declare const editorProps: {
514
514
  type: PropType<"fixed" | "flat">;
515
515
  default: string;
516
516
  };
517
+ /**
518
+ * 控制最大显示的目录层级
519
+ */
520
+ catalogMaxDepth: {
521
+ type: PropType<number>;
522
+ default: undefined;
523
+ };
517
524
  /**
518
525
  * markdown content.
519
526
  *