source: node_modules/@types/hast/index.d.ts

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 3.1 KB
Line 
1import { Literal as UnistLiteral, Node as UnistNode, Parent as UnistParent } from "unist";
2
3export { UnistNode as Node };
4
5/**
6 * This map registers all node types that may be used as top-level content in the document.
7 *
8 * These types are accepted inside `root` nodes.
9 *
10 * This interface can be augmented to register custom node types.
11 *
12 * @example
13 * declare module 'hast' {
14 * interface RootContentMap {
15 * // Allow using raw nodes defined by `rehype-raw`.
16 * raw: Raw;
17 * }
18 * }
19 */
20export interface RootContentMap {
21 comment: Comment;
22 doctype: DocType;
23 element: Element;
24 text: Text;
25}
26
27/**
28 * This map registers all node types that may be used as content in an element.
29 *
30 * These types are accepted inside `element` nodes.
31 *
32 * This interface can be augmented to register custom node types.
33 *
34 * @example
35 * declare module 'hast' {
36 * interface RootContentMap {
37 * custom: Custom;
38 * }
39 * }
40 */
41export interface ElementContentMap {
42 comment: Comment;
43 element: Element;
44 text: Text;
45}
46
47export type Content = RootContent | ElementContent;
48
49export type RootContent = RootContentMap[keyof RootContentMap];
50
51export type ElementContent = ElementContentMap[keyof ElementContentMap];
52
53/**
54 * Node in hast containing other nodes.
55 */
56export interface Parent extends UnistParent {
57 /**
58 * List representing the children of a node.
59 */
60 children: Content[];
61}
62
63/**
64 * Nodes in hast containing a value.
65 */
66export interface Literal extends UnistLiteral {
67 value: string;
68}
69
70/**
71 * Root represents a document.
72 * Can be used as the root of a tree, or as a value of the
73 * content field on a 'template' Element, never as a child.
74 */
75export interface Root extends Parent {
76 /**
77 * Represents this variant of a Node.
78 */
79 type: "root";
80
81 /**
82 * List representing the children of a node.
83 */
84 children: RootContent[];
85}
86
87/**
88 * Element represents an HTML Element.
89 */
90export interface Element extends Parent {
91 /**
92 * Represents this variant of a Node.
93 */
94 type: "element";
95
96 /**
97 * Represents the element’s local name.
98 */
99 tagName: string;
100
101 /**
102 * Represents information associated with the element.
103 */
104 properties?: Properties | undefined;
105
106 /**
107 * If the tagName field is 'template', a content field can be present.
108 */
109 content?: Root | undefined;
110
111 /**
112 * List representing the children of a node.
113 */
114 children: ElementContent[];
115}
116
117/**
118 * Represents information associated with an element.
119 */
120export interface Properties {
121 [PropertyName: string]: boolean | number | string | null | undefined | Array<string | number>;
122}
123
124/**
125 * Represents an HTML DocumentType.
126 */
127export interface DocType extends UnistNode {
128 /**
129 * Represents this variant of a Node.
130 */
131 type: "doctype";
132
133 name: string;
134}
135
136/**
137 * Represents an HTML Comment.
138 */
139export interface Comment extends Literal {
140 /**
141 * Represents this variant of a Literal.
142 */
143 type: "comment";
144}
145
146/**
147 * Represents an HTML Text.
148 */
149export interface Text extends Literal {
150 /**
151 * Represents this variant of a Literal.
152 */
153 type: "text";
154}
Note: See TracBrowser for help on using the repository browser.