UNPKG

@storm-software/markdownlint

Version:

An opinionated collection of markdownlint rules used by Storm Software.

59 lines (52 loc) 2.28 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _chunk5BKT4CS5js = require('./chunk-5BKT4CS5.js'); // src/rules/no-empty-alt-text.ts var require_no_empty_alt_text = _chunk5BKT4CS5js.__commonJS.call(void 0, { "src/rules/no-empty-alt-text.ts"(exports, module) { module.exports = { names: [ "SSW03", "no-empty-alt-text" ], description: "Please provide an alternative text for the image.", information: new URL("https://github.com/github/markdownlint-github/blob/main/docs/rules/GH003-no-empty-alt-text.md"), tags: [ "accessibility", "images" ], function: /* @__PURE__ */ _chunk5BKT4CS5js.__name.call(void 0, function SS003(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 ImageRegex = new RegExp(/<img(.*?)>/, "gid"); const htmlEmptyAltRegex = new RegExp(/alt=['"]['"]/, "gid"); for (const token of htmlTagsWithImages) { const lineRange = token.map; const lineNumber = token.lineNumber; const lines = params.lines.slice(lineRange[0], lineRange[1]); for (const [i, line] of lines.entries()) { const imageTags = line.matchAll(ImageRegex); for (const imageTag of imageTags) { const imageTagIndex = imageTag.indices[0][0]; const emptyAltMatches = [ ...imageTag[0].matchAll(htmlEmptyAltRegex) ][0]; if (emptyAltMatches) { const matchingContent = emptyAltMatches[0]; const startIndex = emptyAltMatches.indices[0][0]; onError({ lineNumber: lineNumber + i, range: [ imageTagIndex + startIndex + 1, matchingContent.length ] }); } } } } }, "SS003") }; } }); exports.require_no_empty_alt_text = require_no_empty_alt_text;