mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02: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
17
lib/rules.js
17
lib/rules.js
|
@ -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
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