Skip to content

Commit 301e174

Browse files
committed
fix(chat): preserve complete paths through prose link rendering
1 parent 04ba72e commit 301e174

4 files changed

Lines changed: 12 additions & 3 deletions

File tree

‎apps/mobile/src/lib/markdownDocument.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,11 +346,13 @@ function transformNativeMarkdown(
346346
if (raw !== node.value) return;
347347
for (const { index, path } of absoluteFilePathMatches(raw)) {
348348
const escaped = path.replace(/[\\[\]&]/g, "\\$&");
349-
edits.push({
349+
const edit = {
350350
start: start + index,
351351
end: start + index + path.length,
352352
content: `[${escaped}](<${escaped}>)`,
353-
});
353+
};
354+
edits.push(edit);
355+
fileEdits.push(edit);
354356
}
355357
} else if (node.type !== "link" && node.type !== "linkReference" && "children" in node)
356358
node.children.forEach((child, index) => {

‎apps/mobile/src/lib/markdownInlineFileLinks.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ describe("inline code that names a file", () => {
7272
const path =
7373
"/tmp/claude-1000/-home-user--t3-worktrees-app-t3-abc123/session/scratchpad/notes.md";
7474
expect(rewrite(`Saved to ${path}.`)).toBe(`Saved to [${path}](<${path}>).`);
75+
expect(
76+
markdownForNativeRendering(
77+
"Intro /tmp/notes.md\n| a | c |\n|---|---|\n| `./a\\|b.ts` | b |",
78+
ENRICHED_INLINE_FILE_LINK_REGEX,
79+
),
80+
).toContain("[/tmp/notes.md](</tmp/notes.md>)");
7581
const escaped = String.raw`See /tmp/a\_b.md.`;
7682
expect(rewrite(escaped)).toBe(escaped);
7783
expect(rewrite("See `/tmp/claude-1000/...`.")).toBe("See `/tmp/claude-1000/...`.");

‎packages/shared/src/markdownLinks.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ export function isWindowsDrivePathHref(href: string): boolean {
435435

436436
export function absoluteFilePathMatches(text: string): Array<{ index: number; path: string }> {
437437
const paths: Array<{ index: number; path: string }> = [];
438-
for (const match of text.matchAll(/(^|[\s("'])(\/[^\s<>"'`[\]]+)/g)) {
438+
for (const match of text.matchAll(/(^|[\s("'])(\/[^\s<>"'`]+)/g)) {
439439
if (/(?:^|\/)(?:\.{3,}|…)(?:\/|[.,;!?:)]*$)/.test(match[2]!)) continue;
440440
const path = match[2]!.replace(/[.,;!?:)]+$/, "");
441441
if (!parseMarkdownFileLink(path)) continue;

‎packages/shared/src/markdownPipeline.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ it.each([
308308
return urls;
309309
};
310310
expect(links(`Saved to ${path}.`)).toEqual([path]);
311+
expect(links("See /tmp/app/[id]/page.tsx.")).toEqual(["/tmp/app/[id]/page.tsx"]);
311312
expect(links(`See (${path}:12).`)).toEqual([`${path}:12`]);
312313
expect(links(`**${path}**`)).toEqual([path]);
313314
expect(links(`Saved to ${path} and /tmp/other.txt.`)).toEqual([path, "/tmp/other.txt"]);

0 commit comments

Comments
 (0)