From 2ba00751cc8e890b60585444b9dfb0a1825555e6 Mon Sep 17 00:00:00 2001 From: Estevao Soares dos Santos Date: Fri, 14 Sep 2018 17:03:07 +0100 Subject: [PATCH] fix(mentions): allow for usernames with dot, underscore and dash Closes #574 --- src/subParsers/makehtml/anchors.js | 6 +++++- .../makehtml/cases/features/ghMentions.html | 11 +++++++++- .../makehtml/cases/features/ghMentions.md | 20 ++++++++++++++++++- .../makehtml/cases/standard/emphasis.html | 1 + .../makehtml/cases/standard/emphasis.md | 2 ++ 5 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/subParsers/makehtml/anchors.js b/src/subParsers/makehtml/anchors.js index e96f57d5..8a45c82c 100644 --- a/src/subParsers/makehtml/anchors.js +++ b/src/subParsers/makehtml/anchors.js @@ -97,7 +97,7 @@ showdown.subParser('makehtml.anchors', function (text, options, globals) { // Lastly handle GithubMentions if option is enabled if (options.ghMentions) { - text = text.replace(/(^|\s)(\\)?(@([a-z\d\-]+))(?=[.!?;,[\]()]|\s|$)/gmi, function (wm, st, escape, mentions, username) { + text = text.replace(/(^|\s)(\\)?(@([a-z\d]+(?:[a-z\d._-]+?[a-z\d]+)*))/gmi, function (wm, st, escape, mentions, username) { if (escape === '\\') { return st + mentions; } @@ -111,6 +111,10 @@ showdown.subParser('makehtml.anchors', function (text, options, globals) { if (options.openLinksInNewWindow) { target = ' target="¨E95Eblank"'; } + + // lnk = showdown.helper.escapeCharacters(lnk, '*_', false); // replaced line to improve performance + lnk = lnk.replace(showdown.helper.regexes.asteriskDashAndColon, showdown.helper.escapeCharactersCallback); + return st + '' + mentions + ''; }); } diff --git a/test/functional/makehtml/cases/features/ghMentions.html b/test/functional/makehtml/cases/features/ghMentions.html index 4ee52c51..88df16fe 100644 --- a/test/functional/makehtml/cases/features/ghMentions.html +++ b/test/functional/makehtml/cases/features/ghMentions.html @@ -1,3 +1,12 @@

hello @tivie how are you?

this email foo@gmail.com is not parsed

-

this @mentions is not parsed also

+

this @mentions is not parsed

+

@john.doe

+

@john-doe

+

@john_doe

+

@.johndoe

+

@_johndoe

+

@-johndoe

+

@johndoe.

+

@johndoe-

+

@johndoe_

diff --git a/test/functional/makehtml/cases/features/ghMentions.md b/test/functional/makehtml/cases/features/ghMentions.md index 6187b4c2..75e331a2 100644 --- a/test/functional/makehtml/cases/features/ghMentions.md +++ b/test/functional/makehtml/cases/features/ghMentions.md @@ -2,4 +2,22 @@ hello @tivie how are you? this email foo@gmail.com is not parsed -this \@mentions is not parsed also +this \@mentions is not parsed + +@john.doe + +@john-doe + +@john_doe + +@.johndoe + +@_johndoe + +@-johndoe + +@johndoe. + +@johndoe- + +@johndoe_ diff --git a/test/functional/makehtml/cases/standard/emphasis.html b/test/functional/makehtml/cases/standard/emphasis.html index a2436825..06cb4e4b 100644 --- a/test/functional/makehtml/cases/standard/emphasis.html +++ b/test/functional/makehtml/cases/standard/emphasis.html @@ -36,3 +36,4 @@

foobarbaz

this is imbued link with strong

this is imbued link with strong

+

this link has underscore some_link

diff --git a/test/functional/makehtml/cases/standard/emphasis.md b/test/functional/makehtml/cases/standard/emphasis.md index 4d808f2c..967a0745 100644 --- a/test/functional/makehtml/cases/standard/emphasis.md +++ b/test/functional/makehtml/cases/standard/emphasis.md @@ -72,3 +72,5 @@ foo__bar__baz this is **imbued link with strong** this is __imbued link with strong__ + +this link has underscore [some_link](http://www.google.com/some_link)