فهرست منبع

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

Closes #574
Estevao Soares dos Santos 6 سال پیش
والد
کامیت
2ba00751cc

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

+ 10 - 1
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>

+ 19 - 1
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_

+ 1 - 0
test/functional/makehtml/cases/standard/emphasis.html

@@ -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 - 0
test/functional/makehtml/cases/standard/emphasis.md

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