mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01:00
Add MD045/no-alt-text (fixes #75).
This commit is contained in:
parent
ac180ff9b9
commit
4fa837a031
8 changed files with 94 additions and 5 deletions
|
|
@ -86,11 +86,13 @@ playground for learning and exploring.
|
||||||
* **[MD042](doc/Rules.md#md042)** *no-empty-links* - No empty links
|
* **[MD042](doc/Rules.md#md042)** *no-empty-links* - No empty links
|
||||||
* **[MD043](doc/Rules.md#md043)** *required-headers* - Required header structure
|
* **[MD043](doc/Rules.md#md043)** *required-headers* - Required header structure
|
||||||
* **[MD044](doc/Rules.md#md044)** *proper-names* - Proper names should have the correct capitalization
|
* **[MD044](doc/Rules.md#md044)** *proper-names* - Proper names should have the correct capitalization
|
||||||
|
* **[MD045](doc/Rules.md#md045)** *no-alt-text* - Images should have ALT Text attribute
|
||||||
|
|
||||||
See [Rules.md](doc/Rules.md) for more details.
|
See [Rules.md](doc/Rules.md) for more details.
|
||||||
|
|
||||||
## Tags
|
## Tags
|
||||||
|
|
||||||
|
* **accessibility** - MD045
|
||||||
* **atx** - MD018, MD019
|
* **atx** - MD018, MD019
|
||||||
* **atx_closed** - MD020, MD021
|
* **atx_closed** - MD020, MD021
|
||||||
* **blank_lines** - MD012, MD022, MD031, MD032
|
* **blank_lines** - MD012, MD022, MD031, MD032
|
||||||
|
|
@ -103,6 +105,7 @@ See [Rules.md](doc/Rules.md) for more details.
|
||||||
MD024, MD025, MD026, MD036, MD041, MD043
|
MD024, MD025, MD026, MD036, MD041, MD043
|
||||||
* **hr** - MD035
|
* **hr** - MD035
|
||||||
* **html** - MD033
|
* **html** - MD033
|
||||||
|
* **images** - MD045
|
||||||
* **indentation** - MD005, MD006, MD007, MD027
|
* **indentation** - MD005, MD006, MD007, MD027
|
||||||
* **language** - MD040
|
* **language** - MD040
|
||||||
* **line_length** - MD013
|
* **line_length** - MD013
|
||||||
|
|
|
||||||
10
doc/Rules.md
10
doc/Rules.md
|
|
@ -1243,3 +1243,13 @@ the proper capitalization, specify the desired letter case in the `names` array:
|
||||||
]
|
]
|
||||||
|
|
||||||
Set the `code_blocks` parameter to `false` to disable this rule for code blocks.
|
Set the `code_blocks` parameter to `false` to disable this rule for code blocks.
|
||||||
|
|
||||||
|
<a name="md045"></a>
|
||||||
|
|
||||||
|
## MD045 - Images should have ALT Text attribute
|
||||||
|
|
||||||
|
Tags: accessibility, images
|
||||||
|
|
||||||
|
Aliases: no-alt-text
|
||||||
|
|
||||||
|
This rule is triggered when an image is found with no alt text. This is a key concern for accessibility. [Guidance on how to write alt text for images](https://www.phase2technology.com/blog/no-more-excuses-definitive-guide-alt-text-field).
|
||||||
|
|
|
||||||
18
lib/rules.js
18
lib/rules.js
|
|
@ -1219,5 +1219,23 @@ module.exports = [
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "MD045",
|
||||||
|
"desc": "Images should have ALT Text attribute",
|
||||||
|
"tags": [ "accessibility", "images" ],
|
||||||
|
"aliases": [ "no-alt-text" ],
|
||||||
|
"regexp": null,
|
||||||
|
"func": function MD045(params, errors) {
|
||||||
|
forEachInlineChild(params, "image", function forToken(token) {
|
||||||
|
if (token.content === "") {
|
||||||
|
token.attrs.forEach(function forAttr(attr) {
|
||||||
|
if (attr[0] === "alt" && attr[1] === "") {
|
||||||
|
errors.add(token.lineNumber);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -956,6 +956,16 @@
|
||||||
},
|
},
|
||||||
"additionalProperties": false
|
"additionalProperties": false
|
||||||
},
|
},
|
||||||
|
"MD045": {
|
||||||
|
"description": "MD045/no-alt-text - Images should have ALT Text attribute",
|
||||||
|
"type": "boolean",
|
||||||
|
"default": true
|
||||||
|
},
|
||||||
|
"no-alt-text": {
|
||||||
|
"description": "MD045/no-alt-text - Images should have ALT Text attribute",
|
||||||
|
"type": "boolean",
|
||||||
|
"default": true
|
||||||
|
},
|
||||||
"headers": {
|
"headers": {
|
||||||
"description": "headers - MD001, MD002, MD003, MD018, MD019, MD020, MD021, MD022, MD023, MD024, MD025, MD026, MD036, MD041, MD043",
|
"description": "headers - MD001, MD002, MD003, MD018, MD019, MD020, MD021, MD022, MD023, MD024, MD025, MD026, MD036, MD041, MD043",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
|
|
@ -1060,6 +1070,16 @@
|
||||||
"description": "spelling - MD044",
|
"description": "spelling - MD044",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": true
|
"default": true
|
||||||
|
},
|
||||||
|
"images": {
|
||||||
|
"description": "images - MD045",
|
||||||
|
"type": "boolean",
|
||||||
|
"default": true
|
||||||
|
},
|
||||||
|
"accessibility": {
|
||||||
|
"description": "accessibility - MD045",
|
||||||
|
"type": "boolean",
|
||||||
|
"default": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": false
|
"additionalProperties": false
|
||||||
|
|
|
||||||
|
|
@ -15,3 +15,11 @@ name wrong twice:
|
||||||
MarkDownLint.
|
MarkDownLint.
|
||||||
|
|
||||||
A [normal](link) and an [empty one]() and a [fragment](#one).
|
A [normal](link) and an [empty one]() and a [fragment](#one).
|
||||||
|
|
||||||
|
An image without alt text 
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
A reference image without alt text ![][reference]
|
||||||
|
|
||||||
|
[reference]: image.jpg "title"
|
||||||
|
|
@ -45,7 +45,7 @@
|
||||||
"errorRange": [25, 13]
|
"errorRange": [25, 13]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"lineNumber": 18,
|
"lineNumber": 25,
|
||||||
"ruleName": "MD043",
|
"ruleName": "MD043",
|
||||||
"ruleAlias": "required-headers",
|
"ruleAlias": "required-headers",
|
||||||
"ruleDescription": "Required header structure",
|
"ruleDescription": "Required header structure",
|
||||||
|
|
@ -79,5 +79,32 @@
|
||||||
"errorDetail": "Expected: markdownlint; Actual: MarkDownLint",
|
"errorDetail": "Expected: markdownlint; Actual: MarkDownLint",
|
||||||
"errorContext": null,
|
"errorContext": null,
|
||||||
"errorRange": [1, 12]
|
"errorRange": [1, 12]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"lineNumber": 19,
|
||||||
|
"ruleName": "MD045",
|
||||||
|
"ruleAlias": "no-alt-text",
|
||||||
|
"ruleDescription": "Images should have ALT Text attribute",
|
||||||
|
"errorDetail": null,
|
||||||
|
"errorContext": null,
|
||||||
|
"errorRange": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"lineNumber": 21,
|
||||||
|
"ruleName": "MD045",
|
||||||
|
"ruleAlias": "no-alt-text",
|
||||||
|
"ruleDescription": "Images should have ALT Text attribute",
|
||||||
|
"errorDetail": null,
|
||||||
|
"errorContext": null,
|
||||||
|
"errorRange": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"lineNumber": 23,
|
||||||
|
"ruleName": "MD045",
|
||||||
|
"ruleAlias": "no-alt-text",
|
||||||
|
"ruleDescription": "Images should have ALT Text attribute",
|
||||||
|
"errorDetail": null,
|
||||||
|
"errorContext": null,
|
||||||
|
"errorRange": null
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
@ -965,7 +965,7 @@ module.exports.missingStringValue = function missingStringValue(test) {
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.ruleNamesUpperCase = function ruleNamesUpperCase(test) {
|
module.exports.ruleNamesUpperCase = function ruleNamesUpperCase(test) {
|
||||||
test.expect(40);
|
test.expect(41);
|
||||||
rules.forEach(function forRule(rule) {
|
rules.forEach(function forRule(rule) {
|
||||||
test.equal(rule.name, rule.name.toUpperCase(), "Rule name not upper-case.");
|
test.equal(rule.name, rule.name.toUpperCase(), "Rule name not upper-case.");
|
||||||
});
|
});
|
||||||
|
|
@ -973,7 +973,7 @@ module.exports.ruleNamesUpperCase = function ruleNamesUpperCase(test) {
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.uniqueAliases = function uniqueAliases(test) {
|
module.exports.uniqueAliases = function uniqueAliases(test) {
|
||||||
test.expect(80);
|
test.expect(82);
|
||||||
var tags = [];
|
var tags = [];
|
||||||
rules.forEach(function forRule(rule) {
|
rules.forEach(function forRule(rule) {
|
||||||
Array.prototype.push.apply(tags, rule.tags);
|
Array.prototype.push.apply(tags, rule.tags);
|
||||||
|
|
@ -990,7 +990,7 @@ module.exports.uniqueAliases = function uniqueAliases(test) {
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.readme = function readme(test) {
|
module.exports.readme = function readme(test) {
|
||||||
test.expect(104);
|
test.expect(108);
|
||||||
var tagToRules = {};
|
var tagToRules = {};
|
||||||
rules.forEach(function forRule(rule) {
|
rules.forEach(function forRule(rule) {
|
||||||
rule.tags.forEach(function forTag(tag) {
|
rule.tags.forEach(function forTag(tag) {
|
||||||
|
|
@ -1052,7 +1052,7 @@ module.exports.readme = function readme(test) {
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.doc = function doc(test) {
|
module.exports.doc = function doc(test) {
|
||||||
test.expect(303);
|
test.expect(310);
|
||||||
fs.readFile("doc/Rules.md", shared.utf8Encoding,
|
fs.readFile("doc/Rules.md", shared.utf8Encoding,
|
||||||
function readFile(err, contents) {
|
function readFile(err, contents) {
|
||||||
test.ifError(err);
|
test.ifError(err);
|
||||||
|
|
|
||||||
3
test/no-alt-text.md
Normal file
3
test/no-alt-text.md
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
# This is an image link without any alt text
|
||||||
|
|
||||||
|
 {MD045}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue