mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01:00
Update MD039/no-space-in-links to handle RegExp match failure (fixes #262).
This commit is contained in:
parent
0f73f06232
commit
67d1476ed8
2 changed files with 20 additions and 9 deletions
24
lib/md039.js
24
lib/md039.js
|
|
@ -28,22 +28,28 @@ module.exports = {
|
||||||
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 line = params.lines[lineNumber - 1];
|
||||||
|
let range = null;
|
||||||
|
let fixInfo = null;
|
||||||
const match = line.slice(lineIndex).match(spaceInLinkRe);
|
const match = line.slice(lineIndex).match(spaceInLinkRe);
|
||||||
const column = match.index + lineIndex + 1;
|
if (match) {
|
||||||
const length = match[0].length;
|
const column = match.index + lineIndex + 1;
|
||||||
lineIndex = column + length - 1;
|
const length = match[0].length;
|
||||||
|
range = [ column, length ];
|
||||||
|
fixInfo = {
|
||||||
|
"editColumn": column + 1,
|
||||||
|
"deleteCount": length - 2,
|
||||||
|
"insertText": linkText.trim()
|
||||||
|
};
|
||||||
|
lineIndex = column + length - 1;
|
||||||
|
}
|
||||||
addErrorContext(
|
addErrorContext(
|
||||||
onError,
|
onError,
|
||||||
lineNumber,
|
lineNumber,
|
||||||
`[${linkText}]`,
|
`[${linkText}]`,
|
||||||
left,
|
left,
|
||||||
right,
|
right,
|
||||||
[ column, length ],
|
range,
|
||||||
{
|
fixInfo
|
||||||
"editColumn": column + 1,
|
|
||||||
"deleteCount": length - 2,
|
|
||||||
"insertText": linkText.trim()
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else if ((type === "softbreak") || (type === "hardbreak")) {
|
} else if ((type === "softbreak") || (type === "hardbreak")) {
|
||||||
|
|
|
||||||
|
|
@ -45,3 +45,8 @@ function MoreCodeButNotCode(input) {
|
||||||
[Links](ending)
|
[Links](ending)
|
||||||
[with](spaces)
|
[with](spaces)
|
||||||
[error ]({MD039})
|
[error ]({MD039})
|
||||||
|
|
||||||
|
Wrapped [ link with leading space
|
||||||
|
](https://example.com) {MD039}
|
||||||
|
|
||||||
|
Non-wrapped [ link with leading space](https://example.com) {MD039}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue