diff --git a/demo/markdownlint-browser.js b/demo/markdownlint-browser.js index bb2549de..7225e113 100644 --- a/demo/markdownlint-browser.js +++ b/demo/markdownlint-browser.js @@ -3967,7 +3967,7 @@ module.exports = { var linkText = ""; var lineIndex = 0; children.forEach(function (child) { - var content = child.content, type = child.type; + var content = child.content, markup = child.markup, type = child.type; if (type === "link_open") { inLink = true; linkText = ""; @@ -4000,7 +4000,9 @@ module.exports = { lineIndex = 0; } else if (inLink) { - linkText += content; + linkText += type.endsWith("_inline") ? + "".concat(markup).concat(content).concat(markup) : + (content || markup); } }); }); diff --git a/lib/md039.js b/lib/md039.js index 8397cfc5..791acfc5 100644 --- a/lib/md039.js +++ b/lib/md039.js @@ -19,7 +19,7 @@ module.exports = { let linkText = ""; let lineIndex = 0; children.forEach((child) => { - const { content, type } = child; + const { content, markup, type } = child; if (type === "link_open") { inLink = true; linkText = ""; @@ -57,7 +57,9 @@ module.exports = { lineNumber++; lineIndex = 0; } else if (inLink) { - linkText += content; + linkText += type.endsWith("_inline") ? + `${markup}${content}${markup}` : + (content || markup); } }); }); diff --git a/test/detailed-results-spaces-inside-link-text.md b/test/detailed-results-spaces-inside-link-text.md new file mode 100644 index 00000000..27027ca7 --- /dev/null +++ b/test/detailed-results-spaces-inside-link-text.md @@ -0,0 +1,17 @@ +# Spaces Inside Link Text + +[ link ](https://example.com/) {MD039} + +[ "link" ](https://example.com/) {MD039} + +[ `link` ](https://example.com/) {MD039} + +[ *link* ](https://example.com/) {MD039} + +[ __link__ ](https://example.com/) {MD039} + +[ link "link" ](https://example.com/) {MD039} + +[ link `link` ](https://example.com/) {MD039} + +[ *link* link ](https://example.com/) {MD039} diff --git a/test/detailed-results-spaces-inside-link-text.md.fixed b/test/detailed-results-spaces-inside-link-text.md.fixed new file mode 100644 index 00000000..588c1a99 --- /dev/null +++ b/test/detailed-results-spaces-inside-link-text.md.fixed @@ -0,0 +1,17 @@ +# Spaces Inside Link Text + +[link](https://example.com/) {MD039} + +["link"](https://example.com/) {MD039} + +[`link`](https://example.com/) {MD039} + +[*link*](https://example.com/) {MD039} + +[__link__](https://example.com/) {MD039} + +[link "link"](https://example.com/) {MD039} + +[link `link`](https://example.com/) {MD039} + +[*link* link](https://example.com/) {MD039} diff --git a/test/detailed-results-spaces-inside-link-text.results.json b/test/detailed-results-spaces-inside-link-text.results.json new file mode 100644 index 00000000..177fbd2d --- /dev/null +++ b/test/detailed-results-spaces-inside-link-text.results.json @@ -0,0 +1,162 @@ +[ + { + "errorContext": "[ link ]", + "errorDetail": null, + "errorRange": [ + 1, + 8 + ], + "fixInfo": { + "deleteCount": 6, + "editColumn": 2, + "insertText": "link" + }, + "lineNumber": 3, + "ruleDescription": "Spaces inside link text", + "ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md039", + "ruleNames": [ + "MD039", + "no-space-in-links" + ] + }, + { + "errorContext": "[ \"link\" ]", + "errorDetail": null, + "errorRange": [ + 1, + 10 + ], + "fixInfo": { + "deleteCount": 8, + "editColumn": 2, + "insertText": "\"link\"" + }, + "lineNumber": 5, + "ruleDescription": "Spaces inside link text", + "ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md039", + "ruleNames": [ + "MD039", + "no-space-in-links" + ] + }, + { + "errorContext": "[ `link` ]", + "errorDetail": null, + "errorRange": [ + 1, + 10 + ], + "fixInfo": { + "deleteCount": 8, + "editColumn": 2, + "insertText": "`link`" + }, + "lineNumber": 7, + "ruleDescription": "Spaces inside link text", + "ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md039", + "ruleNames": [ + "MD039", + "no-space-in-links" + ] + }, + { + "errorContext": "[ *link* ]", + "errorDetail": null, + "errorRange": [ + 1, + 10 + ], + "fixInfo": { + "deleteCount": 8, + "editColumn": 2, + "insertText": "*link*" + }, + "lineNumber": 9, + "ruleDescription": "Spaces inside link text", + "ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md039", + "ruleNames": [ + "MD039", + "no-space-in-links" + ] + }, + { + "errorContext": "[ __link__ ]", + "errorDetail": null, + "errorRange": [ + 1, + 12 + ], + "fixInfo": { + "deleteCount": 10, + "editColumn": 2, + "insertText": "__link__" + }, + "lineNumber": 11, + "ruleDescription": "Spaces inside link text", + "ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md039", + "ruleNames": [ + "MD039", + "no-space-in-links" + ] + }, + { + "errorContext": "[ link \"link\" ]", + "errorDetail": null, + "errorRange": [ + 1, + 15 + ], + "fixInfo": { + "deleteCount": 13, + "editColumn": 2, + "insertText": "link \"link\"" + }, + "lineNumber": 13, + "ruleDescription": "Spaces inside link text", + "ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md039", + "ruleNames": [ + "MD039", + "no-space-in-links" + ] + }, + { + "errorContext": "[ link `link` ]", + "errorDetail": null, + "errorRange": [ + 1, + 15 + ], + "fixInfo": { + "deleteCount": 13, + "editColumn": 2, + "insertText": "link `link`" + }, + "lineNumber": 15, + "ruleDescription": "Spaces inside link text", + "ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md039", + "ruleNames": [ + "MD039", + "no-space-in-links" + ] + }, + { + "errorContext": "[ *link* link ]", + "errorDetail": null, + "errorRange": [ + 1, + 15 + ], + "fixInfo": { + "deleteCount": 13, + "editColumn": 2, + "insertText": "*link* link" + }, + "lineNumber": 17, + "ruleDescription": "Spaces inside link text", + "ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md039", + "ruleNames": [ + "MD039", + "no-space-in-links" + ] + } +] \ No newline at end of file diff --git a/test/spaces_inside_link_text.md b/test/spaces_inside_link_text.md index 84176ff4..df11518b 100644 --- a/test/spaces_inside_link_text.md +++ b/test/spaces_inside_link_text.md @@ -10,7 +10,7 @@ [*foo*](https://bar/) -[**foo**](https://bar/) +[__foo__](https://bar/) [foo "bar"](https://baz/) @@ -28,6 +28,8 @@ [ *foo* ](https://bar/) {MD039} +[ __foo__ ](https://bar/) {MD039} + The following shouldn't break anything: [![Screenshot.png](/images/Screenshot.png)](/images/Screenshot.png)