GeezerVison is showing github.com — fix(shared): file links wrapping images keep their disambiguating fol… · patroza/t3code@4f5d613
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/shared/src/markdownLinks.test.ts +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -192,6 +192,11 @@ describe("extractMarkdownLinkHrefs", () => { | 192 | 192 | ["[".repeat(32_000), []], | 193 | 193 | ["[a](<foo)bar> invalid [b](ok)", ["<foo", "ok"]], | 194 | 194 | ["[[[nested](src/main.ts) [unfinished", ["src/main.ts"]], | | 195 | + [ | | 196 | + "[](src/index.ts) [](lib/index.ts)", | | 197 | + ["a.png", "src/index.ts", "b.png", "lib/index.ts"], | | 198 | + ], | | 199 | + [String.raw`[\](src/index.ts) [label!](ok)`, ["a.png", "ok"]], | 195 | 200 | ["See [the [docs] guide](docs/guide.md) and [[1]](src/a.ts)", ["docs/guide.md", "src/a.ts"]], | 196 | 201 | ["[a [b](x) [c \\[d](y) [e\\]](z)", ["x", "y", "z"]], | 197 | 202 | ["[a [b]\n\nc](src/a.ts) [outer [inner]()](src/b.ts)", []], | |
Collapse file Copy file name to clipboardExpand all lines: packages/shared/src/markdownLinks.ts +9-9Lines changed: 9 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -533,21 +533,21 @@ function markdownLinkDestinationScanner(markdown: string) { | 533 | 533 | export function extractMarkdownLinkHrefs(markdown: string): string[] { | 534 | 534 | const hrefs: string[] = []; | 535 | 535 | const scanDestination = markdownLinkDestinationScanner(markdown); | 536 | | - const bracket = /[[\]\\]|\n[ \t\r]*\n/g; | 537 | | - let openBrackets = 0; | | 536 | + const bracket = /!\[|[[\]\\]|\n[ \t\r]*\n/g; | | 537 | + const openers: boolean[] = []; | 538 | 538 | for (let match = bracket.exec(markdown); match; match = bracket.exec(markdown)) { | 539 | 539 | if (match[0] === "\\") { | 540 | 540 | bracket.lastIndex = match.index + 2; | 541 | 541 | } else if (match[0].startsWith("\n")) { | 542 | | - openBrackets = 0; | 543 | | - } else if (match[0] === "[") { | 544 | | - openBrackets += 1; | 545 | | - } else if (openBrackets > 0) { | 546 | | - openBrackets -= 1; | | 542 | + openers.length = 0; | | 543 | + } else if (match[0].endsWith("[")) { | | 544 | + openers.push(match[0] === "!["); | | 545 | + } else if (openers.length > 0) { | | 546 | + const image = openers.pop(); | 547 | 547 | const destination = scanDestination(match.index + 1); | 548 | 548 | if (!destination) continue; | 549 | | - // A link cannot contain a link, so the brackets still open around it become text. | 550 | | - openBrackets = 0; | | 549 | + // A link cannot contain a link, but it can contain an image. | | 550 | + if (!image) openers.length = 0; | 551 | 551 | bracket.lastIndex = destination.end; | 552 | 552 | const href = markdown.slice(destination.hrefStart, destination.hrefEnd).trim(); | 553 | 553 | if (href) hrefs.push(href); | |
Collapse file Copy file name to clipboardExpand all lines: packages/shared/src/threadFindText.test.ts +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -104,6 +104,12 @@ it("searches displayed prose and file-chip labels without hidden paths", () => { | 104 | 104 | "label main.ts · L3:C2", | 105 | 105 | ]); | 106 | 106 | expect(assistantSegments("[label](src/main.ts#L3C2)")).toEqual(["label"]); | | 107 | + expect( | | 108 | + assistantSegments( | | 109 | + "[](src/index.ts) [](lib/index.ts)", | | 110 | + "/workspace/repo", | | 111 | + ), | | 112 | + ).toEqual(["index.ts · repo/src index.ts · repo/lib"]); | 107 | 113 | for (const text of [ | 108 | 114 | "[a](/repo/app/(a)/page.tsx) and [b](/repo/app/(b)/page.tsx)", | 109 | 115 | String.raw`[a](/repo/app/\(a\)/page.tsx) and [b](/repo/app/\(b\)/page.tsx)`, | |
|