mirror of https://github.com/showdownjs/showdown
fix(headings): inconsistent behavior in lists
In text, headings only require a single linebreak to be treated as such. However, in lists, they would require a double linebreak. Now, the behavior in lists and text is consistent, requiring only a single linebreak. Closes #495pull/587/head
parent
d9eea64794
commit
26abc7a795
|
@ -1,4 +1,4 @@
|
|||
;/*! showdown v 2.0.0-alpha1 - 14-09-2018 */
|
||||
;/*! showdown v 2.0.0-alpha1 - 15-09-2018 */
|
||||
(function(){
|
||||
/**
|
||||
* Created by Tivie on 13-07-2015.
|
||||
|
@ -3387,11 +3387,6 @@ showdown.subParser('makehtml.italicsAndBold', function (text, options, globals)
|
|||
// called "catastrophic backtrace". Ominous!
|
||||
|
||||
function parseInside (txt, left, right) {
|
||||
/*
|
||||
if (options.simplifiedAutoLink) {
|
||||
txt = showdown.subParser('simplifiedAutoLinks')(txt, options, globals);
|
||||
}
|
||||
*/
|
||||
return left + txt + right;
|
||||
}
|
||||
|
||||
|
@ -3497,6 +3492,7 @@ showdown.subParser('makehtml.lists', function (text, options, globals) {
|
|||
// Since version 1.5, nesting sublists requires 4 spaces (or 1 tab) indentation,
|
||||
// which is a syntax breaking change
|
||||
// activating this option reverts to old behavior
|
||||
// This will be removed in version 2.0
|
||||
if (options.disableForced4SpacesIndentedSublists) {
|
||||
rgx = /(\n)?(^ {0,3})([*+-]|\d+[.])[ \t]+((\[(x|X| )?])?[ \t]*[^\r]+?(\n{1,2}))(?=\n*(¨0|\2([*+-]|\d+[.])[ \t]+))/gm;
|
||||
}
|
||||
|
@ -3532,13 +3528,25 @@ showdown.subParser('makehtml.lists', function (text, options, globals) {
|
|||
return '¨A' + wm2;
|
||||
});
|
||||
|
||||
// SPECIAL CASE: an heading followed by a paragraph of text that is not separated by a double newline
|
||||
// or/nor indented. ex:
|
||||
//
|
||||
// - # foo
|
||||
// bar is great
|
||||
//
|
||||
// While this does now follow the spec per se, not allowing for this might cause confusion since
|
||||
// header blocks don't need double newlines after
|
||||
if (/^#+.+\n.+/.test(item)) {
|
||||
item = item.replace(/^(#+.+)$/m, '$1\n');
|
||||
}
|
||||
|
||||
// m1 - Leading line or
|
||||
// Has a double return (multi paragraph) or
|
||||
// Has sublist
|
||||
// Has a double return (multi paragraph)
|
||||
if (m1 || (item.search(/\n{2,}/) > -1)) {
|
||||
item = showdown.subParser('makehtml.githubCodeBlocks')(item, options, globals);
|
||||
item = showdown.subParser('makehtml.blockGamut')(item, options, globals);
|
||||
} else {
|
||||
|
||||
// Recursion for sub-lists:
|
||||
item = showdown.subParser('makehtml.lists')(item, options, globals);
|
||||
item = item.replace(/\n$/, ''); // chomp(item)
|
||||
|
@ -3546,6 +3554,7 @@ showdown.subParser('makehtml.lists', function (text, options, globals) {
|
|||
|
||||
// Colapse double linebreaks
|
||||
item = item.replace(/\n\n+/g, '\n\n');
|
||||
|
||||
if (isParagraphed) {
|
||||
item = showdown.subParser('makehtml.paragraphs')(item, options, globals);
|
||||
} else {
|
||||
|
@ -3625,26 +3634,25 @@ showdown.subParser('makehtml.lists', function (text, options, globals) {
|
|||
return result;
|
||||
}
|
||||
|
||||
/** Start of list parsing **/
|
||||
// Start of list parsing
|
||||
var subListRgx = /^(( {0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(¨0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/gm;
|
||||
var mainListRgx = /(\n\n|^\n?)(( {0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(¨0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/gm;
|
||||
|
||||
text = globals.converter._dispatch('lists.before', text, options, globals).getText();
|
||||
// add sentinel to hack around khtml/safari bug:
|
||||
// http://bugs.webkit.org/show_bug.cgi?id=11231
|
||||
text += '¨0';
|
||||
|
||||
if (globals.gListLevel) {
|
||||
text = text.replace(/^(( {0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(¨0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/gm,
|
||||
function (wholeMatch, list, m2) {
|
||||
var listType = (m2.search(/[*+-]/g) > -1) ? 'ul' : 'ol';
|
||||
return parseConsecutiveLists(list, listType, true);
|
||||
}
|
||||
);
|
||||
text = text.replace(subListRgx, function (wholeMatch, list, m2) {
|
||||
var listType = (m2.search(/[*+-]/g) > -1) ? 'ul' : 'ol';
|
||||
return parseConsecutiveLists(list, listType, true);
|
||||
});
|
||||
} else {
|
||||
text = text.replace(/(\n\n|^\n?)(( {0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(¨0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/gm,
|
||||
function (wholeMatch, m1, list, m3) {
|
||||
var listType = (m3.search(/[*+-]/g) > -1) ? 'ul' : 'ol';
|
||||
return parseConsecutiveLists(list, listType, false);
|
||||
}
|
||||
);
|
||||
text = text.replace(mainListRgx, function (wholeMatch, m1, list, m3) {
|
||||
var listType = (m3.search(/[*+-]/g) > -1) ? 'ul' : 'ol';
|
||||
return parseConsecutiveLists(list, listType, false);
|
||||
});
|
||||
}
|
||||
|
||||
// strip sentinel
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -46,6 +46,7 @@ showdown.subParser('makehtml.lists', function (text, options, globals) {
|
|||
// Since version 1.5, nesting sublists requires 4 spaces (or 1 tab) indentation,
|
||||
// which is a syntax breaking change
|
||||
// activating this option reverts to old behavior
|
||||
// This will be removed in version 2.0
|
||||
if (options.disableForced4SpacesIndentedSublists) {
|
||||
rgx = /(\n)?(^ {0,3})([*+-]|\d+[.])[ \t]+((\[(x|X| )?])?[ \t]*[^\r]+?(\n{1,2}))(?=\n*(¨0|\2([*+-]|\d+[.])[ \t]+))/gm;
|
||||
}
|
||||
|
@ -81,13 +82,25 @@ showdown.subParser('makehtml.lists', function (text, options, globals) {
|
|||
return '¨A' + wm2;
|
||||
});
|
||||
|
||||
// SPECIAL CASE: an heading followed by a paragraph of text that is not separated by a double newline
|
||||
// or/nor indented. ex:
|
||||
//
|
||||
// - # foo
|
||||
// bar is great
|
||||
//
|
||||
// While this does now follow the spec per se, not allowing for this might cause confusion since
|
||||
// header blocks don't need double newlines after
|
||||
if (/^#+.+\n.+/.test(item)) {
|
||||
item = item.replace(/^(#+.+)$/m, '$1\n');
|
||||
}
|
||||
|
||||
// m1 - Leading line or
|
||||
// Has a double return (multi paragraph) or
|
||||
// Has sublist
|
||||
// Has a double return (multi paragraph)
|
||||
if (m1 || (item.search(/\n{2,}/) > -1)) {
|
||||
item = showdown.subParser('makehtml.githubCodeBlocks')(item, options, globals);
|
||||
item = showdown.subParser('makehtml.blockGamut')(item, options, globals);
|
||||
} else {
|
||||
|
||||
// Recursion for sub-lists:
|
||||
item = showdown.subParser('makehtml.lists')(item, options, globals);
|
||||
item = item.replace(/\n$/, ''); // chomp(item)
|
||||
|
@ -95,6 +108,7 @@ showdown.subParser('makehtml.lists', function (text, options, globals) {
|
|||
|
||||
// Colapse double linebreaks
|
||||
item = item.replace(/\n\n+/g, '\n\n');
|
||||
|
||||
if (isParagraphed) {
|
||||
item = showdown.subParser('makehtml.paragraphs')(item, options, globals);
|
||||
} else {
|
||||
|
@ -174,26 +188,25 @@ showdown.subParser('makehtml.lists', function (text, options, globals) {
|
|||
return result;
|
||||
}
|
||||
|
||||
/** Start of list parsing **/
|
||||
// Start of list parsing
|
||||
var subListRgx = /^(( {0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(¨0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/gm;
|
||||
var mainListRgx = /(\n\n|^\n?)(( {0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(¨0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/gm;
|
||||
|
||||
text = globals.converter._dispatch('lists.before', text, options, globals).getText();
|
||||
// add sentinel to hack around khtml/safari bug:
|
||||
// http://bugs.webkit.org/show_bug.cgi?id=11231
|
||||
text += '¨0';
|
||||
|
||||
if (globals.gListLevel) {
|
||||
text = text.replace(/^(( {0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(¨0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/gm,
|
||||
function (wholeMatch, list, m2) {
|
||||
var listType = (m2.search(/[*+-]/g) > -1) ? 'ul' : 'ol';
|
||||
return parseConsecutiveLists(list, listType, true);
|
||||
}
|
||||
);
|
||||
text = text.replace(subListRgx, function (wholeMatch, list, m2) {
|
||||
var listType = (m2.search(/[*+-]/g) > -1) ? 'ul' : 'ol';
|
||||
return parseConsecutiveLists(list, listType, true);
|
||||
});
|
||||
} else {
|
||||
text = text.replace(/(\n\n|^\n?)(( {0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(¨0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/gm,
|
||||
function (wholeMatch, m1, list, m3) {
|
||||
var listType = (m3.search(/[*+-]/g) > -1) ? 'ul' : 'ol';
|
||||
return parseConsecutiveLists(list, listType, false);
|
||||
}
|
||||
);
|
||||
text = text.replace(mainListRgx, function (wholeMatch, m1, list, m3) {
|
||||
var listType = (m3.search(/[*+-]/g) > -1) ? 'ul' : 'ol';
|
||||
return parseConsecutiveLists(list, listType, false);
|
||||
});
|
||||
}
|
||||
|
||||
// strip sentinel
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
<ul>
|
||||
<li>Increase the number of water changes.</li>
|
||||
<li><h1 id="proteinskimmers">Protein skimmers:</h1>
|
||||
<p>This remove dissolved</p></li>
|
||||
<li><h1 id="chemicalfiltermedia">Chemical filter media:</h1>
|
||||
<p>When placed in your filter</p></li>
|
||||
<li>#</li>
|
||||
<li>something</li>
|
||||
<li>#
|
||||
something</li>
|
||||
<li># something</li>
|
||||
</ul>
|
|
@ -0,0 +1,10 @@
|
|||
- Increase the number of water changes.
|
||||
- # Protein skimmers:
|
||||
This remove dissolved
|
||||
- # Chemical filter media:
|
||||
When placed in your filter
|
||||
- #
|
||||
- something
|
||||
- #
|
||||
something
|
||||
- \# something
|
Loading…
Reference in New Issue