Merge remote-tracking branch 'fred/content-mathml' into develop
Add Content MathML support.
This commit is contained in:
commit
607b1031a3
112
unpacked/extensions/MathML/content-mathml.js
Normal file
112
unpacked/extensions/MathML/content-mathml.js
Normal file
File diff suppressed because one or more lines are too long
|
@ -1,3 +1,5 @@
|
|||
/* -*- Mode: Javascript; indent-tabs-mode:nil; js-indent-level: 2 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/*************************************************************
|
||||
*
|
||||
* MathJax/jax/input/MathML/jax.js
|
||||
|
@ -36,17 +38,8 @@
|
|||
Parse: function (math) {
|
||||
var doc;
|
||||
if (typeof math !== "string") {doc = math.parentNode} else {
|
||||
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"')}
|
||||
// HTML5 removes xmlns: namespaces, so put them back for XML
|
||||
var match = math.match(/^(<math( ('.*?'|".*?"|[^>])+)>)/i);
|
||||
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);
|
||||
}
|
||||
math = math.replace(/^\s*(?:\/\/)?<!(--)?\[CDATA\[((.|\n)*)(\/\/)?\]\]\1>\s*$/,"$2");
|
||||
math = math.replace(/&([a-z][a-z0-9]*);/ig,this.replaceEntity);
|
||||
doc = MATHML.ParseXML(math); if (doc == null) {MATHML.Error("Error parsing MathML")}
|
||||
doc = MATHML.ParseXML(this.preProcessMath.call(this,math));
|
||||
if (doc == null) {MATHML.Error("Error parsing MathML")}
|
||||
}
|
||||
var err = doc.getElementsByTagName("parsererror")[0];
|
||||
if (err) MATHML.Error("Error parsing MathML: "+err.textContent.replace(/This page.*?errors:|XML Parsing Error: |Below is a rendering of the page.*/g,""));
|
||||
|
@ -160,6 +153,26 @@
|
|||
}
|
||||
},
|
||||
|
||||
//
|
||||
// Clean Up the <math> source to prepare for XML parsing
|
||||
//
|
||||
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"')
|
||||
}
|
||||
// HTML5 removes xmlns: namespaces, so put them back for XML
|
||||
var match = math.match(/^(<math( ('.*?'|".*?"|[^>])+)>)/i);
|
||||
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(/^<math/i) && !math.match(/^<[^<>]* xmlns=/)) {
|
||||
// append the MathML namespace
|
||||
math = math.replace(/^<(math)/i,'<math xmlns="http://www.w3.org/1998/Math/MathML"')
|
||||
}
|
||||
math = math.replace(/^\s*(?:\/\/)?<!(--)?\[CDATA\[((.|\n)*)(\/\/)?\]\]\1>\s*$/,"$2");
|
||||
return math.replace(/&([a-z][a-z0-9]*);/ig,this.replaceEntity);
|
||||
},
|
||||
|
||||
//
|
||||
// Remove attribute whitespace
|
||||
//
|
||||
|
@ -239,6 +252,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
|
||||
//
|
||||
|
@ -247,10 +272,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"+
|
||||
|
|
Loading…
Reference in New Issue
Block a user