fix: fix list item with blank first line (#3351)
* fix: fix list item with blank first line * move blankline
This commit is contained in:
parent
b17ff8be46
commit
d28e4c65ea
@ -260,12 +260,12 @@ export class _Tokenizer {
|
|||||||
|
|
||||||
// Get next list item
|
// Get next list item
|
||||||
const itemRegex = new RegExp(`^( {0,3}${bull})((?:[\t ][^\\n]*)?(?:\\n|$))`);
|
const itemRegex = new RegExp(`^( {0,3}${bull})((?:[\t ][^\\n]*)?(?:\\n|$))`);
|
||||||
let raw = '';
|
|
||||||
let itemContents = '';
|
|
||||||
let endsWithBlankLine = false;
|
let endsWithBlankLine = false;
|
||||||
// Check if current bullet point can start a new List Item
|
// Check if current bullet point can start a new List Item
|
||||||
while (src) {
|
while (src) {
|
||||||
let endEarly = false;
|
let endEarly = false;
|
||||||
|
let raw = '';
|
||||||
|
let itemContents = '';
|
||||||
if (!(cap = itemRegex.exec(src))) {
|
if (!(cap = itemRegex.exec(src))) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -279,11 +279,14 @@ export class _Tokenizer {
|
|||||||
|
|
||||||
let line = cap[2].split('\n', 1)[0].replace(/^\t+/, (t: string) => ' '.repeat(3 * t.length));
|
let line = cap[2].split('\n', 1)[0].replace(/^\t+/, (t: string) => ' '.repeat(3 * t.length));
|
||||||
let nextLine = src.split('\n', 1)[0];
|
let nextLine = src.split('\n', 1)[0];
|
||||||
|
let blankLine = !line.trim();
|
||||||
|
|
||||||
let indent = 0;
|
let indent = 0;
|
||||||
if (this.options.pedantic) {
|
if (this.options.pedantic) {
|
||||||
indent = 2;
|
indent = 2;
|
||||||
itemContents = line.trimStart();
|
itemContents = line.trimStart();
|
||||||
|
} else if (blankLine) {
|
||||||
|
indent = cap[1].length + 1;
|
||||||
} else {
|
} else {
|
||||||
indent = cap[2].search(/[^ ]/); // Find first non-space char
|
indent = cap[2].search(/[^ ]/); // Find first non-space char
|
||||||
indent = indent > 4 ? 1 : indent; // Treat indented code blocks (> 4 spaces) as having only 1 indent
|
indent = indent > 4 ? 1 : indent; // Treat indented code blocks (> 4 spaces) as having only 1 indent
|
||||||
@ -291,9 +294,7 @@ export class _Tokenizer {
|
|||||||
indent += cap[1].length;
|
indent += cap[1].length;
|
||||||
}
|
}
|
||||||
|
|
||||||
let blankLine = false;
|
if (blankLine && /^ *$/.test(nextLine)) { // Items begin with at most one blank line
|
||||||
|
|
||||||
if (!line && /^ *$/.test(nextLine)) { // Items begin with at most one blank line
|
|
||||||
raw += nextLine + '\n';
|
raw += nextLine + '\n';
|
||||||
src = src.substring(nextLine.length + 1);
|
src = src.substring(nextLine.length + 1);
|
||||||
endEarly = true;
|
endEarly = true;
|
||||||
@ -404,8 +405,8 @@ export class _Tokenizer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Do not consume newlines at end of final item. Alternatively, make itemRegex *start* with any newlines to simplify/speed up endsWithBlankLine logic
|
// Do not consume newlines at end of final item. Alternatively, make itemRegex *start* with any newlines to simplify/speed up endsWithBlankLine logic
|
||||||
list.items[list.items.length - 1].raw = raw.trimEnd();
|
list.items[list.items.length - 1].raw = list.items[list.items.length - 1].raw.trimEnd();
|
||||||
(list.items[list.items.length - 1]).text = itemContents.trimEnd();
|
list.items[list.items.length - 1].text = list.items[list.items.length - 1].text.trimEnd();
|
||||||
list.raw = list.raw.trimEnd();
|
list.raw = list.raw.trimEnd();
|
||||||
|
|
||||||
// Item child tokens handled here at end because we needed to have the final item to trim it first
|
// Item child tokens handled here at end because we needed to have the final item to trim it first
|
||||||
|
8
test/specs/new/list_with_line_break.html
Normal file
8
test/specs/new/list_with_line_break.html
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<ol>
|
||||||
|
<li></li>
|
||||||
|
</ol>
|
||||||
|
<p>Monday
|
||||||
|
2.
|
||||||
|
Tuesday
|
||||||
|
3.
|
||||||
|
Wednesday</p>
|
6
test/specs/new/list_with_line_break.md
Normal file
6
test/specs/new/list_with_line_break.md
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
1.
|
||||||
|
Monday
|
||||||
|
2.
|
||||||
|
Tuesday
|
||||||
|
3.
|
||||||
|
Wednesday
|
Loading…
x
Reference in New Issue
Block a user