Skip to content

Commit 084385b

Browse files
committed
Update Safe.js to filter mathsize and not throw error for \mmlToken attributes that are filtered.
1 parent 25a10d7 commit 084385b

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed

unpacked/extensions/Safe.js

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,17 @@
9797
config: CONFIG,
9898
div1: document.createElement("div"), // for CSS processing
9999
div2: document.createElement("div"),
100+
101+
//
102+
// Methods called for MathML attribute processing
103+
//
104+
filter: {
105+
"class": "filterClass",
106+
id: "filterID",
107+
fontsize: "filterFontSize",
108+
mathsize: "filterFontSize",
109+
style: "filterStyles"
110+
},
100111

101112
//
102113
// Filter HREF URL's
@@ -242,9 +253,10 @@
242253
});
243254

244255
HUB.Register.StartupHook("TeX Jax Ready",function () {
245-
var TEX = MathJax.InputJax.TeX;
256+
var TEX = MathJax.InputJax.TeX,
257+
PARSE = TEX.Parse, METHOD = SAFE.filter;
246258

247-
TEX.Parse.Augment({
259+
PARSE.Augment({
248260

249261
//
250262
// Implements \require{name} with filtering
@@ -258,11 +270,9 @@
258270
//
259271
// Controls \mmlToken attributes
260272
//
261-
MmlTokenAllow: {
262-
fontsize: (ALLOW.fontsize === "all"),
263-
id: (ALLOW.cssIDs === "all"),
264-
"class": (ALLOW.classes === "all"),
265-
style: (ALLOW.styles === "all")
273+
MmlFilterAttribute: function (name,value) {
274+
if (METHOD[name]) {value = SAFE[METHOD[name]](value)}
275+
return value;
266276
},
267277

268278
//
@@ -292,16 +302,9 @@
292302
});
293303

294304
HUB.Register.StartupHook("MathML Jax Ready",function () {
295-
var PARSE = MathJax.InputJax.MathML.Parse;
305+
var PARSE = MathJax.InputJax.MathML.Parse,
306+
METHOD = SAFE.filter;
296307

297-
var METHOD = {
298-
href: "filterURL",
299-
"class": "filterClass",
300-
id: "filterID",
301-
fontsize: "filterFontSize",
302-
style: "filterStyles"
303-
};
304-
305308
//
306309
// Filter MathML attributes
307310
//

unpacked/jax/input/TeX/jax.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,15 +1441,18 @@
14411441
"%1 is not a recognized attribute for %2",
14421442
match[1],type]);
14431443
}
1444-
var value = match[2].replace(/^(['"])(.*)\1$/,"$2");
1445-
if (value.toLowerCase() === "true") {value = true}
1446-
else if (value.toLowerCase() === "false") {value = false}
1447-
def[match[1]] = value;
1448-
def.attrNames.push(match[1]);
1444+
var value = this.MmlFilterAttribute(match[1],match[2].replace(/^(['"])(.*)\1$/,"$2"));
1445+
if (value) {
1446+
if (value.toLowerCase() === "true") {value = true}
1447+
else if (value.toLowerCase() === "false") {value = false}
1448+
def[match[1]] = value;
1449+
def.attrNames.push(match[1]);
1450+
}
14491451
attr = attr.substr(match[0].length);
14501452
}
14511453
this.Push(this.mmlToken(MML[type](data).With(def)));
14521454
},
1455+
MmlFilterAttribute: function (name,value) {return value},
14531456
MmlTokenAllow: {
14541457
fontfamily:1, fontsize:1, fontweight:1, fontstyle:1,
14551458
color:1, background:1,

0 commit comments

Comments
 (0)