mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-05 03:08:40 +00:00
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:
12
katex.js
12
katex.js
@@ -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 = {
|
||||
|
Reference in New Issue
Block a user