From 84ff8bb6164d494f5d70fe58443ac226fafed07a Mon Sep 17 00:00:00 2001 From: OHTAKE Tomohiro Date: Wed, 7 Sep 2016 17:09:13 +0900 Subject: [PATCH 1/4] MD029 and MD030 should allow ordered list in blockquote --- lib/rules.js | 6 +++--- test/ordered_list_in_blockquote.md | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 test/ordered_list_in_blockquote.md diff --git a/lib/rules.js b/lib/rules.js index 7c59e0d1..8b316de0 100644 --- a/lib/rules.js +++ b/lib/rules.js @@ -622,7 +622,7 @@ module.exports = [ if (!list.unordered) { var number = 1; list.items.forEach(function forItem(item) { - var re = new RegExp("^\\s*" + String(number) + "\\."); + var re = new RegExp("^(\\s|> )*" + String(number) + "\\."); if (!re.test(item.line)) { errors.push(item.lineNumber); } @@ -652,8 +652,8 @@ module.exports = [ (allSingle ? ulSingle : ulMulti) : (allSingle ? olSingle : olMulti); list.items.forEach(function forItem(item) { - var match = /^\s*\S+(\s+)/.exec(item.line); - if (!match || (match[1].length !== expectedSpaces)) { + var match = /^(\s|> )*\S+(\s+)/.exec(item.line); + if (!match || (match[2].length !== expectedSpaces)) { errors.push(item.lineNumber); } }); diff --git a/test/ordered_list_in_blockquote.md b/test/ordered_list_in_blockquote.md new file mode 100644 index 00000000..1cc5d916 --- /dev/null +++ b/test/ordered_list_in_blockquote.md @@ -0,0 +1,9 @@ +> 1. The simplest ordered list in blockquote + +1. ol + + > 1. ol-li-blockquote-ol-li + > 1. ol-li-blockquote-ol-li-ol-li {MD027} + +> 1. blockquote-ol-li +> 1. blockquote-ol-li-ol-li {MD027} From cbfdff227e27cd90120945491dcc3ff497cc4332 Mon Sep 17 00:00:00 2001 From: OHTAKE Tomohiro Date: Fri, 9 Sep 2016 10:30:22 +0900 Subject: [PATCH 2/4] MD027 should support blockquote nesting --- lib/rules.js | 10 +++++----- test/blockquote_spaces.md | 8 ++++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/rules.js b/lib/rules.js index 8b316de0..3cfee2e9 100644 --- a/lib/rules.js +++ b/lib/rules.js @@ -575,17 +575,17 @@ module.exports = [ "tags": [ "blockquote", "whitespace", "indentation" ], "aliases": [ "no-multiple-space-blockquote" ], "func": function MD027(params, errors) { - var inBlockquote = false; + var blockquoteNesting = 0; params.tokens.forEach(function forToken(token) { if (token.type === "blockquote_open") { - inBlockquote = true; + blockquoteNesting++; } else if (token.type === "blockquote_close") { - inBlockquote = false; - } else if ((token.type === "inline") && inBlockquote) { + blockquoteNesting--; + } else if ((token.type === "inline") && blockquoteNesting > 0) { token.content.split(shared.newLineRe) .forEach(function forLine(line, offset) { if (/^\s/.test(line) || - (!offset && /^\s*>\s\s/.test(token.line))) { + (!offset && /^(\s*>)+\s\s/.test(token.line))) { errors.push(token.lineNumber + offset); } }); diff --git a/test/blockquote_spaces.md b/test/blockquote_spaces.md index 084c27ad..a17bd054 100644 --- a/test/blockquote_spaces.md +++ b/test/blockquote_spaces.md @@ -21,3 +21,11 @@ Test the first line being indented too much: > Foo {MD027} > Bar {MD027} > Baz + +Nested blockquote + +> A {MD027} +> +> > B {MD027} +> +> C {MD027} From 0c685092666e3fc4c812b8bd27e13b04a52a6edf Mon Sep 17 00:00:00 2001 From: David Anson Date: Sat, 10 Sep 2016 14:46:35 -0700 Subject: [PATCH 3/4] Update new tests to preserve '_' for tests from Ruby and '-' for tests only in Node. --- test/blockquote-spaces-nested.md | 7 +++++++ test/blockquote_spaces.md | 8 -------- ...ist_in_blockquote.md => ordered-list-in-blockquote.md} | 2 ++ 3 files changed, 9 insertions(+), 8 deletions(-) create mode 100644 test/blockquote-spaces-nested.md rename test/{ordered_list_in_blockquote.md => ordered-list-in-blockquote.md} (86%) diff --git a/test/blockquote-spaces-nested.md b/test/blockquote-spaces-nested.md new file mode 100644 index 00000000..3517bf9b --- /dev/null +++ b/test/blockquote-spaces-nested.md @@ -0,0 +1,7 @@ +# Nested blockquote + +> A {MD027} +> +> > B {MD027} +> +> C {MD027} diff --git a/test/blockquote_spaces.md b/test/blockquote_spaces.md index a17bd054..084c27ad 100644 --- a/test/blockquote_spaces.md +++ b/test/blockquote_spaces.md @@ -21,11 +21,3 @@ Test the first line being indented too much: > Foo {MD027} > Bar {MD027} > Baz - -Nested blockquote - -> A {MD027} -> -> > B {MD027} -> -> C {MD027} diff --git a/test/ordered_list_in_blockquote.md b/test/ordered-list-in-blockquote.md similarity index 86% rename from test/ordered_list_in_blockquote.md rename to test/ordered-list-in-blockquote.md index 1cc5d916..3818e108 100644 --- a/test/ordered_list_in_blockquote.md +++ b/test/ordered-list-in-blockquote.md @@ -1,3 +1,5 @@ +# Ordered list in blockquote + > 1. The simplest ordered list in blockquote 1. ol From 256e5a7e738dfb3f55bd506b594ecc3fd42233e0 Mon Sep 17 00:00:00 2001 From: David Anson Date: Sat, 10 Sep 2016 19:23:50 -0700 Subject: [PATCH 4/4] Add more tests for recent changes, handle additional edge cases. --- lib/rules.js | 11 ++--- test/blockquote-spaces-nested.md | 52 ++++++++++++++++++++++++ test/lists-in-blockquote.md | 64 ++++++++++++++++++++++++++++++ test/ordered-list-in-blockquote.md | 11 ----- 4 files changed, 122 insertions(+), 16 deletions(-) create mode 100644 test/lists-in-blockquote.md delete mode 100644 test/ordered-list-in-blockquote.md diff --git a/lib/rules.js b/lib/rules.js index 3cfee2e9..20ba2921 100644 --- a/lib/rules.js +++ b/lib/rules.js @@ -4,7 +4,8 @@ var shared = require("./shared"); // Returns the indent for a token function indentFor(token) { - return token.line.length - token.line.trimLeft().length; + var line = token.line.replace(/^[\s>]*(> |>)/, ""); + return line.length - line.trimLeft().length; } // Returns the heading style for a heading token @@ -581,7 +582,7 @@ module.exports = [ blockquoteNesting++; } else if (token.type === "blockquote_close") { blockquoteNesting--; - } else if ((token.type === "inline") && blockquoteNesting > 0) { + } else if ((token.type === "inline") && (blockquoteNesting > 0)) { token.content.split(shared.newLineRe) .forEach(function forLine(line, offset) { if (/^\s/.test(line) || @@ -622,7 +623,7 @@ module.exports = [ if (!list.unordered) { var number = 1; list.items.forEach(function forItem(item) { - var re = new RegExp("^(\\s|> )*" + String(number) + "\\."); + var re = new RegExp("^[\\s>]*" + String(number) + "\\."); if (!re.test(item.line)) { errors.push(item.lineNumber); } @@ -652,8 +653,8 @@ module.exports = [ (allSingle ? ulSingle : ulMulti) : (allSingle ? olSingle : olMulti); list.items.forEach(function forItem(item) { - var match = /^(\s|> )*\S+(\s+)/.exec(item.line); - if (!match || (match[2].length !== expectedSpaces)) { + var match = /^[\s>]*\S+(\s+)/.exec(item.line); + if (!match || (match[1].length !== expectedSpaces)) { errors.push(item.lineNumber); } }); diff --git a/test/blockquote-spaces-nested.md b/test/blockquote-spaces-nested.md index 3517bf9b..3d4a1ab9 100644 --- a/test/blockquote-spaces-nested.md +++ b/test/blockquote-spaces-nested.md @@ -5,3 +5,55 @@ > > B {MD027} > > C {MD027} + +Text + +> A {MD027} +> +> > B {MD027} +> > +> > > C {MD027} +> > +> > D {MD027} +> +> E {MD027} + +Text + +> A {MD027} +> +>> B {MD027} +>> +>>> C {MD027} +>> +>> D {MD027} +> +> E {MD027} + +Text + +> > Text {MD027} + +Text + + > > Text {MD027} + +Text + + > > Text {MD027} + +Text + +> > Text {MD027} + +Text + +> > > Text {MD027} + +Text + +> > > > Text {MD027} + +Text + +>> >> Text {MD027} diff --git a/test/lists-in-blockquote.md b/test/lists-in-blockquote.md new file mode 100644 index 00000000..f34d9864 --- /dev/null +++ b/test/lists-in-blockquote.md @@ -0,0 +1,64 @@ +# Lists in blockquote + +> 1. The simplest ordered list in blockquote + +Text + +> + The simplest unordered list in blockquote + +Text + +>1. Item + +Text + +>+ Item + +Text + +>1. Item {MD030} + +Text + +>+ Item {MD030} + +Text + +> 1. Item +> 1. Item {MD027} + +Text + +> - Item +> - Item {MD027} + +Text + + > 1. Item + > 1. Item {MD027} + > 1. Item {MD027} {MD030} + +Text + + > * Item + > * Item {MD027} + > * Item {MD027} {MD030} + > * Item {MD027} {MD005} + > * Item {MD027} {MD005} + +Text + + > Text + > > - Item + > > - Item {MD027} + > > - Item + > > > - Item + > > > - Item {MD027} + > > > - Item {MD027} + +Text + +>* Item +> * Item +>>* Item +>> * Item diff --git a/test/ordered-list-in-blockquote.md b/test/ordered-list-in-blockquote.md deleted file mode 100644 index 3818e108..00000000 --- a/test/ordered-list-in-blockquote.md +++ /dev/null @@ -1,11 +0,0 @@ -# Ordered list in blockquote - -> 1. The simplest ordered list in blockquote - -1. ol - - > 1. ol-li-blockquote-ol-li - > 1. ol-li-blockquote-ol-li-ol-li {MD027} - -> 1. blockquote-ol-li -> 1. blockquote-ol-li-ol-li {MD027}