mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 05:50:13 +01:00
Allow opt-out for list items with blank lines in MD009/no-trailing-spaces (fixes #55).
This commit is contained in:
parent
b436640918
commit
d826833a82
7 changed files with 157 additions and 7 deletions
18
doc/Rules.md
18
doc/Rules.md
|
|
@ -254,20 +254,28 @@ Tags: whitespace
|
||||||
|
|
||||||
Aliases: no-trailing-spaces
|
Aliases: no-trailing-spaces
|
||||||
|
|
||||||
Parameters: br_spaces (number; default 0)
|
Parameters: br_spaces, list_item_empty_lines (number; default 0, boolean; default false)
|
||||||
|
|
||||||
This rule is triggered on any lines that end with whitespace. To fix this,
|
This rule is triggered on any lines that end with whitespace. To fix this,
|
||||||
find the line that is triggered and remove any trailing spaces from the end.
|
find the line that is triggered and remove any trailing spaces from the end.
|
||||||
|
|
||||||
The br_spaces parameter allows an exception to this rule for a specific amount
|
The `br_spaces` parameter allows an exception to this rule for a specific amount
|
||||||
of trailing spaces used to insert an explicit line break/br element. For
|
of trailing spaces used to insert an explicit line break/br element. For
|
||||||
example, set br_spaces to 2 to allow exactly 2 spaces at the end of a line.
|
example, set `br_spaces` to 2 to allow exactly 2 spaces at the end of a line.
|
||||||
|
|
||||||
Note: you have to set br_spaces to 2 or higher for this exception to take
|
Note: you have to set `br_spaces` to 2 or higher for this exception to take
|
||||||
effect - you can't insert a br element with just a single trailing space, so
|
effect - you can't insert a br element with just a single trailing space, so
|
||||||
if you set br_spaces to 1, the exception will be disabled, just as if it was
|
if you set `br_spaces` to 1, the exception will be disabled, just as if it was
|
||||||
set to the default of 0.
|
set to the default of 0.
|
||||||
|
|
||||||
|
Using spaces to indent blank lines inside a list item is usually not necessary,
|
||||||
|
but some parsers require it. Set the `list_item_empty_lines` parameter to `true`
|
||||||
|
to allow this:
|
||||||
|
|
||||||
|
- list item text
|
||||||
|
|
||||||
|
list item text
|
||||||
|
|
||||||
<a name="md010"></a>
|
<a name="md010"></a>
|
||||||
|
|
||||||
## MD010 - Hard tabs
|
## MD010 - Hard tabs
|
||||||
|
|
|
||||||
17
lib/rules.js
17
lib/rules.js
|
|
@ -353,10 +353,23 @@ module.exports = [
|
||||||
"regexp": trailingSpaceRe,
|
"regexp": trailingSpaceRe,
|
||||||
"func": function MD009(params, errors) {
|
"func": function MD009(params, errors) {
|
||||||
var brSpaces = params.options.br_spaces || 0;
|
var brSpaces = params.options.br_spaces || 0;
|
||||||
|
var listItemEmptyLines = params.options.list_item_empty_lines;
|
||||||
|
var allowListItemEmptyLines =
|
||||||
|
(listItemEmptyLines === undefined) ? false : !!listItemEmptyLines;
|
||||||
|
var listItemLineNumbers = [];
|
||||||
|
if (allowListItemEmptyLines) {
|
||||||
|
filterTokens(params, "list_item_open", function forToken(token) {
|
||||||
|
for (var i = token.map[0]; i < token.map[1]; i++) {
|
||||||
|
listItemLineNumbers.push(i + 1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
forEachLine(params, function forLine(line, lineIndex) {
|
forEachLine(params, function forLine(line, lineIndex) {
|
||||||
if (trailingSpaceRe.test(line)) {
|
var lineNumber = lineIndex + 1;
|
||||||
|
if (trailingSpaceRe.test(line) &&
|
||||||
|
(listItemLineNumbers.indexOf(lineNumber) === -1)) {
|
||||||
var expected = (brSpaces < 2) ? 0 : brSpaces;
|
var expected = (brSpaces < 2) ? 0 : brSpaces;
|
||||||
errors.addDetailIf(lineIndex + 1,
|
errors.addDetailIf(lineNumber,
|
||||||
expected, line.length - line.trimRight().length);
|
expected, line.length - line.trimRight().length);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -91,6 +91,11 @@ rules.forEach(function forRule(rule) {
|
||||||
"description": "Spaces for line break",
|
"description": "Spaces for line break",
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"default": 0
|
"default": 0
|
||||||
|
},
|
||||||
|
"list_item_empty_lines": {
|
||||||
|
"description": "Allow spaces for empty lines in list items",
|
||||||
|
"type": "boolean",
|
||||||
|
"default": false
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -207,6 +207,11 @@
|
||||||
"description": "Spaces for line break",
|
"description": "Spaces for line break",
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"default": 0
|
"default": 0
|
||||||
|
},
|
||||||
|
"list_item_empty_lines": {
|
||||||
|
"description": "Allow spaces for empty lines in list items",
|
||||||
|
"type": "boolean",
|
||||||
|
"default": false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": false
|
"additionalProperties": false
|
||||||
|
|
@ -223,6 +228,11 @@
|
||||||
"description": "Spaces for line break",
|
"description": "Spaces for line break",
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"default": 0
|
"default": 0
|
||||||
|
},
|
||||||
|
"list_item_empty_lines": {
|
||||||
|
"description": "Allow spaces for empty lines in list items",
|
||||||
|
"type": "boolean",
|
||||||
|
"default": false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": false
|
"additionalProperties": false
|
||||||
|
|
|
||||||
6
test/trailing-spaces-in-lists-allowed.json
Normal file
6
test/trailing-spaces-in-lists-allowed.json
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"default": true,
|
||||||
|
"MD009": {
|
||||||
|
"list_item_empty_lines": true
|
||||||
|
}
|
||||||
|
}
|
||||||
52
test/trailing-spaces-in-lists-allowed.md
Normal file
52
test/trailing-spaces-in-lists-allowed.md
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
# Heading
|
||||||
|
|
||||||
|
1. text
|
||||||
|
text
|
||||||
|
1. text
|
||||||
|
|
||||||
|
text
|
||||||
|
1. text
|
||||||
|
|
||||||
|
text
|
||||||
|
1. text
|
||||||
|
text
|
||||||
|
|
||||||
|
1. text
|
||||||
|
text
|
||||||
|
|
||||||
|
1. text
|
||||||
|
|
||||||
|
{MD009:16}
|
||||||
|
{MD009:18}
|
||||||
|
|
||||||
|
1. text
|
||||||
|
text
|
||||||
|
1. text
|
||||||
|
|
||||||
|
text
|
||||||
|
1. text
|
||||||
|
|
||||||
|
text
|
||||||
|
1. text
|
||||||
|
text
|
||||||
|
|
||||||
|
1. text
|
||||||
|
text
|
||||||
|
|
||||||
|
1. text
|
||||||
|
|
||||||
|
1. text
|
||||||
|
- text
|
||||||
|
|
||||||
|
text
|
||||||
|
- text
|
||||||
|
|
||||||
|
text
|
||||||
|
- text
|
||||||
|
text
|
||||||
|
|
||||||
|
- text
|
||||||
|
text
|
||||||
|
|
||||||
|
{MD009:37}
|
||||||
|
{MD009:50}
|
||||||
56
test/trailing-spaces-in-lists-default.md
Normal file
56
test/trailing-spaces-in-lists-default.md
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
# Heading
|
||||||
|
|
||||||
|
1. text
|
||||||
|
text
|
||||||
|
1. text
|
||||||
|
|
||||||
|
text
|
||||||
|
1. text
|
||||||
|
|
||||||
|
text
|
||||||
|
1. text
|
||||||
|
text
|
||||||
|
|
||||||
|
1. text
|
||||||
|
text
|
||||||
|
|
||||||
|
1. text
|
||||||
|
|
||||||
|
{MD009:9}
|
||||||
|
{MD009:16}
|
||||||
|
{MD009:18}
|
||||||
|
|
||||||
|
1. text
|
||||||
|
text
|
||||||
|
1. text
|
||||||
|
|
||||||
|
text
|
||||||
|
1. text
|
||||||
|
|
||||||
|
text
|
||||||
|
1. text
|
||||||
|
text
|
||||||
|
|
||||||
|
1. text
|
||||||
|
text
|
||||||
|
|
||||||
|
1. text
|
||||||
|
|
||||||
|
1. text
|
||||||
|
- text
|
||||||
|
|
||||||
|
text
|
||||||
|
- text
|
||||||
|
|
||||||
|
text
|
||||||
|
- text
|
||||||
|
text
|
||||||
|
|
||||||
|
- text
|
||||||
|
text
|
||||||
|
|
||||||
|
{MD009:29}
|
||||||
|
{MD009:36}
|
||||||
|
{MD009:38}
|
||||||
|
{MD009:44}
|
||||||
|
{MD009:51}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue