Open History to see the last commit
1import { expect, it } from "vite-plus/test";
2import { type PluggableList, unified } from "unified";
3import rehypeRaw from "rehype-raw";
4import remarkParse from "remark-parse";
5import remarkRehype from "remark-rehype";
6import type { Root, RootContent } from "mdast";
7import {
8 CHAT_MARKDOWN_REHYPE_PLUGINS,
9 CHAT_MARKDOWN_REMARK_PLUGINS,
10 CHAT_MARKDOWN_REMARK_PLUGINS_WITH_BREAKS,
11 remarkAssistantInsights,
12 remarkEnableOrderedListNumbers,
13} from "./markdownPipeline.ts";
14
15it.each([
16 ["default", CHAT_MARKDOWN_REMARK_PLUGINS],
17 ["with breaks", CHAT_MARKDOWN_REMARK_PLUGINS_WITH_BREAKS],
18] as const)("preserves trailing underscores and tildes in bare URLs (%s)", (_, plugins) => {
19 const processor = unified().use(remarkParse).use(plugins);
20 const shape = (node: Root | RootContent): string => {
21 if (node.type === "text") return node.value;
22 if (node.type === "inlineCode") return `\`${node.value}\``;
23 if (node.type === "code") return `\`\`\`${node.value}\`\`\``;
24 const children = "children" in node ? node.children.map(shape).join("") : "";
25 if (node.type === "link") return `[${children}](${node.url})`;
26 if (node.type === "linkReference") return `[${children}][${node.identifier}]`;
27 if (node.type === "emphasis") return `*${children}*`;
28 if (node.type === "strong") return `**${children}**`;
29 if (node.type === "delete") return `~~${children}~~`;
30 return children;
31 };
32 const link = (url: string) => `[${url}](${/^www\./i.test(url) ? `http://${url}` : url})`;
33 for (const url of [
34 "https://x.com/dimasike_",
35 "http://example.com/name__",
36 "HTTPS://example.com/name_",
37 "https://example.com/a_(b)_",
38 "https://example.com/?name=value_",
39 "https://example.com/#section_",
40 "https://example.com/a_?name=value_#section_",
41 "https://example.com/name~",
42 "https://example.com/name~~",
43 "https://example.com/name_~",
44 "https://example.com/name~_",
45 "https://example.com/name__~~_",
46 "https://example.com/?name=value~",
47 "https://example.com/#section~",
48 "www.example.com/name_",
49 "www.example.com/name~_",
50 "WWW.example.com/name~~",
51 "https://example.com/name-",
52 "https://example.com/name/",
53 "https://example.com/name%5F",
54 "https://example.com/name%7E",
55 ]) {
56 for (const punctuation of ["", ".", ",", "!", "?", ":", ";", ")", "]", '"']) {
57 const markdown = `See ${url}${punctuation} next`;
58 expect(shape(processor.runSync(processor.parse(markdown), markdown) as Root), markdown).toBe(
59 `See ${link(url)}${punctuation} next`,
60 );
61 }
62 }
63 for (const [markdown, expected] of [
64 ["*https://x.com/dimasike_*", `*${link("https://x.com/dimasike_")}*`],
65 ["**https://x.com/dimasike_**", `**${link("https://x.com/dimasike_")}**`],
66 ["_https://x.com/dimasike_", `*${link("https://x.com/dimasike")}*`],
67 ["__https://x.com/dimasike__", `**${link("https://x.com/dimasike")}**`],
68 ["~~https://example.com/name_~~", `~~${link("https://example.com/name_")}~~`],
69 ["~~https://example.com/name~~", `~~${link("https://example.com/name")}~~`],
70 ["~https://example.com/name~", `~~${link("https://example.com/name")}~~`],
71 ["*https://example.com/name~*", `*${link("https://example.com/name~")}*`],
72 ["_https://example.com/name~_", `*${link("https://example.com/name~")}*`],
73 ["[test](https://example.com/name~)", "[test](https://example.com/name~)"],
74 ["[https://x.com/a](https://x.com/a)~_", `${link("https://x.com/a")}~_`],
75 ["<https://x.com/a>~_", `${link("https://x.com/a")}~_`],
76 ["[test][ref]~_\n\n[ref]: https://x.com/a~_", "[test][ref]~_"],
77 ["`https://example.com/name~_`", "`https://example.com/name~_`"],
78 ["```\nhttps://example.com/name~_\n```", "```https://example.com/name~_```"],
79 ["https\\://example.com/name~_", link("https://example.com/name~_")],
80 ["https://example.com/name. _~", `${link("https://example.com/name")}. _~`],
81 ["Mail person@example.com_", "Mail person@example.com_"],
82 ["Mail person@example.com ~_", "Mail [person@example.com](mailto:person@example.com) ~_"],
83 ["[test](https://x.com/dimasike_)", "[test](https://x.com/dimasike_)"],
84 ["[https://x.com/a](https://x.com/a)_", `${link("https://x.com/a")}_`],
85 ["<https://x.com/a>_", `${link("https://x.com/a")}_`],
86 ["[test][ref]_\n\n[ref]: https://x.com/a_", "[test][ref]_"],
87 ["`https://x.com/dimasike_`", "`https://x.com/dimasike_`"],
88 ["```\nhttps://x.com/dimasike_\n```", "```https://x.com/dimasike_```"],
89 ["https://x.com/a. _", `${link("https://x.com/a")}. _`],
90 ["https\\://x.com/dimasike_", link("https://x.com/dimasike_")],
91 ["https://x.com/a\\_", link("https://x.com/a\\_")],
92 ["https://x.com/a_", `${link("https://x.com/a_")};`],
93 [
94 "https://x.com/a_ https://x.com/b_",
95 `${link("https://x.com/a_")} ${link("https://x.com/b_")}`,
96 ],
97 ] as const) {
98 expect(shape(processor.runSync(processor.parse(markdown), markdown) as Root), markdown).toBe(
99 expected,
100 );
101 }
102 for (const url of ["https://x.com/dimasike_", "www.example.com/name~_"]) {
103 const markdown = `${url}, next`;
104 const boundary = { line: 1, column: url.length + 1, offset: url.length };
105 expect(processor.runSync(processor.parse(markdown), markdown)).toMatchObject({
106 children: [
107 {
108 children: [
109 {
110 type: "link",
111 url: /^www\./i.test(url) ? `http://${url}` : url,
112 position: { end: boundary },
113 children: [{ type: "text", value: url, position: { end: boundary } }],
114 },
115 { type: "text", value: ", next", position: { start: boundary } },
116 ],
117 },
118 ],
119 });
120 }
121});
122
123const insightRule = "─".repeat(20);
124const insightFence = (body: string, wrap = "") =>
125 [`${wrap}★ Insight ${insightRule}${wrap}`, body, `${wrap}${insightRule}${wrap}`].join("\n");
126
127it.each(["", "`"])("groups %j insight fences while preserving surrounding markdown", (wrap) => {
128 const markdown = [
129 "Before **bold** and [reference][src].",
130 "",
131 insightFence("- Also [reference][src].", wrap),
132 "",
133 "After.",
134 "",
135 '[src]:\n https://example.com\n "Source"',
136 ].join("\n");
137 const processor = unified()
138 .use(remarkParse)
139 .use(CHAT_MARKDOWN_REMARK_PLUGINS)
140 .use(remarkAssistantInsights)
141 .use(remarkRehype)
142 .use(CHAT_MARKDOWN_REHYPE_PLUGINS);
143 const tree = processor.runSync(processor.parse(markdown), markdown);
144 expect(
145 tree.children.filter((node) => node.type === "element").map((node) => node.tagName),
146 ).toEqual(["p", "blockquote", "p"]);
147 expect(
148 tree.children.find((node) => node.type === "element" && node.tagName === "blockquote"),
149 ).toMatchObject({ properties: { dataAlert: "insight" } });
150 expect(JSON.stringify(tree).match(/"href":"https:\/\/example.com"/g)).toHaveLength(2);
151 expect(JSON.stringify(tree)).toContain('"tagName":"strong"');
152 expect(JSON.stringify(tree)).not.toContain(insightRule);
153});
154
155it.each([
156 ["```text", "★ Insight " + insightRule, "literal", insightRule, "```"].join("\n"),
157 ["- ```text", " ★ Insight " + insightRule, " literal", " " + insightRule, " ```"].join("\n"),
158 [" ★ Insight " + insightRule, " literal", " " + insightRule].join("\n"),
159 ["Paragraph.", " ★ Insight " + insightRule, " literal", " " + insightRule].join("\n"),
160 ["`example", "★ Insight " + insightRule, "literal", insightRule, "`"].join("\n"),
161 insightFence("quoted")
162 .split("\n")
163 .map((line) => "> " + line)
164 .join("\n"),
165])("leaves literal and nested insight examples unchanged: %s", (markdown) => {
166 const processor = unified().use(remarkParse).use(remarkAssistantInsights);
167 const tree = processor.parse(markdown);
168 expect(processor.runSync(structuredClone(tree), markdown)).toEqual(tree);
169});
170
171it("groups streaming bodies and several insights without losing code or headings", () => {
172 const markdown = [
173 "## Setup",
174 "",
175 insightFence("```text\n" + insightRule + "\n```"),
176 "",
177 "## Setup",
178 "",
179 "★ Insight " + insightRule,
180 "Still **streaming**",
181 ].join("\n");
182 const processor = unified().use(remarkParse).use(remarkAssistantInsights);
183 const tree = processor.parse(markdown);
184 processor.runSync(tree, markdown);
185 expect(tree.children.map((node) => node.type)).toEqual([
186 "heading",
187 "blockquote",
188 "heading",
189 "blockquote",
190 ]);
191 expect(tree.children[1]).toMatchObject({ children: [{ type: "code", value: insightRule }] });
192 expect(tree.children[3]).toMatchObject({
193 children: [
194 { type: "paragraph", children: [{ type: "text", value: "Still " }, { type: "strong" }] },
195 ],
196 });
197});
198
199it("keeps reference definitions out of unfinished streaming code", () => {
200 const markdown = `[src]: https://example.com\n\n★ Insight ${insightRule}\n\`\`\`ts\nconst value = 1`;
201 const processor = unified().use(remarkParse).use(remarkAssistantInsights);
202 const tree = processor.parse(markdown);
203 processor.runSync(tree, markdown);
204 expect(tree.children.find((node) => node.type === "blockquote")).toMatchObject({
205 children: [{ type: "code", value: "const value = 1" }],
206 });
207});
208
209it("preserves footnotes and original code positions across a callout", () => {
210 const code = "```sh\necho hello\n```";
211 const markdown = ["Before[^n].", "", insightFence(code), "", "[^n]: Footnote."].join("\n");
212 const processor = unified()
213 .use(remarkParse)
214 .use(remarkAssistantInsights)
215 .use(CHAT_MARKDOWN_REMARK_PLUGINS);
216 const tree = processor.parse(markdown);
217 processor.runSync(tree, markdown);
218 expect(tree.children[0]).toMatchObject({
219 children: [
220 { type: "text", value: "Before" },
221 { type: "footnoteReference", identifier: "n" },
222 { type: "text", value: "." },
223 ],
224 });
225 expect(tree.children.at(-1)).toMatchObject({ type: "footnoteDefinition", identifier: "n" });
226 const note = tree.children.find((node) => node.type === "blockquote");
227 const block = note?.children[0];
228 expect(markdown.slice(block?.position?.start.offset, block?.position?.end.offset)).toBe(code);
229});
230
231it("preserves in-app thread links through the shared Markdown sanitizer", () => {
232 const processor = unified()
233 .use(remarkParse)
234 .use(CHAT_MARKDOWN_REMARK_PLUGINS)
235 .use(remarkRehype, { allowDangerousHtml: true })
236 .use(CHAT_MARKDOWN_REHYPE_PLUGINS);
237 const tree = processor.runSync(
238 processor.parse(
239 '[Open thread](t3-thread://v1/thread)\n\n<t3-thread://v2/environment/thread:a%3A1>\n\n<a href="javascript:alert(1)">Unsafe</a>',
240 ),
241 );
242 expect(tree.children[0]).toMatchObject({
243 tagName: "p",
244 children: [
245 {
246 tagName: "a",
247 properties: { href: "t3-thread://v1/thread" },
248 children: [{ type: "text", value: "Open thread" }],
249 },
250 ],
251 });
252 expect(tree.children[2]).toMatchObject({
253 tagName: "p",
254 children: [
255 {
256 tagName: "a",
257 properties: { href: "t3-thread://v2/environment/thread:a%3A1" },
258 children: [{ type: "text", value: "t3-thread://v2/environment/thread:a%3A1" }],
259 },
260 ],
261 });
262 expect(JSON.stringify(tree)).not.toContain("javascript:");
263});
264
265it("builds the tree rehype-raw builds for markdown without HTML", () => {
266 type Node = {
267 type: string;
268 tagName?: string;
269 value?: string;
270 position?: unknown;
271 data?: unknown;
272 children?: Node[];
273 };
274 // What the round trip changes that renders the same; see `needsHtmlParser`.
275 const comparable = (node: Node): Node => {
276 const { position, children, data, ...rest } = node;
277 const result: Node =
278 node.type === "text" || node.type === "root" ? rest : { ...rest, position, data };
279 if (!children) return result;
280 const merged: Node[] = [];
281 for (const child of children.map(comparable)) {
282 const last = merged.at(-1);
283 if (child.type === "text" && last?.type === "text") last.value += child.value ?? "";
284 else merged.push(child);
285 }
286 // Blank text inside a table moves in front of it; the JSX runtime drops it in tables.
287 const inTable = /^(?:table|thead|tbody|tfoot|tr)$/.test(node.tagName ?? "");
288 result.children = merged.filter(
289 (child, index) =>
290 child.type !== "text" ||
291 child.value?.trim() ||
292 !(inTable || merged[index + 1]?.tagName === "table"),
293 );
294 return result;
295 };
296 const tree = (rehypePlugins: typeof CHAT_MARKDOWN_REHYPE_PLUGINS, markdown: string) => {
297 const processor = unified()
298 .use(remarkParse)
299 .use(CHAT_MARKDOWN_REMARK_PLUGINS)
300 .use(remarkRehype, { allowDangerousHtml: true })
301 .use(rehypePlugins);
302 return comparable(processor.runSync(processor.parse(markdown)) as Node);
303 };
304 const [first, , ...rest] = CHAT_MARKDOWN_REHYPE_PLUGINS;
305 const withRaw = [first!, rehypeRaw, ...rest];
306 for (const markdown of [
307 "- [ ] open\n- [x] done\n\nNote[^1]\n\n[^1]: The note.",
308 "| a | b |\n| :- | -: |\n| `c` |  |\n\n```ts title=x\nconst a = 1;\n```",
309 // The HTML parser moves the footnote's link out of the label's link.
310 "[note[^x]](https://example.com)\n\n[^x]: text",
311 "**a** **b**\r\n> - | a |\r\n> | - |\r\n> | b |\r\n\n-\tx\n\n y",
312 ]) {
313 expect(tree(CHAT_MARKDOWN_REHYPE_PLUGINS, markdown)).toEqual(tree(withRaw, markdown));
314 }
315});
316
317it("keeps local editor file links but not other schemes through the shared Markdown sanitizer", () => {
318 const processor = unified()
319 .use(remarkParse)
320 .use(CHAT_MARKDOWN_REMARK_PLUGINS)
321 .use(remarkRehype, { allowDangerousHtml: true })
322 .use(CHAT_MARKDOWN_REHYPE_PLUGINS);
323 const tree = processor.runSync(
324 processor.parse(
325 [
326 "[cursor](cursor://file/Users/me/repo/file.md:3)",
327 "[code](vscode://file/Users/me/repo/file.md:3:7)",
328 "[insiders](vscode-insiders://file/Users/me/repo/file.md)",
329 "[unknown](foo://file/Users/me/repo/file.md)",
330 "[zed](zed://file/Users/me/repo/file.md)",
331 ].join(" "),
332 ),
333 );
334 type Node = { tagName?: string; properties?: { href?: string }; children?: Node[] };
335 const hrefs = ((tree.children[0] as Node).children ?? [])
336 .filter((node) => node.tagName === "a")
337 .map((node) => node.properties?.href);
338 expect(hrefs).toEqual([
339 "cursor://file/Users/me/repo/file.md:3",
340 "vscode://file/Users/me/repo/file.md:3:7",
341 "vscode-insiders://file/Users/me/repo/file.md",
342 undefined,
343 undefined,
344 ]);
345});
346
347it("keeps mixed-case local editor file links by lowercasing the scheme before sanitizing", () => {
348 const processor = unified()
349 .use(remarkParse)
350 .use(CHAT_MARKDOWN_REMARK_PLUGINS)
351 .use(remarkRehype, { allowDangerousHtml: true })
352 .use(CHAT_MARKDOWN_REHYPE_PLUGINS);
353 const tree = processor.runSync(
354 processor.parse(
355 [
356 "[upper](VSCODE://file/Users/me/repo/file.md:3:7)",
357 "[mixed](Cursor://file/Users/me/repo/file.md:3)",
358 "[other](FOO://file/Users/me/repo/file.md)",
359 ].join(" "),
360 ),
361 );
362 type Node = { tagName?: string; properties?: { href?: string }; children?: Node[] };
363 const hrefs = ((tree.children[0] as Node).children ?? [])
364 .filter((node) => node.tagName === "a")
365 .map((node) => node.properties?.href);
366 expect(hrefs).toEqual([
367 "vscode://file/Users/me/repo/file.md:3:7",
368 "cursor://file/Users/me/repo/file.md:3",
369 undefined,
370 ]);
371});
372
373it("keeps backslashes that CommonMark would read as escapes in prose Windows paths", () => {
374 const processor = unified()
375 .use(remarkParse)
376 .use(CHAT_MARKDOWN_REMARK_PLUGINS)
377 .use(remarkRehype, { allowDangerousHtml: true })
378 .use(CHAT_MARKDOWN_REHYPE_PLUGINS);
379 type Node = { type: string; value?: string; tagName?: string; children?: Node[] };
380 const text = (node: Node): string =>
381 node.type === "text"
382 ? (node.value ?? "")
383 : node.tagName === "code"
384 ? `<code>${(node.children ?? []).map(text).join("")}</code>`
385 : (node.children ?? []).map(text).join("");
386 const render = (markdown: string) => text(processor.runSync(processor.parse(markdown)) as Node);
387
388 expect(
389 render(String.raw`Saved to C:\Users\me\.t3\_build and (C:\.scratch) and C:/work\.config.`),
390 ).toBe(String.raw`Saved to C:\Users\me\.t3\_build and (C:\.scratch) and C:/work\.config.`);
391 expect(render(String.raw`Escaped C:\\Users\\me`)).toBe(String.raw`Escaped C:\\Users\\me`);
392 expect(render(String.raw`See C:\x and \*this\* and Note:\*that\*.`)).toBe(
393 String.raw`See C:\x and *this* and Note:*that*.`,
394 );
395 expect(render(String.raw`${"`"}C:\me\.t3${"`"} and C:\me\.t3`)).toBe(
396 String.raw`<code>C:\me\.t3</code> and C:\me\.t3`,
397 );
398});
399
400it("keeps an image on its own line under a label but leaves inline images inline", () => {
401 const processor = unified()
402 .use(remarkParse)
403 .use(CHAT_MARKDOWN_REMARK_PLUGINS)
404 .use(remarkRehype, { allowDangerousHtml: true })
405 .use(CHAT_MARKDOWN_REHYPE_PLUGINS);
406 type Node = { type: string; value?: string; tagName?: string; children?: Node[] };
407 const shape = (node: Node): string =>
408 node.type === "text"
409 ? (node.value ?? "")
410 : node.tagName === "br" || node.tagName === "img"
411 ? `<${node.tagName}>`
412 : (node.children ?? []).map(shape).join("");
413 const render = (markdown: string) => shape(processor.runSync(processor.parse(markdown)) as Node);
414
415 expect(
416 render("**Palette**\n\n**Hero** (dark)\n"),
417 ).toBe("Palette<br>\n<img><br>\nHero (dark)<br>\n<img>");
418 expect(render("Built [](/ci)\nand wrapped")).toBe("Built <img>\nand wrapped");
419 expect(render("Hard-wrapped\nprose")).toBe("Hard-wrapped\nprose");
420});
421
422it("keeps the number written on each ordered list item only when enabled", () => {
423 type Node = { tagName?: string; properties?: { value?: unknown }; children?: Node[] };
424 const values = (node: Node): unknown[] => [
425 ...(node.tagName === "li" ? [node.properties?.value] : []),
426 ...(node.children ?? []).flatMap(values),
427 ];
428 const renderer = (plugins: PluggableList) => {
429 const processor = unified()
430 .use(remarkParse)
431 .use(plugins)
432 .use(remarkRehype, { allowDangerousHtml: true });
433 return (markdown: string) =>
434 values(processor.runSync(processor.parse(markdown), markdown) as Node);
435 };
436 const render = renderer([
437 ...CHAT_MARKDOWN_REMARK_PLUGINS_WITH_BREAKS,
438 remarkEnableOrderedListNumbers,
439 ]);
440
441 expect(render("3. first\n5. second\n6. third")).toEqual([undefined, "5", undefined]);
442 expect(render("1. one\n1. one again")).toEqual([undefined, "1"]);
443 expect(render("> 1. quoted\n> 4. skipped")).toEqual([undefined, "4"]);
444 expect(render("1. outer\n 1. nested\n 7. jump\n9. back")).toEqual([
445 undefined,
446 undefined,
447 "7",
448 "9",
449 ]);
450 expect(render("1. one\n2. two\n- bullet")).toEqual([undefined, undefined, undefined]);
451 expect(render("- first block\n\n 3. first\n 5. second")).toEqual([
452 undefined,
453 undefined,
454 "5",
455 ]);
456 expect(
457 renderer(CHAT_MARKDOWN_REMARK_PLUGINS)(
458 "3. first\n5. second\n\n- first block\n\n 3. first\n 5. second",
459 ),
460 ).toEqual([undefined, undefined, undefined, undefined, undefined]);
461});
462
463it("moves a <picture>'s color-scheme sources onto its <img>, which the renderer resolves", () => {
464 const processor = unified()
465 .use(remarkParse)
466 .use(CHAT_MARKDOWN_REMARK_PLUGINS)
467 .use(remarkRehype, { allowDangerousHtml: true })
468 .use(CHAT_MARKDOWN_REHYPE_PLUGINS);
469 type Node = { type: string; tagName?: string; properties?: object; children?: Node[] };
470 const tags = (node: Node): string[] => [
471 ...(node.tagName ? [node.tagName] : []),
472 ...(node.children ?? []).flatMap(tags),
473 ];
474 const images = (node: Node): Node[] =>
475 node.tagName === "img" ? [node] : (node.children ?? []).flatMap(images);
476 const tree = processor.runSync(
477 processor.parse(
478 [
479 "<picture>",
480 ' <source media="(prefers-color-scheme: dark)" srcset="docs/dark.webp 1x, docs/dark@2x.webp 2x">',
481 ' <source media="(prefers-color-scheme: dark)" srcset="docs/dark-unused.webp">',
482 ' <source media="(min-width: 600px)" srcset="docs/wide.webp">',
483 ' <img src="docs/light.webp" alt="Studio">',
484 "</picture>",
485 "",
486 '<picture><source media="(prefers-color-scheme: light)" srcset="javascript:alert(1)"><img src="docs/dark.webp"></picture>',
487 "",
488 String.raw`<picture><source media="(prefers-color-scheme: dark)" srcset="C:\shots\dark.png"><img src="C:\shots\light.png"></picture>`,
489 ].join("\n"),
490 ),
491 ) as Node;
492
493 expect(tags(tree)).toEqual(["picture", "img", "p", "picture", "img", "p", "picture", "img"]);
494 expect(images(tree).map((image) => image.properties)).toEqual([
495 { src: "docs/light.webp", alt: "Studio", dataDarkSrc: "docs/dark.webp" },
496 { src: "docs/dark.webp" },
497 { dataLocalSrc: String.raw`C:\shots\light.png`, dataDarkSrc: "file:///C:/shots/dark.png" },
498 ]);
499});
500
501it("links complete absolute paths in prose and skips shortened ones", () => {
502 const path =
503 "/tmp/claude-1000/-home-user--t3-worktrees-app-t3-abc123/session/scratchpad/notes.md";
504 const processor = unified().use(remarkParse).use(CHAT_MARKDOWN_REMARK_PLUGINS);
505 const links = (markdown: string) => {
506 const urls: string[] = [];
507 const visit = (node: Root | RootContent) => {
508 if (node.type === "link") urls.push(node.url);
509 if ("children" in node) node.children.forEach(visit);
510 };
511 visit(processor.runSync(processor.parse(markdown), markdown) as Root);
512 return urls;
513 };
514 expect(links(`Saved to ${path} and /tmp/other.txt.`)).toEqual([path, "/tmp/other.txt"]);
515 expect(links(`See (${path}:12).`)).toEqual([`${path}:12`]);
516 expect(links("See /tmp/report(1).txt. and /tmp/app/[id]/page.tsx.")).toEqual([
517 "/tmp/report(1).txt",
518 "/tmp/app/[id]/page.tsx",
519 ]);
520 expect(links("(see /tmp/claude-1000/...). and /tmp/claude-1000/….")).toEqual([]);
521 expect(links("Served at /index.html; GET /api/users.json; see /tmp/x.md:3.")).toEqual([
522 "/tmp/x.md:3",
523 ]);
524 expect(
525 links(
526 '<a title="</a>" href="https://example.com">/tmp/notes.md</a> and **<a href="x">/tmp/a.md</a>**',
527 ),
528 ).toEqual([]);
529 expect(
530 links("Config lives in /Users/me/Library/Application Support/T3 Code/settings.json now."),
531 ).toEqual([]);
532 expect(links(`/chat/settings and https://example.com${path}`)).toEqual([
533 `https://example.com${path}`,
534 ]);
535 expect(links(`[notes](${path}) and \`${path}\``)).toEqual([path]);
536 expect(links(`\`\`\`\n${path}\n\`\`\``)).toEqual([]);
537});