From 5190b6a41f1ebcbcee4fcde04ac842ecb81a7b40 Mon Sep 17 00:00:00 2001 From: Estevao Soares dos Santos Date: Fri, 27 Jan 2017 19:25:46 +0000 Subject: [PATCH] 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 --- dist/showdown.js | Bin 75466 -> 75503 bytes dist/showdown.js.map | Bin 221733 -> 221872 bytes dist/showdown.min.js | Bin 30945 -> 30970 bytes dist/showdown.min.js.map | Bin 33987 -> 34021 bytes src/subParsers/autoLinks.js | 9 +++++---- ...haracter-before-and-after-linked-mail.html | 1 + ...-character-before-and-after-linked-mail.md | 1 + test/node/testsuite.features.js | 2 ++ 8 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 test/features/#330.simplifiedAutoLink-drops-character-before-and-after-linked-mail.html create mode 100644 test/features/#330.simplifiedAutoLink-drops-character-before-and-after-linked-mail.md diff --git a/dist/showdown.js b/dist/showdown.js index 8b7e44d3453478189fd62f6687ea53baba63ec36..af4d5e3ac8cbb1caf47b47d2026f5c2e0ba13383 100644 GIT binary patch delta 83 zcmX?gmgW6fmJMgx1mkLAiZwOtt#T7Hb4v29H0>u}Zgbr{_*qY?ouy+-%qW lmYFeWvSzmiSCWFQLXtvFje`1SuWnvO<|GB}&0#$yvj8*U9c=&r delta 57 zcmaEVmgUr0mJMgx*zK+2YGR5tC*N&z$J;l_Gy2^JlVQiZF5mK8{_0# MU3{CndQxWr0LP#hH~;_u diff --git a/dist/showdown.js.map b/dist/showdown.js.map index 31a0dc67a8a1a3e1334e71c657fb9a7684878d00..bbfc3ebae764f6c1f494a46ee2f51f7d82224231 100644 GIT binary patch delta 301 zcmW;BF-QVo6u@!bmzVm$zRVLzqYf&}9HOAb5R)7tB4}u{&|4zPLTw5mw;&p%$N3s< zh}LVmz^D^ylW>eCr=}u@rW(xJ{``Mej~?^MV_tMAV@qxksKzlM4@QNg=05V<8c2Gt zN@EZtcY}cEex=vryjljgvXD$J%^OJw^_F5}Aao*-pa<-}{7%!cEm$bix^M%O~&;RI2?Tw_Tu%qZHko2Dugzb6jylK@?Kl zC_sqp7nL+Ga_0+1xw8pKEk>VD&A_?BDi)D;Y u{KL$4j_>MX3?kNRT?8DU^XG$@MqP_*x>hP_Vasa^KlJHZ^m?)(E`I@gl4!30 delta 335 zcmYL^KS%;`9L4$mxbx0m=qX)6W$6%9V4R2*7-51~5KgU?<=97lSyiC;sXm$XgDdS_Y*V%MpaZo1rB`6d*h6xOMQhc=?~G<^>t&ZnTo%U<=OFx*Cga6w>Ma8G65EtIp_TKNvX*HkjW|HQ2C3TY^p7 PmS8S86HK$k9cx>^=dX16 diff --git a/dist/showdown.min.js b/dist/showdown.min.js index dde42109d662bf03a6a418850ec9fc6aa0410e80..0f229ceded9562b29a0a16e858d03c97411f4caf 100644 GIT binary patch delta 181 zcmaF(k@43@#tqNSRdiA`tIHCL6w+*!auYLiO7g9gtcy}hN{jLol5LY~YLt|8QYJH6 zs0ycO>Llr<<|XH+q`HDs7Taq~jV z3N%z*J55_%$xdB6MO(>6KhaL9c5-8^8hl2VjfTny5Xf>%L`cCx0XRf@K4vW~h57Eg-EdH?DTgBDH6l+etXz9*pr2=B=r)TP9+v?kF*0j24 F2LRL_Lg)Yh diff --git a/dist/showdown.min.js.map b/dist/showdown.min.js.map index 70c1a54aa3228c0b5b4c94bab24114a7f50d32ea..84fbe2aa6cbd3069bf388cb8456580a7e81e2c69 100644 GIT binary patch delta 6484 zcmcIoU2I%O6_!n^ZlQ5oHHqV-O`LyHU&UVA>)nMGI(P2%_4V~;eZ5|}&#XO6><02%pmimc&yeFbQmZQhl$v%@M*Gyx`5~H$i zLaZr8e#&sv2iBo8D+^>@Nmd(8AMSGCTI^y;kB&$qDMZp( zhK@bt?NUd++ajzH(v|*mH#uN#vW7F@n$~ZtWe9acy<_##`GDU^Q;=HtTFf~?}05L_f z!vCk45N?t2sA`_(n8j%pke9RxDNx%Ma&e1U7X!k}-U6^Op#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(|uYy%U{;mQSsU7DF0qfA1Q5Gbst zyk)p}Pu)=zGfBJ~kg|^@Rv0i7+Scah*;D w=yBc7@-z8DUKL(CeV{al^>&6|n-|LJwU;hGT$uxi$@vk+C>ik7Z(cg`A6T0p9smFU diff --git a/src/subParsers/autoLinks.js b/src/subParsers/autoLinks.js index 4bf53e9..44ec9e4 100644 --- a/src/subParsers/autoLinks.js +++ b/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 '' + lnkTxt + '' + 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 '' + mail + ''; + return b + '' + mail + ''; } text = globals.converter._dispatch('autoLinks.after', text, options, globals); diff --git a/test/features/#330.simplifiedAutoLink-drops-character-before-and-after-linked-mail.html b/test/features/#330.simplifiedAutoLink-drops-character-before-and-after-linked-mail.html new file mode 100644 index 0000000..e82b0ba --- /dev/null +++ b/test/features/#330.simplifiedAutoLink-drops-character-before-and-after-linked-mail.html @@ -0,0 +1 @@ +

Just an example info@example.com ok?​

diff --git a/test/features/#330.simplifiedAutoLink-drops-character-before-and-after-linked-mail.md b/test/features/#330.simplifiedAutoLink-drops-character-before-and-after-linked-mail.md new file mode 100644 index 0000000..ceb08b1 --- /dev/null +++ b/test/features/#330.simplifiedAutoLink-drops-character-before-and-after-linked-mail.md @@ -0,0 +1 @@ +Just an example info@example.com ok?​ \ No newline at end of file diff --git a/test/node/testsuite.features.js b/test/node/testsuite.features.js index f2bccc0..505cafc 100644 --- a/test/node/testsuite.features.js +++ b/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(); }