| 1 |
(function () { |
| 2 |
var MML = MathJax.ElementJax.mml; |
| 3 |
|
| 4 |
MML.mbase.Augment({ |
| 5 |
toJSON: function () { |
| 6 |
var m = this.data.length; |
| 7 |
var json = {type: this.type}; |
| 8 |
if (this.inferred) json.inferred = true; |
| 9 |
if (this.isToken) { |
| 10 |
json.text = this.data.join(""); |
| 11 |
} else { |
| 12 |
json.children = new Array(m); |
| 13 |
for (var i = 0; i < m; i++) { |
| 14 |
var child = this.data[i]; |
| 15 |
if (child) json.children[i] = child.toJSON(); |
| 16 |
} |
| 17 |
} |
| 18 |
this.jsonAddAttributes(json); |
| 19 |
return json; |
| 20 |
}, |
| 21 |
jsonAddAttributes: function (json) { |
| 22 |
var defaults = (this.type === "mstyle" ? MML.math.prototype.defaults : this.defaults); |
| 23 |
var names = (this.attrNames||MML.copyAttributeNames), |
| 24 |
skip = MML.skipAttributes, |
| 25 |
copy = MML.copyAttributes; |
| 26 |
var attr = {}; |
| 27 |
|
| 28 |
if (!this.attrNames) { |
| 29 |
for (var id in defaults) { |
| 30 |
if (!skip[id] && !copy[id] && defaults.hasOwnProperty(id)) { |
| 31 |
if (this[id] != null && this[id] !== defaults[id]) { |
| 32 |
if (this.Get(id,null,1) !== this[id]) attr[id] = this[id]; |
| 33 |
} |
| 34 |
} |
| 35 |
} |
| 36 |
} |
| 37 |
for (var i = 0, m = names.length; i < m; i++) { |
| 38 |
if (copy[names[i]] === 1 && !defaults.hasOwnProperty(names[i])) continue; |
| 39 |
value = (this.attr||{})[names[i]]; |
| 40 |
if (value == null) value = this[names[i]]; |
| 41 |
if (value != null) attr[names[i]] = value; |
| 42 |
} |
| 43 |
json.attributes = attr; |
| 44 |
} |
| 45 |
}); |
| 46 |
|
| 47 |
MML.chars.Augment({ |
| 48 |
toJSON: function () { |
| 49 |
return this.data.join(""); |
| 50 |
} |
| 51 |
}); |
| 52 |
MML.entity.Augment({ |
| 53 |
toJSON: function () { |
| 54 |
return this.data.join(""); |
| 55 |
} |
| 56 |
}); |
| 57 |
|
| 58 |
MML.msubsup.Augment({ |
| 59 |
toJSON: function () { |
| 60 |
var json = this.SUPER(arguments).toJSON.call(this); |
| 61 |
if (this.data[this.sub] == null) { |
| 62 |
json.type = "msup"; |
| 63 |
json.children.splice(1,1); |
| 64 |
} |
| 65 |
if (this.data[this.sup] == null) { |
| 66 |
json.type = "msub"; |
| 67 |
json.children.splice(2,1); |
| 68 |
} |
| 69 |
return json; |
| 70 |
} |
| 71 |
}); |
| 72 |
|
| 73 |
MML.munderover.Augment({ |
| 74 |
toJSON: function () { |
| 75 |
var json = this.SUPER(arguments).toJSON.call(this); |
| 76 |
if (this.data[this.munder] == null) { |
| 77 |
json.type = "mover"; |
| 78 |
json.children.splice(1,1); |
| 79 |
} |
| 80 |
if (this.data[this.mover] == null) { |
| 81 |
json.type = "munder"; |
| 82 |
json.children.splice(2,1); |
| 83 |
} |
| 84 |
return json; |
| 85 |
} |
| 86 |
}); |
| 87 |
|
| 88 |
MML.TeXAtom.Augment({ |
| 89 |
toJSON: function () { |
| 90 |
var json = this.SUPER(arguments).toJSON.call(this); |
| 91 |
json.type = "mrow"; |
| 92 |
json.TeXAtom = MML.TEXCLASSNAMES[this.Get("texClass")]; |
| 93 |
return json; |
| 94 |
} |
| 95 |
}); |
| 96 |
|
| 97 |
MML.xml.Augment({ |
| 98 |
toJSON: function () { |
| 99 |
return {type:"xml", data: this.toString()}; |
| 100 |
} |
| 101 |
}); |
| 102 |
|
| 103 |
})(); |