Эх сурвалжийг харах

fix(simpleLineBreaks): fix simpleLineBreaks option not working with non-ASCII chars and markdown delimiters

The option simpleLineBreaks was not working with non-ASCII characters such as chinese characters and
when lines started or ended with markdown delimiters such as `*` or `~`

Closes #318, #323
Estevao Soares dos Santos 8 жил өмнө
parent
commit
b1c458a762

+ 6 - 2
dist/showdown.js

@@ -2076,12 +2076,16 @@ showdown.subParser('lists', function (text, options, globals) {
         item = showdown.subParser('lists')(item, options, globals);
         item = item.replace(/\n$/, ''); // chomp(item)
         item = showdown.subParser('hashHTMLBlocks')(item, options, globals);
+        // Colapse double linebreaks
         item = item.replace(/\n\n+/g, '\n\n');
+        // replace double linebreaks with a placeholder
+        item = item.replace(/\n\n/g, '~B');
         if (isParagraphed) {
           item = showdown.subParser('paragraphs')(item, options, globals);
         } else {
           item = showdown.subParser('spanGamut')(item, options, globals);
         }
+        item = item.replace(/~B/g, '\n\n');
       }
 
       // now we need to remove the marker (~A)
@@ -2301,10 +2305,10 @@ showdown.subParser('spanGamut', function (text, options, globals) {
   // Do hard breaks
   if (options.simpleLineBreaks) {
     // GFM style hard breaks
-    text = text.replace(/\b\n\b/g, '<br />\n');
+    text = text.replace(/\n/g, '<br />\n');
   } else {
     // Vanilla hard breaks
-    text = text.replace(/\b  +\n\b/g, '<br />\n');
+    text = text.replace(/  +\n/g, '<br />\n');
   }
 
   text = globals.converter._dispatch('spanGamut.after', text, options, globals);

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 0 - 0
dist/showdown.js.map


Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 0 - 0
dist/showdown.min.js


Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 0 - 0
dist/showdown.min.js.map


+ 4 - 0
src/subParsers/lists.js

@@ -93,12 +93,16 @@ showdown.subParser('lists', function (text, options, globals) {
         item = showdown.subParser('lists')(item, options, globals);
         item = item.replace(/\n$/, ''); // chomp(item)
         item = showdown.subParser('hashHTMLBlocks')(item, options, globals);
+        // Colapse double linebreaks
         item = item.replace(/\n\n+/g, '\n\n');
+        // replace double linebreaks with a placeholder
+        item = item.replace(/\n\n/g, '~B');
         if (isParagraphed) {
           item = showdown.subParser('paragraphs')(item, options, globals);
         } else {
           item = showdown.subParser('spanGamut')(item, options, globals);
         }
+        item = item.replace(/~B/g, '\n\n');
       }
 
       // now we need to remove the marker (~A)

+ 2 - 2
src/subParsers/spanGamut.js

@@ -26,10 +26,10 @@ showdown.subParser('spanGamut', function (text, options, globals) {
   // Do hard breaks
   if (options.simpleLineBreaks) {
     // GFM style hard breaks
-    text = text.replace(/\b\n\b/g, '<br />\n');
+    text = text.replace(/\n/g, '<br />\n');
   } else {
     // Vanilla hard breaks
-    text = text.replace(/\b  +\n\b/g, '<br />\n');
+    text = text.replace(/  +\n/g, '<br />\n');
   }
 
   text = globals.converter._dispatch('spanGamut.after', text, options, globals);

+ 4 - 0
test/features/#318.simpleLineBreaks-does-not-work-with-chinese-characters.html

@@ -0,0 +1,4 @@
+<p>foo烫<br />
+bar</p>
+<p>foo<br />
+bar</p>

+ 5 - 0
test/features/#318.simpleLineBreaks-does-not-work-with-chinese-characters.md

@@ -0,0 +1,5 @@
+foo烫
+bar
+
+foo
+bar

+ 2 - 0
test/features/#323.simpleLineBreaks-breaks-with-strong.html

@@ -0,0 +1,2 @@
+<p><strong>Nom :</strong> aaaa<br />
+<strong>Nom :</strong> aaa</p>

+ 2 - 0
test/features/#323.simpleLineBreaks-breaks-with-strong.md

@@ -0,0 +1,2 @@
+**Nom :** aaaa
+**Nom :** aaa

+ 13 - 0
test/features/simpleLineBreaks2.html

@@ -0,0 +1,13 @@
+<ol>
+    <li><p>One</p></li>
+    <li><p>Two<br />
+        foo</p>
+        <p>bar<br />
+        bazinga</p>
+        <p>nhecos</p></li>
+    <li><p>Three</p>
+        <ul>
+        <li><p>foo</p></li>
+        <li><p>bar</p></li></ul></li>
+</ol>
+   

+ 18 - 0
test/features/simpleLineBreaks2.md

@@ -0,0 +1,18 @@
+ 1. One
+ 2. Two
+    foo
+    
+    bar
+    bazinga
+    
+    
+    
+    
+    nhecos
+    
+ 3. Three
+    
+    - foo
+    
+    - bar
+   

+ 6 - 0
test/node/testsuite.features.js

@@ -37,8 +37,14 @@ 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 === 'simpleLineBreaks2') {
+      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 === '#323.simpleLineBreaks-breaks-with-strong') {
+      converter = new showdown.Converter({simpleLineBreaks: true});
+    } else if (testsuite[i].name === '#318.simpleLineBreaks-does-not-work-with-chinese-characters') {
+      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') {

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно