From 0cc55b07eef7e4b418df0819d766584bbc836b90 Mon Sep 17 00:00:00 2001 From: Estevao Soares dos Santos Date: Fri, 19 Aug 2016 19:12:25 +0100 Subject: [PATCH] fix(simplifiedAutoLink): fix simplified autolink to match GFM behavior Using the simplifiedAutoLink option does not return the expected GFM behaviour when parsing links without a http prefix. Previously, `www.google.com` would be parsed into `www.google.com`. With this fix, showdown behaves like GFM, and the result is `www.google.com` Closes #284, closes #285 --- dist/showdown.js | Bin 72190 -> 72377 bytes dist/showdown.js.map | Bin 214460 -> 215031 bytes dist/showdown.min.js | Bin 28225 -> 28301 bytes dist/showdown.min.js.map | Bin 31789 -> 31951 bytes src/subParsers/autoLinks.js | 14 +++++++++++--- test/features/#164.1.simple-autolink.html | 2 +- ...fiedAutoLink-does-not-match-GFM-style.html | 3 +++ ...lifiedAutoLink-does-not-match-GFM-style.md | 3 +++ test/features/tables/with-span-elements.html | 2 +- test/node/testsuite.features.js | 2 ++ 10 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 test/features/#284.simplifiedAutoLink-does-not-match-GFM-style.html create mode 100644 test/features/#284.simplifiedAutoLink-does-not-match-GFM-style.md diff --git a/dist/showdown.js b/dist/showdown.js index 2291502eff65839b4a86594c6b85e5df3bd1a0d4..8f9cdbaab6004f1b4348b24a633dc2da6a7fc9c5 100644 GIT binary patch delta 267 zcmeyjnPulz7GZ0BEk%XmjQsMH{PH{nLrYx)i;co}s(6c13vv>ZQ++b?vNf$I3r-iG z{Gf_;vP!iqqrzmz>T}#k@{{GRNl*S?%{JM+#-JXgL8ClZMs>QdiK1n4ztpu4D)1L7V~P+vq3Ssc(*}Suhs> DD&|!> delta 106 zcmdnFmF3@N7GZ0BEk%XmjQsMH{PH{nBLiIn^NqrHs>IZ75*0FvQqyc>lvE63l|~!x)5+P@GsUqhRiDgX6S&!^wtX%DbDJY% diff --git a/dist/showdown.js.map b/dist/showdown.js.map index 52bb838b38ab6c5176762899b91526e05cb12b86..7196acc84da6215956a69634d650de234698a6c0 100644 GIT binary patch delta 636 zcmYjMUuaTM80Vb4ZoBSkOWR6ooMv_16mQW}a}IAtGAM8~=%LF{L{W6&>^6hdT3c_y zf_=mXF__Vxw+$h}heeNj8YFv*py?iZh?efD$94Qe?7%tj{l4G7^ZAAJ_oY+AGe z@9{ON11B7KRHWCRHtDXyjE7~KIySFm89#H;Jj-O$Q;&4!Z*6>SJe6QBWx7x(Xqs0^ zdG+`M-PIEQSF#qpqw;n_k7+ziPU?DYR8hE#R}Kz$oS(D<@^SrPKFj2>C`;z!3BNWZ cGk4q4&17w8yfwC)abQe|j?3k9Z)ow|KX#hexc~qF delta 276 zcmey~&%39acf+GMlWns3Sv(ybJtr@`Ejro2iEFyTc}9-urOz2$Fk zw|PueZj%FVOHH4*k&%D;0Y*mF$pRW&)8}V0a!vk_z&ZJVE6Ze_cXilJW6YX-aho*6 zIQ@P6le^yWPJaB(V0t+lquOS!k3o!#rqdY>8D%DaQ0AK4Fo$otLl7g|Vnr0gl6QiVJ2qNuN3~lri?WXqyGf7Xk iSjeP2JzzeQ<@BiwnHEUnR<1tXVG&d4_Tt4%ElU8u;baj2 diff --git a/dist/showdown.min.js b/dist/showdown.min.js index b0676c7bc34811f72084600c52a3fbeec44eefbf..1b74f56fc8916c7c55144ab2c0a9c8ed442ce8cb 100644 GIT binary patch delta 241 zcmX?jhq3oAqmaIqqC#;-etAlMd7gryrLKX+Mxi@;^-0!6sU@XFdHQkX<>fJY`k8tq zsl_E4Nt$YE8cDWEdPS)PIf==s8gO|XrHqo20xNxepn5$eO-&tjn?!|-qSQ27C3Wp2 zZFMC(b?szrB^&)jJEhvR(!Au7%=|osG>t@^B+crw#3F@c+Z4Ux(xiaIqT7*yL6As>PO7F(qHQAFHCZ}olW!TQ bPG$=dWXaS?)12IBEIm0&pKG(P;TIbKimFc( delta 162 zcmeCZ%Xsh(qmaIqqC#;-etAlMd7grifv$o1Mxi@;laus28Pg`e(f4IZx7D|q{6SxX zUDHlKJyR!Ra*jbdW9H;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aceMail); - //simpleURLRegex = /\b(((https?|ftp|dict):\/\/|www\.)[-.+~:?#@!$&'()*,;=[\]\w]+)\b/gi, + // simpleURLRegex = /\b(((https?|ftp|dict):\/\/|www\.)[-.+~:?#@!$&'()*,;=[\]\w]+)\b/gi, // Email addresses: if (options.simplifiedAutoLink) { - text = text.replace(simpleURLRegex, '$1'); + text = text.replace(simpleURLRegex, replaceLink); text = text.replace(simpleMailRegex, replaceMail); } + function replaceLink(wm, link) { + var lnkTxt = link; + if (/^www\./i.test(link)) { + link = link.replace(/^www\./i, 'http://www.'); + } + return '' + lnkTxt + ''; + } + function replaceMail(wholeMatch, m1) { var unescapedStr = showdown.subParser('unescapeSpecialChars')(m1); return showdown.subParser('encodeEmailAddress')(unescapedStr); diff --git a/test/features/#164.1.simple-autolink.html b/test/features/#164.1.simple-autolink.html index 909ae2c..d1a8c6e 100644 --- a/test/features/#164.1.simple-autolink.html +++ b/test/features/#164.1.simple-autolink.html @@ -2,7 +2,7 @@

