@8btc/mditor 0.0.33 → 0.0.35
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 -30
- package/dist/index.min.js +1 -1
- package/dist/method.js +10 -30
- package/dist/method.min.js +1 -1
- package/dist/ts/markdown/mathRender.d.ts +2 -2
- package/package.json +1 -1
- package/src/ts/markdown/mathRender.ts +7 -27
|
@@ -50,8 +50,8 @@ const normalizeTex = (tex: string): string => {
|
|
|
50
50
|
/**
|
|
51
51
|
* 数学公式渲染入口
|
|
52
52
|
*
|
|
53
|
-
* 默认使用
|
|
54
|
-
* 支持通过 options.math.engine 切换为
|
|
53
|
+
* 默认使用 KaTeX 渲染,并在需要时按需加载相关脚本与样式。
|
|
54
|
+
* 支持通过 options.math.engine 切换为 MathJax。
|
|
55
55
|
*
|
|
56
56
|
* 参数说明:
|
|
57
57
|
* - element: 需要进行数学渲染的根容器(默认 document)
|
|
@@ -180,8 +180,6 @@ export const mathRender = (
|
|
|
180
180
|
next();
|
|
181
181
|
};
|
|
182
182
|
if (!window.MathJax) {
|
|
183
|
-
// typeset 设为 true 以正常完成公式渲染;elements 限定为传入的容器,外部使用本包时仅处理该容器,不影响编辑器以外的公式。
|
|
184
|
-
// 渲染时会将 startup.elements 临时设为传入的 element(当前预览/编辑容器),再 clear/updateDocument。
|
|
185
183
|
window.MathJax = {
|
|
186
184
|
loader: {
|
|
187
185
|
paths: { mathjax: `${options.cdn}/dist/js/mathjax` },
|
|
@@ -191,28 +189,12 @@ export const mathRender = (
|
|
|
191
189
|
elements: element instanceof HTMLElement ? [element] : [],
|
|
192
190
|
},
|
|
193
191
|
tex: {
|
|
194
|
-
inlineMath: [
|
|
195
|
-
["$", "$"],
|
|
196
|
-
["\\(", "\\)"],
|
|
197
|
-
],
|
|
198
|
-
displayMath: [
|
|
199
|
-
["$$", "$$"],
|
|
200
|
-
["\\[", "\\]"],
|
|
201
|
-
],
|
|
202
|
-
processEscapes: true, // 允许转义字符(可选,确保分隔符不被误解析)
|
|
203
192
|
macros: options.math.macros,
|
|
204
|
-
// 启用 ams 与 unicode,支持 \unicode 宏以渲染 ∯(oiint)
|
|
205
|
-
packages: { "[+]": ["ams", "unicode", "noerrors"] },
|
|
206
|
-
},
|
|
207
|
-
// 关闭 MathJax 自带右键菜单,使用自定义菜单
|
|
208
|
-
options: {
|
|
209
|
-
enableMenu: false,
|
|
210
193
|
},
|
|
211
194
|
};
|
|
212
|
-
// https://github.com/Vanessa219/vditor/issues/1453
|
|
195
|
+
// https://github.com/Vanessa219/vditor/issues/1453 额外配置(packages、inlineMath、displayMath 等)由调用方通过 mathJaxOptions 传入
|
|
213
196
|
Object.assign(window.MathJax, options.math.mathJaxOptions);
|
|
214
197
|
}
|
|
215
|
-
// 循环加载会抛异常
|
|
216
198
|
addScriptSync(
|
|
217
199
|
`${options.cdn}/dist/js/mathjax/tex-svg-full.js`,
|
|
218
200
|
"protyleMathJaxScript"
|
|
@@ -234,9 +216,7 @@ export const mathRender = (
|
|
|
234
216
|
const pre = mathElement.parentElement as HTMLElement;
|
|
235
217
|
pre.classList.add("vditor-wysiwyg__preview--math");
|
|
236
218
|
}
|
|
237
|
-
// 绑定自定义右键菜单(编辑区生效,预览区自动跳过)
|
|
238
219
|
bindMathContextMenu(mathElement as HTMLElement);
|
|
239
|
-
// 限定 document 范围为当前容器后再 clear/updateDocument,避免处理整页导致编辑器外的 $...$ 被重新渲染;不调用会导致同一公式被渲染 2 次
|
|
240
220
|
const startup = window.MathJax.startup;
|
|
241
221
|
const prevElements = startup.elements;
|
|
242
222
|
if (element instanceof HTMLElement) {
|
|
@@ -253,9 +233,10 @@ export const mathRender = (
|
|
|
253
233
|
errorTextElement &&
|
|
254
234
|
errorTextElement.textContent.trim() !== ""
|
|
255
235
|
) {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
mathElement.className =
|
|
236
|
+
mathElement.innerHTML =
|
|
237
|
+
errorTextElement.textContent.trim();
|
|
238
|
+
mathElement.className =
|
|
239
|
+
"language-math vditor-reset--error";
|
|
259
240
|
}
|
|
260
241
|
if (next) {
|
|
261
242
|
next();
|
|
@@ -264,7 +245,6 @@ export const mathRender = (
|
|
|
264
245
|
);
|
|
265
246
|
};
|
|
266
247
|
window.MathJax.startup.promise.then(() => {
|
|
267
|
-
// 限定仅处理当前容器,避免组件内部或用户配置导致处理整页、影响编辑器以外的公式
|
|
268
248
|
if (window.MathJax.startup) {
|
|
269
249
|
window.MathJax.startup.typeset = true;
|
|
270
250
|
window.MathJax.startup.elements =
|