mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 14:00:13 +01:00
Update handling of lists nested in blockquotes to improve MD007/ul-indent (fixes #266).
This commit is contained in:
parent
742f2a8d79
commit
11ea2ad5f1
2 changed files with 55 additions and 1 deletions
|
|
@ -254,6 +254,8 @@ module.exports.flattenLists = function flattenLists(params) {
|
||||||
const flattenedLists = [];
|
const flattenedLists = [];
|
||||||
const stack = [];
|
const stack = [];
|
||||||
let current = null;
|
let current = null;
|
||||||
|
let nesting = 0;
|
||||||
|
const nestingStack = [];
|
||||||
let lastWithMap = { "map": [ 0, 1 ] };
|
let lastWithMap = { "map": [ 0, 1 ] };
|
||||||
params.tokens.forEach(function forToken(token) {
|
params.tokens.forEach(function forToken(token) {
|
||||||
if ((token.type === "bullet_list_open") ||
|
if ((token.type === "bullet_list_open") ||
|
||||||
|
|
@ -268,10 +270,11 @@ module.exports.flattenLists = function flattenLists(params) {
|
||||||
"indent": indentFor(token),
|
"indent": indentFor(token),
|
||||||
"parentIndent": (current && current.indent) || 0,
|
"parentIndent": (current && current.indent) || 0,
|
||||||
"items": [],
|
"items": [],
|
||||||
"nesting": stack.length - 1,
|
"nesting": nesting,
|
||||||
"lastLineIndex": -1,
|
"lastLineIndex": -1,
|
||||||
"insert": flattenedLists.length
|
"insert": flattenedLists.length
|
||||||
};
|
};
|
||||||
|
nesting++;
|
||||||
} else if ((token.type === "bullet_list_close") ||
|
} else if ((token.type === "bullet_list_close") ||
|
||||||
(token.type === "ordered_list_close")) {
|
(token.type === "ordered_list_close")) {
|
||||||
// Finalize current context and restore previous
|
// Finalize current context and restore previous
|
||||||
|
|
@ -279,9 +282,15 @@ module.exports.flattenLists = function flattenLists(params) {
|
||||||
flattenedLists.splice(current.insert, 0, current);
|
flattenedLists.splice(current.insert, 0, current);
|
||||||
delete current.insert;
|
delete current.insert;
|
||||||
current = stack.pop();
|
current = stack.pop();
|
||||||
|
nesting--;
|
||||||
} else if (token.type === "list_item_open") {
|
} else if (token.type === "list_item_open") {
|
||||||
// Add list item
|
// Add list item
|
||||||
current.items.push(token);
|
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) {
|
} else if (token.map) {
|
||||||
// Track last token with map
|
// Track last token with map
|
||||||
lastWithMap = token;
|
lastWithMap = token;
|
||||||
|
|
|
||||||
|
|
@ -141,3 +141,48 @@ Text
|
||||||
> > - of items {MD004}
|
> > - of items {MD004}
|
||||||
> >
|
> >
|
||||||
> > More quoted text
|
> > 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}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue