From 4378abb4fa5a8d9913abee60b4459d3350ba8300 Mon Sep 17 00:00:00 2001 From: Vladimir Vuksanovic Date: Wed, 24 Oct 2018 04:23:28 +0200 Subject: [PATCH] fix(italicsAndBold): Make italicsAndBold lazy (#608) fix italicsAndBold if literalMidwordUnderscores option is enabled it should end at the nearest closing underscores, not the furthest Closes #544 --- dist/showdown.js | Bin 173123 -> 173064 bytes dist/showdown.js.map | Bin 487634 -> 487636 bytes dist/showdown.min.js | Bin 80968 -> 80969 bytes dist/showdown.min.js.map | Bin 91770 -> 91770 bytes src/subParsers/makehtml/italicsAndBold.js | 4 ++-- .../literalMidWordUnderscores/basic.html | 3 +++ .../literalMidWordUnderscores/basic.md | 6 ++++++ .../makehtml/cases/standard/emphasis.html | 6 ++++++ .../makehtml/cases/standard/emphasis.md | 12 ++++++++++++ 9 files changed, 29 insertions(+), 2 deletions(-) diff --git a/dist/showdown.js b/dist/showdown.js index bdd07a850a71a7b496cbc465987a8bd20bcac7bb..a82f6337a78dc61859a9ae0af17d0c014393a9cb 100644 GIT binary patch delta 689 zcmYk4Ur1AN6vsK|?%uoI=G0`f`6q^HT{D@>(&@Uk4SEPmR~AvtZL%opL0|fVMiPa! z!hw)@j9!Mc*C31z1ofa0Hi%kK4?&O*5!H(X^$;w&yZ17B`+d&ud%nN#Is8`Fl+2nk z=ko?S16`fFy8=PqPQRj_y)>S_cz$ABZNGX?t8aRI;)`clt1q-I+qJuIXlnrcyyAqo zNRc3V7g|B2oEt=rZie3?_icfrBF{EMvqbAx;57AS(9I34@Kokv2YeNbE}9F0M5R2~ z`LiE1VBK{EdA%Ea0%I?%3jDGk5(2jkK#z^%QK*y6#+pf}=EZ|>1GsSzN?55nI5Y&( ze@q)muu)haEo7{DLu&zyE<0@?Z%<4!$kn z2jGMqf7s33Z=EPnl?$u*axFdq?x@3zIcRyW{H_6&+DZU&=0Ra`7kUJ4@?*r9wS}(- z@F$c-EtEQhHoD)9#R@uTVGj-&$nsviU`ux@Z!Bp@FH&{1gpCsNFwZF3?m4#-p~E8b@gzb_j#W4yzk*em(`_Zb=tbO z+3q-OcR8G1Yki}p)}6mG6uEwBc&P5cElt26njZ$rl{ew_GDtlx1j?xzv<2PKsrR7K z10&oo;L(f|D#h?R6o{9lpeJ7`B$y`GZU{*nuYd|YDy=vVt}}uq2UMpikniHt^^eyL@2YnR)Tm3DnW;PKe5wxd>Qje;0h^ zm{hOracwu~^O;}|tQk1U)(fK?MQj{Nm#QT91$boQ0B(F%Y!yKhU8t zCqBRi`%PICS=H?IEADq^S!yK`Ck+=Q32Zc`_B`ggnio3aK=hZ&&v(^b diff --git a/dist/showdown.js.map b/dist/showdown.js.map index b9c2fd78b3de8faee2281c5eb5850691da5dcceb..0b3c9f6289c292ee9616b390558cd3a19dd836eb 100644 GIT binary patch delta 106 zcmccgQ1;40*@hOzElj(XOgC7;BsaZbFSE$>2WObI8Ox?SE@QHs{(c3M#`MaiOj*+# zT9`y88)S)0S6I$u%2?D6lm=pEAZFR_xQw-8Ig7n!eEjqWer)#BfBUk9G1|8W`mt>f J^kZ*S0ssQ6C^`TD delta 127 zcmcceQ1;S8*@hOzElj(XOx|G4I$c4QS#o;AUS^T$56&=aGnPzuT*hQM{rw6ijp>z3 znXGy!wmU9ktyn(oD;vx7eZFi{7&WKw c@nv(Lo)f^vKV907O|$*7AKUiJe(a1&0LqjwUH||9 diff --git a/dist/showdown.min.js b/dist/showdown.min.js index ea2f7b5ce47103dd0393dc913689922c2995fb38..a0ac136753ac126d5c1516a5e9ce9dc1764d8349 100644 GIT binary patch delta 38 wcmV+>0NMY@_yo!L1dtyDF)cALu_Hjv13xKWlflj@la9_Z0Y9_A&W3FP3N*yr4BAf4@%gkls G diff --git a/src/subParsers/makehtml/italicsAndBold.js b/src/subParsers/makehtml/italicsAndBold.js index b644075..07862be 100644 --- a/src/subParsers/makehtml/italicsAndBold.js +++ b/src/subParsers/makehtml/italicsAndBold.js @@ -13,10 +13,10 @@ showdown.subParser('makehtml.italicsAndBold', function (text, options, globals) // Parse underscores 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 parseInside (txt, '', ''); }); - 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 parseInside (txt, '', ''); }); text = text.replace(/\b_(\S[\s\S]*?)_\b/g, function (wm, txt) { diff --git a/test/functional/makehtml/cases/features/literalMidWordUnderscores/basic.html b/test/functional/makehtml/cases/features/literalMidWordUnderscores/basic.html index 8293687..7d7d9e9 100644 --- a/test/functional/makehtml/cases/features/literalMidWordUnderscores/basic.html +++ b/test/functional/makehtml/cases/features/literalMidWordUnderscores/basic.html @@ -7,3 +7,6 @@

strippers, hitler, and stalin

strippers, hitler, and stalin

strippers, hitler, and stalin

+

multiple italics and bolds in a paragraph

+

multiple bolds in a paragraph

+

multiple italics in a paragraph

\ No newline at end of file diff --git a/test/functional/makehtml/cases/features/literalMidWordUnderscores/basic.md b/test/functional/makehtml/cases/features/literalMidWordUnderscores/basic.md index e2be213..54a820e 100644 --- a/test/functional/makehtml/cases/features/literalMidWordUnderscores/basic.md +++ b/test/functional/makehtml/cases/features/literalMidWordUnderscores/basic.md @@ -15,3 +15,9 @@ strippers, _hitler_, and stalin strippers, __hitler__, and stalin strippers, ___hitler___, and stalin + +___multiple___ italics and bolds in a ___paragraph___ + +__multiple__ bolds in a __paragraph__ + +_multiple_ italics in a _paragraph_ \ No newline at end of file diff --git a/test/functional/makehtml/cases/standard/emphasis.html b/test/functional/makehtml/cases/standard/emphasis.html index 06cb4e4..805daf8 100644 --- a/test/functional/makehtml/cases/standard/emphasis.html +++ b/test/functional/makehtml/cases/standard/emphasis.html @@ -37,3 +37,9 @@

this is imbued link with strong

this is imbued link with strong

this link has underscore some_link

+

multiple italics and bolds with underscores in a paragraph

+

multiple italics and bolds with asterisks in a paragraph

+

multiple bolds with underscores in a paragraph

+

multiple bolds with asterisks in a paragraph

+

multiple italics with underscores in a paragraph

+

multiple italics with asterisks in a paragraph

diff --git a/test/functional/makehtml/cases/standard/emphasis.md b/test/functional/makehtml/cases/standard/emphasis.md index 967a074..1177fde 100644 --- a/test/functional/makehtml/cases/standard/emphasis.md +++ b/test/functional/makehtml/cases/standard/emphasis.md @@ -74,3 +74,15 @@ this is **imbued link with strong** this is __imbued link with strong__ this link has underscore [some_link](http://www.google.com/some_link) + +___multiple___ italics and bolds with underscores in a ___paragraph___ + +***multiple*** italics and bolds with asterisks in a ***paragraph*** + +__multiple__ bolds with underscores in a __paragraph__ + +**multiple** bolds with asterisks in a **paragraph** + +_multiple_ italics with underscores in a _paragraph_ + +_multiple_ italics with asterisks in a _paragraph_