Fix MD039/no-space-in-links to handle links within a multi-line paragraph.

This commit is contained in:
David Anson 2019-09-24 23:00:30 -07:00
parent 1ac2e6c3e8
commit 33cb1a71ec
2 changed files with 17 additions and 1 deletions

View file

@ -12,7 +12,8 @@ module.exports = {
"tags": [ "whitespace", "links" ], "tags": [ "whitespace", "links" ],
"function": function MD039(params, onError) { "function": function MD039(params, onError) {
filterTokens(params, "inline", (token) => { filterTokens(params, "inline", (token) => {
const { line, lineNumber, children } = token; const { children } = token;
let { lineNumber } = token;
let inLink = false; let inLink = false;
let linkText = ""; let linkText = "";
let lineIndex = 0; let lineIndex = 0;
@ -25,6 +26,7 @@ module.exports = {
const left = linkText.trimLeft().length !== linkText.length; const left = linkText.trimLeft().length !== linkText.length;
const right = linkText.trimRight().length !== linkText.length; const right = linkText.trimRight().length !== linkText.length;
if (left || right) { if (left || right) {
const line = params.lines[lineNumber - 1];
const match = line.slice(lineIndex).match(spaceInLinkRe); const match = line.slice(lineIndex).match(spaceInLinkRe);
const column = match.index + lineIndex + 1; const column = match.index + lineIndex + 1;
const length = match[0].length; const length = match[0].length;
@ -43,6 +45,9 @@ module.exports = {
} }
); );
} }
} else if (child.type === "softbreak") {
lineNumber++;
lineIndex = 0;
} else if (inLink) { } else if (inLink) {
linkText += child.content; linkText += child.content;
} }

View file

@ -30,3 +30,14 @@
The following shouldn't break anything: The following shouldn't break anything:
[![Screenshot.png](/images/Screenshot.png)](/images/Screenshot.png) [![Screenshot.png](/images/Screenshot.png)](/images/Screenshot.png)
function CodeButNotCode(input) {
return input.replace(/[- ]([a-z])/g, "one"); // {MD039}
}
function MoreCodeButNotCode(input) {
input = input.replace(/[- ]([a-z])/g, "two"); // {MD039}
input = input.toLowerCase();
input = input.replace(/[- ]([a-z])/g, "three"); // {MD039}
return input;
}