Update MD045/no-alt-text to allow violations when an HTML IMG has aria-hidden set to true (fixes #1576).

This commit is contained in:
David Anson 2025-04-27 18:42:25 -07:00
parent faf96d513b
commit b611eba684
7 changed files with 70 additions and 4 deletions

View file

@ -5,6 +5,7 @@ import { getHtmlTagInfo, getDescendantsByType } from "../helpers/micromark-helpe
import { filterByTypesCached } from "./cache.mjs";
const altRe = getHtmlAttributeRe("alt");
const ariaHiddenRe = getHtmlAttributeRe("aria-hidden");
/** @type {import("markdownlint").Rule} */
export default {
@ -40,7 +41,8 @@ export default {
htmlTagInfo &&
!htmlTagInfo.close &&
(htmlTagInfo.name.toLowerCase() === "img") &&
!altRe.test(text)
!altRe.test(text) &&
(ariaHiddenRe.exec(text)?.[1].toLowerCase() !== "true")
) {
const range = [
startColumn,