From 09ae51fdaa8141bf197a7d359a1c1021d10fc9a5 Mon Sep 17 00:00:00 2001 From: David Anson Date: Thu, 27 Oct 2016 22:09:05 -0700 Subject: [PATCH] Improve reporting of MD027 for lists in blockquotes. --- lib/rules.js | 10 +++++++++- test/lists-in-blockquote.md | 16 ++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/lib/rules.js b/lib/rules.js index bb58717c..3a991f11 100644 --- a/lib/rules.js +++ b/lib/rules.js @@ -599,13 +599,21 @@ module.exports = [ "aliases": [ "no-multiple-space-blockquote" ], "func": function MD027(params, errors) { var blockquoteNesting = 0; + var listItemNesting = 0; params.tokens.forEach(function forToken(token) { if (token.type === "blockquote_open") { blockquoteNesting++; } else if (token.type === "blockquote_close") { blockquoteNesting--; + } else if (token.type === "list_item_open") { + listItemNesting++; + } else if (token.type === "list_item_close") { + listItemNesting--; } else if ((token.type === "inline") && (blockquoteNesting > 0)) { - if (/^(\s*>)+\s\s/.test(token.line)) { + var multipleSpaces = listItemNesting ? + /^(\s*>)+\s\s+>/.test(token.line) : + /^(\s*>)+\s\s/.test(token.line); + if (multipleSpaces) { errors.addContext(token.lineNumber, token.line); } token.content.split(shared.newLineRe) diff --git a/test/lists-in-blockquote.md b/test/lists-in-blockquote.md index f34d9864..6c949ded 100644 --- a/test/lists-in-blockquote.md +++ b/test/lists-in-blockquote.md @@ -25,26 +25,26 @@ Text Text > 1. Item -> 1. Item {MD027} +> 1. Item Text > - Item -> - Item {MD027} +> - Item Text > 1. Item - > 1. Item {MD027} - > 1. Item {MD027} {MD030} + > 1. Item + > 1. Item {MD030} Text > * Item - > * Item {MD027} - > * Item {MD027} {MD030} - > * Item {MD027} {MD005} - > * Item {MD027} {MD005} + > * Item + > * Item {MD030} + > * Item {MD005} + > * Item {MD005} Text