md-editor-v3 4.18.0 → 4.19.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.
@@ -139,16 +139,16 @@ const useHighlight = (props) => {
139
139
  );
140
140
  return hljsRef;
141
141
  };
142
+ const mermaidCache = new LRUCache({
143
+ max: 1e3,
144
+ // 缓存10分钟
145
+ ttl: 6e5
146
+ });
142
147
  const useMermaid = (props) => {
143
148
  const theme = inject("theme");
144
149
  const { editorExtensions, editorExtensionsAttrs, mermaidConfig } = configOption;
145
150
  const mermaidRef = shallowRef(editorExtensions.mermaid.instance);
146
151
  const reRenderRef = shallowRef(-1);
147
- const mermaidCache = new LRUCache({
148
- max: 1e3,
149
- // 缓存10分钟
150
- ttl: 6e5
151
- });
152
152
  const configMermaid = () => {
153
153
  const mermaid = mermaidRef.value;
154
154
  if (!props.noMermaid && mermaid) {
@@ -290,6 +290,10 @@ const MermaidPlugin = (md, options) => {
290
290
  line = tokens[idx].map[0];
291
291
  tokens[idx].attrSet("data-line", String(line));
292
292
  }
293
+ const mermaidHtml = mermaidCache.get(code);
294
+ if (mermaidHtml) {
295
+ return `<p class="${prefix}-mermaid" ${line !== void 0 ? "data-line=" + line : ""} data-processed>${mermaidHtml}</p>`;
296
+ }
293
297
  return `<div class="${prefix}-mermaid" ${line !== void 0 ? "data-line=" + line : ""} data-mermaid-theme=${options.themeRef.value}>${code}</div>`;
294
298
  }
295
299
  return temp(tokens, idx, ops, env, slf);
@@ -309,117 +313,100 @@ const mergeAttrs = (token, addAttrs) => {
309
313
  });
310
314
  return tmpAttrs;
311
315
  };
