Ver código fonte

chore: improve ghMentions

Estevao Soares dos Santos 8 anos atrás
pai
commit
a58674e597

+ 6 - 2
dist/showdown.js

@@ -1219,7 +1219,12 @@ 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, '$1<a href="https://www.github.com/$3">$2</a>');
+    text = text.replace(/(^|\s)(\\)?(@([a-z\d\-]+))(?=[.!?;,[\]()]|\s|$)/gmi, function (wm, st, escape, mentions, username) {
+      if (escape === '\\') {
+        return st + mentions;
+      }
+      return st + '<a href="https://www.github.com/' + username + '">' + mentions + '</a>';
+    });
   }
 
   text = globals.converter._dispatch('anchors.after', text, options, globals);
@@ -1612,7 +1617,6 @@ showdown.subParser('escapeSpecialCharsWithinTagAttributes', function (text) {
   return text;
 });
 
-
 /**
  * Handle github codeblocks prior to running HashHTML so that
  * HTML contained within the codeblock gets escaped properly

Diferenças do arquivo suprimidas por serem muito extensas
+ 0 - 0
dist/showdown.js.map


Diferenças do arquivo suprimidas por serem muito extensas
+ 0 - 0
dist/showdown.min.js


Diferenças do arquivo suprimidas por serem muito extensas
+ 0 - 0
dist/showdown.min.js.map


Diferenças do arquivo suprimidas por serem muito extensas
+ 0 - 0
performance.json


+ 43 - 0
performance.log.md

@@ -1,6 +1,49 @@
 # Performance Tests for showdown
 
 
+## [version 1.5.6](https://github.com/showdownjs/showdown/tree/)
+
+### Test Suite: Basic (100 cycles)
+| test | avgTime | max | min |
+|:-----|--------:|----:|----:|
+|Simple "Hello World"|0.484|5.497|0.159|
+|readme.md|8.624|20.725|7.639|
+
+### Test Suite: subParsers (1000 cycles)
+| test | avgTime | max | min |
+|:-----|--------:|----:|----:|
+|hashHTMLBlocks|0.697|1.193|0.637|
+|anchors|0.191|0.628|0.159|
+|autoLinks|0.017|0.318|0.014|
+|blockGamut|7.720|14.917|6.949|
+|blockQuotes|0.065|0.236|0.060|
+|codeBlocks|0.082|1.078|0.063|
+|codeSpans|0.185|0.915|0.168|
+|detab|0.025|0.195|0.023|
+|encodeAmpsAndAngles|0.016|0.319|0.014|
+|encodeBackslashEscapes|0.014|0.264|0.013|
+|encodeCode|0.177|0.489|0.155|
+|encodeEmailAddress|2.849|482.687|2.103|
+|escapeSpecialCharsWithinTagAttributes|0.061|0.428|0.055|
+|githubCodeBlocks|0.084|5.149|0.056|
+|hashBlock|0.035|6.322|0.011|
+|hashElement|0.001|0.228|0.000|
+|hashHTMLSpans|0.024|4.870|0.011|
+|hashPreCodeTags|0.018|0.295|0.015|
+|headers|0.472|4.046|0.405|
+|images|0.040|0.835|0.033|
+|italicsAndBold|0.041|0.422|0.036|
+|lists|5.606|8.275|5.112|
+|outdent|0.051|0.852|0.045|
+|paragraphs|1.368|2.683|1.221|
+|spanGamut|0.638|1.433|0.569|
+|strikethrough|0.000|0.229|0.000|
+|stripBlankLines|0.032|0.298|0.027|
+|stripLinkDefinitions|0.072|0.354|0.062|
+|tables|0.001|0.199|0.000|
+|unescapeSpecialChars|0.003|0.152|0.003|
+
+
 ## [version 1.5.5](https://github.com/showdownjs/showdown/tree/)
 
 ### Test Suite: Basic (100 cycles)

+ 6 - 1
src/subParsers/anchors.js

@@ -66,7 +66,12 @@ 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, '$1<a href="https://www.github.com/$3">$2</a>');
+    text = text.replace(/(^|\s)(\\)?(@([a-z\d\-]+))(?=[.!?;,[\]()]|\s|$)/gmi, function (wm, st, escape, mentions, username) {
+      if (escape === '\\') {
+        return st + mentions;
+      }
+      return st + '<a href="https://www.github.com/' + username + '">' + mentions + '</a>';
+    });
   }
 
   text = globals.converter._dispatch('anchors.after', text, options, globals);

+ 0 - 0
src/subParsers/ghMentions.js


+ 1 - 0
test/features/ghMentions.html

@@ -1,2 +1,3 @@
 <p>hello <a href="https://www.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>

+ 2 - 0
test/features/ghMentions.md

@@ -1,3 +1,5 @@
 hello @tivie how are you?
 
 this email foo@gmail.com is not parsed
+
+this \@mentions is not parsed also

Alguns arquivos não foram mostrados porque muitos arquivos mudaram nesse diff