@8btc/mditor 0.0.26 → 0.0.28

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.
@@ -254603,13 +254603,14 @@
254603
254603
  });
254604
254604
 
254605
254605
  // 第三步:处理纯开标签 <tag attr="value"> → <tag attr="value"></tag>
254606
- // 精准匹配:非自闭合、无后续闭合标签的合法自定义标签
254607
- const unclosedTagRegex = /<([a-z][a-z0-9-]*)\s+([^>]*?)>(?<!\/)\s*(?!<\/\1\s*>)/gi;
254606
+ // 修复:将标签外的空白字符(\s*)排除在匹配范围外,避免替换换行符
254607
+ const unclosedTagRegex = /<([a-z][a-z0-9-]*)\s+([^>]*?)>(?<!\/)(?!\s*<\/\1\s*>)/gi;
254608
254608
  md = md.replace(unclosedTagRegex, function(match, tagName, attrs) {
254609
254609
  // 兜底过滤:避免已闭合标签被重复处理
254610
254610
  if (match.includes('/>') || match.endsWith(`></${tagName}>`)) {
254611
254611
  return match;
254612
254612
  }
254613
+ // 只替换标签本身,保留原有换行符
254613
254614
  return `<${tagName} ${attrs}></${tagName}>`;
254614
254615
  });
254615
254616
 
@@ -254627,7 +254628,6 @@
254627
254628
  inst[name] = function(text) {
254628
254629
  text = __vditorPreprocessBackslashMath(text);
254629
254630
  text = __vditorPreprocessCustomTags(text);
254630
- console.log(text)
254631
254631
  return orig.call(inst, text)
254632
254632
  }
254633
254633
  }
package/dist/method.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Vditor v0.0.26 - A markdown editor written in TypeScript.
2
+ * Vditor v0.0.28 - A markdown editor written in TypeScript.
3
3
  *
4
4
  * MIT License
5
5
  *
@@ -45,7 +45,7 @@ return /******/ (() => { // webpackBootstrap
45
45
  /* harmony export */ "g": () => (/* binding */ Constants)
46
46
  /* harmony export */ });
47
47
  /* unused harmony export VDITOR_VERSION */
48
- var _VDITOR_VERSION = (/* unused pure expression or super */ null && ("0.0.26"));
48
+ var _VDITOR_VERSION = (/* unused pure expression or super */ null && ("0.0.28"));
49
49
 
