Update MD013/line-length not to report long link-only lines (fixes #36).

This commit is contained in:
David Anson 2017-03-01 21:43:04 -08:00
parent acd36d5802
commit 0c1f40323d
2 changed files with 35 additions and 4 deletions

View file

@ -56,7 +56,7 @@ function unorderedListStyleFor(token) {
return "dash";
case "+":
return "plus";
case "*":
// case "*":
default:
return "asterisk";
}
@ -435,14 +435,25 @@ module.exports = [
headerLineNumbers.push(heading.lineNumber);
});
}
var re = longLineReFunc(params.options);
var linkOnlyLineNumbers = [];
filterTokens(params, "inline", function forToken(token) {
if (((token.children.length === 2) || (token.children.length === 3)) &&
(token.children[0].type === "link_open") &&
(token.children[token.children.length - 1].type === "link_close")) {
linkOnlyLineNumbers.push(token.lineNumber);
}
});
var longLineRe = longLineReFunc(params.options);
var labelRe = /^\s*\[.*[^\\]]:/;
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)) {
(linkOnlyLineNumbers.indexOf(lineNumber) < 0) &&
longLineRe.test(line) &&
!labelRe.test(line)) {
errors.addDetailIf(lineNumber, lineLength, line.length);
}
});

View file

@ -1,3 +1,23 @@
This is a very very very very very very very very very very very very very very long line {MD013}
This line however, while very long, doesn't have whitespace after the 80th columnwhichallowsforURLsandotherlongthings.
[This long line is comprised entirely of a link](http://example.com "This is the long link's title")
> [This long line is comprised entirely of a link](http://example.com "This is the long link's title")
[This long line is comprised entirely of a link](http://example.com "But is inside a code block") {MD013}
This [long line is comprised mostly of a link](http://example.com "This is the long link's title") {MD013}
[This long line is comprised mostly of a link](http://example.com "This is the long link's title") text {MD013}
This long line includes a simple [reference][label] link and is long enough to violate the rule. {MD013}
[This long line is comprised entirely of a reference link and is long enough to violate the rule][label]
[label]: http://example.org "Title for a link reference that is itself long enough to violate the rule"
[Link to broken label][notlabel]
[notlabel\]: notlink "Invalid syntax for a link label because the right bracket is backslash-escaped {MD013}"