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
This commit is contained in:
Estevao Soares dos Santos 2017-01-06 03:51:12 +00:00
parent de7c37eaea
commit b1c458a762
13 changed files with 56 additions and 2 deletions

BIN
dist/showdown.js vendored

Binary file not shown.

BIN
dist/showdown.js.map vendored

Binary file not shown.

BIN
dist/showdown.min.js vendored

Binary file not shown.

Binary file not shown.

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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>

View File

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

View File

@ -37,8 +37,14 @@ describe('makeHtml() features testsuite', function () {
converter = new showdown.Converter({disableForced4SpacesIndentedSublists: true}); converter = new showdown.Converter({disableForced4SpacesIndentedSublists: true});
} else if (testsuite[i].name === '#206.treat-single-line-breaks-as-br') { } else if (testsuite[i].name === '#206.treat-single-line-breaks-as-br') {
converter = new showdown.Converter({simpleLineBreaks: true}); 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') { } else if (testsuite[i].name === '#316.new-simpleLineBreaks-option-breaks-lists') {
converter = new showdown.Converter({simpleLineBreaks: true}); 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') { } else if (testsuite[i].name === 'excludeTrailingPunctuationFromURLs-option') {
converter = new showdown.Converter({simplifiedAutoLink: true, excludeTrailingPunctuationFromURLs: true}); converter = new showdown.Converter({simplifiedAutoLink: true, excludeTrailingPunctuationFromURLs: true});
} else if (testsuite[i].name === 'requireSpaceBeforeHeadingText') { } else if (testsuite[i].name === 'requireSpaceBeforeHeadingText') {