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

View File

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

View File

@ -335,6 +335,22 @@
ucMatch: HTML.ucMatch, ucMatch: HTML.ucMatch,
setScript: HTML.setScript, 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 // Remove any existing output
// //
prev = script.previousSibling; 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); prev.parentNode.removeChild(prev);
// //
// Add the node for the math and mark it as being processed // Add the node for the math and mark it as being processed
@ -1328,7 +1344,7 @@
if (child) { if (child) {
var type = options.childNodes; var type = options.childNodes;
if (type) { if (type) {
if (type instanceof Array) type = type[i]; if (type instanceof Array) type = type[i]||"span";
node = CHTML.addElement(node,type); node = CHTML.addElement(node,type);
} }
cnode = child.toCommonHTML(node,options.childOptions); cnode = child.toCommonHTML(node,options.childOptions);
@ -2035,9 +2051,9 @@
// //
var base, under, over, nodes = []; var base, under, over, nodes = [];
if (stretch) { if (stretch) {
base = node.getElementsByTagName("mjx-op")[0]; base = CHTML.getNode(node,"mjx-op");
under = node.getElementsByTagName("mjx-under")[0]; under = CHTML.getNode(node,"mjx-under");
over = node.getElementsByTagName("mjx-over")[0]; over = CHTML.getNode(node,"mjx-over");
nodes[0] = base; nodes[1] = under||over; nodes[2] = over; nodes[0] = base; nodes[1] = under||over; nodes[2] = over;
} else { } else {
var types = ["mjx-op","mjx-under","mjx-over"]; var types = ["mjx-op","mjx-under","mjx-over"];
@ -2235,9 +2251,9 @@
// //
var base, sub, sup; var base, sub, sup;
if (stretch) { if (stretch) {
base = node.getElementsByTagName("mjx-base")[0]; base = CHTML.getNode(node,"mjx-base");
sub = node.getElementsByTagName("mjx-sub")[0]; sub = CHTML.getNode(node,"mjx-sub");
sup = node.getElementsByTagName("mjx-sup")[0]; sup = CHTML.getNode(node,"mjx-sup");
} else { } else {
var types = ["mjx-base","mjx-sub","mjx-sup"]; var types = ["mjx-base","mjx-sub","mjx-sup"];
if (this.sup === 1) types[1] = types[2]; if (this.sup === 1) types[1] = types[2];