瀏覽代碼

修改数学公式

11wqe1 1 月之前
父節點
當前提交
edcee98a1b

+ 45 - 3
src/components/components/askStatic2.vue

@@ -33,7 +33,7 @@
                   cursor: pointer;
                 "
               >
-                {{ index + 1 + "、"  }} <span ref="latexElement" v-html="item.teststitle"></span>
+                {{ index + 1 + "、"  }} <span ref="latexElement" v-html="renderedFormula(item.teststitle)"></span>
               </div>
             </el-tooltip>
             <!-- </el-tooltip> -->
@@ -200,7 +200,50 @@ export default {
     };
   },
   computed: {
-    
+        renderedFormula() {
+      return function(val){
+        try {
+           // 判断是否含有HTML标签,<tag ...>...</tag>
+            const hasTag = /<([a-zA-Z][\w\-]*)([^>]*)>([\s\S]*?)<\/\1>/g.test(val);
+            if (!hasTag) {
+              val = val.trim().replace(/[\u200B-\u200D\uFEFF]/g, '');
+
+              // 纯文本,整体渲染
+              try {
+                return katex.renderToString(val.trim(), {
+                  throwOnError: false,
+                  strict: false,
+                  output: "htmlAndMathml"
+                });
+              } catch (e) {
+                return val; // 渲染失败原样输出
+              }
+            } else {
+              // 有标签,对每个标签内容渲染
+              return val.replace(
+                /<([a-zA-Z][\w\-]*)([^>]*)>([\s\S]*?)<\/\1>/g,
+                (match, tag, attrs, inner) => {
+                  let html;
+                  val = val.trim().replace(/[\u200B-\u200D\uFEFF]/g, '');
+                  try {
+                    html = katex.renderToString(inner.trim(), {
+                      throwOnError: false,
+                      strict: false,
+                      output: "htmlAndMathml"
+                    });
+                  } catch (e) {
+                    html = inner;
+                  }
+                  return `<${tag}${attrs}>${html}</${tag}>`;
+                }
+              );
+            }
+        } catch (e) {
+          console.error('KaTeX渲染错误:', e);
+          return val;
+        }
+      }
+    }
   },
   methods: {
     handleClose(done) {
@@ -273,7 +316,6 @@ export default {
 
 .a_add_head >>> .katex {
   font-size: 16px;
-  display: block;
   width: 100%;
   white-space: normal;
 }

+ 47 - 6
src/components/components/choseWorksDetailDialog.vue

@@ -56,8 +56,7 @@
                       v-if="[72].includes(toolType)"
                     @click="upLoadApp">作业提交</el-button>
                   </div>
-
-                  <span v-if="testData.toolDetail"><span v-html="testData.toolDetail"></span></span>
+                  <span v-if="testData.toolDetail"><span v-html="renderedFormula(testData.toolDetail)"></span></span>
 									<span v-else>无</span>
                 </div>
 
@@ -85,7 +84,7 @@
                         >
                           (多选题)
                         </div>
-                        <div style="display: flex;align-items: center;">题目:<span v-html="item1.teststitle"></span></div>
+                        <div style="display: flex;align-items: center;">题目:<span v-html="renderedFormula(item1.teststitle)"></span></div>
                       </div>
                       <img
                         v-if="item1.img"
@@ -1045,7 +1044,7 @@
                         typeof item.answer === "number"
                           ? "单选题:"
                           : "多选题:"
-                      }}<span v-html="item.title"></span></span
+                      }}<span v-html="renderedFormula(item.title)"></span></span
                     >
                   </div>
 
