From 43e9448d6e1d742c1d8d7e8aee8a3e6a7ebda1fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Estev=C3=A3o=20Soares=20dos=20Santos?= Date: Sat, 11 Jul 2015 15:59:06 +0100 Subject: [PATCH] feat(strikethrough): add support for GFM strikethrough Github Flavored Markdown supports strikethrough (``) syntax using double tilde `~~` delimiters. This commit adds this feature to showdown through an option called "strikethrough". Related to #164 --- dist/showdown.js | Bin 56166 -> 56484 bytes dist/showdown.js.map | Bin 178543 -> 179233 bytes dist/showdown.min.js | Bin 18448 -> 18646 bytes dist/showdown.min.js.map | Bin 20522 -> 20704 bytes src/showdown.js | 3 ++- src/subParsers/spanGamut.js | 1 + src/subParsers/strikethrough.js | 9 +++++++++ test/features/#164.3.strikethrough.html | 5 +++++ test/features/#164.3.strikethrough.md | 5 +++++ test/node/showdown.js | 3 ++- test/node/testsuite.features.js | 2 ++ 11 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 src/subParsers/strikethrough.js create mode 100644 test/features/#164.3.strikethrough.html create mode 100644 test/features/#164.3.strikethrough.md diff --git a/dist/showdown.js b/dist/showdown.js index 561e2b1c94bd2fd6db25aef578829c5690084986..f61f1a0e0c09c2e6731740a01e66fb8e69802241 100644 GIT binary patch delta 174 zcmaF1jd{sV<_+f(5G(E!#A_gHhpJ4oOc5;8HEH8?h$qwN% zlXsktnw&6I1Wo3_DyhkLmMf!)9t@Px)z`4MsteJqHmcQ#j;o8+)`au*({&WoZBkNm W>{JYG^g*=xrR*}T-`>NvmthzA?#p~P05$Zmyn=jtt@PP^HQl*f z&0ih_g*UE16S)!+9A{SnynJsFIt7-Yj~fcm&f%&Ciu=I| zkZI!=nS5(9eLiAgn-3h63R`J?*g~&-D4{=OGTFi)b2GVdW%>S!J`njMv(g9r0aOY5H~q6rE=%EJ*3o)&aBQ(!0SLxoRVfuOA4(l&Yj z$KJRh-Dx_#S%3}$Ck-s=Pr`$4X!*AeO!U%dgOhAu$ec<+mF@=OH2rlee^n>MCzjwj zN{vgnFGK?iZo5&mr(ae30|7O(?_ik5;#&<``ZWDC#dk|&dsU{Du6la6PBd(W5k-;GUoWpt^K8(Bh%p%t6u#rCwqMdIG zC}!lrBKEK+i|zbd26ytAEbcO+)hxP2{(cq@usbK1qB-=Nsc&}(owb}vH(;JUpT|}s zDu1kWUYS5=Ng$%}OdhxK_YU07g*-a8Yr4}!GrYyv@(-KReX&_MVyM7e~*&^i<0x_D*{ zInknY)98C|#z8R&0+kd*DYG_GBqj(^R)dRZ5!Ca&+_kv(e)oLm9PYW_&@bi3mXdsx zHoleilBJ?Ib9}>XR8q~I{_tdfm|A<_nWdogdHs^ql7&d^0Y&*AkHE3%^7gGEjMfDkSyXB}@`} zAq|*ZYmpXAZn6#~&b1EXLYzyS>T?78F%jSK{~qUZM|vs2KHRS3ARZ(*fc1K=n$$=6 GTIOFK;{-zh diff --git a/dist/showdown.min.js b/dist/showdown.min.js index b9e9494d4b491e246c86c48030ec511b97554b45..60cbcfd160b5903992e4e124bdd42eb1b2b7e994 100644 GIT binary patch delta 153 zcmbO*f$`cz#tk#r_;iX(iZZiPOEQY`OVcwpPi1Shoh&8K%ZnmBna{B%2>*gcZ;P}HfZX(ZYv>J_CHvm=Uo;eCt diff --git a/dist/showdown.min.js.map b/dist/showdown.min.js.map index 900b5d6d5a13d4f8678d30bf8b2761e42aff69b3..a1834e3e6a753513889ee9df9a930a75e1fb91fe 100644 GIT binary patch delta 7865 zcmbVRYiwKBeTR%LVcbQsW7&FGvL#uM*rLRj__FN8=N?{CSJc%tP0r0xWm_?v6$RP_ORxc3yCN9YZ`-g2!wM8==VB-d?918|*f4AZ=3x5}AlSP7 z{{M3?Ny$pm?u+Gn&j0-1Z+`Qgwh!KI`?KCt&+qJRSJqZ`%iGm@sr>D(Q~&Tx+tjx| z^gZ`0ZL8|z=fC7Lg^U=|zoK^9ueRM&Z?})NZK&_IU-#`wzbQn%uAc3<>Z|FGeU<3w z^92mPd8l6L2!7$7KPz%kxvS5D(!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OL@c#65F%r#?M{*M0i)nt}Ze=fq)t$Kl_5-6-S^@rnuGqqLbu|E&CRBO4% z;HQ^;RV`~wz#}t8DgKh#laA5jtAE)rZqXMKxFNr7gkRZZmTU+2jdO!na_h=O4I%4B zm09M5 zPhwY<1#&Ef-wQk@5&2%K*XMGK$e*No`&zZb)8U$m=IN~LG#5wQXqjeTEwFxZ{@)uR zT1Fs*9-BtcQ#Nm$0@srask5}b) z<{aPFJ*EiA=d76yppWgya||;6icynkD|`zS`1a_R$}{n^4dJ+~7_P9yOh|su@;|~e zCzYoo0wNwJ`9}tERzHItd&k&jP!$vhyOkdez3?%`TR(8b~ z*}+k~j>0aMMc0_$=6mFh)pcl1X@yXZ@g})hYl;k5oE8iEQ^it0Babv zo`h}me#V*}Vx?82VGUa5)RF~e=B}VZ8-E0=9v>%|0uh$VQy^>*{S3wqBU zByH%rsekPG&J(7)4RqC_nN-kxz}{8()^``!Cy4fd^B\n'); diff --git a/src/subParsers/strikethrough.js b/src/subParsers/strikethrough.js new file mode 100644 index 0000000..b84ab39 --- /dev/null +++ b/src/subParsers/strikethrough.js @@ -0,0 +1,9 @@ +showdown.subParser('strikethrough', function (text, options) { + 'use strict'; + + if (options.strikethrough) { + text = text.replace(/(?:~T){2}([^~]+)(?:~T){2}/g, '$1'); + } + + return text; +}); diff --git a/test/features/#164.3.strikethrough.html b/test/features/#164.3.strikethrough.html new file mode 100644 index 0000000..68139e4 --- /dev/null +++ b/test/features/#164.3.strikethrough.html @@ -0,0 +1,5 @@ +

