Fix CHTML issues due to change from custom tags to span-with-class approach (i.e., replace uses of getElementsByTagName). Also fix some issues found by running the test suite.

This commit is contained in:
Davide P. Cervone 2015-09-13 17:48:29 -04:00
parent f54168eed3
commit 031dccee98
3 changed files with 38 additions and 22 deletions

View File

@ -45,7 +45,7 @@ MathJax.Hub.Register.StartupHook("CommonHTML Jax Ready",function () {
//
var base, bbox;
if (stretch) {
base = node.getElementsByTagName("mjx-base")[0];
base = CHTML.getNode(node,"mjx-base");
} else {
this.CHTMLaddChild(node,0,{type:"mjx-base", noBBox:true, forceChild:true});
base = node.firstChild;
@ -137,10 +137,10 @@ MathJax.Hub.Register.StartupHook("CommonHTML Jax Ready",function () {
//
CHTMLgetScripts: function (BOX,BBOX,stretch,node) {
if (stretch) {
BOX.sub = node.getElementsByTagName("mjx-sub")[0];
BOX.sup = node.getElementsByTagName("mjx-sup")[0];
BOX.presub = node.getElementsByTagName("mjx-presub")[0];
BOX.presup = node.getElementsByTagName("mjx-presup")[0];
BOX.sub = CHTML.getNode(node,"mjx-sub");
BOX.sup = CHTML.getNode(node,"mjx-sup");
BOX.presub = CHTML.getNode(node,"mjx-presub");
BOX.presup = CHTML.getNode(node,"mjx-presup");
BBOX.sub = this.CHTMLbbox.sub;
BBOX.sup = this.CHTMLbbox.sup;
BBOX.presub = this.CHTMLbbox.presub;

View File

@ -505,9 +505,9 @@ MathJax.Hub.Register.StartupHook("CommonHTML Jax Ready",function () {
//
if (end.length === 0) {
var NODE = this.CHTMLnodeElement(),
stack = NODE.getElementsByTagName("mjx-stack")[0],
sup = NODE.getElementsByTagName("mjx-sup")[0],
sub = NODE.getElementsByTagName("mjx-sub")[0];
stack = CHTML.getNode(NODE,"mjx-stack"),
sup = CHTML.getNode(NODE,"mjx-sup"),
sub = CHTML.getNode(NODE,"mjx-sub");
if (stack) node.appendChild(stack);
else if (sup) node.appendChild(sup);
else if (sub) node.appendChild(sub);
@ -569,9 +569,9 @@ MathJax.Hub.Register.StartupHook("CommonHTML Jax Ready",function () {
//
if (start.length < 1) {
NODE = this.CHTMLnodeElement();
var prestack = NODE.getElementsByTagName("mjx-prestack")[0],
presup = NODE.getElementsByTagName("mjx-presup")[0],
presub = NODE.getElementsByTagName("mjx-presub")[0];
var prestack = CHTML.getNode(NODE,"mjx-prestack"),
presup = CHTML.getNode(NODE,"mjx-presup"),
presub = CHTML.getNode(NODE,"mjx-presub");
if (prestack) node.appendChild(prestack);
else if (presup) node.appendChild(presup);
else if (presub) node.appendChild(presub);
@ -598,9 +598,9 @@ MathJax.Hub.Register.StartupHook("CommonHTML Jax Ready",function () {
//
if (end.length === 0) {
NODE = this.CHTMLnodeElement();
var stack = NODE.getElementsByTagName("mjx-stack")[0],
sup = NODE.getElementsByTagName("mjx-sup")[0],
sub = NODE.getElementsByTagName("mjx-sub")[0];
var stack = CHTML.getNode(NODE,"mjx-stack"),
sup = CHTML.getNode(NODE,"mjx-sup"),
sub = CHTML.getNode(NODE,"mjx-sub");
if (stack) node.appendChild(stack);
else if (sup) node.appendChild(sup);
else if (sub) node.appendChild(sub);

View File

@ -335,6 +335,22 @@
ucMatch: HTML.ucMatch,
setScript: HTML.setScript,
//
// This replaces node.getElementsByTagName(type)[0]
// and should be replaced by that if we go back to using
// custom tags
//
getNode: (document.getElementsByClassName ?
function (node,type) {return node.getElementsByClassName(type)[0]} :
function (node,type) {
var nodes = node.getElementsByTagName("span");
var name = RegExp("\\b"+type+"\\b");
for (var i = 0, m = nodes.length; i < m; i++) {
if (name.test(nodes[i].className)) return nodes[i];
}
}
),
/********************************************/
@ -361,7 +377,7 @@
// Remove any existing output
//
prev = script.previousSibling;
if (prev && prev.className.substr(0,9) === "mjx-chtml")
if (prev && prev.className && String(prev.className).substr(0,9) === "mjx-chtml")
prev.parentNode.removeChild(prev);
//
// Add the node for the math and mark it as being processed
@ -1328,7 +1344,7 @@
if (child) {
var type = options.childNodes;
if (type) {
if (type instanceof Array) type = type[i];
if (type instanceof Array) type = type[i]||"span";
node = CHTML.addElement(node,type);
}
cnode = child.toCommonHTML(node,options.childOptions);
@ -2035,9 +2051,9 @@
//
var base, under, over, nodes = [];
if (stretch) {
base = node.getElementsByTagName("mjx-op")[0];
under = node.getElementsByTagName("mjx-under")[0];
over = node.getElementsByTagName("mjx-over")[0];
base = CHTML.getNode(node,"mjx-op");
under = CHTML.getNode(node,"mjx-under");
over = CHTML.getNode(node,"mjx-over");
nodes[0] = base; nodes[1] = under||over; nodes[2] = over;
} else {
var types = ["mjx-op","mjx-under","mjx-over"];
@ -2235,9 +2251,9 @@
//
var base, sub, sup;
if (stretch) {
base = node.getElementsByTagName("mjx-base")[0];
sub = node.getElementsByTagName("mjx-sub")[0];
sup = node.getElementsByTagName("mjx-sup")[0];
base = CHTML.getNode(node,"mjx-base");
sub = CHTML.getNode(node,"mjx-sub");
sup = CHTML.getNode(node,"mjx-sup");
} else {
var types = ["mjx-base","mjx-sub","mjx-sup"];
if (this.sup === 1) types[1] = types[2];