From 69a57f4da4b1dc37cffc6c8e56d69e50e7480443 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Sun, 12 Oct 2014 16:57:18 -0400 Subject: [PATCH] Make displaystyle and scriptlevel be forced only if they are in the list of default properties. Resolves issue #912 better than before. --- unpacked/extensions/toMathML.js | 13 +++++++------ unpacked/jax/element/mml/jax.js | 7 +++++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/unpacked/extensions/toMathML.js b/unpacked/extensions/toMathML.js index 61fb02ab5..aae34f73a 100644 --- a/unpacked/extensions/toMathML.js +++ b/unpacked/extensions/toMathML.js @@ -52,13 +52,14 @@ MathJax.Hub.Register.LoadHook("[MathJax]/jax/element/mml/jax.js",function () { toMathMLattributes: function () { var attr = [], defaults = this.defaults; - var copy = (this.attrNames||MML.copyAttributeNames), skip = MML.skipAttributes; + var names = (this.attrNames||MML.copyAttributeNames), + skip = MML.skipAttributes, copy = MML.copyAttributes; if (this.type === "math" && (!this.attr || !this.attr.xmlns)) {attr.push('xmlns="http://www.w3.org/1998/Math/MathML"')} if (!this.attrNames) { if (this.type === "mstyle") {defaults = MML.math.prototype.defaults} - for (var id in defaults) {if (!skip[id] && defaults.hasOwnProperty(id)) { + for (var id in defaults) {if (!skip[id] && !copy[id] && defaults.hasOwnProperty(id)) { if (this[id] != null && this[id] !== defaults[id]) { var value = this[id]; delete this[id]; if (this.Get(id) !== value) {attr.push(id+'="'+this.toMathMLattribute(value)+'"')} @@ -66,10 +67,10 @@ MathJax.Hub.Register.LoadHook("[MathJax]/jax/element/mml/jax.js",function () { } }} } - for (var i = 0, m = copy.length; i < m; i++) { - if (copy[i] === "class") continue; // this is handled separately below - value = (this.attr||{})[copy[i]]; if (value == null) {value = this[copy[i]]} - if (value != null) {attr.push(copy[i]+'="'+this.toMathMLquote(value)+'"')} + for (var i = 0, m = names.length; i < m; i++) { + if (copy[names[i]] === 1 && !defaults.hasOwnProperty(names[i])) continue; + value = (this.attr||{})[names[i]]; if (value == null) {value = this[names[i]]} + if (value != null) {attr.push(names[i]+'="'+this.toMathMLquote(value)+'"')} } this.toMathMLclass(attr); if (attr.length) {return " "+attr.join(" ")} else {return ""} diff --git a/unpacked/jax/element/mml/jax.js b/unpacked/jax/element/mml/jax.js index f8f56f1ef..55c3ac7c0 100644 --- a/unpacked/jax/element/mml/jax.js +++ b/unpacked/jax/element/mml/jax.js @@ -214,12 +214,15 @@ MathJax.ElementJax.mml.Augment({ NONE: -1 }, TEXCLASSNAMES: ["ORD", "OP", "BIN", "REL", "OPEN", "CLOSE", "PUNCT", "INNER", "VCENTER"], + skipAttributes: { + texClass:true, useHeight:true, texprimestyle:true + }, copyAttributes: { + displaystyle:1, scriptlevel:1, open:1, close:1, form:1, fontfamily:true, fontsize:true, fontweight:true, fontstyle:true, color:true, background:true, - id:true, "class":true, href:true, style:true + id:true, "class":1, href:true, style:true }, - skipAttributes: {texClass: true, useHeight: true, texprimestyle: true}, copyAttributeNames: [ "displaystyle", "scriptlevel", "open", "close", "form", // force these to be copied "fontfamily", "fontsize", "fontweight", "fontstyle",