// it matched. clear the text node and create the three
// nodes before it - text, img, text (according to regexp match).
// NOTE: the reason we clear the node value instead of using it for
// the right part of the expression it to keep the cursor located
// at the end of the node if the cursor is on it
textNode.nodeValue = '';

// create the text node that should be after the image and insert it
var rightHalfNode = document.createTextNode(textNodeSplit[3]);
textNode.parentNode.insertBefore(rightHalfNode, textNode);

// create the text node that should be before the image and insert it
textNode.parentNode.insertBefore(document.createTextNode(textNodeSplit[1]), imgElement);

// set the new textNode to be what was left. maybe there's more
// to match (for example "[;A = B;] thus [;A \subseteq B;]")
textNode = rightHalfNode;
}
}
else {
// if the common ancestor is not the direct parent, stop immediately
if (startNode.parentNode != endNode.parentNode)
return;

// verify that the only tags in the range are <br> and <wbr>
var node;

// go through all children and check their textContent. in the meanwhile
// remember which index we are currently in, and then recurse until finding
// the actual node which contains the relevant index

// switch an image that was TeXified back to text.
// removes the ;s so that it doesn't get re-TeXified immediately
// double-click will re-TeXify is, and also adding the ;s back will do the job.
function unTeXifyImage(event) {
var imgElement = event.currentTarget;

// handle the keydown event -- if the key was ctrl-shift-; write our signature
function onKeyDown(event) {
// ctrl-shift-;
if (event.keyCode == 59 && (event.ctrlKey || event.metaKey) && event.shiftKey) {
// we use typing simulation in order to it to work not only in "regular" html components but also in
// high-tech javascript hacks like gmail and hotmail
simulateTextTyping(event.target, signature);
}
}