MCPcopy Create free account
hub / github.com/TruthHun/BookStack / MathNode

Class MathNode

static/katex/katex.mjs:6604–6684  ·  view source on GitHub ↗

* This node represents a general purpose MathML node of any type. The * constructor requires the type of node to create (for example, `"mo"` or * `"mspace"`, corresponding to ` ` and ` ` tags).

Source from the content-addressed store, hash-verified

6602 */
6603
6604class MathNode {
6605 constructor(type, children) {
6606 this.type = void 0;
6607 this.attributes = void 0;
6608 this.children = void 0;
6609 this.type = type;
6610 this.attributes = {};
6611 this.children = children || [];
6612 }
6613 /**
6614 * Sets an attribute on a MathML node. MathML depends on attributes to convey a
6615 * semantic content, so this is used heavily.
6616 */
6617
6618
6619 setAttribute(name, value) {
6620 this.attributes[name] = value;
6621 }
6622 /**
6623 * Gets an attribute on a MathML node.
6624 */
6625
6626
6627 getAttribute(name) {
6628 return this.attributes[name];
6629 }
6630 /**
6631 * Converts the math node into a MathML-namespaced DOM element.
6632 */
6633
6634
6635 toNode() {
6636 const node = document.createElementNS("http://www.w3.org/1998/Math/MathML", this.type);
6637
6638 for (const attr in this.attributes) {
6639 if (Object.prototype.hasOwnProperty.call(this.attributes, attr)) {
6640 node.setAttribute(attr, this.attributes[attr]);
6641 }
6642 }
6643
6644 for (let i = 0; i < this.children.length; i++) {
6645 node.appendChild(this.children[i].toNode());
6646 }
6647
6648 return node;
6649 }
6650 /**
6651 * Converts the math node into an HTML markup string.
6652 */
6653
6654
6655 toMarkup() {
6656 let markup = "<" + this.type; // Add the attributes
6657
6658 for (const attr in this.attributes) {
6659 if (Object.prototype.hasOwnProperty.call(this.attributes, attr)) {
6660 markup += " " + attr + "=\"";
6661 markup += utils.escape(this.attributes[attr]);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected