@@ -356,22 +356,36 @@ export function isMarkdownFileLinkLabel(label: string, href: string): boolean { |
356 | 356 | if (!destination) return false; |
357 | 357 | const normalize = (path: string) => |
358 | 358 | 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 | + } |
373 | 387 | } |
374 | | - return destinationPath === labelPath || destinationPath.endsWith(`/${labelPath}`); |
| 388 | + return matchesLabelPosition(splitFilePathPosition(trimmed)); |
375 | 389 | } |
376 | 390 |
|
377 | 391 | export function isRelativeFilePath(path: string): boolean { |
|