Skip to content

Commit 7116cde

Browse files
committed
Improve getNode() so that it doesn't find elements inside nodes that come from other MathML nodes (those with IDs). Resolves issue mathjax#1447.
1 parent 288e4f4 commit 7116cde

File tree

1 file changed

+11
-25
lines changed
  • unpacked/jax/output/CommonHTML

1 file changed

+11
-25
lines changed

unpacked/jax/output/CommonHTML/jax.js

+11-25
Original file line numberDiff line numberDiff line change
@@ -336,34 +336,20 @@
336336
ucMatch: HTML.ucMatch,
337337
setScript: HTML.setScript,
338338

339-
getNodesByClass: (document.getElementsByClassName ?
340-
function (node,type) {return node.getElementsByClassName(type)} :
341-
function (node,type) {
342-
var NODES = [];
343-
var nodes = node.getElementsByTagName("span");
344-
var name = RegExp("\\b"+type+"\\b");
345-
for (var i = 0, m = nodes.length; i < m; i++) {
346-
if (name.test(nodes[i].className)) NODES.push = nodes[i];
347-
}
348-
return NODES;
349-
}
350-
),
339+
//
340+
// Look through the children of a node for one with the given type
341+
// but don't step into child nodes that are from MathML elements
342+
// themselves (they will have IDs).
343+
//
351344
getNode: function (node,type) {
352-
var nodes = this.getNodesByClass(node,type);
353-
if (nodes.length === 1) return nodes[0];
354-
var closest = nodes[0], N = this.getNodeDepth(node,closest);
355-
for (var i = 1, m = nodes.length; i < m; i++) {
356-
var n = this.getNodeDepth(node,nodes[i]);
357-
if (n < N) {closest = nodes[i]; N = n}
345+
var name = RegExp("\\b"+type+"\\b");
346+
for (var i = 0, m = node.childNodes.length; i < m; i++) {
347+
var child = node.childNodes[i];
348+
if (name.test(child.className)) return child;
349+
if (child.id == null) return this.getNode(child,type);
358350
}
359-
return closest;
360351
},
361-
getNodeDepth: function (parent,node) {
362-
var n = 0;
363-
while (node && node !== parent) {node = node.parentNode; n++}
364-
return n;
365-
},
366-
352+
367353

368354
/********************************************/
369355

0 commit comments

Comments
 (0)