From 87b3b5212e02f34b73ff0f18e2e8fd63f10df242 Mon Sep 17 00:00:00 2001 From: calixteman Date: Sun, 30 Nov 2025 22:20:24 +0100 Subject: [PATCH] Aria-hide the text content part of a MathML formula (bug 1998046) It'll avoid to have the text content and the MathML content read by screen readers. --- test/integration/accessibility_spec.mjs | 19 ++++++++++++++++--- web/struct_tree_layer_builder.js | 12 ++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/test/integration/accessibility_spec.mjs b/test/integration/accessibility_spec.mjs index 94472ddc8..52815f181 100644 --- a/test/integration/accessibility_spec.mjs +++ b/test/integration/accessibility_spec.mjs @@ -336,10 +336,20 @@ describe("accessibility", () => { expect(mathML) .withContext(`In ${browserName}`) .toEqual( - " x2 = |x| " + ` x2 = |x| ` ); + + // Check that the math corresponding element is hidden in the text + // layer. + const ariaHidden = await page.$eval("span#p58R_mc13", el => + el.getAttribute("aria-hidden") + ); + expect(ariaHidden).withContext(`In ${browserName}`).toEqual("true"); } else { - pending(`Sanitizer API (in ${browserName}) is not supported`); + // eslint-disable-next-line no-console + console.log( + `Pending in Chrome: Sanitizer API (in ${browserName}) is not supported` + ); } }) ); @@ -379,7 +389,10 @@ describe("accessibility", () => { ' 𝑛 𝑝 = 𝑛 mod 𝑝 ' ); } else { - pending(`Sanitizer API (in ${browserName}) is not supported`); + // eslint-disable-next-line no-console + console.log( + `Pending in Chrome: Sanitizer API (in ${browserName}) is not supported` + ); } }) ); diff --git a/web/struct_tree_layer_builder.js b/web/struct_tree_layer_builder.js index 393191420..94d7617c3 100644 --- a/web/struct_tree_layer_builder.js +++ b/web/struct_tree_layer_builder.js @@ -341,6 +341,18 @@ class StructTreeLayerBuilder { element.setHTML(node.mathML, { sanitizer: MathMLSanitizer.sanitizer, }); + // Hide all the corresponding content elements in the text layer in + // order to avoid screen readers reading both the MathML and the + // text content. + for (const { id } of node.children || []) { + if (!id) { + continue; + } + const elem = document.getElementById(id); + if (elem) { + elem.ariaHidden = true; + } + } } if ( !node.mathML &&