@storm-software/markdownlint
Version:
An opinionated collection of markdownlint rules used by Storm Software.
69 lines (62 loc) • 2.38 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true});
var _chunk5BKT4CS5js = require('./chunk-5BKT4CS5.js');
// src/rules/no-generic-link-text.ts
var require_no_generic_link_text = _chunk5BKT4CS5js.__commonJS.call(void 0, {
"src/rules/no-generic-link-text.ts"(exports, module) {
function stripAndDowncaseText(text) {
return text.toLowerCase().replace(/[.,/#!$%^&*;:{}=\-_`~()]/g, "").replace(/\s+/g, " ").trim();
}
_chunk5BKT4CS5js.__name.call(void 0, stripAndDowncaseText, "stripAndDowncaseText");
var bannedLinkText = [
"read more",
"learn more",
"more",
"here",
"click here",
"link"
];
module.exports = {
names: [
"SSW02",
"no-generic-link-text"
],
description: "Avoid using generic link text like `Learn more` or `Click here`",
information: new URL("https://github.com/github/markdownlint-github/blob/main/docs/rules/GH002-no-generic-link-text.md"),
tags: [
"accessibility",
"links"
],
function: /* @__PURE__ */ _chunk5BKT4CS5js.__name.call(void 0, function SS002(params, onError) {
let bannedLinkTexts = bannedLinkText.concat(params.config.additional_banned_texts || []);
const exceptions = params.config.exceptions || [];
if (exceptions.length > 0) {
bannedLinkTexts = bannedLinkTexts.filter((text) => !exceptions.includes(text));
}
const inlineTokens = params.tokens.filter((t) => t.type === "inline");
for (const token of inlineTokens) {
const { children } = token;
let inLink = false;
let linkText = "";
for (const child of children) {
const { content, type } = child;
if (type === "link_open") {
inLink = true;
linkText = "";
} else if (type === "link_close") {
inLink = false;
if (bannedLinkTexts.includes(stripAndDowncaseText(linkText))) {
onError({
lineNumber: child.lineNumber,
detail: `For link: ${linkText}`
});
}
} else if (inLink) {
linkText += content;
}
}
}
}, "SS002")
};
}
});
exports.require_no_generic_link_text = require_no_generic_link_text;