Debian Codegraph @

ts/input/asciimath/mathjax2/legacy/jax/element/MmlNode.js

raw
1 (function () {
2 var MML = MathJax.ElementJax.mml;
3
4 var PROPERTY = [
5 'texWithDelims',
6 'movesupsub',
7 'subsupOK',
8 'primes',
9 'movablelimits',
10 'scriptlevel',
11 'open',
12 'close',
13 'isError',
14 'multiline',
15 'variantForm',
16 'autoOP',
17 'fnOP'
18 ];
19 var RENAME = {
20 texWithDelims: 'withDelims'
21 };
22
23 MML.mbase.Augment({
24 toMmlNode: function (factory) {
25 var kind = this.type;
26 if (kind === 'texatom') kind = 'TeXAtom';
27 var node = this.nodeMake(factory, kind);
28 if ("texClass" in this) node.texClass = this.texClass;
29 return node;
30 },
31 nodeMake: function (factory,kind) {
32 var node = factory.MML[kind === 'TeXmathchoice' ? 'mathchoice' : kind]();
33 var data = (this.data[0] && this.data[0].inferred && this.inferRow ? this.data[0].data : this.data);
34 for (var i = 0, m = data.length; i < m; i++) {
35 var child = data[i];
36 if (child) node.appendChild(child.toMmlNode(factory));
37 }
38 this.nodeAddAttributes(node);
39 this.nodeAddProperties(node);
40 return node;
41 },
42 nodeAddAttributes: function (node) {
43 var defaults = (this.type === "mstyle" ? MML.math.prototype.defaults : this.defaults);
44 var names = (this.attrNames||MML.copyAttributeNames),
45 skip = MML.skipAttributes,
46 copy = MML.copyAttributes;
47 if (!this.attrNames) {
48 for (var id in defaults) {
49 if (!skip[id] && !copy[id] && defaults.hasOwnProperty(id)) {
50 if (this[id] != null && this[id] !== defaults[id]) {
51 if (this.Get(id,null,1) !== this[id]) node.attributes.set(id,this[id]);
52 }
53 }
54 }
55 if (this['class']) node.attributes.set('class',this['class']);
56 }
57 for (var i = 0, m = names.length; i < m; i++) {
58 if (copy[names[i]] === 1 && !defaults.hasOwnProperty(names[i])) continue;
59 var value = (this.attr||{})[names[i]];
60 if (value == null) value = this[names[i]];
61 if (value === 'true' || value === 'false') value = (value === 'true');
62 if (value != null) node.attributes.set(names[i],value);
63 }
64 },
65 nodeAddProperties: function (node) {
66 for (var i = 0, m = PROPERTY.length; i < m; i++) {
67 var name = PROPERTY[i];
68 if (this[name] != null &&
69 (this.defaults[name] == null || this.defaults[name] === MML.AUTO)) {
70 node.setProperty(RENAME[name] || name, this[name]);
71 }
72 }
73 }
74 });
75
76 MML.chars.Augment({
77 toMmlNode: function (factory) {
78 return factory.MML.text().setText(this.data.join(""));
79 }
80 });
81 MML.entity.Augment({
82 toMmlNode: function (factory) {
83 return factory.MML.text().setText(this.toString());
84 }
85 });
86
87 MML.msubsup.Augment({
88 toMmlNode: function (factory) {
89 var kind = (this.data[this.sub] == null ? 'msup' :
90 this.data[this.sup] == null ? 'msub' : 'msubsup');
91 return this.nodeMake(factory, kind);
92 }
93 });
94
95 MML.munderover.Augment({
96 toMmlNode: function (factory) {
97 var kind = (this.data[this.under] == null ? 'mover' :
98 this.data[this.over] == null ? 'munder' : 'munderover');
99 return this.nodeMake(factory, kind);
100 }
101 });
102
103 MML.xml.Augment({
104 toMmlNode: function (factory) {
105 return factory.MML.xml(this.data);
106 }
107 });
108
109 })();