Skip to content

Commit

Permalink
fix(simpleLineBreaks): fix simpleLineBreaks option not working with n…
Browse files Browse the repository at this point in the history
…on-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
  • Loading branch information
tivie committed Jan 6, 2017
1 parent de7c37e commit b1c458a
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 7 deletions.
8 changes: 6 additions & 2 deletions dist/showdown.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/showdown.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/showdown.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/showdown.min.js.map

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/subParsers/lists.js
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/subParsers/spanGamut.js
Expand Up @@ -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);
Expand Down
@@ -0,0 +1,4 @@
<p>foo烫<br />
bar</p>
<p>foo<br />
bar</p>
@@ -0,0 +1,5 @@
foo烫
bar

foo
bar
2 changes: 2 additions & 0 deletions test/features/#323.simpleLineBreaks-breaks-with-strong.html
@@ -0,0 +1,2 @@
<p><strong>Nom :</strong> aaaa<br />
<strong>Nom :</strong> aaa</p>
2 changes: 2 additions & 0 deletions test/features/#323.simpleLineBreaks-breaks-with-strong.md
@@ -0,0 +1,2 @@
**Nom :** aaaa
**Nom :** aaa
13 changes: 13 additions & 0 deletions 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 changes: 18 additions & 0 deletions test/features/simpleLineBreaks2.md
@@ -0,0 +1,18 @@
1. One
2. Two
foo

bar
bazinga




nhecos

3. Three

- foo

- bar

6 changes: 6 additions & 0 deletions test/node/testsuite.features.js
Expand Up @@ -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') {
Expand Down

0 comments on commit b1c458a

Please sign in to comment.