@@ -1521,7 +1520,50 @@ export default {
   },
 
   computed: {
-
+    renderedFormula() {
+      return function(val){
+        try {
+           // 判断是否含有HTML标签,<tag ...>...</tag>
+            const hasTag = /<([a-zA-Z][\w\-]*)([^>]*)>([\s\S]*?)<\/\1>/g.test(val);
+            if (!hasTag) {
+              val = val.trim().replace(/[\u200B-\u200D\uFEFF]/g, '');
+
+              // 纯文本,整体渲染
+              try {
+                return katex.renderToString(val.trim(), {
+                  throwOnError: false,
+                  strict: false,
+                  output: "htmlAndMathml"
+                });
+              } catch (e) {
+                return val; // 渲染失败原样输出
+              }
+            } else {
+              // 有标签,对每个标签内容渲染
+              return val.replace(
+                /<([a-zA-Z][\w\-]*)([^>]*)>([\s\S]*?)<\/\1>/g,
+                (match, tag, attrs, inner) => {
+                  let html;
+                  val = val.trim().replace(/[\u200B-\u200D\uFEFF]/g, '');
+                  try {
+                    html = katex.renderToString(inner.trim(), {
+                      throwOnError: false,
+                      strict: false,
+                      output: "htmlAndMathml"
+                    });
+                  } catch (e) {
+                    html = inner;
+                  }
+                  return `<${tag}${attrs}>${html}</${tag}>`;
+                }
+              );
+            }
+        } catch (e) {
+          console.error('KaTeX渲染错误:', e);
+          return val;
+        }
+      }
+    },
     tableData() {
       let _result = [];
       if (this.show && this.toolIndex !== null && [45].includes(this.toolType)) {
@@ -4347,7 +4389,6 @@ ol {
 
 .a_add_head >>> .katex {
   font-size: 16px;
-  display: block;
   width: 100%;
   white-space: normal;
 }

+ 3 - 3
src/components/components/sortToolWorkShow.vue

@@ -119,14 +119,14 @@
                     })
                 });
 
-                console.log('llllllll',JSON.parse(JSON.stringify(allWork)));
+                // console.log('llllllll',JSON.parse(JSON.stringify(allWork)));
                 
                 for (let index = 0; index < allWork.length; index++) {
                     groups[index] = this.countDuplicates(allWork[index])
                 }
 
 
-                console.log('groups',JSON.parse(JSON.stringify(groups)));
+                // console.log('groups',JSON.parse(JSON.stringify(groups)));
                 
 
                 // let groups = this.countDuplicates(allWork)
@@ -143,7 +143,7 @@
 
                 
                 this.sortData = groups
-                console.log('sortData',sortData);
+                // console.log('sortData',sortData);
 
                 // console.log('groups',groups);
                 

+ 45 - 3
src/components/components/studentWorkPreviewDialog.vue

@@ -39,7 +39,7 @@
                   <span
                     style="display: flex;align-items: center;"
                     >{{ item.type == 1 ? "单选题:" : "多选题:"
-                    }}<span v-html="item.teststitle"></span> </span
+                    }}<span v-html="renderedFormula(item.teststitle)"></span> </span
                   >
                 </div>
                 <div
