UNPKG

@storm-software/markdownlint

Version:

An opinionated collection of markdownlint rules used by Storm Software.

69 lines (66 loc) 2.19 kB
import { __commonJS, __name } from "./chunk-A3UDIEI3.mjs"; // src/rules/no-generic-link-text.ts var require_no_generic_link_text = __commonJS({ "src/rules/no-generic-link-text.ts"(exports, module) { function stripAndDowncaseText(text) { return text.toLowerCase().replace(/[.,/#!$%^&*;:{}=\-_`~()]/g, "").replace(/\s+/g, " ").trim(); } __name(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__ */ __name(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") }; } }); export { require_no_generic_link_text };