Skip to content

Commit 6790255

Browse files
authored
[main.js] getHTML: add aria-label to correct childnode (#291)
* [main.js] getHTML: add aria-label to correct childnode Resolves #289 * [main.js] GetHTML: make handling of speakText more robust * improve selectors * update tests part of #289 * address review comments * fix whitespace
1 parent aa4f2b1 commit 6790255

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

lib/main.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -570,9 +570,11 @@ function GetHTML(result) {
570570

571571
// add speech text if there isn't one
572572
if (data.speakText){
573-
for (var i=0, m=html.childNodes.length; i < m; i++)
574-
html.childNodes[i].setAttribute("aria-hidden",true);
575-
if (!html.getAttribute("aria-label")) html.setAttribute("aria-label",result.speakText);
573+
var labelTarget = html.querySelector('.mjx-math');
574+
for (child of labelTarget.childNodes) child.setAttribute("aria-hidden",true);
575+
if (!labelTarget.getAttribute("aria-label")){
576+
labelTarget.setAttribute("aria-label",result.speakText);
577+
}
576578
}
577579
// remove automatically generated IDs
578580
var ids = html.querySelectorAll('[id^="MJXc-Node-"]');

test/issue207.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ tape('Generate dummy speechText', function(t) {
1717

1818
mjSpeechTest = function(data, expected, desc) {
1919
var document = jsdom(data.html).defaultView.document;
20-
var element = document.querySelector('.MJXc-display');
20+
var element = document.querySelector('.mjx-math');
2121
var actual = element.getAttribute('aria-label');
2222
t.equal(actual, expected, 'HTML output contains speechText from ' + desc);
2323
document = jsdom(data.mml).defaultView.document;

test/issue289.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
var tape = require('tape');
2+
var mjAPI = require("../lib/main.js");
3+
4+
tape('HTML output: add aria-label to correct childnode', function(t) {
5+
t.plan(1);
6+
mjAPI.start();
7+
var mml = '<math alttext="0"><mn>1</mn></math>';
8+
9+
mjAPI.typeset({
10+
math: mml,
11+
format: "MathML",
12+
htmlNode: true,
13+
html: true
14+
}, function(data) {
15+
t.equal(data.htmlNode.parentNode.querySelectorAll('[aria-label]').length, 1, 'Aria-label is unique');
16+
});
17+
});

0 commit comments

Comments
 (0)