50
50
  var Constants = /** @class */ (function () {
51
51
  function Constants() {
@@ -347,7 +347,7 @@ var Constants = /** @class */ (function () {
347
347
  "c#",
348
348
  "bat",
349
349
  ];
350
- Constants.CDN = "https://webcdn.wujieai.com/vditor@".concat("0.0.26");
350
+ Constants.CDN = "https://webcdn.wujieai.com/vditor@".concat("0.0.28");
351
351
  Constants.MARKDOWN_OPTIONS = {
352
352
  autoSpace: false,
353
353
  gfmAutoLink: true,
@@ -2669,12 +2669,15 @@ var mathRender = function (element, options) {
2669
2669
  next();
2670
2670
  };
2671
2671
  if (!window.MathJax) {
2672
+ // 关闭自动 typeset,避免处理整个 document 导致页面其他区域(如用户消息)中的 $...$ 被重新渲染。
2673
+ // 公式仅由本函数内对 tex2svgPromise 的显式调用渲染,且仅针对传入的 element 内的节点。
2672
2674
  window.MathJax = {
2673
2675
  loader: {
2674
2676
  paths: { mathjax: "".concat(options.cdn, "/dist/js/mathjax") },
2675
2677
  },
2676
2678
  startup: {
2677
- typeset: true,
2679
+ typeset: false,
2680
+ elements: [],
2678
2681
  },
2679
2682
  tex: {
2680
2683
  inlineMath: [
@@ -4163,26 +4166,6 @@ var attachLineNumbersToBlocks = function (root, sourceMarkdown) {
4163
4166
  tableGroups: tableGroups,
4164
4167
  });
4165
4168
  }
4166
- console.log("[LineNumber][perf]", {
4167
- cached: !!cached,
4168
- times: {
4169
- normalize: Math.round((tNorm - t0) * 100) / 100,
4170
- index: Math.round((tIndexDone - tNorm) * 100) / 100,
4171
- blocks: Math.round((tBlockDone - tIndexDone) * 100) / 100,
4172
- ul: Math.round((tUlDone - tBlockDone) * 100) / 100,
4173
- ol: Math.round((tOlDone - tUlDone) * 100) / 100,
4174
- table: Math.round((tTableDone - tIndexDone) * 100) / 100,
4175
- apply: Math.round((tApplyDone - tTableDone) * 100) / 100,
4176
- total: Math.round((tApplyDone - t0) * 100) / 100,
4177
- },
4178
- counts: {
4179
- blocks: blocks.length,
4180
- ul: ulElements.length,
4181
- ol: olElements.length,
4182
- tables: tables.length,
4183
- updates: attrUpdates.length,
4184
- },
4185
- });
4186
4169
  };
4187
4170
  /**
4188
4171
  * 节流后的行号更新函数,避免频繁更新 data-linenumber
@@ -5136,148 +5119,6 @@ var speechRender = function (element, lang) {
5136
5119
  var selectionRender = __webpack_require__(616);
5137
5120
  // EXTERNAL MODULE: ./src/ts/util/mathSelection.ts
5138
5121
  var mathSelection = __webpack_require__(35);
5139
- ;// CONCATENATED MODULE: ./src/ts/markdown/customRender.ts
5140
- /**
5141
- * 自定义组件渲染模块
5142
- * 支持将 HTML 标签(如 <read-button label="文献解读">)转换为自定义 HTML
5143
- */
5144
- var __assign = (undefined && undefined.__assign) || function () {
5145
- __assign = Object.assign || function(t) {
5146
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5147
- s = arguments[i];
5148
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
5149
- t[p] = s[p];
5150
- }
5151
- return t;
5152
- };
5153
- return __assign.apply(this, arguments);
5154
- };
5155
- /**
5156
- * 解析 HTML 属性字符串
5157
- * @param str 属性字符串,如 'label="文献解读" id="test"'
5158
- * @returns 属性对象
5159
- */
5160
- function parseAttributes(str) {
5161
- var attributes = {};
5162
- if (!str)
5163
- return attributes;
5164
- var attrRegex = /(\w+)="([^"]*)"/g;
5165
- var match;
5166
- while ((match = attrRegex.exec(str)) !== null) {
5167
- attributes[match[1]] = match[2];
5168
- }
5169
- return attributes;
5170
- }
5171
- /**
5172
- * 从 HTML 字符串中提取自定义标签
5173
- * @param html HTML 字符串
5174
- * @param tagName 标签名称,如 'read-button'
5175
- * @returns 匹配的标签信息数组
5176
- */
5177
- function extractCustomTags(html, tagName) {
5178
- var results = [];
5179
- // 匹配自闭合标签和非自闭合标签
5180
- var selfClosingRegex = new RegExp("<".concat(tagName, "\\s+([^>]*)\\s*/>"), "g");
5181
- var openCloseRegex = new RegExp("<".concat(tagName, "\\s+([^>]*)>([^<]*)</").concat(tagName, ">"), "g");
5182
- var match;
5183
- // 处理自闭合标签
5184
- while ((match = selfClosingRegex.exec(html)) !== null) {
5185
- results.push({
5186
- fullTag: match[0],
5187
- attributes: parseAttributes(match[1]),
5188
- content: "",
5189
- });
5190
- }
5191
- // 处理开闭合标签
5192
- while ((match = openCloseRegex.exec(html)) !== null) {
5193
- results.push({
5194
- fullTag: match[0],
5195
- attributes: parseAttributes(match[1]),
5196
- content: match[2],
5197
- });
5198
- }
5199
- return results;
5200
- }
5201
- /**
5202
- * 使用 HTML 字符串渲染自定义标签
5203
- * @param html HTML 字符串
5204
- * @param tagName 标签名称
5205
- * @param component 自定义组件配置
5206
- * @returns 修改后的 HTML 字符串
5207
- */
5208
- function renderCustomComponentHTML(html, tagName, component) {
5209
- var tags = extractCustomTags(html, tagName);
5210
- var result = html;
5211
- // 反向遍历以保持位置正确性
5212
- for (var i = tags.length - 1; i >= 0; i--) {
5213
- var tag = tags[i];
5214
- var htmlString = component.renderHTML(tag.attributes);
5215
- result = result.replace(tag.fullTag, htmlString);
5216
- }
5217
- return result;
5218
- }
5219
- /**
5220
- * 在 DOM 元素中查找并渲染自定义组件
5221
- * @param element DOM 元素
5222
- * @param customComponents 自定义组件集合
5223
- */
5224
- function renderCustomComponents(element, customComponents) {
5225
- Object.keys(customComponents).forEach(function (tagName) {
5226
- var component = customComponents[tagName];
5227
- var customElements = element.querySelectorAll(tagName);
5228
- console.log(element, customComponents, "customComponents");
5229
- // 反向遍历以避免 DOM 修改时的索引问题
5230
- Array.from(customElements)
5231
- .reverse()
5232
- .forEach(function (el) {
5233
- var attributes = {};
5234
- el.getAttributeNames().forEach(function (name) {
5235
- attributes[name] = el.getAttribute(name) || "";
5236
- });
5237
- // 使用 innerHTML 保留内部 HTML 内容,而不仅仅是纯文本
5238
- var content = el.innerHTML || "";
5239
- // 使用 HTML 渲染
5240
- var htmlString = component.renderHTML(__assign(__assign({}, attributes), { children: content }));
5241
- el.outerHTML = htmlString;
5242
- });
5243
- });
5244
- }
5245
- /**
5246
- * 批量处理自定义组件 - 用于预处理 HTML 字符串
5247
- * @param html HTML 字符串
5248
- * @param customComponents 自定义组件集合
5249
- * @returns 处理后的 HTML 字符串
5250
- */
5251
- function processCustomComponents(html, customComponents) {
5252
- var result = html;
5253
- Object.keys(customComponents).forEach(function (tagName) {
5254
- var component = customComponents[tagName];
5255
- result = renderCustomComponentHTML(result, tagName, component);
5256
- });
5257
- return result;
5258
- }
5259
- /**
5260
- * 处理 markdown 中的自定义组件
5261
- * 将 markdown 中的自定义标签转换为对应的 HTML
5262
- * @param markdown markdown 字符串
5263
- * @param customComponents 自定义组件集合
5264
- * @returns 处理后的 markdown 字符串
5265
- */
5266
- function processMarkdownCustomComponents(markdown, customComponents) {
5267
- var result = markdown;
5268
- Object.keys(customComponents).forEach(function (tagName) {
5269
- var component = customComponents[tagName];
5270
- result = renderCustomComponentHTML(result, tagName, component);
5271
- });
5272
- return result;
5273
- }
5274
- /**
5275
- * 导出默认函数和其他公共 API
5276
- */
5277
- function customRender(element, customComponents) {
5278
- renderCustomComponents(element, customComponents);
5279
- }
5280
-
5281
5122
  ;// CONCATENATED MODULE: ./src/ts/markdown/previewRender.ts
5282
5123
  var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
5283
5124
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
@@ -5337,7 +5178,6 @@ var __generator = (undefined && undefined.__generator) || function (thisArg, bod
5337
5178
 
5338
5179
 
5339
5180
 
5340
-
5341
5181
 
5342
5182
 
5343
5183
  var mergeOptions = function (options) {
@@ -5478,8 +5318,6 @@ var previewRender = function (previewElement, markdown, options) { return __awai
5478
5318
  _a.sent();
5479
5319
  _a.label = 8;
5480
5320
  case 8:
5481
- console.log(previewElement, "previewElement");
5482
- customRender(previewElement, mergedOptions.customComponents || {});
5483
5321
  (0,setContentTheme/* setContentTheme */.Z)(mergedOptions.theme.current, mergedOptions.theme.path);
5484
5322
  if (mergedOptions.anchor === 1) {
5485
5323
  previewElement.classList.add("vditor-reset--anchor");
@@ -5552,7 +5390,6 @@ var previewRender = function (previewElement, markdown, options) { return __awai
5552
5390
  .querySelectorAll(".language-math")
5553
5391
  .forEach(function (mathEl) {
5554
5392
  var mathSource = mathEl.getAttribute("data-math");
5555
- console.log(mathEl.tagName, "mathEl");
5556
5393
  if (mathSource) {
5557
5394
  if (mathEl.tagName === "SPAN") {
5558
5395
  var textNode = document.createTextNode("$".concat(mathSource, "$"));