MCPcopy Create free account
hub / github.com/KaTeX/KaTeX / toNode

Method toNode

src/mathMLTree.ts:82–110  ·  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, 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.

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