Skip to content

Commit 2402c21

Browse files
committed
Refactor to improve performance of email regex
Closes GH-8. Related-to: GH-9.
1 parent c990a62 commit 2402c21

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lib/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ function transformGfmAutolinkLiterals(tree) {
132132
tree,
133133
[
134134
[/(https?:\/\/|www(?=\.))([-.\w]+)([^ \t\r\n]*)/gi, findUrl],
135-
[/([-.\w+]+)@([-\w]+(?:\.[-\w]+)+)/g, findEmail]
135+
[/(?<=^|\s|\p{P}|\p{S})([-.\w+]+)@([-\w]+(?:\.[-\w]+)+)/gu, findEmail]
136136
],
137137
{ignore: ['link', 'linkReference']}
138138
)
@@ -274,6 +274,7 @@ function previous(match, email) {
274274
(match.index === 0 ||
275275
unicodeWhitespace(code) ||
276276
unicodePunctuation(code)) &&
277+
// If it’s an email, the previous character should not be a slash.
277278
(!email || code !== 47)
278279
)
279280
}

0 commit comments

Comments
 (0)