Skip to content

Commit

Permalink
Update MD027/no-multiple-space-blockquote to handle multiple lines of…
Browse files Browse the repository at this point in the history
… indented code inside a blockquote (fixes #1393).
  • Loading branch information
DavidAnson committed Oct 29, 2024
1 parent 368cb1b commit 0eedda0
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 4 deletions.
10 changes: 8 additions & 2 deletions demo/markdownlint-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4680,9 +4680,15 @@ module.exports = {
"tags": [ "blockquote", "whitespace", "indentation" ],
"parser": "micromark",
"function": function MD027(params, onError) {
const { tokens } = params.parsers.micromark;
for (const token of filterByTypesCached([ "linePrefix" ])) {
const siblings = token.parent?.children || params.parsers.micromark.tokens;
if (siblings[siblings.indexOf(token) - 1]?.type === "blockQuotePrefix") {
const parent = token.parent;
const codeIndented = parent?.type === "codeIndented";
const siblings = parent?.children || tokens;
if (
!codeIndented &&
(siblings[siblings.indexOf(token) - 1]?.type === "blockQuotePrefix")
) {
const { startColumn, startLine, text } = token;
const { length } = text;
const line = params.lines[startLine - 1];
Expand Down
10 changes: 8 additions & 2 deletions lib/md027.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ module.exports = {
"tags": [ "blockquote", "whitespace", "indentation" ],
"parser": "micromark",
"function": function MD027(params, onError) {
const { tokens } = params.parsers.micromark;
for (const token of filterByTypesCached([ "linePrefix" ])) {
const siblings = token.parent?.children || params.parsers.micromark.tokens;
if (siblings[siblings.indexOf(token) - 1]?.type === "blockQuotePrefix") {
const parent = token.parent;
const codeIndented = parent?.type === "codeIndented";
const siblings = parent?.children || tokens;
if (
!codeIndented &&
(siblings[siblings.indexOf(token) - 1]?.type === "blockQuotePrefix")
) {
const { startColumn, startLine, text } = token;
const { length } = text;
const line = params.lines[startLine - 1];
Expand Down
14 changes: 14 additions & 0 deletions test/blockquote_spaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,17 @@ Test nothing in the blockquote:

>
{MD027:-1}

<!-- markdownlint-disable code-block-style -->

> Blockquoted code blocks:
>
> Code
> Code
> Code
>
> ```text
> Code
> Code
> Code
> ```
14 changes: 14 additions & 0 deletions test/snapshots/markdownlint-test-scenarios.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -6825,6 +6825,20 @@ Generated by [AVA](https://avajs.dev).
> ␊
{MD027:-1}␊
<!-- markdownlint-disable code-block-style -->␊
> Blockquoted code blocks:␊
>␊
> Code␊
> Code␊
> Code␊
>␊
> \`\`\`text␊
> Code␊
> Code␊
> Code␊
> \`\`\`␊
`,
}

Expand Down
Binary file modified test/snapshots/markdownlint-test-scenarios.js.snap
Binary file not shown.

0 comments on commit 0eedda0

Please sign in to comment.