Skip to content

Commit

Permalink
Update MD027/no-multiple-space-blockquote to add a list_items paramet…
Browse files Browse the repository at this point in the history
…er (fixes #1473).
  • Loading branch information
DavidAnson committed Mar 4, 2025
1 parent d02090d commit 435c55f
Show file tree
Hide file tree
Showing 14 changed files with 333 additions and 14 deletions.
4 changes: 4 additions & 0 deletions doc-build/md027.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ To fix, remove any extraneous space:
> indentation.
```

Inferring intended list indentation within a blockquote can be challenging;
setting the `list_items` parameter to `false` disables this rule for ordered
and unordered list items.

Rationale: Consistent formatting makes it easier to understand a document.
8 changes: 8 additions & 0 deletions doc/Rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,10 @@ Tags: `blockquote`, `indentation`, `whitespace`

Aliases: `no-multiple-space-blockquote`

Parameters:

- `list_items`: Include list items (`boolean`, default `true`)

Fixable: Some violations can be fixed by tooling

This rule is triggered when blockquotes have more than one space after the
Expand All @@ -960,6 +964,10 @@ To fix, remove any extraneous space:
> indentation.
```

Inferring intended list indentation within a blockquote can be challenging;
setting the `list_items` parameter to `false` disables this rule for ordered
and unordered list items.

Rationale: Consistent formatting makes it easier to understand a document.

<a name="md028"></a>
Expand Down
8 changes: 8 additions & 0 deletions doc/md027.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Tags: `blockquote`, `indentation`, `whitespace`

Aliases: `no-multiple-space-blockquote`

Parameters:

- `list_items`: Include list items (`boolean`, default `true`)

Fixable: Some violations can be fixed by tooling

This rule is triggered when blockquotes have more than one space after the
Expand All @@ -21,4 +25,8 @@ To fix, remove any extraneous space:
> indentation.
```

Inferring intended list indentation within a blockquote can be challenging;
setting the `list_items` parameter to `false` disables this rule for ordered
and unordered list items.

Rationale: Consistent formatting makes it easier to understand a document.
18 changes: 16 additions & 2 deletions lib/configuration-strict.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,11 +470,25 @@ export interface ConfigurationStrict {
/**
* MD027/no-multiple-space-blockquote : Multiple spaces after blockquote symbol : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md027.md
*/
MD027?: boolean;
MD027?:
| boolean
| {
/**
* Include list items
*/
list_items?: boolean;
};
/**
* MD027/no-multiple-space-blockquote : Multiple spaces after blockquote symbol : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md027.md
*/
"no-multiple-space-blockquote"?: boolean;
"no-multiple-space-blockquote"?:
| boolean
| {
/**
* Include list items
*/
list_items?: boolean;
};
/**
* MD028/no-blanks-blockquote : Blank line inside blockquote : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md028.md
*/
Expand Down
12 changes: 11 additions & 1 deletion lib/md027.mjs
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
// @ts-check

import { addErrorContext } from "../helpers/helpers.cjs";
import { getParentOfType } from "../helpers/micromark-helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";

/** @type {import("../helpers/micromark-helpers.cjs").TokenType[]} */
const listTypes = [ "listOrdered", "listUnordered" ];

/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD027", "no-multiple-space-blockquote" ],
"description": "Multiple spaces after blockquote symbol",
"tags": [ "blockquote", "whitespace", "indentation" ],
"parser": "micromark",
"function": function MD027(params, onError) {
const listItems = params.config.list_items;
const includeListItems = (listItems === undefined) ? true : !!listItems;
const { tokens } = params.parsers.micromark;
for (const token of filterByTypesCached([ "linePrefix" ])) {
const parent = token.parent;
const codeIndented = parent?.type === "codeIndented";
const siblings = parent?.children || tokens;
if (
!codeIndented &&
(siblings[siblings.indexOf(token) - 1]?.type === "blockQuotePrefix")
(siblings[siblings.indexOf(token) - 1]?.type === "blockQuotePrefix") &&
(includeListItems || (
!listTypes.includes(siblings[siblings.indexOf(token) + 1]?.type) &&
!getParentOfType(token, listTypes)
))
) {
const { startColumn, startLine, text } = token;
const { length } = text;
Expand Down
5 changes: 4 additions & 1 deletion schema/.markdownlint.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@
},

// MD027/no-multiple-space-blockquote : Multiple spaces after blockquote symbol : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md027.md
"MD027": true,
"MD027": {
// Include list items
"list_items": true
},

// MD028/no-blanks-blockquote : Blank line inside blockquote : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md028.md
"MD028": true,
Expand Down
4 changes: 3 additions & 1 deletion schema/.markdownlint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ MD026:
punctuation: ".,;:!。,;:!"

# MD027/no-multiple-space-blockquote : Multiple spaces after blockquote symbol : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md027.md
MD027: true
MD027:
# Include list items
list_items: true

# MD028/no-blanks-blockquote : Blank line inside blockquote : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md028.md
MD028: true
Expand Down
9 changes: 9 additions & 0 deletions schema/build-config-schema.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,15 @@ for (const rule of rules) {
}
};
break;
case "MD027":
scheme.properties = {
"list_items": {
"description": "Include list items",
"type": "boolean",
"default": true
}
};
break;
case "MD029":
scheme.properties = {
"style": {
Expand Down
30 changes: 26 additions & 4 deletions schema/markdownlint-config-schema-strict.json
Original file line number Diff line number Diff line change
Expand Up @@ -723,13 +723,35 @@
},
"MD027": {
"description": "MD027/no-multiple-space-blockquote : Multiple spaces after blockquote symbol : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md027.md",
"type": "boolean",
"default": true
"type": [
"boolean",
"object"
],
"default": true,
"properties": {
"list_items": {
"description": "Include list items",
"type": "boolean",
"default": true
}
},
"additionalProperties": false
},
"no-multiple-space-blockquote": {
"description": "MD027/no-multiple-space-blockquote : Multiple spaces after blockquote symbol : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md027.md",
"type": "boolean",
"default": true
"type": [
"boolean",
"object"
],
"default": true,
"properties": {
"list_items": {
"description": "Include list items",
"type": "boolean",
"default": true
}
},
"additionalProperties": false
},
"MD028": {
"description": "MD028/no-blanks-blockquote : Blank line inside blockquote : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md028.md",
Expand Down
30 changes: 26 additions & 4 deletions schema/markdownlint-config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -723,13 +723,35 @@
},
"MD027": {
"description": "MD027/no-multiple-space-blockquote : Multiple spaces after blockquote symbol : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md027.md",
"type": "boolean",
"default": true
"type": [
"boolean",
"object"
],
"default": true,
"properties": {
"list_items": {
"description": "Include list items",
"type": "boolean",
"default": true
}
},
"additionalProperties": false
},
"no-multiple-space-blockquote": {
"description": "MD027/no-multiple-space-blockquote : Multiple spaces after blockquote symbol : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md027.md",
"type": "boolean",
"default": true
"type": [
"boolean",
"object"
],
"default": true,
"properties": {
"list_items": {
"description": "Include list items",
"type": "boolean",
"default": true
}
},
"additionalProperties": false
},
"MD028": {
"description": "MD028/no-blanks-blockquote : Blank line inside blockquote : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md028.md",
Expand Down
104 changes: 104 additions & 0 deletions test/lists-in-blockquote-start-indented-no-list-items.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Lists in Blockquote Start Indented

Text

+ Item
+ Item
more
item
+ Item
+ Item
+ Item
more
item
+ Item
+ Item
+ Item
+ Item
+ Item

Text

Code

Text

<!-- markdownlint-disable ul-indent -->

> Text
>
> + Item
> + Item
> more
> item
> + Item
> + Item
> + Item
> more
> item
> + Item
> + Item
> + Item
> + Item
> + Item
>
> Text
>
> Code
<!-- markdownlint-restore -->

Text

1. Item
1. Item
more
item
1. Item
1. Item
1. Item
more
item
1. Item
1. Item
1. Item
1. Item
1. Item

Text

Code

Text

> Text
>
> 1. Item
> 1. Item
> more
> item
> 1. Item
> 1. Item
> 1. Item
> more
> item
> 1. Item
> 1. Item
> 1. Item
> 1. Item
> 1. Item
>
> Text
>
> Code
Text

<!-- markdownlint-configure-file {
"no-multiple-space-blockquote": {
"list_items": false
},
"ul-indent": {
"start_indented": true
}
} -->
2 changes: 1 addition & 1 deletion test/markdownlint-test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ test("readme", async(t) => {
});

test("validateJsonUsingConfigSchemaStrict", async(t) => {
t.plan(186);
t.plan(187);
// @ts-ignore
const ajv = new Ajv(ajvOptions);
const validateSchemaStrict = ajv.compile(configSchemaStrict);
Expand Down
Loading

0 comments on commit 435c55f

Please sign in to comment.