Add headers parameter to MD013/line-length (fixes #35).

This commit is contained in:
David Anson 2017-02-11 16:20:24 -08:00
parent 16dc230d54
commit 00171da565
6 changed files with 56 additions and 4 deletions

View file

@ -334,7 +334,7 @@ Tags: 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
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
being forced to break them in the middle.
You also have the option to exclude this rule for code blocks and tables. To
do this, set the `code_blocks` and/or `tables` parameters to false.
You have the option to exclude this rule for code blocks, tables, or headers.
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
requirement for document readability, and tentatively compatible with code

View file

@ -427,13 +427,23 @@ module.exports = [
var includeCodeBlocks = (codeBlocks === undefined) ? true : !!codeBlocks;
var tables = params.options.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);
forEachLine(params,
function forLine(line, lineIndex, inCode, onFence, inTable) {
var lineNumber = lineIndex + 1;
if ((includeCodeBlocks || !inCode) &&
(includeTables || !inTable) &&
(includeHeaders || (headerLineNumbers.indexOf(lineNumber)) < 0) &&
re.test(line)) {
errors.addDetailIf(lineIndex + 1, lineLength, line.length);
errors.addDetailIf(lineNumber, lineLength, line.length);
}
});
}

View file

@ -129,6 +129,11 @@ rules.forEach(function forRule(rule) {
"description": "Include tables",
"type": "boolean",
"default": true
},
"headers": {
"description": "Include headers",
"type": "boolean",
"default": true
}
};
break;

View file

@ -323,6 +323,11 @@
"description": "Include tables",
"type": "boolean",
"default": true
},
"headers": {
"description": "Include headers",
"type": "boolean",
"default": true
}
},
"additionalProperties": false
@ -349,6 +354,11 @@
"description": "Include tables",
"type": "boolean",
"default": true
},
"headers": {
"description": "Include headers",
"type": "boolean",
"default": true
}
},
"additionalProperties": false

View file

@ -0,0 +1,6 @@
{
"default": true,
"MD013": {
"headers": false
}
}

View 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}