From 14a9fecc6493ec780716bf712205b9e9c4e80beb Mon Sep 17 00:00:00 2001 From: pablodanswer Date: Mon, 2 Sep 2024 13:33:18 -0700 Subject: [PATCH] update code block (#2297) --- web/src/app/chat/message/CodeBlock.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/web/src/app/chat/message/CodeBlock.tsx b/web/src/app/chat/message/CodeBlock.tsx index 7da83195b..29f141bcc 100644 --- a/web/src/app/chat/message/CodeBlock.tsx +++ b/web/src/app/chat/message/CodeBlock.tsx @@ -50,6 +50,12 @@ export function CodeBlock({ ); codeText = codeText.trim(); + // Find the last occurrence of closing backticks + const lastBackticksIndex = codeText.lastIndexOf("```"); + if (lastBackticksIndex !== -1) { + codeText = codeText.slice(0, lastBackticksIndex + 3); + } + // Remove the language declaration and trailing backticks const codeLines = codeText.split("\n"); if (