UNPKG

@storm-software/markdownlint

Version:

An opinionated collection of markdownlint rules used by Storm Software.

74 lines (67 loc) 2.88 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _chunk5BKT4CS5js = require('./chunk-5BKT4CS5.js'); // src/rules/no-default-alt-text.ts var require_no_default_alt_text = _chunk5BKT4CS5js.__commonJS.call(void 0, { "src/rules/no-default-alt-text.ts"(exports, module) { var defaultScreenshotRegex = `(?:screen|clean) ?(?:shot|cast) \\d{4}-\\d{2}-\\d{2}[^'"\\]]*`; var imageRegex = "image"; var combinedRegex = `(${[ defaultScreenshotRegex, imageRegex ].join("|")})`; var markdownAltRegex = new RegExp(`!\\[${combinedRegex}\\]\\(.*\\)`, "gid"); var htmlAltRegex = new RegExp(`alt=["']${combinedRegex}["']`, "gid"); module.exports = { names: [ "SSW01", "no-default-alt-text" ], description: "Images should have meaningful alternative text (alt text)", information: new URL("https://github.com/github/markdownlint-github/blob/main/docs/rules/GH001-no-default-alt-text.md"), tags: [ "accessibility", "images" ], function: /* @__PURE__ */ _chunk5BKT4CS5js.__name.call(void 0, function SS001(params, onError) { const htmlTagsWithImages = params.parsers.markdownit.tokens.filter((token) => { return token.type === "html_block" && token.content.includes("<img") || token.type === "inline" && token.content.includes("<img") && token.children.some((child) => child.type === "html_inline"); }); const inlineImages = params.parsers.markdownit.tokens.filter((token) => token.type === "inline" && token.children.some((child) => child.type === "image")); for (const token of [ ...htmlTagsWithImages, ...inlineImages ]) { const lineRange = token.map; const lineNumber = token.lineNumber; const lines = params.lines.slice(lineRange[0], lineRange[1]); for (let i = 0; i < lines.length; i++) { const line = lines[i]; let matches; if (token.type === "inline") { if (token.children.some((child) => child.type === "html_inline")) { matches = line.matchAll(htmlAltRegex); } else { matches = line.matchAll(markdownAltRegex); } } else { matches = line.matchAll(htmlAltRegex); } for (const match of matches) { const altText = match[1]; const [startIndex] = match.indices[1]; onError({ lineNumber: lineNumber + i, range: [ startIndex + 1, altText.length ], detail: `Flagged alt: ${altText}` }); } } } }, "SS001") }; } }); exports.require_no_default_alt_text = require_no_default_alt_text;