Skip to content

Commit

Permalink
[main.js] getHTML: add aria-label to correct childnode (#291)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
pkra committed Mar 13, 2017
1 parent dacd703 commit c8feb42
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
8 changes: 5 additions & 3 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -570,9 +570,11 @@ function GetHTML(result) {

// add speech text if there isn't one
if (data.speakText){
for (var i=0, m=html.childNodes.length; i < m; i++)
html.childNodes[i].setAttribute("aria-hidden",true);
if (!html.getAttribute("aria-label")) html.setAttribute("aria-label",result.speakText);
var labelTarget = html.querySelector('.mjx-math');
for (child of labelTarget.childNodes) child.setAttribute("aria-hidden",true);
if (!labelTarget.getAttribute("aria-label")){
labelTarget.setAttribute("aria-label",result.speakText);
}
}
// remove automatically generated IDs
var ids = html.querySelectorAll('[id^="MJXc-Node-"]');
Expand Down
2 changes: 1 addition & 1 deletion test/issue207.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ tape('Generate dummy speechText', function(t) {

mjSpeechTest = function(data, expected, desc) {
var document = jsdom(data.html).defaultView.document;
var element = document.querySelector('.MJXc-display');
var element = document.querySelector('.mjx-math');
var actual = element.getAttribute('aria-label');
t.equal(actual, expected, 'HTML output contains speechText from ' + desc);
document = jsdom(data.mml).defaultView.document;
Expand Down
17 changes: 17 additions & 0 deletions test/issue289.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var tape = require('tape');
var mjAPI = require("../lib/main.js");

tape('HTML output: add aria-label to correct childnode', function(t) {
t.plan(1);
mjAPI.start();
var mml = '<math alttext="0"><mn>1</mn></math>';

mjAPI.typeset({
math: mml,
format: "MathML",
htmlNode: true,
html: true
}, function(data) {
t.equal(data.htmlNode.parentNode.querySelectorAll('[aria-label]').length, 1, 'Aria-label is unique');
});
});

0 comments on commit c8feb42

Please sign in to comment.