diff --git a/unpacked/extensions/MathML/content-mathml.js b/unpacked/extensions/MathML/content-mathml.js index 11560a86f..ed45f8ac0 100644 --- a/unpacked/extensions/MathML/content-mathml.js +++ b/unpacked/extensions/MathML/content-mathml.js @@ -44,27 +44,41 @@ MathJax.Hub.Register.StartupHook("mml Jax Ready",function () { var MATHML = MathJax.InputJax.MathML; MATHML.prefilterHooks.Add(function (data) { - // Parse the MathML source but add a dummy root to handle the HTML5 case - // where the MathML namespace may not be specified on the element. - var doc = MathJax.InputJax.MathML.ParseXML( - "" + - MATHML.Parse(data.math, true) + - ""); + // Parse the but use MATHML.Parse to apply the normal preprocessing. + if (!MATHML.ParseXML) {MATHML.ParseXML = MATHML.createParser()} + var doc = MathJax.InputJax.MathML.ParseXML(MATHML.Parse(data.math, true)); // Now transform the using the ctop stylesheet. - var newMath = MathJax.InputJax.MathML.ctopXSLT. - transformToFragment(doc.documentElement.firstChild, doc); + var newdoc = MathJax.InputJax.MathML. + ctopXSLT.transformToDocument(doc.documentElement); // Serialize the again. - var serializer = new XMLSerializer(); - data.math = serializer.serializeToString(newMath, doc); + if (window.XMLSerializer) { + var serializer = new XMLSerializer(); + data.math = serializer.serializeToString(newdoc.documentElement, doc); + } else { + data.math = newdoc.toString(); + } }); - if (!MATHML.ParseXML) {MATHML.ParseXML = MATHML.createParser()} - var ctopStylesheet = MathJax.InputJax.MathML.ParseXML(' +i +i / / ei ei E 0x . (-1) λ. id domain codomain image unexpected domainofapplication restriction {   if     otherwise / ! / max min (+) mod (×) gcd xor ¬ . . , || ¯ arg lcm = > < | d dddd D, + + , div div() grad grad() curl 2 () || × = lim lim tendsto e loglog , σ σ2 median mode () [|] [|] () () [m , | m , =;] () det || T , . Z R Q N C P e i NaN true false π γ () () ||, share ) ( ] [ } { ) ( ] [ } { \ )(}{>< top right ;color:;background-color:; 0 decimalpoint decimalpoint. decimalpoint*0.1em0.15em0.2em0.15em 0 /\)(:=) ', "text/xml"); + var ctopStylesheet = ' +i +i / / ei ei E 0x . (-1) λ. id domain codomain image unexpected domainofapplication restriction {   if     otherwise / ! / max min (+) mod (×) gcd xor ¬ . . , || ¯ arg lcm = > < | d dddd D, + + , div div() grad grad() curl 2 () || × = lim lim tendsto e loglog , σ σ2 median mode () [|] [|] () () [m , | m , =;] () det || T , . Z R Q N C P e i NaN true false π γ () () ||, share ) ( ] [ } { ) ( ] [ } { \ )(}{>< top right ;color:;background-color:; 0 decimalpoint decimalpoint. decimalpoint*0.1em0.15em0.2em0.15em 0 /\)(:=) '; if (window.XSLTProcessor) { + // standard method: just use an XSLTProcessor and parse the stylesheet + if (!MATHML.ParseXML) {MATHML.ParseXML = MATHML.createParser()} MATHML.ctopXSLT = new XSLTProcessor(); - MATHML.ctopXSLT.importStylesheet(ctopStylesheet); + MATHML.ctopXSLT.importStylesheet(MATHML.ParseXML(ctopStylesheet)); + } else { + // Internet Explorer <= 8: use transformNode + if (!MATHML.ParseXSLT) { + MATHML.ParseXSLT = MATHML.createMSParser(); + MATHML.ParseXSLT.async = false; + MATHML.ParseXSLT.loadXML(ctopStylesheet); + } + MATHML.ctopXSLT = { + transformToDocument: function(node) { + return node.transformNode(MATHML.ParseXSLT); + } + } } MathJax.Hub.Startup.signal.Post("MathML content-mathml Ready"); diff --git a/unpacked/jax/input/MathML/jax.js b/unpacked/jax/input/MathML/jax.js index b19180da8..7f7e6ea5a 100644 --- a/unpacked/jax/input/MathML/jax.js +++ b/unpacked/jax/input/MathML/jax.js @@ -30,9 +30,9 @@ MATHML.Parse = MathJax.Object.Subclass({ - Init: function (string, cleanUpOnly) { - if (cleanUpOnly) { - return this.cleanUpMath.call(this,string); + Init: function (string, preProcessMathOnly) { + if (preProcessMathOnly) { + return this.preProcessMath.call(this,string); } this.Parse(string); }, @@ -43,7 +43,7 @@ Parse: function (math) { var doc; if (typeof math !== "string") {doc = math.parentNode} else { - doc = MATHML.ParseXML(this.cleanUpMath.call(this,math)); + doc = MATHML.ParseXML(this.preProcessMath.call(this,math)); if (doc == null) {MATHML.Error("Error parsing MathML")} } var err = doc.getElementsByTagName("parsererror")[0]; @@ -161,7 +161,7 @@ // // Clean Up the source to prepare for XML parsing // - cleanUpMath: function (math) { + preProcessMath: function (math) { if (math.match(/^<[a-z]+:/i) && !math.match(/^<[^<>]* xmlns:/)) { math = math.replace(/^<([a-z]+)(:math)/i,'<$1$2 xmlns:$1="http://www.w3.org/1998/Math/MathML"') } @@ -170,6 +170,10 @@ if (match && match[2].match(/ (?!xmlns=)[a-z]+=\"http:/i)) { math = match[1].replace(/ (?!xmlns=)([a-z]+=(['"])http:.*?\2)/ig," xmlns:$1 $1") + math.substr(match[0].length); } + if (math.match(/^]* xmlns=/)) { + // append the MathML namespace + math = math.replace(/^<(math)/i,'\s*$/,"$2"); return math.replace(/&([a-z][a-z0-9]*);/ig,this.replaceEntity); }, @@ -253,6 +257,18 @@ return this.div; }, parseError: function (string) {return null}, + createMSParser: function() { + var parser = null; + var xml = ["MSXML2.DOMDocument.6.0","MSXML2.DOMDocument.5.0", + "MSXML2.DOMDocument.4.0","MSXML2.DOMDocument.3.0", + "MSXML2.DOMDocument.2.0","Microsoft.XMLDOM"]; + for (var i = 0, m = xml.length; i < m && !parser; i++) { + try { + parser = new ActiveXObject(xml[i]) + } catch (err) {} + } + return parser; + }, // // Create the parser using a DOMParser, or other fallback method // @@ -261,10 +277,7 @@ this.parser = new DOMParser(); return(this.parseDOM); } else if (window.ActiveXObject) { - var xml = ["MSXML2.DOMDocument.6.0","MSXML2.DOMDocument.5.0","MSXML2.DOMDocument.4.0", - "MSXML2.DOMDocument.3.0","MSXML2.DOMDocument.2.0","Microsoft.XMLDOM"]; - for (var i = 0, m = xml.length; i < m && !this.parser; i++) - {try {this.parser = new ActiveXObject(xml[i])} catch (err) {}} + this.parser = this.createMSParser(); if (!this.parser) { alert("MathJax can't create an XML parser for MathML. Check that\n"+ "the 'Script ActiveX controls marked safe for scripting' security\n"+