Skip to content

Commit 9938750

Browse files
sharull9claude
andcommitted
fix(mobile): keep bare thread links out of code, definitions, and URLs
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 45e8936 commit 9938750

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ describe("thread links", () => {
112112
expect(
113113
relabelThreadLinks("See (t3-thread://v1/t1), then t3-thread://v2/there/t1.", local, title),
114114
).toBe("See ([Here](t3-thread://v1/t1)), then [There](t3-thread://v2/there/t1).");
115-
for (const marker of ["*", "**", "_", "__", '"', "'"]) {
115+
for (const marker of ["*", "**", "_", "__", "~~", '"', "'"]) {
116116
const emphasized = `${marker}t3-thread://v2/there/t1${marker}`;
117117
expect(threadLinkRefs(emphasized, local)).toEqual([ref("there", "t1")]);
118118
expect(relabelThreadLinks(emphasized, local, title)).toBe(
@@ -150,6 +150,10 @@ describe("thread links", () => {
150150
"Literal `t3-thread://v2/local/t1`",
151151
"Literal `first line\nt3-thread://v2/local/t1`",
152152
"[open](https://example.com/?redirect=t3-thread://v1/t1)",
153+
"https://example.com/?redirect=t3-thread://v1/t1",
154+
"[Open][ref]",
155+
"",
156+
"[ref]: t3-thread://v2/local/t1",
153157
].join("\n");
154158
expect(relabelThreadLinks(markdown, local, () => "New")).toBe(
155159
[
@@ -161,8 +165,15 @@ describe("thread links", () => {
161165
"Literal `t3-thread://v2/local/t1`",
162166
"Literal `first line\nt3-thread://v2/local/t1`",
163167
"[open](https://example.com/?redirect=t3-thread://v1/t1)",
168+
"https://example.com/?redirect=t3-thread://v1/t1",
169+
"[Open][ref]",
170+
"",
171+
"[ref]: t3-thread://v2/local/t1",
164172
].join("\n"),
165173
);
174+
expect(threadLinkRefs("Stray `\n\n[old](t3-thread://v1/t1) `code`", local)).toEqual([
175+
ref("local", "t1"),
176+
]);
166177
expect(threadLinkRefs("`first line\nt3-thread://v2/local/t1`", local)).toEqual([]);
167178
expect(
168179
threadLinkRefs("[open](https://example.com/?redirect=t3-thread://v1/t1)", local),

‎packages/shared/src/threadLinks.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const V1_PREFIX = `${THREAD_LINK_PROTOCOL}://v1/`;
77
const V2_PREFIX = `${THREAD_LINK_PROTOCOL}://v2/`;
88
// Code comes first in the alternation so a link written inside a code span or fence is skipped.
99
const THREAD_LINK_OUTSIDE_CODE =
10-
/(?<fence>(`{3,}|~{3,})[\s\S]*?(?:\2|$))|(?<span>(`+)[\s\S]*?\4)|\[(?<label>[^\]\n]*)\]\((?<href>t3-thread:\/\/v[12]\/[^\s)]+)\)|\[[^\]\n]*\]\([^\n)]*\)|<(?<autolink>t3-thread:\/\/v[12]\/[^\s<>]+)>|(?<![a-zA-Z0-9/])(?<bare>t3-thread:\/\/v[12]\/[^\s<>`"'\])]*[^\s<>`"'*_\]).,!?;:])/g;
10+
/(?<fence>(`{3,}|~{3,})[\s\S]*?(?:\2|$))|(?<span>(`+)(?:[^\n]|\n(?![ \t\r]*\n))*?\4)|(?:^|\n) {0,3}\[[^\]\n]+\]:[^\n]*|\[(?<label>[^\]\n]*)\]\((?<href>t3-thread:\/\/v[12]\/[^\s)]+)\)|\[[^\]\n]*\]\([^\n)]*\)|<(?<autolink>t3-thread:\/\/v[12]\/[^\s<>]+)>|(?<![^\s(*_~"'])(?<bare>t3-thread:\/\/v[12]\/[^\s<>`"'\])]*[^\s<>`"'*_~\]).,!?;:])/g;
1111

1212
const decodeThreadId = Schema.decodeUnknownOption(ThreadId);
1313
const decodeEnvironmentId = Schema.decodeUnknownOption(EnvironmentId);

0 commit comments

Comments
 (0)