Add getHtmlAttributeRe helper for creating a RegExp to match an HTML attribute name/value.

This commit is contained in:
David Anson 2023-10-18 23:45:39 -07:00
parent 531e58ed9a
commit 06466905a5
4 changed files with 36 additions and 15 deletions

View file

@ -2,11 +2,10 @@
"use strict";
const { addError, nextLinesRe } = require("../helpers");
const { addError, getHtmlAttributeRe, nextLinesRe } = require("../helpers");
const { filterByTypes, getHtmlTagInfo } = require("../helpers/micromark.cjs");
// Regular expression for identifying alt attribute
const altRe = /\salt=/i;
const altRe = getHtmlAttributeRe("alt");
module.exports = {
"names": [ "MD045", "no-alt-text" ],
@ -40,6 +39,7 @@ module.exports = {
const htmlTagInfo = getHtmlTagInfo(htmlText);
if (
htmlTagInfo &&
!htmlTagInfo.close &&
(htmlTagInfo.name.toLowerCase() === "img") &&
!altRe.test(text)
) {