diff --git a/demo/markdownlint-browser.js b/demo/markdownlint-browser.js index 2b3925f2..185f94ef 100644 --- a/demo/markdownlint-browser.js +++ b/demo/markdownlint-browser.js @@ -3712,7 +3712,7 @@ module.exports = { // @ts-check var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addErrorContext = _a.addErrorContext, filterTokens = _a.filterTokens; -var spaceInLinkRe = /\[(?:\s+(?:[^\]]*?)\s*|(?:[^\]]*?)\s+)](?=\(\S*\))/; +var spaceInLinkRe = /\[(?:\s+(?:[^\]]*?)\s*|(?:[^\]]*?)\s+)](?=((?:\([^)]*\))|(?:\[[^\]]*\])))/; module.exports = { "names": ["MD039", "no-space-in-links"], "description": "Spaces inside link text", diff --git a/lib/md039.js b/lib/md039.js index c65a9cbe..8397cfc5 100644 --- a/lib/md039.js +++ b/lib/md039.js @@ -4,7 +4,8 @@ const { addErrorContext, filterTokens } = require("../helpers"); -const spaceInLinkRe = /\[(?:\s+(?:[^\]]*?)\s*|(?:[^\]]*?)\s+)](?=\(\S*\))/; +const spaceInLinkRe = + /\[(?:\s+(?:[^\]]*?)\s*|(?:[^\]]*?)\s+)](?=((?:\([^)]*\))|(?:\[[^\]]*\])))/; module.exports = { "names": [ "MD039", "no-space-in-links" ], diff --git a/test/detailed-results-links.md b/test/detailed-results-links.md index 3548c6c5..c9d90dc3 100644 --- a/test/detailed-results-links.md +++ b/test/detailed-results-links.md @@ -28,3 +28,17 @@ Text more \* text https://example.com/same more \[ te Text https://example.com/first more text https://example.com/second still more text https://example.com/third done (Incorrect link syntax)[https://www.example.com/] + +Text [link ](https://example.com/) text. + +Text [ link](https://example.com/) text. + +Text [ link ](https://example.com/) text. + +Text [link ][reference] text. + +Text [ link][reference] text. + +Text [ link ][reference] text. + +[reference]: https://example.com/ diff --git a/test/detailed-results-links.md.fixed b/test/detailed-results-links.md.fixed index 90f735cf..ab3cf6e0 100644 --- a/test/detailed-results-links.md.fixed +++ b/test/detailed-results-links.md.fixed @@ -28,3 +28,17 @@ Text more \* text https://example.com/same more \[ te Text more text still more text done [Incorrect link syntax](https://www.example.com/) + +Text [link](https://example.com/) text. + +Text [link](https://example.com/) text. + +Text [link](https://example.com/) text. + +Text [link][reference] text. + +Text [link][reference] text. + +Text [link][reference] text. + +[reference]: https://example.com/ diff --git a/test/detailed-results-links.results.json b/test/detailed-results-links.results.json index 9d6c721a..8dc8bae9 100644 --- a/test/detailed-results-links.results.json +++ b/test/detailed-results-links.results.json @@ -271,5 +271,125 @@ "deleteCount": 25, "insertText": "" } + }, + { + "lineNumber": 32, + "ruleNames": [ + "MD039", + "no-space-in-links" + ], + "ruleDescription": "Spaces inside link text", + "ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md039", + "errorDetail": null, + "errorContext": "[link ]", + "errorRange": [ + 6, + 7 + ], + "fixInfo": { + "editColumn": 7, + "deleteCount": 5, + "insertText": "link" + } + }, + { + "lineNumber": 34, + "ruleNames": [ + "MD039", + "no-space-in-links" + ], + "ruleDescription": "Spaces inside link text", + "ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md039", + "errorDetail": null, + "errorContext": "[ link]", + "errorRange": [ + 6, + 7 + ], + "fixInfo": { + "editColumn": 7, + "deleteCount": 5, + "insertText": "link" + } + }, + { + "lineNumber": 36, + "ruleNames": [ + "MD039", + "no-space-in-links" + ], + "ruleDescription": "Spaces inside link text", + "ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md039", + "errorDetail": null, + "errorContext": "[ link ]", + "errorRange": [ + 6, + 8 + ], + "fixInfo": { + "editColumn": 7, + "deleteCount": 6, + "insertText": "link" + } + }, + { + "lineNumber": 38, + "ruleNames": [ + "MD039", + "no-space-in-links" + ], + "ruleDescription": "Spaces inside link text", + "ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md039", + "errorDetail": null, + "errorContext": "[link ]", + "errorRange": [ + 6, + 7 + ], + "fixInfo": { + "editColumn": 7, + "deleteCount": 5, + "insertText": "link" + } + }, + { + "lineNumber": 40, + "ruleNames": [ + "MD039", + "no-space-in-links" + ], + "ruleDescription": "Spaces inside link text", + "ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md039", + "errorDetail": null, + "errorContext": "[ link]", + "errorRange": [ + 6, + 7 + ], + "fixInfo": { + "editColumn": 7, + "deleteCount": 5, + "insertText": "link" + } + }, + { + "lineNumber": 42, + "ruleNames": [ + "MD039", + "no-space-in-links" + ], + "ruleDescription": "Spaces inside link text", + "ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md039", + "errorDetail": null, + "errorContext": "[ link ]", + "errorRange": [ + 6, + 8 + ], + "fixInfo": { + "editColumn": 7, + "deleteCount": 6, + "insertText": "link" + } } ] \ No newline at end of file diff --git a/test/spaces_inside_link_text.md b/test/spaces_inside_link_text.md index 8e6baa15..84176ff4 100644 --- a/test/spaces_inside_link_text.md +++ b/test/spaces_inside_link_text.md @@ -50,3 +50,15 @@ Wrapped [ link with leading space ](https://example.com) {MD039} Non-wrapped [ link with leading space](https://example.com) {MD039} + +[][ref] + +[link][ref] + +[link ][ref] {MD039} + +[ link][ref] {MD039} + +[ link ][ref] {MD039} + +[ref]: https://example.com