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 Oct 16, 2018
1 parent 79ed024 commit dfeb1e2
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 11 deletions.
2 changes: 1 addition & 1 deletion dist/showdown.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/showdown.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/showdown.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/showdown.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/subParsers/anchors.js
Expand Up @@ -75,7 +75,7 @@ showdown.subParser('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 Down
9 changes: 8 additions & 1 deletion test/features/ghMentions.html
@@ -1,3 +1,10 @@
<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>@.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>
16 changes: 15 additions & 1 deletion test/features/ghMentions.md
Expand Up @@ -2,4 +2,18 @@ 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

@.johndoe

@_johndoe

@-johndoe

@johndoe.

@johndoe-

This file was deleted.

This file was deleted.

0 comments on commit dfeb1e2

Please sign in to comment.