2018-01-21 21:44:25 -08:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
2019-04-13 11:18:57 -07:00
|
|
|
const { addErrorContext, bareUrlRe, filterTokens, rangeFromRegExp } =
|
|
|
|
|
require("../helpers");
|
2018-01-21 21:44:25 -08:00
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
"names": [ "MD034", "no-bare-urls" ],
|
|
|
|
|
"description": "Bare URL used",
|
|
|
|
|
"tags": [ "links", "url" ],
|
|
|
|
|
"function": function MD034(params, onError) {
|
2019-04-13 11:18:57 -07:00
|
|
|
filterTokens(params, "inline", function forToken(token) {
|
2018-04-27 22:05:34 -07:00
|
|
|
let inLink = false;
|
2018-01-21 21:44:25 -08:00
|
|
|
token.children.forEach(function forChild(child) {
|
2018-04-27 22:05:34 -07:00
|
|
|
let match = null;
|
2018-01-21 21:44:25 -08:00
|
|
|
if (child.type === "link_open") {
|
|
|
|
|
inLink = true;
|
|
|
|
|
} else if (child.type === "link_close") {
|
|
|
|
|
inLink = false;
|
|
|
|
|
} else if ((child.type === "text") &&
|
|
|
|
|
!inLink &&
|
2019-04-13 11:18:57 -07:00
|
|
|
(match = bareUrlRe.exec(child.content))) {
|
|
|
|
|
addErrorContext(onError, child.lineNumber, match[0], null,
|
|
|
|
|
null, rangeFromRegExp(child.line, bareUrlRe));
|
2018-01-21 21:44:25 -08:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|