Fix greedy regex which was also affecting href in <a> tags

pull/287/head
lowlighter 3 years ago
parent f8f68bae16
commit 9ae115165b
No known key found for this signature in database
GPG Key ID: B7C0F095CFC70776

@ -61,15 +61,15 @@
const baseUrl = String.raw`https?:\/\/(?:www\.)?github.com\/([\w.-]+\/[\w.-]+)\/`
return value
.replace(
RegExp(baseUrl + String.raw`(?:issues|pull|discussions)\/(\d+)(?:\?\S+)?(#\S+)?`, "g"),
RegExp(baseUrl + String.raw`(?:issues|pull|discussions)\/(\d+)(?:\?[\w-]+)?(#[\w-]+)?(?=<)`, "g"),
(_, repo, id, comment) => (options?.repo === repo ? "" : repo) + `#${id}` + (comment ? ` (comment)` : ""),
) // -> 'lowlighter/metrics#123'
.replace(
RegExp(baseUrl + String.raw`commit\/([\da-f]+)`, "g"),
RegExp(baseUrl + String.raw`commit\/([\da-f]+)(?=<)`, "g"),
(_, repo, sha) => (options?.repo === repo ? "" : repo + "@") + sha,
) // -> 'lowlighter/metrics@123abc'
.replace(
RegExp(baseUrl + String.raw`compare\/(\S+...\S+)`, "g"),
RegExp(baseUrl + String.raw`compare\/([\w-.]+...[\w-.]+)(?=<)`, "g"),
(_, repo, tags) => (options?.repo === repo ? "" : repo + "@") + tags,
) // -> 'lowlighter/metrics@1.0...1.1'
}

Loading…
Cancel
Save