@8btc/mditor 0.0.24 → 0.0.25

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.
@@ -66,6 +66,16 @@
66
66
  border: 1px solid #141414;
67
67
  }
68
68
 
69
+ .vditor-reset .language-math {
70
+ user-select: all;
71
+ cursor: text;
72
+ transition: background-color 0.1s ease;
73
+ }
74
+ .vditor-reset .language-math.vditor-math--selected {
75
+ background-color: highlight !important;
76
+ color: highlighttext !important;
77
+ }
78
+
69
79
  .vditor-reset table tr {
70
80
  /* background-color: #2f363d; */
71
81
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
@@ -38,6 +38,16 @@
38
38
  border: 1px solid #d1d5da;
39
39
  }
40
40
 
41
+ .vditor-reset .language-math {
42
+ user-select: all;
43
+ cursor: text;
44
+ transition: background-color 0.1s ease;
45
+ }
46
+ .vditor-reset .language-math.vditor-math--selected {
47
+ background-color: highlight !important;
48
+ color: highlighttext !important;
49
+ }
50
+
41
51
  .vditor-reset table tr {
42
52
  border-bottom: 1px solid #e5e5e5;
43
53
  > th {
package/dist/index.css CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Vditor v0.0.24 - A markdown editor written in TypeScript.
2
+ * Vditor v0.0.25 - A markdown editor written in TypeScript.
3
3
  *
4
4
  * MIT License
5
5
  *
@@ -25,7 +25,7 @@
25
25
  *
26
26
  */
27
27
  /*!
28
- * Vditor v0.0.24 - A markdown editor written in TypeScript.
28
+ * Vditor v0.0.25 - A markdown editor written in TypeScript.
29
29
  *
30
30
  * MIT License
31
31
  *
@@ -552,6 +552,17 @@
552
552
  .vditor-preview img:not(.emoji) {
553
553
  cursor: pointer;
554
554
  }
555
+ .vditor-preview .language-math {
556
+ -webkit-user-select: all;
557
+ -moz-user-select: all;
558
+ user-select: all;
559
+ cursor: text;
560
+ transition: background-color 0.1s ease;
561
+ }
562
+ .vditor-preview .language-math.vditor-math--selected {
563
+ background-color: highlight !important;
564
+ color: highlighttext !important;
565
+ }
555
566
  .vditor-devtools {
556
567
  display: none;
557
568
  overflow: auto;
@@ -1384,6 +1395,17 @@
1384
1395
  text-align: center;
1385
1396
  font-size: 100% !important;
1386
1397
  }
1398
+ .vditor-wysiwyg .language-math {
1399
+ -webkit-user-select: all;
1400
+ -moz-user-select: all;
1401
+ user-select: all;
1402
+ cursor: text;
1403
+ transition: background-color 0.1s ease;
1404
+ }
1405
+ .vditor-wysiwyg .language-math.vditor-math--selected {
1406
+ background-color: highlight !important;
1407
+ color: highlighttext !important;
1408
+ }
1387
1409
  .vditor-wysiwyg > .vditor-reset > h1:before,
1388
1410
  .vditor-wysiwyg > .vditor-reset > h2:before,
1389
1411
  .vditor-wysiwyg > .vditor-reset > h3:before,
@@ -1698,6 +1720,17 @@
1698
1720
  .vditor-ir .vditor-reset > :is(p, h1, h2, h3, h4, h5, h6, ul, ol, code, pre):has(+ .vditor-ir__node[data-type="math-block"]) {
1699
1721
  margin-bottom: 0 !important;
1700
1722
  }
1723
+ .vditor-ir .language-math {
1724
+ -webkit-user-select: all;
1725
+ -moz-user-select: all;
1726
+ user-select: all;
1727
+ cursor: text;
1728
+ transition: background-color 0.1s ease;
1729
+ }
1730
+ .vditor-ir .language-math.vditor-math--selected {
1731
+ background-color: highlight !important;
1732
+ color: highlighttext !important;
1733
+ }
1701
1734
  @media screen and (max-width: 32.5rem) {
1702
1735
  .vditor-ir h1:before,
1703
1736
  .vditor-ir h2:before,
@@ -1815,6 +1848,17 @@
1815
1848
  .vditor-sv__marker--strong {
1816
1849
  font-weight: bold;
1817
1850
  }
1851
+ .vditor-sv .language-math {
1852
+ -webkit-user-select: all;
1853
+ -moz-user-select: all;
1854
+ user-select: all;
1855
+ cursor: text;
1856
+ transition: background-color 0.1s ease;
1857
+ }
1858
+ .vditor-sv .language-math.vditor-math--selected {
1859
+ background-color: highlight !important;
1860
+ color: highlighttext !important;
1861
+ }
1818
1862
  .vditor--linenumber .vditor-reset > ul [data-linenumber][data-list-level="1"]:after,
1819
1863
  .vditor--linenumber .vditor-reset ol [data-linenumber][data-list-level="1"]:after {
1820
1864
  margin-left: -5rem !important;
@@ -2161,4 +2205,16 @@ details > summary {
2161
2205
  details > summary::-webkit-details-marker {
2162
2206
  display: none;
2163
2207
  }
2208
+ ::-moz-selection {
2209
+ background: highlight;
2210
+ /* 系统原生高亮背景色 */
2211
+ color: highlighttext;
2212
+ /* 系统原生高亮文本色 */
2213
+ }
2214
+ ::selection {
2215
+ background: highlight;
2216
+ /* 系统原生高亮背景色 */
2217
+ color: highlighttext;
2218
+ /* 系统原生高亮文本色 */
2219
+ }
2164
2220
 
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Vditor v0.0.24 - A markdown editor written in TypeScript.
2
+ * Vditor v0.0.25 - A markdown editor written in TypeScript.
3
3
  *
4
4
  * MIT License
5
5
  *
@@ -2488,6 +2488,8 @@ var speechRender = function (element, lang) {
2488
2488
 
2489
2489
  // EXTERNAL MODULE: ./src/ts/markdown/selectionRender.ts
2490
2490
  var selectionRender = __webpack_require__(616);
2491
+ // EXTERNAL MODULE: ./src/ts/util/mathSelection.ts
2492
+ var mathSelection = __webpack_require__(35);
2491
2493
  ;// CONCATENATED MODULE: ./src/ts/markdown/previewRender.ts
2492
2494
  var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
2493
2495
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
@@ -2546,6 +2548,7 @@ var __generator = (undefined && undefined.__generator) || function (thisArg, bod
2546
2548
 
2547
2549
 
2548
2550
 
2551
+
2549
2552
 
2550
2553
 
2551
2554
  var mergeOptions = function (options) {
@@ -2721,6 +2724,61 @@ var previewRender = function (previewElement, markdown, options) { return __awai
2721
2724
  if (mergedOptions.lazyLoadImage) {
2722
2725
  lazyLoadImageRender(previewElement);
2723
2726
  }
2727
+ // 绑定数学公式选中高亮监听
2728
+ (0,mathSelection/* bindMathSelectionListener */.I)(previewElement);
2729
+ // 绑定复制事件,处理数学公式源码复制
2730
+ previewElement.addEventListener("copy", function (event) {
2731
+ var selection = window.getSelection();
2732
+ if (!selection || selection.isCollapsed || selection.rangeCount === 0) {
2733
+ return;
2734
+ }
2735
+ var range = selection.getRangeAt(0);
2736
+ // 检查选区是否只包含单个数学公式
2737
+ var mathElement = (0,hasClosest/* hasClosestByClassName */.fb)(range.startContainer, "language-math");
2738
+ var mathEndElement = (0,hasClosest/* hasClosestByClassName */.fb)(range.endContainer, "language-math");
2739
+ // 如果选区的起点和终点都在同一个数学公式元素内,复制源码
2740
+ if (mathElement &&
2741
+ mathEndElement &&
2742
+ mathElement.isSameNode(mathEndElement)) {
2743
+ event.stopPropagation();
2744
+ event.preventDefault();
2745
+ var mathSource = mathElement.getAttribute("data-math") || range.toString();
2746
+ event.clipboardData.setData("text/plain", mathSource);
2747
+ event.clipboardData.setData("text/html", "");
2748
+ return;
2749
+ }
2750
+ // 处理包含多个公式的混合内容
2751
+ var fragment = range.cloneContents();
2752
+ var mathElements = fragment.querySelectorAll(".language-math");
2753
+ if (mathElements.length > 0) {
2754
+ event.stopPropagation();
2755
+ event.preventDefault();
2756
+ // 创建临时容器来处理内容
2757
+ var tempDiv = document.createElement("div");
2758
+ tempDiv.appendChild(fragment);
2759
+ // 替换所有数学公式为源码
2760
+ tempDiv
2761
+ .querySelectorAll(".language-math")
2762
+ .forEach(function (mathEl) {
2763
+ var mathSource = mathEl.getAttribute("data-math");
2764
+ console.log(mathEl.tagName, "mathEl");
2765
+ if (mathSource) {
2766
+ if (mathEl.tagName === "SPAN") {
2767
+ var textNode = document.createTextNode("$".concat(mathSource, "$"));
2768
+ mathEl.parentNode.replaceChild(textNode, mathEl);
2769
+ }
2770
+ else {
2771
+ var textNode = document.createTextNode("$$".concat(mathSource, "$$"));
2772
+ mathEl.parentNode.replaceChild(textNode, mathEl);
2773
+ }
2774
+ }
2775
+ });
2776
+ // 获取纯文本内容
2777
+ var plainText = tempDiv.textContent || tempDiv.innerText || "";
2778
+ event.clipboardData.setData("text/plain", plainText);
2779
+ event.clipboardData.setData("text/html", "");
2780
+ }
2781
+ });
2724
2782
  previewElement.addEventListener("click", function (event) {
2725
2783
  var _a, _b;
2726
2784
  var spanElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(event.target, "SPAN");
@@ -2866,7 +2924,7 @@ var Vditor = /** @class */ (function () {
2866
2924
  /* harmony export */ "H": () => (/* binding */ _VDITOR_VERSION),
2867
2925
  /* harmony export */ "g": () => (/* binding */ Constants)
2868
2926
  /* harmony export */ });
2869
- var _VDITOR_VERSION = "0.0.24";
2927
+ var _VDITOR_VERSION = "0.0.25";
2870
2928
 
2871
2929
  var Constants = /** @class */ (function () {
2872
2930
  function Constants() {
@@ -3168,7 +3226,7 @@ var Constants = /** @class */ (function () {
3168
3226
  "c#",
3169
3227
  "bat",
3170
3228
  ];
3171
- Constants.CDN = "https://webcdn.wujieai.com/vditor@".concat("0.0.24");
3229
+ Constants.CDN = "https://webcdn.wujieai.com/vditor@".concat("0.0.25");
3172
3230
  Constants.MARKDOWN_OPTIONS = {
3173
3231
  autoSpace: false,
3174
3232
  gfmAutoLink: true,
@@ -7256,7 +7314,8 @@ var getTopList = function (element) {
7256
7314
  var topUlElement = hasTopClosestByTag(element, "UL");
7257
7315
  var topOlElement = hasTopClosestByTag(element, "OL");
7258
7316
  var topListElement = topUlElement;
7259
- if (topOlElement && (!topUlElement || (topUlElement && topOlElement.contains(topUlElement)))) {
7317
+ if (topOlElement &&
7318
+ (!topUlElement || (topUlElement && topOlElement.contains(topUlElement)))) {
7260
7319
  topListElement = topOlElement;
7261
7320
  }
7262
7321
  return topListElement;
@@ -7397,6 +7456,66 @@ var hasClosestByHeadings = function (element) {
7397
7456
  };
7398
7457
 
7399
7458
 
7459
+ /***/ }),
7460
+
7461
+ /***/ 35:
7462
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
7463
+
7464
+ "use strict";
7465
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
7466
+ /* harmony export */ "I": () => (/* binding */ bindMathSelectionListener)
7467
+ /* harmony export */ });
7468
+ /* unused harmony export updateMathSelection */
7469
+ /**
7470
+ * 数学公式选中高亮工具
7471
+ * 监听选区变化,为选中的数学公式添加高亮样式
7472
+ */
7473
+ var MATH_SELECTED_CLASS = "vditor-math--selected";
7474
+ /**
7475
+ * 检查并更新数学公式的选中高亮状态
7476
+ * @param container 容器元素(编辑器或预览区域)
7477
+ */
7478
+ var updateMathSelection = function (container) {
7479
+ var selection = window.getSelection();
7480
+ // 获取所有数学公式元素
7481
+ var mathElements = container.querySelectorAll(".language-math");
7482
+ // 移除所有旧的高亮
7483
+ mathElements.forEach(function (el) { return el.classList.remove(MATH_SELECTED_CLASS); });
7484
+ // 无选中内容则返回
7485
+ if (!selection || selection.isCollapsed || selection.rangeCount === 0) {
7486
+ return;
7487
+ }
7488
+ // 检测选中的公式节点并添加高亮
7489
+ mathElements.forEach(function (element) {
7490
+ if (selection.containsNode(element, true)) {
7491
+ element.classList.add(MATH_SELECTED_CLASS);
7492
+ }
7493
+ });
7494
+ };
7495
+ /**
7496
+ * 为容器绑定数学公式选中高亮监听
7497
+ * @param container 容器元素(编辑器或预览区域)
7498
+ */
7499
+ var bindMathSelectionListener = function (container) {
7500
+ var updateHandler = function () { return updateMathSelection(container); };
7501
+ // 监听选区变化
7502
+ document.addEventListener("selectionchange", updateHandler);
7503
+ // 监听鼠标抬起(处理拖拽选择)
7504
+ container.addEventListener("mouseup", updateHandler);
7505
+ // 监听键盘选择(Shift + 方向键)
7506
+ container.addEventListener("keyup", function (e) {
7507
+ if (e.shiftKey && ["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(e.key)) {
7508
+ updateHandler();
7509
+ }
7510
+ });
7511
+ // 返回清理函数
7512
+ return function () {
7513
+ document.removeEventListener("selectionchange", updateHandler);
7514
+ container.removeEventListener("mouseup", updateHandler);
7515
+ };
7516
+ };
7517
+
7518
+
7400
7519
  /***/ }),
7401
7520
 
7402
7521
  /***/ 673:
@@ -15342,6 +15461,8 @@ var Hint = /** @class */ (function () {
15342
15461
  }());
15343
15462
 
15344
15463
 
15464
+ // EXTERNAL MODULE: ./src/ts/util/mathSelection.ts
15465
+ var mathSelection = __webpack_require__(35);
15345
15466
  ;// CONCATENATED MODULE: ./src/ts/ir/index.ts
15346
15467
 
15347
15468
 
@@ -15355,6 +15476,7 @@ var Hint = /** @class */ (function () {
15355
15476
 
15356
15477
 
15357
15478
 
15479
+
15358
15480
  var IR = /** @class */ (function () {
15359
15481
  function IR(vditor) {
15360
15482
  var _a;
@@ -15375,7 +15497,15 @@ var IR = /** @class */ (function () {
15375
15497
  dropEvent(vditor, this.element);
15376
15498
  copyEvent(vditor, this.element, this.copy);
15377
15499
  cutEvent(vditor, this.element, this.copy);
15500
+ // 绑定数学公式选中高亮监听
15501
+ this.mathSelectionCleanup = (0,mathSelection/* bindMathSelectionListener */.I)(this.element);
15378
15502
  }
15503
+ IR.prototype.unbindListener = function () {
15504
+ // 清理数学公式选中监听
15505
+ if (this.mathSelectionCleanup) {
15506
+ this.mathSelectionCleanup();
15507
+ }
15508
+ };
15379
15509
  IR.prototype.copy = function (event, vditor) {
15380
15510
  var range = getSelection().getRangeAt(0);
15381
15511
  if (range.toString() === "") {
@@ -15383,8 +15513,30 @@ var IR = /** @class */ (function () {
15383
15513
  }
15384
15514
  event.stopPropagation();
15385
15515
  event.preventDefault();
15516
+ // 检查选区是否在数学公式元素内
15517
+ var mathElement = (0,hasClosest/* hasClosestByClassName */.fb)(range.startContainer, "language-math");
15518
+ var mathEndElement = (0,hasClosest/* hasClosestByClassName */.fb)(range.endContainer, "language-math");
15519
+ // 如果选区的起点和终点都在同一个数学公式元素内,复制源码
15520
+ if (mathElement && mathEndElement && mathElement.isSameNode(mathEndElement)) {
15521
+ var mathSource = mathElement.getAttribute("data-math") || range.toString();
15522
+ event.clipboardData.setData("text/plain", mathSource);
15523
+ event.clipboardData.setData("text/html", "");
15524
+ return;
15525
+ }
15526
+ // 处理包含多个公式的混合内容
15386
15527
  var tempElement = document.createElement("div");
15387
15528
  tempElement.appendChild(range.cloneContents());
15529
+ var mathElements = tempElement.querySelectorAll(".language-math");
15530
+ if (mathElements.length > 0) {
15531
+ // 替换所有数学公式为源码
15532
+ mathElements.forEach(function (mathEl) {
15533
+ var mathSource = mathEl.getAttribute("data-math");
15534
+ if (mathSource) {
15535
+ var textNode = document.createTextNode(mathSource);
15536
+ mathEl.parentNode.replaceChild(textNode, mathEl);
15537
+ }
15538
+ });
15539
+ }
15388
15540
  event.clipboardData.setData("text/plain", vditor.lute.VditorIRDOM2Md(tempElement.innerHTML).trim());
15389
15541
  event.clipboardData.setData("text/html", "");
15390
15542
  };
@@ -15668,6 +15820,7 @@ var selectionRender = __webpack_require__(616);
15668
15820
 
15669
15821
 
15670
15822
 
15823
+
15671
15824
  var Preview = /** @class */ (function () {
15672
15825
  /**
15673
15826
  * 构造预览区域容器,注册复制与点击事件。
@@ -15728,7 +15881,15 @@ var Preview = /** @class */ (function () {
15728
15881
  }
15729
15882
  });
15730
15883
  this.element.appendChild(this.previewElement);
15884
+ // 绑定数学公式选中高亮监听
15885
+ this.mathSelectionCleanup = (0,mathSelection/* bindMathSelectionListener */.I)(this.previewElement);
15731
15886
  }
15887
+ Preview.prototype.unbindListener = function () {
15888
+ // 清理数学公式选中监听
15889
+ if (this.mathSelectionCleanup) {
15890
+ this.mathSelectionCleanup();
15891
+ }
15892
+ };
15732
15893
  /**
15733
15894
  * 渲染预览内容。
15734
15895
  * - 优先使用远程接口(options.preview.url);失败则使用 Lute 本地渲染。
@@ -15944,6 +16105,7 @@ var Resize = /** @class */ (function () {
15944
16105
 
15945
16106
 
15946
16107
 
16108
+
15947
16109
  var Editor = /** @class */ (function () {
15948
16110
  function Editor(vditor) {
15949
16111
  var _a;
@@ -15964,7 +16126,15 @@ var Editor = /** @class */ (function () {
15964
16126
  dropEvent(vditor, this.element);
15965
16127
  copyEvent(vditor, this.element, this.copy);
15966
16128
  cutEvent(vditor, this.element, this.copy);
16129
+ // 绑定数学公式选中高亮监听
16130
+ this.mathSelectionCleanup = (0,mathSelection/* bindMathSelectionListener */.I)(this.element);
15967
16131
  }
16132
+ Editor.prototype.unbindListener = function () {
16133
+ // 清理数学公式选中监听
16134
+ if (this.mathSelectionCleanup) {
16135
+ this.mathSelectionCleanup();
16136
+ }
16137
+ };
15968
16138
  Editor.prototype.copy = function (event, vditor) {
15969
16139
  event.stopPropagation();
15970
16140
  event.preventDefault();
@@ -18320,6 +18490,7 @@ var wysiwyg_generator = (undefined && undefined.__generator) || function (thisAr
18320
18490
 
18321
18491
 
18322
18492
 
18493
+
18323
18494
  var WYSIWYG = /** @class */ (function () {
18324
18495
  function WYSIWYG(vditor) {
18325
18496
  var _this = this;
@@ -18517,6 +18688,8 @@ var WYSIWYG = /** @class */ (function () {
18517
18688
  };
18518
18689
  }
18519
18690
  }
18691
+ // 绑定数学公式选中高亮监听
18692
+ this.mathSelectionCleanup = (0,mathSelection/* bindMathSelectionListener */.I)(this.element);
18520
18693
  }
18521
18694
  WYSIWYG.prototype.getComments = function (vditor, getData) {
18522
18695
  var _this = this;
@@ -18677,11 +18850,15 @@ var WYSIWYG = /** @class */ (function () {
18677
18850
  };
18678
18851
  WYSIWYG.prototype.unbindListener = function () {
18679
18852
  window.removeEventListener("scroll", this.scrollListener);
18853
+ // 清理数学公式选中监听
18854
+ if (this.mathSelectionCleanup) {
18855
+ this.mathSelectionCleanup();
18856
+ }
18680
18857
  };
18681
18858
  /**
18682
18859
  * 复制事件处理
18683
18860
  * - 代码块与链接:按原有规则格式化复制
18684
- * - 数学公式选区:仅复制可见文本内容(不转换为 Markdown/TeX/MathML)
18861
+ * - 数学公式选区:复制公式源码(与 sv 模式一致)
18685
18862
  * - 其他内容:转换为 Markdown 文本复制
18686
18863
  */
18687
18864
  WYSIWYG.prototype.copy = function (event, vditor) {
@@ -18718,24 +18895,32 @@ var WYSIWYG = /** @class */ (function () {
18718
18895
  event.clipboardData.setData("text/html", "");
18719
18896
  return;
18720
18897
  }
18721
- // 数学公式选区:仅复制可见文本
18722
- var startPreview = (0,hasClosest/* hasClosestByClassName */.fb)(range.startContainer, "vditor-wysiwyg__preview");
18723
- var endPreview = (0,hasClosest/* hasClosestByClassName */.fb)(range.endContainer, "vditor-wysiwyg__preview");
18724
- var isMathPreview = function (el) {
18725
- var first = el.firstElementChild;
18726
- return !!first && first.classList.contains("language-math");
18727
- };
18728
- if (startPreview &&
18729
- endPreview &&
18730
- startPreview.isSameNode(endPreview) &&
18731
- isMathPreview(startPreview)) {
18732
- event.clipboardData.setData("text/plain", range.toString());
18898
+ // 数学公式选区:复制公式源码
18899
+ // 检查选区是否在数学公式元素内
18900
+ var mathElement = (0,hasClosest/* hasClosestByClassName */.fb)(range.startContainer, "language-math");
18901
+ var mathEndElement = (0,hasClosest/* hasClosestByClassName */.fb)(range.endContainer, "language-math");
18902
+ // 如果选区的起点和终点都在同一个数学公式元素内
18903
+ if (mathElement && mathEndElement && mathElement.isSameNode(mathEndElement)) {
18904
+ var mathSource = mathElement.getAttribute("data-math") || range.toString();
18905
+ event.clipboardData.setData("text/plain", mathSource);
18733
18906
  event.clipboardData.setData("text/html", "");
18734
18907
  return;
18735
18908
  }
18736
- // 默认:转换为 Markdown 文本
18909
+ // 处理包含多个公式的混合内容
18737
18910
  var tempElement = document.createElement("div");
18738
18911
  tempElement.appendChild(range.cloneContents());
18912
+ var mathElements = tempElement.querySelectorAll(".language-math");
18913
+ if (mathElements.length > 0) {
18914
+ // 替换所有数学公式为源码
18915
+ mathElements.forEach(function (mathEl) {
18916
+ var mathSource = mathEl.getAttribute("data-math");
18917
+ if (mathSource) {
18918
+ var textNode = document.createTextNode(mathSource);
18919
+ mathEl.parentNode.replaceChild(textNode, mathEl);
18920
+ }
18921
+ });
18922
+ }
18923
+ // 默认:转换为 Markdown 文本
18739
18924
  event.clipboardData.setData("text/plain", vditor.lute.VditorDOM2Md(tempElement.innerHTML).trim());
18740
18925
  event.clipboardData.setData("text/html", tempElement.innerHTML);
18741
18926
  };
@@ -18766,20 +18951,28 @@ var WYSIWYG = /** @class */ (function () {
18766
18951
  html: "",
18767
18952
  };
18768
18953
  }
18769
- var startPreview = (0,hasClosest/* hasClosestByClassName */.fb)(range.startContainer, "vditor-wysiwyg__preview");
18770
- var endPreview = (0,hasClosest/* hasClosestByClassName */.fb)(range.endContainer, "vditor-wysiwyg__preview");
18771
- var isMathPreview = function (el) {
18772
- var first = el.firstElementChild;
18773
- return !!first && first.classList.contains("language-math");
18774
- };
18775
- if (startPreview &&
18776
- endPreview &&
18777
- startPreview.isSameNode(endPreview) &&
18778
- isMathPreview(startPreview)) {
18779
- return { plainText: range.toString(), html: "" };
18954
+ // 检查选区是否在数学公式元素内
18955
+ var mathElement = (0,hasClosest/* hasClosestByClassName */.fb)(range.startContainer, "language-math");
18956
+ var mathEndElement = (0,hasClosest/* hasClosestByClassName */.fb)(range.endContainer, "language-math");
18957
+ // 如果选区的起点和终点都在同一个数学公式元素内
18958
+ if (mathElement && mathEndElement && mathElement.isSameNode(mathEndElement)) {
18959
+ var mathSource = mathElement.getAttribute("data-math") || range.toString();
18960
+ return { plainText: mathSource, html: "" };
18780
18961
  }
18962
+ // 处理包含多个公式的混合内容
18781
18963
  var tempElement = document.createElement("div");
18782
18964
  tempElement.appendChild(range.cloneContents());
18965
+ var mathElements = tempElement.querySelectorAll(".language-math");
18966
+ if (mathElements.length > 0) {
18967
+ // 替换所有数学公式为源码
18968
+ mathElements.forEach(function (mathEl) {
18969
+ var mathSource = mathEl.getAttribute("data-math");
18970
+ if (mathSource) {
18971
+ var textNode = document.createTextNode(mathSource);
18972
+ mathEl.parentNode.replaceChild(textNode, mathEl);
18973
+ }
18974
+ });
18975
+ }
18783
18976
  return {
18784
18977
  plainText: vditor.lute.VditorDOM2Md(tempElement.innerHTML).trim(),
18785
18978
  html: tempElement.innerHTML,