GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(shared): file links wrapping images keep their disambiguating fol… · patroza/t3code@4f5d613

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/shared/src
    • markdownLinks.test.ts
    • markdownLinks.ts
    • threadFindText.test.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: packages/shared/src/markdownLinks.test.ts
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ describe("extractMarkdownLinkHrefs", () => {
192192
["[".repeat(32_000), []],
193193
["[a](<foo)bar> invalid [b](ok)", ["<foo", "ok"]],
194194
["[[[nested](src/main.ts) [unfinished", ["src/main.ts"]],
195+
[
196+
"[![a](a.png)](src/index.ts) [![b](b.png)](lib/index.ts)",
197+
["a.png", "src/index.ts", "b.png", "lib/index.ts"],
198+
],
199+
[String.raw`[\![a](a.png)](src/index.ts) [label!](ok)`, ["a.png", "ok"]],
195200
["See [the [docs] guide](docs/guide.md) and [[1]](src/a.ts)", ["docs/guide.md", "src/a.ts"]],
196201
["[a [b](x) [c \\[d](y) [e\\]](z)", ["x", "y", "z"]],
197202
["[a [b]\n\nc](src/a.ts) [outer [inner]()](src/b.ts)", []],
Collapse file

‎packages/shared/src/markdownLinks.ts‎

Copy file name to clipboardExpand all lines: packages/shared/src/markdownLinks.ts
+9-9Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -533,21 +533,21 @@ function markdownLinkDestinationScanner(markdown: string) {
533533
export function extractMarkdownLinkHrefs(markdown: string): string[] {
534534
const hrefs: string[] = [];
535535
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[] = [];
538538
for (let match = bracket.exec(markdown); match; match = bracket.exec(markdown)) {
539539
if (match[0] === "\\") {
540540
bracket.lastIndex = match.index + 2;
541541
} 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();
547547
const destination = scanDestination(match.index + 1);
548548
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;
551551
bracket.lastIndex = destination.end;
552552
const href = markdown.slice(destination.hrefStart, destination.hrefEnd).trim();
553553
if (href) hrefs.push(href);
Collapse file

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

Copy file name to clipboardExpand all lines: packages/shared/src/threadFindText.test.ts
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ it("searches displayed prose and file-chip labels without hidden paths", () => {
104104
"label main.ts · L3:C2",
105105
]);
106106
expect(assistantSegments("[label](src/main.ts#L3C2)")).toEqual(["label"]);
107+
expect(
108+
assistantSegments(
109+
"[![a](https://example.com/a.png)](src/index.ts) [![b](https://example.com/b.png)](lib/index.ts)",
110+
"/workspace/repo",
111+
),
112+
).toEqual(["index.ts · repo/src index.ts · repo/lib"]);
107113
for (const text of [
108114
"[a](/repo/app/(a)/page.tsx) and [b](/repo/app/(b)/page.tsx)",
109115
String.raw`[a](/repo/app/\(a\)/page.tsx) and [b](/repo/app/\(b\)/page.tsx)`,

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.