From 1edb3f0a78639f96eb5fdffa343df670fb47007d Mon Sep 17 00:00:00 2001 From: David Anson Date: Sat, 28 Sep 2019 22:50:33 -0700 Subject: [PATCH] Update MD039/no-space-in-links to handle hardbreaks (fixes #222). --- lib/md039.js | 9 +++++---- test/spaces_inside_link_text.md | 4 ++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/md039.js b/lib/md039.js index f9464cf7..477cf3ed 100644 --- a/lib/md039.js +++ b/lib/md039.js @@ -18,10 +18,11 @@ module.exports = { let linkText = ""; let lineIndex = 0; children.forEach((child) => { - if (child.type === "link_open") { + const { content, type } = child; + if (type === "link_open") { inLink = true; linkText = ""; - } else if (child.type === "link_close") { + } else if (type === "link_close") { inLink = false; const left = linkText.trimLeft().length !== linkText.length; const right = linkText.trimRight().length !== linkText.length; @@ -45,11 +46,11 @@ module.exports = { } ); } - } else if (child.type === "softbreak") { + } else if ((type === "softbreak") || (type === "hardbreak")) { lineNumber++; lineIndex = 0; } else if (inLink) { - linkText += child.content; + linkText += content; } }); }); diff --git a/test/spaces_inside_link_text.md b/test/spaces_inside_link_text.md index 76f2f420..96335bb3 100644 --- a/test/spaces_inside_link_text.md +++ b/test/spaces_inside_link_text.md @@ -41,3 +41,7 @@ function MoreCodeButNotCode(input) { input = input.replace(/[- ]([a-z])/g, "three"); // {MD039} return input; } + +[Links](ending) +[with](spaces) +[error ]({MD039})