Fix bug in MD039 where links with markup could trigger incorrectly.

This commit is contained in:
David Anson 2015-04-17 09:15:19 -07:00
parent 1906214b07
commit 31ae415dbe
2 changed files with 30 additions and 4 deletions

View file

@ -742,16 +742,27 @@ module.exports = [
filterTokens(params.tokens, "inline")
.forEach(function forToken(token) {
var inLink = false;
var index = 0;
var lastChildRightSpaceLineNumber = 0;
token.children.forEach(function forChild(child) {
if (child.type === "link_open") {
inLink = true;
index = 0;
} else if (child.type === "link_close") {
inLink = false;
} else if ((child.type === "text") &&
inLink &&
(child.content.trim().length !== child.content.length)) {
if (lastChildRightSpaceLineNumber) {
errors.push(lastChildRightSpaceLineNumber);
}
} else if (inLink) {
if ((index === 0) &&
(child.content.trimLeft().length !== child.content.length)) {
errors.push(child.lineNumber);
}
lastChildRightSpaceLineNumber =
(child.content.trimRight().length !== child.content.length) ?
child.lineNumber : 0;
index++;
}
});
});
}

15
test/links-with-markup.md Normal file
View file

@ -0,0 +1,15 @@
[This link is plain](link)
[This link has `code`](link)
[This link has *some* emphasis](link)
[This link has **more** emphasis](link)
[This link has `code` and right space ](link) {MD039}
[ This link has _emphasis_ and left space](link) {MD039}
[This](link) line has [multiple](link) links.
[This](line) does [too ](link) and one has a [space](link) {MD039}