-
-
Notifications
You must be signed in to change notification settings - Fork 320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider not adding empty alt tags to rendered images #718
Comments
OK, I did not know this. I agree that the reference implementations and test should be changed. |
This is better than `alt=""`, which signals to browsers that the image is not part of the main content. See commonmark/commonmark-spec#718.
I've now updated cmark and commonmark.js accordingly. |
I believe that this change is terrible for accessibility of millions of existing, accessible, blog posts and other markdown pages currently in the wild.
There is a chance that people did this, yes. And maybe that case is more likely, sure. But it is very valid to use empty alt attribute in HTML. This change breaks anyone that depended on that, and marks their sites as inaccessible. For more information, please see the HTML spec on the
While it is nice to cause some more linting warnings with a change like this, there are very valid use cases of empty alt attribute values, and this change makes it impossible to write valid empty alt attributes, such as when images are explained in surrounding prose already. In the past, some of markdown parsers in the JavaScript ecosystem made this mistake, not setting an empty string. People raised bugs, they were right, and it was fixed. This change also does not work well with consistency of CommonMark: |
I'll reopen for further comment. The change can always be reverted, nothing has been released yet. |
I'll note that the original Markdown.pl did not emit an alt with empty content. Pandoc followed it in this behavior. And I haven't had complaints about this over the 15+ years I've been maintaining pandoc. But according to babelmark pandoc is an outlier in this among modern implementations. |
I believe omitting
In my view, defaulting to Instead it's more likely that the author was either still working on the document and hasn't filled in the |
I don’t understand this. Why? I linked to the HTML spec above, which refutes your statements. The spec specifically recommends using an empty alt if the image is explained in prose. I am of the opinion that (almost) all images should be a non-essential thing, that can be omitted entirely. For people on slow internet connections. For people that are color blind, can’t look at a screen currently, for broken files, for copy/pasting, and numerous other reasons: explain what they add in surrounding prose, so that they don’t add anything essential. This stems in part from humans being terrible at writing alt text. Most people don’t get it right.
The problem with “chances” is that there are either false positives or false negatives. Because HTML is more expressive than markdown. Similar to empty src or href attributes. I don‘t want valid markdown, written in an accessible way, to be generates as inaccessible HTML just because there is a chance that other people write inaccessible HTML. If you want to check your markdown, there are markdown linters that you can enable. Or use an HTML linter that checks for empty alts if you believe that they are never okay. |
@coding-horror do you have any thoughts on this issue? |
I'm not arguing there aren't valid use cases for
Right now we can't know what the author intended if they write |
Do you have examples of this? Concrete reasons to make this assertion? I wonder if the statement is correct. The HTML spec goes into detail on why empty alt attributes are very valid in many cases. That figure + image w/ empty alt + caption style is also used in the HTML spec (giant page, slow to load, use What will happen if this goes through, in the scenario of people writing a website in markdown, is that suddenly their CI will start breaking because their HTML is no longer valid (not everyone will have that set up of course, but that is the intent behind this feature: to mark sites as inaccessible). ![Bismarck in 1836, at age 21](#)
Bismarck in 1836, at age 21 or inject bogus alt text: ![ ](#)
Bismarck in 1836, at age 21 …which are both very bad for accessibility. Why should CommonMark decide Wikipedia’s site is inaccessible? /**
* @typedef {import('mdast').Root} Root
*/
import {visit} from 'unist-util-visit'
/** @type {import('unified').Plugin<[], Root>} */
function myRemarkPluginCheckingEmptyAlts() {
return function (tree, file) {
visit(tree, (node) => {
if ((node.type === 'image' || node.type === 'imageReference') && !node.alt) {
file.warn('Expected `alt` text to be non-empty', node)
}
})
}
} |
Also, screen readers will read the filename of the image when there is no alt, which, except in interactive controls, is rather distracting. When the alt is empty, screen readers will skip it, or just read "image" (depending on how you navigate). |
I've reverted the change for now. |
Originally reported in markdown-it/markdown-it#885
Setup
![](nosuch)
Problem
Common Mark currently renders this image with an empty
alt
attribute.![](nosuch)
is rendered as<img src="nosuch" alt="">
.Renders as:
This is expected since according to mdn:
I know the spec isn't really about how markdown is rendered, so my suggestion is to change the tests for this: https://spec.commonmark.org/0.30/#example-580
It seems more likely to me that the user did mean to include the image and simply forgot the
alt
than that they wanted to hide the image from non-visual browsersThe text was updated successfully, but these errors were encountered: