From ed4c33fe4e58a1a62934cd54ba7d4adebf7ac49b Mon Sep 17 00:00:00 2001 From: Estevao Soares dos Santos Date: Tue, 20 Dec 2016 23:57:10 +0000 Subject: [PATCH] fix(simpleLineBreaks): fix simpleLineBreak option breaking lists html When option was enabled, `
` tags where being added wrongfully between `
  • ` tags, which resulted in malformed html. This commit prevents this behavior. Closes #316 --- dist/showdown.js | Bin 72737 -> 72899 bytes dist/showdown.js.map | Bin 214329 -> 214801 bytes dist/showdown.min.js | Bin 29590 -> 29666 bytes dist/showdown.min.js.map | Bin 32736 -> 32816 bytes src/subParsers/hashHTMLSpans.js | 4 +- src/subParsers/lists.js | 4 ++ src/subParsers/spanGamut.js | 8 +-- ...-simpleLineBreaks-option-breaks-lists.html | 48 +++++++++++++++++ ...ew-simpleLineBreaks-option-breaks-lists.md | 51 ++++++++++++++++++ .../disableForced4SpacesIndentedSublists.html | 12 ++--- ...6.entity-in-code-block-in-nested-list.html | 18 +++---- ...196.entity-in-code-block-in-nested-list.md | 2 +- ...nordered-list-inconsistent-behavior-2.html | 12 ++--- test/node/testsuite.features.js | 2 + 14 files changed, 126 insertions(+), 35 deletions(-) create mode 100644 test/features/#316.new-simpleLineBreaks-option-breaks-lists.html create mode 100644 test/features/#316.new-simpleLineBreaks-option-breaks-lists.md diff --git a/dist/showdown.js b/dist/showdown.js index da59e0dff4de5acbc52dbefd02ae829c63dbf0e4..6914604b0ee12d87ff9246794e9a84970e5ac61e 100644 GIT binary patch delta 187 zcmZ3ugXQo}mJPDI8J#D~?Ka_XR@b!VQc$R!{P3E{|vSwKACs&=cg9@F?rhh={gGPF?lh0KvOn5J)6(C`N8w4 zQqw0gF{+8{>npgs`6?8bROX~AWF!`)C?pl7CT36GkSfg8bnkvqiBn1U+kizX8%#4zf0B}G=IRF3v delta 109 zcmX@SlV#x!mJPDI8GR*~8XJ(Y0{*{SQW%9}QqD(P)(*v0q6(;}vAj+zspbg=Q LY~RPs$SMf{-PtE3 diff --git a/dist/showdown.js.map b/dist/showdown.js.map index 54d865e10e90ff26213bb1fa7f2c20849b25aec4..efebbf72d96ffb704df5c5f6ca89b23ded29c998 100644 GIT binary patch delta 571 zcmZ{ePiPZS5XPCeo5rl&Y^_O5vQ}T}VKv*biI_tSVoJ0MT5KJK+pfGwu z!F0bcZ4QdfE-I`sp_954V^w*KM4N%M+Gl`h6r=7Y1nZF(}??(Ft$ZX?`8=u}1-t9%u zFztxv|H#CD%Y<->gA464`2HhEN=I<424Osfu%FS+Fs5}d_~;s}et`@oTjYRf2$jhBPvq8RjaY>cJ7`sNc;Z;@Y$3xwc8{aFE*PqRnMVQva z05yKi#=aDfsnQ+bZ@to@j&o7T2wE0BHatSB7cZ5H^nAW@jutA#{Dmquz7yS(%@#Iq l3)qTEdjbMJoi9(8O8I}#Zh=y2{-p!>;RlKGv!?Ve^b?lw$hQCh delta 401 zcmXAiO(=tL9LM|ppJ$6ld$#h-+iaeZmiCZBG8f~bJc^q%Cn1Ww<+j?zMOx#BUtA2u zjUD9Qq>Xl8a`JNUaIrKl~rV2d0=be;BNV8z`;DMbJj>e&Vl zCi)d}w1R@SUJcV(4dVkAJP9b2P(kK38!+dh%WJTs=TTXk0Sm^40>w_FOD9L4Ahgp(aDBCi-Mf WDJ0OEAyxfdR$ccCz&{MhRrUjS{ER&S diff --git a/dist/showdown.min.js b/dist/showdown.min.js index 9df38efdd248a2805cf97a1c9389d248337eb1ff..3269405f55d2a525f2083835e65e541d9eba8543 100644 GIT binary patch delta 140 zcmbRCobl0f#toCa8J#Cj_EutYR+{YXBQ^P(mcZo2nR1gSxN}Tq_t9Z@R?<$j%|)!QEEX>Vsfg6eoS6Wp0<9vjuMEm`C-fxE{!B0GYKSQ dlT@UjZx@rNq-m9iq$5c|K^vrG^V9T=+yF@WFP#7Y delta 69 zcmV-L0J{I;=K+@I0kD!w0ZfyVOCkbHB9lu@8k6=a5R-C8CX)wDEC);?D`YDoOtU&n btPry*UEc};Zj%mZ8U-LAD_m}~F=(+1Yo8Z7 diff --git a/dist/showdown.min.js.map b/dist/showdown.min.js.map index 05a2d68c5fe5e7c75c8193c4030784f8414ac16a..ee4a61d3d8ed5b9a9487797ef9aff1dc28ae69c9 100644 GIT binary patch delta 233 zcmaFxpK(J2(+2Gn#?Z++DUBQ^uIA1<{*Gmnx2Bxr%yr3e0&+53Hn*o%Fd91>JC*zD zxH>xem-&IH;9_T;P)Em5oopvZ$84ueACRE0r8`(IQperV*?4kXx)^6LNKK%ltLbFM z^tp__o9Cx@GO-u?Jn8F8<05 E0Eh%f{{R30 delta 170 zcmdnc!1Ulh;|A>%#^A|1DUBSJuIA1<{*DEcx2BxrOn1p~0&>iqH@Bx&FfzGTO%6<- z%jmuNeR?Modxno=nVXLL|j45$xy~3Y2iqaGvBYJ$aA4#AfS~ GuiOAFMK+rN diff --git a/src/subParsers/hashHTMLSpans.js b/src/subParsers/hashHTMLSpans.js index 588728d..0d4fb02 100644 --- a/src/subParsers/hashHTMLSpans.js +++ b/src/subParsers/hashHTMLSpans.js @@ -7,7 +7,7 @@ showdown.subParser('hashHTMLSpans', function (text, config, globals) { var matches = showdown.helper.matchRecursiveRegExp(text, ']*>', '', 'gi'); for (var i = 0; i < matches.length; ++i) { - text = text.replace(matches[i][0], '~L' + (globals.gHtmlSpans.push(matches[i][0]) - 1) + 'L'); + text = text.replace(matches[i][0], '~C' + (globals.gHtmlSpans.push(matches[i][0]) - 1) + 'C'); } return text; }); @@ -19,7 +19,7 @@ showdown.subParser('unhashHTMLSpans', function (text, config, globals) { 'use strict'; for (var i = 0; i < globals.gHtmlSpans.length; ++i) { - text = text.replace('~L' + i + 'L', globals.gHtmlSpans[i]); + text = text.replace('~C' + i + 'C', globals.gHtmlSpans[i]); } return text; diff --git a/src/subParsers/lists.js b/src/subParsers/lists.js index 4b40f66..6bd24b0 100644 --- a/src/subParsers/lists.js +++ b/src/subParsers/lists.js @@ -4,6 +4,7 @@ showdown.subParser('lists', function (text, options, globals) { 'use strict'; text = globals.converter._dispatch('lists.before', text, options, globals); + /** * Process the contents of a single ordered or unordered list, splitting it * into individual list items. @@ -91,6 +92,8 @@ showdown.subParser('lists', function (text, options, globals) { // Recursion for sub-lists: item = showdown.subParser('lists')(item, options, globals); item = item.replace(/\n$/, ''); // chomp(item) + item = showdown.subParser('hashHTMLBlocks')(item, options, globals); + item = item.replace(/\n\n+/g, '\n\n'); if (isParagraphed) { item = showdown.subParser('paragraphs')(item, options, globals); } else { @@ -102,6 +105,7 @@ showdown.subParser('lists', function (text, options, globals) { item = item.replace('~A', ''); // we can finally wrap the line in list item tags item = '' + item + '
  • \n'; + return item; }); diff --git a/src/subParsers/spanGamut.js b/src/subParsers/spanGamut.js index 7e945bd..bb0f194 100644 --- a/src/subParsers/spanGamut.js +++ b/src/subParsers/spanGamut.js @@ -24,12 +24,12 @@ showdown.subParser('spanGamut', function (text, options, globals) { text = showdown.subParser('strikethrough')(text, options, globals); // Do hard breaks - - // GFM style hard breaks if (options.simpleLineBreaks) { - text = text.replace(/\n/g, '
    \n'); + // GFM style hard breaks + text = text.replace(/\b\n\b/g, '
    \n'); } else { - text = text.replace(/ +\n/g, '
    \n'); + // Vanilla hard breaks + text = text.replace(/\b +\n\b/g, '
    \n'); } text = globals.converter._dispatch('spanGamut.after', text, options, globals); diff --git a/test/features/#316.new-simpleLineBreaks-option-breaks-lists.html b/test/features/#316.new-simpleLineBreaks-option-breaks-lists.html new file mode 100644 index 0000000..943c7b2 --- /dev/null +++ b/test/features/#316.new-simpleLineBreaks-option-breaks-lists.html @@ -0,0 +1,48 @@ +
      +
    1. One
    2. +
    3. Two
        +
      • A
      • +
      • B
    4. +
    5. Three
    6. +
    +
    +

    this has
    + simple linebreaks

    +
    +
    testing
    +some
    +code
    +
    +
      +
    1. paragraphed list

      +

      this belongs
      + to the first list item

    2. +
    3. This text
      + also

    4. +
    +

    simple
    + text

    + +

    simple
    + text

    + \ No newline at end of file diff --git a/test/features/#316.new-simpleLineBreaks-option-breaks-lists.md b/test/features/#316.new-simpleLineBreaks-option-breaks-lists.md new file mode 100644 index 0000000..6a83c8b --- /dev/null +++ b/test/features/#316.new-simpleLineBreaks-option-breaks-lists.md @@ -0,0 +1,51 @@ +1. One +2. Two + - A + - B +3. Three + +> this has +> simple linebreaks + + testing + some + code + + 1. paragraphed list + + this belongs + to the first list item + + 2. This text + also + +simple +text + + - a list + item + - another + list item + +simple +text + + - some item + + another + paragraph + + - And + now + + paragraph + sublist + + - and + even + + another + one + + - foo + diff --git a/test/features/disableForced4SpacesIndentedSublists.html b/test/features/disableForced4SpacesIndentedSublists.html index a31cc1f..416eb65 100644 --- a/test/features/disableForced4SpacesIndentedSublists.html +++ b/test/features/disableForced4SpacesIndentedSublists.html @@ -1,13 +1,9 @@

    ...

    diff --git a/test/issues/#196.entity-in-code-block-in-nested-list.html b/test/issues/#196.entity-in-code-block-in-nested-list.html index c9b90a7..8de7bb3 100644 --- a/test/issues/#196.entity-in-code-block-in-nested-list.html +++ b/test/issues/#196.entity-in-code-block-in-nested-list.html @@ -1,17 +1,11 @@

    Test pre in a list

    \ No newline at end of file diff --git a/test/issues/#196.entity-in-code-block-in-nested-list.md b/test/issues/#196.entity-in-code-block-in-nested-list.md index ace136b..cec2670 100644 --- a/test/issues/#196.entity-in-code-block-in-nested-list.md +++ b/test/issues/#196.entity-in-code-block-in-nested-list.md @@ -1,7 +1,7 @@ Test pre in a list - & < -- `& <` +- `& <` - & < - `& <` - & < diff --git a/test/issues/#299.nested-ordered-unordered-list-inconsistent-behavior-2.html b/test/issues/#299.nested-ordered-unordered-list-inconsistent-behavior-2.html index 3e6399e..a5680ae 100644 --- a/test/issues/#299.nested-ordered-unordered-list-inconsistent-behavior-2.html +++ b/test/issues/#299.nested-ordered-unordered-list-inconsistent-behavior-2.html @@ -20,10 +20,8 @@

    foo

    foo

    foo

    diff --git a/test/node/testsuite.features.js b/test/node/testsuite.features.js index 699a73c..e98ad3f 100644 --- a/test/node/testsuite.features.js +++ b/test/node/testsuite.features.js @@ -37,6 +37,8 @@ describe('makeHtml() features testsuite', function () { converter = new showdown.Converter({disableForced4SpacesIndentedSublists: true}); } else if (testsuite[i].name === '#206.treat-single-line-breaks-as-br') { converter = new showdown.Converter({simpleLineBreaks: true}); + } else if (testsuite[i].name === '#316.new-simpleLineBreaks-option-breaks-lists') { + converter = new showdown.Converter({simpleLineBreaks: true}); } else if (testsuite[i].name === 'excludeTrailingPunctuationFromURLs-option') { converter = new showdown.Converter({simplifiedAutoLink: true, excludeTrailingPunctuationFromURLs: true}); } else if (testsuite[i].name === 'requireSpaceBeforeHeadingText') {