mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
A11Y: Set role=presentation if alt attr is missing (#18546)
This applies to all images posted that do not have a user description.
This commit is contained in:
@@ -173,6 +173,7 @@ export const DEFAULT_LIST = [
|
||||
"iframe[allowfullscreen]",
|
||||
"iframe[allow]",
|
||||
"img[alt]",
|
||||
"img[role]",
|
||||
"img[height]",
|
||||
"img[title]",
|
||||
"img[width]",
|
||||
|
||||
@@ -253,7 +253,13 @@ function renderImageOrPlayableMedia(tokens, idx, options, env, slf) {
|
||||
}
|
||||
}
|
||||
|
||||
token.attrs[token.attrIndex("alt")][1] = altSplit.join("|");
|
||||
const altValue = altSplit.join("|").trim();
|
||||
if (altValue === "") {
|
||||
token.attrSet("role", "presentation");
|
||||
} else {
|
||||
token.attrSet("alt", altValue);
|
||||
}
|
||||
|
||||
return slf.renderToken(tokens, idx, options);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user