www.foobar

-

www.foobar.com

+

www.foobar.com

http://foobar.com

diff --git a/test/features/#284.simplifiedAutoLink-does-not-match-GFM-style.html b/test/features/#284.simplifiedAutoLink-does-not-match-GFM-style.html new file mode 100644 index 0000000..91b5e46 --- /dev/null +++ b/test/features/#284.simplifiedAutoLink-does-not-match-GFM-style.html @@ -0,0 +1,3 @@ +

this is a link to www.github.com

+ +

this is a link to www.google.com

diff --git a/test/features/#284.simplifiedAutoLink-does-not-match-GFM-style.md b/test/features/#284.simplifiedAutoLink-does-not-match-GFM-style.md new file mode 100644 index 0000000..ead003c --- /dev/null +++ b/test/features/#284.simplifiedAutoLink-does-not-match-GFM-style.md @@ -0,0 +1,3 @@ +this is a link to www.github.com + +this is a link to diff --git a/test/features/tables/with-span-elements.html b/test/features/tables/with-span-elements.html index 1b4a4d1..3f7236e 100644 --- a/test/features/tables/with-span-elements.html +++ b/test/features/tables/with-span-elements.html @@ -19,7 +19,7 @@ google - www.foo.com + www.foo.com normal diff --git a/test/node/testsuite.features.js b/test/node/testsuite.features.js index 049d3b1..4502e1e 100644 --- a/test/node/testsuite.features.js +++ b/test/node/testsuite.features.js @@ -31,6 +31,8 @@ describe('makeHtml() features testsuite', function () { converter = new showdown.Converter({literalMidWordUnderscores: true}); } else if (testsuite[i].name === '#259.es6-template-strings-indentation-issues') { converter = new showdown.Converter({smartIndentationFix: true}); + } else if (testsuite[i].name === '#284.simplifiedAutoLink-does-not-match-GFM-style') { + converter = new showdown.Converter({simplifiedAutoLink: true}); } else { converter = new showdown.Converter(); }