mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-21 21:30:47 +02: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;
|
||||
if (left || right) {
|
||||
const line = params.lines[lineNumber - 1];
|
||||
let range = null;
|
||||
let fixInfo = null;
|
||||
const match = line.slice(lineIndex).match(spaceInLinkRe);
|
||||
const column = match.index + lineIndex + 1;
|
||||
const length = match[0].length;
|
||||
lineIndex = column + length - 1;
|
||||
if (match) {
|
||||
const column = match.index + lineIndex + 1;
|
||||
const length = match[0].length;
|
||||
range = [ column, length ];
|
||||
fixInfo = {
|
||||
"editColumn": column + 1,
|
||||
"deleteCount": length - 2,
|
||||
"insertText": linkText.trim()
|
||||
};
|
||||
lineIndex = column + length - 1;
|
||||
}
|
||||
addErrorContext(
|
||||
onError,
|
||||
lineNumber,
|
||||
`[${linkText}]`,
|
||||
left,
|
||||
right,
|
||||
[ column, length ],
|
||||
{
|
||||
"editColumn": column + 1,
|
||||
"deleteCount": length - 2,
|
||||
"insertText": linkText.trim()
|
||||
}
|
||||
range,
|
||||
fixInfo
|
||||
);
|
||||
}
|
||||
} else if ((type === "softbreak") || (type === "hardbreak")) {
|
||||
|
|
|
@ -45,3 +45,8 @@ function MoreCodeButNotCode(input) {
|
|||
[Links](ending)
|
||||
[with](spaces)
|
||||
[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