fix(mentions): allow for usernames with dot, underscore and dash

Closes #574
This commit is contained in:
Estevao Soares dos Santos 2018-09-14 17:03:07 +01:00
parent b0d475fc08
commit 2ba00751cc
5 changed files with 37 additions and 3 deletions

View File

@ -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 + '<a href="' + lnk + '"' + target + '>' + mentions + '</a>';
});
}

View File

@ -1,3 +1,12 @@
<p>hello <a href="https://github.com/tivie">@tivie</a> how are you?</p>
<p>this email foo@gmail.com is not parsed</p>
<p>this @mentions is not parsed also</p>
<p>this @mentions is not parsed</p>
<p><a href="https://github.com/john.doe">@john.doe</a></p>
<p><a href="https://github.com/john-doe">@john-doe</a></p>
<p><a href="https://github.com/john_doe">@john_doe</a></p>
<p>@.johndoe</p>
<p>@_johndoe</p>
<p>@-johndoe</p>
<p><a href="https://github.com/johndoe">@johndoe</a>.</p>
<p><a href="https://github.com/johndoe">@johndoe</a>-</p>
<p><a href="https://github.com/johndoe">@johndoe</a>_</p>

View File

@ -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_

View File

@ -36,3 +36,4 @@
<p>foo<strong>bar</strong>baz</p>
<p>this is <strong><a href="//google.com">imbued link with strong</a></strong></p>
<p>this is <strong><a href="//google.com">imbued link with strong</a></strong></p>
<p>this link has underscore <a href="http://www.google.com/some_link">some_link</a></p>

View File

@ -72,3 +72,5 @@ foo__bar__baz
this is **<a href="//google.com">imbued link with strong</a>**
this is __<a href="//google.com">imbued link with strong</a>__
this link has underscore [some_link](http://www.google.com/some_link)