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 with #L line anchors in their label no longer… · patroza/t3code@0c4e7d8

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/shared/src
    • markdownLinks.test.ts
    • markdownLinks.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
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ describe("isMarkdownFileLinkLabel", () => {
1717
["example.ts:99", "/repo/src/example.ts:12", false],
1818
["example.ts:12-20", "/repo/src/example.ts:12-20", true],
1919
["example.ts:12-20", "/repo/src/example.ts:12", false],
20+
["src/main.ts#L10-L20", "/repo/src/main.ts#L10-L20", true],
21+
["main.ts#L42C7", "/repo/src/main.ts:42:7", true],
22+
["src/main.ts#L10-L20", "/repo/src/main.ts#L10", false],
23+
["src/main.ts:10#L20", "/repo/src/main.ts:10", false],
24+
["C#/Program.cs#L10", "./C%23/Program.cs#L10", true],
25+
["src/main.ts#L10", "./src/main.ts%23L10", true],
2026
])("classifies %s for %s", (label, href, expected) => {
2127
expect(isMarkdownFileLinkLabel(label, href)).toBe(expected);
2228
});
Collapse file

‎packages/shared/src/markdownLinks.ts‎

Copy file name to clipboardExpand all lines: packages/shared/src/markdownLinks.ts
+29-15Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -356,22 +356,36 @@ export function isMarkdownFileLinkLabel(label: string, href: string): boolean {
356356
if (!destination) return false;
357357
const normalize = (path: string) =>
358358
path.replaceAll("\\", "/").replace(/^\.\//, "").replace(/\/+$/, "");
359-
const labelPosition = splitFilePathPosition(label.trim());
360-
if (
361-
(labelPosition.line !== undefined && labelPosition.line !== destination.line) ||
362-
(labelPosition.column !== undefined && labelPosition.column !== destination.column) ||
363-
(labelPosition.endLine !== undefined && labelPosition.endLine !== destination.endLine)
364-
) {
365-
return false;
366-
}
367-
let labelPath = normalize(labelPosition.path);
368-
let destinationPath = normalize(destination.path);
369-
if (labelPath.length === 0) return true;
370-
if (isWindowsAbsolutePath(destination.path)) {
371-
labelPath = labelPath.toLowerCase();
372-
destinationPath = destinationPath.toLowerCase();
359+
const trimmed = label.trim();
360+
const isWindowsDestination = isWindowsAbsolutePath(destination.path);
361+
const destinationPath = isWindowsDestination
362+
? normalize(destination.path).toLowerCase()
363+
: normalize(destination.path);
364+
const matchesLabelPosition = (labelPosition: FilePathPosition): boolean => {
365+
if (
366+
(labelPosition.line !== undefined && labelPosition.line !== destination.line) ||
367+
(labelPosition.column !== undefined && labelPosition.column !== destination.column) ||
368+
(labelPosition.endLine !== undefined && labelPosition.endLine !== destination.endLine)
369+
) {
370+
return false;
371+
}
372+
let labelPath = normalize(labelPosition.path);
373+
if (labelPath.length === 0) return true;
374+
if (isWindowsDestination) {
375+
labelPath = labelPath.toLowerCase();
376+
}
377+
return destinationPath === labelPath || destinationPath.endsWith(`/${labelPath}`);
378+
};
379+
const hashIndex = trimmed.lastIndexOf("#");
380+
if (hashIndex >= 0) {
381+
const path = trimmed.slice(0, hashIndex);
382+
const anchored = splitFilePathPosition(path, trimmed.slice(hashIndex));
383+
// A `:line` suffix before the hash wins in splitFilePathPosition; only a position from the anchor counts here.
384+
if (anchored.line !== undefined && anchored.path === path && matchesLabelPosition(anchored)) {
385+
return true;
386+
}
373387
}
374-
return destinationPath === labelPath || destinationPath.endsWith(`/${labelPath}`);
388+
return matchesLabelPosition(splitFilePathPosition(trimmed));
375389
}
376390

377391
export function isRelativeFilePath(path: string): boolean {

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.