Skip to content

Instantly share code, notes, and snippets.

@jcmckeown
Last active April 8, 2016 20:49
Show Gist options
  • Save jcmckeown/0d00c005d0b4ff213707 to your computer and use it in GitHub Desktop.
Save jcmckeown/0d00c005d0b4ff213707 to your computer and use it in GitHub Desktop.
If you're using intensedebate comments on a page that already includes mathjax, this plugin script (to enter here: (http://intensedebate.com/pluginEditor/) ) will use the ambient mathjax to typeset maths in the comments. I have this running in my tumblr, http://jessecmckeown.tumblr.com .
var id_math_stuff = {
// id_math_stuff.theMJ
theMJ : window.MathJax,
// id_math_stuff.idMathRun =
idMathRun : function () {
if (id_math_stuff.theMJ) {
id_math_stuff.theMJ.Hub.Queue(["Typeset", id_math_stuff.theMJ.Hub, "idc-cover"]);
} else {
console.log("there is still no mathjax?");
}
},
// id_math_stuff.saveEscapes =
saveEscapes : function (commentext) {
var the_text = commentext.replace(/\?/ig, "?a");
the_text = the_text.replace(/\x5c/ig, "?b");
return the_text;
},
// id_math_stuff.escapeEscapes =
escapeEscapes : function (argRec) {
var the_text = argRec.text;
the_text = the_text.replace(/\?b/ig, "\\");
the_text = the_text.replace(/\?a/ig, "?");
return the_text;
},
// id_math_stuff.switchEdit =
switchEdit : function () {
if (!id_math_stuff.editComment) {
id_math_stuff.editComment = window.IDeditComment;
window.IDeditComment = function (commentid) {
var elt, nowJax, delim, t;
/** because it only seems sensible */
if (!commentObj.curUser.userid || commentObj.curUser.userid <= 0) {
return;
}
/** There shouldn't be scripts that aren't mathjax's! */
elt = document.getElementById("IDComment-CommentText" + commentid).getElementsByTagName("script");
while ( elt[0] ) {
t = elt [0] ;
nowJax = id_math_stuff.theMJ.Hub.getJaxFor(t);
delim = /display/.test(t.type) ? "$$" : "$";
t.insertAdjacentHTML('afterend', delim + nowJax.originalText + delim);
nowJax.Remove();
t.parentNode.removeChild(t);
}
id_math_stuff.editComment(commentid);
};
}
if (!id_math_stuff.saveComment) {
id_math_stuff.saveComment = window.IDsaveComment;
window.IDsaveComment = function (commentid) {
var textare = document.getElementById( "IDEditCommentTextArea"+commentid);
var theString = id_math_stuff.saveEscapes(textare.value);
textare.value = theString;
id_math_stuff.saveComment(commentid);
var ctext = document.getElementById( "IDComment-CommentText" + commentid);
ctext.innerHTML = id_math_stuff.escapeEscapes( ctext.innerHTML );
id_math_stuff.theMJ.Hub.Queue(["Typeset", id_math_stuff.theMJ.Hub, "idc-cover"]);
}
}
}
};
id_add_action('comment_post', id_math_stuff.idMathRun, 45);
id_add_action('idcomments_func_load', id_math_stuff.switchEdit, 99);
id_add_filter('pre_comment_text', id_math_stuff.saveEscapes, 2);
id_add_filter('comment_text_load', id_math_stuff.escapeEscapes, 40);
@jcmckeown
Copy link
Author

now v 7.1 ! MathJax kindly leaves "display" in the script "type" HTML attribute, whatever OutputJax one is using.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment