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
32
lib/rules.js
32
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,12 +337,19 @@ 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)) {
|
||||
errors.push(lineIndex + 1);
|
||||
}
|
||||
});
|
||||
forEachLine(params,
|
||||
function forLine(line, lineIndex, inCode, onFence, inTable) {
|
||||
if ((includeCodeBlocks || !inCode) &&
|
||||
(includeTables || !inTable) &&
|
||||
re.test(line)) {
|
||||
errors.push(lineIndex + 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue