Don't add an aria-label on MathML elements in the struct tree (bug 2004951)

This commit is contained in:
Calixte Denizet 2026-01-05 16:50:12 +01:00 committed by calixteman
parent 91fa05d2e8
commit da463f2da9
No known key found for this signature in database
GPG Key ID: 0C5442631EE0691F
4 changed files with 44 additions and 0 deletions

View File

@ -460,4 +460,42 @@ describe("accessibility", () => {
);
});
});
describe("No alt-text with MathML", () => {
let pages;
beforeEach(async () => {
pages = await loadAndWait("bug2004951.pdf", ".textLayer");
});
afterEach(async () => {
await closePages(pages);
});
it("must check that there's no alt-text on the MathML node", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
const isSanitizerSupported = await page.evaluate(() => {
try {
// eslint-disable-next-line no-undef
return typeof Sanitizer !== "undefined";
} catch {
return false;
}
});
const ariaLabel = await page.$eval(
"span[aria-owns='p3R_mc2']",
el => el.getAttribute("aria-label") || ""
);
if (isSanitizerSupported) {
expect(ariaLabel).withContext(`In ${browserName}`).toEqual("");
} else {
expect(ariaLabel)
.withContext(`In ${browserName}`)
.toEqual("cube root of , x plus y end cube root ");
}
})
);
});
});
});

View File

@ -768,3 +768,4 @@
!issue20513.pdf
!issue20516.pdf
!issue20489.pdf
!bug2004951.pdf

BIN
test/pdfs/bug2004951.pdf Executable file

Binary file not shown.

View File

@ -370,6 +370,10 @@ class StructTreeLayerBuilder {
elem.ariaHidden = true;
}
}
// For now, we don't want to keep the alt text if there's valid
// MathML (see https://github.com/w3c/mathml-aam/issues/37).
// TODO: Revisit this decision in the future.
delete node.alt;
}
if (
!node.mathML &&
@ -377,6 +381,7 @@ class StructTreeLayerBuilder {
node.children[0].role !== "math"
) {
element = document.createElementNS(MathMLNamespace, "math");
delete node.alt;
}
}
}