mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01:00
Refine implementation of MD045/no-alt-text in previous commit.
This commit is contained in:
parent
4fa837a031
commit
f91f0880c3
7 changed files with 61 additions and 44 deletions
|
|
@ -86,7 +86,7 @@ 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
|
* **[MD045](doc/Rules.md#md045)** *no-alt-text* - Images should have alternate text (alt text)
|
||||||
|
|
||||||
See [Rules.md](doc/Rules.md) for more details.
|
See [Rules.md](doc/Rules.md) for more details.
|
||||||
|
|
||||||
|
|
|
||||||
26
doc/Rules.md
26
doc/Rules.md
|
|
@ -1246,10 +1246,32 @@ Set the `code_blocks` parameter to `false` to disable this rule for code blocks.
|
||||||
|
|
||||||
<a name="md045"></a>
|
<a name="md045"></a>
|
||||||
|
|
||||||
## MD045 - Images should have ALT Text attribute
|
## MD045 - Images should have alternate text (alt text)
|
||||||
|
|
||||||
Tags: accessibility, images
|
Tags: accessibility, images
|
||||||
|
|
||||||
Aliases: no-alt-text
|
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).
|
This rule is triggered when an image is missing alternate text (alt text) information.
|
||||||
|
Alternate text is important for accessibility, describing the content of an image for
|
||||||
|
people who may not be able to see it.
|
||||||
|
|
||||||
|
Alternate text is commonly specified inline as:
|
||||||
|
|
||||||
|
```md
|
||||||
|

|
||||||
|
```
|
||||||
|
|
||||||
|
Or with reference syntax as:
|
||||||
|
|
||||||
|
```md
|
||||||
|
![Alternate text][ref]
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
[ref]: image.jpg "Optional title"
|
||||||
|
```
|
||||||
|
|
||||||
|
Guidance for writing alternate text is available from the [W3C](https://www.w3.org/WAI/alt/),
|
||||||
|
[Wikipedia](https://en.wikipedia.org/wiki/Alt_attribute), and
|
||||||
|
[other locations](https://www.phase2technology.com/blog/no-more-excuses-definitive-guide-alt-text-field).
|
||||||
|
|
|
||||||
|
|
@ -1222,18 +1222,14 @@ module.exports = [
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "MD045",
|
"name": "MD045",
|
||||||
"desc": "Images should have ALT Text attribute",
|
"desc": "Images should have alternate text (alt text)",
|
||||||
"tags": [ "accessibility", "images" ],
|
"tags": [ "accessibility", "images" ],
|
||||||
"aliases": [ "no-alt-text" ],
|
"aliases": [ "no-alt-text" ],
|
||||||
"regexp": null,
|
"regexp": null,
|
||||||
"func": function MD045(params, errors) {
|
"func": function MD045(params, errors) {
|
||||||
forEachInlineChild(params, "image", function forToken(token) {
|
forEachInlineChild(params, "image", function forToken(token) {
|
||||||
if (token.content === "") {
|
if (token.content === "") {
|
||||||
token.attrs.forEach(function forAttr(attr) {
|
errors.add(token.lineNumber);
|
||||||
if (attr[0] === "alt" && attr[1] === "") {
|
|
||||||
errors.add(token.lineNumber);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -957,12 +957,12 @@
|
||||||
"additionalProperties": false
|
"additionalProperties": false
|
||||||
},
|
},
|
||||||
"MD045": {
|
"MD045": {
|
||||||
"description": "MD045/no-alt-text - Images should have ALT Text attribute",
|
"description": "MD045/no-alt-text - Images should have alternate text (alt text)",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": true
|
"default": true
|
||||||
},
|
},
|
||||||
"no-alt-text": {
|
"no-alt-text": {
|
||||||
"description": "MD045/no-alt-text - Images should have ALT Text attribute",
|
"description": "MD045/no-alt-text - Images should have alternate text (alt text)",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": true
|
"default": true
|
||||||
},
|
},
|
||||||
|
|
@ -1071,13 +1071,13 @@
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": true
|
"default": true
|
||||||
},
|
},
|
||||||
"images": {
|
"accessibility": {
|
||||||
"description": "images - MD045",
|
"description": "accessibility - MD045",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": true
|
"default": true
|
||||||
},
|
},
|
||||||
"accessibility": {
|
"images": {
|
||||||
"description": "accessibility - MD045",
|
"description": "images - MD045",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": true
|
"default": true
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,10 +16,4 @@ 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 
|
An image without alternate text 
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
A reference image without alt text ![][reference]
|
|
||||||
|
|
||||||
[reference]: image.jpg "title"
|
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@
|
||||||
"errorRange": [25, 13]
|
"errorRange": [25, 13]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"lineNumber": 25,
|
"lineNumber": 20,
|
||||||
"ruleName": "MD043",
|
"ruleName": "MD043",
|
||||||
"ruleAlias": "required-headers",
|
"ruleAlias": "required-headers",
|
||||||
"ruleDescription": "Required header structure",
|
"ruleDescription": "Required header structure",
|
||||||
|
|
@ -84,25 +84,7 @@
|
||||||
"lineNumber": 19,
|
"lineNumber": 19,
|
||||||
"ruleName": "MD045",
|
"ruleName": "MD045",
|
||||||
"ruleAlias": "no-alt-text",
|
"ruleAlias": "no-alt-text",
|
||||||
"ruleDescription": "Images should have ALT Text attribute",
|
"ruleDescription": "Images should have alternate text (alt text)",
|
||||||
"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,
|
"errorDetail": null,
|
||||||
"errorContext": null,
|
"errorContext": null,
|
||||||
"errorRange": null
|
"errorRange": null
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,26 @@
|
||||||
# This is an image link without any alt text
|
# Images with and without alternate text
|
||||||
|
|
||||||
 {MD045}
|

|
||||||
|
|
||||||
|
 {MD045}
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
 {MD045}
|
||||||
|
|
||||||
|
Image without alternate text  in a sentence. {MD045}
|
||||||
|
|
||||||
|
Reference image with alternate text ![Alternate text][notitle]
|
||||||
|
|
||||||
|
Reference image without alternate text ![][notitle] {MD045}
|
||||||
|
|
||||||
|
Reference image with alternate text and title ![Alternate text][title]
|
||||||
|
|
||||||
|
Reference image without alternate text and title ![][title] {MD045}
|
||||||
|
|
||||||
|
Link to image with alternate text [](image.jpg)
|
||||||
|
|
||||||
|
Link to image without alternate text [](image.jpg) {MD045}
|
||||||
|
|
||||||
|
[notitle]: image.jpg
|
||||||
|
[title]: image.jpg "Title"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue