@8btc/mditor 0.0.27 → 0.0.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -284,6 +284,8 @@ new Vditor("vditor", {
284
284
  | engine | 数学公式渲染引擎:KaTeX, MathJax | 'KaTeX' |
285
285
  | mathJaxOptions | 数学公式渲染引擎为 MathJax 时的参数 | - |
286
286
 
287
+ 使用 MathJax 时,**无需配置 `startup.elements`**:包内会将公式渲染范围限定为当前预览/编辑容器,不会处理页面其他区域;`mathJaxOptions` 中若传入 `startup.typeset` 或 `startup.elements`,会在加载后被包内强制覆盖以保证作用域正确。
288
+
287
289
  #### options.preview.actions?: Array<IPreviewAction | IPreviewActionCustom>
288
290
 
289
291
  默认值为 ["desktop", "tablet", "mobile", "mp-wechat", "zhihu"]。
package/dist/index.css CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Vditor v0.0.27 - A markdown editor written in TypeScript.
2
+ * Vditor v0.0.29 - 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.27 - A markdown editor written in TypeScript.
28
+ * Vditor v0.0.29 - A markdown editor written in TypeScript.
29
29
  *
30
30
  * MIT License
31
31
  *
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Vditor v0.0.27 - A markdown editor written in TypeScript.
2
+ * Vditor v0.0.29 - A markdown editor written in TypeScript.
3
3
  *
4
4
  * MIT License
5
5
  *
@@ -2261,7 +2261,7 @@ module.exports.DIFF_EQUAL = DIFF_EQUAL;
2261
2261
 
2262
2262
  /***/ }),
2263
2263
 
2264
- /***/ 242:
2264
+ /***/ 408:
2265
2265
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
2266
2266
 
2267
2267
  "use strict";
