* Converts the math node into a MathML-namespaced DOM element.
()
| 80 | * Converts the math node into a MathML-namespaced DOM element. |
| 81 | */ |
| 82 | toNode(): Node { |
| 83 | const node = document.createElementNS( |
| 84 | "http://www.w3.org/1998/Math/MathML", this.type); |
| 85 | |
| 86 | for (const [attr, value] of Object.entries(this.attributes)) { |
| 87 | node.setAttribute(attr, value); |
| 88 | } |
| 89 | |
| 90 | if (this.classes.length > 0) { |
| 91 | node.className = createClass(this.classes); |
| 92 | } |
| 93 | |
| 94 | for (let i = 0; i < this.children.length; i++) { |
| 95 | // Combine multiple TextNodes into one TextNode, to prevent |
| 96 | // screen readers from reading each as a separate word [#3995] |
| 97 | if (this.children[i] instanceof TextNode && |
| 98 | this.children[i + 1] instanceof TextNode) { |
| 99 | let text = this.children[i].toText() + this.children[++i].toText(); |
| 100 | while (this.children[i + 1] instanceof TextNode) { |
| 101 | text += this.children[++i].toText(); |
| 102 | } |
| 103 | node.appendChild(new TextNode(text).toNode()); |
| 104 | } else { |
| 105 | node.appendChild(this.children[i].toNode()); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | return node; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Converts the math node into an HTML markup string. |
nothing calls this directly
no test coverage detected