Эх сурвалжийг харах

fix(simplifiedAutoLink): fix missing spaces before and after email addresses

Space char before and after the linked email address is no longer dropped
with "simplifiedAutoLink" option enabled.

Closes #330
Estevao Soares dos Santos 8 жил өмнө
parent
commit
5190b6a41f

+ 5 - 4
dist/showdown.js

@@ -1323,8 +1323,8 @@ showdown.subParser('autoLinks', function (text, options, globals) {
   var simpleURLRegex  = /\b(((https?|ftp|dict):\/\/|www\.)[^'">\s]+\.[^'">\s]+)()(?=\s|$)(?!["<>])/gi,
       simpleURLRegex2 = /\b(((https?|ftp|dict):\/\/|www\.)[^'">\s]+\.[^'">\s]+?)([.!?()]?)(?=\s|$)(?!["<>])/gi,
       delimUrlRegex   = /<(((https?|ftp|dict):\/\/|www\.)[^'">\s]+)>/gi,
-      simpleMailRegex = /(?:^|\s)([A-Za-z0-9!#$%&'*+-/=?^_`{|}~.]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)(?:$|\s)/gi,
-      delimMailRegex  = /<(?:mailto:)?([-.\w]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)>/gi;
+      simpleMailRegex = /(^|\s)(?:mailto:)?([A-Za-z0-9!#$%&'*+-/=?^_`{|}~.]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)(?=$|\s)/gmi,
+      delimMailRegex  = /<()(?:mailto:)?([-.\w]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)>/gi;
 
   text = text.replace(delimUrlRegex, replaceLink);
   text = text.replace(delimMailRegex, replaceMail);
@@ -1352,8 +1352,9 @@ showdown.subParser('autoLinks', function (text, options, globals) {
     return '<a href="' + link + '">' + lnkTxt + '</a>' + append;
   }
 
-  function replaceMail(wholeMatch, mail) {
+  function replaceMail(wholeMatch, b, mail) {
     var href = 'mailto:';
+    b = b || '';
     mail = showdown.subParser('unescapeSpecialChars')(mail);
     if (options.encodeEmails) {
       mail = showdown.helper.encodeEmailAddress(mail);
@@ -1361,7 +1362,7 @@ showdown.subParser('autoLinks', function (text, options, globals) {
     } else {
       href = href + mail;
     }
-    return '<a href="' + href + '">' + mail + '</a>';
+    return b + '<a href="' + href + '">' + mail + '</a>';
   }
 
   text = globals.converter._dispatch('autoLinks.after', text, options, globals);

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 0 - 0
dist/showdown.js.map


Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 0 - 0
dist/showdown.min.js


Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 0 - 0
dist/showdown.min.js.map


+ 5 - 4
src/subParsers/autoLinks.js

@@ -6,8 +6,8 @@ showdown.subParser('autoLinks', function (text, options, globals) {
   var simpleURLRegex  = /\b(((https?|ftp|dict):\/\/|www\.)[^'">\s]+\.[^'">\s]+)()(?=\s|$)(?!["<>])/gi,
       simpleURLRegex2 = /\b(((https?|ftp|dict):\/\/|www\.)[^'">\s]+\.[^'">\s]+?)([.!?()]?)(?=\s|$)(?!["<>])/gi,
       delimUrlRegex   = /<(((https?|ftp|dict):\/\/|www\.)[^'">\s]+)>/gi,
-      simpleMailRegex = /(?:^|\s)([A-Za-z0-9!#$%&'*+-/=?^_`{|}~.]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)(?:$|\s)/gi,
-      delimMailRegex  = /<(?:mailto:)?([-.\w]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)>/gi;
+      simpleMailRegex = /(^|\s)(?:mailto:)?([A-Za-z0-9!#$%&'*+-/=?^_`{|}~.]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)(?=$|\s)/gmi,
+      delimMailRegex  = /<()(?:mailto:)?([-.\w]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)>/gi;
 
   text = text.replace(delimUrlRegex, replaceLink);
   text = text.replace(delimMailRegex, replaceMail);
@@ -35,8 +35,9 @@ showdown.subParser('autoLinks', function (text, options, globals) {
     return '<a href="' + link + '">' + lnkTxt + '</a>' + append;
   }
 
-  function replaceMail(wholeMatch, mail) {
+  function replaceMail(wholeMatch, b, mail) {
     var href = 'mailto:';
+    b = b || '';
     mail = showdown.subParser('unescapeSpecialChars')(mail);
     if (options.encodeEmails) {
       mail = showdown.helper.encodeEmailAddress(mail);
@@ -44,7 +45,7 @@ showdown.subParser('autoLinks', function (text, options, globals) {
     } else {
       href = href + mail;
     }
-    return '<a href="' + href + '">' + mail + '</a>';
+    return b + '<a href="' + href + '">' + mail + '</a>';
   }
 
   text = globals.converter._dispatch('autoLinks.after', text, options, globals);

+ 1 - 0
test/features/#330.simplifiedAutoLink-drops-character-before-and-after-linked-mail.html

@@ -0,0 +1 @@
+<p>Just an example <a href="mailto:info@example.com">info@example.com</a> ok?​</p>

+ 1 - 0
test/features/#330.simplifiedAutoLink-drops-character-before-and-after-linked-mail.md

@@ -0,0 +1 @@
+Just an example info@example.com ok?​

+ 2 - 0
test/node/testsuite.features.js

@@ -55,6 +55,8 @@ describe('makeHtml() features testsuite', function () {
       converter = new showdown.Converter({ghMentions: true});
     } else if (testsuite[i].name === 'disable-email-encoding') {
       converter = new showdown.Converter({encodeEmails: false});
+    } else if (testsuite[i].name === '#330.simplifiedAutoLink-drops-character-before-and-after-linked-mail') {
+      converter = new showdown.Converter({encodeEmails: false, simplifiedAutoLink: true});
     } else {
       converter = new showdown.Converter();
     }

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно