mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01:00
Add headers parameter to MD013/line-length (fixes #35).
This commit is contained in:
parent
16dc230d54
commit
00171da565
6 changed files with 56 additions and 4 deletions
|
|
@ -334,7 +334,7 @@ Tags: line_length
|
||||||
|
|
||||||
Aliases: line-length
|
Aliases: line-length
|
||||||
|
|
||||||
Parameters: line_length, code_blocks, tables (number; default 80, boolean; default true)
|
Parameters: line_length, code_blocks, tables, headers (number; default 80, boolean; default true)
|
||||||
|
|
||||||
This rule is triggered when there are lines that are longer than the
|
This rule is triggered when there are lines that are longer than the
|
||||||
configured line length (default: 80 characters). To fix this, split the line
|
configured line length (default: 80 characters). To fix this, split the line
|
||||||
|
|
@ -344,8 +344,8 @@ This rule has an exception where there is no whitespace beyond the configured
|
||||||
line length. This allows you to still include items such as long URLs without
|
line length. This allows you to still include items such as long URLs without
|
||||||
being forced to break them in the middle.
|
being forced to break them in the middle.
|
||||||
|
|
||||||
You also have the option to exclude this rule for code blocks and tables. To
|
You have the option to exclude this rule for code blocks, tables, or headers.
|
||||||
do this, set the `code_blocks` and/or `tables` parameters to false.
|
To do so, set the `code_blocks`, `tables`, or `headers` parameter(s) to false.
|
||||||
|
|
||||||
Code blocks are included in this rule by default since it is often a
|
Code blocks are included in this rule by default since it is often a
|
||||||
requirement for document readability, and tentatively compatible with code
|
requirement for document readability, and tentatively compatible with code
|
||||||
|
|
|
||||||
12
lib/rules.js
12
lib/rules.js
|
|
@ -427,13 +427,23 @@ module.exports = [
|
||||||
var includeCodeBlocks = (codeBlocks === undefined) ? true : !!codeBlocks;
|
var includeCodeBlocks = (codeBlocks === undefined) ? true : !!codeBlocks;
|
||||||
var tables = params.options.tables;
|
var tables = params.options.tables;
|
||||||
var includeTables = (tables === undefined) ? true : !!tables;
|
var includeTables = (tables === undefined) ? true : !!tables;
|
||||||
|
var headers = params.options.headers;
|
||||||
|
var includeHeaders = (headers === undefined) ? true : !!headers;
|
||||||
|
var headerLineNumbers = [];
|
||||||
|
if (!includeHeaders) {
|
||||||
|
forEachHeading(params, function forHeading(heading) {
|
||||||
|
headerLineNumbers.push(heading.lineNumber);
|
||||||
|
});
|
||||||
|
}
|
||||||
var re = longLineReFunc(params.options);
|
var re = longLineReFunc(params.options);
|
||||||
forEachLine(params,
|
forEachLine(params,
|
||||||
function forLine(line, lineIndex, inCode, onFence, inTable) {
|
function forLine(line, lineIndex, inCode, onFence, inTable) {
|
||||||
|
var lineNumber = lineIndex + 1;
|
||||||
if ((includeCodeBlocks || !inCode) &&
|
if ((includeCodeBlocks || !inCode) &&
|
||||||
(includeTables || !inTable) &&
|
(includeTables || !inTable) &&
|
||||||
|
(includeHeaders || (headerLineNumbers.indexOf(lineNumber)) < 0) &&
|
||||||
re.test(line)) {
|
re.test(line)) {
|
||||||
errors.addDetailIf(lineIndex + 1, lineLength, line.length);
|
errors.addDetailIf(lineNumber, lineLength, line.length);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -129,6 +129,11 @@ rules.forEach(function forRule(rule) {
|
||||||
"description": "Include tables",
|
"description": "Include tables",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": true
|
"default": true
|
||||||
|
},
|
||||||
|
"headers": {
|
||||||
|
"description": "Include headers",
|
||||||
|
"type": "boolean",
|
||||||
|
"default": true
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -323,6 +323,11 @@
|
||||||
"description": "Include tables",
|
"description": "Include tables",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": true
|
"default": true
|
||||||
|
},
|
||||||
|
"headers": {
|
||||||
|
"description": "Include headers",
|
||||||
|
"type": "boolean",
|
||||||
|
"default": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": false
|
"additionalProperties": false
|
||||||
|
|
@ -349,6 +354,11 @@
|
||||||
"description": "Include tables",
|
"description": "Include tables",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": true
|
"default": true
|
||||||
|
},
|
||||||
|
"headers": {
|
||||||
|
"description": "Include headers",
|
||||||
|
"type": "boolean",
|
||||||
|
"default": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": false
|
"additionalProperties": false
|
||||||
|
|
|
||||||
6
test/long-header-exceptions.json
Normal file
6
test/long-header-exceptions.json
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"default": true,
|
||||||
|
"MD013": {
|
||||||
|
"headers": false
|
||||||
|
}
|
||||||
|
}
|
||||||
21
test/long-header-exceptions.md
Normal file
21
test/long-header-exceptions.md
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
# Header
|
||||||
|
|
||||||
|
Text
|
||||||
|
|
||||||
|
## Header header header header header header header header header header header header header header header header
|
||||||
|
|
||||||
|
Text
|
||||||
|
|
||||||
|
Text text text text text text text text text text text text text text text text text text text text text text text text {MD013}
|
||||||
|
|
||||||
|
## Header header
|
||||||
|
|
||||||
|
Text
|
||||||
|
|
||||||
|
Text text text text text text text text text text text text text text text text text text text text text text text text {MD013}
|
||||||
|
|
||||||
|
### Header header header header header header header header header header header header header header header header header
|
||||||
|
|
||||||
|
Text
|
||||||
|
|
||||||
|
Text text text text text text text text text text text text text text text text text text text text text text text text {MD013}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue