mirror of
https://github.com/showdownjs/showdown.git
synced 2024-03-22 13:30:55 +08:00
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:
parent
de7c37eaea
commit
b1c458a762
BIN
dist/showdown.js
vendored
BIN
dist/showdown.js
vendored
Binary file not shown.
BIN
dist/showdown.js.map
vendored
BIN
dist/showdown.js.map
vendored
Binary file not shown.
BIN
dist/showdown.min.js
vendored
BIN
dist/showdown.min.js
vendored
Binary file not shown.
BIN
dist/showdown.min.js.map
vendored
BIN
dist/showdown.min.js.map
vendored
Binary file not shown.
|
@ -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)
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
<p>foo烫<br />
|
||||||
|
bar</p>
|
||||||
|
<p>foo<br />
|
||||||
|
bar</p>
|
|
@ -0,0 +1,5 @@
|
||||||
|
foo烫
|
||||||
|
bar
|
||||||
|
|
||||||
|
foo
|
||||||
|
bar
|
|
@ -0,0 +1,2 @@
|
||||||
|
<p><strong>Nom :</strong> aaaa<br />
|
||||||
|
<strong>Nom :</strong> aaa</p>
|
|
@ -0,0 +1,2 @@
|
||||||
|
**Nom :** aaaa
|
||||||
|
**Nom :** aaa
|
13
test/features/simpleLineBreaks2.html
Normal file
13
test/features/simpleLineBreaks2.html
Normal 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>
|
||||||
|
|
18
test/features/simpleLineBreaks2.md
Normal file
18
test/features/simpleLineBreaks2.md
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
1. One
|
||||||
|
2. Two
|
||||||
|
foo
|
||||||
|
|
||||||
|
bar
|
||||||
|
bazinga
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
nhecos
|
||||||
|
|
||||||
|
3. Three
|
||||||
|
|
||||||
|
- foo
|
||||||
|
|
||||||
|
- bar
|
||||||
|
|
|
@ -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') {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user