From 7bcfadde59356a67e418ae12531d27ed45b07604 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=82=A6?= Date: Tue, 28 Oct 2025 09:19:07 +0800 Subject: [PATCH] =?UTF-8?q?=20=20-=20=E5=9C=A8=20js/core/app-shell.js:1275?= =?UTF-8?q?=20=E5=BC=95=E5=85=A5=20window.mermaid.parse(code)=20=E8=AF=AD?= =?UTF-8?q?=E6=B3=95=E6=A0=A1=E9=AA=8C=EF=BC=8C=E8=8B=A5=E6=8D=95=E8=8E=B7?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E5=88=99=E6=8A=9B=E5=87=BA=E5=B8=A6=E6=9C=89?= =?UTF-8?q?=E2=80=9CMermaid=20=20=20=20=20=E8=AF=AD=E6=B3=95=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E2=80=9D=E6=8F=8F=E8=BF=B0=E7=9A=84=E9=94=99=E8=AF=AF?= =?UTF-8?q?=EF=BC=8C=E9=98=BB=E6=96=AD=E5=90=8E=E7=BB=AD=E6=B8=B2=E6=9F=93?= =?UTF-8?q?=E6=B5=81=E7=A8=8B=E5=B9=B6=E9=81=BF=E5=85=8D=E7=94=9F=E6=88=90?= =?UTF-8?q?=E6=97=A0=E6=95=88=E5=9B=BE=E8=A1=A8=E3=80=82=20=20=20-=20?= =?UTF-8?q?=E5=9C=A8=20js/core/app-shell.js:1244=20=E7=9A=84=E6=B8=B2?= =?UTF-8?q?=E6=9F=93=E5=BC=82=E5=B8=B8=E5=88=86=E6=94=AF=E4=B8=AD=E7=BB=9F?= =?UTF-8?q?=E4=B8=80=E5=A4=84=E7=90=86=E9=94=99=E8=AF=AF=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=EF=BC=8C=E6=97=A2=E5=9C=A8=E6=9F=A5=E7=9C=8B=E5=8C=BA=E5=9F=9F?= =?UTF-8?q?=E5=B1=95=E7=A4=BA=EF=BC=8C=E5=8F=88=E5=9C=A8=E8=BE=93=E5=85=A5?= =?UTF-8?q?=E6=A1=86=E6=9C=AB=E5=B0=BE=E8=BF=BD=E5=8A=A0=20=20=20=20=20?= =?UTF-8?q?=EF=BC=88=E9=81=BF=E5=85=8D=E9=87=8D=E5=A4=8D=E8=BF=BD=E5=8A=A0?= =?UTF-8?q?=EF=BC=89=EF=BC=8C=E5=B9=B6=E8=87=AA=E5=8A=A8=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E8=BE=93=E5=85=A5=E6=A1=86=E9=AB=98=E5=BA=A6=EF=BC=8C=E6=96=B9?= =?UTF-8?q?=E4=BE=BF=E7=94=A8=E6=88=B7=E5=9F=BA=E4=BA=8E=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E4=BF=AE=E6=94=B9=20Mermaid=20=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/core/app-shell.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/js/core/app-shell.js b/js/core/app-shell.js index 5c57719..429827f 100644 --- a/js/core/app-shell.js +++ b/js/core/app-shell.js @@ -1238,11 +1238,22 @@ } catch (error) { this.destroyMermaidPanZoom(); console.error('Mermaid 渲染失败:', error); + const errorMessage = error.message || '未知错误'; this.el.viewer.innerHTML = `
- Mermaid 渲染失败:${Utils.escapeHtml(error.message || '未知错误')} + Mermaid 渲染失败:${Utils.escapeHtml(errorMessage)}
`; + if (this.el.chatInput) { + const existingValue = this.el.chatInput.value || ''; + const appendedValue = existingValue.includes(errorMessage) + ? existingValue + : existingValue + ? `${existingValue}\n${errorMessage}` + : errorMessage; + this.el.chatInput.value = appendedValue; + Utils.autoResizeTextarea(this.el.chatInput); + } } } @@ -1256,6 +1267,15 @@ if (!code.trim()) { throw new Error('缺少 Mermaid 代码,无法渲染'); } + try { + window.mermaid.parse(code); + } catch (parseError) { + const syntaxMessage = + parseError?.str || parseError?.message || '未知错误'; + const error = new Error(`Mermaid 语法错误:${syntaxMessage}`); + error.isMermaidSyntaxError = true; + throw error; + } const { svg } = await window.mermaid.render("mermaidSvg", code); const updatedArtifact = { ...artifact,