From 81edc70da7372f662954321d4b372e1eae189870 Mon Sep 17 00:00:00 2001 From: Vladimir Vuksanovic Date: Sun, 21 Oct 2018 15:20:39 +0200 Subject: [PATCH] fix(underline): Make underline lazy fix underline if literalMidwordUnderscores option is enabled it should end at the nearest closing underscores, not the furthest --- dist/showdown.js | Bin 173123 -> 173300 bytes dist/showdown.js.map | Bin 487634 -> 488486 bytes dist/showdown.min.js | Bin 80968 -> 81122 bytes dist/showdown.min.js.map | Bin 91770 -> 91924 bytes src/subParsers/makehtml/underline.js | 10 ++++++++-- .../cases/features/underline/simple.html | 1 + .../cases/features/underline/simple.md | 2 ++ 7 files changed, 11 insertions(+), 2 deletions(-) diff --git a/dist/showdown.js b/dist/showdown.js index bdd07a850a71a7b496cbc465987a8bd20bcac7bb..347c64379aae817dc1112e963169b96e3f865ea4 100644 GIT binary patch delta 729 zcmYjPTS!y^5arD7y}Mr5SK`|Gh{Z>(+Olqz&(_qa2um%KsC0M5DDp#pdXSMsVOh8# zB#zOKi2ep)G!W#6LgYe}L46cKeneD164ghr(cOD5OMi1_&YU?j%*qSx=c+d8^#uLF zYX6SvV7<38p!v>R7#cW#Zg|L7aphhpzv$8N&+f%ge!P6q8M^a|w*(Q8WfyuCZmlQJ zbQu($&4VIsoA6tahRryt$V4%URbIb@Q(QMrc~Ve@Ck|Pw!WWy-#gk1?Ik5nzd8mLu@ka7l@_8ZJutHx8T_w^qlOAuQPL~<(?xa!6!pAO}GLro8 zFlEZz5gM>Gecjgh5^gy`iab3=t;R78tckCWdMxT}m}c~sJ54v5<=GtdfeYtpE3|+7 C)7#EKj&4yQCAP=Jm-DR^PG2XLK%OmT(qw8 zxk~*mZ>gukTH;m}NBhxu+mU?-g7OI&RFPUCaCuVSfr;+EZCf8enUGPV zX^u#9IC41B94#rE>Dt$QAG1xIv~HtHOM$^Wv=Z zCJQl8&vs(#a8hsNG+?S|@nNIhxWEm1;ltL%o6gN>r09AaO>_$USfR`J_;F^DD4_mI zw9C8jt_*p7Mmx>a;xR;35#UFg__Gs}sXvHYO}fI5ZP=5L7CUfICmNdYkWSFMX6#55 q2SQjUPduOL)-F`&O%y{3I;7!{{H8B4JXOuuc^#vYoEl+!s`3}Woajyf diff --git a/dist/showdown.js.map b/dist/showdown.js.map index b9c2fd78b3de8faee2281c5eb5850691da5dcceb..6d6808f9a6ecdc206f64d50996421de0acdc9bfe 100644 GIT binary patch delta 309 zcmccgPhy8dh?sp$bX88s$vu;!Z{dzM*j`hrzV8q+sK1C<|G%A`EKp@m6gvOyM9OA!_= zY14UEFzuSYz=&CH@_|(%K$Ezp3uLlzO>gjI7M}j#9K=lB>A&|ea!n7&V`80L&p&rU%?))BvjEo1SrwIc;*nM6T%qyi8ov z{xh;pFZjaDHGRTLCjP1afkywXVd4jAm7Ba_g7|bdXC|TP|5q{@ONg?QgS5OxF)!spauSnMHS}YW;^X5rVuGV%ierLf zwd^(HCm%c~J-vsEQ9w!)RT+}1$p_BKfYb<1_Bii4{UH~l?BoOIO}7IXsfLVP0E0X! A4FCWD delta 110 zcmaF#ljXz@mI?AKrn&}}jmle<84b9UQuT^b3vv>ZQ#JHslH%>-<27P}qhpF=f@8Hb rTp~WbkBd=2!3s$+s#1Hf+R26&RJYe~Go~6c@p1tG4u~V7 diff --git a/dist/showdown.min.js.map b/dist/showdown.min.js.map index 3f1838a5b2e9a858840585e2fd396e1f294c37e6..b1c38ab5d374d88e32f41e6c5d45eadb62199b81 100644 GIT binary patch delta 188 zcmex$hIPt0)`l&NPqmeDohsZaTy@+XlUyBjTphh!^IU#x6R(j*k8yA`oPPqpwb=qiaN-`*c4YMoC4e zsw!-%+{>IwT!6;APH)p;6k~QRaGqTA#u~(_;;V47bOpN0(=pvS!qRoJ{a(ZE_PUJL FmH>J5Icxv` delta 135 zcmbPoj`i0W)`l&NPqmE`E8Hqvb=)1pTpe{>9bH`WT!EBhV1=`efs>=Nhmkvo>uv6= z69^R5F>-QrG?^~1!zij?>Z0T8=;#k30zq0GeRYBz-7}m@Tp&6o&v|P(T|t+ziZ92> a(iLcjr=x*Wgr)0b`@M$SZ|X8yTLJ*_yeMV> diff --git a/src/subParsers/makehtml/underline.js b/src/subParsers/makehtml/underline.js index ad7f654..a3d4414 100644 --- a/src/subParsers/makehtml/underline.js +++ b/src/subParsers/makehtml/underline.js @@ -8,11 +8,17 @@ showdown.subParser('makehtml.underline', function (text, options, globals) { text = globals.converter._dispatch('makehtml.underline.before', text, options, globals).getText(); if (options.literalMidWordUnderscores) { - text = text.replace(/\b_?__(\S[\s\S]*)___?\b/g, function (wm, txt) { + text = text.replace(/\b___(\S[\s\S]*?)___\b/g, function (wm, txt) { + return '' + txt + ''; + }); + text = text.replace(/\b__(\S[\s\S]*?)__\b/g, function (wm, txt) { return '' + txt + ''; }); } else { - text = text.replace(/_?__(\S[\s\S]*?)___?/g, function (wm, m) { + text = text.replace(/___(\S[\s\S]*?)___/g, function (wm, m) { + return (/\S$/.test(m)) ? '' + m + '' : wm; + }); + text = text.replace(/__(\S[\s\S]*?)__/g, function (wm, m) { return (/\S$/.test(m)) ? '' + m + '' : wm; }); } diff --git a/test/functional/makehtml/cases/features/underline/simple.html b/test/functional/makehtml/cases/features/underline/simple.html index 51756cf..1f8e5ae 100644 --- a/test/functional/makehtml/cases/features/underline/simple.html +++ b/test/functional/makehtml/cases/features/underline/simple.html @@ -2,3 +2,4 @@

an underlined sentence

three underscores are fine

_single_ underscores are left alone

+

multiple underlines in a paragraph

\ No newline at end of file diff --git a/test/functional/makehtml/cases/features/underline/simple.md b/test/functional/makehtml/cases/features/underline/simple.md index cc96921..510be1f 100644 --- a/test/functional/makehtml/cases/features/underline/simple.md +++ b/test/functional/makehtml/cases/features/underline/simple.md @@ -5,3 +5,5 @@ __an underlined sentence__ ___three underscores are fine___ _single_ underscores are left alone + +__multiple__ underlines in a __paragraph__ \ No newline at end of file