Skip to content

Commit b3f29a1

Browse files
committed
Skip image reference labels when rewriting link definitions
Collect labels used by image references (![alt][label]) and exclude them from the reference-style link definition rewrite, preventing image URLs from getting .md appended. Made-with: Cursor
1 parent 92e32ca commit b3f29a1

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,10 +464,19 @@ function convertLinksToAbsoluteUrls(content, pageUrlDir, siteUrl) {
464464
}
465465
);
466466

467-
// Reference-style link definitions: [ref]: url
467+
// Collect labels used by image references (![alt][label]) so we skip them
468+
const imageRefLabels = new Set();
469+
const imageRefPattern = /!\[[^\]]*\]\[([^\]]+)\]/g;
470+
let imgMatch;
471+
while ((imgMatch = imageRefPattern.exec(content)) !== null) {
472+
imageRefLabels.add(imgMatch[1].toLowerCase());
473+
}
474+
475+
// Reference-style link definitions: [ref]: url (skip image labels)
468476
content = content.replace(
469477
/^\[([^\]]+)\]:\s+(\S+)$/gm,
470478
(match, ref, href) => {
479+
if (imageRefLabels.has(ref.toLowerCase())) return match;
471480
const resolved = resolveLink(href.trim(), pageUrlDir, siteUrl);
472481
return resolved ? `[${ref}]: ${resolved}` : match;
473482
}

0 commit comments

Comments
 (0)