diff --git a/web/src/labs/marked/parser/CodeBlock.ts b/web/src/labs/marked/parser/CodeBlock.ts index ca5afb3a..52e94540 100644 --- a/web/src/labs/marked/parser/CodeBlock.ts +++ b/web/src/labs/marked/parser/CodeBlock.ts @@ -10,11 +10,18 @@ const renderer = (rawStr: string): string => { } const language = escape(matchResult[1]) || "plaintext"; - const highlightedCodes = hljs.highlight(matchResult[2], { - language, - }).value; + let highlightedCode = hljs.highlightAuto(matchResult[2]).value; - return `
${highlightedCodes}
${matchResult[3]}`; + try { + const temp = hljs.highlight(matchResult[2], { + language, + }).value; + highlightedCode = temp; + } catch (error) { + // do nth + } + + return `
${highlightedCode}
${matchResult[3]}`; }; export default {