Browse Source

fix:继续修复

大侠咬超人 2 days ago
parent
commit
c41ffb0c4e
2 changed files with 4 additions and 3 deletions
  1. 1 1
      app/Services/KatexRenderer.php
  2. 3 2
      scripts/katex-render.mjs

+ 1 - 1
app/Services/KatexRenderer.php

@@ -36,7 +36,7 @@ class KatexRenderer
 
     public function __construct()
     {
-        $this->scriptPath = base_path('scripts/katex-render.js');
+        $this->scriptPath = base_path('scripts/katex-render.mjs');
     }
 
     /**

+ 3 - 2
scripts/katex-render.js → scripts/katex-render.mjs

@@ -7,6 +7,9 @@
  * 将 HTML 中的 LaTeX 公式渲染为 KaTeX HTML
  */
 
+import { createRequire } from 'module';
+const require = createRequire(import.meta.url);
+
 // 尝试多个路径加载 KaTeX
 let katex;
 const possiblePaths = [
@@ -19,11 +22,9 @@ let loadError = null;
 for (const modulePath of possiblePaths) {
     try {
         katex = require(modulePath);
-        // console.error('KaTeX loaded from:', modulePath);
         break;
     } catch (e) {
         loadError = e;
-        // 继续尝试下一个路径
     }
 }