mirror of
https://github.com/SethCohen/github-releases-to-discord
synced 2026-09-07 20:03:23 +00:00
fix: improve @mention parsing for GitHub usernames (#33)
- Update regex to correctly identify valid GitHub usernames - Prevent false positives for package names and email addresses - Exclude matches within code snippets, URLs, and Markdown links
This commit is contained in:
@@ -28,11 +28,14 @@ const reduceNewlines = (text) => text.replace(/\n\s*\n/g, (ws) => {
|
||||
});
|
||||
|
||||
/**
|
||||
* Converts @mentions to GitHub profile links.
|
||||
* Converts @mentions to GitHub profile links for valid GitHub usernames.
|
||||
* @param {string} text The input text.
|
||||
* @returns {string} The text with @mentions converted to links.
|
||||
* @returns {string} The text with valid @mentions converted to links.
|
||||
*/
|
||||
const convertMentionsToLinks = (text) => text.replace(/@(\S+)/g, (match, name) => `[@${name}](https://github.com/${name})`);
|
||||
const convertMentionsToLinks = (text) => text.replace(
|
||||
/(?<![/@\w])@((?!-)(?!.*?--)[a-zA-Z0-9](?:-?[a-zA-Z0-9]){0,37})(?![.\w/-])(?!.*\])/g,
|
||||
(match, name) => `[@${name}](https://github.com/${name})`
|
||||
);
|
||||
|
||||
/**
|
||||
* Reduces headings to a smaller format if 'reduce_headings' is enabled.
|
||||
|
||||
Reference in New Issue
Block a user