forked from DavidAnson/markdownlint
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmd045.js
More file actions
30 lines (27 loc) · 915 Bytes
/
md045.js
File metadata and controls
30 lines (27 loc) · 915 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// @ts-check
"use strict";
const { addError } = require("../helpers");
const { filterByTypes } = require("../helpers/micromark.cjs");
module.exports = {
"names": [ "MD045", "no-alt-text" ],
"description": "Images should have alternate text (alt text)",
"tags": [ "accessibility", "images" ],
"function": function MD045(params, onError) {
const images = filterByTypes(params.parsers.micromark.tokens, [ "image" ]);
for (const image of images) {
const labelTexts = filterByTypes(image.children, [ "labelText" ]);
if (labelTexts.some((labelText) => labelText.text.length === 0)) {
const range = (image.startLine === image.endLine) ?
[ image.startColumn, image.endColumn - image.startColumn ] :
undefined;
addError(
onError,
image.startLine,
undefined,
undefined,
range
);
}
}
}
};