The best way to control Claude Code, Codex and more from any computer or phone
fix(mobile): Windows image paths and non-ASCII file links open like desktop (#25802)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: amv146 <39172404+amv146@users.noreply.github.com>
Theo Browne committed
Oct 27, 2026 at 01:12 UTC
1a4f3c4a3c29d5cb4fb34308dc2e959b6de347c1
7 files changed
+106
-17
apps/mobile/src/lib/markdownDocument.ts
+54
-4
@@ -1,7 +1,8 @@
1
import type { Root, RootContent } from "mdast";
2
-import { unified } from "unified";
2
+import { unified, type Processor } from "unified";
3
import remarkParse from "remark-parse";
4
import remarkGfm from "remark-gfm";
5
+import { isWindowsAbsolutePath } from "@t3tools/shared/path";
6
7
const parser = unified().use(remarkParse).use(remarkGfm);
8
export type MarkdownNode = Root | RootContent;
@@ -382,13 +383,62 @@ export function markdownWithTableBreaks(markdown: string): string {
383
return transformNativeMarkdown(markdown, undefined, true);
384
}
385
386
+// `>` covers a destination continued on a blockquote line.
387
+const WINDOWS_DESTINATION = /\](?:\(|:)[\s>]*<?(?:[A-Za-z]:[\\/]|\\\\)/;
388
+
389
+interface DestinationToken {
390
+ readonly start: { readonly offset: number };
391
+ readonly end: { readonly offset: number };
392
+}
393
+
394
+/**
395
+ * Markdown reads `C:\work\.t3` as `C:\work.t3`. Web keeps authored Windows destinations
396
+ * literally (see `remarkKeepWindowsPaths` in shared), so escape their backslashes to give
397
+ * both parsers here the same path. `\&` stays an escape, as `markdownWithHtml` emits it.
398
+ * Expects authored Markdown: already escaped output would be escaped twice.
399
+ */
400
+function markdownWithWindowsPathDestinations(markdown: string): string {
401
+ // Skips the extra parse for the common message that has no Windows destination.
402
+ if (!WINDOWS_DESTINATION.test(markdown)) return markdown;
403
+ const edits: MarkdownEdit[] = [];
404
+ function record(
405
+ this: { resume(): string; sliceSerialize(token: DestinationToken): string },
406
+ token: DestinationToken,
407
+ ) {
408
+ this.resume();
409
+ const authored = this.sliceSerialize(token);
410
+ if (!isWindowsAbsolutePath(authored) || !authored.includes("\\") || /[<>]/.test(authored))
411
+ return;
412
+ const start = token.start.offset;
413
+ const end = token.end.offset;
414
+ const escaped = authored.replace(/\\(?!&)/g, "\\\\");
415
+ // A bare destination ends at an unescaped `)`, so wrap it to keep `\)` inside.
416
+ const angled = markdown[start - 1] === "<";
417
+ edits.push({ start, end, content: angled ? escaped : `<${escaped}>` });
418
+ }
419
+ unified()
420
+ .use(remarkParse)
421
+ .use(remarkGfm)
422
+ .use(function (this: Processor) {
423
+ (this.data().fromMarkdownExtensions ??= []).push({
424
+ exit: { resourceDestinationString: record, definitionDestinationString: record },
425
+ });
426
+ })
427
+ .parse(markdown);
428
+ return applyMarkdownEdits(markdown, edits);
429
+}
430
+
431
+// HTML wrappers can expose Markdown that wasn't in the first AST, so normalize them first.
432
+export function markdownForNativeParsing(markdown: string): string {
433
+ return markdownWithWindowsPathDestinations(markdownWithHtml(markdown));
434
+}
435
+
436
export function parseMarkdownDocument(markdown: string): Root {
386
- return parser.parse(markdownWithHtml(markdown));
437
+ return parser.parse(markdownForNativeParsing(markdown));
438
}
439
440
export function markdownForNativeRendering(markdown: string, fileLink: RegExp): string {
390
- // HTML wrappers can expose Markdown that wasn't in the first AST, so normalize them first.
391
- return transformNativeMarkdown(markdownWithHtml(markdown), fileLink, true);
441
+ return transformNativeMarkdown(markdownForNativeParsing(markdown), fileLink, true);
442
}
443
444
/** Native media slots only cover standalone images; nested file embeds must become links. */
apps/mobile/src/lib/markdownHtml.test.ts
+34
@@ -1,5 +1,6 @@
1
import { describe, expect, it } from "vite-plus/test";
2
import {
3
+ markdownForNativeRendering,
4
markdownHtmlContent,
5
markdownWithHtml,
6
markdownWithFileEmbeds,
@@ -9,6 +10,7 @@ import {
10
import { markdownImageSources } from "./markdownImageSources";
11
import { markdownFileEmbedLabel, resolveMarkdownMediaPreview } from "./markdownMedia";
12
import { resolveMarkdownLinkPresentation } from "./markdownLinks";
13
+import { ENRICHED_INLINE_FILE_LINK_REGEX } from "./enrichedLinkPresentation";
14
import { EnvironmentId, ThreadId } from "@t3tools/contracts";
15
import { parseMarkdown } from "react-native-enriched-markdown/src/web/parseMarkdown";
16
@@ -296,3 +298,35 @@ describe("file embeds in native thread and file Markdown", () => {
298
expect(converted.fileHrefs.has(href)).toBe(true);
299
});
300
});
301
+
302
+describe("Windows paths in native Markdown", () => {
303
+ // regression: #23722 Markdown escapes ate the separator before `.t3` and `_build`
304
+ it("keeps backslashes in Windows image and link destinations", async () => {
305
+ const image = String.raw`C:\work\.t3\_build\shot.png`;
306
+ const link = String.raw`\\server\share\.t3\notes.md`;
307
+ const markdown = [
308
+ ``,
309
+ String.raw`b.png)`,
310
+ `[notes](<${link}>)`,
311
+ `<img src="${image}">`,
312
+ String.raw``,
313
+ String.raw`<img src="C:\R&D\.t3\b.png">`,
314
+ "> ",
315
+ ].join("\n\n");
316
+
317
+ const native = await parseMarkdown(
318
+ markdownForNativeRendering(markdown, ENRICHED_INLINE_FILE_LINK_REGEX),
319
+ );
320
+ const urls: string[] = [];
321
+ const collect = (node: { attributes?: { url?: string }; children?: unknown[] }) => {
322
+ if (node.attributes?.url) urls.push(node.attributes.url);
323
+ node.children?.forEach((child) => collect(child as typeof node));
324
+ };
325
+ collect(native);
326
+ const paren = String.raw`C:\a\)b.png`;
327
+ const amp = String.raw`C:\R&D\.t3\a&b.png`;
328
+ const htmlAmp = String.raw`C:\R&D\.t3\b.png`;
329
+ expect(urls).toEqual([image, paren, link, image, amp, htmlAmp, image]);
330
+ expect(markdownImageSources(markdown)).toEqual([image, paren, amp, htmlAmp]);
331
+ });
332
+});
apps/mobile/src/lib/markdownInlineFileLinks.test.ts
+1
-2
@@ -7,7 +7,6 @@ import { ENRICHED_INLINE_FILE_LINK_REGEX } from "./enrichedLinkPresentation";
7
import {
8
markdownForNativeRendering,
9
markdownWithInlineFileLinks,
10
- parseMarkdownDocument,
10
markdownWithHtml,
11
} from "./markdownDocument";
12
@@ -87,7 +86,7 @@ describe("inline code that names a file", () => {
86
87
it("links to the exact path when it holds backslashes or ampersands", () => {
88
for (const path of ["C:\\repo\\_private\\file.ts", "./src/a©.ts", "./src/[id].ts"]) {
90
- const paragraph = parseMarkdownDocument(rewrite(`\`${path}\``)).children[0];
89
+ const paragraph = parser.parse(rewrite(`\`${path}\``)).children[0];
90
const link = paragraph?.type === "paragraph" ? paragraph.children[0] : undefined;
91
expect(link?.type === "link" && link.url).toBe(path);
92
expect(
apps/mobile/src/lib/markdownLinks.ts
+1
-5
@@ -265,11 +265,7 @@ export function resolveMarkdownLinkPresentation(href: string): MarkdownLinkPrese
265
}
266
} catch {}
267
268
- const target =
269
- parseMarkdownFileLink(normalized) ??
270
- (/^(?:[A-Za-z0-9._-]+(?: +[A-Za-z0-9._-]+)*\/)+$/.test(normalized)
271
- ? { path: normalized }
272
- : null);
268
+ const target = parseMarkdownFileLink(normalized);
269
if (target) {
270
return {
271
kind: "file",
apps/mobile/src/native/EnrichedMarkdownText.tsx
+2
-2
@@ -7,7 +7,7 @@ import {
7
import {
8
markdownForNativeRendering,
9
markdownWithFileEmbeds,
10
- markdownWithHtml,
10
+ markdownForNativeParsing,
11
markdownWithInlineFileLinks,
12
markdownWithTableBreaks,
13
} from "../lib/markdownDocument";
@@ -165,7 +165,7 @@ export function MobileEnrichedMarkdownText(props: SelectableMarkdownTextProps) {
165
};
166
}
167
const content = markdownWithInlineFileLinks(
168
- markdownWithHtml(props.markdown),
168
+ markdownForNativeParsing(props.markdown),
169
ENRICHED_INLINE_FILE_LINK_REGEX,
170
);
171
const files = markdownWithFileEmbeds(content, fileEmbedLabel);
packages/shared/src/markdownLinks.test.ts
+9
@@ -54,6 +54,15 @@ describe("parseMarkdownFileLink", () => {
54
expect(parseMarkdownFileLink("docs/My%20Folder/")?.path).toBe("docs/My Folder/");
55
});
56
57
+ // regression: #16096 relative links with non-ASCII names open as files
58
+ it("recognizes relative paths with non-ASCII names", () => {
59
+ expect(parseMarkdownFileLink("pastexam/線性代數/exam_易志偉.pdf")?.path).toBe(
60
+ "pastexam/線性代數/exam_易志偉.pdf",
61
+ );
62
+ expect(parseMarkdownFileLink("Résumé%20final.pdf")?.path).toBe("Résumé final.pdf");
63
+ expect(parseMarkdownFileLink("資料.備份")?.path).toBe("資料.備份");
64
+ });
65
+
66
it("accepts conventional extensionless names with or without a position", () => {
67
expect(parseMarkdownFileLink("Makefile")).toEqual({ path: "Makefile" });
68
expect(parseMarkdownFileLink("Dockerfile:8")).toEqual({ path: "Dockerfile", line: 8 });
packages/shared/src/markdownLinks.ts
+5
-4
@@ -14,13 +14,14 @@ import {
14
15
const RELATIVE_PATH_PREFIX_PATTERN = /^(~\/|\.{1,2}\/)/;
16
17
-// The final segment is optional so an explicit folder link may end in `/`
18
-// (`patches/`, `docs/My Folder/`). A bare name with no slash still fails.
17
+// Names may use any script (`線性代數/考試.pdf`). The final segment is optional so an
18
+// explicit folder link may end in `/` (`patches/`, `docs/My Folder/`). A bare name with no
19
+// slash still fails.
20
const RELATIVE_FILE_PATH_PATTERN =
20
- /^(?:[A-Za-z0-9._-]+(?: +[A-Za-z0-9._-]+)*\/)+(?:[A-Za-z0-9._-]+(?: +[A-Za-z0-9._-]+)*(?::\d+){0,2})?$/;
21
+ /^(?:[\p{L}\p{M}\p{N}._-]+(?: +[\p{L}\p{M}\p{N}._-]+)*\/)+(?:[\p{L}\p{M}\p{N}._-]+(?: +[\p{L}\p{M}\p{N}._-]+)*(?::\d+){0,2})?$/u;
22
23
const RELATIVE_FILE_NAME_PATTERN =
23
- /^[A-Za-z0-9._-]+(?: +[A-Za-z0-9._-]+)*\.[A-Za-z0-9_-]+(?::\d+){0,2}$/;
24
+ /^[\p{L}\p{M}\p{N}._-]+(?: +[\p{L}\p{M}\p{N}._-]+)*\.[\p{L}\p{M}\p{N}_-]+(?::\d+){0,2}$/u;
25
26
const EXTERNAL_SCHEME_PATTERN = /^([A-Za-z][A-Za-z0-9+.-]*):(.*)$/;
27