
Summary: KaTeX doesn't work correctly in quirks mode. Warn in the console and disable rendering if that happens. Test Plan: - Make sure the test still loads and renders math - Make sure a warning is thrown when the doctype is removed, and no more math is rendered - Make sure the tests pass both on the web and with `make test` Reviewers: alpert Reviewed By: alpert Differential Revision: http://phabricator.khanacademy.org/D13192
55 lines
1.5 KiB
JavaScript
55 lines
1.5 KiB
JavaScript
/**
|
|
* This is the main entry point for KaTeX. Here, we expose functions for
|
|
* rendering expressions either to DOM nodes or to markup strings.
|
|
*
|
|
* We also expose the ParseError class to check if errors thrown from KaTeX are
|
|
* errors in the expression, or errors in javascript handling.
|
|
*/
|
|
|
|
var ParseError = require("./src/ParseError");
|
|
|
|
var buildTree = require("./src/buildTree");
|
|
var parseTree = require("./src/parseTree");
|
|
var utils = require("./src/utils");
|
|
|
|
/**
|
|
* Parse and build an expression, and place that expression in the DOM node
|
|
* given.
|
|
*/
|
|
var render = function(toParse, baseNode) {
|
|
utils.clearNode(baseNode);
|
|
|
|
var tree = parseTree(toParse);
|
|
var node = buildTree(tree).toNode();
|
|
|
|
baseNode.appendChild(node);
|
|
};
|
|
|
|
// KaTeX's styles don't work properly in quirks mode. Print out an error, and
|
|
// disable rendering.
|
|
if (typeof document !== "undefined") {
|
|
if (document.compatMode !== "CSS1Compat") {
|
|
typeof console !== "undefined" && console.warn(
|
|
"Warning: KaTeX doesn't work in quirks mode. Make sure your " +
|
|
"website has a suitable doctype.");
|
|
|
|
render = function() {
|
|
throw new ParseError("KaTeX doesn't work in quirks mode.");
|
|
};
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Parse and build an expression, and return the markup for that.
|
|
*/
|
|
var renderToString = function(toParse) {
|
|
var tree = parseTree(toParse);
|
|
return buildTree(tree).toMarkup();
|
|
};
|
|
|
|
module.exports = {
|
|
render: render,
|
|
renderToString: renderToString,
|
|
ParseError: ParseError
|
|
};
|