summaryrefslogtreecommitdiffhomepage
path: root/packages
diff options
context:
space:
mode:
authorDavid Hill <[email protected]>2025-12-16 11:50:23 +0000
committerDavid Hill <[email protected]>2025-12-16 11:50:23 +0000
commit6c1a1a77b762dbde875f0325ca43903c2c0840b6 (patch)
tree5a3cf0cdf1e1b9594383db32229a8c2f30133981 /packages
parent2e21c623204df104af2f7cd64d5b9344c9e2c99c (diff)
downloadopencode-6c1a1a77b762dbde875f0325ca43903c2c0840b6.tar.gz
opencode-6c1a1a77b762dbde875f0325ca43903c2c0840b6.zip
fix: strip parentheses from file paths generated by llm
Diffstat (limited to 'packages')
-rw-r--r--packages/ui/src/components/markdown.tsx8
-rw-r--r--packages/web/src/components/share/content-markdown.tsx8
2 files changed, 14 insertions, 2 deletions
diff --git a/packages/ui/src/components/markdown.tsx b/packages/ui/src/components/markdown.tsx
index 071132e80..7524f8921 100644
--- a/packages/ui/src/components/markdown.tsx
+++ b/packages/ui/src/components/markdown.tsx
@@ -7,6 +7,12 @@ function strip(text: string): string {
return match ? match[2] : text
}
+function removeParensAroundFileRefs(text: string): string {
+ // Remove parentheses around inline code that looks like a file reference
+ // Matches: (`path/to/file.ext`) or (`path/to/file.ext:1-10`) or (`file.ext:42`)
+ return text.replace(/\(\s*(`[^`]+\.[a-zA-Z0-9]+(?::\d+(?:-\d+)?)?`)\s*\)/g, "$1")
+}
+
export function Markdown(
props: ComponentProps<"div"> & {
text: string
@@ -17,7 +23,7 @@ export function Markdown(
const [local, others] = splitProps(props, ["text", "class", "classList"])
const marked = useMarked()
const [html] = createResource(
- () => strip(local.text),
+ () => removeParensAroundFileRefs(strip(local.text)),
async (markdown) => {
return marked.parse(markdown)
},
diff --git a/packages/web/src/components/share/content-markdown.tsx b/packages/web/src/components/share/content-markdown.tsx
index 69cde82b2..db3f4a516 100644
--- a/packages/web/src/components/share/content-markdown.tsx
+++ b/packages/web/src/components/share/content-markdown.tsx
@@ -29,7 +29,7 @@ interface Props {
}
export function ContentMarkdown(props: Props) {
const [html] = createResource(
- () => strip(props.text),
+ () => removeParensAroundFileRefs(strip(props.text)),
async (markdown) => {
return markedWithShiki.parse(markdown)
},
@@ -65,3 +65,9 @@ function strip(text: string): string {
const match = text.match(wrappedRe)
return match ? match[2] : text
}
+
+function removeParensAroundFileRefs(text: string): string {
+ // Remove parentheses around inline code that looks like a file reference
+ // Matches: (`path/to/file.ext`) or (`path/to/file.ext:1-10`) or (`file.ext:42`)
+ return text.replace(/\(\s*(`[^`]+\.[a-zA-Z0-9]+(?::\d+(?:-\d+)?)?`)\s*\)/g, "$1")
+}