@8btc/mditor 0.0.5 → 0.0.7

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/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Vditor v0.0.3 - A markdown editor written in TypeScript.
2
+ * Vditor v0.0.6 - A markdown editor written in TypeScript.
3
3
  *
4
4
  * MIT License
5
5
  *
@@ -2791,7 +2791,7 @@ var Vditor = /** @class */ (function () {
2791
2791
  /* harmony export */ "H": () => (/* binding */ _VDITOR_VERSION),
2792
2792
  /* harmony export */ "g": () => (/* binding */ Constants)
2793
2793
  /* harmony export */ });
2794
- var _VDITOR_VERSION = "0.0.3";
2794
+ var _VDITOR_VERSION = "0.0.6";
2795
2795
 
2796
2796
  var Constants = /** @class */ (function () {
2797
2797
  function Constants() {
@@ -3093,7 +3093,7 @@ var Constants = /** @class */ (function () {
3093
3093
  "c#",
3094
3094
  "bat",
3095
3095
  ];
3096
- Constants.CDN = "https://webcdn.wujieai.com/vditor@".concat("0.0.3");
3096
+ Constants.CDN = "https://webcdn.wujieai.com/vditor@".concat("0.0.6");
3097
3097
  Constants.MARKDOWN_OPTIONS = {
3098
3098
  autoSpace: false,
3099
3099
  gfmAutoLink: true,
@@ -7443,8 +7443,11 @@ var input = function (vditor, range, ignoreSpace, event) {
7443
7443
  if (ignoreSpace === void 0) { ignoreSpace = false; }
7444
7444
  var blockElement = (0,hasClosest/* hasClosestBlock */.F9)(range.startContainer);
7445
7445
  // 前后可以输入空格
7446
- if (blockElement && !ignoreSpace && blockElement.getAttribute("data-type") !== "code-block") {
7447
- if ((isHrMD(blockElement.innerHTML) && blockElement.previousElementSibling) ||
7446
+ if (blockElement &&
7447
+ !ignoreSpace &&
7448
+ blockElement.getAttribute("data-type") !== "code-block") {
7449
+ if ((isHrMD(blockElement.innerHTML) &&
7450
+ blockElement.previousElementSibling) ||
7448
7451
  isHeadingMD(blockElement.innerHTML)) {
7449
7452
  return;
7450
7453
  }
@@ -7454,7 +7457,8 @@ var input = function (vditor, range, ignoreSpace, event) {
7454
7457
  var startSpace = true;
7455
7458
  for (var i = startOffset - 1;
7456
7459
  // 软换行后有空格
7457
- i > blockElement.textContent.substr(0, startOffset).lastIndexOf("\n"); i--) {
7460
+ i >
7461
+ blockElement.textContent.substr(0, startOffset).lastIndexOf("\n"); i--) {
7458
7462
  if (blockElement.textContent.charAt(i) !== " " &&
7459
7463
  // 多个 tab 前删除不形成代码块 https://github.com/Vanessa219/vditor/issues/162 1
7460
7464
  blockElement.textContent.charAt(i) !== "\t") {
@@ -7468,7 +7472,8 @@ var input = function (vditor, range, ignoreSpace, event) {
7468
7472
  // 结尾可以输入空格
7469
7473
  var endSpace = true;
7470
7474
  for (var i = startOffset - 1; i < blockElement.textContent.length; i++) {
7471
- if (blockElement.textContent.charAt(i) !== " " && blockElement.textContent.charAt(i) !== "\n") {
7475
+ if (blockElement.textContent.charAt(i) !== " " &&
7476
+ blockElement.textContent.charAt(i) !== "\n") {
7472
7477
  endSpace = false;
7473
7478
  break;
7474
7479
  }
@@ -7489,8 +7494,11 @@ var input = function (vditor, range, ignoreSpace, event) {
7489
7494
  // inline marker space https://github.com/Vanessa219/vditor/issues/239
7490
7495
  }
7491
7496
  else {
7492
- var previousNode = range.startContainer.previousSibling;
7493
- if (previousNode && previousNode.nodeType !== 3 && previousNode.classList.contains("vditor-ir__node--expand")) {
7497
+ var previousNode = range.startContainer
7498
+ .previousSibling;
7499
+ if (previousNode &&
7500
+ previousNode.nodeType !== 3 &&
7501
+ previousNode.classList.contains("vditor-ir__node--expand")) {
7494
7502
  // FireFox https://github.com/Vanessa219/vditor/issues/239
7495
7503
  previousNode.classList.remove("vditor-ir__node--expand");
7496
7504
  }
@@ -7501,7 +7509,9 @@ var input = function (vditor, range, ignoreSpace, event) {
7501
7509
  }
7502
7510
  }
7503
7511
  }
7504
- vditor.ir.element.querySelectorAll(".vditor-ir__node--expand").forEach(function (item) {
7512
+ vditor.ir.element
7513
+ .querySelectorAll(".vditor-ir__node--expand")
7514
+ .forEach(function (item) {
7505
7515
  item.classList.remove("vditor-ir__node--expand");
7506
7516
  });
7507
7517
  if (!blockElement) {
@@ -7537,7 +7547,9 @@ var input = function (vditor, range, ignoreSpace, event) {
7537
7547
  blockElement = topListElement;
7538
7548
  }
7539
7549
  // 应到引用层,否则 > --- 会解析为 front-matter;列表中有 blockquote 则解析 blockquote;blockquote 中有列表则解析列表
7540
- if (blockquoteElement && (!topListElement || (topListElement && !blockquoteElement.contains(topListElement)))) {
7550
+ if (blockquoteElement &&
7551
+ (!topListElement ||
7552
+ (topListElement && !blockquoteElement.contains(topListElement)))) {
7541
7553
  blockElement = blockquoteElement;
7542
7554
  }
7543
7555
  // 修改脚注
@@ -7549,11 +7561,15 @@ var input = function (vditor, range, ignoreSpace, event) {
7549
7561
  // 如果为列表的话,需要把上下的列表都重绘
7550
7562
  var listPrevElement = blockElement.previousElementSibling;
7551
7563
  var listNextElement = blockElement.nextElementSibling;
7552
- if (listPrevElement && (listPrevElement.tagName === "UL" || listPrevElement.tagName === "OL")) {
7564
+ if (listPrevElement &&
7565
+ (listPrevElement.tagName === "UL" ||
7566
+ listPrevElement.tagName === "OL")) {
7553
7567
  html = listPrevElement.outerHTML + html;
7554
7568
  listPrevElement.remove();
7555
7569
  }
7556
- if (listNextElement && (listNextElement.tagName === "UL" || listNextElement.tagName === "OL")) {
7570
+ if (listNextElement &&
7571
+ (listNextElement.tagName === "UL" ||
7572
+ listNextElement.tagName === "OL")) {
7557
7573
  html = html + listNextElement.outerHTML;
7558
7574
  listNextElement.remove();
7559
7575
  }
@@ -7562,22 +7578,29 @@ var input = function (vditor, range, ignoreSpace, event) {
7562
7578
  }
7563
7579
  else if (blockElement.previousElementSibling &&
7564
7580
  blockElement.previousElementSibling.textContent.replace(constants/* Constants.ZWSP */.g.ZWSP, "") !== "" &&
7565
- event && event.inputType === "insertParagraph") {
7581
+ event &&
7582
+ event.inputType === "insertParagraph") {
7566
7583
  // 换行时需要处理上一段落
7567
7584
  html = blockElement.previousElementSibling.outerHTML + html;
7568
7585
  blockElement.previousElementSibling.remove();
7569
7586
  }
7570
7587
  if (!blockElement.innerText.startsWith("```")) {
7571
7588
  // 添加链接引用
7572
- vditor.ir.element.querySelectorAll("[data-type='link-ref-defs-block']").forEach(function (item) {
7573
- if (item && !blockElement.isEqualNode(item)) {
7589
+ vditor.ir.element
7590
+ .querySelectorAll("[data-type='link-ref-defs-block']")
7591
+ .forEach(function (item) {
7592
+ if (item &&
7593
+ !blockElement.isEqualNode(item)) {
7574
7594
  html += item.outerHTML;
7575
7595
  item.remove();
7576
7596
  }
7577
7597
  });
7578
7598
  // 添加脚注
7579
- vditor.ir.element.querySelectorAll("[data-type='footnotes-block']").forEach(function (item) {
7580
- if (item && !blockElement.isEqualNode(item)) {
7599
+ vditor.ir.element
7600
+ .querySelectorAll("[data-type='footnotes-block']")
7601
+ .forEach(function (item) {
7602
+ if (item &&
7603
+ !blockElement.isEqualNode(item)) {
7581
7604
  html += item.outerHTML;
7582
7605
  item.remove();
7583
7606
  }
@@ -7603,7 +7626,10 @@ var input = function (vditor, range, ignoreSpace, event) {
7603
7626
  var marker = footnoteItemText.substring(1, footnoteItemText.indexOf("]:"));
7604
7627
  var footnoteRefElement = vditor.ir.element.querySelector("sup[data-type=\"footnotes-ref\"][data-footnotes-label=\"".concat(marker, "\"]"));
7605
7628
  if (footnoteRefElement) {
7606
- footnoteRefElement.setAttribute("aria-label", footnoteItemText.substr(marker.length + 3).trim().substr(0, 24));
7629
+ footnoteRefElement.setAttribute("aria-label", footnoteItemText
7630
+ .substr(marker.length + 3)
7631
+ .trim()
7632
+ .substr(0, 24));
7607
7633
  }
7608
7634
  }
7609
7635
  }
@@ -7639,7 +7665,9 @@ var input = function (vditor, range, ignoreSpace, event) {
7639
7665
  vditor.ir.element.insertAdjacentElement("beforeend", allFootnoteElement[0]);
7640
7666
  }
7641
7667
  (0,selection/* setRangeByWbr */.ib)(vditor.ir.element, range);
7642
- vditor.ir.element.querySelectorAll(".vditor-ir__preview[data-render='2']").forEach(function (item) {
7668
+ vditor.ir.element
7669
+ .querySelectorAll(".vditor-ir__preview[data-render='2']")
7670
+ .forEach(function (item) {
7643
7671
  processCodeRender(item, vditor);
7644
7672
  });
7645
7673
  renderToc(vditor);
@@ -8020,18 +8048,22 @@ var inputEvent = function (vditor, event) {
8020
8048
  var _a;
8021
8049
  var range = getSelection().getRangeAt(0).cloneRange();
8022
8050
  var startContainer = range.startContainer;
8023
- if (range.startContainer.nodeType !== 3 && range.startContainer.tagName === "DIV") {
8051
+ if (range.startContainer.nodeType !== 3 &&
8052
+ range.startContainer.tagName === "DIV") {
8024
8053
  startContainer = range.startContainer.childNodes[range.startOffset - 1];
8025
8054
  }
8026
8055
  var blockElement = (0,hasClosest/* hasClosestByAttribute */.a1)(startContainer, "data-block", "0");
8027
8056
  // 不调用 lute 解析
8028
- if (blockElement && event && (event.inputType === "deleteContentBackward" || event.data === " ")) {
8057
+ if (blockElement &&
8058
+ event &&
8059
+ (event.inputType === "deleteContentBackward" || event.data === " ")) {
8029
8060
  // 开始可以输入空格
8030
8061
  var startOffset = (0,selection/* getSelectPosition */.im)(blockElement, vditor.sv.element, range).start;
8031
8062
  var startSpace = true;
8032
8063
  for (var i = startOffset - 1;
8033
8064
  // 软换行后有空格
8034
- i > blockElement.textContent.substr(0, startOffset).lastIndexOf("\n"); i--) {
8065
+ i >
8066
+ blockElement.textContent.substr(0, startOffset).lastIndexOf("\n"); i--) {
8035
8067
  if (blockElement.textContent.charAt(i) !== " " &&
8036
8068
  // 多个 tab 前删除不形成代码块 https://github.com/Vanessa219/vditor/issues/162 1
8037
8069
  blockElement.textContent.charAt(i) !== "\t") {
@@ -8051,18 +8083,22 @@ var inputEvent = function (vditor, event) {
8051
8083
  var codeBlockMarkerElement = (0,hasClosest/* hasClosestByAttribute */.a1)(startContainer, "data-type", "code-block-open-marker") ||
8052
8084
  (0,hasClosest/* hasClosestByAttribute */.a1)(startContainer, "data-type", "code-block-close-marker");
8053
8085
  if (codeBlockMarkerElement) {
8054
- if (codeBlockMarkerElement.getAttribute("data-type") === "code-block-close-marker") {
8086
+ if (codeBlockMarkerElement.getAttribute("data-type") ===
8087
+ "code-block-close-marker") {
8055
8088
  var openMarkerElement = getSideByType(startContainer, "code-block-open-marker");
8056
8089
  if (openMarkerElement) {
8057
- openMarkerElement.textContent = codeBlockMarkerElement.textContent;
8090
+ openMarkerElement.textContent =
8091
+ codeBlockMarkerElement.textContent;
8058
8092
  processAfterRender(vditor);
8059
8093
  return;
8060
8094
  }
8061
8095
  }
8062
- if (codeBlockMarkerElement.getAttribute("data-type") === "code-block-open-marker") {
8096
+ if (codeBlockMarkerElement.getAttribute("data-type") ===
8097
+ "code-block-open-marker") {
8063
8098
  var openMarkerElement = getSideByType(startContainer, "code-block-close-marker", false);
8064
8099
  if (openMarkerElement) {
8065
- openMarkerElement.textContent = codeBlockMarkerElement.textContent;
8100
+ openMarkerElement.textContent =
8101
+ codeBlockMarkerElement.textContent;
8066
8102
  processAfterRender(vditor);
8067
8103
  return;
8068
8104
  }
@@ -8071,37 +8107,46 @@ var inputEvent = function (vditor, event) {
8071
8107
  // https://github.com/Vanessa219/vditor/issues/877 数学公式输入删除生成节点
8072
8108
  var mathBlockMarkerElement = (0,hasClosest/* hasClosestByAttribute */.a1)(startContainer, "data-type", "math-block-open-marker");
8073
8109
  if (mathBlockMarkerElement) {
8074
- var mathBlockCloseElement = mathBlockMarkerElement.nextElementSibling.nextElementSibling;
8075
- if (mathBlockCloseElement && mathBlockCloseElement.getAttribute("data-type") === "math-block-close-marker") {
8110
+ var mathBlockCloseElement = mathBlockMarkerElement.nextElementSibling
8111
+ .nextElementSibling;
8112
+ if (mathBlockCloseElement &&
8113
+ mathBlockCloseElement.getAttribute("data-type") ===
8114
+ "math-block-close-marker") {
8076
8115
  mathBlockCloseElement.remove();
8077
8116
  processAfterRender(vditor);
8078
8117
  }
8079
8118
  return;
8080
8119
  }
8081
- blockElement.querySelectorAll('[data-type="code-block-open-marker"]').forEach(function (item) {
8120
+ blockElement
8121
+ .querySelectorAll('[data-type="code-block-open-marker"]')
8122
+ .forEach(function (item) {
8082
8123
  if (item.textContent.length === 1) {
8083
8124
  item.remove();
8084
8125
  }
8085
8126
  });
8086
- blockElement.querySelectorAll('[data-type="code-block-close-marker"]').forEach(function (item) {
8127
+ blockElement
8128
+ .querySelectorAll('[data-type="code-block-close-marker"]')
8129
+ .forEach(function (item) {
8087
8130
  if (item.textContent.length === 1) {
8088
8131
  item.remove();
8089
8132
  }
8090
8133
  });
8091
8134
  // 标题删除
8092
8135
  var headingElement = (0,hasClosest/* hasClosestByAttribute */.a1)(startContainer, "data-type", "heading-marker");
8093
- if (headingElement && headingElement.textContent.indexOf("#") === -1) {
8136
+ if (headingElement &&
8137
+ headingElement.textContent.indexOf("#") === -1) {
8094
8138
  processAfterRender(vditor);
8095
8139
  return;
8096
8140
  }
8097
8141
  }
8098
8142
  // 删除或空格不解析,否则会 format 回去
8099
- if ((event.data === " " || event.inputType === "deleteContentBackward") &&
8100
- ((0,hasClosest/* hasClosestByAttribute */.a1)(startContainer, "data-type", "padding") // 场景:b 前进行删除 [> 1. a\n> b]
8101
- || (0,hasClosest/* hasClosestByAttribute */.a1)(startContainer, "data-type", "li-marker") // 场景:删除最后一个字符 [* 1\n* ]
8102
- || (0,hasClosest/* hasClosestByAttribute */.a1)(startContainer, "data-type", "task-marker") // 场景:删除最后一个字符 [* [ ] ]
8103
- || (0,hasClosest/* hasClosestByAttribute */.a1)(startContainer, "data-type", "blockquote-marker") // 场景:删除最后一个字符 [> ]
8104
- )) {
8143
+ if ((event.data === " " ||
8144
+ event.inputType === "deleteContentBackward") &&
8145
+ ((0,hasClosest/* hasClosestByAttribute */.a1)(startContainer, "data-type", "padding") || // 场景:b 前进行删除 [> 1. a\n> b]
8146
+ (0,hasClosest/* hasClosestByAttribute */.a1)(startContainer, "data-type", "li-marker") || // 场景:删除最后一个字符 [* 1\n* ]
8147
+ (0,hasClosest/* hasClosestByAttribute */.a1)(startContainer, "data-type", "task-marker") || // 场景:删除最后一个字符 [* [ ] ]
8148
+ (0,hasClosest/* hasClosestByAttribute */.a1)(startContainer, "data-type", "blockquote-marker")) // 场景:删除最后一个字符 [> ]
8149
+ ) {
8105
8150
  processAfterRender(vditor);
8106
8151
  return;
8107
8152
  }
@@ -8114,7 +8159,8 @@ var inputEvent = function (vditor, event) {
8114
8159
  if (!blockElement) {
8115
8160
  blockElement = vditor.sv.element;
8116
8161
  }
8117
- if (((_a = blockElement.firstElementChild) === null || _a === void 0 ? void 0 : _a.getAttribute("data-type")) === "link-ref-defs-block") {
8162
+ if (((_a = blockElement.firstElementChild) === null || _a === void 0 ? void 0 : _a.getAttribute("data-type")) ===
8163
+ "link-ref-defs-block") {
8118
8164
  // 修改链接引用
8119
8165
  blockElement = vditor.sv.element;
8120
8166
  }
@@ -8129,9 +8175,11 @@ var inputEvent = function (vditor, event) {
8129
8175
  }
8130
8176
  // 清除浏览器自带的样式
8131
8177
  blockElement.querySelectorAll("[style]").forEach(function (item) {
8178
+ // 不可前置,否则会影响 newline 的样式
8132
8179
  item.removeAttribute("style");
8133
8180
  });
8134
8181
  blockElement.querySelectorAll("font").forEach(function (item) {
8182
+ // 不可前置,否则会影响光标的位置
8135
8183
  item.outerHTML = item.innerHTML;
8136
8184
  });
8137
8185
  var html = blockElement.textContent;
@@ -8145,22 +8193,29 @@ var inputEvent = function (vditor, event) {
8145
8193
  html = blockElement.previousElementSibling.textContent + html;
8146
8194
  blockElement.previousElementSibling.remove();
8147
8195
  }
8148
- if (blockElement.previousElementSibling && html.indexOf("---\n") === 0) {
8196
+ if (blockElement.previousElementSibling &&
8197
+ html.indexOf("---\n") === 0) {
8149
8198
  // 确认 yaml-front 是否为首行
8150
8199
  html = blockElement.previousElementSibling.textContent + html;
8151
8200
  blockElement.previousElementSibling.remove();
8152
8201
  }
8153
8202
  // 添加链接引用
8154
8203
  var footnotes_1 = "";
8155
- vditor.sv.element.querySelectorAll("[data-type='link-ref-defs-block']").forEach(function (item, index) {
8156
- if (item && !blockElement.isEqualNode(item.parentElement)) {
8204
+ vditor.sv.element
8205
+ .querySelectorAll("[data-type='link-ref-defs-block']")
8206
+ .forEach(function (item, index) {
8207
+ if (item &&
8208
+ !blockElement.isEqualNode(item.parentElement)) {
8157
8209
  footnotes_1 += item.parentElement.textContent + "\n";
8158
8210
  item.parentElement.remove();
8159
8211
  }
8160
8212
  });
8161
8213
  // 添加脚注到文章头,便于lute处理
8162
- vditor.sv.element.querySelectorAll("[data-type='footnotes-link']").forEach(function (item, index) {
8163
- if (item && !blockElement.isEqualNode(item.parentElement)) {
8214
+ vditor.sv.element
8215
+ .querySelectorAll("[data-type='footnotes-link']")
8216
+ .forEach(function (item, index) {
8217
+ if (item &&
8218
+ !blockElement.isEqualNode(item.parentElement)) {
8164
8219
  footnotes_1 += item.parentElement.textContent + "\n";
8165
8220
  item.parentElement.remove();
8166
8221
  }
@@ -8174,7 +8229,9 @@ var inputEvent = function (vditor, event) {
8174
8229
  else {
8175
8230
  blockElement.outerHTML = html;
8176
8231
  }
8177
- vditor.sv.element.querySelectorAll("[data-type='link-ref-defs-block']").forEach(function (item) {
8232
+ vditor.sv.element
8233
+ .querySelectorAll("[data-type='link-ref-defs-block']")
8234
+ .forEach(function (item) {
8178
8235
  vditor.sv.element.insertAdjacentElement("beforeend", item.parentElement);
8179
8236
  });
8180
8237
  // 合并脚注
@@ -8678,117 +8735,14 @@ var highlightToolbarIR = function (vditor) {
8678
8735
 
8679
8736
  ;// CONCATENATED MODULE: ./src/ts/util/attachLineNumbers.ts
8680
8737
  /**
8681
- * 预处理 Markdown:构建块、无序列表、有序列表的行号索引。
8738
+ * 为编辑区域添加行号标记:
8739
+ * - 为所有包含 `data-block` 的块级节点写入 `data-linenumber`
8740
+ * - 额外为每个 `ul` 的直接 `li` 子元素写入 `data-linenumber`(不修改 `ul` 本身)
8741
+ * 通过解析传入的 Markdown 源文本,建立内容到源文件行号的映射,
8742
+ * 兼顾多行文本、嵌套列表、重复内容及空白/特殊字符,并提供基础错误保护。
8682
8743
  */
8683
- var prepareLineNumberIndex = function (sourceMarkdown) {
8684
- var ZWSP = "\u200b";
8685
- var normalize = function (text) {
8686
- return text
8687
- .replace(/\r\n|\r/g, "\n")
8688
- .replace(new RegExp(ZWSP, "g"), "")
8689
- .replace(/\u00a0/g, " ")
8690
- .replace(/\u2006/g, "")
8691
- .replace(/[\t\f\v ]+/g, " ");
8692
- };
8693
- var stripInlineMD = function (text) {
8694
- return text
8695
- .replace(/\\([*_`~])/g, "$1")
8696
- .replace(/\*\*|__/g, "")
8697
- .replace(/\*|_/g, "")
8698
- .replace(/~~/g, "")
8699
- .replace(/`+/g, "")
8700
- .replace(/\\\(/g, "(")
8701
- .replace(/\\\)/g, ")")
8702
- .replace(/\\\[/g, "[")
8703
- .replace(/\\\]/g, "]")
8704
- .replace(/\$/g, "")
8705
- .trim();
8706
- };
8707
- var stripInlineForList = function (text) {
8708
- return stripInlineMD(text)
8709
- .replace(/\$(?:\\.|[^$])*\$/g, "")
8710
- .replace(/\\\([^)]*\\\)/g, "")
8711
- .replace(/\\\[[^\]]*\\\]/g, "")
8712
- .replace(/\\[a-zA-Z]+/g, "")
8713
- .replace(/[{}]/g, "")
8714
- .trim();
8715
- };
8716
- var srcLines = normalize(sourceMarkdown).split("\n");
8717
- var strippedLines = srcLines.map(function (l) { return stripInlineMD(l); });
8718
- var lineLookup = new Map();
8719
- for (var i = 0; i < strippedLines.length; i++) {
8720
- var key = strippedLines[i];
8721
- if (!lineLookup.has(key)) {
8722
- lineLookup.set(key, [i + 1]);
8723
- }
8724
- else {
8725
- lineLookup.get(key).push(i + 1);
8726
- }
8727
- }
8728
- var unorderedEntries = [];
8729
- var unorderedLookup = new Map();
8730
- for (var i = 0; i < srcLines.length; i++) {
8731
- var raw = srcLines[i];
8732
- var m = raw.match(/^\s*[*+-]\s+(?:\[(?: |x|X)\]\s+)?(.*)$/);
8733
- if (m && typeof m[1] === "string") {
8734
- var contentStripped = stripInlineForList(m[1]);
8735
- unorderedEntries.push({ ln: i + 1, content: contentStripped });
8736
- if (!unorderedLookup.has(contentStripped)) {
8737
- unorderedLookup.set(contentStripped, [i + 1]);
8738
- }
8739
- else {
8740
- unorderedLookup.get(contentStripped).push(i + 1);
8741
- }
8742
- }
8743
- }
8744
- var orderedEntries = [];
8745
- var orderedLookup = new Map();
8746
- var ORDERED_RE = /\s*\d+(?:[.)、.。]|[\uFF0E\uFF09\u3001])\s+(?:\[(?: |x|X)\]\s+)?(.*)/;
8747
- for (var i = 0; i < srcLines.length; i++) {
8748
- var raw = srcLines[i];
8749
- var m = raw.match(new RegExp("^".concat(ORDERED_RE.source, "$")));
8750
- if (m && typeof m[1] === "string") {
8751
- var contentStripped = stripInlineForList(m[1]);
8752
- orderedEntries.push({ ln: i + 1, content: contentStripped });
8753
- if (!orderedLookup.has(contentStripped)) {
8754
- orderedLookup.set(contentStripped, [i + 1]);
8755
- }
8756
- else {
8757
- orderedLookup.get(contentStripped).push(i + 1);
8758
- }
8759
- }
8760
- }
8761
- var orderedGroups = [];
8762
- for (var i = 0; i < srcLines.length;) {
8763
- var raw = srcLines[i];
8764
- if (new RegExp("^".concat(ORDERED_RE.source, "$")).test(raw)) {
8765
- var group = [];
8766
- while (i < srcLines.length &&
8767
- new RegExp("^".concat(ORDERED_RE.source, "$")).test(srcLines[i])) {
8768
- group.push(i + 1);
8769
- i++;
8770
- }
8771
- if (group.length > 0) {
8772
- orderedGroups.push(group);
8773
- }
8774
- }
8775
- else {
8776
- i++;
8777
- }
8778
- }
8779
- return {
8780
- srcLines: srcLines,
8781
- strippedLines: strippedLines,
8782
- lineLookup: lineLookup,
8783
- unorderedEntries: unorderedEntries,
8784
- unorderedLookup: unorderedLookup,
8785
- orderedEntries: orderedEntries,
8786
- orderedLookup: orderedLookup,
8787
- orderedGroups: orderedGroups,
8788
- };
8789
- };
8790
- var attachLineNumbersToBlocks = function (root, sourceMarkdownOrIndex) {
8791
- if (!root || !sourceMarkdownOrIndex) {
8744
+ var attachLineNumbersToBlocks = function (root, sourceMarkdown) {
8745
+ if (!root || !sourceMarkdown) {
8792
8746
  return;
8793
8747
  }
8794
8748
  var ZWSP = "\u200b";
@@ -8800,10 +8754,8 @@ var attachLineNumbersToBlocks = function (root, sourceMarkdownOrIndex) {
8800
8754
  .replace(/\u2006/g, "")
8801
8755
  .replace(/[\t\f\v ]+/g, " ");
8802
8756
  };
8803
- var index = typeof sourceMarkdownOrIndex === "string"
8804
- ? prepareLineNumberIndex(sourceMarkdownOrIndex)
8805
- : sourceMarkdownOrIndex;
8806
- var srcLines = index.srcLines;
8757
+ var srcNorm = normalize(sourceMarkdown);
8758
+ var srcLines = srcNorm.split("\n");
8807
8759
  var stripInlineMD = function (text) {
8808
8760
  return (text
8809
8761
  .replace(/\\([*_`~])/g, "$1")
@@ -8832,8 +8784,17 @@ var attachLineNumbersToBlocks = function (root, sourceMarkdownOrIndex) {
8832
8784
  .replace(/[{}]/g, "")
8833
8785
  .trim());
8834
8786
  };
8835
- var strippedLines = index.strippedLines;
8836
- var lineLookup = index.lineLookup;
8787
+ var strippedLines = srcLines.map(function (l) { return stripInlineMD(l); });
8788
+ var lineLookup = new Map();
8789
+ for (var i = 0; i < strippedLines.length; i++) {
8790
+ var key = strippedLines[i];
8791
+ if (!lineLookup.has(key)) {
8792
+ lineLookup.set(key, [i + 1]);
8793
+ }
8794
+ else {
8795
+ lineLookup.get(key).push(i + 1);
8796
+ }
8797
+ }
8837
8798
  var usedLines = new Set();
8838
8799
  var pickFirstUnused = function (candidates) {
8839
8800
  if (!candidates || candidates.length === 0)
@@ -8860,11 +8821,26 @@ var attachLineNumbersToBlocks = function (root, sourceMarkdownOrIndex) {
8860
8821
  return -1;
8861
8822
  };
8862
8823
  /**
8863
- * 无序列表行号索引
8824
+ * 预处理:收集 Markdown 中所有无序列表(ul)行及其去除行内标记后的内容,构建快速查找结构。
8825
+ * 仅匹配以 `*`、`-`、`+` 开头的条目,支持任务列表如 `- [ ]`、`* [x]`。
8864
8826
  */
8827
+ var unorderedListEntries = [];
8828
+ var unorderedLookup = new Map();
8865
8829
  var usedUnorderedLines = new Set();
8866
- var unorderedListEntries = index.unorderedEntries;
8867
- var unorderedLookup = index.unorderedLookup;
8830
+ for (var i = 0; i < srcLines.length; i++) {
8831
+ var raw = srcLines[i];
8832
+ var m = raw.match(/^\s*[*+-]\s+(?:\[(?: |x|X)\]\s+)?(.*)$/);
8833
+ if (m && typeof m[1] === "string") {
8834
+ var contentStripped = stripInlineForList(m[1]);
8835
+ unorderedListEntries.push({ ln: i + 1, content: contentStripped });
8836
+ if (!unorderedLookup.has(contentStripped)) {
8837
+ unorderedLookup.set(contentStripped, [i + 1]);
8838
+ }
8839
+ else {
8840
+ unorderedLookup.get(contentStripped).push(i + 1);
8841
+ }
8842
+ }
8843
+ }
8868
8844
  /**
8869
8845
  * 从无序列表候选行中为给定文本选择一个行号。
8870
8846
  * 优先精确匹配(去标记后完全相同),否则回退到包含匹配。
@@ -8900,15 +8876,47 @@ var attachLineNumbersToBlocks = function (root, sourceMarkdownOrIndex) {
8900
8876
  return -1;
8901
8877
  };
8902
8878
  /**
8903
- * 有序列表行号索引
8879
+ * 预处理:收集 Markdown 中所有有序列表(ol)行及其内容,支持 `1.` 或 `1)` 以及任务列表前缀。
8904
8880
  */
8881
+ var orderedListEntries = [];
8882
+ var orderedLookup = new Map();
8905
8883
  var usedOrderedLines = new Set();
8906
- var orderedListEntries = index.orderedEntries;
8907
- var orderedLookup = index.orderedLookup;
8908
- var orderedGroups = index.orderedGroups;
8884
+ var ORDERED_RE = /\s*\d+(?:[.)、.。]|[\uFF0E\uFF09\u3001])\s+(?:\[(?: |x|X)\]\s+)?(.*)/;
8885
+ var ORDERED_FULL = new RegExp("^".concat(ORDERED_RE.source, "$"));
8886
+ for (var i = 0; i < srcLines.length; i++) {
8887
+ var raw = srcLines[i];
8888
+ var m = raw.match(ORDERED_FULL);
8889
+ if (m && typeof m[1] === "string") {
8890
+ var contentStripped = stripInlineForList(m[1]);
8891
+ orderedListEntries.push({ ln: i + 1, content: contentStripped });
8892
+ if (!orderedLookup.has(contentStripped)) {
8893
+ orderedLookup.set(contentStripped, [i + 1]);
8894
+ }
8895
+ else {
8896
+ orderedLookup.get(contentStripped).push(i + 1);
8897
+ }
8898
+ }
8899
+ }
8909
8900
  console.debug("[LineNumber][ol:index]", {
8910
8901
  total: orderedListEntries.length,
8911
8902
  });
8903
+ var orderedGroups = [];
8904
+ for (var i = 0; i < srcLines.length;) {
8905
+ var raw = srcLines[i];
8906
+ if (ORDERED_FULL.test(raw)) {
8907
+ var group = [];
8908
+ while (i < srcLines.length && ORDERED_FULL.test(srcLines[i])) {
8909
+ group.push(i + 1);
8910
+ i++;
8911
+ }
8912
+ if (group.length > 0) {
8913
+ orderedGroups.push(group);
8914
+ }
8915
+ }
8916
+ else {
8917
+ i++;
8918
+ }
8919
+ }
8912
8920
  /**
8913
8921
  * 为给定文本在有序列表候选中选择行号,精确匹配优先,包含匹配回退。
8914
8922
  */
@@ -8965,19 +8973,28 @@ var attachLineNumbersToBlocks = function (root, sourceMarkdownOrIndex) {
8965
8973
  var container = el;
8966
8974
  var dataType = container.getAttribute("data-type") || "";
8967
8975
  if (dataType === "math-block" || dataType === "code-block") {
8968
- // container.setAttribute("data-linenumber", "");
8976
+ return;
8977
+ }
8978
+ // 仅 li 需要行号:跳过并清理 ul/ol 自身及其内部嵌套的 p/div 等块
8979
+ var tagName = container.tagName;
8980
+ if (tagName === "UL" || tagName === "OL") {
8981
+ container.removeAttribute("data-linenumber");
8982
+ return;
8983
+ }
8984
+ var liAncestor = container.closest("li");
8985
+ if (liAncestor) {
8986
+ container.removeAttribute("data-linenumber");
8969
8987
  return;
8970
8988
  }
8971
8989
  var text = container.textContent || "";
8972
8990
  var normText = normalize(text);
8973
8991
  // 跳过纯空白块
8974
8992
  if (!normText.trim()) {
8975
- // container.setAttribute("data-linenumber", "");
8993
+ container.removeAttribute("data-linenumber");
8976
8994
  return;
8977
8995
  }
8978
8996
  var lineNumber = -1;
8979
- var tag = container.tagName;
8980
- if (tag === "BLOCKQUOTE") {
8997
+ if (tagName === "BLOCKQUOTE") {
8981
8998
  var firstLine = normText.split("\n").find(function (l) { return l.trim().length > 0; }) ||
8982
8999
  normText;
8983
9000
  var stripped = stripInlineMD(firstLine);
@@ -9151,6 +9168,34 @@ var attachLineNumbersToBlocks = function (root, sourceMarkdownOrIndex) {
9151
9168
  }
9152
9169
  });
9153
9170
  };
9171
+ /**
9172
+ * 节流后的行号更新函数,避免频繁更新 data-linenumber
9173
+ */
9174
+ var attachLineNumbersToBlocksThrottled = (function () {
9175
+ var last = 0;
9176
+ var timer = 0;
9177
+ var lastArgs = null;
9178
+ var wait = 500;
9179
+ var invoke = function () {
9180
+ timer = 0;
9181
+ last = Date.now();
9182
+ var args = lastArgs;
9183
+ lastArgs = null;
9184
+ if (args) {
9185
+ attachLineNumbersToBlocks(args[0], args[1]);
9186
+ }
9187
+ };
9188
+ return function (root, source) {
9189
+ var now = Date.now();
9190
+ lastArgs = [root, source];
9191
+ if (now - last >= wait) {
9192
+ invoke();
9193
+ }
9194
+ else if (!timer) {
9195
+ timer = window.setTimeout(invoke, wait - (now - last));
9196
+ }
9197
+ };
9198
+ })();
9154
9199
 
9155
9200
  ;// CONCATENATED MODULE: ./src/ts/wysiwyg/afterRenderEvent.ts
9156
9201
 
@@ -9190,8 +9235,9 @@ var afterRenderEvent = function (vditor, options) {
9190
9235
  vditor.undo.addToUndoStack(vditor);
9191
9236
  }
9192
9237
  try {
9193
- var lnIndex = vditor.lineNumberIndex || prepareLineNumberIndex(text);
9194
- attachLineNumbersToBlocks(vditor.wysiwyg.element, lnIndex);
9238
+ if (vditor.options.lineNumber) {
9239
+ attachLineNumbersToBlocksThrottled(vditor.wysiwyg.element, text);
9240
+ }
9195
9241
  }
9196
9242
  catch (_a) {
9197
9243
  void 0;
@@ -10797,6 +10843,7 @@ var highlightToolbar = function (vditor) {
10797
10843
  ;// CONCATENATED MODULE: ./src/ts/wysiwyg/renderDomByMd.ts
10798
10844
 
10799
10845
 
10846
+
10800
10847
  var renderDomByMd = function (vditor, md, options) {
10801
10848
  if (options === void 0) { options = {
10802
10849
  enableAddUndoStack: true,
@@ -10805,10 +10852,20 @@ var renderDomByMd = function (vditor, md, options) {
10805
10852
  }; }
10806
10853
  var editorElement = vditor.wysiwyg.element;
10807
10854
  editorElement.innerHTML = vditor.lute.Md2VditorDOM(md);
10808
- editorElement.querySelectorAll(".vditor-wysiwyg__preview[data-render='2']").forEach(function (item) {
10855
+ editorElement
10856
+ .querySelectorAll(".vditor-wysiwyg__preview[data-render='2']")
10857
+ .forEach(function (item) {
10809
10858
  processCodeRender(item, vditor);
10810
10859
  item.previousElementSibling.setAttribute("style", "display:none");
10811
10860
  });
10861
+ if (vditor.options.lineNumber) {
10862
+ try {
10863
+ attachLineNumbersToBlocks(editorElement, md);
10864
+ }
10865
+ catch (_a) {
10866
+ void 0;
10867
+ }
10868
+ }
10812
10869
  afterRenderEvent(vditor, options);
10813
10870
  };
10814
10871
 
@@ -11820,8 +11877,9 @@ var processAfterRender = function (vditor, options) {
11820
11877
  vditor.undo.addToUndoStack(vditor);
11821
11878
  }
11822
11879
  try {
11823
- var lnIndex = vditor.lineNumberIndex || prepareLineNumberIndex(text);
11824
- attachLineNumbersToBlocks(vditor.sv.element, lnIndex);
11880
+ if (vditor.options.lineNumber) {
11881
+ attachLineNumbersToBlocksThrottled(vditor.sv.element, text);
11882
+ }
11825
11883
  }
11826
11884
  catch (_a) {
11827
11885
  void 0;
@@ -12261,18 +12319,19 @@ var input_input = function (vditor, range, event) {
12261
12319
  // 使用顶级块元素,应使用 innerHTML
12262
12320
  blockElement = vditor.wysiwyg.element;
12263
12321
  }
12264
- if (event && event.inputType !== "formatItalic"
12265
- && event.inputType !== "deleteByDrag"
12266
- && event.inputType !== "insertFromDrop"
12267
- && event.inputType !== "formatBold"
12268
- && event.inputType !== "formatRemove"
12269
- && event.inputType !== "formatStrikeThrough"
12270
- && event.inputType !== "insertUnorderedList"
12271
- && event.inputType !== "insertOrderedList"
12272
- && event.inputType !== "formatOutdent"
12273
- && event.inputType !== "formatIndent"
12274
- && event.inputType !== "" // document.execCommand('unlink', false)
12275
- || !event) {
12322
+ if ((event &&
12323
+ event.inputType !== "formatItalic" &&
12324
+ event.inputType !== "deleteByDrag" &&
12325
+ event.inputType !== "insertFromDrop" &&
12326
+ event.inputType !== "formatBold" &&
12327
+ event.inputType !== "formatRemove" &&
12328
+ event.inputType !== "formatStrikeThrough" &&
12329
+ event.inputType !== "insertUnorderedList" &&
12330
+ event.inputType !== "insertOrderedList" &&
12331
+ event.inputType !== "formatOutdent" &&
12332
+ event.inputType !== "formatIndent" &&
12333
+ event.inputType !== "") || // document.execCommand('unlink', false)
12334
+ !event) {
12276
12335
  var previousAEmptyElement = previoueIsEmptyA(range.startContainer);
12277
12336
  if (previousAEmptyElement) {
12278
12337
  // 链接结尾回车不应该复制到下一行 https://github.com/Vanessa219/vditor/issues/163
@@ -12315,7 +12374,8 @@ var input_input = function (vditor, range, event) {
12315
12374
  var blockquoteElement = (0,hasClosestByHeadings/* hasClosestByTag */.S)(range.startContainer, "BLOCKQUOTE");
12316
12375
  if (blockquoteElement) {
12317
12376
  // li 中有 blockquote 就只渲染 blockquote
12318
- blockElement = (0,hasClosest/* hasClosestBlock */.F9)(range.startContainer) || blockElement;
12377
+ blockElement =
12378
+ (0,hasClosest/* hasClosestBlock */.F9)(range.startContainer) || blockElement;
12319
12379
  }
12320
12380
  else {
12321
12381
  blockElement = topListElement;
@@ -12326,15 +12386,20 @@ var input_input = function (vditor, range, event) {
12326
12386
  blockElement = footnoteElement;
12327
12387
  }
12328
12388
  html_1 = blockElement.outerHTML;
12329
- if (blockElement.tagName === "UL" || blockElement.tagName === "OL") {
12389
+ if (blockElement.tagName === "UL" ||
12390
+ blockElement.tagName === "OL") {
12330
12391
  // 如果为列表的话,需要把上下的列表都重绘
12331
12392
  var listPrevElement = blockElement.previousElementSibling;
12332
12393
  var listNextElement = blockElement.nextElementSibling;
12333
- if (listPrevElement && (listPrevElement.tagName === "UL" || listPrevElement.tagName === "OL")) {
12394
+ if (listPrevElement &&
12395
+ (listPrevElement.tagName === "UL" ||
12396
+ listPrevElement.tagName === "OL")) {
12334
12397
  html_1 = listPrevElement.outerHTML + html_1;
12335
12398
  listPrevElement.remove();
12336
12399
  }
12337
- if (listNextElement && (listNextElement.tagName === "UL" || listNextElement.tagName === "OL")) {
12400
+ if (listNextElement &&
12401
+ (listNextElement.tagName === "UL" ||
12402
+ listNextElement.tagName === "OL")) {
12338
12403
  html_1 = html_1 + listNextElement.outerHTML;
12339
12404
  listNextElement.remove();
12340
12405
  }
@@ -12343,15 +12408,21 @@ var input_input = function (vditor, range, event) {
12343
12408
  }
12344
12409
  if (!blockElement.innerText.startsWith("```")) {
12345
12410
  // 添加链接引用
12346
- vditor.wysiwyg.element.querySelectorAll("[data-type='link-ref-defs-block']").forEach(function (item) {
12347
- if (item && !blockElement.isEqualNode(item)) {
12411
+ vditor.wysiwyg.element
12412
+ .querySelectorAll("[data-type='link-ref-defs-block']")
12413
+ .forEach(function (item) {
12414
+ if (item &&
12415
+ !blockElement.isEqualNode(item)) {
12348
12416
  html_1 += item.outerHTML;
12349
12417
  item.remove();
12350
12418
  }
12351
12419
  });
12352
12420
  // 添加脚注
12353
- vditor.wysiwyg.element.querySelectorAll("[data-type='footnotes-block']").forEach(function (item) {
12354
- if (item && !blockElement.isEqualNode(item)) {
12421
+ vditor.wysiwyg.element
12422
+ .querySelectorAll("[data-type='footnotes-block']")
12423
+ .forEach(function (item) {
12424
+ if (item &&
12425
+ !blockElement.isEqualNode(item)) {
12355
12426
  html_1 += item.outerHTML;
12356
12427
  item.remove();
12357
12428
  }
@@ -12362,10 +12433,12 @@ var input_input = function (vditor, range, event) {
12362
12433
  html_1 = blockElement.innerHTML;
12363
12434
  }
12364
12435
  // 合并多个 em, strong,s。以防止多个相同元素在一起时不满足 commonmark 规范,出现标记符
12365
- html_1 = html_1.replace(/<\/(strong|b)><strong data-marker="\W{2}">/g, "")
12436
+ html_1 = html_1
12437
+ .replace(/<\/(strong|b)><strong data-marker="\W{2}">/g, "")
12366
12438
  .replace(/<\/(em|i)><em data-marker="\W{1}">/g, "")
12367
12439
  .replace(/<\/(s|strike)><s data-marker="~{1,2}">/g, "");
12368
- if (html_1 === '<p data-block="0">```<wbr></p>' && vditor.hint.recentLanguage) {
12440
+ if (html_1 === '<p data-block="0">```<wbr></p>' &&
12441
+ vditor.hint.recentLanguage) {
12369
12442
  html_1 = '<p data-block="0">```<wbr></p>'.replace("```", "```" + vditor.hint.recentLanguage);
12370
12443
  }
12371
12444
  log("SpinVditorDOM", html_1, "argument", vditor.options.debugger);
@@ -12418,11 +12491,14 @@ var input_input = function (vditor, range, event) {
12418
12491
  }
12419
12492
  // 设置光标
12420
12493
  (0,selection/* setRangeByWbr */.ib)(vditor.wysiwyg.element, range);
12421
- vditor.wysiwyg.element.querySelectorAll(".vditor-wysiwyg__preview[data-render='2']")
12494
+ vditor.wysiwyg.element
12495
+ .querySelectorAll(".vditor-wysiwyg__preview[data-render='2']")
12422
12496
  .forEach(function (item) {
12423
12497
  processCodeRender(item, vditor);
12424
12498
  });
12425
- if (event && (event.inputType === "deleteContentBackward" || event.inputType === "deleteContentForward") &&
12499
+ if (event &&
12500
+ (event.inputType === "deleteContentBackward" ||
12501
+ event.inputType === "deleteContentForward") &&
12426
12502
  vditor.options.comment.enable) {
12427
12503
  vditor.wysiwyg.triggerRemoveComment(vditor);
12428
12504
  vditor.options.comment.adjustTop(vditor.wysiwyg.getComments(vditor, true));
@@ -12930,25 +13006,12 @@ var isHeadingMD = function (text) {
12930
13006
  }
12931
13007
  return false;
12932
13008
  };
12933
-
12934
-
12935
13009
  var execAfterRender = function (vditor, options) {
12936
13010
  if (options === void 0) { options = {
12937
13011
  enableAddUndoStack: true,
12938
13012
  enableHint: false,
12939
13013
  enableInput: true,
12940
13014
  }; }
12941
- try {
12942
- var md = getMarkdown(vditor);
12943
- var cached = vditor.lineNumberIndex;
12944
- var same = cached &&
12945
- Array.isArray(cached.srcLines) &&
12946
- cached.srcLines.join("\n") === md;
12947
- vditor.lineNumberIndex = same ? cached : prepareLineNumberIndex(md);
12948
- }
12949
- catch (_a) {
12950
- vditor.lineNumberIndex = undefined;
12951
- }
12952
13015
  if (vditor.currentMode === "wysiwyg") {
12953
13016
  afterRenderEvent(vditor, options);
12954
13017
  }
@@ -14277,8 +14340,9 @@ var process_processAfterRender = function (vditor, options) {
14277
14340
  vditor.undo.addToUndoStack(vditor);
14278
14341
  }
14279
14342
  try {
14280
- var lnIndex = vditor.lineNumberIndex || prepareLineNumberIndex(text);
14281
- attachLineNumbersToBlocks(vditor.ir.element, lnIndex);
14343
+ if (vditor.options.lineNumber) {
14344
+ attachLineNumbersToBlocksThrottled(vditor.ir.element, text);
14345
+ }
14282
14346
  }
14283
14347
  catch (_a) {
14284
14348
  void 0;
@@ -17718,7 +17782,8 @@ var WYSIWYG = /** @class */ (function () {
17718
17782
  }
17719
17783
  divElement.innerHTML = "<pre class=\"vditor-reset\" placeholder=\"".concat(vditor.options.placeholder, "\"\n contenteditable=\"true\" spellcheck=\"false\"></pre>\n<div class=\"vditor-panel vditor-panel--none\"></div>\n<div class=\"vditor-panel vditor-panel--none\">\n <button type=\"button\" aria-label=\"").concat(window.VditorI18n.comment, "\" class=\"vditor-icon vditor-tooltipped vditor-tooltipped__n\">\n <svg><use xlink:href=\"#vditor-icon-comment\"></use></svg>\n </button>\n</div>");
17720
17784
  this.element = divElement.firstElementChild;
17721
- this.popover = divElement.firstElementChild.nextElementSibling;
17785
+ this.popover = divElement.firstElementChild
17786
+ .nextElementSibling;
17722
17787
  this.selectPopover = divElement.lastElementChild;
17723
17788
  this.bindEvent(vditor);
17724
17789
  focusEvent(vditor, this.element);
@@ -17751,28 +17816,31 @@ var WYSIWYG = /** @class */ (function () {
17751
17816
  item.setAttribute("data-cmtids", item.getAttribute("data-cmtids") + " " + id);
17752
17817
  }
17753
17818
  if (wrap) {
17754
- if (item.nodeType !== 3 && item.getAttribute("data-block") === "0"
17755
- && index === 0 && rangeClone.startOffset > 0) {
17756
- item.innerHTML =
17757
- "<span class=\"vditor-comment\" data-cmtids=\"".concat(id, "\">").concat(item.innerHTML, "</span>");
17819
+ if (item.nodeType !== 3 &&
17820
+ item.getAttribute("data-block") === "0" &&
17821
+ index === 0 &&
17822
+ rangeClone.startOffset > 0) {
17823
+ item.innerHTML = "<span class=\"vditor-comment\" data-cmtids=\"".concat(id, "\">").concat(item.innerHTML, "</span>");
17758
17824
  blockStartElement = item;
17759
17825
  }
17760
- else if (item.nodeType !== 3 && item.getAttribute("data-block") === "0"
17761
- && index === contents.childNodes.length - 1
17762
- && rangeClone.endOffset < rangeClone.endContainer.textContent.length) {
17763
- item.innerHTML =
17764
- "<span class=\"vditor-comment\" data-cmtids=\"".concat(id, "\">").concat(item.innerHTML, "</span>");
17826
+ else if (item.nodeType !== 3 &&
17827
+ item.getAttribute("data-block") === "0" &&
17828
+ index === contents.childNodes.length - 1 &&
17829
+ rangeClone.endOffset <
17830
+ rangeClone.endContainer.textContent.length) {
17831
+ item.innerHTML = "<span class=\"vditor-comment\" data-cmtids=\"".concat(id, "\">").concat(item.innerHTML, "</span>");
17765
17832
  blockEndElement = item;
17766
17833
  }
17767
- else if (item.nodeType !== 3 && item.getAttribute("data-block") === "0") {
17834
+ else if (item.nodeType !== 3 &&
17835
+ item.getAttribute("data-block") === "0") {
17768
17836
  if (index === 0) {
17769
17837
  removeStart = true;
17770
17838
  }
17771
- else if (index === contents.childNodes.length - 1) {
17839
+ else if (index ===
17840
+ contents.childNodes.length - 1) {
17772
17841
  removeEnd = true;
17773
17842
  }
17774
- item.innerHTML =
17775
- "<span class=\"vditor-comment\" data-cmtids=\"".concat(id, "\">").concat(item.innerHTML, "</span>");
17843
+ item.innerHTML = "<span class=\"vditor-comment\" data-cmtids=\"".concat(id, "\">").concat(item.innerHTML, "</span>");
17776
17844
  }
17777
17845
  else {
17778
17846
  var commentElement = document.createElement("span");
@@ -17789,7 +17857,10 @@ var WYSIWYG = /** @class */ (function () {
17789
17857
  startElement.insertAdjacentHTML("beforeend", blockStartElement.innerHTML);
17790
17858
  blockStartElement.remove();
17791
17859
  }
17792
- else if (startElement.textContent.trim().replace(constants/* Constants.ZWSP */.g.ZWSP, "") === "" && removeStart) {
17860
+ else if (startElement.textContent
17861
+ .trim()
17862
+ .replace(constants/* Constants.ZWSP */.g.ZWSP, "") === "" &&
17863
+ removeStart) {
17793
17864
  startElement.remove();
17794
17865
  }
17795
17866
  }
@@ -17799,7 +17870,10 @@ var WYSIWYG = /** @class */ (function () {
17799
17870
  endElement.insertAdjacentHTML("afterbegin", blockEndElement.innerHTML);
17800
17871
  blockEndElement.remove();
17801
17872
  }
17802
- else if (endElement.textContent.trim().replace(constants/* Constants.ZWSP */.g.ZWSP, "") === "" && removeEnd) {
17873
+ else if (endElement.textContent
17874
+ .trim()
17875
+ .replace(constants/* Constants.ZWSP */.g.ZWSP, "") === "" &&
17876
+ removeEnd) {
17803
17877
  endElement.remove();
17804
17878
  }
17805
17879
  }
@@ -17820,8 +17894,7 @@ var WYSIWYG = /** @class */ (function () {
17820
17894
  if (vditor.currentMode === "wysiwyg" && vditor.options.comment.enable) {
17821
17895
  this.commentIds = [];
17822
17896
  this.element.querySelectorAll(".vditor-comment").forEach(function (item) {
17823
- _this.commentIds =
17824
- _this.commentIds.concat(item.getAttribute("data-cmtids").split(" "));
17897
+ _this.commentIds = _this.commentIds.concat(item.getAttribute("data-cmtids").split(" "));
17825
17898
  });
17826
17899
  this.commentIds = Array.from(new Set(this.commentIds));
17827
17900
  var comments_1 = [];
@@ -17844,7 +17917,9 @@ var WYSIWYG = /** @class */ (function () {
17844
17917
  var s = new Set(b);
17845
17918
  return a.filter(function (x) { return !s.has(x); });
17846
17919
  };
17847
- if (vditor.currentMode === "wysiwyg" && vditor.options.comment.enable && vditor.wysiwyg.commentIds.length > 0) {
17920
+ if (vditor.currentMode === "wysiwyg" &&
17921
+ vditor.options.comment.enable &&
17922
+ vditor.wysiwyg.commentIds.length > 0) {
17848
17923
  var oldIds = JSON.parse(JSON.stringify(this.commentIds));
17849
17924
  this.getComments(vditor);
17850
17925
  var removedIds = difference(oldIds, this.commentIds);
@@ -17878,7 +17953,9 @@ var WYSIWYG = /** @class */ (function () {
17878
17953
  event.preventDefault();
17879
17954
  var codeElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(range.startContainer, "CODE");
17880
17955
  var codeEndElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(range.endContainer, "CODE");
17881
- if (codeElement && codeEndElement && codeEndElement.isSameNode(codeElement)) {
17956
+ if (codeElement &&
17957
+ codeEndElement &&
17958
+ codeEndElement.isSameNode(codeElement)) {
17882
17959
  var codeText = "";
17883
17960
  if (codeElement.parentElement.tagName === "PRE") {
17884
17961
  codeText = range.toString();
@@ -17908,7 +17985,10 @@ var WYSIWYG = /** @class */ (function () {
17908
17985
  var first = el.firstElementChild;
17909
17986
  return !!first && first.classList.contains("language-math");
17910
17987
  };
17911
- if (startPreview && endPreview && startPreview.isSameNode(endPreview) && isMathPreview(startPreview)) {
17988
+ if (startPreview &&
17989
+ endPreview &&
17990
+ startPreview.isSameNode(endPreview) &&
17991
+ isMathPreview(startPreview)) {
17912
17992
  event.clipboardData.setData("text/plain", range.toString());
17913
17993
  event.clipboardData.setData("text/html", "");
17914
17994
  return;
@@ -17922,14 +18002,16 @@ var WYSIWYG = /** @class */ (function () {
17922
18002
  WYSIWYG.prototype.bindEvent = function (vditor) {
17923
18003
  var _this = this;
17924
18004
  this.unbindListener();
17925
- window.addEventListener("scroll", this.scrollListener = function () {
18005
+ window.addEventListener("scroll", (this.scrollListener = function () {
17926
18006
  hidePanel(vditor, ["hint"]);
17927
- if (_this.popover.style.display !== "block" || _this.selectPopover.style.display !== "block") {
18007
+ if (_this.popover.style.display !== "block" ||
18008
+ _this.selectPopover.style.display !== "block") {
17928
18009
  return;
17929
18010
  }
17930
18011
  var top = parseInt(_this.popover.getAttribute("data-top"), 10);
17931
18012
  if (vditor.options.height !== "auto") {
17932
- if (vditor.options.toolbarConfig.pin && vditor.toolbar.element.getBoundingClientRect().top === 0) {
18013
+ if (vditor.options.toolbarConfig.pin &&
18014
+ vditor.toolbar.element.getBoundingClientRect().top === 0) {
17933
18015
  var popoverTop = Math.max(window.scrollY - vditor.element.offsetTop - 8, Math.min(top - vditor.wysiwyg.element.scrollTop, _this.element.clientHeight - 21)) + "px";
17934
18016
  if (_this.popover.style.display === "block") {
17935
18017
  _this.popover.style.top = popoverTop;
@@ -17943,28 +18025,33 @@ var WYSIWYG = /** @class */ (function () {
17943
18025
  else if (!vditor.options.toolbarConfig.pin) {
17944
18026
  return;
17945
18027
  }
17946
- var popoverTop1 = Math.max(top, (window.scrollY - vditor.element.offsetTop - 8)) + "px";
18028
+ var popoverTop1 = Math.max(top, window.scrollY - vditor.element.offsetTop - 8) + "px";
17947
18029
  if (_this.popover.style.display === "block") {
17948
18030
  _this.popover.style.top = popoverTop1;
17949
18031
  }
17950
18032
  if (_this.selectPopover.style.display === "block") {
17951
18033
  _this.selectPopover.style.top = popoverTop1;
17952
18034
  }
17953
- });
18035
+ }));
17954
18036
  this.element.addEventListener("scroll", function () {
17955
18037
  hidePanel(vditor, ["hint"]);
17956
- if (vditor.options.comment && vditor.options.comment.enable && vditor.options.comment.scroll) {
18038
+ if (vditor.options.comment &&
18039
+ vditor.options.comment.enable &&
18040
+ vditor.options.comment.scroll) {
17957
18041
  vditor.options.comment.scroll(vditor.wysiwyg.element.scrollTop);
17958
18042
  }
17959
18043
  if (_this.popover.style.display !== "block") {
17960
18044
  return;
17961
18045
  }
17962
- var top = parseInt(_this.popover.getAttribute("data-top"), 10) - vditor.wysiwyg.element.scrollTop;
18046
+ var top = parseInt(_this.popover.getAttribute("data-top"), 10) -
18047
+ vditor.wysiwyg.element.scrollTop;
17963
18048
  var max = -8;
17964
- if (vditor.options.toolbarConfig.pin && vditor.toolbar.element.getBoundingClientRect().top === 0) {
18049
+ if (vditor.options.toolbarConfig.pin &&
18050
+ vditor.toolbar.element.getBoundingClientRect().top === 0) {
17965
18051
  max = window.scrollY - vditor.element.offsetTop + max;
17966
18052
  }
17967
- var topPx = Math.max(max, Math.min(top, _this.element.clientHeight - 21)) + "px";
18053
+ var topPx = Math.max(max, Math.min(top, _this.element.clientHeight - 21)) +
18054
+ "px";
17968
18055
  _this.popover.style.top = topPx;
17969
18056
  _this.selectPopover.style.top = topPx;
17970
18057
  });
@@ -17980,7 +18067,8 @@ var WYSIWYG = /** @class */ (function () {
17980
18067
  blockElement.outerHTML = vditor.lute.SpinVditorDOM(blockElement.outerHTML);
17981
18068
  }
17982
18069
  else {
17983
- vditor.wysiwyg.element.innerHTML = vditor.lute.SpinVditorDOM(vditor.wysiwyg.element.innerHTML);
18070
+ vditor.wysiwyg.element.innerHTML =
18071
+ vditor.lute.SpinVditorDOM(vditor.wysiwyg.element.innerHTML);
17984
18072
  }
17985
18073
  (0,selection/* setRangeByWbr */.ib)(vditor.wysiwyg.element, range);
17986
18074
  },
@@ -18003,7 +18091,8 @@ var WYSIWYG = /** @class */ (function () {
18003
18091
  _this.composingLock = false;
18004
18092
  });
18005
18093
  this.element.addEventListener("input", function (event) {
18006
- if (event.inputType === "deleteByDrag" || event.inputType === "insertFromDrop") {
18094
+ if (event.inputType === "deleteByDrag" ||
18095
+ event.inputType === "insertFromDrop") {
18007
18096
  // https://github.com/Vanessa219/vditor/issues/801 编辑器内容拖拽问题
18008
18097
  return;
18009
18098
  }
@@ -18012,7 +18101,10 @@ var WYSIWYG = /** @class */ (function () {
18012
18101
  afterRenderEvent(vditor);
18013
18102
  return;
18014
18103
  }
18015
- if (_this.composingLock || event.data === "‘" || event.data === "“" || event.data === "《") {
18104
+ if (_this.composingLock ||
18105
+ event.data === "‘" ||
18106
+ event.data === "“" ||
18107
+ event.data === "《") {
18016
18108
  afterRenderEvent(vditor);
18017
18109
  return;
18018
18110
  }
@@ -18030,7 +18122,10 @@ var WYSIWYG = /** @class */ (function () {
18030
18122
  var startOffset = (0,selection/* getSelectPosition */.im)(blockElement, vditor.wysiwyg.element, range).start;
18031
18123
  // 开始可以输入空格
18032
18124
  var startSpace = true;
18033
- for (var i = startOffset - 1; i > blockElement.textContent.substr(0, startOffset).lastIndexOf("\n"); i--) {
18125
+ for (var i = startOffset - 1; i >
18126
+ blockElement.textContent
18127
+ .substr(0, startOffset)
18128
+ .lastIndexOf("\n"); i--) {
18034
18129
  if (blockElement.textContent.charAt(i) !== " " &&
18035
18130
  // 多个 tab 前删除不形成代码块 https://github.com/Vanessa219/vditor/issues/162 1
18036
18131
  blockElement.textContent.charAt(i) !== "\t") {
@@ -18044,7 +18139,8 @@ var WYSIWYG = /** @class */ (function () {
18044
18139
  // 结尾可以输入空格
18045
18140
  var endSpace = true;
18046
18141
  for (var i = startOffset - 1; i < blockElement.textContent.length; i++) {
18047
- if (blockElement.textContent.charAt(i) !== " " && blockElement.textContent.charAt(i) !== "\n") {
18142
+ if (blockElement.textContent.charAt(i) !== " " &&
18143
+ blockElement.textContent.charAt(i) !== "\n") {
18048
18144
  endSpace = false;
18049
18145
  break;
18050
18146
  }
@@ -18059,16 +18155,20 @@ var WYSIWYG = /** @class */ (function () {
18059
18155
  renderToc(vditor);
18060
18156
  headingElement.remove();
18061
18157
  }
18062
- if ((startSpace && blockElement.getAttribute("data-type") !== "code-block")
18063
- || endSpace || isHeadingMD(blockElement.innerHTML) ||
18064
- (isHrMD(blockElement.innerHTML) && blockElement.previousElementSibling)) {
18158
+ if ((startSpace &&
18159
+ blockElement.getAttribute("data-type") !== "code-block") ||
18160
+ endSpace ||
18161
+ isHeadingMD(blockElement.innerHTML) ||
18162
+ (isHrMD(blockElement.innerHTML) &&
18163
+ blockElement.previousElementSibling)) {
18065
18164
  if (typeof vditor.options.input === "function") {
18066
18165
  vditor.options.input(getMarkdown(vditor));
18067
18166
  }
18068
18167
  return;
18069
18168
  }
18070
18169
  // https://github.com/Vanessa219/vditor/issues/1565
18071
- if (event.inputType === "insertParagraph" && _this.element.innerHTML === '<p><br></p><p><br></p>') {
18170
+ if (event.inputType === "insertParagraph" &&
18171
+ _this.element.innerHTML === "<p><br></p><p><br></p>") {
18072
18172
  blockElement.previousElementSibling.remove();
18073
18173
  }
18074
18174
  input_input(vditor, range, event);
@@ -18113,11 +18213,15 @@ var WYSIWYG = /** @class */ (function () {
18113
18213
  return;
18114
18214
  }
18115
18215
  var range = (0,selection/* getEditorRange */.zh)(vditor);
18116
- if (event.target.isEqualNode(_this.element) && _this.element.lastElementChild && range.collapsed) {
18216
+ if (event.target.isEqualNode(_this.element) &&
18217
+ _this.element.lastElementChild &&
18218
+ range.collapsed) {
18117
18219
  var lastRect = _this.element.lastElementChild.getBoundingClientRect();
18118
18220
  if (event.y > lastRect.top + lastRect.height) {
18119
18221
  if (_this.element.lastElementChild.tagName === "P" &&
18120
- _this.element.lastElementChild.textContent.trim().replace(constants/* Constants.ZWSP */.g.ZWSP, "") === "") {
18222
+ _this.element.lastElementChild.textContent
18223
+ .trim()
18224
+ .replace(constants/* Constants.ZWSP */.g.ZWSP, "") === "") {
18121
18225
  range.selectNodeContents(_this.element.lastElementChild);
18122
18226
  range.collapse(false);
18123
18227
  }
@@ -18131,8 +18235,7 @@ var WYSIWYG = /** @class */ (function () {
18131
18235
  // 点击后光标落于预览区,需展开代码块(无选区时)
18132
18236
  var previewElement = (0,hasClosest/* hasClosestByClassName */.fb)(event.target, "vditor-wysiwyg__preview");
18133
18237
  if (!previewElement) {
18134
- previewElement =
18135
- (0,hasClosest/* hasClosestByClassName */.fb)((0,selection/* getEditorRange */.zh)(vditor).startContainer, "vditor-wysiwyg__preview");
18238
+ previewElement = (0,hasClosest/* hasClosestByClassName */.fb)((0,selection/* getEditorRange */.zh)(vditor).startContainer, "vditor-wysiwyg__preview");
18136
18239
  }
18137
18240
  if (previewElement) {
18138
18241
  var hasSelection = getSelectText(vditor.wysiwyg.element).trim().length > 0;
@@ -18152,25 +18255,34 @@ var WYSIWYG = /** @class */ (function () {
18152
18255
  scrollCenter(vditor);
18153
18256
  }
18154
18257
  if ((event.key === "Backspace" || event.key === "Delete") &&
18155
- vditor.wysiwyg.element.innerHTML !== "" && vditor.wysiwyg.element.childNodes.length === 1 &&
18156
- vditor.wysiwyg.element.firstElementChild && vditor.wysiwyg.element.firstElementChild.tagName === "P"
18157
- && vditor.wysiwyg.element.firstElementChild.childElementCount === 0
18158
- && (vditor.wysiwyg.element.textContent === "" || vditor.wysiwyg.element.textContent === "\n")) {
18258
+ vditor.wysiwyg.element.innerHTML !== "" &&
18259
+ vditor.wysiwyg.element.childNodes.length === 1 &&
18260
+ vditor.wysiwyg.element.firstElementChild &&
18261
+ vditor.wysiwyg.element.firstElementChild.tagName === "P" &&
18262
+ vditor.wysiwyg.element.firstElementChild
18263
+ .childElementCount === 0 &&
18264
+ (vditor.wysiwyg.element.textContent === "" ||
18265
+ vditor.wysiwyg.element.textContent === "\n")) {
18159
18266
  // 为空时显示 placeholder
18160
18267
  vditor.wysiwyg.element.innerHTML = "";
18161
18268
  }
18162
18269
  var range = (0,selection/* getEditorRange */.zh)(vditor);
18163
18270
  if (event.key === "Backspace") {
18164
18271
  // firefox headings https://github.com/Vanessa219/vditor/issues/211
18165
- if ((0,compatibility/* isFirefox */.vU)() && range.startContainer.textContent === "\n" && range.startOffset === 1) {
18272
+ if ((0,compatibility/* isFirefox */.vU)() &&
18273
+ range.startContainer.textContent === "\n" &&
18274
+ range.startOffset === 1) {
18166
18275
  range.startContainer.textContent = "";
18167
18276
  }
18168
18277
  }
18169
18278
  // 没有被块元素包裹
18170
18279
  modifyPre(vditor, range);
18171
18280
  highlightToolbarWYSIWYG(vditor);
18172
- if (event.key !== "ArrowDown" && event.key !== "ArrowRight" && event.key !== "Backspace"
18173
- && event.key !== "ArrowLeft" && event.key !== "ArrowUp") {
18281
+ if (event.key !== "ArrowDown" &&
18282
+ event.key !== "ArrowRight" &&
18283
+ event.key !== "Backspace" &&
18284
+ event.key !== "ArrowLeft" &&
18285
+ event.key !== "ArrowUp") {
18174
18286
  return;
18175
18287
  }
18176
18288
  if (event.key === "ArrowLeft" || event.key === "ArrowRight") {
@@ -18178,11 +18290,14 @@ var WYSIWYG = /** @class */ (function () {
18178
18290
  }
18179
18291
  // 上下左右,删除遇到块预览的处理
18180
18292
  var previewElement = (0,hasClosest/* hasClosestByClassName */.fb)(range.startContainer, "vditor-wysiwyg__preview");
18181
- if (!previewElement && range.startContainer.nodeType !== 3 && range.startOffset > 0) {
18293
+ if (!previewElement &&
18294
+ range.startContainer.nodeType !== 3 &&
18295
+ range.startOffset > 0) {
18182
18296
  // table 前删除遇到代码块
18183
18297
  var blockRenderElement = range.startContainer;
18184
18298
  if (blockRenderElement.classList.contains("vditor-wysiwyg__block")) {
18185
- previewElement = blockRenderElement.lastElementChild;
18299
+ previewElement =
18300
+ blockRenderElement.lastElementChild;
18186
18301
  }
18187
18302
  }
18188
18303
  if (!previewElement) {
@@ -18190,7 +18305,8 @@ var WYSIWYG = /** @class */ (function () {
18190
18305
  }
18191
18306
  var previousElement = previewElement.previousElementSibling;
18192
18307
  if (previousElement.style.display === "none") {
18193
- if (event.key === "ArrowDown" || event.key === "ArrowRight") {
18308
+ if (event.key === "ArrowDown" ||
18309
+ event.key === "ArrowRight") {
18194
18310
  showCode(previewElement, vditor);
18195
18311
  }
18196
18312
  else {
@@ -18216,7 +18332,8 @@ var WYSIWYG = /** @class */ (function () {
18216
18332
  // 跳过渲染块,光标移动到下一个节点
18217
18333
  if (nextNode.nodeType === 3) {
18218
18334
  // inline
18219
- while (nextNode.textContent.length === 0 && nextNode.nextSibling) {
18335
+ while (nextNode.textContent.length === 0 &&
18336
+ nextNode.nextSibling) {
18220
18337
  // https://github.com/Vanessa219/vditor/issues/100 2
18221
18338
  nextNode = nextNode.nextSibling;
18222
18339
  }
@@ -18413,6 +18530,26 @@ var Vditor = /** @class */ (function (_super) {
18413
18530
  Vditor.prototype.getValue = function () {
18414
18531
  return getMarkdown(this.vditor);
18415
18532
  };
18533
+ /**
18534
+ * 手动更新行号
18535
+ * - 读取当前模式下的 Markdown 文本并为对应编辑区域同步/节流写入 data-linenumber
18536
+ * - 依赖配置 `lineNumber: true`,关闭时直接跳过以提升性能
18537
+ * @param immediate 为 true 时立即更新;默认为节流更新以避免频繁调用
18538
+ */
18539
+ Vditor.prototype.updateLineNumbers = function (immediate) {
18540
+ if (immediate === void 0) { immediate = false; }
18541
+ if (!this.vditor.options.lineNumber) {
18542
+ return;
18543
+ }
18544
+ var text = getMarkdown(this.vditor);
18545
+ var root = this.vditor[this.vditor.currentMode].element;
18546
+ if (immediate) {
18547
+ attachLineNumbersToBlocks(root, text);
18548
+ }
18549
+ else {
18550
+ attachLineNumbersToBlocksThrottled(root, text);
18551
+ }
18552
+ };
18416
18553
  /** 获取编辑器当前编辑模式 */
18417
18554
  Vditor.prototype.getCurrentMode = function () {
18418
18555
  return this.vditor.currentMode;
@@ -18584,14 +18721,14 @@ var Vditor = /** @class */ (function (_super) {
18584
18721
  Vditor.prototype.setValue = function (markdown, clearStack) {
18585
18722
  var _this = this;
18586
18723
  if (clearStack === void 0) { clearStack = false; }
18587
- try {
18588
- this.vditor.lineNumberIndex = prepareLineNumberIndex(markdown);
18589
- }
18590
- catch (_a) {
18591
- this.vditor.lineNumberIndex = undefined;
18592
- }
18593
18724
  if (this.vditor.currentMode === "sv") {
18594
18725
  this.vditor.sv.element.innerHTML = "<div data-block='0'>".concat(this.vditor.lute.SpinVditorSVDOM(markdown), "</div>");
18726
+ if (this.vditor.options.lineNumber) {
18727
+ try {
18728
+ attachLineNumbersToBlocks(this.vditor.sv.element, markdown || "");
18729
+ }
18730
+ catch (_a) { }
18731
+ }
18595
18732
  processAfterRender(this.vditor, {
18596
18733
  enableAddUndoStack: true,
18597
18734
  enableHint: false,
@@ -18613,6 +18750,12 @@ var Vditor = /** @class */ (function (_super) {
18613
18750
  .forEach(function (item) {
18614
18751
  processCodeRender(item, _this.vditor);
18615
18752
  });
18753
+ if (this.vditor.options.lineNumber) {
18754
+ try {
18755
+ attachLineNumbersToBlocks(this.vditor.ir.element, markdown || "");
18756
+ }
18757
+ catch (_b) { }
18758
+ }
18616
18759
  process_processAfterRender(this.vditor, {
18617
18760
  enableAddUndoStack: true,
18618
18761
  enableHint: false,