Skip to content

Commit d02e5a8

Browse files
weshokeWesley SmithCline Evaluation
authored
fix excessive markdown format character escaping (RooCodeInc#3355)
* fix excessive markdown format character escaping * add changeset * made it a little more robust --------- Co-authored-by: Wesley Smith <[email protected]> Co-authored-by: Cline Evaluation <[email protected]>
1 parent 20f1991 commit d02e5a8

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

.changeset/heavy-spoons-ring.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"claude-dev": patch
3+
---
4+
5+
Fix for markdown copy excessive escape characters

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

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,27 @@ interface ChatViewProps {
4141
showHistoryView: () => void
4242
}
4343

44+
// Function to clean up markdown escape characters
45+
function cleanupMarkdownEscapes(markdown: string): string {
46+
return (
47+
markdown
48+
// Handle underscores and asterisks (single or multiple)
49+
.replace(/\\([_*]+)/g, "$1")
50+
51+
// Handle angle brackets (for generics and XML)
52+
.replace(/\\([<>])/g, "$1")
53+
54+
// Handle backticks (for code)
55+
.replace(/\\(`)/g, "$1")
56+
57+
// Handle other common markdown special characters
58+
.replace(/\\([[\]()#.!])/g, "$1")
59+
60+
// Fix multiple consecutive backslashes
61+
.replace(/\\{2,}([_*`<>[\]()#.!])/g, "$1")
62+
)
63+
}
64+
4465
async function convertHtmlToMarkdown(html: string) {
4566
// Process the HTML to Markdown
4667
const result = await unified()
@@ -55,10 +76,14 @@ async function convertHtmlToMarkdown(html: string) {
5576
rule: "-", // Use - for horizontal rules
5677
ruleSpaces: false, // No spaces in horizontal rules
5778
fences: true,
79+
escape: false,
80+
entities: false,
5881
})
5982
.process(html)
6083

61-
return String(result)
84+
const md = String(result)
85+
// Apply comprehensive cleanup of escape characters
86+
return cleanupMarkdownEscapes(md)
6287
}
6388

6489
export const MAX_IMAGES_PER_MESSAGE = 20 // Anthropic limits to 20 images
@@ -120,7 +145,6 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie
120145

121146
// Convert HTML to Markdown
122147
const markdown = await convertHtmlToMarkdown(selectedHtml)
123-
124148
vscode.postMessage({ type: "copyToClipboard", text: markdown })
125149
e.preventDefault()
126150
}

0 commit comments

Comments
 (0)