Skip to content

Commit 3532ac3

Browse files
authored
Merge pull request #20551 from calixteman/bug2004951_part2
Don't add an aria-label on MathML elements in the struct tree (bug 2004951)
2 parents 91fa05d + da463f2 commit 3532ac3

4 files changed

Lines changed: 44 additions & 0 deletions

File tree

test/integration/accessibility_spec.mjs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,4 +460,42 @@ describe("accessibility", () => {
460460
);
461461
});
462462
});
463+
464+
describe("No alt-text with MathML", () => {
465+
let pages;
466+
467+
beforeEach(async () => {
468+
pages = await loadAndWait("bug2004951.pdf", ".textLayer");
469+
});
470+
471+
afterEach(async () => {
472+
await closePages(pages);
473+
});
474+
475+
it("must check that there's no alt-text on the MathML node", async () => {
476+
await Promise.all(
477+
pages.map(async ([browserName, page]) => {
478+
const isSanitizerSupported = await page.evaluate(() => {
479+
try {
480+
// eslint-disable-next-line no-undef
481+
return typeof Sanitizer !== "undefined";
482+
} catch {
483+
return false;
484+
}
485+
});
486+
const ariaLabel = await page.$eval(
487+
"span[aria-owns='p3R_mc2']",
488+
el => el.getAttribute("aria-label") || ""
489+
);
490+
if (isSanitizerSupported) {
491+
expect(ariaLabel).withContext(`In ${browserName}`).toEqual("");
492+
} else {
493+
expect(ariaLabel)
494+
.withContext(`In ${browserName}`)
495+
.toEqual("cube root of , x plus y end cube root ");
496+
}
497+
})
498+
);
499+
});
500+
});
463501
});

test/pdfs/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,3 +768,4 @@
768768
!issue20513.pdf
769769
!issue20516.pdf
770770
!issue20489.pdf
771+
!bug2004951.pdf

test/pdfs/bug2004951.pdf

58.3 KB
Binary file not shown.

web/struct_tree_layer_builder.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,13 +370,18 @@ class StructTreeLayerBuilder {
370370
elem.ariaHidden = true;
371371
}
372372
}
373+
// For now, we don't want to keep the alt text if there's valid
374+
// MathML (see https://github.com/w3c/mathml-aam/issues/37).
375+
// TODO: Revisit this decision in the future.
376+
delete node.alt;
373377
}
374378
if (
375379
!node.mathML &&
376380
node.children.length === 1 &&
377381
node.children[0].role !== "math"
378382
) {
379383
element = document.createElementNS(MathMLNamespace, "math");
384+
delete node.alt;
380385
}
381386
}
382387
}

0 commit comments

Comments
 (0)