MCPcopy
hub / github.com/markdoc/markdoc / Node

Class Node

src/ast/node.ts:16–84  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14} from '../types';
15
16export default class Node implements AstType {
17 readonly $$mdtype = 'Node';
18
19 attributes: Record<string, any>;
20 slots: Record<string, Node>;
21 children: Node[];
22 errors: ValidationError[] = [];
23 lines: number[] = [];
24 type: NodeType;
25 tag?: string;
26 annotations: AttributeValue[];
27
28 inline = false;
29 location?: Location;
30
31 constructor(
32 type: NodeType = 'node',
33 attributes: Record<string, any> = {},
34 children: Node[] = [],
35 tag?: string
36 ) {
37 this.attributes = attributes;
38 this.children = children;
39 this.type = type;
40 this.tag = tag;
41 this.annotations = [];
42 this.slots = {};
43 }
44
45 *walk(): Generator<Node, void, unknown> {
46 for (const child of [...Object.values(this.slots), ...this.children]) {
47 yield child;
48 yield* child.walk();
49 }
50 }
51
52 push(node: Node) {
53 this.children.push(node);
54 }
55
56 resolve(config: Config = {}): Node {
57 return Object.assign(new Node(), this, {
58 children: this.children.map((child) => child.resolve(config)),
59 attributes: resolve(this.attributes, config),
60 slots: Object.fromEntries(
61 Object.entries(this.slots).map(([name, slot]) => [
62 name,
63 slot.resolve(config),
64 ])
65 ),
66 });
67 }
68
69 findSchema(config: Config = {}): Schema | undefined {
70 return transformer.findSchema(this, config);
71 }
72
73 transformAttributes(config: Config = {}) {

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…