MCPcopy
hub / github.com/KaTeX/KaTeX / toNode

Method toNode

src/mathMLTree.ts:82–112  ·  view source on GitHub ↗

* Converts the math node into a MathML-namespaced DOM element.

()

Source from the content-addressed store, hash-verified

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 in this.attributes) {
87 if (Object.prototype.hasOwnProperty.call(this.attributes, attr)) {
88 node.setAttribute(attr, this.attributes[attr]);
89 }
90 }
91
92 if (this.classes.length > 0) {
93 node.className = createClass(this.classes);
94 }
95
96 for (let i = 0; i < this.children.length; i++) {
97 // Combine multiple TextNodes into one TextNode, to prevent
98 // screen readers from reading each as a separate word [#3995]
99 if (this.children[i] instanceof TextNode &&
100 this.children[i + 1] instanceof TextNode) {
101 let text = this.children[i].toText() + this.children[++i].toText();
102 while (this.children[i + 1] instanceof TextNode) {
103 text += this.children[++i].toText();
104 }
105 node.appendChild(new TextNode(text).toNode());
106 } else {
107 node.appendChild(this.children[i].toNode());
108 }
109 }
110
111 return node;
112 }
113
114 /**
115 * Converts the math node into an HTML markup string.

Callers

nothing calls this directly

Calls 4

createClassFunction · 0.90
toTextMethod · 0.65
toNodeMethod · 0.65
setAttributeMethod · 0.45

Tested by

no test coverage detected