Skip to content

Commit

Permalink
chore(plugins/tidy-html): justify empty alt attribute over removal
Browse files Browse the repository at this point in the history
  • Loading branch information
Fdawgs committed Nov 14, 2022
1 parent ae61008 commit 361cec3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/plugins/tidy-html/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async function plugin(server) {
* Defaults to `en` if not set.
* @param {boolean=} options.removeAlt - Set `alt` attributes in `<img>` tags to empty string if set to `true`.
* Useful for sending to clinical systems where img tags are stripped from received documents
* (i.e. TPP's SystmOne).
* (i.e. TPP's SystmOne), and for screen reader users.
* @returns {string|Error} Tidied HTML; throws error if `options.language` is not valid IANA language tag.
*/
async function tidyHtml(html, options = {}) {
Expand All @@ -39,7 +39,13 @@ async function plugin(server) {
);
}

// Remove alt attribute from img tags
/**
* When an alt attribute is not present in an <img> tag, screen readers may announce the image's file name instead.
* This can be a confusing experience if the file name is not representative of the image's contents.
* See https://dequeuniversity.com/rules/axe/4.4/image-alt?application=axeAPI
*
* As such, alt attributes in <img> tags are set to an empty string rather than removed here.
*/
if (options?.removeAlt === true) {
const images = dom.window.document.querySelectorAll("img");
images.forEach((element) => {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/tidy-html/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe("Tidy-CSS Plugin", () => {
expect(response.statusCode).toBe(400);
});

test("Should remove alt attribute from img tags", async () => {
test("Should set alt attribute in img tags to empty string", async () => {
server.post("/", async (req) => {
const result = await server.tidyHtml(req.body, { removeAlt: true });
return result;
Expand Down

0 comments on commit 361cec3

Please sign in to comment.