1/* March 19, 2004 MathHTML (c) Peter Jipsen http://www.chapman.edu/~jipsen 2This program is free software; you can redistribute it and/or modify 3it under the terms of the GNU General Public License as published by 4the Free Software Foundation; either version 2 of the License, or (at 5your option) any later version. 6This program is distributed in the hope that it will be useful, but 7WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 8or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 9(at http://www.gnu.org/copyleft/gpl.html) for more details.*/ 10 11function convertMath(node) {// for Gecko 12 if (node.nodeType==1) { 13 var newnode = 14 document.createElementNS("http://www.w3.org/1998/Math/MathML", 15 node.nodeName.toLowerCase()); 16 for(var i=0; i < node.attributes.length; i++) { 17 if (node.attributes[i].nodeName == 'displaystyle') { 18 newnode.setAttribute(node.attributes[i].nodeName,node.attributes[i].nodeValue); 19 } 20 } 21 for (var i=0; i<node.childNodes.length; i++) { 22 var st = node.childNodes[i].nodeValue; 23 if (st==null || st.slice(0,1)!=" " && st.slice(0,1)!="\n") 24 newnode.appendChild(convertMath(node.childNodes[i])); 25 } 26 return newnode; 27 } 28 else return node; 29} 30function convert() { 31 32 if (document.createElementNS) { 33 var mmlnode = document.getElementsByTagName("span"); 34 35 for (var i=0; i<mmlnode.length; i++) { 36 var tmp_node = mmlnode[i]; 37 if (tmp_node.className == 'asciimath') { 38 tmp_node.replaceChild(convertMath(tmp_node.firstChild),tmp_node.firstChild); 39 /* 40 for (var j=0;j<tmp_node.childNodes.length;j++) { 41 if (tmp_node.childNodes[j].nodeType != 3) { 42 43 } 44 } 45 */ 46 } 47 } 48 } else { 49 var st,node,newnode; 50 var mmlnode = document.getElementsByTagName("math"); 51 52 for (var i=0; i<mmlnode.length; i++) { 53 var str = ""; 54 node = mmlnode[i]; 55 while (node.nodeName!="/MATH" && node.nextSibling) { 56 st = node.nodeName.toLowerCase(); 57 if (st=="#text") { 58 str += node.nodeValue; 59 } else { 60 str += (st.slice(0,1)=="/" ? "</m:"+st.slice(1) : "<m:"+st); 61 if (st.slice(0,1)!="/") { 62 for(var j=0; j < node.attributes.length; j++) { 63 if (node.attributes[j].nodeValue!="italic" && 64 node.attributes[j].nodeValue!="" && 65 node.attributes[j].nodeValue!="inherit" && 66 node.attributes[j].nodeValue!=undefined) { 67 str += " "+node.attributes[j].nodeName+"="+ 68 "\""+node.attributes[j].nodeValue+"\""; 69 } 70 } 71 } 72 str += ">"; 73 } 74 node = node.nextSibling; 75 node.parentNode.removeChild(node.previousSibling); 76 } 77 78 if (str != '') { 79 str += "</m:math>"; 80 newnode = document.createElement("span"); 81 node.parentNode.replaceChild(newnode,node); 82 newnode.innerHTML = str; 83 } 84 } 85 } 86}