@@ -2490,147 +2490,6 @@ var speechRender = function (element, lang) {
2490
2490
  var selectionRender = __webpack_require__(616);
2491
2491
  // EXTERNAL MODULE: ./src/ts/util/mathSelection.ts
2492
2492
  var mathSelection = __webpack_require__(35);
2493
- ;// CONCATENATED MODULE: ./src/ts/markdown/customRender.ts
2494
- /**
2495
- * 自定义组件渲染模块
2496
- * 支持将 HTML 标签(如 <read-button label="文献解读">)转换为自定义 HTML
2497
- */
2498
- var __assign = (undefined && undefined.__assign) || function () {
2499
- __assign = Object.assign || function(t) {
2500
- for (var s, i = 1, n = arguments.length; i < n; i++) {
2501
- s = arguments[i];
2502
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
2503
- t[p] = s[p];
2504
- }
2505
- return t;
2506
- };
2507
- return __assign.apply(this, arguments);
2508
- };
2509
- /**
2510
- * 解析 HTML 属性字符串
2511
- * @param str 属性字符串,如 'label="文献解读" id="test"'
2512
- * @returns 属性对象
2513
- */
2514
- function parseAttributes(str) {
2515
- var attributes = {};
2516
- if (!str)
2517
- return attributes;
2518
- var attrRegex = /(\w+)="([^"]*)"/g;
2519
- var match;
2520
- while ((match = attrRegex.exec(str)) !== null) {
2521
- attributes[match[1]] = match[2];
2522
- }
2523
- return attributes;
2524
- }
2525
- /**
2526
- * 从 HTML 字符串中提取自定义标签
2527
- * @param html HTML 字符串
2528
- * @param tagName 标签名称,如 'read-button'
2529
- * @returns 匹配的标签信息数组
2530
- */
2531
- function extractCustomTags(html, tagName) {
2532
- var results = [];
2533
- // 匹配自闭合标签和非自闭合标签
2534
- var selfClosingRegex = new RegExp("<".concat(tagName, "\\s+([^>]*)\\s*/>"), "g");
2535
- var openCloseRegex = new RegExp("<".concat(tagName, "\\s+([^>]*)>([^<]*)</").concat(tagName, ">"), "g");
2536
- var match;
2537
- // 处理自闭合标签
2538
- while ((match = selfClosingRegex.exec(html)) !== null) {
2539
- results.push({
2540
- fullTag: match[0],
2541
- attributes: parseAttributes(match[1]),
2542
- content: "",
2543
- });
2544
- }
2545
- // 处理开闭合标签
2546
- while ((match = openCloseRegex.exec(html)) !== null) {
2547
- results.push({
2548
- fullTag: match[0],
2549
- attributes: parseAttributes(match[1]),
2550
- content: match[2],
2551
- });
2552
- }
2553
- return results;
2554
- }
2555
- /**
2556
- * 使用 HTML 字符串渲染自定义标签
2557
- * @param html HTML 字符串
2558
- * @param tagName 标签名称
2559
- * @param component 自定义组件配置
2560
- * @returns 修改后的 HTML 字符串
2561
- */
2562
- function renderCustomComponentHTML(html, tagName, component) {
2563
- var tags = extractCustomTags(html, tagName);
2564
- var result = html;
2565
- // 反向遍历以保持位置正确性
2566
- for (var i = tags.length - 1; i >= 0; i--) {
2567
- var tag = tags[i];
2568
- var htmlString = component.renderHTML(tag.attributes);
2569
- result = result.replace(tag.fullTag, htmlString);
2570
- }
2571
- return result;
2572
- }
2573
- /**
2574
- * 在 DOM 元素中查找并渲染自定义组件
2575
- * @param element DOM 元素
2576
- * @param customComponents 自定义组件集合
2577
- */
2578
- function renderCustomComponents(element, customComponents) {
2579
- Object.keys(customComponents).forEach(function (tagName) {
2580
- var component = customComponents[tagName];
2581
- var customElements = element.querySelectorAll(tagName);
2582
- // 反向遍历以避免 DOM 修改时的索引问题
2583
- Array.from(customElements)
2584
- .reverse()
2585
- .forEach(function (el) {
2586
- var attributes = {};
2587
- el.getAttributeNames().forEach(function (name) {
2588
- attributes[name] = el.getAttribute(name) || "";
2589
- });
2590
- // 使用 innerHTML 保留内部 HTML 内容,而不仅仅是纯文本
2591
- var content = el.innerHTML || "";
2592
- // 使用 HTML 渲染
2593
- var htmlString = component.renderHTML(__assign(__assign({}, attributes), { children: content }));
2594
- el.outerHTML = htmlString;
2595
- });
2596
- });
2597
- }
2598
- /**
2599
- * 批量处理自定义组件 - 用于预处理 HTML 字符串
2600
- * @param html HTML 字符串
2601
- * @param customComponents 自定义组件集合
2602
- * @returns 处理后的 HTML 字符串
2603
- */
2604
- function processCustomComponents(html, customComponents) {
2605
- var result = html;
2606
- Object.keys(customComponents).forEach(function (tagName) {
2607
- var component = customComponents[tagName];
2608
- result = renderCustomComponentHTML(result, tagName, component);
2609
- });
2610
- return result;
2611
- }
2612
- /**
2613
- * 处理 markdown 中的自定义组件
2614
- * 将 markdown 中的自定义标签转换为对应的 HTML
2615
- * @param markdown markdown 字符串
2616
- * @param customComponents 自定义组件集合
2617
- * @returns 处理后的 markdown 字符串
2618
- */
2619
- function processMarkdownCustomComponents(markdown, customComponents) {
2620
- var result = markdown;
2621
- Object.keys(customComponents).forEach(function (tagName) {
2622
- var component = customComponents[tagName];
2623
- result = renderCustomComponentHTML(result, tagName, component);
2624
- });
2625
- return result;
2626
- }
2627
- /**
2628
- * 导出默认函数和其他公共 API
2629
- */
2630
- function customRender(element, customComponents) {
2631
- renderCustomComponents(element, customComponents);
2632
- }
2633
-
2634
2493
  ;// CONCATENATED MODULE: ./src/ts/markdown/previewRender.ts
2635
2494
  var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
