Update handling of lists nested in blockquotes to improve MD007/ul-indent (fixes #266).

This commit is contained in:
David Anson 2020-03-21 13:17:34 -07:00
parent 742f2a8d79
commit 11ea2ad5f1
2 changed files with 55 additions and 1 deletions

View file

@ -254,6 +254,8 @@ module.exports.flattenLists = function flattenLists(params) {
const flattenedLists = [];
const stack = [];
let current = null;
let nesting = 0;
const nestingStack = [];
let lastWithMap = { "map": [ 0, 1 ] };
params.tokens.forEach(function forToken(token) {
if ((token.type === "bullet_list_open") ||
@ -268,10 +270,11 @@ module.exports.flattenLists = function flattenLists(params) {
"indent": indentFor(token),
"parentIndent": (current && current.indent) || 0,
"items": [],
"nesting": stack.length - 1,
"nesting": nesting,
"lastLineIndex": -1,
"insert": flattenedLists.length
};
nesting++;
} else if ((token.type === "bullet_list_close") ||
(token.type === "ordered_list_close")) {
// Finalize current context and restore previous
@ -279,9 +282,15 @@ module.exports.flattenLists = function flattenLists(params) {
flattenedLists.splice(current.insert, 0, current);
delete current.insert;
current = stack.pop();
nesting--;
} else if (token.type === "list_item_open") {
// Add list item
current.items.push(token);
} else if (token.type === "blockquote_open") {
nestingStack.push(nesting);
nesting = 0;
} else if (token.type === "blockquote_close") {
nesting = nestingStack.pop();
} else if (token.map) {
// Track last token with map
lastWithMap = token;

View file

@ -141,3 +141,48 @@ Text
> > - of items {MD004}
> >
> > More quoted text
Text
+ List
> blockquote in list
>
> + list in blockquote in list
Text
+ List
Text
> + list in blockquote
> + list in blockquote
Text
> + list in blockquote
Text
+ List
Text
> + list in blockquote
Text
+ List
> + list in blockquote
> + sublist in blockquote
> + list in blockquote
> + sublist in blockquote
Text
+ List
Text
> + list in blockquote
> + list in blockquote {MD005} {MD007}
> + list in blockquote
> + sublist in blockquote
> + sublist in blockquote {MD005} {MD007}