@8btc/mditor 0.0.28 → 0.0.30

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.
@@ -71,7 +71,7 @@ export const mathRender = (
71
71
  cdn: Constants.CDN,
72
72
  math: {
73
73
  engine: "MathJax",
74
- inlineDigit: false,
74
+ inlineDigit: true,
75
75
  macros: {},
76
76
  },
77
77
  };
@@ -180,8 +180,8 @@ export const mathRender = (
180
180
  next();
181
181
  };
182
182
  if (!window.MathJax) {
183
- // 关闭自动 typeset,避免处理整个 document 导致页面其他区域(如用户消息)中的 $...$ 被重新渲染。
184
- // 公式仅由本函数内对 tex2svgPromise 的显式调用渲染,且仅针对传入的 element 内的节点。
183
+ // 关闭自动 typeset、不指定 elements,避免处理整个 document。外部使用本包时无需配置 startup.elements:
184
+ // 渲染时会将 startup.elements 临时设为传入的 element(当前预览/编辑容器),再 clear/updateDocument。
185
185
  window.MathJax = {
186
186
  loader: {
187
187
  paths: { mathjax: `${options.cdn}/dist/js/mathjax` },
@@ -236,8 +236,15 @@ export const mathRender = (
236
236
  }
237
237
  // 绑定自定义右键菜单(编辑区生效,预览区自动跳过)
238
238
  bindMathContextMenu(mathElement as HTMLElement);
239
- window.MathJax.startup.document.clear();
240
- window.MathJax.startup.document.updateDocument();
239
+ // 限定 document 范围为当前容器后再 clear/updateDocument,避免处理整页导致编辑器外的 $...$ 被重新渲染;不调用会导致同一公式被渲染 2 次
240
+ const startup = window.MathJax.startup;
241
+ const prevElements = startup.elements;
242
+ if (element instanceof HTMLElement) {
243
+ startup.elements = [element];
244
+ }
245
+ startup.document.clear();
246
+ startup.document.updateDocument();
247
+ startup.elements = prevElements !== undefined ? prevElements : [];
241
248
  const errorTextElement = node.querySelector(
242
249
  '[data-mml-node="merror"]'
243
250
  );
@@ -256,6 +263,11 @@ export const mathRender = (
256
263
  );
257
264
  };
258
265
  window.MathJax.startup.promise.then(() => {
266
+ // 脚本加载后再次强制不自动 typeset、不指定 elements,避免组件内部或用户配置导致处理整页
267
+ if (window.MathJax.startup) {
268
+ window.MathJax.startup.typeset = false;
269
+ window.MathJax.startup.elements = [];
270
+ }
259
271
  const chains: any[] = [];
260
272
  for (let i = 0; i < mathElements.length; i++) {
261
273
  const mathElement = mathElements[i];