@8btc/mditor 0.0.25 → 0.0.27
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.css +2 -2
- package/dist/index.js +150 -27
- package/dist/index.min.js +1 -1
- package/dist/js/lute/lute.min.js +29 -1
- package/dist/method.js +146 -24
- package/dist/method.min.js +1 -1
- package/dist/ts/markdown/customRender.d.ts +73 -0
- package/dist/types/index.d.ts +16 -0
- package/package.json +1 -1
- package/src/ts/markdown/customRender.ts +203 -0
- package/src/ts/markdown/previewRender.ts +5 -1
- package/src/ts/preview/index.ts +3 -1
- package/src/ts/util/Options.ts +1 -0
- package/src/ts/util/attachLineNumbers.ts +1 -20
package/dist/index.css
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Vditor v0.0.
|
|
2
|
+
* Vditor v0.0.27 - 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.
|
|
28
|
+
* Vditor v0.0.27 - 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.
|
|
2
|
+
* Vditor v0.0.27 - 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
|
-
/***/
|
|
2264
|
+
/***/ 242:
|
|
2265
2265
|
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
2266
2266
|
|
|
2267
2267
|
"use strict";
|
|
@@ -2490,6 +2490,147 @@ 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
|
+
|
|
2493
2634
|
;// CONCATENATED MODULE: ./src/ts/markdown/previewRender.ts
|
|
2494
2635
|
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2495
2636
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
@@ -2549,6 +2690,7 @@ var __generator = (undefined && undefined.__generator) || function (thisArg, bod
|
|
|
2549
2690
|
|
|
2550
2691
|
|
|
2551
2692
|
|
|
2693
|
+
|
|
2552
2694
|
|
|
2553
2695
|
|
|
2554
2696
|
var mergeOptions = function (options) {
|
|
@@ -2689,6 +2831,7 @@ var previewRender = function (previewElement, markdown, options) { return __awai
|
|
|
2689
2831
|
_a.sent();
|
|
2690
2832
|
_a.label = 8;
|
|
2691
2833
|
case 8:
|
|
2834
|
+
customRender(previewElement, mergedOptions.customComponents || {});
|
|
2692
2835
|
(0,setContentTheme/* setContentTheme */.Z)(mergedOptions.theme.current, mergedOptions.theme.path);
|
|
2693
2836
|
if (mergedOptions.anchor === 1) {
|
|
2694
2837
|
previewElement.classList.add("vditor-reset--anchor");
|
|
@@ -2761,7 +2904,6 @@ var previewRender = function (previewElement, markdown, options) { return __awai
|
|
|
2761
2904
|
.querySelectorAll(".language-math")
|
|
2762
2905
|
.forEach(function (mathEl) {
|
|
2763
2906
|
var mathSource = mathEl.getAttribute("data-math");
|
|
2764
|
-
console.log(mathEl.tagName, "mathEl");
|
|
2765
2907
|
if (mathSource) {
|
|
2766
2908
|
if (mathEl.tagName === "SPAN") {
|
|
2767
2909
|
var textNode = document.createTextNode("$".concat(mathSource, "$"));
|
|
@@ -2924,7 +3066,7 @@ var Vditor = /** @class */ (function () {
|
|
|
2924
3066
|
/* harmony export */ "H": () => (/* binding */ _VDITOR_VERSION),
|
|
2925
3067
|
/* harmony export */ "g": () => (/* binding */ Constants)
|
|
2926
3068
|
/* harmony export */ });
|
|
2927
|
-
var _VDITOR_VERSION = "0.0.
|
|
3069
|
+
var _VDITOR_VERSION = "0.0.27";
|
|
2928
3070
|
|
|
2929
3071
|
var Constants = /** @class */ (function () {
|
|
2930
3072
|
function Constants() {
|
|
@@ -3226,7 +3368,7 @@ var Constants = /** @class */ (function () {
|
|
|
3226
3368
|
"c#",
|
|
3227
3369
|
"bat",
|
|
3228
3370
|
];
|
|
3229
|
-
Constants.CDN = "https://webcdn.wujieai.com/vditor@".concat("0.0.
|
|
3371
|
+
Constants.CDN = "https://webcdn.wujieai.com/vditor@".concat("0.0.27");
|
|
3230
3372
|
Constants.MARKDOWN_OPTIONS = {
|
|
3231
3373
|
autoSpace: false,
|
|
3232
3374
|
gfmAutoLink: true,
|
|
@@ -7068,26 +7210,6 @@ var attachLineNumbersToBlocks = function (root, sourceMarkdown) {
|
|
|
7068
7210
|
tableGroups: tableGroups,
|
|
7069
7211
|
});
|
|
7070
7212
|
}
|
|
7071
|
-
console.log("[LineNumber][perf]", {
|
|
7072
|
-
cached: !!cached,
|
|
7073
|
-
times: {
|
|
7074
|
-
normalize: Math.round((tNorm - t0) * 100) / 100,
|
|
7075
|
-
index: Math.round((tIndexDone - tNorm) * 100) / 100,
|
|
7076
|
-
blocks: Math.round((tBlockDone - tIndexDone) * 100) / 100,
|
|
7077
|
-
ul: Math.round((tUlDone - tBlockDone) * 100) / 100,
|
|
7078
|
-
ol: Math.round((tOlDone - tUlDone) * 100) / 100,
|
|
7079
|
-
table: Math.round((tTableDone - tIndexDone) * 100) / 100,
|
|
7080
|
-
apply: Math.round((tApplyDone - tTableDone) * 100) / 100,
|
|
7081
|
-
total: Math.round((tApplyDone - t0) * 100) / 100,
|
|
7082
|
-
},
|
|
7083
|
-
counts: {
|
|
7084
|
-
blocks: blocks.length,
|
|
7085
|
-
ul: ulElements.length,
|
|
7086
|
-
ol: olElements.length,
|
|
7087
|
-
tables: tables.length,
|
|
7088
|
-
updates: attrUpdates.length,
|
|
7089
|
-
},
|
|
7090
|
-
});
|
|
7091
7213
|
};
|
|
7092
7214
|
/**
|
|
7093
7215
|
* 节流后的行号更新函数,避免频繁更新 data-linenumber
|
|
@@ -7930,8 +8052,8 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
7930
8052
|
"default": () => (/* binding */ src)
|
|
7931
8053
|
});
|
|
7932
8054
|
|
|
7933
|
-
// EXTERNAL MODULE: ./src/method.ts +
|
|
7934
|
-
var method = __webpack_require__(
|
|
8055
|
+
// EXTERNAL MODULE: ./src/method.ts + 5 modules
|
|
8056
|
+
var method = __webpack_require__(242);
|
|
7935
8057
|
// EXTERNAL MODULE: ./src/ts/constants.ts
|
|
7936
8058
|
var constants = __webpack_require__(145);
|
|
7937
8059
|
// EXTERNAL MODULE: ./src/ts/markdown/getMarkdown.ts
|
|
@@ -18020,6 +18142,7 @@ var Options = /** @class */ (function () {
|
|
|
18020
18142
|
type: "markdown",
|
|
18021
18143
|
},
|
|
18022
18144
|
customRenders: [],
|
|
18145
|
+
customComponents: {},
|
|
18023
18146
|
debugger: false,
|
|
18024
18147
|
fullscreen: {
|
|
18025
18148
|
index: 90,
|