From 006ba3b877b0f59b6adc9137e8cb35c20693e65b Mon Sep 17 00:00:00 2001 From: archer <545436317@qq.com> Date: Mon, 12 Jun 2023 22:51:36 +0800 Subject: [PATCH] fix: mermaid --- .../components/Markdown/MermaidCodeBlock.tsx | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/client/src/components/Markdown/MermaidCodeBlock.tsx b/client/src/components/Markdown/MermaidCodeBlock.tsx index 9d3a80a65..91304b729 100644 --- a/client/src/components/Markdown/MermaidCodeBlock.tsx +++ b/client/src/components/Markdown/MermaidCodeBlock.tsx @@ -27,7 +27,29 @@ const MermaidBlock = ({ code }: { code: string }) => { useEffect(() => { try { - const formatCode = code.replace(/:/g, ':'); + const punctuationMap: Record = { + ',': ',', + ';': ';', + '。': '.', + ':': ':', + '!': '!', + '?': '?', + '“': '"', + '”': '"', + '‘': "'", + '’': "'", + '【': '[', + '】': ']', + '(': '(', + ')': ')', + '《': '<', + '》': '>', + '、': ',' + }; + const formatCode = code.replace( + /([,;。:!?“”‘’【】()《》、])/g, + (match) => punctuationMap[match] + ); mermaidAPI.render(`mermaid-${Date.now()}`, formatCode, (svgCode: string) => { setSvg(svgCode);