2018-01-21 21:44:25 -08:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2019-09-04 22:18:23 -07:00
|
|
|
const { addError, forEachInlineChild } = require("../helpers");
|
2018-01-21 21:44:25 -08:00
|
|
|
|
2019-09-04 22:18:23 -07:00
|
|
|
const reversedLinkRe = /\(([^)]+)\)\[([^\]^][^\]]*)]/g;
|
2018-01-21 21:44:25 -08:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
"names": [ "MD011", "no-reversed-links" ],
|
|
|
|
"description": "Reversed link syntax",
|
|
|
|
"tags": [ "links" ],
|
|
|
|
"function": function MD011(params, onError) {
|
2019-09-04 22:18:23 -07:00
|
|
|
forEachInlineChild(params, "text", (token) => {
|
|
|
|
const { lineNumber, content } = token;
|
|
|
|
let match = null;
|
|
|
|
while ((match = reversedLinkRe.exec(content)) !== null) {
|
|
|
|
const [ reversedLink, linkText, linkDestination ] = match;
|
|
|
|
const column = match.index + 1;
|
|
|
|
const length = reversedLink.length;
|
|
|
|
addError(
|
|
|
|
onError,
|
|
|
|
lineNumber,
|
|
|
|
reversedLink,
|
|
|
|
null,
|
|
|
|
[ column, length ],
|
|
|
|
{
|
|
|
|
"editColumn": column,
|
|
|
|
"deleteCount": length,
|
|
|
|
"insertText": `[${linkText}](${linkDestination})`
|
|
|
|
}
|
|
|
|
);
|
2018-01-21 21:44:25 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|