2636
2495
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
@@ -2690,7 +2549,6 @@ var __generator = (undefined && undefined.__generator) || function (thisArg, bod
2690
2549
 
2691
2550
 
2692
2551
 
2693
-
2694
2552
 
2695
2553
 
2696
2554
  var mergeOptions = function (options) {
@@ -2831,7 +2689,6 @@ var previewRender = function (previewElement, markdown, options) { return __awai
2831
2689
  _a.sent();
2832
2690
  _a.label = 8;
2833
2691
  case 8:
2834
- customRender(previewElement, mergedOptions.customComponents || {});
2835
2692
  (0,setContentTheme/* setContentTheme */.Z)(mergedOptions.theme.current, mergedOptions.theme.path);
2836
2693
  if (mergedOptions.anchor === 1) {
2837
2694
  previewElement.classList.add("vditor-reset--anchor");
@@ -3066,7 +2923,7 @@ var Vditor = /** @class */ (function () {
3066
2923
  /* harmony export */ "H": () => (/* binding */ _VDITOR_VERSION),
3067
2924
  /* harmony export */ "g": () => (/* binding */ Constants)
3068
2925
  /* harmony export */ });
3069
- var _VDITOR_VERSION = "0.0.27";
2926
+ var _VDITOR_VERSION = "0.0.29";
3070
2927
 
3071
2928
  var Constants = /** @class */ (function () {
3072
2929
  function Constants() {
@@ -3368,7 +3225,7 @@ var Constants = /** @class */ (function () {
3368
3225
  "c#",
3369
3226
  "bat",
3370
3227
  ];
3371
- Constants.CDN = "https://webcdn.wujieai.com/vditor@".concat("0.0.27");
3228
+ Constants.CDN = "https://webcdn.wujieai.com/vditor@".concat("0.0.29");
3372
3229
  Constants.MARKDOWN_OPTIONS = {
3373
3230
  autoSpace: false,
3374
3231
  gfmAutoLink: true,
@@ -5703,12 +5560,15 @@ var mathRender = function (element, options) {
5703
5560
  next();
5704
5561
  };
5705
5562
  if (!window.MathJax) {
5563
+ // 关闭自动 typeset、不指定 elements,避免处理整个 document。外部使用本包时无需配置 startup.elements:
5564
+ // 渲染时会将 startup.elements 临时设为传入的 element(当前预览/编辑容器),再 clear/updateDocument。
5706
5565
  window.MathJax = {
5707
5566
  loader: {
5708
5567
  paths: { mathjax: "".concat(options.cdn, "/dist/js/mathjax") },
5709
5568
  },
5710
5569
  startup: {
5711
- typeset: true,
5570
+ typeset: false,
5571
+ elements: [],
5712
5572
  },
5713
5573
  tex: {
5714
5574
  inlineMath: [
@@ -5751,8 +5611,15 @@ var mathRender = function (element, options) {
5751
5611
  }
5752
5612
  // 绑定自定义右键菜单(编辑区生效,预览区自动跳过)
5753
5613
  (0,_mathContextMenu__WEBPACK_IMPORTED_MODULE_2__/* .bindMathContextMenu */ .xX)(mathElement);
5754
- window.MathJax.startup.document.clear();
5755
- window.MathJax.startup.document.updateDocument();
5614
+ // 限定 document 范围为当前容器后再 clear/updateDocument,避免处理整页导致编辑器外的 $...$ 被重新渲染;不调用会导致同一公式被渲染 2 次
5615
+ var startup = window.MathJax.startup;
5616
+ var prevElements = startup.elements;
5617
+ if (element instanceof HTMLElement) {
5618
+ startup.elements = [element];
5619
+ }
5620
+ startup.document.clear();
5621
+ startup.document.updateDocument();
5622
+ startup.elements = prevElements !== undefined ? prevElements : [];
5756
5623
  var errorTextElement = node.querySelector('[data-mml-node="merror"]');
5757
5624
  if (errorTextElement &&
5758
5625
  errorTextElement.textContent.trim() !== "") {
@@ -5766,6 +5633,11 @@ var mathRender = function (element, options) {
5766
5633
  });
5767
5634
  };
5768
5635
  window.MathJax.startup.promise.then(function () {
5636
+ // 脚本加载后再次强制不自动 typeset、不指定 elements,避免组件内部或用户配置导致处理整页
5637
+ if (window.MathJax.startup) {
5638
+ window.MathJax.startup.typeset = false;
5639
+ window.MathJax.startup.elements = [];
5640
+ }
5769
5641
  var chains = [];
5770
5642
  var _loop_1 = function (i) {
5771
5643
  var mathElement = mathElements[i];
@@ -8052,8 +7924,8 @@ __webpack_require__.d(__webpack_exports__, {
8052
7924
  "default": () => (/* binding */ src)
8053
7925
  });
8054
7926
 
8055
- // EXTERNAL MODULE: ./src/method.ts + 5 modules
8056
- var method = __webpack_require__(242);
7927
+ // EXTERNAL MODULE: ./src/method.ts + 4 modules
7928
+ var method = __webpack_require__(408);
8057
7929
  // EXTERNAL MODULE: ./src/ts/constants.ts
8058
7930
  var constants = __webpack_require__(145);
8059
7931
  // EXTERNAL MODULE: ./src/ts/markdown/getMarkdown.ts
@@ -18142,7 +18014,6 @@ var Options = /** @class */ (function () {
18142
18014
  type: "markdown",
18143
18015
  },
18144
18016
  customRenders: [],
18145
- customComponents: {},
18146
18017
  debugger: false,
18147
18018
  fullscreen: {
18148
18019
  index: 90,