@8btc/mditor 0.0.27 → 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.
- package/dist/index.css +2 -2
- package/dist/index.js +10 -151
- package/dist/index.min.js +1 -1
- package/dist/method.js +7 -147
- package/dist/method.min.js +1 -1
- package/dist/types/index.d.ts +0 -16
- package/package.json +1 -1
- package/src/ts/markdown/mathRender.ts +4 -1
- package/src/ts/markdown/previewRender.ts +1 -5
- package/src/ts/util/Options.ts +0 -1
- package/dist/ts/markdown/customRender.d.ts +0 -73
- package/src/ts/markdown/customRender.ts +0 -203
package/dist/method.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Vditor v0.0.
|
|
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.
|
|
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.
|
|
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:
|
|
2679
|
+
typeset: false,
|
|
2680
|
+
elements: [],
|
|
2678
2681
|
},
|
|
2679
2682
|
tex: {
|
|
2680
2683
|
inlineMath: [
|
|
@@ -5116,147 +5119,6 @@ var speechRender = function (element, lang) {
|
|
|
5116
5119
|
var selectionRender = __webpack_require__(616);
|
|
5117
5120
|
// EXTERNAL MODULE: ./src/ts/util/mathSelection.ts
|
|
5118
5121
|
var mathSelection = __webpack_require__(35);
|
|
5119
|
-
;// CONCATENATED MODULE: ./src/ts/markdown/customRender.ts
|
|
5120
|
-
/**
|
|
5121
|
-
* 自定义组件渲染模块
|
|
5122
|
-
* 支持将 HTML 标签(如 <read-button label="文献解读">)转换为自定义 HTML
|
|
5123
|
-
*/
|
|
5124
|
-
var __assign = (undefined && undefined.__assign) || function () {
|
|
5125
|
-
__assign = Object.assign || function(t) {
|
|
5126
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5127
|
-
s = arguments[i];
|
|
5128
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
5129
|
-
t[p] = s[p];
|
|
5130
|
-
}
|
|
5131
|
-
return t;
|
|
5132
|
-
};
|
|
5133
|
-
return __assign.apply(this, arguments);
|
|
5134
|
-
};
|
|
5135
|
-
/**
|
|
5136
|
-
* 解析 HTML 属性字符串
|
|
5137
|
-
* @param str 属性字符串,如 'label="文献解读" id="test"'
|
|
5138
|
-
* @returns 属性对象
|
|
5139
|
-
*/
|
|
5140
|
-
function parseAttributes(str) {
|
|
5141
|
-
var attributes = {};
|
|
5142
|
-
if (!str)
|
|
5143
|
-
return attributes;
|
|
5144
|
-
var attrRegex = /(\w+)="([^"]*)"/g;
|
|
5145
|
-
var match;
|
|
5146
|
-
while ((match = attrRegex.exec(str)) !== null) {
|
|
5147
|
-
attributes[match[1]] = match[2];
|
|
5148
|
-
}
|
|
5149
|
-
return attributes;
|
|
5150
|
-
}
|
|
5151
|
-
/**
|
|
5152
|
-
* 从 HTML 字符串中提取自定义标签
|
|
5153
|
-
* @param html HTML 字符串
|
|
5154
|
-
* @param tagName 标签名称,如 'read-button'
|
|
5155
|
-
* @returns 匹配的标签信息数组
|
|
5156
|
-
*/
|
|
5157
|
-
function extractCustomTags(html, tagName) {
|
|
5158
|
-
var results = [];
|
|
5159
|
-
// 匹配自闭合标签和非自闭合标签
|
|
5160
|
-
var selfClosingRegex = new RegExp("<".concat(tagName, "\\s+([^>]*)\\s*/>"), "g");
|
|
5161
|
-
var openCloseRegex = new RegExp("<".concat(tagName, "\\s+([^>]*)>([^<]*)</").concat(tagName, ">"), "g");
|
|
5162
|
-
var match;
|
|
5163
|
-
// 处理自闭合标签
|
|
5164
|
-
while ((match = selfClosingRegex.exec(html)) !== null) {
|
|
5165
|
-
results.push({
|
|
5166
|
-
fullTag: match[0],
|
|
5167
|
-
attributes: parseAttributes(match[1]),
|
|
5168
|
-
content: "",
|
|
5169
|
-
});
|
|
5170
|
-
}
|
|
5171
|
-
// 处理开闭合标签
|
|
5172
|
-
while ((match = openCloseRegex.exec(html)) !== null) {
|
|
5173
|
-
results.push({
|
|
5174
|
-
fullTag: match[0],
|
|
5175
|
-
attributes: parseAttributes(match[1]),
|
|
5176
|
-
content: match[2],
|
|
5177
|
-
});
|
|
5178
|
-
}
|
|
5179
|
-
return results;
|
|
5180
|
-
}
|
|
5181
|
-
/**
|
|
5182
|
-
* 使用 HTML 字符串渲染自定义标签
|
|
5183
|
-
* @param html HTML 字符串
|
|
5184
|
-
* @param tagName 标签名称
|
|
5185
|
-
* @param component 自定义组件配置
|
|
5186
|
-
* @returns 修改后的 HTML 字符串
|
|
5187
|
-
*/
|
|
5188
|
-
function renderCustomComponentHTML(html, tagName, component) {
|
|
5189
|
-
var tags = extractCustomTags(html, tagName);
|
|
5190
|
-
var result = html;
|
|
5191
|
-
// 反向遍历以保持位置正确性
|
|
5192
|
-
for (var i = tags.length - 1; i >= 0; i--) {
|
|
5193
|
-
var tag = tags[i];
|
|
5194
|
-
var htmlString = component.renderHTML(tag.attributes);
|
|
5195
|
-
result = result.replace(tag.fullTag, htmlString);
|
|
5196
|
-
}
|
|
5197
|
-
return result;
|
|
5198
|
-
}
|
|
5199
|
-
/**
|
|
5200
|
-
* 在 DOM 元素中查找并渲染自定义组件
|
|
5201
|
-
* @param element DOM 元素
|
|
5202
|
-
* @param customComponents 自定义组件集合
|
|
5203
|
-
*/
|
|
5204
|
-
function renderCustomComponents(element, customComponents) {
|
|
5205
|
-
Object.keys(customComponents).forEach(function (tagName) {
|
|
5206
|
-
var component = customComponents[tagName];
|
|
5207
|
-
var customElements = element.querySelectorAll(tagName);
|
|
5208
|
-
// 反向遍历以避免 DOM 修改时的索引问题
|
|
5209
|
-
Array.from(customElements)
|
|
5210
|
-
.reverse()
|
|
5211
|
-
.forEach(function (el) {
|
|
5212
|
-
var attributes = {};
|
|
5213
|
-
el.getAttributeNames().forEach(function (name) {
|
|
5214
|
-
attributes[name] = el.getAttribute(name) || "";
|
|
5215
|
-
});
|
|
5216
|
-
// 使用 innerHTML 保留内部 HTML 内容,而不仅仅是纯文本
|
|
5217
|
-
var content = el.innerHTML || "";
|
|
5218
|
-
// 使用 HTML 渲染
|
|
5219
|
-
var htmlString = component.renderHTML(__assign(__assign({}, attributes), { children: content }));
|
|
5220
|
-
el.outerHTML = htmlString;
|
|
5221
|
-
});
|
|
5222
|
-
});
|
|
5223
|
-
}
|
|
5224
|
-
/**
|
|
5225
|
-
* 批量处理自定义组件 - 用于预处理 HTML 字符串
|
|
5226
|
-
* @param html HTML 字符串
|
|
5227
|
-
* @param customComponents 自定义组件集合
|
|
5228
|
-
* @returns 处理后的 HTML 字符串
|
|
5229
|
-
*/
|
|
5230
|
-
function processCustomComponents(html, customComponents) {
|
|
5231
|
-
var result = html;
|
|
5232
|
-
Object.keys(customComponents).forEach(function (tagName) {
|
|
5233
|
-
var component = customComponents[tagName];
|
|
5234
|
-
result = renderCustomComponentHTML(result, tagName, component);
|
|
5235
|
-
});
|
|
5236
|
-
return result;
|
|
5237
|
-
}
|
|
5238
|
-
/**
|
|
5239
|
-
* 处理 markdown 中的自定义组件
|
|
5240
|
-
* 将 markdown 中的自定义标签转换为对应的 HTML
|
|
5241
|
-
* @param markdown markdown 字符串
|
|
5242
|
-
* @param customComponents 自定义组件集合
|
|
5243
|
-
* @returns 处理后的 markdown 字符串
|
|
5244
|
-
*/
|
|
5245
|
-
function processMarkdownCustomComponents(markdown, customComponents) {
|
|
5246
|
-
var result = markdown;
|
|
5247
|
-
Object.keys(customComponents).forEach(function (tagName) {
|
|
5248
|
-
var component = customComponents[tagName];
|
|
5249
|
-
result = renderCustomComponentHTML(result, tagName, component);
|
|
5250
|
-
});
|
|
5251
|
-
return result;
|
|
5252
|
-
}
|
|
5253
|
-
/**
|
|
5254
|
-
* 导出默认函数和其他公共 API
|
|
5255
|
-
*/
|
|
5256
|
-
function customRender(element, customComponents) {
|
|
5257
|
-
renderCustomComponents(element, customComponents);
|
|
5258
|
-
}
|
|
5259
|
-
|
|
5260
5122
|
;// CONCATENATED MODULE: ./src/ts/markdown/previewRender.ts
|
|
5261
5123
|
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
5262
5124
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
@@ -5316,7 +5178,6 @@ var __generator = (undefined && undefined.__generator) || function (thisArg, bod
|
|
|
5316
5178
|
|
|
5317
5179
|
|
|
5318
5180
|
|
|
5319
|
-
|
|
5320
5181
|
|
|
5321
5182
|
|
|
5322
5183
|
var mergeOptions = function (options) {
|
|
@@ -5457,7 +5318,6 @@ var previewRender = function (previewElement, markdown, options) { return __awai
|
|
|
5457
5318
|
_a.sent();
|
|
5458
5319
|
_a.label = 8;
|
|
5459
5320
|
case 8:
|
|
5460
|
-
customRender(previewElement, mergedOptions.customComponents || {});
|
|
5461
5321
|
(0,setContentTheme/* setContentTheme */.Z)(mergedOptions.theme.current, mergedOptions.theme.path);
|
|
5462
5322
|
if (mergedOptions.anchor === 1) {
|
|
5463
5323
|
previewElement.classList.add("vditor-reset--anchor");
|