Procházet zdrojové kódy

Fix KaTeX rendering with soft break tags

yemeishu před 2 týdny
rodič
revize
100205cbd8
2 změnil soubory, kde provedl 3 přidání a 1 odebrání
  1. 2 1
      app/Services/KatexRenderer.php
  2. 1 0
      scripts/katex-render.mjs

+ 2 - 1
app/Services/KatexRenderer.php

@@ -204,7 +204,8 @@ class KatexRenderer
                 $decoded = html_entity_decode($tex, ENT_QUOTES, 'UTF-8');
             }
 
-            // 清理公式内部的换行与 <br>,避免 \frac{M}\n{N} 破坏解析
+            // 清理公式内部的软换行标签,避免断行优化污染 LaTeX 内容
+            $tex = preg_replace('/<wbr\\s*\\/?>/i', '', $tex);
             $tex = preg_replace('/<br\\s*\\/?>/i', '', $tex);
             $tex = preg_replace('/\\r\\n|\\r|\\n/', '', $tex);
 

+ 1 - 0
scripts/katex-render.mjs

@@ -146,6 +146,7 @@ function processDelimiter(html, left, right, displayMode) {
         try {
             // 清理 LaTeX 内容 - 先解码 HTML 实体
             let cleanLatex = decodeHtmlEntities(latex.trim());
+            cleanLatex = cleanLatex.replace(/<wbr\s*\/?>/gi, '');
 
             // 跳过空内容
             if (!cleanLatex) {