Skip to content

Commit b4dff4e

Browse files
authored
Merge pull request RooCodeInc#1650 from cline/double_underscore_fix
Double underscore fix
2 parents f108f20 + 9640a5f commit b4dff4e

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

webview-ui/src/components/common/MarkdownBlock.tsx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,44 @@ const remarkUrlToLink = () => {
5050
}
5151
}
5252

53+
/**
54+
* Custom remark plugin that prevents filenames with extensions from being parsed as bold text
55+
* For example: __init__.py should not be rendered as bold "init" followed by ".py"
56+
* Solves https://github.com/cline/cline/issues/1028
57+
*/
58+
const remarkPreventBoldFilenames = () => {
59+
return (tree: any) => {
60+
visit(tree, "strong", (node: any, index: number | undefined, parent: any) => {
61+
// Only process if there's a next node (potential file extension)
62+
if (!parent || typeof index === "undefined" || index === parent.children.length - 1) return
63+
64+
const nextNode = parent.children[index + 1]
65+
66+
// Check if next node is text and starts with . followed by extension
67+
if (nextNode.type !== "text" || !nextNode.value.match(/^\.[a-zA-Z0-9]+/)) return
68+
69+
// If the strong node has multiple children, something weird is happening
70+
if (node.children?.length !== 1) return
71+
72+
// Get the text content from inside the strong node
73+
const strongContent = node.children?.[0]?.value
74+
if (!strongContent || typeof strongContent !== "string") return
75+
76+
// Validate that the strong content is a valid filename
77+
if (!strongContent.match(/^[a-zA-Z0-9_-]+$/)) return
78+
79+
// Combine into a single text node
80+
const newNode = {
81+
type: "text",
82+
value: `__${strongContent}__${nextNode.value}`,
83+
}
84+
85+
// Replace both nodes with the combined text node
86+
parent.children.splice(index, 2, newNode)
87+
})
88+
}
89+
}
90+
5391
const StyledMarkdown = styled.div`
5492
pre {
5593
background-color: ${CODE_BLOCK_BG_COLOR};
@@ -160,6 +198,7 @@ const MarkdownBlock = memo(({ markdown }: MarkdownBlockProps) => {
160198
const { theme } = useExtensionState()
161199
const [reactContent, setMarkdown] = useRemark({
162200
remarkPlugins: [
201+
remarkPreventBoldFilenames,
163202
remarkUrlToLink,
164203
() => {
165204
return (tree) => {

0 commit comments

Comments
 (0)