Add MathML rendering to improve accessibility

Summary:
This adds support for rendering KaTeX to both HTML and MathML
with the intent of improving accessibility. To accomplish this, both
MathML and HTML are rendered, but with the MathML visually hidden and
the HTML spans aria-hidden. Hopefully, this should produce much better
accessibility for KaTeX.

Should fix/improve #38

Closes #189

Test Plan:
 - Ensure all the tests, and the new tests, still pass.
 - Ensure that for each of the group types in `buildHTML.js`, there is a
   corresponding one in `buildMathML.js`.
 - Ensure that the huxley screenshots didn't change (except for
   BinomTest, which changed because I fixed a bug in `buildHTML` where
   `genfrac` didn't have a `groupToType` mapping).
 - Run ChromeVox on the test page, render some math. (for example,
   `\sqrt{x^2}`)
   - Ensure that a mathy-sounding expression is read. (I hear "group
     square root of x squared math").
   - Ensure that nothing else is read (like no "x" or "2").
 - Ensure that MathML markup is generated correctly and is interpreted
   by the browser correctly by running
   `document.getElementById("math").innerHTML =
   katex.renderToString("\\sqrt{x^2}");` and seeing that the same speech
   is read.

Reviewers: john, alpert

Reviewed By: john, alpert

Subscribers: alpert, john

Differential Revision: https://phabricator.khanacademy.org/D16373
This commit is contained in:
Emily Eisenberg
2015-03-01 18:33:09 -08:00
parent 2349a1ed85
commit aaeab1200c
12 changed files with 1865 additions and 1185 deletions

View File

@@ -17,13 +17,13 @@ var utils = require("./src/utils");
* Parse and build an expression, and place that expression in the DOM node
* given.
*/
var render = function(toParse, baseNode, options) {
var render = function(expression, baseNode, options) {
utils.clearNode(baseNode);
var settings = new Settings(options);
var tree = parseTree(toParse, settings);
var node = buildTree(tree, settings).toNode();
var tree = parseTree(expression, settings);
var node = buildTree(tree, expression, settings).toNode();
baseNode.appendChild(node);
};
@@ -45,11 +45,11 @@ if (typeof document !== "undefined") {
/**
* Parse and build an expression, and return the markup for that.
*/
var renderToString = function(toParse, options) {
var renderToString = function(expression, options) {
var settings = new Settings(options);
var tree = parseTree(toParse, settings);
return buildTree(tree, settings).toMarkup();
var tree = parseTree(expression, settings);
return buildTree(tree, expression, settings).toMarkup();
};
module.exports = {