md-editor-v3 4.18.1 → 4.19.0-1

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
@@ -768,6 +768,23 @@ config({
768
768
  });
769
769
  ```
770
770
 
771
+ ### 🔧 katexConfig
772
+
773
+ Configure `katex`, [Details](https://katex.org/docs/options)
774
+
775
+ ```js
776
+ import { config } from 'md-editor-v3';
777
+
778
+ config({
779
+ katexConfig(base: any) {
780
+ return {
781
+ ...base,
782
+ strict: false
783
+ };
784
+ }
785
+ });
786
+ ```
787
+
771
788
  ## 🪡 Shortcut Key
772
789
 
773
790
  _Pay attention: shortcut keys are only available when the textarea has received focus!_
@@ -1008,7 +1025,7 @@ const onUploadImg = async (files, callback) => {
1008
1025
  --md-color: if(@isDark, #999, #222);
1009
1026
  --md-hover-color: if(@isDark, #bbb, #000);
1010
1027
  --md-bk-color: if(@isDark, #000, #fff);
1011
- --md-bk-color-outstand: if(@isDark, #111, #f6f6f6);
1028
+ --md-bk-color-outstand: if(@isDark, #333, #f2f2f2);
1012
1029
  --md-bk-hover-color: if(@isDark, #1b1a1a, #f5f7fa);
1013
1030
  --md-border-color: if(@isDark, #2d2d2d, #e6e6e6);
1014
1031
  --md-border-hover-color: if(@isDark, #636262, #b9b9b9);
@@ -83,6 +83,9 @@ const toolbarProps = {
83
83
  */
84
84
  showToolbarName: {
85
85
  type: Boolean
86
+ },
87
+ catalogVisible: {
88
+ type: Boolean
86
89
  }
87
90
  };
88
91
  const useSreenfull = (props2) => {
@@ -167,8 +170,11 @@ const TableShape = /* @__PURE__ */ vue.defineComponent({
167
170
  x: -1,
168
171
  y: -1
169
172
  });
173
+ const tableShapeStr = vue.computed(() => {
174
+ return JSON.stringify(props2.tableShape);
175
+ });
170
176
  const initShape = () => {
171
- const shape = [...props2.tableShape];
177
+ const shape = [...JSON.parse(tableShapeStr.value)];
172
178
  if (!shape[2] || shape[2] < shape[0]) {
173
179
  shape[2] = shape[0];
174
180
  }
@@ -178,7 +184,7 @@ const TableShape = /* @__PURE__ */ vue.defineComponent({
178
184
  return shape;
179
185
  };
180
186
  const tableShape = vue.ref(initShape());
181
- vue.watch(() => props2.tableShape, () => {
187
+ vue.watch([tableShapeStr], () => {
182
188
  tableShape.value = initShape();
183
189
  });
184
190
  return () => vue.createVNode("div", {
@@ -948,7 +954,7 @@ const ToolBar = /* @__PURE__ */ vue.defineComponent({
948
954
  }
949
955
  case "pageFullscreen": {
950
956
  return !props2.setting.fullscreen && vue.createVNode("div", {
951
- "class": `${config.prefix}-toolbar-item`,
957
+ "class": [`${config.prefix}-toolbar-item`, props2.setting.pageFullscreen && `${config.prefix}-toolbar-active`],
952
958
  "title": (_T = ult.value.toolbarTips) == null ? void 0 : _T.pageFullscreen,
953
959
  "onClick": () => {
954
960
  props2.updateSetting("pageFullscreen");
@@ -961,7 +967,7 @@ const ToolBar = /* @__PURE__ */ vue.defineComponent({
961
967
  }
962
968
  case "fullscreen": {
963
969
  return vue.createVNode("div", {
964
- "class": `${config.prefix}-toolbar-item`,
970
+ "class": [`${config.prefix}-toolbar-item`, props2.setting.fullscreen && `${config.prefix}-toolbar-active`],
965
971
  "title": (_V = ult.value.toolbarTips) == null ? void 0 : _V.fullscreen,
966
972
  "onClick": () => {
967
973
  fullscreenHandler();
@@ -974,7 +980,7 @@ const ToolBar = /* @__PURE__ */ vue.defineComponent({
974
980
  }
975
981
  case "preview": {
976
982
  return vue.createVNode("div", {
977
- "class": `${config.prefix}-toolbar-item`,
983
+ "class": [`${config.prefix}-toolbar-item`, props2.setting.preview && `${config.prefix}-toolbar-active`],
978
984
  "title": (_X = ult.value.toolbarTips) == null ? void 0 : _X.preview,
979
985
  "onClick": () => {
980
986
  props2.updateSetting("preview");
@@ -987,7 +993,7 @@ const ToolBar = /* @__PURE__ */ vue.defineComponent({
987
993
  }
988
994
  case "previewOnly": {
989
995
  return vue.createVNode("div", {
990
- "class": `${config.prefix}-toolbar-item`,
996
+ "class": [`${config.prefix}-toolbar-item`, props2.setting.previewOnly && `${config.prefix}-toolbar-active`],
991
997
  "title": (_Z = ult.value.toolbarTips) == null ? void 0 : _Z.previewOnly,
992
998
  "onClick": () => {
993
999
  props2.updateSetting("previewOnly");
@@ -1000,7 +1006,7 @@ const ToolBar = /* @__PURE__ */ vue.defineComponent({
1000
1006
  }
1001
1007
  case "htmlPreview": {
1002
1008
  return vue.createVNode("div", {
1003
- "class": `${config.prefix}-toolbar-item`,
1009
+ "class": [`${config.prefix}-toolbar-item`, props2.setting.htmlPreview && `${config.prefix}-toolbar-active`],
1004
1010
  "title": (_$ = ult.value.toolbarTips) == null ? void 0 : _$.htmlPreview,
1005
1011
  "onClick": () => {
1006
1012
  props2.updateSetting("htmlPreview");
@@ -1013,7 +1019,7 @@ const ToolBar = /* @__PURE__ */ vue.defineComponent({
1013
1019
  }
1014
1020
  case "catalog": {
1015
1021
  return vue.createVNode("div", {
1016
- "class": `${config.prefix}-toolbar-item`,
1022
+ "class": [`${config.prefix}-toolbar-item`, props2.catalogVisible && `${config.prefix}-toolbar-active`],
1017
1023
  "title": (_ba = ult.value.toolbarTips) == null ? void 0 : _ba.catalog,
1018
1024
  "onClick": () => {
1019
1025
  eventName.bus.emit(editorId, eventName.CHANGE_CATALOG_VISIBLE);
@@ -2081,8 +2087,8 @@ const createAutocompletion = (completions) => {
2081
2087
  from: word.from,
2082
2088
  options: [
2083
2089
  // 标题
2084
- ...["h1", "h2", "h3", "h4", "h5", "h6"].map((key, index2) => {
2085
- const label = new Array(index2 + 1).fill("#").join("");
2090
+ ...["h2", "h3", "h4", "h5", "h6"].map((key, index2) => {
2091
+ const label = new Array(index2 + 2).fill("#").join("");
2086
2092
  return {
2087
2093
  label,
2088
2094
  type: "text",
@@ -3209,7 +3215,8 @@ const Editor = /* @__PURE__ */ vue.defineComponent({
3209
3215
  "tableShape": props2.tableShape,
3210
3216
  "defToolbars": defToolbars,
3211
3217
  "noUploadImg": noUploadImg,
3212
- "showToolbarName": props2.showToolbarName
3218
+ "showToolbarName": props2.showToolbarName,
3219
+ "catalogVisible": catalogVisible.value
3213
3220
  }, null), vue.createVNode(Content, {
3214
3221
  "ref": codeRef,
3215
3222
  "modelValue": props2.modelValue,
@@ -432,7 +432,8 @@ const configOption = {
432
432
  },
433
433
  markdownItPlugins: (s) => s,
434
434
  iconfontType: "svg",
435
- mermaidConfig: (c) => c
435
+ mermaidConfig: (c) => c,
436
+ katexConfig: (c) => c
436
437
  };
437
438
  const config = (option) => {
438
439
  return util.deepMerge(configOption, option);
@@ -314,117 +314,100 @@ const mergeAttrs = (token, addAttrs) => {
314
314
  });
315
315
  return tmpAttrs;
316
316
  };
317
- const isValidDelim = (state, pos) => {
318
- let can_open = true, can_close = true;
319
- const max = state.posMax;
320
- const prevChar = pos > 0 ? state.src.charCodeAt(pos - 1) : -1;
321
- const nextChar = pos + 1 <= max ? state.src.charCodeAt(pos + 1) : -1;
322
- if (prevChar === 32 || prevChar === 9 || nextChar >= 48 && nextChar <= 57) {
323
- can_close = false;
324
- }
325
- if (nextChar === 32 || nextChar === 9) {
326
- can_open = false;
327
- }
328
- return {
329
- can_open,
330
- can_close
331
- };
332
- };
333
317
  const math_inline = (state, silent) => {
334
- let match, token, res, pos;
335
- if (state.src[state.pos] !== "$") {
336
- return false;
337
- }
338
- res = isValidDelim(state, state.pos);
339
- if (!res.can_open) {
340
- if (!silent) {
341
- state.pending += "$";
342
- }
343
- state.pos += 1;
344
- return true;
345
- }
346
- const start = state.pos + 1;
347
- match = start;
348
- while ((match = state.src.indexOf("$", match)) !== -1) {
349
- pos = match - 1;
350
- while (state.src[pos] === "\\") {
351
- pos -= 1;
352
- }
353
- if ((match - pos) % 2 == 1) {
354
- break;
355
- }
356
- match += 1;
357
- }
358
- if (match === -1) {
359
- if (!silent) {
360
- state.pending += "$";
361
- }
362
- state.pos = start;
363
- return true;
364
- }
365
- if (match - start === 0) {
366
- if (!silent) {
367
- state.pending += "$$";
368
- }
369
- state.pos = start + 1;
370
- return true;
371
- }
372
- res = isValidDelim(state, match);
373
- if (!res.can_close) {
374
- if (!silent) {
375
- state.pending += "$";
318
+ const delimiters = [
319
+ { open: "$", close: "$" },
320
+ { open: "\\(", close: "\\)" }
321
+ ];
322
+ let match, token, pos;
323
+ for (const delim of delimiters) {
324
+ if (state.src.startsWith(delim.open, state.pos)) {
325
+ const start = state.pos + delim.open.length;
326
+ match = start;
327
+ while ((match = state.src.indexOf(delim.close, match)) !== -1) {
328
+ pos = match - 1;
329
+ while (state.src[pos] === "\\") {
330
+ pos -= 1;
331
+ }
332
+ if ((match - pos) % 2 == 1) {
333
+ break;
334
+ }
335
+ match += delim.close.length;
336
+ }
337
+ if (match === -1) {
338
+ if (!silent) {
339
+ state.pending += delim.open;
340
+ }
341
+ state.pos = start;
342
+ return true;
343
+ }
344
+ if (match - start === 0) {
345
+ if (!silent) {
346
+ state.pending += delim.open + delim.close;
347
+ }
348
+ state.pos = start + delim.close.length;
349
+ return true;
350
+ }
351
+ if (!silent) {
352
+ token = state.push("math_inline", "math", 0);
353
+ token.markup = delim.open;
354
+ token.content = state.src.slice(start, match);
355
+ }
356
+ state.pos = match + delim.close.length;
357
+ return true;
376
358
  }
377
- state.pos = start;
378
- return true;
379
359
  }
380
- if (!silent) {
381
- token = state.push("math_inline", "math", 0);
382
- token.markup = "$";
383
- token.content = state.src.slice(start, match);
384
- }
385
- state.pos = match + 1;
386
- return true;
360
+ return false;
387
361
  };
388
362
  const math_block = (state, start, end, silent) => {
389
- let firstLine, lastLine, next, lastPos, found = false, pos = state.bMarks[start] + state.tShift[start], max = state.eMarks[start];
390
- if (pos + 2 > max) {
391
- return false;
392
- }
393
- if (state.src.slice(pos, pos + 2) !== "$$") {
394
- return false;
395
- }
396
- pos += 2;
397
- firstLine = state.src.slice(pos, max);
398
- if (silent) {
399
- return true;
400
- }
401
- if (firstLine.trim().slice(-2) === "$$") {
402
- firstLine = firstLine.trim().slice(0, -2);
403
- found = true;
404
- }
405
- for (next = start; !found; ) {
406
- next++;
407
- if (next >= end) {
408
- break;
363
+ const delimiters = [
364
+ { open: "$$", close: "$$" },
365
+ { open: "\\[", close: "\\]" }
366
+ ];
367
+ let firstLine, lastLine, next, lastPos, found = false;
368
+ let pos = state.bMarks[start] + state.tShift[start];
369
+ let max = state.eMarks[start];
370
+ for (const delim of delimiters) {
371
+ if (pos + delim.open.length > max) {
372
+ continue;
409
373
  }
410
- pos = state.bMarks[next] + state.tShift[next];
411
- max = state.eMarks[next];
412
- if (pos < max && state.tShift[next] < state.blkIndent) {
413
- break;
374
+ if (state.src.slice(pos, pos + delim.open.length) !== delim.open) {
375
+ continue;
414
376
  }
415
- if (state.src.slice(pos, max).trim().slice(-2) === "$$") {
416
- lastPos = state.src.slice(0, max).lastIndexOf("$$");
417
- lastLine = state.src.slice(pos, lastPos);
377
+ pos += delim.open.length;
378
+ firstLine = state.src.slice(pos, max);
379
+ if (silent) {
380
+ return true;
381
+ }
382
+ if (firstLine.trim().slice(-delim.close.length) === delim.close) {
383
+ firstLine = firstLine.trim().slice(0, -delim.close.length);
418
384
  found = true;
419
385
  }
386
+ for (next = start; !found; ) {
387
+ next++;
388
+ if (next >= end) {
389
+ break;
390
+ }
391
+ pos = state.bMarks[next] + state.tShift[next];
392
+ max = state.eMarks[next];
393
+ if (pos < max && state.tShift[next] < state.blkIndent) {
394
+ break;
395
+ }
396
+ if (state.src.slice(pos, max).trim().slice(-delim.close.length) === delim.close) {
397
+ lastPos = state.src.slice(0, max).lastIndexOf(delim.close);
398
+ lastLine = state.src.slice(pos, lastPos);
399
+ found = true;
400
+ }
401
+ }
402
+ state.line = next + 1;
403
+ const token = state.push("math_block", "math", 0);
404
+ token.block = true;
405
+ token.content = (firstLine && firstLine.trim() ? firstLine + "\n" : "") + state.getLines(start + 1, next, state.tShift[start], true) + (lastLine && lastLine.trim() ? lastLine : "");
406
+ token.map = [start, state.line];
407
+ token.markup = delim.open;
408
+ return true;
420
409
  }
421
- state.line = next + 1;
422
- const token = state.push("math_block", "math", 0);
423
- token.block = true;
424
- token.content = (firstLine && firstLine.trim() ? firstLine + "\n" : "") + state.getLines(start + 1, next, state.tShift[start], true) + (lastLine && lastLine.trim() ? lastLine : "");
425
- token.map = [start, state.line];
426
- token.markup = "$$";
427
- return true;
410
+ return false;
428
411
  };
429
412
  const KatexPlugin = (md, { katexRef }) => {
430
413
  const katexInline = (tokens, idx, options, env, slf) => {
@@ -433,9 +416,12 @@ const KatexPlugin = (md, { katexRef }) => {
433
416
  attrs: mergeAttrs(token, [["class", `${config.prefix}-katex-inline`]])
434
417
  };
435
418
  if (katexRef.value) {
436
- const html = katexRef.value.renderToString(token.content, {
437
- throwOnError: false
438
- });
419
+ const html = katexRef.value.renderToString(
420
+ token.content,
421
+ config.configOption.katexConfig({
422
+ throwOnError: false
423
+ })
424
+ );
439
425
  return `<span ${slf.renderAttrs(tmpToken)} data-processed>${html}</span>`;
440
426
  } else {
441
427
  return `<span ${slf.renderAttrs(tmpToken)}>${token.content}</span>`;
@@ -447,16 +433,19 @@ const KatexPlugin = (md, { katexRef }) => {
447
433
  attrs: mergeAttrs(token, [["class", `${config.prefix}-katex-block`]])
448
434
  };
449
435
  if (katexRef.value) {
450
- const html = katexRef.value.renderToString(token.content, {
451
- throwOnError: false,
452
- displayMode: true
453
- });
436
+ const html = katexRef.value.renderToString(
437
+ token.content,
438
+ config.configOption.katexConfig({
439
+ throwOnError: false,
440
+ displayMode: true
441
+ })
442
+ );
454
443
  return `<p ${slf.renderAttrs(tmpToken)} data-processed>${html}</p>`;
455
444
  } else {
456
445
  return `<p ${slf.renderAttrs(tmpToken)}>${token.content}</p>`;
457
446
  }
458
447
  };
459
- md.inline.ruler.after("escape", "math_inline", math_inline);
448
+ md.inline.ruler.before("escape", "math_inline", math_inline);
460
449
  md.block.ruler.after("blockquote", "math_block", math_block, {
461
450
  alt: ["paragraph", "reference", "blockquote", "list"]
462
451
  });
@@ -4,7 +4,7 @@ var __publicField = (obj, key, value) => {
4
4
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
5
  return value;
6
6
  };
7
- import { defineComponent, createVNode, inject, ref, onMounted, reactive, watch, computed, nextTick, Fragment, cloneVNode, toRef, shallowRef, onBeforeUnmount } from "vue";
7
+ import { defineComponent, createVNode, inject, ref, onMounted, reactive, computed, watch, nextTick, Fragment, cloneVNode, toRef, shallowRef, onBeforeUnmount } from "vue";
8
8
  import { p as prefix, f as configOption, b as allToolbar, M as MinInputBoxWidth, d as allFooter } from "./chunks/config.mjs";
9
9
  import { draggingScroll, linkTo, debounce, createSmoothScroll, throttle } from "@vavt/util";
10
10
  import { a as Dropdown, D as DropdownToolbar } from "./chunks/index2.mjs";
@@ -82,6 +82,9 @@ const toolbarProps = {
82
82
  */
83
83
  showToolbarName: {
84
84
  type: Boolean
85
+ },
86
+ catalogVisible: {
87
+ type: Boolean
85
88
  }
86
89
  };
87
90
  const useSreenfull = (props2) => {
@@ -166,8 +169,11 @@ const TableShape = /* @__PURE__ */ defineComponent({
166
169
  x: -1,
167
170
  y: -1
168
171
  });
172
+ const tableShapeStr = computed(() => {
173
+ return JSON.stringify(props2.tableShape);
174
+ });
169
175
  const initShape = () => {
170
- const shape = [...props2.tableShape];
176
+ const shape = [...JSON.parse(tableShapeStr.value)];
171
177
  if (!shape[2] || shape[2] < shape[0]) {
172
178
  shape[2] = shape[0];
173
179
  }
@@ -177,7 +183,7 @@ const TableShape = /* @__PURE__ */ defineComponent({
177
183
  return shape;
178
184
  };
179
185
  const tableShape = ref(initShape());
180
- watch(() => props2.tableShape, () => {
186
+ watch([tableShapeStr], () => {
181
187
  tableShape.value = initShape();
182
188
  });
183
189
  return () => createVNode("div", {
@@ -947,7 +953,7 @@ const ToolBar = /* @__PURE__ */ defineComponent({
947
953
  }
948
954
  case "pageFullscreen": {
949
955
  return !props2.setting.fullscreen && createVNode("div", {
950
- "class": `${prefix}-toolbar-item`,
956
+ "class": [`${prefix}-toolbar-item`, props2.setting.pageFullscreen && `${prefix}-toolbar-active`],
951
957
  "title": (_T = ult.value.toolbarTips) == null ? void 0 : _T.pageFullscreen,
952
958
  "onClick": () => {
953
959
  props2.updateSetting("pageFullscreen");
@@ -960,7 +966,7 @@ const ToolBar = /* @__PURE__ */ defineComponent({
960
966
  }
961
967
  case "fullscreen": {
962
968
  return createVNode("div", {
963
- "class": `${prefix}-toolbar-item`,
969
+ "class": [`${prefix}-toolbar-item`, props2.setting.fullscreen && `${prefix}-toolbar-active`],
964
970
  "title": (_V = ult.value.toolbarTips) == null ? void 0 : _V.fullscreen,
965
971
  "onClick": () => {
966
972
  fullscreenHandler();
@@ -973,7 +979,7 @@ const ToolBar = /* @__PURE__ */ defineComponent({
973
979
  }
974
980
  case "preview": {
975
981
  return createVNode("div", {
976
- "class": `${prefix}-toolbar-item`,
982
+ "class": [`${prefix}-toolbar-item`, props2.setting.preview && `${prefix}-toolbar-active`],
977
983
  "title": (_X = ult.value.toolbarTips) == null ? void 0 : _X.preview,
978
984
  "onClick": () => {
979
985
  props2.updateSetting("preview");
@@ -986,7 +992,7 @@ const ToolBar = /* @__PURE__ */ defineComponent({
986
992
  }
987
993
  case "previewOnly": {
988
994
  return createVNode("div", {
989
- "class": `${prefix}-toolbar-item`,
995
+ "class": [`${prefix}-toolbar-item`, props2.setting.previewOnly && `${prefix}-toolbar-active`],
990
996
  "title": (_Z = ult.value.toolbarTips) == null ? void 0 : _Z.previewOnly,
991
997
  "onClick": () => {
992
998
  props2.updateSetting("previewOnly");
@@ -999,7 +1005,7 @@ const ToolBar = /* @__PURE__ */ defineComponent({
999
1005
  }
1000
1006
  case "htmlPreview": {
1001
1007
  return createVNode("div", {
1002
- "class": `${prefix}-toolbar-item`,
1008
+ "class": [`${prefix}-toolbar-item`, props2.setting.htmlPreview && `${prefix}-toolbar-active`],
1003
1009
  "title": (_$ = ult.value.toolbarTips) == null ? void 0 : _$.htmlPreview,
1004
1010
  "onClick": () => {
1005
1011
  props2.updateSetting("htmlPreview");
@@ -1012,7 +1018,7 @@ const ToolBar = /* @__PURE__ */ defineComponent({
1012
1018
  }
1013
1019
  case "catalog": {
1014
1020
  return createVNode("div", {
1015
- "class": `${prefix}-toolbar-item`,
1021
+ "class": [`${prefix}-toolbar-item`, props2.catalogVisible && `${prefix}-toolbar-active`],
1016
1022
  "title": (_ba = ult.value.toolbarTips) == null ? void 0 : _ba.catalog,
1017
1023
  "onClick": () => {
1018
1024
  bus.emit(editorId, CHANGE_CATALOG_VISIBLE);
@@ -2080,8 +2086,8 @@ const createAutocompletion = (completions) => {
2080
2086
  from: word.from,
2081
2087
  options: [
2082
2088
  // 标题
2083
- ...["h1", "h2", "h3", "h4", "h5", "h6"].map((key, index) => {
2084
- const label = new Array(index + 1).fill("#").join("");
2089
+ ...["h2", "h3", "h4", "h5", "h6"].map((key, index) => {
2090
+ const label = new Array(index + 2).fill("#").join("");
2085
2091
  return {
2086
2092
  label,
2087
2093
  type: "text",
@@ -3208,7 +3214,8 @@ const Editor = /* @__PURE__ */ defineComponent({
3208
3214
  "tableShape": props2.tableShape,
3209
3215
  "defToolbars": defToolbars,
3210
3216
  "noUploadImg": noUploadImg,
3211
- "showToolbarName": props2.showToolbarName
3217
+ "showToolbarName": props2.showToolbarName,
3218
+ "catalogVisible": catalogVisible.value
3212
3219
  }, null), createVNode(Content, {
3213
3220
  "ref": codeRef,
3214
3221
  "modelValue": props2.modelValue,
@@ -431,7 +431,8 @@ const configOption = {
431
431
  },
432
432
  markdownItPlugins: (s) => s,
433
433
  iconfontType: "svg",
434
- mermaidConfig: (c) => c
434
+ mermaidConfig: (c) => c,
435
+ katexConfig: (c) => c
435
436
  };
436
437
  const config = (option) => {
437
438
  return deepMerge(configOption, option);