From 8288d484d9a478f66b08aba402ead486cb9f8a6d Mon Sep 17 00:00:00 2001 From: Vanessa Date: Tue, 6 May 2025 23:06:56 +0800 Subject: [PATCH] :recycle: https://github.com/siyuan-note/siyuan/issues/12571 --- app/src/protyle/preview/index.ts | 20 +++++++++----------- app/src/types/index.d.ts | 7 +++++-- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/app/src/protyle/preview/index.ts b/app/src/protyle/preview/index.ts index afef5317a..1546849e5 100644 --- a/app/src/protyle/preview/index.ts +++ b/app/src/protyle/preview/index.ts @@ -234,21 +234,19 @@ export class Preview { } }); }); + if(typeof window.MathJax === "undefined") { + window.MathJax = { + svg: { + fontCache: "none" + }, + }; + } await addScriptSync(`${Constants.PROTYLE_CDN}/js/mathjax/tex-svg-full.js`, "protyleMathJaxScript"); await window.MathJax.startup.promise; copyElement.querySelectorAll('[data-subtype="math"]').forEach(mathElement => { const node = window.MathJax.tex2svg(Lute.UnEscapeHTMLStr(mathElement.getAttribute("data-content")).trim(), {display: mathElement.tagName === "DIV"}); - node.querySelectorAll("use").forEach(item => { - const useTarget = node.querySelector(item.getAttribute("xlink:href")); - if (useTarget) { - useTarget.setAttribute("transform", item.getAttribute("transform") || ""); - item.outerHTML = useTarget.outerHTML; - } - }); - node.querySelector("mjx-assistive-mml")?.remove(); - node.querySelector("defs")?.remove(); - mathElement.innerHTML = ""; - mathElement.append(node); + node.querySelector("mjx-assistive-mml").remove(); + mathElement.innerHTML= node.outerHTML; }); } else if (type === "zhihu") { this.link2online(copyElement); diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.ts index b6bf08b1d..e7616d376 100644 --- a/app/src/types/index.d.ts +++ b/app/src/types/index.d.ts @@ -152,10 +152,13 @@ interface Window { }): void; }; MathJax: { - tex2svg(math: string, options: {display: boolean}): HTMLElement - startup: { + svg: { + fontCache: string + } + startup?: { promise: Promise } + tex2svg?(math: string, options: { display: boolean }): HTMLElement }; hljs: { listLanguages(): string[];