Skip to content

Commit

Permalink
Update MD039/no-space-in-links to fix reference-style links, be sligh…
Browse files Browse the repository at this point in the history
…tly more permissive matching link content.
  • Loading branch information
DavidAnson committed Dec 22, 2021
1 parent 064a1e3 commit 7a76f1d
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 2 deletions.
2 changes: 1 addition & 1 deletion demo/markdownlint-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion lib/md039.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" ],
Expand Down
14 changes: 14 additions & 0 deletions test/detailed-results-links.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,17 @@ Text <https://example.com/same> 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/
14 changes: 14 additions & 0 deletions test/detailed-results-links.md.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,17 @@ Text <https://example.com/same> 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/
120 changes: 120 additions & 0 deletions test/detailed-results-links.results.json
Original file line number Diff line number Diff line change
Expand Up @@ -271,5 +271,125 @@
"deleteCount": 25,
"insertText": "<https://example.com/third>"
}
},
{
"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"
}
}
]
12 changes: 12 additions & 0 deletions test/spaces_inside_link_text.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7a76f1d

Please sign in to comment.