Skip to content

Commit

Permalink
fix(mentions): allow for usernames with dot, underscore and dash
Browse files Browse the repository at this point in the history
Closes #574
  • Loading branch information
tivie committed Sep 14, 2018
1 parent b0d475f commit 2ba0075
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/subParsers/makehtml/anchors.js
Expand Up @@ -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;
}
Expand All @@ -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>';
});
}
Expand Down
11 changes: 10 additions & 1 deletion test/functional/makehtml/cases/features/ghMentions.html
@@ -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>
20 changes: 19 additions & 1 deletion test/functional/makehtml/cases/features/ghMentions.md
Expand Up @@ -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_
1 change: 1 addition & 0 deletions test/functional/makehtml/cases/standard/emphasis.html
Expand Up @@ -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>
2 changes: 2 additions & 0 deletions test/functional/makehtml/cases/standard/emphasis.md
Expand Up @@ -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)

0 comments on commit 2ba0075

Please sign in to comment.