Merge branch 'safe-patch' into v2.2-beta

This commit is contained in:
Davide P. Cervone 2013-05-14 14:54:38 -04:00
commit 6dad7d5a9e
3 changed files with 54 additions and 26 deletions

View File

@ -29,7 +29,9 @@
* limitations under the License.
*/
if (!MathJax.Hub.config.extensions) {MathJax.Hub.config.extensions = []}
MathJax.Hub.config.extensions.push("Safe.js");
MathJax.Hub.Register.StartupHook("End Config", function () {
if (!MathJax.Hub.config.extensions) {MathJax.Hub.config.extensions = []}
MathJax.Hub.config.extensions.push("Safe.js");
});
MathJax.Ajax.loadComplete("[MathJax]/config/Safe.js");
MathJax.Ajax.loadComplete("[MathJax]/config/Safe.js");

View File

@ -97,6 +97,20 @@
config: CONFIG,
div1: document.createElement("div"), // for CSS processing
div2: document.createElement("div"),
//
// Methods called for MathML attribute processing
//
filter: {
"class": "filterClass",
style: "filterStyles",
id: "filterID",
fontsize: "filterFontSize",
mathsize: "filterFontSize",
scriptminsize: "filterFontSize",
scriptsizemultiplier: "filterSizeMultiplier",
scriptlevel: "filterScriptLevel"
},
//
// Filter HREF URL's
@ -113,12 +127,12 @@
//
filterClass: function (CLASS) {
if (ALLOW.classes === "none" ||
(ALLOW.classes !== "all" && !CLASS.match(/^MJX-/))) {CLASS = null}
(ALLOW.classes !== "all" && !CLASS.match(/^MJX-[-a-zA-Z0-9_.]+$/))) {CLASS = null}
return CLASS;
},
filterID: function (id) {
if (ALLOW.cssIDs === "none" ||
(ALLOW.cssIDs !== "all" && !id.match(/^MJX-/))) {id = null}
(ALLOW.cssIDs !== "all" && !id.match(/^MJX-[-a-zA-Z0-9_.]+$/))) {id = null}
return id;
},
@ -171,6 +185,23 @@
return (ALLOW.fontsize === "all" ? size: null);
},
//
// Filter scriptsizemultiplier
//
filterSizeMultiplier: function (size) {
if (ALLOW.fontsize === "none") {size = null}
else if (ALLOW.fontsize !== "all") {size = Math.min(1,Math.max(.6,size)).toString()}
return size;
},
//
// Filter scriptLevel
//
filterScriptLevel: function (level) {
if (ALLOW.fontsize === "none") {level = null}
else if (ALLOW.fontsize !== "all") {level = Math.max(0,level).toString()}
return level;
},
//
// Filter TeX extension names
//
@ -242,9 +273,10 @@
});
HUB.Register.StartupHook("TeX Jax Ready",function () {
var TEX = MathJax.InputJax.TeX;
var TEX = MathJax.InputJax.TeX,
PARSE = TEX.Parse, METHOD = SAFE.filter;
TEX.Parse.Augment({
PARSE.Augment({
//
// Implements \require{name} with filtering
@ -258,11 +290,9 @@
//
// Controls \mmlToken attributes
//
MmlTokenAllow: {
fontsize: (ALLOW.fontsize === "all"),
id: (ALLOW.cssIDs === "all"),
"class": (ALLOW.classes === "all"),
style: (ALLOW.styles === "all")
MmlFilterAttribute: function (name,value) {
if (METHOD[name]) {value = SAFE[METHOD[name]](value)}
return value;
},
//
@ -292,16 +322,9 @@
});
HUB.Register.StartupHook("MathML Jax Ready",function () {
var PARSE = MathJax.InputJax.MathML.Parse;
var PARSE = MathJax.InputJax.MathML.Parse,
METHOD = SAFE.filter;
var METHOD = {
href: "filterURL",
"class": "filterClass",
id: "filterID",
fontsize: "filterFontSize",
style: "filterStyles"
};
//
// Filter MathML attributes
//

View File

@ -1441,15 +1441,18 @@
"%1 is not a recognized attribute for %2",
match[1],type]);
}
var value = match[2].replace(/^(['"])(.*)\1$/,"$2");
if (value.toLowerCase() === "true") {value = true}
else if (value.toLowerCase() === "false") {value = false}
def[match[1]] = value;
def.attrNames.push(match[1]);
var value = this.MmlFilterAttribute(match[1],match[2].replace(/^(['"])(.*)\1$/,"$2"));
if (value) {
if (value.toLowerCase() === "true") {value = true}
else if (value.toLowerCase() === "false") {value = false}
def[match[1]] = value;
def.attrNames.push(match[1]);
}
attr = attr.substr(match[0].length);
}
this.Push(this.mmlToken(MML[type](data).With(def)));
},
MmlFilterAttribute: function (name,value) {return value},
MmlTokenAllow: {
fontfamily:1, fontsize:1, fontweight:1, fontstyle:1,
color:1, background:1,