312
- const isValidDelim = (state, pos) => {
313
- let can_open = true, can_close = true;
314
- const max = state.posMax;
315
- const prevChar = pos > 0 ? state.src.charCodeAt(pos - 1) : -1;
316
- const nextChar = pos + 1 <= max ? state.src.charCodeAt(pos + 1) : -1;
317
- if (prevChar === 32 || prevChar === 9 || nextChar >= 48 && nextChar <= 57) {
318
- can_close = false;
319
- }
320
- if (nextChar === 32 || nextChar === 9) {
321
- can_open = false;
322
- }
323
- return {
324
- can_open,
325
- can_close
326
- };
327
- };
328
316
  const math_inline = (state, silent) => {
329
- let match, token, res, pos;
330
- if (state.src[state.pos] !== "$") {
331
- return false;
332
- }
333
- res = isValidDelim(state, state.pos);
334
- if (!res.can_open) {
335
- if (!silent) {
336
- state.pending += "$";
337
- }
338
- state.pos += 1;
339
- return true;
340
- }
341
- const start = state.pos + 1;
342
- match = start;
343
- while ((match = state.src.indexOf("$", match)) !== -1) {
344
- pos = match - 1;
345
- while (state.src[pos] === "\\") {
346
- pos -= 1;
347
- }
348
- if ((match - pos) % 2 == 1) {
349
- break;
350
- }
351
- match += 1;
352
- }
353
- if (match === -1) {
354
- if (!silent) {
355
- state.pending += "$";
356
- }
357
- state.pos = start;
358
- return true;
359
- }
360
- if (match - start === 0) {
361
- if (!silent) {
362
- state.pending += "$$";
363
- }
364
- state.pos = start + 1;
365
- return true;
366
- }
367
- res = isValidDelim(state, match);
368
- if (!res.can_close) {
369
- if (!silent) {
370
- state.pending += "$";
317
+ const delimiters = [
318
+ { open: "$", close: "$" },
319
+ { open: "\\(", close: "\\)" }
320
+ ];
321
+ let match, token, pos;
322
+ for (const delim of delimiters) {
323
+ if (state.src.startsWith(delim.open, state.pos)) {
324
+ const start = state.pos + delim.open.length;
325
+ match = start;
326
+ while ((match = state.src.indexOf(delim.close, match)) !== -1) {
327
+ pos = match - 1;
328
+ while (state.src[pos] === "\\") {
329
+ pos -= 1;
330
+ }
331
+ if ((match - pos) % 2 == 1) {
332
+ break;
333
+ }
334
+ match += delim.close.length;
335
+ }
336
+ if (match === -1) {
337
+ if (!silent) {
338
+ state.pending += delim.open;
339
+ }
340
+ state.pos = start;
341
+ return true;
342
+ }
343
+ if (match - start === 0) {
344
+ if (!silent) {
345
+ state.pending += delim.open + delim.close;
346
+ }
347
+ state.pos = start + delim.close.length;
348
+ return true;
349
+ }
350
+ if (!silent) {
351
+ token = state.push("math_inline", "math", 0);
352
+ token.markup = delim.open;
353
+ token.content = state.src.slice(start, match);
354
+ }
355
+ state.pos = match + delim.close.length;
356
+ return true;
371
357
  }
372
- state.pos = start;
373
- return true;
374
358
  }
375
- if (!silent) {
376
- token = state.push("math_inline", "math", 0);
377
- token.markup = "$";
378
- token.content = state.src.slice(start, match);
379
- }
380
- state.pos = match + 1;
381
- return true;
359
+ return false;
382
360
  };
383
361
  const math_block = (state, start, end, silent) => {
384
- let firstLine, lastLine, next, lastPos, found = false, pos = state.bMarks[start] + state.tShift[start], max = state.eMarks[start];
385
- if (pos + 2 > max) {
386
- return false;
387
- }
388
- if (state.src.slice(pos, pos + 2) !== "$$") {
389
- return false;
390
- }
391
- pos += 2;
392
- firstLine = state.src.slice(pos, max);
393
- if (silent) {
394
- return true;
395
- }
396
- if (firstLine.trim().slice(-2) === "$$") {
397
- firstLine = firstLine.trim().slice(0, -2);
398
- found = true;
399
- }
400
- for (next = start; !found; ) {
401
- next++;
402
- if (next >= end) {
403
- break;
362
+ const delimiters = [
363
+ { open: "$$", close: "$$" },
364
+ { open: "\\[", close: "\\]" }
365
+ ];
366
+ let firstLine, lastLine, next, lastPos, found = false;
367
+ let pos = state.bMarks[start] + state.tShift[start];
368
+ let max = state.eMarks[start];
369
+ for (const delim of delimiters) {
370
+ if (pos + delim.open.length > max) {
371
+ continue;
404
372
  }
405
- pos = state.bMarks[next] + state.tShift[next];
406
- max = state.eMarks[next];
407
- if (pos < max && state.tShift[next] < state.blkIndent) {
408
- break;
373
+ if (state.src.slice(pos, pos + delim.open.length) !== delim.open) {
374
+ continue;
375
+ }
376
+ pos += delim.open.length;
377
+ firstLine = state.src.slice(pos, max);
378
+ if (silent) {
379
+ return true;
409
380
  }
410
- if (state.src.slice(pos, max).trim().slice(-2) === "$$") {
411
- lastPos = state.src.slice(0, max).lastIndexOf("$$");
412
- lastLine = state.src.slice(pos, lastPos);
381
+ if (firstLine.trim().slice(-delim.close.length) === delim.close) {
382
+ firstLine = firstLine.trim().slice(0, -delim.close.length);
413
383
  found = true;
414
384
  }
385
+ for (next = start; !found; ) {
386
+ next++;
387
+ if (next >= end) {
388
+ break;
389
+ }
390
+ pos = state.bMarks[next] + state.tShift[next];
391
+ max = state.eMarks[next];
392
+ if (pos < max && state.tShift[next] < state.blkIndent) {
393
+ break;
394
+ }
395
+ if (state.src.slice(pos, max).trim().slice(-delim.close.length) === delim.close) {
396
+ lastPos = state.src.slice(0, max).lastIndexOf(delim.close);
397
+ lastLine = state.src.slice(pos, lastPos);
398
+ found = true;
399
+ }
400
+ }
401
+ state.line = next + 1;
402
+ const token = state.push("math_block", "math", 0);
403
+ token.block = true;
404
+ token.content = (firstLine && firstLine.trim() ? firstLine + "\n" : "") + state.getLines(start + 1, next, state.tShift[start], true) + (lastLine && lastLine.trim() ? lastLine : "");
405
+ token.map = [start, state.line];
406
+ token.markup = delim.open;
407
+ return true;
415
408
  }
416
- state.line = next + 1;
417
- const token = state.push("math_block", "math", 0);
418
- token.block = true;
419
- token.content = (firstLine && firstLine.trim() ? firstLine + "\n" : "") + state.getLines(start + 1, next, state.tShift[start], true) + (lastLine && lastLine.trim() ? lastLine : "");
420
- token.map = [start, state.line];
421
- token.markup = "$$";
422
- return true;
409
+ return false;
423
410
  };
424
411
  const KatexPlugin = (md, { katexRef }) => {
425
412
  const katexInline = (tokens, idx, options, env, slf) => {
@@ -428,9 +415,12 @@ const KatexPlugin = (md, { katexRef }) => {
428
415
  attrs: mergeAttrs(token, [["class", `${prefix}-katex-inline`]])
429
416
  };
430
417
  if (katexRef.value) {
431
- const html = katexRef.value.renderToString(token.content, {
432
- throwOnError: false
433
- });
418
+ const html = katexRef.value.renderToString(
419
+ token.content,
420
+ configOption.katexConfig({
421
+ throwOnError: false
422
+ })
423
+ );
434
424
  return `<span ${slf.renderAttrs(tmpToken)} data-processed>${html}</span>`;
435
425
  } else {
436
426
  return `<span ${slf.renderAttrs(tmpToken)}>${token.content}</span>`;
@@ -442,16 +432,19 @@ const KatexPlugin = (md, { katexRef }) => {
442
432
  attrs: mergeAttrs(token, [["class", `${prefix}-katex-block`]])
443
433
  };
444
434
  if (katexRef.value) {
445
- const html = katexRef.value.renderToString(token.content, {
446
- throwOnError: false,
447
- displayMode: true
448
- });
435
+ const html = katexRef.value.renderToString(
436
+ token.content,
437
+ configOption.katexConfig({
438
+ throwOnError: false,
439
+ displayMode: true
440
+ })
441
+ );
449
442
  return `<p ${slf.renderAttrs(tmpToken)} data-processed>${html}</p>`;
450
443
  } else {
451
444
  return `<p ${slf.renderAttrs(tmpToken)}>${token.content}</p>`;
452
445
  }
453
446
  };
454
- md.inline.ruler.after("escape", "math_inline", math_inline);
447
+ md.inline.ruler.before("escape", "math_inline", math_inline);
455
448
  md.block.ruler.after("blockquote", "math_block", math_block, {
456
449
  alt: ["paragraph", "reference", "blockquote", "list"]
457
450
  });
package/lib/preview.css CHANGED
@@ -2,7 +2,7 @@
2
2
  --md-color: #3f4a54;
3
3
  --md-hover-color: #000;
4
4
  --md-bk-color: #fff;
5
- --md-bk-color-outstand: #f6f6f6;
5
+ --md-bk-color-outstand: #f2f2f2;
6
6
  --md-bk-hover-color: #f5f7fa;
7
7
  --md-border-color: #e6e6e6;
8
8
  --md-border-hover-color: #b9b9b9;
@@ -60,7 +60,7 @@
60
60
  --md-color: #999;
61
61
  --md-hover-color: #bbb;
62
62
  --md-bk-color: #000;
63
- --md-bk-color-outstand: #111;
63
+ --md-bk-color-outstand: #333;
64
64
  --md-bk-hover-color: #1b1a1a;
65
65
  --md-border-color: #2d2d2d;
66
66
  --md-border-hover-color: #636262;
@@ -75,7 +75,7 @@
75
75
  --md-color: #3f4a54;
76
76
  --md-hover-color: #000;
77
77
  --md-bk-color: #fff;
78
- --md-bk-color-outstand: #f6f6f6;
78
+ --md-bk-color-outstand: #f2f2f2;
79
79
  --md-bk-hover-color: #f5f7fa;
80
80
  --md-border-color: #e6e6e6;
81
81
  --md-border-hover-color: #b9b9b9;
@@ -147,7 +147,7 @@
147
147
  --md-color: #3f4a54;
148
148
  --md-hover-color: #000;
149
149
  --md-bk-color: #fff;
150
- --md-bk-color-outstand: #f6f6f6;
150
+ --md-bk-color-outstand: #f2f2f2;
151
151
  --md-bk-hover-color: #f5f7fa;
152
152
  --md-border-color: #e6e6e6;
153
153
  --md-border-hover-color: #b9b9b9;
@@ -188,7 +188,7 @@
188
188
  --md-color: #999;
189
189
  --md-hover-color: #bbb;
190
190
  --md-bk-color: #000;
191
- --md-bk-color-outstand: #111;
191
+ --md-bk-color-outstand: #333;
192
192
  --md-bk-hover-color: #1b1a1a;
193
193
  --md-border-color: #2d2d2d;
194
194
  --md-border-hover-color: #636262;
package/lib/style.css CHANGED
@@ -313,9 +313,10 @@
313
313
  box-sizing: content-box;
314
314
  }.md-editor-toolbar-wrapper .md-editor-toolbar-item {
315
315
  display: inline-block;
316
- padding: 0 4px;
316
+ margin: 0 2px;
317
+ padding: 0 2px;
317
318
  transition: all 0.3s;
318
- border-radius: 0;
319
+ border-radius: 3px;
319
320
  cursor: pointer;
320
321
  list-style: none;
321
322
  user-select: none;
@@ -325,7 +326,8 @@
325
326
  word-break: keep-all;
326
327
  white-space: nowrap;
327
328
  }.md-editor-toolbar-wrapper .md-editor-toolbar-item:hover {
328
- border-radius: 3px;
329
+ background-color: var(--md-bk-color-outstand);
330
+ }.md-editor-toolbar-wrapper .md-editor-toolbar-active {
329
331
  background-color: var(--md-bk-color-outstand);
330
332
  }.md-editor-toolbar-wrapper .md-editor-toolbar-left,
331
333
  .md-editor-toolbar-wrapper .md-editor-toolbar-right {
@@ -441,7 +443,7 @@
441
443
  --md-color: #3f4a54;
442
444
  --md-hover-color: #000;
443
445
  --md-bk-color: #fff;
444
- --md-bk-color-outstand: #f6f6f6;
446
+ --md-bk-color-outstand: #f2f2f2;
445
447
  --md-bk-hover-color: #f5f7fa;
446
448
  --md-border-color: #e6e6e6;
447
449
  --md-border-hover-color: #b9b9b9;
@@ -499,7 +501,7 @@
499
501
  --md-color: #999;
500
502
  --md-hover-color: #bbb;
501
503
  --md-bk-color: #000;
502
- --md-bk-color-outstand: #111;
504
+ --md-bk-color-outstand: #333;
503
505
  --md-bk-hover-color: #1b1a1a;
504
506
  --md-border-color: #2d2d2d;
505
507
  --md-border-hover-color: #636262;
@@ -514,7 +516,7 @@
514
516
  --md-color: #3f4a54;
515
517
  --md-hover-color: #000;
516
518
  --md-bk-color: #fff;
517
- --md-bk-color-outstand: #f6f6f6;
519
+ --md-bk-color-outstand: #f2f2f2;
518
520
  --md-bk-hover-color: #f5f7fa;
519
521
  --md-border-color: #e6e6e6;
520
522
  --md-border-hover-color: #b9b9b9;
@@ -586,7 +588,7 @@
586
588
  --md-color: #3f4a54;
587
589
  --md-hover-color: #000;
588
590
  --md-bk-color: #fff;
589
- --md-bk-color-outstand: #f6f6f6;
591
+ --md-bk-color-outstand: #f2f2f2;
590
592
  --md-bk-hover-color: #f5f7fa;
591
593
  --md-border-color: #e6e6e6;
592
594
  --md-border-hover-color: #b9b9b9;
@@ -627,7 +629,7 @@
627
629
  --md-color: #999;
628
630
  --md-hover-color: #bbb;
629
631
  --md-bk-color: #000;
630
- --md-bk-color-outstand: #111;
632
+ --md-bk-color-outstand: #333;
631
633
  --md-bk-hover-color: #1b1a1a;
632
634
  --md-border-color: #2d2d2d;
633
635
  --md-border-hover-color: #636262;
@@ -1,6 +1,6 @@
1
1
  import { ComputedRef } from 'vue';
2
- import { Themes } from '../../../../type';
3
2
  import markdownit from 'markdown-it';
3
+ import { Themes } from '../../../../type';
4
4
  declare const MermaidPlugin: (md: markdownit, options: {
5
5
  themeRef: ComputedRef<Themes>;
6
6
  }) => void;
@@ -43,6 +43,9 @@ declare const _default: import("vue").DefineComponent<{
43
43
  showToolbarName: {
44
44
  type: import("vue").PropType<boolean>;
45
45
  };
46
+ catalogVisible: {
47
+ type: import("vue").PropType<boolean>;
48
+ };
46
49
  }, () => import("vue/jsx-runtime").JSX.Element, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
47
50
  noPrettier: {
48
51
  type: import("vue").PropType<boolean>;
@@ -86,6 +89,9 @@ declare const _default: import("vue").DefineComponent<{
86
89
  showToolbarName: {
87
90
  type: import("vue").PropType<boolean>;
88
91
  };
92
+ catalogVisible: {
93
+ type: import("vue").PropType<boolean>;
94
+ };
89
95
  }>>, {
90
96
  toolbars: ToolbarNames[];
91
97
  toolbarsExclude: ToolbarNames[];
@@ -49,5 +49,8 @@ export declare const toolbarProps: {
49
49
  showToolbarName: {
50
50
  type: PropType<boolean>;
51
51
  };
52
+ catalogVisible: {
53
+ type: PropType<boolean>;
54
+ };
52
55
  };
53
56
  export type ToolbarProps = Readonly<LooseRequired<Readonly<ExtractPropTypes<typeof toolbarProps>>>>;
@@ -306,6 +306,13 @@ export interface ConfigOption {
306
306
  * @returns
307
307
  */
308
308
  mermaidConfig: (base: any) => any;
309
+ /**
310
+ * katex配置
311
+ *
312
+ * @param baseConfig
313
+ * @returns
314
+ */
315
+ katexConfig: (baseConfig: any) => any;
309
316
  }
310
317
  /**
311
318
  * 扩展编辑器内部功能,包括marked和一些内部依赖实例,如highlight、cropper等
@@ -0,0 +1,2 @@
1
+ import { LRUCache } from 'lru-cache';
2
+ export declare const mermaidCache: LRUCache<{}, {}, unknown>;