fix: mermaid

This commit is contained in:
archer
2023-06-12 22:51:36 +08:00
parent 5a534aa630
commit 006ba3b877

View File

@@ -27,7 +27,29 @@ const MermaidBlock = ({ code }: { code: string }) => {
useEffect(() => {
try {
const formatCode = code.replace(//g, ':');
const punctuationMap: Record<string, string> = {
'': ',',
'': ';',
'。': '.',
'': ':',
'': '!',
'': '?',
'“': '"',
'”': '"',
'': "'",
'': "'",
'【': '[',
'】': ']',
'': '(',
'': ')',
'《': '<',
'》': '>',
'、': ','
};
const formatCode = code.replace(
/([,;。:!?“”‘’【】()《》、])/g,
(match) => punctuationMap[match]
);
mermaidAPI.render(`mermaid-${Date.now()}`, formatCode, (svgCode: string) => {
setSvg(svgCode);