Skip to content

Commit

Permalink
Refactor to improve performance of email regex
Browse files Browse the repository at this point in the history
Closes GH-8.
Related-to: GH-9.
  • Loading branch information
wooorm committed Aug 19, 2024
1 parent c990a62 commit 2402c21
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function transformGfmAutolinkLiterals(tree) {
tree,
[
[/(https?:\/\/|www(?=\.))([-.\w]+)([^ \t\r\n]*)/gi, findUrl],
[/([-.\w+]+)@([-\w]+(?:\.[-\w]+)+)/g, findEmail]
[/(?<=^|\s|\p{P}|\p{S})([-.\w+]+)@([-\w]+(?:\.[-\w]+)+)/gu, findEmail]
],
{ignore: ['link', 'linkReference']}
)
Expand Down Expand Up @@ -274,6 +274,7 @@ function previous(match, email) {
(match.index === 0 ||
unicodeWhitespace(code) ||
unicodePunctuation(code)) &&
// If it’s an email, the previous character should not be a slash.
(!email || code !== 47)
)
}

2 comments on commit 2402c21

@TheKonka
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ChristianMurphy
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheKonka right, see #10

Please sign in to comment.