MCPcopy
hub / github.com/KaTeX/KaTeX / DocumentFragment

Class DocumentFragment

src/tree.ts:21–79  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19 * children and doesn't have any DOM node properties.
20 */
21export class DocumentFragment<ChildType extends VirtualNode>
22 implements HtmlDomNode, MathDomNode {
23 children: ReadonlyArray<ChildType>;
24 classes: string[];
25 height: number;
26 depth: number;
27 maxFontSize: number;
28 style: CssStyle; // Never used; needed for satisfying interface.
29
30 constructor(children: ReadonlyArray<ChildType>) {
31 this.children = children;
32 this.classes = [];
33 this.height = 0;
34 this.depth = 0;
35 this.maxFontSize = 0;
36 this.style = {};
37 }
38
39 hasClass(className: string): boolean {
40 return this.classes.includes(className);
41 }
42
43 /** Convert the fragment into a node. */
44 toNode(): Node {
45 const frag = document.createDocumentFragment();
46
47 for (let i = 0; i < this.children.length; i++) {
48 frag.appendChild(this.children[i].toNode());
49 }
50
51 return frag;
52 }
53
54 /** Convert the fragment into HTML markup. */
55 toMarkup(): string {
56 let markup = "";
57
58 // Simply concatenate the markup for the children together.
59 for (let i = 0; i < this.children.length; i++) {
60 markup += this.children[i].toMarkup();
61 }
62
63 return markup;
64 }
65
66 /**
67 * Converts the math node into a string, similar to innerText. Applies to
68 * MathDomNode's only.
69 */
70 toText(): string {
71 return this.children.map((child: ChildType): string => {
72 if (isMathDomNode(child)) {
73 return child.toText();
74 }
75 throw new Error(
76 `Expected MathDomNode with toText, got ${child.constructor.name}`);
77 }).join("");
78 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…