Skip to content

Commit 2953e01

Browse files
committed
Fix problems with annotation-xml in IE (work around IE lack of importNode, and bug with copying style attributes
1 parent 0d9bb61 commit 2953e01

File tree

12 files changed

+55
-25
lines changed

12 files changed

+55
-25
lines changed

config/Accessible-full.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/Accessible.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/MML_HTMLorMML-full.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/MML_HTMLorMML.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/TeX-AMS-MML_HTMLorMML-full.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/TeX-AMS-MML_HTMLorMML.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/TeX-AMS_HTML-full.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/TeX-AMS_HTML.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extensions/mml2jax.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jax/element/mml/jax.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unpacked/extensions/mml2jax.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,14 @@ MathJax.Extension.mml2jax = {
124124
// In IE, outerHTML doesn't properly quote attributes, so quote them by hand
125125
// In Opera, HTML special characters aren't quoted in attributes, so quote them
126126
html = "<"+node.nodeName.toLowerCase();
127-
var attributes = node.attributes;
128-
for (i = 0, m = attributes.length; i < m; i++) {
129-
if (attributes[i].specified) {
130-
// Opera 11.5 beta turns xmlns into xmlns:xmlns, so put it back
131-
// *** FIXME: Similar problems may occur for other attributes?
132-
html += " "+attributes[i].nodeName.toLowerCase().replace(/xmlns:xmlns/,"xmlns")+"=";
133-
html += '"'+this.quoteHTML(attributes[i].nodeValue)+'"';
127+
for (i = 0, m = node.attributes.length; i < m; i++) {
128+
var attribute = node.attributes[i];
129+
if (attribute.specified) {
130+
// Opera 11.5 beta turns xmlns into xmlns:xmlns, so put it back (*** check after 11.5 is out ***)
131+
html += " "+attribute.nodeName.toLowerCase().replace(/xmlns:xmlns/,"xmlns")+"=";
132+
var value = attribute.nodeValue; // IE < 8 doesn't properly set style by setAttributes
133+
if (value == null && attribute.nodeName === "style" && node.style) {value = node.style.cssText}
134+
html += '"'+this.quoteHTML(value)+'"';
134135
}
135136
}
136137
html += ">";
@@ -153,6 +154,7 @@ MathJax.Extension.mml2jax = {
153154
return html;
154155
},
155156
quoteHTML: function (string) {
157+
if (string == null) {string = ""}
156158
return string.replace(/&/g,"&#x26;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;");
157159
},
158160

unpacked/jax/element/mml/jax.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,10 +1183,38 @@ MathJax.ElementJax.mml.Augment({
11831183
},
11841184
Append: function () {
11851185
for (var i = 0, m = arguments.length; i < m; i++) {
1186-
this.data.push(arguments[i]);
1187-
this.div.appendChild(document.importNode(arguments[i],true));
1186+
var node = this.Import(arguments[i]);
1187+
this.data.push(node);
1188+
this.div.appendChild(node);
11881189
}
11891190
},
1191+
Import: function (node) {
1192+
if (document.importNode) {return document.importNode(node,true)}
1193+
//
1194+
// IE < 9 doesn't have importNode, so fake it.
1195+
//
1196+
var nNode, i, m;
1197+
if (node.nodeType === 1) { // ELEMENT_NODE
1198+
nNode = document.createElement(node.nodeName);
1199+
if (node.className) {nNode.className=iNode.className}
1200+
for (i = 0, m = node.attributes.length; i < m; i++) {
1201+
var attribute = node.attributes[i];
1202+
if (attribute.specified && attribute.nodeValue != null && attribute.nodeValue != '')
1203+
{nNode.setAttribute(attribute.nodeName,attribute.nodeValue)}
1204+
if (attribute.nodeName === "style") {nNode.style.cssText = attribute.nodeValue}
1205+
}
1206+
if (node.className) {nNode.className = node.className}
1207+
} else if (node.nodeType === 3 || node.nodeType === 4) { // TEXT_NODE or CDATA_SECTION_NODE
1208+
nNode = document.createTextNode(node.nodeValue);
1209+
} else if (node.nodeType === 8) { // COMMENT_NODE
1210+
nNode = document.createComment(node.nodeValue);
1211+
} else {
1212+
return document.createTextNode('');
1213+
}
1214+
for (i = 0, m = node.childNodes.length; i < m; i++)
1215+
{nNode.appendChild(this.Import(node.childNodes[i]))}
1216+
return nNode;
1217+
},
11901218
value: function () {return this.div},
11911219
toString: function () {return this.div.innerHTML}
11921220
});

0 commit comments

Comments
 (0)