md-editor-v3 4.14.2-0 → 4.15.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.
package/README.md CHANGED
@@ -124,6 +124,8 @@ Inputing prompt and mark, emoji extensions
124
124
  | noImgZoomIn | `boolean` | false | Enable the function of enlarging images |
125
125
  | customIcon | `CustomIcon` | {} | Customized icons |
126
126
  | sanitizeMermaid | `(h: string) => Promise<string>` | (h: string) => Promise.resolve(h) | Convert the generated mermaid code |
127
+ | codeFoldable | `boolean` | true | Whether to enable code folding feature |
128
+ | autoFoldThreshold | `number` | 30 | Threshold for triggering automatic code folding by line count |
127
129
 
128
130
  ### 🔩 MdEditor Props
129
131
 
@@ -2966,7 +2966,9 @@ const Content = /* @__PURE__ */ vue.defineComponent({
2966
2966
  "formatCopiedText": props2.formatCopiedText,
2967
2967
  "noHighlight": props2.noHighlight,
2968
2968
  "noImgZoomIn": props2.noImgZoomIn,
2969
- "sanitizeMermaid": props2.sanitizeMermaid
2969
+ "sanitizeMermaid": props2.sanitizeMermaid,
2970
+ "codeFoldable": props2.codeFoldable,
2971
+ "autoFoldThreshold": props2.autoFoldThreshold
2970
2972
  }, null), props2.catalogVisible && vue.createVNode(MdCatalog, {
2971
2973
  "theme": props2.theme,
2972
2974
  "class": `${config.prefix}-catalog-editor`,
@@ -3242,7 +3244,9 @@ const Editor = /* @__PURE__ */ vue.defineComponent({
3242
3244
  ctx.emit("onInputBoxWitdhChange", width);
3243
3245
  },
3244
3246
  "sanitizeMermaid": props2.sanitizeMermaid,
3245
- "transformImgUrl": props2.transformImgUrl
3247
+ "transformImgUrl": props2.transformImgUrl,
3248
+ "codeFoldable": props2.codeFoldable,
3249
+ "autoFoldThreshold": props2.autoFoldThreshold
3246
3250
  }, null), props2.footers.length > 0 && vue.createVNode(Footer, {
3247
3251
  "modelValue": props2.modelValue,
3248
3252
  "footers": props2.footers,
@@ -33,46 +33,28 @@ const userZoom = (props, html) => {
33
33
  }
34
34
  });
35
35
  };
