commit 62af02bd4e8ec99ddfcae0b0e11998591e92ba2f
parent d17c0922e4f0ff2ec1eaf5da96c0d1c8fb7ef45b
Author: Ben Eater <eater@khanacademy.org>
Date: Tue, 12 Nov 2013 14:09:13 -0800
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
Diffstat:
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/katex.js b/katex.js
@@ -5,10 +5,11 @@ var parseTree = require("./parseTree");
var utils = require("./utils");
var process = function(toParse, baseNode) {
+ utils.clearNode(baseNode);
+
var tree = parseTree(toParse);
var node = buildTree(tree);
- utils.clearNode(baseNode);
baseNode.appendChild(node);
};