mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Update MD013/line-length with new code_block_line_length parameter (fixes #184).
This commit is contained in:
parent
1d8b9e7e62
commit
64351f73be
6 changed files with 59 additions and 4 deletions
|
@ -443,14 +443,15 @@ Tags: line_length
|
|||
|
||||
Aliases: line-length
|
||||
|
||||
Parameters: line_length, heading_line_length, code_blocks, tables, headings, headers (number; default 80, boolean; default true)
|
||||
Parameters: line_length, heading_line_length, code_block_line_length, code_blocks, tables, headings, headers (number; default 80, boolean; default true)
|
||||
|
||||
> If `headings` is not provided, `headers` (deprecated) will be used.
|
||||
|
||||
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
|
||||
up into multiple lines. To set a different maximum length for headings, use
|
||||
`heading_line_length`.
|
||||
`heading_line_length`. To set a different maximum length for code blocks, use
|
||||
`code_block_line_length`
|
||||
|
||||
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
|
||||
|
|
11
lib/md013.js
11
lib/md013.js
|
@ -27,10 +27,13 @@ module.exports = {
|
|||
"function": function MD013(params, onError) {
|
||||
const lineLength = params.config.line_length || 80;
|
||||
const headingLineLength = params.config.heading_line_length || lineLength;
|
||||
const codeLineLength = params.config.code_block_line_length || lineLength;
|
||||
const longLineRe =
|
||||
new RegExp(longLineRePrefix + lineLength + longLineRePostfix);
|
||||
const longHeadingLineRe =
|
||||
new RegExp(longLineRePrefix + headingLineLength + longLineRePostfix);
|
||||
const longCodeLineRe =
|
||||
new RegExp(longLineRePrefix + codeLineLength + longLineRePostfix);
|
||||
const codeBlocks = params.config.code_blocks;
|
||||
const includeCodeBlocks = (codeBlocks === undefined) ? true : !!codeBlocks;
|
||||
const tables = params.config.tables;
|
||||
|
@ -59,8 +62,12 @@ module.exports = {
|
|||
forEachLine(lineMetadata(), (line, lineIndex, inCode, onFence, inTable) => {
|
||||
const lineNumber = lineIndex + 1;
|
||||
const isHeading = includesSorted(headingLineNumbers, lineNumber);
|
||||
const length = isHeading ? headingLineLength : lineLength;
|
||||
const lengthRe = isHeading ? longHeadingLineRe : longLineRe;
|
||||
const length = inCode ?
|
||||
codeLineLength :
|
||||
(isHeading ? headingLineLength : lineLength);
|
||||
const lengthRe = inCode ?
|
||||
longCodeLineRe :
|
||||
(isHeading ? longHeadingLineRe : longLineRe);
|
||||
if ((includeCodeBlocks || !inCode) &&
|
||||
(includeTables || !inTable) &&
|
||||
(includeHeadings || !isHeading) &&
|
||||
|
|
|
@ -134,6 +134,11 @@ rules.forEach(function forRule(rule) {
|
|||
"type": "integer",
|
||||
"default": 80
|
||||
},
|
||||
"code_block_line_length": {
|
||||
"description": "Number of characters for code blocks",
|
||||
"type": "integer",
|
||||
"default": 80
|
||||
},
|
||||
"code_blocks": {
|
||||
"description": "Include code blocks",
|
||||
"type": "boolean",
|
||||
|
|
|
@ -379,6 +379,11 @@
|
|||
"type": "integer",
|
||||
"default": 80
|
||||
},
|
||||
"code_block_line_length": {
|
||||
"description": "Number of characters for code blocks",
|
||||
"type": "integer",
|
||||
"default": 80
|
||||
},
|
||||
"code_blocks": {
|
||||
"description": "Include code blocks",
|
||||
"type": "boolean",
|
||||
|
@ -420,6 +425,11 @@
|
|||
"type": "integer",
|
||||
"default": 80
|
||||
},
|
||||
"code_block_line_length": {
|
||||
"description": "Number of characters for code blocks",
|
||||
"type": "integer",
|
||||
"default": 80
|
||||
},
|
||||
"code_blocks": {
|
||||
"description": "Include code blocks",
|
||||
"type": "boolean",
|
||||
|
|
7
test/long-lines-short-code.json
Normal file
7
test/long-lines-short-code.json
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"default": true,
|
||||
"MD013": {
|
||||
"code_block_line_length": 30
|
||||
},
|
||||
"MD046": false
|
||||
}
|
25
test/long-lines-short-code.md
Normal file
25
test/long-lines-short-code.md
Normal file
|
@ -0,0 +1,25 @@
|
|||
# Long Lines, Short Code
|
||||
|
||||
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 text text text text text text text {MD013}
|
||||
|
||||
Text
|
||||
|
||||
Code code code code
|
||||
|
||||
Text
|
||||
|
||||
Code code code code code code code {MD013}
|
||||
|
||||
Text
|
||||
|
||||
```text
|
||||
Code code code code code
|
||||
```
|
||||
|
||||
Text
|
||||
|
||||
```text
|
||||
Code code code code code code code code {MD013}
|
||||
```
|
Loading…
Add table
Add a link
Reference in a new issue