@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 +2 -0
- package/dist/index.css +2 -2
- package/dist/index.js +24 -153
- package/dist/index.min.js +1 -1
- package/dist/method.js +21 -149
- package/dist/method.min.js +1 -1
- package/dist/types/index.d.ts +6 -17
- package/package.json +1 -1
- package/src/ts/markdown/mathRender.ts +18 -3
- 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.29 - 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.29"));
|
|
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.29");
|
|
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、不指定 elements,避免处理整个 document。外部使用本包时无需配置 startup.elements:
|
|
2673
|
+
// 渲染时会将 startup.elements 临时设为传入的 element(当前预览/编辑容器),再 clear/updateDocument。
|
|
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: [
|
|
@@ -2717,8 +2720,15 @@ var mathRender = function (element, options) {
|
|
|
2717
2720
|
}
|
|
2718
2721
|
// 绑定自定义右键菜单(编辑区生效,预览区自动跳过)
|
|
2719
2722
|
(0,_mathContextMenu__WEBPACK_IMPORTED_MODULE_2__/* .bindMathContextMenu */ .xX)(mathElement);
|
|
2720
|
-
|
|
2721
|
-
window.MathJax.startup
|
|
2723
|
+
// 限定 document 范围为当前容器后再 clear/updateDocument,避免处理整页导致编辑器外的 $...$ 被重新渲染;不调用会导致同一公式被渲染 2 次
|
|
2724
|
+
var startup = window.MathJax.startup;
|
|
2725
|
+
var prevElements = startup.elements;
|
|
2726
|
+
if (element instanceof HTMLElement) {
|
|
2727
|
+
startup.elements = [element];
|
|
2728
|
+
}
|
|
2729
|
+
startup.document.clear();
|
|
2730
|
+
startup.document.updateDocument();
|
|
2731
|
+
startup.elements = prevElements !== undefined ? prevElements : [];
|
|
2722
2732
|
var errorTextElement = node.querySelector('[data-mml-node="merror"]');
|
|
2723
2733
|
if (errorTextElement &&
|
|
2724
2734
|
errorTextElement.textContent.trim() !== "") {
|
|
@@ -2732,6 +2742,11 @@ var mathRender = function (element, options) {
|
|
|
2732
2742
|
});
|
|
2733
2743
|
};
|
|
2734
2744
|
window.MathJax.startup.promise.then(function () {
|
|
2745
|
+
// 脚本加载后再次强制不自动 typeset、不指定 elements,避免组件内部或用户配置导致处理整页
|
|
2746
|
+
if (window.MathJax.startup) {
|
|
2747
|
+
window.MathJax.startup.typeset = false;
|
|
2748
|
+
window.MathJax.startup.elements = [];
|
|
2749
|
+
}
|
|
2735
2750
|
var chains = [];
|
|
2736
2751
|
var _loop_1 = function (i) {
|
|
2737
2752
|
var mathElement = mathElements[i];
|
|
@@ -5116,147 +5131,6 @@ var speechRender = function (element, lang) {
|
|
|
5116
5131
|
var selectionRender = __webpack_require__(616);
|
|
5117
5132
|
// EXTERNAL MODULE: ./src/ts/util/mathSelection.ts
|
|
5118
5133
|
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
5134
|
;// CONCATENATED MODULE: ./src/ts/markdown/previewRender.ts
|
|
5261
5135
|
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
5262
5136
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
@@ -5316,7 +5190,6 @@ var __generator = (undefined && undefined.__generator) || function (thisArg, bod
|
|
|
5316
5190
|
|
|
5317
5191
|
|
|
5318
5192
|
|
|
5319
|
-
|
|
5320
5193
|
|
|
5321
5194
|
|
|
5322
5195
|
var mergeOptions = function (options) {
|
|
@@ -5457,7 +5330,6 @@ var previewRender = function (previewElement, markdown, options) { return __awai
|
|
|
5457
5330
|
_a.sent();
|
|
5458
5331
|
_a.label = 8;
|
|
5459
5332
|
case 8:
|
|
5460
|
-
customRender(previewElement, mergedOptions.customComponents || {});
|
|
5461
5333
|
(0,setContentTheme/* setContentTheme */.Z)(mergedOptions.theme.current, mergedOptions.theme.path);
|
|
5462
5334
|
if (mergedOptions.anchor === 1) {
|
|
5463
5335
|
previewElement.classList.add("vditor-reset--anchor");
|