mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Update MD013 to allow excluding code and tables.
This commit is contained in:
parent
36eaa821d9
commit
b7342485d9
5 changed files with 106 additions and 8 deletions
|
@ -266,7 +266,7 @@ lines inside code blocks.
|
|||
|
||||
Tags: line_length
|
||||
|
||||
Parameters: line_length (number; default 80)
|
||||
Parameters: line_length, code_blocks, tables (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
|
||||
|
@ -276,6 +276,13 @@ 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.
|
||||
|
||||
Code blocks are included in this rule by default since it is often a
|
||||
requirement for document readability, and tentatively compatible with code
|
||||
rules. Still, some languages do not lend themselves to short lines.
|
||||
|
||||
## MD014 - Dollar signs used before commands without showing output
|
||||
|
||||
Tags: code
|
||||
|
|
26
lib/rules.js
26
lib/rules.js
|
@ -49,7 +49,7 @@ function forEachLine(params, callback) {
|
|||
var fence = match && match[1];
|
||||
if (fence &&
|
||||
(!inFence || (fence.substr(0, fenceStart.length) === fenceStart))) {
|
||||
metadata = inFence ? -2 : 2;
|
||||
metadata = inFence ? 2 : 6;
|
||||
fenceStart = inFence ? null : fence;
|
||||
inFence = !inFence;
|
||||
} else if (inFence) {
|
||||
|
@ -63,12 +63,23 @@ function forEachLine(params, callback) {
|
|||
lineMetadata[i] = 1;
|
||||
}
|
||||
});
|
||||
// Find tables normally
|
||||
filterTokens(params, "table_open", function forToken(token) {
|
||||
for (var i = token.map[0]; i < token.map[1]; i++) {
|
||||
lineMetadata[i] += 8;
|
||||
}
|
||||
});
|
||||
params.forEachLine = lineMetadata;
|
||||
}
|
||||
// Invoke callback
|
||||
params.lines.forEach(function forLine(line, lineIndex) {
|
||||
var metadata = params.forEachLine[lineIndex];
|
||||
callback(line, lineIndex, !!metadata, (metadata >> 1));
|
||||
callback(
|
||||
line,
|
||||
lineIndex,
|
||||
!!(metadata & 7),
|
||||
(((metadata & 6) >> 1) || 2) - 2,
|
||||
!!(metadata & 8));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -326,9 +337,16 @@ module.exports = [
|
|||
"tags": [ "line_length" ],
|
||||
"func": function MD013(params, errors) {
|
||||
var lineLength = params.options.line_length || 80;
|
||||
var codeBlocks = params.options.code_blocks;
|
||||
var includeCodeBlocks = (codeBlocks === undefined) ? true : !!codeBlocks;
|
||||
var tables = params.options.tables;
|
||||
var includeTables = (tables === undefined) ? true : !!tables;
|
||||
var re = new RegExp("^.{" + lineLength + "}.*\\s");
|
||||
params.lines.forEach(function forLine(line, lineIndex) {
|
||||
if (re.test(line)) {
|
||||
forEachLine(params,
|
||||
function forLine(line, lineIndex, inCode, onFence, inTable) {
|
||||
if ((includeCodeBlocks || !inCode) &&
|
||||
(includeTables || !inTable) &&
|
||||
re.test(line)) {
|
||||
errors.push(lineIndex + 1);
|
||||
}
|
||||
});
|
||||
|
|
28
test/long_lines_code-default.md
Normal file
28
test/long_lines_code-default.md
Normal file
|
@ -0,0 +1,28 @@
|
|||
This is a short line.
|
||||
|
||||
This is a very very very very very very very very very very very very very very very very very very very very long line. {MD013}
|
||||
|
||||
This is a short line.
|
||||
|
||||
```text
|
||||
Here is a short line in a code block.
|
||||
Here is a very very very very very very very very very very very very very very very very very very very long line in a code block. {MD013}
|
||||
```
|
||||
|
||||
This is a short line.
|
||||
|
||||
| First Header | Second Header | Third Header | Fourth Header | Fifth Header | Sixth Header | {MD013}
|
||||
| ------------- | ------------- | ------------- | ------------- | ------------- | ------------- | {MD013}
|
||||
| Content Cell | Content Cell | Content Cell | Content Cell | Content Cell | Content Cell | {MD013}
|
||||
| ============= | ============= | ============= | ============= | ============= | ============= | {MD013}
|
||||
| Footer Cell | Footer Cell | Footer Cell | Footer Cell | Footer Cell | Footer Cell | {MD013}
|
||||
|
||||
This is a very very very very very very very very very very very very very very very very very very very very long line. {MD013}
|
||||
|
||||
Another line.
|
||||
|
||||
| First Header | Second Header | Third Header | Fourth Header | Fifth Header | Sixth Header | {MD013}
|
||||
| ------------- | ------------- | ------------- | ------------- | ------------- | ------------- | {MD013}
|
||||
| Content Cell | Content Cell | Content Cell | Content Cell | Content Cell | Content Cell | {MD013}
|
||||
| ============= | ============= | ============= | ============= | ============= | ============= | {MD013}
|
||||
| Footer Cell | Footer Cell | Footer Cell | Footer Cell | Footer Cell | Footer Cell | {MD013}
|
7
test/long_lines_code.json
Normal file
7
test/long_lines_code.json
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"default": true,
|
||||
"MD013": {
|
||||
"code_blocks": false,
|
||||
"tables": false
|
||||
}
|
||||
}
|
38
test/long_lines_code.md
Normal file
38
test/long_lines_code.md
Normal file
|
@ -0,0 +1,38 @@
|
|||
This is a short line.
|
||||
|
||||
This is a very very very very very very very very very very very very very very very very very very very very long line. {MD013}
|
||||
|
||||
This is a short line.
|
||||
|
||||
```text
|
||||
Here is a short line in a code block.
|
||||
Here is a very very very very very very very very very very very very very very very very very very very long line in a code block.
|
||||
```
|
||||
|
||||
This is a short line.
|
||||
|
||||
| First Header | Second Header | Third Header | Fourth Header | Fifth Header | Sixth Header |
|
||||
| ------------- | ------------- | ------------- | ------------- | ------------- | ------------- |
|
||||
| Content Cell | Content Cell | Content Cell | Content Cell | Content Cell | Content Cell |
|
||||
| Content Cell | Content Cell | Content Cell | Content Cell | Content Cell | Content Cell |
|
||||
| ------------- | ------------- | ------------- | ------------- | ------------- | ------------- |
|
||||
| Content Cell | Content Cell | Content Cell | Content Cell | Content Cell | Content Cell |
|
||||
| Content Cell | Content Cell | Content Cell | Content Cell | Content Cell | Content Cell |
|
||||
| ============= | ============= | ============= | ============= | ============= | ============= |
|
||||
| Footer Cell | Footer Cell | Footer Cell | Footer Cell | Footer Cell | Footer Cell |
|
||||
{: rules="groups"}
|
||||
|
||||
This is a very very very very very very very very very very very very very very very very very very very very long line. {MD013}
|
||||
|
||||
Another line.
|
||||
|
||||
| First Header | Second Header | Third Header | Fourth Header | Fifth Header | Sixth Header |
|
||||
| ------------- | ------------- | ------------- | ------------- | ------------- | ------------- |
|
||||
| Content Cell | Content Cell | Content Cell | Content Cell | Content Cell | Content Cell |
|
||||
| Content Cell | Content Cell | Content Cell | Content Cell | Content Cell | Content Cell |
|
||||
| ------------- | ------------- | ------------- | ------------- | ------------- | ------------- |
|
||||
| Content Cell | Content Cell | Content Cell | Content Cell | Content Cell | Content Cell |
|
||||
| Content Cell | Content Cell | Content Cell | Content Cell | Content Cell | Content Cell |
|
||||
| ============= | ============= | ============= | ============= | ============= | ============= |
|
||||
| Footer Cell | Footer Cell | Footer Cell | Footer Cell | Footer Cell | Footer Cell |
|
||||
{: rules="groups"}
|
Loading…
Add table
Add a link
Reference in a new issue