md-editor-v3 1.8.0 → 1.9.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
@@ -4,7 +4,7 @@
4
4
 
5
5
  English \| [中文](https://github.com/imzbf/md-editor-v3/blob/dev/README-CN.md)
6
6
 
7
- Markdown editor for vue3, developed by `jsx` and `typescript`.
7
+ Markdown editor for vue3, developed in `jsx` and `typescript`.
8
8
 
9
9
  - Documentation and demo:[Go](https://imzbf.github.io/md-editor-v3)
10
10
 
@@ -23,6 +23,7 @@ Markdown editor for vue3, developed by `jsx` and `typescript`.
23
23
  - Render article directly(no editor,no event listener, only preview content).
24
24
  - Preview themes, support `defalut`、`vuepress`、`github` styles(not identical).
25
25
  - `mermaid`(>=1.3.0).
26
+ - `katex` mathematical formula(>=1.9.0).
26
27
 
27
28
  > More features are developing, if you have some ideas or find issues, please tell it to me~
28
29
 
@@ -71,6 +72,10 @@ Markdown editor for vue3, developed by `jsx` and `typescript`.
71
72
  | mermaidJs<sup>v1.8.0</sup> | String | [mermaid@8.13.5](https://cdn.jsdelivr.net/npm/mermaid@8.13.5/dist/mermaid.min.js) | mermaidJs url |
72
73
  | noMermaid<sup>v1.8.0</sup> | Boolean | false | do not use mermaid |
73
74
  | placeholder<sup>v1.8.0</sup> | String | '' | |
75
+ | katex<sup>v1.9.0</sup> | Object | undefined | `katex` instance(you need import css by yourself.) |
76
+ | katexJs<sup>v1.9.0</sup> | String | [katex.min.js@0.15.1](https://cdn.jsdelivr.net/npm/katex@0.15.1/dist/katex.min.js) | katexJs url |
77
+ | katexCss<sup>v1.9.0</sup> | String | [katex.min.css@0.15.1](https://cdn.jsdelivr.net/npm/katex@0.15.1/dist/katex.min.css) | katexCss url |
78
+ | noKatex<sup>v1.9.0</sup> | Boolean | false | do not use katex |
74
79
 
75
80
  [toolbars]
76
81
 
@@ -94,6 +99,7 @@ Markdown editor for vue3, developed by `jsx` and `typescript`.
94
99
  'image',
95
100
  'table',
96
101
  'mermaid',
102
+ 'katex',
97
103
  '-',
98
104
  'revoke',
99
105
  'next',
@@ -132,6 +138,7 @@ export interface ToolbarTips {
132
138
  image?: string;
133
139
  table?: string;
134
140
  mermaid?: string;
141
+ katex?: string;
135
142
  revoke?: string;
136
143
  next?: string;
137
144
  save?: string;
@@ -194,6 +201,13 @@ export interface StaticTextDefaultValue {
194
201
  relationship?: string;
195
202
  journey?: string;
196
203
  };
204
+ // 1.9.0
205
+ katex?: {
206
+ // formula inline
207
+ inline: string;
208
+ // formula block
209
+ block: string;
210
+ };
197
211
  }
198
212
  ```
199
213
 
@@ -26,6 +26,7 @@ export interface ToolbarTips {
26
26
  image?: string;
27
27
  table?: string;
28
28
  mermaid?: string;
29
+ katex?: string;
29
30
  revoke?: string;
30
31
  next?: string;
31
32
  save?: string;
@@ -80,6 +81,10 @@ export interface StaticTextDefaultValue {
80
81
  relationship?: string;
81
82
  journey?: string;
82
83
  };
84
+ katex?: {
85
+ inline: string;
86
+ block: string;
87
+ };
83
88
  }
84
89
  export interface StaticTextDefault {
85
90
  'zh-CN': StaticTextDefaultValue;
@@ -273,6 +278,21 @@ declare const _default: import("vue").DefineComponent<{
273
278
  type: PropType<string>;
274
279
  default: string;
275
280
  };
281
+ katex: {
282
+ type: ObjectConstructor;
283
+ };
284
+ katexJs: {
285
+ type: PropType<string>;
286
+ default: string;
287
+ };
288
+ katexCss: {
289
+ type: PropType<string>;
290
+ default: string;
291
+ };
292
+ noKatex: {
293
+ type: PropType<boolean>;
294
+ default: boolean;
295
+ };
276
296
  }, () => JSX.Element, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, Record<string, any>, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<{
277
297
  modelValue?: unknown;
278
298
  theme?: unknown;
@@ -316,6 +336,10 @@ declare const _default: import("vue").DefineComponent<{
316
336
  noMermaid?: unknown;
317
337
  sanitize?: unknown;
318
338
  placeholder?: unknown;
339
+ katex?: unknown;
340
+ katexJs?: unknown;
341
+ katexCss?: unknown;
342
+ noKatex?: unknown;
319
343
  } & {
320
344
  editorId: string;
321
345
  prettier: boolean;
@@ -355,8 +379,12 @@ declare const _default: import("vue").DefineComponent<{
355
379
  noMermaid: boolean;
356
380
  sanitize: (html: string) => string;
357
381
  placeholder: string;
382
+ katexJs: string;
383
+ katexCss: string;
384
+ noKatex: boolean;
358
385
  } & {
359
386
  mermaid?: Record<string, any> | undefined;
387
+ katex?: Record<string, any> | undefined;
360
388
  onSave?: ((v: string) => void) | undefined;
361
389
  onChange?: ((v: string) => void) | undefined;
362
390
  onUploadImg?: ((files: FileList, callBack: (urls: string[]) => void) => void) | undefined;
@@ -401,5 +429,8 @@ declare const _default: import("vue").DefineComponent<{
401
429
  noMermaid: boolean;
402
430
  sanitize: (html: string) => string;
403
431
  placeholder: string;
432
+ katexJs: string;
433
+ katexCss: string;
434
+ noKatex: boolean;
404
435
  }>;
405
436
  export default _default;
@@ -22,7 +22,7 @@ var __publicField = (obj, key, value) => {
22
22
  return value;
23
23
  };
24
24
  import { onMounted, onBeforeUnmount, provide, computed, defineComponent, createVNode, reactive, ref, watch, cloneVNode, nextTick, inject, mergeProps, Fragment, Teleport } from "vue";
25
- const iconfontUrl = "//at.alicdn.com/t/font_2605852_ihjkm7wo1y.js";
25
+ const iconfontUrl = "//at.alicdn.com/t/font_2605852_pqekijay2ij.js";
26
26
  const highlightUrl = {
27
27
  atom: "https://cdn.jsdelivr.net/npm/highlight.js@11.2.0/styles/atom-one-dark.css",
28
28
  github: "https://cdn.jsdelivr.net/npm/highlight.js@11.2.0/styles/github.css",
@@ -57,6 +57,7 @@ const allToolbar = [
57
57
  "image",
58
58
  "table",
59
59
  "mermaid",
60
+ "katex",
60
61
  "-",
61
62
  "revoke",
62
63
  "next",
@@ -89,6 +90,7 @@ const staticTextDefault = {
89
90
  image: "\u56FE\u7247",
90
91
  table: "\u8868\u683C",
91
92
  mermaid: "mermaid\u56FE",
93
+ katex: "\u516C\u5F0F",
92
94
  revoke: "\u540E\u9000",
93
95
  next: "\u524D\u8FDB",
94
96
  save: "\u4FDD\u5B58",
@@ -138,6 +140,10 @@ const staticTextDefault = {
138
140
  pie: "\u997C\u56FE",
139
141
  relationship: "\u5173\u7CFB\u56FE",
140
142
  journey: "\u65C5\u7A0B\u56FE"
143
+ },
144
+ katex: {
145
+ inline: "\u884C\u5185\u516C\u5F0F",
146
+ block: "\u5757\u7EA7\u516C\u5F0F"
141
147
  }
142
148
  },
143
149
  "en-US": {
@@ -158,6 +164,7 @@ const staticTextDefault = {
158
164
  image: "image",
159
165
  table: "table",
160
166
  mermaid: "mermaid",
167
+ katex: "formula",
161
168
  revoke: "revoke",
162
169
  next: "undo revoke",
163
170
  save: "save",
@@ -207,10 +214,16 @@ const staticTextDefault = {
207
214
  pie: "pie",
208
215
  relationship: "relationship",
209
216
  journey: "journey"
217
+ },
218
+ katex: {
219
+ inline: "inline",
220
+ block: "block"
210
221
  }
211
222
  }
212
223
  };
213
224
  const mermaidUrl = "https://cdn.jsdelivr.net/npm/mermaid@8.13.5/dist/mermaid.min.js";
225
+ const katexJsUrl = "https://cdn.jsdelivr.net/npm/katex@0.15.1/dist/katex.min.js";
226
+ const katexCssUrl = "https://cdn.jsdelivr.net/npm/katex@0.15.1/dist/katex.min.css";
214
227
  class Bus {
215
228
  constructor() {
216
229
  __publicField(this, "pools", {});
@@ -678,7 +691,7 @@ const setPosition = (tarDom, startPos = 0, endPos = startPos) => {
678
691
  tarDom.focus();
679
692
  }, 0);
680
693
  } else {
681
- console.log("\u65E0\u6CD5\u91CD\u7F6E\u5149\u6807\u4F4D\u7F6E\uFF01");
694
+ console.log("can not reset position!");
682
695
  }
683
696
  };
684
697
  const insert = (dom, tarValue, params) => {
@@ -897,7 +910,6 @@ var Modal = defineComponent({
897
910
  keyMoveClear();
898
911
  });
899
912
  watch(() => props2.isFullscreen, (nVal) => {
900
- console.log(123);
901
913
  if (nVal) {
902
914
  keyMoveClear();
903
915
  } else {
@@ -1411,7 +1423,8 @@ var ToolBar = defineComponent({
1411
1423
  catalog: false,
1412
1424
  image: false,
1413
1425
  table: false,
1414
- mermaid: false
1426
+ mermaid: false,
1427
+ katex: false
1415
1428
  });
1416
1429
  const emitHandler = (direct, params) => {
1417
1430
  bus.emit(editorId, "replace", direct, params);
@@ -1454,7 +1467,7 @@ var ToolBar = defineComponent({
1454
1467
  uploadRef.value.addEventListener("change", uploadHandler);
1455
1468
  });
1456
1469
  const barRender = (barItem) => {
1457
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M;
1470
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O;
1458
1471
  switch (barItem) {
1459
1472
  case "-": {
1460
1473
  return createVNode(Divider, null, null);
@@ -1963,6 +1976,44 @@ var ToolBar = defineComponent({
1963
1976
  }
1964
1977
  });
1965
1978
  }
1979
+ case "katex": {
1980
+ return createVNode(Dropdown, {
1981
+ "visible": visible.katex,
1982
+ "onChange": (v) => {
1983
+ visible.katex = v;
1984
+ },
1985
+ "overlay": createVNode("ul", {
1986
+ "class": `${prefix}-menu`,
1987
+ "onClick": () => {
1988
+ visible.katex = false;
1989
+ }
1990
+ }, [createVNode("li", {
1991
+ "class": `${prefix}-menu-item`,
1992
+ "onClick": () => {
1993
+ emitHandler("katexInline");
1994
+ }
1995
+ }, [(_N = ult.value.katex) == null ? void 0 : _N.inline]), createVNode("li", {
1996
+ "class": `${prefix}-menu-item`,
1997
+ "onClick": () => {
1998
+ emitHandler("katexBlock");
1999
+ }
2000
+ }, [(_O = ult.value.katex) == null ? void 0 : _O.block])]),
2001
+ "key": "bar-katex"
2002
+ }, {
2003
+ default: () => {
2004
+ var _a2;
2005
+ return [createVNode("div", {
2006
+ "class": `${prefix}-toolbar-item`,
2007
+ "title": (_a2 = ult.value.toolbarTips) == null ? void 0 : _a2.mermaid
2008
+ }, [createVNode("svg", {
2009
+ "class": `${prefix}-icon`,
2010
+ "aria-hidden": "true"
2011
+ }, [createVNode("use", {
2012
+ "xlink:href": "#icon-formula"
2013
+ }, null)])])];
2014
+ }
2015
+ });
2016
+ }
1966
2017
  }
1967
2018
  };
1968
2019
  return () => {
@@ -4423,6 +4474,18 @@ journey
4423
4474
  deviationStart = 2;
4424
4475
  break;
4425
4476
  }
4477
+ case "katexInline": {
4478
+ targetValue = "$$";
4479
+ deviationStart = 1;
4480
+ deviationEnd = -1;
4481
+ break;
4482
+ }
4483
+ case "katexBlock": {
4484
+ targetValue = "$$\n\n$$\n";
4485
+ deviationStart = 1;
4486
+ deviationEnd = -4;
4487
+ break;
4488
+ }
4426
4489
  }
4427
4490
  }
4428
4491
  return insert(inputArea, targetValue, {
@@ -4433,6 +4496,74 @@ journey
4433
4496
  subfixVal
4434
4497
  });
4435
4498
  };
4499
+ var kaTexExtensions = {
4500
+ block(prefix2, katex) {
4501
+ return {
4502
+ name: "KaTexBlockExtension",
4503
+ level: "block",
4504
+ start: (text) => {
4505
+ var _a;
4506
+ return (_a = text.match(/\$\$\n/)) == null ? void 0 : _a.index;
4507
+ },
4508
+ tokenizer(text) {
4509
+ const reg = /^\$\$\n([^$]*)\$\$\n?/;
4510
+ const match = reg.exec(text);
4511
+ if (match) {
4512
+ const token = {
4513
+ type: "KaTexBlockExtension",
4514
+ raw: match[0],
4515
+ text: match[1].trim(),
4516
+ tokens: []
4517
+ };
4518
+ return token;
4519
+ }
4520
+ },
4521
+ renderer(token) {
4522
+ if (katex || window.katex) {
4523
+ const html = (katex || window.katex).renderToString(token.text, {
4524
+ throwOnError: false
4525
+ });
4526
+ return `<span class="${prefix2}-katex-block" data-processed>${html}</span>`;
4527
+ } else {
4528
+ return `<span class="${prefix2}-katex-block">${token.text}</span>`;
4529
+ }
4530
+ }
4531
+ };
4532
+ },
4533
+ inline(prefix2, katex) {
4534
+ return {
4535
+ name: "KaTexInlineExtension",
4536
+ level: "inline",
4537
+ start: (text) => {
4538
+ var _a;
4539
+ return (_a = text.match(/\$[^$]/)) == null ? void 0 : _a.index;
4540
+ },
4541
+ tokenizer(text) {
4542
+ const reg = /^\$([^$]*)\$/;
4543
+ const match = reg.exec(text);
4544
+ if (match) {
4545
+ const token = {
4546
+ type: "KaTexInlineExtension",
4547
+ raw: match[0],
4548
+ text: match[1].trim(),
4549
+ tokens: []
4550
+ };
4551
+ return token;
4552
+ }
4553
+ },
4554
+ renderer(token) {
4555
+ if (katex || window.katex) {
4556
+ const html = (katex || window.katex).renderToString(token.text, {
4557
+ throwOnError: false
4558
+ });
4559
+ return `<span class="${prefix2}-katex-inline" data-processed>${html}</span>`;
4560
+ } else {
4561
+ return `<span class="${prefix2}-katex-inline">${token.text}</span>`;
4562
+ }
4563
+ }
4564
+ };
4565
+ }
4566
+ };
4436
4567
  const useHistory = (props2, textAreaRef) => {
4437
4568
  var _a, _b;
4438
4569
  const previewOnly = inject("previewOnly");
@@ -4507,6 +4638,7 @@ const useMarked = (props2, mermaidData) => {
4507
4638
  const showCodeRowNumber = inject("showCodeRowNumber");
4508
4639
  const editorId = inject("editorId");
4509
4640
  const highlightInited = ref(false);
4641
+ const katexInited = ref(false);
4510
4642
  let heads = [];
4511
4643
  const renderer = new marked.Renderer();
4512
4644
  renderer.heading = (...headProps) => {
@@ -4551,6 +4683,14 @@ const useMarked = (props2, mermaidData) => {
4551
4683
  renderer,
4552
4684
  breaks: true
4553
4685
  });
4686
+ if (!props2.noKatex) {
4687
+ marked.use({
4688
+ extensions: [
4689
+ kaTexExtensions.inline(prefix, props2.katex),
4690
+ kaTexExtensions.block(prefix, props2.katex)
4691
+ ]
4692
+ });
4693
+ }
4554
4694
  if (props2.hljs) {
4555
4695
  marked.setOptions({
4556
4696
  highlight: (code) => {
@@ -4565,6 +4705,7 @@ const useMarked = (props2, mermaidData) => {
4565
4705
  highlightInited.value;
4566
4706
  mermaidData.reRender;
4567
4707
  mermaidData.mermaidInited;
4708
+ katexInited.value;
4568
4709
  return props2.sanitize(_html);
4569
4710
  });
4570
4711
  const highlightLoad = () => {
@@ -4581,6 +4722,28 @@ const useMarked = (props2, mermaidData) => {
4581
4722
  props2.onGetCatalog(heads);
4582
4723
  bus.emit(editorId, "catalogChanged", heads);
4583
4724
  });
4725
+ let katexScript;
4726
+ let katexLink;
4727
+ onMounted(() => {
4728
+ if (!props2.noKatex && !props2.katex) {
4729
+ katexScript = document.createElement("script");
4730
+ katexScript.src = props2.katexJs;
4731
+ katexScript.onload = () => {
4732
+ katexInited.value = true;
4733
+ };
4734
+ katexScript.id = `${prefix}-katex`;
4735
+ katexLink = document.createElement("link");
4736
+ katexLink.rel = "stylesheet";
4737
+ katexLink.href = props2.katexCss;
4738
+ katexLink.id = `${prefix}-katexCss`;
4739
+ appendHandler(katexScript);
4740
+ appendHandler(katexLink);
4741
+ }
4742
+ });
4743
+ onBeforeUnmount(() => {
4744
+ katexScript && katexScript.remove();
4745
+ katexLink && katexLink.remove();
4746
+ });
4584
4747
  return {
4585
4748
  html,
4586
4749
  highlightLoad
@@ -4781,6 +4944,21 @@ var Content = defineComponent({
4781
4944
  placeholder: {
4782
4945
  type: String,
4783
4946
  default: ""
4947
+ },
4948
+ katex: {
4949
+ type: Object
4950
+ },
4951
+ katexJs: {
4952
+ type: String,
4953
+ default: ""
4954
+ },
4955
+ katexCss: {
4956
+ type: String,
4957
+ default: ""
4958
+ },
4959
+ noKatex: {
4960
+ type: Boolean,
4961
+ default: false
4784
4962
  }
4785
4963
  },
4786
4964
  setup(props2) {
@@ -5123,6 +5301,21 @@ const props = {
5123
5301
  placeholder: {
5124
5302
  type: String,
5125
5303
  default: ""
5304
+ },
5305
+ katex: {
5306
+ type: Object
5307
+ },
5308
+ katexJs: {
5309
+ type: String,
5310
+ default: katexJsUrl
5311
+ },
5312
+ katexCss: {
5313
+ type: String,
5314
+ default: katexCssUrl
5315
+ },
5316
+ noKatex: {
5317
+ type: Boolean,
5318
+ default: false
5126
5319
  }
5127
5320
  };
5128
5321
  var Editor = defineComponent({
@@ -5244,7 +5437,11 @@ var Editor = defineComponent({
5244
5437
  "mermaidJs": props2.mermaidJs,
5245
5438
  "noMermaid": props2.noMermaid,
5246
5439
  "sanitize": props2.sanitize,
5247
- "placeholder": props2.placeholder
5440
+ "placeholder": props2.placeholder,
5441
+ "katex": props2.katex,
5442
+ "katexJs": props2.katexJs,
5443
+ "katexCss": props2.katexCss,
5444
+ "noKatex": props2.noKatex
5248
5445
  }, null), catalogShow.value && createVNode(Catalog, {
5249
5446
  "markedHeadingId": props2.markedHeadingId
5250
5447
  }, null), !previewOnly && createVNode(Teleport, {