From cb55e579983ed155fcb80fe5740ecfe56ebf38f0 Mon Sep 17 00:00:00 2001 From: pablodanswer Date: Mon, 2 Sep 2024 11:26:42 -0700 Subject: [PATCH 1/2] update code block --- web/src/app/chat/message/CodeBlock.tsx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/web/src/app/chat/message/CodeBlock.tsx b/web/src/app/chat/message/CodeBlock.tsx index 7da83195b43..dbbd08a4917 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 ( @@ -102,6 +108,13 @@ export function CodeBlock({ if (!codeText) { return; } + console.log(codeText); + console.log( + content.slice( + props.node.position.start.offset, + props.node.position.end.offset + ) + ); navigator.clipboard.writeText(codeText).then(() => { setCopied(true); From 51865e62116aa27e42b5b31d6a793586951132fa Mon Sep 17 00:00:00 2001 From: pablodanswer Date: Mon, 2 Sep 2024 11:27:14 -0700 Subject: [PATCH 2/2] remove log --- web/src/app/chat/message/CodeBlock.tsx | 7 ------- 1 file changed, 7 deletions(-) diff --git a/web/src/app/chat/message/CodeBlock.tsx b/web/src/app/chat/message/CodeBlock.tsx index dbbd08a4917..29f141bcc3f 100644 --- a/web/src/app/chat/message/CodeBlock.tsx +++ b/web/src/app/chat/message/CodeBlock.tsx @@ -108,13 +108,6 @@ export function CodeBlock({ if (!codeText) { return; } - console.log(codeText); - console.log( - content.slice( - props.node.position.start.offset, - props.node.position.end.offset - ) - ); navigator.clipboard.writeText(codeText).then(() => { setCopied(true);