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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
<p>hello <a href="https://github.com/tivie">@tivie</a> how are you?</p>
<p>this email [email protected] 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,18 @@ hello @tivie how are you?

this email [email protected] 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.