@8btc/mditor 0.0.25 → 0.0.26
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 +152 -6
- package/dist/index.min.js +1 -1
- package/dist/js/lute/lute.min.js +29 -1
- package/dist/method.js +148 -3
- 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 -0
- package/src/ts/preview/index.ts +3 -1
- package/src/ts/util/Options.ts +1 -0
package/dist/index.css
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Vditor v0.0.
|
|
2
|
+
* Vditor v0.0.26 - 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.26 - 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.26 - 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,148 @@ 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
|
+
console.log(element, customComponents, "customComponents");
|
|
2583
|
+
// 反向遍历以避免 DOM 修改时的索引问题
|
|
2584
|
+
Array.from(customElements)
|
|
2585
|
+
.reverse()
|
|
2586
|
+
.forEach(function (el) {
|
|
2587
|
+
var attributes = {};
|
|
2588
|
+
el.getAttributeNames().forEach(function (name) {
|
|
2589
|
+
attributes[name] = el.getAttribute(name) || "";
|
|
2590
|
+
});
|
|
2591
|
+
// 使用 innerHTML 保留内部 HTML 内容,而不仅仅是纯文本
|
|
2592
|
+
var content = el.innerHTML || "";
|
|
2593
|
+
// 使用 HTML 渲染
|
|
2594
|
+
var htmlString = component.renderHTML(__assign(__assign({}, attributes), { children: content }));
|
|
2595
|
+
el.outerHTML = htmlString;
|
|
2596
|
+
});
|
|
2597
|
+
});
|
|
2598
|
+
}
|
|
2599
|
+
/**
|
|
2600
|
+
* 批量处理自定义组件 - 用于预处理 HTML 字符串
|
|
2601
|
+
* @param html HTML 字符串
|
|
2602
|
+
* @param customComponents 自定义组件集合
|
|
2603
|
+
* @returns 处理后的 HTML 字符串
|
|
2604
|
+
*/
|
|
2605
|
+
function processCustomComponents(html, customComponents) {
|
|
2606
|
+
var result = html;
|
|
2607
|
+
Object.keys(customComponents).forEach(function (tagName) {
|
|
2608
|
+
var component = customComponents[tagName];
|
|
2609
|
+
result = renderCustomComponentHTML(result, tagName, component);
|
|
2610
|
+
});
|
|
2611
|
+
return result;
|
|
2612
|
+
}
|
|
2613
|
+
/**
|
|
2614
|
+
* 处理 markdown 中的自定义组件
|
|
2615
|
+
* 将 markdown 中的自定义标签转换为对应的 HTML
|
|
2616
|
+
* @param markdown markdown 字符串
|
|
2617
|
+
* @param customComponents 自定义组件集合
|
|
2618
|
+
* @returns 处理后的 markdown 字符串
|
|
2619
|
+
*/
|
|
2620
|
+
function processMarkdownCustomComponents(markdown, customComponents) {
|
|
2621
|
+
var result = markdown;
|
|
2622
|
+
Object.keys(customComponents).forEach(function (tagName) {
|
|
2623
|
+
var component = customComponents[tagName];
|
|
2624
|
+
result = renderCustomComponentHTML(result, tagName, component);
|
|
2625
|
+
});
|
|
2626
|
+
return result;
|
|
2627
|
+
}
|
|
2628
|
+
/**
|
|
2629
|
+
* 导出默认函数和其他公共 API
|
|
2630
|
+
*/
|
|
2631
|
+
function customRender(element, customComponents) {
|
|
2632
|
+
renderCustomComponents(element, customComponents);
|
|
2633
|
+
}
|
|
2634
|
+
|
|
2493
2635
|
;// CONCATENATED MODULE: ./src/ts/markdown/previewRender.ts
|
|
2494
2636
|
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2495
2637
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
@@ -2549,6 +2691,7 @@ var __generator = (undefined && undefined.__generator) || function (thisArg, bod
|
|
|
2549
2691
|
|
|
2550
2692
|
|
|
2551
2693
|
|
|
2694
|
+
|
|
2552
2695
|
|
|
2553
2696
|
|
|
2554
2697
|
var mergeOptions = function (options) {
|
|
@@ -2689,6 +2832,8 @@ var previewRender = function (previewElement, markdown, options) { return __awai
|
|
|
2689
2832
|
_a.sent();
|
|
2690
2833
|
_a.label = 8;
|
|
2691
2834
|
case 8:
|
|
2835
|
+
console.log(previewElement, "previewElement");
|
|
2836
|
+
customRender(previewElement, mergedOptions.customComponents || {});
|
|
2692
2837
|
(0,setContentTheme/* setContentTheme */.Z)(mergedOptions.theme.current, mergedOptions.theme.path);
|
|
2693
2838
|
if (mergedOptions.anchor === 1) {
|
|
2694
2839
|
previewElement.classList.add("vditor-reset--anchor");
|
|
@@ -2924,7 +3069,7 @@ var Vditor = /** @class */ (function () {
|
|
|
2924
3069
|
/* harmony export */ "H": () => (/* binding */ _VDITOR_VERSION),
|
|
2925
3070
|
/* harmony export */ "g": () => (/* binding */ Constants)
|
|
2926
3071
|
/* harmony export */ });
|
|
2927
|
-
var _VDITOR_VERSION = "0.0.
|
|
3072
|
+
var _VDITOR_VERSION = "0.0.26";
|
|
2928
3073
|
|
|
2929
3074
|
var Constants = /** @class */ (function () {
|
|
2930
3075
|
function Constants() {
|
|
@@ -3226,7 +3371,7 @@ var Constants = /** @class */ (function () {
|
|
|
3226
3371
|
"c#",
|
|
3227
3372
|
"bat",
|
|
3228
3373
|
];
|
|
3229
|
-
Constants.CDN = "https://webcdn.wujieai.com/vditor@".concat("0.0.
|
|
3374
|
+
Constants.CDN = "https://webcdn.wujieai.com/vditor@".concat("0.0.26");
|
|
3230
3375
|
Constants.MARKDOWN_OPTIONS = {
|
|
3231
3376
|
autoSpace: false,
|
|
3232
3377
|
gfmAutoLink: true,
|
|
@@ -7930,8 +8075,8 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
7930
8075
|
"default": () => (/* binding */ src)
|
|
7931
8076
|
});
|
|
7932
8077
|
|
|
7933
|
-
// EXTERNAL MODULE: ./src/method.ts +
|
|
7934
|
-
var method = __webpack_require__(
|
|
8078
|
+
// EXTERNAL MODULE: ./src/method.ts + 5 modules
|
|
8079
|
+
var method = __webpack_require__(242);
|
|
7935
8080
|
// EXTERNAL MODULE: ./src/ts/constants.ts
|
|
7936
8081
|
var constants = __webpack_require__(145);
|
|
7937
8082
|
// EXTERNAL MODULE: ./src/ts/markdown/getMarkdown.ts
|
|
@@ -18020,6 +18165,7 @@ var Options = /** @class */ (function () {
|
|
|
18020
18165
|
type: "markdown",
|
|
18021
18166
|
},
|
|
18022
18167
|
customRenders: [],
|
|
18168
|
+
customComponents: {},
|
|
18023
18169
|
debugger: false,
|
|
18024
18170
|
fullscreen: {
|
|
18025
18171
|
index: 90,
|