mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01:00
Fix bug in MD039 where links with markup could trigger incorrectly.
This commit is contained in:
parent
1906214b07
commit
31ae415dbe
2 changed files with 30 additions and 4 deletions
19
lib/rules.js
19
lib/rules.js
|
|
@ -742,15 +742,26 @@ module.exports = [
|
||||||
filterTokens(params.tokens, "inline")
|
filterTokens(params.tokens, "inline")
|
||||||
.forEach(function forToken(token) {
|
.forEach(function forToken(token) {
|
||||||
var inLink = false;
|
var inLink = false;
|
||||||
|
var index = 0;
|
||||||
|
var lastChildRightSpaceLineNumber = 0;
|
||||||
token.children.forEach(function forChild(child) {
|
token.children.forEach(function forChild(child) {
|
||||||
if (child.type === "link_open") {
|
if (child.type === "link_open") {
|
||||||
inLink = true;
|
inLink = true;
|
||||||
|
index = 0;
|
||||||
} else if (child.type === "link_close") {
|
} else if (child.type === "link_close") {
|
||||||
inLink = false;
|
inLink = false;
|
||||||
} else if ((child.type === "text") &&
|
if (lastChildRightSpaceLineNumber) {
|
||||||
inLink &&
|
errors.push(lastChildRightSpaceLineNumber);
|
||||||
(child.content.trim().length !== child.content.length)) {
|
}
|
||||||
errors.push(child.lineNumber);
|
} 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
15
test/links-with-markup.md
Normal 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}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue