Skip to content

Commit 8bfb258

Browse files
fix(shared): preserve reference link labels that display a thread URL (#45430)
Co-authored-by: SAPHID <saphid@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
1 parent 54a42b2 commit 8bfb258

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,18 @@ describe("hosted thread links", () => {
691691
`[Review][thread]\n\n[thread]: ${hosted}\n\nSee [Demo](t3-thread://v2/local/demo)`,
692692
);
693693

694+
for (const markdown of [
695+
`[${hosted}][site]\n\n[site]: https://example.com`,
696+
`![${hosted}][site]\n\n[site]: https://example.com`,
697+
]) {
698+
expect(relabelThreadLinks(markdown, local, () => "Demo")).toBe(markdown);
699+
expect(threadLinkRefs(markdown, local)).toEqual([]);
700+
}
701+
const labelWithLiveAfter = `[${hosted}][site]\n\n[site]: https://example.com\n\n${hosted}`;
702+
expect(relabelThreadLinks(labelWithLiveAfter, local, () => "Demo")).toBe(
703+
`[${hosted}][site]\n\n[site]: https://example.com\n\n[Demo](t3-thread://v2/local/demo)`,
704+
);
705+
694706
const paragraphContinuation = `Intro\n[thread]: ${hosted}`;
695707
expect(relabelThreadLinks(paragraphContinuation, local, () => "Demo")).toBe(
696708
`Intro\n[thread]: [Demo](t3-thread://v2/local/demo)`,

‎packages/shared/src/threadLinks.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,13 @@ function parsedLinkSource(markdown: string) {
403403
const node = pending.pop()!;
404404
const start = node.position?.start.offset;
405405
const end = node.position?.end.offset;
406-
if (node.type === "code" || node.type === "inlineCode" || node.type === "definition") {
406+
if (
407+
node.type === "code" ||
408+
node.type === "inlineCode" ||
409+
node.type === "definition" ||
410+
node.type === "linkReference" ||
411+
node.type === "imageReference"
412+
) {
407413
if (start !== undefined && end !== undefined) skippedRanges?.push({ start, end });
408414
continue;
409415
}

0 commit comments

Comments
 (0)