Pārlūkot izejas kodu

fix(paragraphs): fix empty lines generating empty paragraphs

Empty lines should not be parsed as paragraphs. This was happening
in determined circumstances.
For instance, when stripping reference style links, `\n\n` was left being,
creating an undesired empty paragraph. This commit fixes the issue.

Closes #334
Estevao Soares dos Santos 8 gadi atpakaļ
vecāks
revīzija
54bf74472a

+ 4 - 1
dist/showdown.js

@@ -2351,7 +2351,10 @@ showdown.subParser('paragraphs', function (text, options, globals) {
     // if this is an HTML marker, copy it
     if (str.search(/¨(K|G)(\d+)\1/g) >= 0) {
       grafsOut.push(str);
-    } else {
+
+    // test for presence of characters to prevent empty lines being parsed
+    // as paragraphs (resulting in undesired extra empty paragraphs)
+    } else if (str.search(/\S/) >= 0) {
       str = showdown.subParser('spanGamut')(str, options, globals);
       str = str.replace(/^([ \t]*)/g, '<p>');
       str += '</p>';

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
dist/showdown.js.map


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
dist/showdown.min.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
dist/showdown.min.js.map


+ 4 - 1
src/subParsers/paragraphs.js

@@ -18,7 +18,10 @@ showdown.subParser('paragraphs', function (text, options, globals) {
     // if this is an HTML marker, copy it
     if (str.search(/¨(K|G)(\d+)\1/g) >= 0) {
       grafsOut.push(str);
-    } else {
+
+    // test for presence of characters to prevent empty lines being parsed
+    // as paragraphs (resulting in undesired extra empty paragraphs)
+    } else if (str.search(/\S/) >= 0) {
       str = showdown.subParser('spanGamut')(str, options, globals);
       str = str.replace(/^([ \t]*)/g, '<p>');
       str += '</p>';

+ 0 - 0
test/cases/strip-references.html


+ 13 - 0
test/cases/strip-references.md

@@ -0,0 +1,13 @@
+[1]: http://www.google.co.uk
+
+[http://www.google.co.uk]: http://www.google.co.uk
+
+
+
+
+
+[1]: http://dsurl.stuff/something.jpg
+
+[1]:http://www.google.co.uk
+
+ [1]:http://www.google.co.uk

Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels