hack around clozes breaking mathjax

This commit is contained in:
Damien Elmes 2017-08-06 14:48:30 +10:00
parent 21b770cb10
commit 4c286fa3f7

View file

@ -8,6 +8,7 @@ function _updateQA(html, onupdate, onshown) {
qa.fadeTo(fadeTime, 0, function() {
// update text
qa.html(html);
_removeStylingFromMathjaxCloze();
onupdate(qa);
// don't allow drags of images, which cause them to be deleted
@ -64,3 +65,19 @@ function _typeAnsPress() {
pycmd("ans");
}
}
function _removeStylingFromMathjaxCloze() {
$(".cloze").each(function (i) {
if (_clozeIsInsideMathjax(this)) {
this.outerHTML = this.innerHTML;
}
});
}
function _clozeIsInsideMathjax(node) {
if (!node.previousSibling || node.previousSibling.nodeType !== 3) {
return;
}
// look for mathjax opening in previous text
return /\(|\$\$/.test(node.previousSibling.textContent);
}