a strikethrough word

+ +

this should~~not be parsed

+ +

strike-through text

diff --git a/test/features/#164.3.strikethrough.md b/test/features/#164.3.strikethrough.md new file mode 100644 index 0000000..3498b1a --- /dev/null +++ b/test/features/#164.3.strikethrough.md @@ -0,0 +1,5 @@ +a ~~strikethrough~~ word + +this should~~not be parsed + +~~strike-through text~~ diff --git a/test/node/showdown.js b/test/node/showdown.js index 80834ff..5dd74a7 100644 --- a/test/node/showdown.js +++ b/test/node/showdown.js @@ -24,7 +24,8 @@ describe('showdown.options', function () { headerLevelStart: 1, parseImgDimensions: false, simplifiedAutoLink: false, - literalMidWordUnderscores: false + literalMidWordUnderscores: false, + strikethrough: false }; expect(showdown.getDefaultOptions()).to.be.eql(opts); }); diff --git a/test/node/testsuite.features.js b/test/node/testsuite.features.js index 77e0e24..4278638 100644 --- a/test/node/testsuite.features.js +++ b/test/node/testsuite.features.js @@ -18,6 +18,8 @@ describe('makeHtml() features testsuite', function () { converter = new showdown.Converter({simplifiedAutoLink: true}); } else if (testsuite[i].name === '#164.2.disallow_underscore_emphasis_mid_word') { converter = new showdown.Converter({literalMidWordUnderscores: true}); + } else if (testsuite[i].name === '#164.3.strikethrough') { + converter = new showdown.Converter({strikethrough: true}); } else { converter = new showdown.Converter(); }