Skip to content

Commit

Permalink
[main.js] GetHTML: make handling of speakText more robust
Browse files Browse the repository at this point in the history
* improve selectors
* update tests
part of #289
  • Loading branch information
pkra committed Feb 8, 2017
1 parent 14c33c2 commit 5dc08bb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
9 changes: 6 additions & 3 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,9 +569,12 @@ 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.firstChild.getAttribute("aria-label")) html.firstChild.setAttribute("aria-label",result.speakText);
var labelTarget = html.querySelector('.mjx-math');
for (var i=0, m=labelTarget.childNodes.length; i < m; i++)
labelTarget.childNodes[i].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
5 changes: 3 additions & 2 deletions test/issue289.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
var tape = require('tape');
var mjAPI = require("../lib/main.js");

tape('mmlNode should not produce mml', function(t) {
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
htmlNode: true,
html: true
}, function(data) {
t.equal(data.htmlNode.parentNode.querySelectorAll('[aria-label]').length, 1, 'Aria-label is unique');
});
Expand Down

0 comments on commit 5dc08bb

Please sign in to comment.