@@ -400,7 +400,50 @@ export default {
     }
   },
   computed: {
-
+    renderedFormula() {
+      return function(val){
+       try {
+           // 判断是否含有HTML标签,<tag ...>...</tag>
+            const hasTag = /<([a-zA-Z][\w\-]*)([^>]*)>([\s\S]*?)<\/\1>/g.test(val);
+            if (!hasTag) {
+              val = val.trim().replace(/[\u200B-\u200D\uFEFF]/g, '');
+
+              // 纯文本,整体渲染
+              try {
+                return katex.renderToString(val.trim(), {
+                  throwOnError: false,
+                  strict: false,
+                  output: "htmlAndMathml"
+                });
+              } catch (e) {
+                return val; // 渲染失败原样输出
+              }
+            } else {
+              // 有标签,对每个标签内容渲染
+              return val.replace(
+                /<([a-zA-Z][\w\-]*)([^>]*)>([\s\S]*?)<\/\1>/g,
+                (match, tag, attrs, inner) => {
+                  let html;
+                  val = val.trim().replace(/[\u200B-\u200D\uFEFF]/g, '');
+                  try {
+                    html = katex.renderToString(inner.trim(), {
+                      throwOnError: false,
+                      strict: false,
+                      output: "htmlAndMathml"
+                    });
+                  } catch (e) {
+                    html = inner;
+                  }
+                  return `<${tag}${attrs}>${html}</${tag}>`;
+                }
+              );
+            }
+        } catch (e) {
+          console.error('KaTeX渲染错误:', e);
+          return val;
+        }
+      }
+    },
     MarkdownT() {
       return function (c) {
         let md = new MarkdownIt();
@@ -468,7 +511,6 @@ export default {
 
 .studentWorkPreviewDialog >>> .katex {
   font-size: 16px;
-  display: block;
   width: 100%;
   white-space: normal;
 }

+ 72 - 6
src/components/easy2/studyStudent.vue

@@ -522,9 +522,9 @@
                   v-html="
                     chapInfoList[courseType].chapterInfo[0].taskJson[taskCount]
                       .taskDetail
-                      ? chapInfoList[courseType].chapterInfo[0].taskJson[
+                      ? renderedFormula2(chapInfoList[courseType].chapterInfo[0].taskJson[
                           taskCount
-                        ].taskDetail
+                        ].taskDetail)
                       : '暂无描述'
                   "
                 ></div>
@@ -1577,7 +1577,7 @@
                       <!-- @click.stop="updateToolDetail(toolIndex, 2)" -->
                       <div
                         style="height:100%;"
-                        v-html="tool.toolDetail"
+                        v-html="renderedFormula(tool.toolDetail)"
                         v-if="toolDetailIndex != toolIndex"
                       ></div>
                       <div v-else @click.stop="" style="height:100%;">
@@ -6206,7 +6206,7 @@
                               cursor: pointer;
                             "
                           >
-                            {{ index + 1 + "、"  }} <span v-html="item.teststitle"></span>
+                            {{ index + 1 + "、"  }} <span v-html="renderedFormula(item.teststitle)"></span>
                           </div>
                         </el-tooltip>
                       </div>
@@ -13035,7 +13035,7 @@
                 >
                   (多选题)
                 </div>
-                <div>题目:<span v-html="testJson.testJson[index1].teststitle"></span></div>
+                <div>题目:<span v-html="renderedFormula(testJson.testJson[index1].teststitle)"></span></div>
               </div>
               <img
                 v-if="testJson.testJson[index1].img"
@@ -26197,7 +26197,74 @@ export default {
     this.updateSplitScreenData(1);
   },
   computed: {
+    renderedFormula2() {
+      return function(val){
+        // 处理换行符和HTML实体
+        const normalized = val
+          .replace(/&amp;/g, '&')
+          .replace(/<br\/?>/g, '\n');
+        
+        // 匹配行内公式($...$)和块级公式($$...$$)
+        return normalized.replace(/(\${1,2})([^$]+)(\${1,2})/g, (_, delim, expr) => {
+          try {
+            return katex.renderToString(expr.trim(), {
+              displayMode: false,
+              throwOnError: false,
+              macros: {
+                '\\aligned': '\\begin{aligned}#1\\end{aligned}'
+              }
+            });
+          } catch (e) {
+            console.warn('KaTeX渲染失败:', e);
+            return `<span style="color:red">${expr}</span>`;
+          }
+        })
+      }
+    },
+    renderedFormula() {
+      return function(val){
+        try {
+        // 判断是否含有HTML标签,<tag ...>...</tag>
+            const hasTag = /<([a-zA-Z][\w\-]*)([^>]*)>([\s\S]*?)<\/\1>/g.test(val);
+            if (!hasTag) {
+            val = val.trim().replace(/[\u200B-\u200D\uFEFF]/g, '');
 
+            // 纯文本,整体渲染
+            try {
+              return katex.renderToString(val.trim(), {
+                throwOnError: false,
+                strict: false,
+                output: "htmlAndMathml"
+              });
+            } catch (e) {
+              return val; // 渲染失败原样输出
+            }
+            } else {
+            // 有标签,对每个标签内容渲染
+            return val.replace(
+              /<([a-zA-Z][\w\-]*)([^>]*)>([\s\S]*?)<\/\1>/g,
+              (match, tag, attrs, inner) => {
+              let html;
+              val = val.trim().replace(/[\u200B-\u200D\uFEFF]/g, '');
+              try {
+                html = katex.renderToString(inner.trim(), {
+                throwOnError: false,
+                strict: false,
+                output: "htmlAndMathml"
+                });
+              } catch (e) {
+                html = inner;
+              }
+                return `<${tag}${attrs}>${html}</${tag}>`;
+              }
+            );
+          }
+        } catch (e) {
+          console.error('KaTeX渲染错误:', e);
+          return val;
+        }
+      }
+    },
     isAndroid() {
       return /Android/i.test(navigator.userAgent);
     },
@@ -30916,7 +30983,6 @@ div::-webkit-scrollbar {
 }
 .pb_content >>> .katex {
   font-size: 16px;
-  display: block;
   width: 100%;
   white-space: normal;
 }

+ 74 - 7
src/components/easy3/studyStudent.vue

@@ -537,9 +537,9 @@
                   v-html="
                     chapInfoList[courseType].chapterInfo[0].taskJson[taskCount]
                       .taskDetail
-                      ? chapInfoList[courseType].chapterInfo[0].taskJson[
+                      ? renderedFormula2(chapInfoList[courseType].chapterInfo[0].taskJson[
                           taskCount
-                        ].taskDetail
+                        ].taskDetail)
                       : '暂无描述'
                   "
                 ></div>
@@ -1551,7 +1551,7 @@
                       <!-- <div class="toolTitle">工具描述</div> -->
                       <!-- @click.stop="updateToolDetail(toolIndex, 2)" 点击开启修改-->
                       <div style="height:100%;"
-                        v-html="tool.toolDetail"
+                        v-html="renderedFormula(tool.toolDetail)"
                         v-if="toolDetailIndex != toolIndex"
                       ></div>
                       <div v-else @click.stop="" style="height:100%;">
@@ -4465,7 +4465,7 @@
                               cursor: pointer;
                             "
                           >
-                            {{ index + 1 + "、"  }} <span v-html="item.teststitle"></span>
+                            {{ index + 1 + "、"  }} <span v-html="renderedFormula(item.teststitle)"></span>
                           </div>
                         </el-tooltip>
                       </div>
@@ -9667,7 +9667,7 @@
                 >
                   (多选题)
                 </div>
-                <div>题目:<span v-html="testJson.testJson[index1].teststitle"></span></div>
+                <div>题目:<span v-html="renderedFormula(testJson.testJson[index1].teststitle)"></span></div>
               </div>
               <img
                 v-if="testJson.testJson[index1].img"
@@ -13172,7 +13172,7 @@ export default {
           {
             role: "user",
             content:
-               `Role: 你是一名小学英语作文的老师,根据这篇文章的内容你去批改这篇文章,然后仅输出一篇纠错好的文章。文章:${t}`,
+              `Role: 你是一名小学英语作文的老师,根据这篇文章的内容你去批改这篇文章,然后仅输出一篇纠错好的文章。文章:${t}`,
           },
         ],
         uid: this.userid,
@@ -21552,6 +21552,74 @@ export default {
 		this.updateSplitScreenData(1);
   },
   computed: {
+    renderedFormula2() {
+      return function(val){
+        // 处理换行符和HTML实体
+        const normalized = val
+          .replace(/&amp;/g, '&')
+          .replace(/<br\/?>/g, '\n');
+        
+        // 匹配行内公式($...$)和块级公式($$...$$)
+        return normalized.replace(/(\${1,2})([^$]+)(\${1,2})/g, (_, delim, expr) => {
+          try {
+            return katex.renderToString(expr.trim(), {
+              displayMode: false,
+              throwOnError: false,
+              macros: {
+                '\\aligned': '\\begin{aligned}#1\\end{aligned}'
+              }
+            });
+          } catch (e) {
+            console.warn('KaTeX渲染失败:', e);
+            return `<span style="color:red">${expr}</span>`;
+          }
+        })
+      }
+    },
+    renderedFormula() {
+      return function(val){
+        try {
+        // 判断是否含有HTML标签,<tag ...>...</tag>
+            const hasTag = /<([a-zA-Z][\w\-]*)([^>]*)>([\s\S]*?)<\/\1>/g.test(val);
+            if (!hasTag) {
+            val = val.trim().replace(/[\u200B-\u200D\uFEFF]/g, '');
+
+            // 纯文本,整体渲染
+            try {
+              return katex.renderToString(val.trim(), {
+                throwOnError: false,
+                strict: false,
+                output: "htmlAndMathml"
+              });
+            } catch (e) {
+              return val; // 渲染失败原样输出
+            }
+            } else {
+            // 有标签,对每个标签内容渲染
+            return val.replace(
+              /<([a-zA-Z][\w\-]*)([^>]*)>([\s\S]*?)<\/\1>/g,
+              (match, tag, attrs, inner) => {
+              let html;
+              val = val.trim().replace(/[\u200B-\u200D\uFEFF]/g, '');
+              try {
+                html = katex.renderToString(inner.trim(), {
+                throwOnError: false,
+                strict: false,
+                output: "htmlAndMathml"
+                });
+              } catch (e) {
+                html = inner;
+              }
+                return `<${tag}${attrs}>${html}</${tag}>`;
+              }
+            );
+          }
+        } catch (e) {
+          console.error('KaTeX渲染错误:', e);
+          return val;
+        }
+      }
+    },
     isAndroid() {
       return /Android/i.test(navigator.userAgent);
     },
@@ -22015,7 +22083,6 @@ export default {
 }
 .pb_content >>> .katex {
   font-size: 16px;
-  display: block;
   width: 100%;
   white-space: normal;
 }

+ 75 - 8
src/components/studyStudent.vue

@@ -500,9 +500,9 @@
                   v-html="
                     chapInfoList[courseType].chapterInfo[0].taskJson[taskCount]
                       .taskDetail
-                      ? chapInfoList[courseType].chapterInfo[0].taskJson[
+                      ? renderedFormula2(chapInfoList[courseType].chapterInfo[0].taskJson[
                           taskCount
-                        ].taskDetail
+                        ].taskDetail)  
                       : '暂无描述'
                   "
                 ></div>
@@ -1511,7 +1511,7 @@
                       <!-- <div class="toolTitle">工具描述</div> -->
                         <!-- @click.stop="updateToolDetail(toolIndex, 2)" -->
                       <div style="height:100%;"
-                        v-html="tool.toolDetail"
+                        v-html="renderedFormula(tool.toolDetail)"
                         v-if="toolDetailIndex != toolIndex"
                       ></div>
                       <div v-else @click.stop="" style="height:100%;">
@@ -4425,7 +4425,7 @@
                               cursor: pointer;
                             "
                           >
-                            {{ index + 1 + "、"  }} <span v-html="item.teststitle"></span>
+                              {{ index + 1 + "、"  }} <span v-html="renderedFormula(item.teststitle)"></span>
                           </div>
                         </el-tooltip>
                       </div>
@@ -9603,7 +9603,7 @@
                 >
                   (多选题)
                 </div>
-                <div>题目:<span v-html="testJson.testJson[index1].teststitle"></span></div>
+                  <div>题目:<span v-html="renderedFormula(testJson.testJson[index1].teststitle)"></span></div>
               </div>
               <img
                 v-if="testJson.testJson[index1].img"
@@ -13108,7 +13108,7 @@ export default {
           {
             role: "user",
             content:
-             `Role: 你是一名小学英语作文的老师,根据这篇文章的内容你去批改这篇文章,然后仅输出一篇纠错好的文章。文章:${t}`,
+            `Role: 你是一名小学英语作文的老师,根据这篇文章的内容你去批改这篇文章,然后仅输出一篇纠错好的文章。文章:${t}`,
           },
         ],
         uid: this.userid,
@@ -21505,6 +21505,74 @@ export default {
 		this.updateSplitScreenData(1);
   },
   computed: {
+    renderedFormula2() {
+      return function(val){
+        // 处理换行符和HTML实体
+        const normalized = val
+          .replace(/&amp;/g, '&')
+          .replace(/<br\/?>/g, '\n');
+        
+        // 匹配行内公式($...$)和块级公式($$...$$)
+        return normalized.replace(/(\${1,2})([^$]+)(\${1,2})/g, (_, delim, expr) => {
+          try {
+            return katex.renderToString(expr.trim(), {
+              displayMode: false,
+              throwOnError: false,
+              macros: {
+                '\\aligned': '\\begin{aligned}#1\\end{aligned}'
+              }
+            });
+          } catch (e) {
+            console.warn('KaTeX渲染失败:', e);
+            return `<span style="color:red">${expr}</span>`;
+          }
+        })
+      }
+    },
+    renderedFormula() {
+      return function(val){
+        try {
+        // 判断是否含有HTML标签,<tag ...>...</tag>
+            const hasTag = /<([a-zA-Z][\w\-]*)([^>]*)>([\s\S]*?)<\/\1>/g.test(val);
+            if (!hasTag) {
+            val = val.trim().replace(/[\u200B-\u200D\uFEFF]/g, '');
+
+            // 纯文本,整体渲染
+            try {
+              return katex.renderToString(val.trim(), {
+                throwOnError: false,
+                strict: false,
+                output: "htmlAndMathml"
+              });
+            } catch (e) {
+              return val; // 渲染失败原样输出
+            }
+            } else {
+            // 有标签,对每个标签内容渲染
+            return val.replace(
+              /<([a-zA-Z][\w\-]*)([^>]*)>([\s\S]*?)<\/\1>/g,
+              (match, tag, attrs, inner) => {
+              let html;
+              val = val.trim().replace(/[\u200B-\u200D\uFEFF]/g, '');
+              try {
+                html = katex.renderToString(inner.trim(), {
+                throwOnError: false,
+                strict: false,
+                output: "htmlAndMathml"
+                });
+              } catch (e) {
+                html = inner;
+              }
+                return `<${tag}${attrs}>${html}</${tag}>`;
+              }
+            );
+          }
+        } catch (e) {
+          console.error('KaTeX渲染错误:', e);
+          return val;
+        }
+      }
+    },
     isAndroid() {
       return /Android/i.test(navigator.userAgent);
     },
@@ -21514,7 +21582,7 @@ export default {
           ? c
               .replaceAll(/\r\n/g, "<br/>")
               .replaceAll(/\n/g, "<br/>")
-              .replaceAll(/\s/g, " &nbsp")
+              .replaceAll(/\s/g, "&nbsp")
           : "";
       };
     },
@@ -26149,7 +26217,6 @@ div::-webkit-scrollbar {
 }
 .pb_content >>> .katex {
   font-size: 16px;
-  display: block;
   width: 100%;
   white-space: normal;
 }

+ 73 - 6
src/components/studySutdentClass/studyStudent.vue

@@ -537,9 +537,9 @@
                   v-html="
                     chapInfoList[courseType].chapterInfo[0].taskJson[taskCount]
                       .taskDetail
-                      ? chapInfoList[courseType].chapterInfo[0].taskJson[
+                      ? renderedFormula2(chapInfoList[courseType].chapterInfo[0].taskJson[
                           taskCount
-                        ].taskDetail
+                        ].taskDetail)
                       : '暂无描述'
                   "
                 ></div>
@@ -1573,7 +1573,7 @@
                       <!-- @click.stop="updateToolDetail(toolIndex, 2)" -->
                       <div
                         style="height:100%;"
-                        v-html="tool.toolDetail"
+                        v-html="renderedFormula(tool.toolDetail)"
                         v-if="toolDetailIndex != toolIndex"
                       ></div>
                       <div v-else @click.stop="" style="height:100%;">
@@ -6202,7 +6202,7 @@
                               cursor: pointer;
                             "
                           >
-                            {{ index + 1 + "、"  }} <span v-html="item.teststitle"></span>
+                            {{ index + 1 + "、"  }} <span v-html="renderedFormula(item.teststitle)"></span>
                           </div>
                         </el-tooltip>
                       </div>
@@ -12848,7 +12848,7 @@
                 >
                   (多选题)
                 </div>
-                <div>题目:<span v-html="testJson.testJson[index1].teststitle"></span></div>
+                <div>题目:<span v-html="renderedFormula(testJson.testJson[index1].teststitle)"></span></div>
               </div>
               <img
                 v-if="testJson.testJson[index1].img"
@@ -25592,6 +25592,74 @@ export default {
 		this.updateSplitScreenData(1);
   },
   computed: {
+    renderedFormula2() {
+      return function(val){
+        // 处理换行符和HTML实体
+        const normalized = val
+          .replace(/&amp;/g, '&')
+          .replace(/<br\/?>/g, '\n');
+        
+        // 匹配行内公式($...$)和块级公式($$...$$)
+        return normalized.replace(/(\${1,2})([^$]+)(\${1,2})/g, (_, delim, expr) => {
+          try {
+            return katex.renderToString(expr.trim(), {
+              displayMode: false,
+              throwOnError: false,
+              macros: {
+                '\\aligned': '\\begin{aligned}#1\\end{aligned}'
+              }
+            });
+          } catch (e) {
+            console.warn('KaTeX渲染失败:', e);
+            return `<span style="color:red">${expr}</span>`;
+          }
+        })
+      }
+    },
+    renderedFormula() {
+      return function(val){
+        try {
+        // 判断是否含有HTML标签,<tag ...>...</tag>
+            const hasTag = /<([a-zA-Z][\w\-]*)([^>]*)>([\s\S]*?)<\/\1>/g.test(val);
+            if (!hasTag) {
+            val = val.trim().replace(/[\u200B-\u200D\uFEFF]/g, '');
+
+            // 纯文本,整体渲染
+            try {
+              return katex.renderToString(val.trim(), {
+                throwOnError: false,
+                strict: false,
+                output: "htmlAndMathml"
+              });
+            } catch (e) {
+              return val; // 渲染失败原样输出
+            }
+            } else {
+            // 有标签,对每个标签内容渲染
+            return val.replace(
+              /<([a-zA-Z][\w\-]*)([^>]*)>([\s\S]*?)<\/\1>/g,
+              (match, tag, attrs, inner) => {
+              let html;
+              val = val.trim().replace(/[\u200B-\u200D\uFEFF]/g, '');
+              try {
+                html = katex.renderToString(inner.trim(), {
+                throwOnError: false,
+                strict: false,
+                output: "htmlAndMathml"
+                });
+              } catch (e) {
+                html = inner;
+              }
+                return `<${tag}${attrs}>${html}</${tag}>`;
+              }
+            );
+          }
+        } catch (e) {
+          console.error('KaTeX渲染错误:', e);
+          return val;
+        }
+      }
+    },
     isAndroid() {
       return /Android/i.test(navigator.userAgent);
     },
@@ -30267,7 +30335,6 @@ div::-webkit-scrollbar {
 }
 .pb_content >>> .katex {
   font-size: 16px;
-  display: block;
   width: 100%;
   white-space: normal;
 }