/* -*- Mode: Javascript; indent-tabs-mode:nil; js-indent-level: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/*************************************************************
*
* MathJax/extensions/mml2jax.js
*
* Implements the MathML to Jax preprocessor that locates )
if (node.outerHTML != null && node.outerHTML.match(/(.<\/[A-Z]+>|\/>)$/)) {
for (i = 0, m = node.childNodes.length; i < m; i++)
{html += this.OuterHTML(node.childNodes[i])}
html += ""+node.nodeName.toLowerCase()+">";
}
}
return html;
},
OuterHTML: function (node) {
if (node.nodeName.charAt(0) === "#") {return this.NodeHTML(node)}
if (!this.AttributeBug) {return node.outerHTML}
var html = this.NodeHTML(node);
for (var i = 0, m = node.childNodes.length; i < m; i++)
{html += this.OuterHTML(node.childNodes[i]);}
html += ""+node.nodeName.toLowerCase()+">";
return html;
},
quoteHTML: function (string) {
if (string == null) {string = ""}
return string.replace(/&/g,"&").replace(//g,">").replace(/\"/g,""");
},
createPreview: function (math,script) {
var preview = this.config.preview;
if (preview === "none") return;
if (preview === "mathml") {preview = math}
else if (preview === "alttext" || preview === "altimg") {
var alttext = this.filterPreview(math.getAttribute("alttext"));
if (preview === "alttext") {
if (alttext != null) {preview = MathJax.HTML.TextNode(alttext)} else {preview = null}
} else {
var src = math.getAttribute("altimg");
if (src != null) {
// FIXME: use altimg-valign when display="inline"?
var style = {width: math.getAttribute("altimg-width"), height: math.getAttribute("altimg-height")};
preview = MathJax.HTML.Element("img",{src:src,alt:alttext,style:style});
} else {preview = null}
}
}
if (preview) {
var span = MathJax.HTML.Element("span",{className:MathJax.Hub.config.preRemoveClass});
span.appendChild(preview);
script.parentNode.insertBefore(span,script);
}
},
filterPreview: function (text) {return text},
InitBrowser: function () {
var test = MathJax.HTML.Element("span",{id:"<", className: "mathjax", innerHTML: "x"});
var html = test.outerHTML || "";
this.AttributeBug = html !== "" && !(
html.match(/id="<"/) && // "<" should convert to "<"
html.match(/class="mathjax"/) && // IE leaves out quotes
html.match(/<\/math>/) // Opera 9 drops tags after self-closing tags
);
this.MathTagBug = test.childNodes.length > 1; // IE < 9 flattens unknown tags
this.CleanupHTML = MathJax.Hub.Browser.isMSIE; // remove namespace and other added tags
}
};
// We register the preprocessors with the following priorities:
// - mml2jax.js: 5
// - jsMath2jax.js: 8
// - asciimath2jax.js, tex2jax.js: 10 (default)
// See issues 18 and 484 and the other *2jax.js files.
MathJax.Hub.Register.PreProcessor(["PreProcess",MathJax.Extension.mml2jax],5);
MathJax.Ajax.loadComplete("[MathJax]/extensions/mml2jax.js");