md-editor-v3 2.6.0 → 2.7.0-beta.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.
@@ -231,7 +231,7 @@ const staticTextDefault = {
231
231
  }
232
232
  }
233
233
  };
234
- const mermaidUrl = `${cdnBase}/mermaid/9.2.2/mermaid.min.js`;
234
+ const mermaidUrl = `${cdnBase}/mermaid/9.3.0/mermaid.min.js`;
235
235
  const katexUrl = {
236
236
  js: `${cdnBase}/KaTeX/0.16.3/katex.min.js`,
237
237
  css: `${cdnBase}/KaTeX/0.16.3/katex.min.css`
@@ -3273,10 +3273,10 @@ class Tokenizer {
3273
3273
  if (!nextChar || nextChar && (prevChar === "" || this.rules.inline.punctuation.exec(prevChar))) {
3274
3274
  const lLength = match[0].length - 1;
3275
3275
  let rDelim, rLength, delimTotal = lLength, midDelimTotal = 0;
3276
- const endReg = match[0][0] === "*" ? this.rules.inline.emStrong.rDelimAst : this.rules.inline.emStrong.rDelimUnd;
3277
- endReg.lastIndex = 0;
3276
+ const endReg2 = match[0][0] === "*" ? this.rules.inline.emStrong.rDelimAst : this.rules.inline.emStrong.rDelimUnd;
3277
+ endReg2.lastIndex = 0;
3278
3278
  maskedSrc = maskedSrc.slice(-1 * src.length + lLength);
3279
- while ((match = endReg.exec(maskedSrc)) != null) {
3279
+ while ((match = endReg2.exec(maskedSrc)) != null) {
3280
3280
  rDelim = match[1] || match[2] || match[3] || match[4] || match[5] || match[6];
3281
3281
  if (!rDelim)
3282
3282
  continue;
@@ -5143,7 +5143,7 @@ const splitHelp = (textarea) => {
5143
5143
  };
5144
5144
  };
5145
5145
  const directive2flag = (direct, selectedText = "", inputArea, params) => {
5146
- var _a, _b, _c, _d, _e;
5146
+ var _a, _b, _c, _d, _e, _f;
5147
5147
  let targetValue = "";
5148
5148
  let deviationStart = 0;
5149
5149
  let deviationEnd = 0;
@@ -5159,8 +5159,8 @@ const directive2flag = (direct, selectedText = "", inputArea, params) => {
5159
5159
  deviationStart = pix.length + 1;
5160
5160
  } else if (direct === "prettier") {
5161
5161
  const prettier = window.prettier || ((_c = (_b = configOption.editorExtensions) == null ? void 0 : _b.prettier) == null ? void 0 : _c.prettierInstance);
5162
- const prettierPlugins = window.prettierPlugins || [
5163
- (_e = (_d = configOption.editorExtensions) == null ? void 0 : _d.prettier) == null ? void 0 : _e.parserMarkdownInstance
5162
+ const prettierPlugins = [
5163
+ ((_d = window.prettierPlugins) == null ? void 0 : _d.markdown) || ((_f = (_e = configOption.editorExtensions) == null ? void 0 : _e.prettier) == null ? void 0 : _f.parserMarkdownInstance)
5164
5164
  ];
5165
5165
  if (!prettier || prettierPlugins[0] === void 0) {
5166
5166
  bus.emit(params.editorId, "errorCatcher", {
@@ -5574,6 +5574,80 @@ var kaTexExtensions = {
5574
5574
  };
5575
5575
  }
5576
5576
  };
5577
+ const alertTypes = [
5578
+ "abstract",
5579
+ "attention",
5580
+ "bug",
5581
+ "caution",
5582
+ "danger",
5583
+ "error",
5584
+ "example",
5585
+ "failure",
5586
+ "hint",
5587
+ "info",
5588
+ "note",
5589
+ "question",
5590
+ "quote",
5591
+ "success",
5592
+ "tip",
5593
+ "warning"
5594
+ ];
5595
+ const startReg = new RegExp(`^!!!\\s+(${alertTypes.join("|")})\\s+(.*)$`);
5596
+ const endReg = /^!!!\s*$/;
5597
+ const Alert = {
5598
+ name: "alert",
5599
+ level: "block",
5600
+ start(src) {
5601
+ var _a;
5602
+ const index2 = (_a = src.match(new RegExp(`(^|[\\r\\n])!!!\\s+(${alertTypes.join("|")})\\s+(.*)`))) == null ? void 0 : _a.index;
5603
+ return index2;
5604
+ },
5605
+ tokenizer(src) {
5606
+ const lines = src.split(/\n/);
5607
+ if (startReg.test(lines[0])) {
5608
+ const section = { x: -1, y: -1 };
5609
+ const sections = [];
5610
+ for (let i = 0, k = lines.length; i < k; i++) {
5611
+ if (startReg.test(lines[i])) {
5612
+ section.x = i;
5613
+ } else if (endReg.test(lines[i])) {
5614
+ section.y = i;
5615
+ if (section.x >= 0) {
5616
+ sections.push(__spreadValues({}, section));
5617
+ section.x = -1;
5618
+ section.y = -1;
5619
+ }
5620
+ }
5621
+ }
5622
+ if (sections.length) {
5623
+ const section2 = sections[0];
5624
+ const [_, icon, title] = startReg.exec(lines[section2.x]) || [];
5625
+ const text = lines.slice(section2.x + 1, section2.y).join("\n");
5626
+ const raw = lines.slice(section2.x, section2.y + 1).join("\n");
5627
+ const token = {
5628
+ type: "alert",
5629
+ raw,
5630
+ icon,
5631
+ title,
5632
+ text,
5633
+ titleTokens: [],
5634
+ tokens: [],
5635
+ childTokens: ["title", "text"]
5636
+ };
5637
+ this.lexer.inlineTokens(token.title, token.titleTokens);
5638
+ this.lexer.blockTokens(token.text, token.tokens);
5639
+ return token;
5640
+ }
5641
+ }
5642
+ },
5643
+ renderer(token) {
5644
+ const html = `<div class="md-editor-alert md-editor-alert-${token.icon}">
5645
+ <p class="md-editor-alert-title">${this.parser.parseInline(token.titleTokens, null)}</p>
5646
+ ${this.parser.parse(token.tokens)}
5647
+ </div>`;
5648
+ return html;
5649
+ }
5650
+ };
5577
5651
  const useHistory = (props, textAreaRef, completeStatus) => {
5578
5652
  var _a, _b;
5579
5653
  const previewOnly = inject("previewOnly");
@@ -5699,6 +5773,9 @@ const useMarked = (props, mermaidData) => {
5699
5773
  const katexInited = ref(false);
5700
5774
  const heads = ref([]);
5701
5775
  let renderer = new marked.Renderer();
5776
+ marked.use({
5777
+ extensions: [Alert]
5778
+ });
5702
5779
  const markedCode = renderer.code;
5703
5780
  renderer.code = (code, language, isEscaped) => {
5704
5781
  if (!props.noMermaid && language === "mermaid") {
@@ -5869,17 +5946,18 @@ const useAutoScroll = (props, html, textAreaRef, previewRef, htmlRef) => {
5869
5946
  };
5870
5947
  const initCopyEntry = () => {
5871
5948
  document.querySelectorAll(`#${editorId}-preview pre`).forEach((pre) => {
5872
- var _a;
5873
- const copyBtnText = ((_a = ult.value.copyCode) == null ? void 0 : _a.text) || "\u590D\u5236\u4EE3\u7801";
5949
+ var _a, _b;
5950
+ (_a = pre.querySelector(".copy-button")) == null ? void 0 : _a.remove();
5951
+ const copyBtnText = ((_b = ult.value.copyCode) == null ? void 0 : _b.text) || "\u590D\u5236\u4EE3\u7801";
5874
5952
  const copyButton = document.createElement("span");
5875
5953
  copyButton.setAttribute("class", "copy-button");
5876
5954
  copyButton.innerText = copyBtnText;
5877
5955
  copyButton.addEventListener("click", () => {
5878
- var _a2, _b;
5956
+ var _a2, _b2;
5879
5957
  const codeText = pre.querySelector("code").innerText;
5880
5958
  const success = copyToClipboard(props.formatCopiedText(codeText));
5881
5959
  const succssTip = ((_a2 = ult.value.copyCode) == null ? void 0 : _a2.successTips) || "\u5DF2\u590D\u5236\uFF01";
5882
- const failTip = ((_b = ult.value.copyCode) == null ? void 0 : _b.failTips) || "\u5DF2\u590D\u5236\uFF01";
5960
+ const failTip = ((_b2 = ult.value.copyCode) == null ? void 0 : _b2.failTips) || "\u5DF2\u590D\u5236\uFF01";
5883
5961
  copyButton.innerText = success ? succssTip : failTip;
5884
5962
  setTimeout(() => {
5885
5963
  copyButton.innerText = copyBtnText;
@@ -5907,6 +5985,7 @@ const useAutoScroll = (props, html, textAreaRef, previewRef, htmlRef) => {
5907
5985
  }
5908
5986
  };
5909
5987
  watch(() => html.value, htmlChanged);
5988
+ watch(() => ult.value, initCopyEntry);
5910
5989
  watch(() => props.setting.preview, settingPreviewChanged);
5911
5990
  watch(() => props.setting.htmlPreview, settingPreviewChanged);
5912
5991
  watch(() => props.scrollAuto, (sa) => {
@@ -6581,8 +6660,6 @@ const MdCatalog = defineComponent({
6581
6660
  })]);
6582
6661
  }
6583
6662
  });
6584
- var index = "";
6585
- var all = "";
6586
6663
  const editorProps = () => ({
6587
6664
  modelValue: {
6588
6665
  type: String,
@@ -6747,6 +6824,9 @@ const editorProps = () => ({
6747
6824
  }
6748
6825
  });
6749
6826
  const markedHeadingId = (text) => text;
6827
+ var index = "";
6828
+ var alert = "";
6829
+ var all = "";
6750
6830
  const Editor = defineComponent({
6751
6831
  name: "MdEditorV3",
6752
6832
  props: editorProps(),