Skip to content

Commit ad35b29

Browse files
fix(mobile): inline-code paths with emphasis characters keep their file name chip
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent ca83d4d commit ad35b29

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

‎apps/mobile/src/native/useEnrichedLinkVariants.test.tsx‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,10 @@ it("keeps the file name chip for a file URL autolink", async () => {
9393

9494
expect(content[url]?.label).toBe("guide.md");
9595
});
96+
97+
it("keeps the file name chip for an inline-code path whose underscores parse as emphasis", async () => {
98+
const url = "src/__tests__/a.test.ts";
99+
const content = await pillContent([{ url, label: "src/tests/a.test.ts", title: "" }]);
100+
101+
expect(content[url]?.label).toBe("a.test.ts");
102+
});

‎apps/mobile/src/native/useEnrichedLinkVariants.ts‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ export function withChipIcon(
6262
: customization;
6363
}
6464

65+
// Autolinks and inline-code paths link their own text, but the parser keeps backslash escapes
66+
// (preserveWindowsPaths) and drops emphasis markers, e.g. `src/__tests__/a.ts` reads src/tests/a.ts.
67+
const LINK_TEXT_MARKUP = /[\\*_~$|^=]/g;
68+
function isLinkTextOfUrl(label: string, url: string) {
69+
return label.replace(LINK_TEXT_MARKUP, "") === url.replace(LINK_TEXT_MARKUP, "");
70+
}
71+
6572
function presentation(
6673
url: string,
6774
props: Pick<SelectableMarkdownTextProps, "linkCustomization" | "skills" | "textStyle">,
@@ -82,12 +89,8 @@ function presentation(
8289
if (link.kind === "file")
8390
return {
8491
// Without a label the native pill shows the authored text, e.g. [the setup steps](docs/guide.md).
85-
// An autolink's text is its URL. preserveWindowsPaths keeps backslash escapes in link text.
8692
label: authoredLabels.every(
87-
(label) =>
88-
label === url ||
89-
isMarkdownFileLinkLabel(label, link.href) ||
90-
isMarkdownFileLinkLabel(label.replace(/\\(.)/g, "$1"), link.href),
93+
(label) => isMarkdownFileLinkLabel(label, link.href) || isLinkTextOfUrl(label, url),
9194
)
9295
? link.label
9396
: undefined,

0 commit comments

Comments
 (0)