36
- const StrIcon = (name, customIcon) => {
37
- if (typeof customIcon[name] === "string") {
38
- return customIcon[name];
39
- }
40
- const defaultStr = `<i class="${config.prefix}-iconfont ${config.prefix}-icon-${name}"></i>`;
41
- switch (config.configOption.iconfontType) {
42
- case "svg": {
43
- return `<svg class="${config.prefix}-icon" aria-hidden="true"><use xlink:href="#${config.prefix}-icon-${name}"></use></svg>`;
44
- }
45
- default: {
46
- return defaultStr;
47
- }
48
- }
49
- };
50
36
  const useCopyCode = (props, html, key) => {
51
37
  const editorId = vue.inject("editorId");
52
38
  const ult = vue.inject("usedLanguageText");
53
- const customIcon = vue.inject("customIcon");
54
39
  const initCopyEntry = () => {
55
- document.querySelectorAll(`#${editorId}-preview pre`).forEach((pre) => {
56
- var _a;
40
+ document.querySelectorAll(`#${editorId} .${config.prefix}-preview .${config.prefix}-code`).forEach((codeBlock) => {
57
41
  let clearTimer = -1;
58
- (_a = pre.querySelector(".copy-button")) == null ? void 0 : _a.remove();
59
- const copyBtnText = ult.value.copyCode.text;
60
- const copyButton = document.createElement("span");
61
- copyButton.setAttribute("class", "copy-button");
62
- copyButton.dataset.tips = copyBtnText;
63
- copyButton.innerHTML = StrIcon("copy", customIcon.value);
64
- copyButton.addEventListener("click", () => {
65
- clearTimeout(clearTimer);
66
- const codeText = pre.querySelector("code").innerText;
67
- const success = copy(props.formatCopiedText(codeText));
68
- const succssTip = ult.value.copyCode.successTips;
69
- const failTip = ult.value.copyCode.failTips;
70
- copyButton.dataset.tips = success ? succssTip : failTip;
71
- clearTimer = window.setTimeout(() => {
72
- copyButton.dataset.tips = copyBtnText;
73
- }, 1500);
74
- });
75
- pre.appendChild(copyButton);
42
+ const copyButton = codeBlock.querySelector(
43
+ `.${config.prefix}-copy-button`
44
+ );
45
+ if (copyButton)
46
+ copyButton.onclick = (e) => {
47
+ e.preventDefault();
48
+ clearTimeout(clearTimer);
49
+ const activeCode = codeBlock.querySelector("input:checked + pre code") || codeBlock.querySelector("pre code");
50
+ const codeText = activeCode.textContent;
51
+ const success = copy(props.formatCopiedText(codeText));
52
+ const { text, successTips, failTips } = ult.value.copyCode;
53
+ copyButton.innerHTML = success ? successTips : failTips;
54
+ clearTimer = window.setTimeout(() => {
55
+ copyButton.innerHTML = text;
56
+ }, 1500);
57
+ };
76
58
  });
77
59
  };
78
60
  const htmlChanged = () => {
@@ -590,14 +572,31 @@ const codetabs = (md, _opts) => {
590
572
  return info ? info.split(/(\s+)/g)[0] : "";
591
573
  }
592
574
  const fenceGroup = (tokens, idx, options, env, slf) => {
575
+ var _a, _b;
593
576
  if (tokens[idx].hidden) {
594
577
  return "";
595
578
  }
596
- const [GROUP, _] = getGroupAndTab(tokens[idx]);
579
+ const [GROUP] = getGroupAndTab(tokens[idx]);
597
580
  if (GROUP === null) {
598
- return defaultRender(tokens, idx, options, env, slf);
581
+ const open2 = tokens[idx].content.trim().split("\n").length < _opts.autoFoldThreshold;
582
+ const tagContainer2 = _opts.codeFoldable ? "details" : "div", tagHeader2 = _opts.codeFoldable ? "summary" : "div";
583
+ const codeRendered = defaultRender(tokens, idx, options, env, slf);
584
+ return `<${tagContainer2} class="${config.prefix}-code"${open2 ? " open" : ""}>
585
+ <${tagHeader2} class="${config.prefix}-code-head">
586
+ <div class="${config.prefix}-code-flag">
587
+ <span></span>
588
+ <span></span>
589
+ <span></span>
590
+ </div>
591
+ <div>
592
+ <span class="${config.prefix}-code-lang">${tokens[idx].info.trim()}</span>
593
+ <span class="${config.prefix}-copy-button">${(_a = _opts.usedLanguageTextRef.value) == null ? void 0 : _a.copyCode.text}</span>
594
+ </div>
595
+ </${tagHeader2}>${codeRendered}</${tagContainer2}>`;
599
596
  }
600
- let token, group, tab, checked, labels = "", pres = "";
597
+ let token, group, tab, checked, labels = "", pres = "", langs = "";
598
+ const open = tokens[idx].content.trim().split("\n").length < _opts.autoFoldThreshold;
599
+ const tagContainer = _opts.codeFoldable ? "details" : "div", tagHeader = _opts.codeFoldable ? "summary" : "div";
601
600
  for (let i = idx; i < tokens.length; i++) {
602
601
  token = tokens[i];
603
602
  [group, tab] = getGroupAndTab(token);
@@ -606,17 +605,31 @@ const codetabs = (md, _opts) => {
606
605
  }
607
606
  token.info = token.info.replace(re, "");
608
607
  token.hidden = true;
609
- checked = i - idx > 0 ? "" : " checked";
610
- labels += `<li><input type="radio" name="label-group-${_opts.editorId}-${idx}"${checked}><label for="group-${_opts.editorId}-${idx}-tab-${i - idx}" onclick="this.previousElementSibling.click()">${tab || getLangName(token)}</label></li>
611
- `;
612
- pres += `<input type="radio" id="group-${_opts.editorId}-${idx}-tab-${i - idx}" name="group-${_opts.editorId}-${idx}"${checked}>
613
- ` + defaultRender(tokens, i, options, env, slf);
608
+ const className = `${config.prefix}-codetab-${_opts.editorId}-${idx}-${i - idx}`;
609
+ checked = i - idx > 0 ? "" : "checked";
610
+ labels += `<li>
611
+ <input type="radio" name="${config.prefix}-codetab-label-${_opts.editorId}-${idx}" class="${className}" ${checked}>
612
+ <label onclick="document.querySelectorAll('.${className}').forEach(e => e.click())">${tab || getLangName(token)}</label>
613
+ </li>`;
614
+ pres += `<input type="radio" name="${config.prefix}-codetab-pre-${_opts.editorId}-${idx}" class="${className}" ${checked}>
615
+ ${defaultRender(tokens, i, options, env, slf)}`;
616
+ langs += `<input type="radio" name="${config.prefix}-codetab-lang-${_opts.editorId}-${idx}" class="${className}" ${checked}>
617
+ <span class=${config.prefix}-code-lang>${getLangName(token)}</span>`;
614
618
  }
615
- return '<div class="code-tabs">\n<ul>\n' + labels + "</ul>\n" + pres + "</div>";
619
+ return `<${tagContainer} class="${config.prefix}-code" ${open ? " open" : ""}>
620
+ <${tagHeader} class="${config.prefix}-code-head">
621
+ <div class="${config.prefix}-code-flag">
622
+ <ul class="${config.prefix}-codetab-label">${labels}</ul>
623
+ </div>
624
+ <div>
625
+ <span class="${config.prefix}-codetab-lang">${langs}</span>
626
+ <span class="${config.prefix}-copy-button">${(_b = _opts.usedLanguageTextRef.value) == null ? void 0 : _b.copyCode.text}</span>
627
+ </div>
628
+ </${tagHeader}>${pres}</${tagContainer}>`;
616
629
  };
617
630
  md.renderer.rules.fence = fenceGroup;
618
631
  };
619
- const CodeTabsPlugin = codetabs;
632
+ const CodePlugin = codetabs;
620
633
  const initLineNumber = (md) => {
621
634
  [
622
635
  "paragraph_open",
@@ -654,6 +667,9 @@ const initLineNumber = (md) => {
654
667
  const useMarkdownIt = (props, previewOnly) => {
655
668
  const { editorConfig, markdownItConfig, markdownItPlugins } = config.configOption;
656
669
  const editorId = vue.inject("editorId");
670
+ const usedLanguageTextRef = vue.inject(
671
+ "usedLanguageText"
672
+ );
657
673
  const showCodeRowNumber = vue.inject("showCodeRowNumber");
658
674
  const themeRef = vue.inject("theme");
659
675
  const headsRef = vue.ref([]);
@@ -689,9 +705,15 @@ const useMarkdownIt = (props, previewOnly) => {
689
705
  options: { mdHeadingId: props.mdHeadingId, headsRef }
690
706
  },
691
707
  {
692
- type: "codeTabs",
693
- plugin: CodeTabsPlugin,
694
- options: { editorId }
708
+ type: "code",
709
+ plugin: CodePlugin,
710
+ options: {
711
+ editorId,
712
+ usedLanguageTextRef,
713
+ // showCodeRowNumber,
714
+ codeFoldable: props.codeFoldable,
715
+ autoFoldThreshold: props.autoFoldThreshold
716
+ }
695
717
  },
696
718
  {
697
719
  type: "xss",
@@ -764,7 +786,7 @@ const useMarkdownIt = (props, previewOnly) => {
764
786
  } else {
765
787
  codeHtml = md.utils.escapeHtml(str);
766
788
  }
767
- const codeSpan = showCodeRowNumber ? index.generateCodeRowNumber(codeHtml.replace(/^\n+|\n+$/g, "")) : `<span class="code-block">${codeHtml.replace(/^\n+|\n+$/g, "")}</span>`;
789
+ const codeSpan = showCodeRowNumber ? index.generateCodeRowNumber(codeHtml.replace(/^\n+|\n+$/g, "")) : `<span class="${config.prefix}-code-block">${codeHtml.replace(/^\n+|\n+$/g, "")}</span>`;
768
790
  return `<pre><code class="language-${language}" language=${language}>${codeSpan}</code></pre>`;
769
791
  }
770
792
  });
@@ -872,6 +894,12 @@ const contentPreviewProps = {
872
894
  },
873
895
  sanitizeMermaid: {
874
896
  type: Function
897
+ },
898
+ codeFoldable: {
899
+ type: Boolean
900
+ },
901
+ autoFoldThreshold: {
902
+ type: Number
875
903
  }
876
904
  };
877
905
  const contentProps = {
@@ -1579,6 +1607,25 @@ const mdPreviewProps = {
1579
1607
  sanitizeMermaid: {
1580
1608
  type: Function,
1581
1609
  default: (h) => Promise.resolve(h)
1610
+ },
1611
+ /**
1612
+ * 是否开启折叠代码功能
1613
+ * 不开启会使用div标签替代details标签
1614
+ *
1615
+ * @default true
1616
+ */
1617
+ codeFoldable: {
1618
+ type: Boolean,
1619
+ default: true
1620
+ },
1621
+ /**
1622
+ * 触发自动折叠代码的行数阈值
1623
+ *
1624
+ * @default 30
1625
+ */
1626
+ autoFoldThreshold: {
1627
+ type: Number,
1628
+ default: 30
1582
1629
  }
1583
1630
  };
1584
1631
  const editorProps = {
@@ -1914,7 +1961,9 @@ const MdPreview = /* @__PURE__ */ vue.defineComponent({
1914
1961
  "noHighlight": noHighlight,
1915
1962
  "noImgZoomIn": props.noImgZoomIn,
1916
1963
  "previewOnly": true,
1917
- "sanitizeMermaid": props.sanitizeMermaid
1964
+ "sanitizeMermaid": props.sanitizeMermaid,
1965
+ "codeFoldable": props.codeFoldable,
1966
+ "autoFoldThreshold": props.autoFoldThreshold
1918
1967
  }, null)]);
1919
1968
  };
1920
1969
  }
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ const config = require("./config.cjs");
2
3
  const base642File = (base64, fileName = "image.png") => {
3
4
  const arr = base64.split(",");
4
5
  const regResult = arr[0].match(/:(.*?);/);
@@ -24,7 +25,7 @@ const generateCodeRowNumber = (code) => {
24
25
  rowNumberList.push("<span></span>");
25
26
  });
26
27
  rowNumberList.push("</span>");
27
- return `<span class="code-block">${code}</span>${rowNumberList.join("")}`;
28
+ return `<span class="${config.prefix}-code-block">${code}</span>${rowNumberList.join("")}`;
28
29
  };
29
30
  const getRelativeTop = (element, container) => {
30
31
  if (!element || !container) {
@@ -39,8 +40,8 @@ const getRelativeTop = (element, container) => {
39
40
  };
40
41
  const getNextId = /* @__PURE__ */ (() => {
41
42
  let count = 0;
42
- return (prefix) => {
43
- return prefix + ++count;
43
+ return (prefix2) => {
44
+ return prefix2 + ++count;
44
45
  };
45
46
  })();
46
47
  const getZIndexIncrement = /* @__PURE__ */ (() => {
@@ -2965,7 +2965,9 @@ const Content = /* @__PURE__ */ defineComponent({
2965
2965
  "formatCopiedText": props2.formatCopiedText,
2966
2966
  "noHighlight": props2.noHighlight,
2967
2967
  "noImgZoomIn": props2.noImgZoomIn,
2968
- "sanitizeMermaid": props2.sanitizeMermaid
2968
+ "sanitizeMermaid": props2.sanitizeMermaid,
2969
+ "codeFoldable": props2.codeFoldable,
2970
+ "autoFoldThreshold": props2.autoFoldThreshold
2969
2971
  }, null), props2.catalogVisible && createVNode(MdCatalog, {
2970
2972
  "theme": props2.theme,
2971
2973
  "class": `${prefix}-catalog-editor`,
@@ -3241,7 +3243,9 @@ const Editor = /* @__PURE__ */ defineComponent({
3241
3243
  ctx.emit("onInputBoxWitdhChange", width);
3242
3244
  },
3243
3245
  "sanitizeMermaid": props2.sanitizeMermaid,
3244
- "transformImgUrl": props2.transformImgUrl
3246
+ "transformImgUrl": props2.transformImgUrl,
3247
+ "codeFoldable": props2.codeFoldable,
3248
+ "autoFoldThreshold": props2.autoFoldThreshold
3245
3249
  }, null), props2.footers.length > 0 && createVNode(Footer, {
3246
3250
  "modelValue": props2.modelValue,
3247
3251
  "footers": props2.footers,
@@ -1,5 +1,5 @@
1
1
  import { inject, onMounted, watch, toRef, nextTick, shallowRef, ref, computed, defineComponent, createVNode, Fragment, reactive, provide, onBeforeUnmount } from "vue";
2
- import { f as configOption, p as prefix, g as codeCss, s as staticTextDefault, b as allToolbar, d as allFooter } from "./config.mjs";
2
+ import { p as prefix, f as configOption, g as codeCss, s as staticTextDefault, b as allToolbar, d as allFooter } from "./config.mjs";
3
3
  import { b as bus, C as CATALOG_CHANGED, P as PUSH_CATALOG, R as RERENDER, B as BUILD_FINISHED, O as ON_SAVE, E as ERROR_CATCHER, U as UPLOAD_IMAGE, a as CHANGE_CATALOG_VISIBLE, c as PAGE_FULL_SCREEN_CHANGED, F as FULL_SCREEN_CHANGED, d as PREVIEW_CHANGED, e as PREVIEW_ONLY_CHANGED, H as HTML_PREVIEW_CHANGED, f as CATALOG_VISIBLE_CHANGED, g as REPLACE, h as CHANGE_FULL_SCREEN, i as EVENT_LISTENER } from "./event-name.mjs";
4
4
  import { a as appendHandler, u as updateHandler } from "./dom.mjs";
5
5
  import { debounce, uuid, deepMerge, deepClone } from "@vavt/util";
@@ -32,46 +32,28 @@ const userZoom = (props, html) => {
32
32
  }
33
33
  });
34
34
  };
35
- const StrIcon = (name, customIcon) => {
36
- if (typeof customIcon[name] === "string") {
37
- return customIcon[name];
38
- }
39
- const defaultStr = `<i class="${prefix}-iconfont ${prefix}-icon-${name}"></i>`;
40
- switch (configOption.iconfontType) {
41
- case "svg": {
42
- return `<svg class="${prefix}-icon" aria-hidden="true"><use xlink:href="#${prefix}-icon-${name}"></use></svg>`;
43
- }
44
- default: {
45
- return defaultStr;
46
- }
47
- }
48
- };
49
35
  const useCopyCode = (props, html, key) => {
50
36
  const editorId = inject("editorId");
51
37
  const ult = inject("usedLanguageText");
52
- const customIcon = inject("customIcon");
53
38
  const initCopyEntry = () => {
54
- document.querySelectorAll(`#${editorId}-preview pre`).forEach((pre) => {
55
- var _a;
39
+ document.querySelectorAll(`#${editorId} .${prefix}-preview .${prefix}-code`).forEach((codeBlock) => {
56
40
  let clearTimer = -1;
57
- (_a = pre.querySelector(".copy-button")) == null ? void 0 : _a.remove();
58
- const copyBtnText = ult.value.copyCode.text;
59
- const copyButton = document.createElement("span");
60
- copyButton.setAttribute("class", "copy-button");
61
- copyButton.dataset.tips = copyBtnText;
62
- copyButton.innerHTML = StrIcon("copy", customIcon.value);
63
- copyButton.addEventListener("click", () => {
64
- clearTimeout(clearTimer);
65
- const codeText = pre.querySelector("code").innerText;
66
- const success = copy(props.formatCopiedText(codeText));
67
- const succssTip = ult.value.copyCode.successTips;
68
- const failTip = ult.value.copyCode.failTips;
69
- copyButton.dataset.tips = success ? succssTip : failTip;
70
- clearTimer = window.setTimeout(() => {
71
- copyButton.dataset.tips = copyBtnText;
72
- }, 1500);
73
- });
74
- pre.appendChild(copyButton);
41
+ const copyButton = codeBlock.querySelector(
42
+ `.${prefix}-copy-button`
43
+ );
44
+ if (copyButton)
45
+ copyButton.onclick = (e) => {
46
+ e.preventDefault();
47
+ clearTimeout(clearTimer);
48
+ const activeCode = codeBlock.querySelector("input:checked + pre code") || codeBlock.querySelector("pre code");
49
+ const codeText = activeCode.textContent;
50
+ const success = copy(props.formatCopiedText(codeText));
51
+ const { text, successTips, failTips } = ult.value.copyCode;
52
+ copyButton.innerHTML = success ? successTips : failTips;
53
+ clearTimer = window.setTimeout(() => {
54
+ copyButton.innerHTML = text;
55
+ }, 1500);
56
+ };
75
57
  });
76
58
  };
77
59
  const htmlChanged = () => {
@@ -589,14 +571,31 @@ const codetabs = (md, _opts) => {
589
571
  return info ? info.split(/(\s+)/g)[0] : "";
590
572
  }
591
573
  const fenceGroup = (tokens, idx, options, env, slf) => {
574
+ var _a, _b;
592
575
  if (tokens[idx].hidden) {
593
576
  return "";
594
577
  }
595
- const [GROUP, _] = getGroupAndTab(tokens[idx]);
578
+ const [GROUP] = getGroupAndTab(tokens[idx]);
596
579
  if (GROUP === null) {
597
- return defaultRender(tokens, idx, options, env, slf);
580
+ const open2 = tokens[idx].content.trim().split("\n").length < _opts.autoFoldThreshold;
581
+ const tagContainer2 = _opts.codeFoldable ? "details" : "div", tagHeader2 = _opts.codeFoldable ? "summary" : "div";
582
+ const codeRendered = defaultRender(tokens, idx, options, env, slf);
583
+ return `<${tagContainer2} class="${prefix}-code"${open2 ? " open" : ""}>
584
+ <${tagHeader2} class="${prefix}-code-head">
585
+ <div class="${prefix}-code-flag">
586
+ <span></span>
587
+ <span></span>
588
+ <span></span>
589
+ </div>
590
+ <div>
591
+ <span class="${prefix}-code-lang">${tokens[idx].info.trim()}</span>
592
+ <span class="${prefix}-copy-button">${(_a = _opts.usedLanguageTextRef.value) == null ? void 0 : _a.copyCode.text}</span>
593
+ </div>
594
+ </${tagHeader2}>${codeRendered}</${tagContainer2}>`;
598
595
  }
599
- let token, group, tab, checked, labels = "", pres = "";
596
+ let token, group, tab, checked, labels = "", pres = "", langs = "";
597
+ const open = tokens[idx].content.trim().split("\n").length < _opts.autoFoldThreshold;
598
+ const tagContainer = _opts.codeFoldable ? "details" : "div", tagHeader = _opts.codeFoldable ? "summary" : "div";
600
599
  for (let i = idx; i < tokens.length; i++) {
601
600
  token = tokens[i];
602
601
  [group, tab] = getGroupAndTab(token);
@@ -605,17 +604,31 @@ const codetabs = (md, _opts) => {
605
604
  }
606
605
  token.info = token.info.replace(re, "");
607
606
  token.hidden = true;
608
- checked = i - idx > 0 ? "" : " checked";
609
- labels += `<li><input type="radio" name="label-group-${_opts.editorId}-${idx}"${checked}><label for="group-${_opts.editorId}-${idx}-tab-${i - idx}" onclick="this.previousElementSibling.click()">${tab || getLangName(token)}</label></li>
610
- `;
611
- pres += `<input type="radio" id="group-${_opts.editorId}-${idx}-tab-${i - idx}" name="group-${_opts.editorId}-${idx}"${checked}>
612
- ` + defaultRender(tokens, i, options, env, slf);
607
+ const className = `${prefix}-codetab-${_opts.editorId}-${idx}-${i - idx}`;
608
+ checked = i - idx > 0 ? "" : "checked";
609
+ labels += `<li>
610
+ <input type="radio" name="${prefix}-codetab-label-${_opts.editorId}-${idx}" class="${className}" ${checked}>
611
+ <label onclick="document.querySelectorAll('.${className}').forEach(e => e.click())">${tab || getLangName(token)}</label>
612
+ </li>`;
613
+ pres += `<input type="radio" name="${prefix}-codetab-pre-${_opts.editorId}-${idx}" class="${className}" ${checked}>
614
+ ${defaultRender(tokens, i, options, env, slf)}`;
615
+ langs += `<input type="radio" name="${prefix}-codetab-lang-${_opts.editorId}-${idx}" class="${className}" ${checked}>
616
+ <span class=${prefix}-code-lang>${getLangName(token)}</span>`;
613
617
  }
614
- return '<div class="code-tabs">\n<ul>\n' + labels + "</ul>\n" + pres + "</div>";
618
+ return `<${tagContainer} class="${prefix}-code" ${open ? " open" : ""}>
619
+ <${tagHeader} class="${prefix}-code-head">
620
+ <div class="${prefix}-code-flag">
621
+ <ul class="${prefix}-codetab-label">${labels}</ul>
622
+ </div>
623
+ <div>
624
+ <span class="${prefix}-codetab-lang">${langs}</span>
625
+ <span class="${prefix}-copy-button">${(_b = _opts.usedLanguageTextRef.value) == null ? void 0 : _b.copyCode.text}</span>
626
+ </div>
627
+ </${tagHeader}>${pres}</${tagContainer}>`;
615
628
  };
616
629
  md.renderer.rules.fence = fenceGroup;
617
630
  };
618
- const CodeTabsPlugin = codetabs;
631
+ const CodePlugin = codetabs;
619
632
  const initLineNumber = (md) => {
620
633
  [
621
634
  "paragraph_open",
@@ -653,6 +666,9 @@ const initLineNumber = (md) => {
653
666
  const useMarkdownIt = (props, previewOnly) => {
654
667
  const { editorConfig, markdownItConfig, markdownItPlugins } = configOption;
655
668
  const editorId = inject("editorId");
669
+ const usedLanguageTextRef = inject(
670
+ "usedLanguageText"
671
+ );
656
672
  const showCodeRowNumber = inject("showCodeRowNumber");
657
673
  const themeRef = inject("theme");
658
674
  const headsRef = ref([]);
@@ -688,9 +704,15 @@ const useMarkdownIt = (props, previewOnly) => {
688
704
  options: { mdHeadingId: props.mdHeadingId, headsRef }
689
705
  },
690
706
  {
691
- type: "codeTabs",
692
- plugin: CodeTabsPlugin,
693
- options: { editorId }
707
+ type: "code",
708
+ plugin: CodePlugin,
709
+ options: {
710
+ editorId,
711
+ usedLanguageTextRef,
712
+ // showCodeRowNumber,
713
+ codeFoldable: props.codeFoldable,
714
+ autoFoldThreshold: props.autoFoldThreshold
715
+ }
694
716
  },
695
717
  {
696
718
  type: "xss",
@@ -763,7 +785,7 @@ const useMarkdownIt = (props, previewOnly) => {
763
785
  } else {
764
786
  codeHtml = md.utils.escapeHtml(str);
765
787
  }
766
- const codeSpan = showCodeRowNumber ? generateCodeRowNumber(codeHtml.replace(/^\n+|\n+$/g, "")) : `<span class="code-block">${codeHtml.replace(/^\n+|\n+$/g, "")}</span>`;
788
+ const codeSpan = showCodeRowNumber ? generateCodeRowNumber(codeHtml.replace(/^\n+|\n+$/g, "")) : `<span class="${prefix}-code-block">${codeHtml.replace(/^\n+|\n+$/g, "")}</span>`;
767
789
  return `<pre><code class="language-${language}" language=${language}>${codeSpan}</code></pre>`;
768
790
  }
769
791
  });
@@ -871,6 +893,12 @@ const contentPreviewProps = {
871
893
  },
872
894
  sanitizeMermaid: {
873
895
  type: Function
896
+ },
897
+ codeFoldable: {
898
+ type: Boolean
899
+ },
900
+ autoFoldThreshold: {
901
+ type: Number
874
902
  }
875
903
  };
876
904
  const contentProps = {
@@ -1578,6 +1606,25 @@ const mdPreviewProps = {
1578
1606
  sanitizeMermaid: {
1579
1607
  type: Function,
1580
1608
  default: (h) => Promise.resolve(h)
1609
+ },
1610
+ /**
1611
+ * 是否开启折叠代码功能
1612
+ * 不开启会使用div标签替代details标签
1613
+ *
1614
+ * @default true
1615
+ */
1616
+ codeFoldable: {
1617
+ type: Boolean,
1618
+ default: true
1619
+ },
1620
+ /**
1621
+ * 触发自动折叠代码的行数阈值
1622
+ *
1623
+ * @default 30
1624
+ */
1625
+ autoFoldThreshold: {
1626
+ type: Number,
1627
+ default: 30
1581
1628
  }
1582
1629
  };
1583
1630
  const editorProps = {
@@ -1913,7 +1960,9 @@ const MdPreview = /* @__PURE__ */ defineComponent({
1913
1960
  "noHighlight": noHighlight,
1914
1961
  "noImgZoomIn": props.noImgZoomIn,
1915
1962
  "previewOnly": true,
1916
- "sanitizeMermaid": props.sanitizeMermaid
1963
+ "sanitizeMermaid": props.sanitizeMermaid,
1964
+ "codeFoldable": props.codeFoldable,
1965
+ "autoFoldThreshold": props.autoFoldThreshold
1917
1966
  }, null)]);
1918
1967
  };
1919
1968
  }
@@ -1,3 +1,4 @@
1
+ import { p as prefix } from "./config.mjs";
1
2
  const base642File = (base64, fileName = "image.png") => {
2
3
  const arr = base64.split(",");
3
4
  const regResult = arr[0].match(/:(.*?);/);
@@ -23,7 +24,7 @@ const generateCodeRowNumber = (code) => {
23
24
  rowNumberList.push("<span></span>");
24
25
  });
25
26
  rowNumberList.push("</span>");
26
- return `<span class="code-block">${code}</span>${rowNumberList.join("")}`;
27
+ return `<span class="${prefix}-code-block">${code}</span>${rowNumberList.join("")}`;
27
28
  };
28
29
  const getRelativeTop = (element, container) => {
29
30
  if (!element || !container) {
@@ -38,8 +39,8 @@ const getRelativeTop = (element, container) => {
38
39
  };
39
40
  const getNextId = /* @__PURE__ */ (() => {
40
41
  let count = 0;
41
- return (prefix) => {
42
- return prefix + ++count;
42
+ return (prefix2) => {
43
+ return prefix2 + ++count;
43
44
  };
44
45
  })();
45
46
  const getZIndexIncrement = /* @__PURE__ */ (() => {