2018-01-21 21:44:25 -08:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2018-04-27 22:05:34 -07:00
|
|
|
const shared = require("./shared");
|
2018-01-21 21:44:25 -08:00
|
|
|
|
2018-04-27 22:05:34 -07:00
|
|
|
const spaceInLinkRe = /\[(?:\s+(?:[^\]]*?)\s*|(?:[^\]]*?)\s+)](?=\(\S*\))/;
|
2018-01-21 21:44:25 -08:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
"names": [ "MD039", "no-space-in-links" ],
|
|
|
|
"description": "Spaces inside link text",
|
|
|
|
"tags": [ "whitespace", "links" ],
|
|
|
|
"function": function MD039(params, onError) {
|
|
|
|
shared.filterTokens(params, "inline", function forToken(token) {
|
2018-04-27 22:05:34 -07:00
|
|
|
let inLink = false;
|
|
|
|
let linkText = "";
|
2018-01-21 21:44:25 -08:00
|
|
|
token.children.forEach(function forChild(child) {
|
|
|
|
if (child.type === "link_open") {
|
|
|
|
inLink = true;
|
|
|
|
linkText = "";
|
|
|
|
} else if (child.type === "link_close") {
|
|
|
|
inLink = false;
|
2018-04-27 22:05:34 -07:00
|
|
|
const left = shared.trimLeft(linkText).length !== linkText.length;
|
|
|
|
const right = shared.trimRight(linkText).length !== linkText.length;
|
2018-01-21 21:44:25 -08:00
|
|
|
if (left || right) {
|
|
|
|
shared.addErrorContext(onError, token.lineNumber,
|
|
|
|
"[" + linkText + "]", left, right,
|
|
|
|
shared.rangeFromRegExp(token.line, spaceInLinkRe));
|
|
|
|
}
|
|
|
|
} else if (inLink) {
|
|
|
|
linkText += child.content;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|