Skip to content

Commit e4c7b76

Browse files
committed
fix(ui): remove trailing code delimiters from markdown content
1 parent 4ce2664 commit e4c7b76

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

webview-ui/src/components/chat/ChatRow.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -986,13 +986,21 @@ const Markdown = memo(({ markdown, partial }: { markdown?: string; partial?: boo
986986
const [isHovering, setIsHovering] = useState(false)
987987
const { copyWithFeedback } = useCopyToClipboard(200) // shorter feedback duration for copy button flash
988988

989+
// Remove trailing code delimiters like "```tool_code" or "```xml"
990+
const cleanedMarkdown = useMemo(() => {
991+
if (!markdown) return markdown
992+
993+
// Regex to match trailing code block delimiters at the very end of the string
994+
return markdown.replace(/```[a-zA-Z0-9_-]*\s*$/g, "")
995+
}, [markdown])
996+
989997
return (
990998
<div
991999
onMouseEnter={() => setIsHovering(true)}
9921000
onMouseLeave={() => setIsHovering(false)}
9931001
style={{ position: "relative" }}>
9941002
<div style={{ wordBreak: "break-word", overflowWrap: "anywhere", marginBottom: -15, marginTop: -15 }}>
995-
<MarkdownBlock markdown={markdown} />
1003+
<MarkdownBlock markdown={cleanedMarkdown} />
9961004
</div>
9971005
{markdown && !partial && isHovering && (
9981006
<div

0 commit comments

Comments
 (0)