scribble-math/katex.js
Ben Eater 62af02bd4e Empty the output element before parsing the input
If there's an exception while parsing (because it's something katex doesn't support), the output doesn't get cleared. Typically when this happens, we'll fall back to MathJax and render that in a different element, leaving the previous KaTex-formatted math plus the new MathJax-formatted math next to each other in the page, which is never what you'd want.

Test Plan: Using the fallback mechanism in khan-exercises utils/tex.js, render something katex can deal with, like "3", then using the same element, reprocess with something katex can't deal with, like "\approx 3". Previously the result would be "3 \approx 3" (with the first 3 being left over from the original katex rendering. With this change, only the "\approx 3" remains on the page.

Auditors: alex, alpert
2013-11-12 14:09:13 -08:00

20 lines
407 B
JavaScript

var ParseError = require("./ParseError");
var buildTree = require("./buildTree");
var parseTree = require("./parseTree");
var utils = require("./utils");
var process = function(toParse, baseNode) {
utils.clearNode(baseNode);
var tree = parseTree(toParse);
var node = buildTree(tree);
baseNode.appendChild(node);
};
module.exports = {
process: process,
ParseError: ParseError
};