var MathMLFragments = { "annotation": "\ \ \ \ ", "annotation-xml": "\ \ \ \ ", "maction": "\ \ \ \ ", "menclose": "", "merror": "", "mfrac": "\ \ \ \ ", "mi": "", "mmultiscripts": "\ \ \ \ \ ", "mn": "", "mo": "", "mover": "\ \ \ \ ", "mpadded": "", "mphantom": "", "mprescripts": "\ \ \ \ \ \ ", "mroot": "\ \ \ \ ", "mrow": "", "ms": "", "mspace": "", "msqrt": "", "mstyle": "", "msub": "\ \ \ \ ", "msubsup": "\ \ \ \ \ ", "msup": "\ \ \ \ ", "mtable": "\ \ \ \ \ \ ", "mtd": "\ \ \ \ \ \ ", "mtext": "", "mtr": "\ \ \ \ \ \ ", "munder": "\ \ \ \ ", "munderover": "\ \ \ \ \ ", "none": "\ \ \ \ \ ", "semantics": "\ \ \ \ " }; var FragmentHelper = { mathml_namespace: "http://www.w3.org/1998/Math/MathML", createElement: function(tag) { return document.createElementNS(this.mathml_namespace, tag); }, isValidChildOfMrow: function(tag) { return !(tag == "annotation" || tag == "annotation-xml" || tag == "mprescripts" || tag == "none" || tag == "mtr" || tag == "mtd"); }, isTokenElement: function(tag) { return (tag == "mi" || tag == "mtext" || tag == "mo" || tag == "mn" || tag == "ms") }, isEmpty: function(tag) { return tag === "mspace" || tag == "mprescripts" || tag == "none"; }, element: function(fragment) { return fragment.getElementsByClassName('element')[0]; }, appendChild: function(fragment, allowInvalid) { var element = this.element(fragment) || fragment; if (element.classList.contains("foreign-container")) { var el = document.createElement("span"); el.textContent = "a"; return element.appendChild(el); } if (element.classList.contains("mathml-container") || allowInvalid) { var el = this.createElement("mi"); el.textContent = "a"; return element.appendChild(el); } throw "Cannot append child to the element"; }, forceNonEmptyElement: function(fragment) { var element = this.element(fragment) || fragment; if (element.firstElementChild) return element.firstElementChild; return this.appendChild(fragment); }, forceNonEmptyDescendants: function(fragment) { var element = this.element(fragment) || fragment; if (element.classList.contains("mathml-container") || element.classList.contains("foreign-container")) { for (var i = 0; i < 10; i++) this.appendChild(element); return; } var child = element.firstElementChild; if (child) { for (; child; child = child.nextElementSibling) { this.forceNonEmptyDescendants(child); } return; } }, }