@@ -20,14 +20,16 @@ The latest released version is [`2.4.0`][latest].
20
20
* [ Where this specification fits] ( #where-this-specification-fits )
21
21
* [ Virtual DOM] ( #virtual-dom )
22
22
* [ Types] ( #types )
23
- * [ Nodes] ( #nodes )
24
- * [ ` Parent ` ] ( #parent )
23
+ * [ Nodes (abstract)] ( #nodes-abstract )
25
24
* [ ` Literal ` ] ( #literal )
26
- * [ ` Root ` ] ( #root )
27
- * [ ` Element ` ] ( #element )
28
- * [ ` Doctype ` ] ( #doctype )
25
+ * [ ` Parent ` ] ( #parent )
26
+ * [ Nodes] ( #nodes )
29
27
* [ ` Comment ` ] ( #comment )
28
+ * [ ` Doctype ` ] ( #doctype )
29
+ * [ ` Element ` ] ( #element )
30
+ * [ ` Root ` ] ( #root )
30
31
* [ ` Text ` ] ( #text )
32
+ * [ Types] ( #types-1 )
31
33
* [ Glossary] ( #glossary )
32
34
* [ List of utilities] ( #list-of-utilities )
33
35
* [ Related HTML utilities] ( #related-html-utilities )
@@ -79,13 +81,24 @@ with npm:
79
81
npm install @types/hast
80
82
```
81
83
82
- ## Nodes
84
+ ## Nodes (abstract)
85
+
86
+ ### ` Literal `
87
+
88
+ ``` idl
89
+ interface Literal <: UnistLiteral {
90
+ value: string
91
+ }
92
+ ```
93
+
94
+ ** Literal** (** [ UnistLiteral] [ dfn-unist-literal ] ** ) represents a node in hast
95
+ containing a value.
83
96
84
97
### ` Parent `
85
98
86
99
``` idl
87
100
interface Parent <: UnistParent {
88
- children: [Element | Doctype | Comment | Text]
101
+ children: [Comment | Doctype | Element | Text]
89
102
}
90
103
```
91
104
@@ -94,30 +107,53 @@ containing other nodes (said to be *[children][term-child]*).
94
107
95
108
Its content is limited to only other hast content.
96
109
97
- ### ` Literal `
110
+ ## Nodes
111
+
112
+ ### ` Comment `
98
113
99
114
``` idl
100
- interface Literal <: UnistLiteral {
101
- value: string
115
+ interface Comment <: Literal {
116
+ type: 'comment'
102
117
}
103
118
```
104
119
105
- ** Literal ** (** [ UnistLiteral ] [ dfn-unist- literal ] ** ) represents a node in hast
106
- containing a value .
120
+ ** Comment ** (** [ Literal ] [ dfn-literal ] ** ) represents a [ Comment ] [ concept-comment ]
121
+ ( [ \[ DOM \] ] [ dom ] ) .
107
122
108
- ### ` Root `
123
+ For example, the following HTML:
124
+
125
+ ``` html
126
+ <!-- Charlie-->
127
+ ```
128
+
129
+ Yields:
130
+
131
+ ``` js
132
+ {type: ' comment' , value: ' Charlie' }
133
+ ```
134
+
135
+ ### ` Doctype `
109
136
110
137
``` idl
111
- interface Root <: Parent {
112
- type: 'root '
138
+ interface Doctype <: Node {
139
+ type: 'doctype '
113
140
}
114
141
```
115
142
116
- ** Root** (** [ Parent] [ dfn-parent ] ** ) represents a document.
143
+ ** Doctype** (** [ Node] [ dfn-unist-node ] ** ) represents a
144
+ [ DocumentType] [ concept-documenttype ] ([ \[ DOM\] ] [ dom ] ).
117
145
118
- ** Root** can be used as the * [ root] [ term-root ] * of a * [ tree] [ term-tree ] * , or as
119
- a value of the ` content ` field on a ` 'template' ` ** [ Element] [ dfn-element ] ** ,
120
- never as a * [ child] [ term-child ] * .
146
+ For example, the following HTML:
147
+
148
+ ``` html
149
+ <!doctype html>
150
+ ```
151
+
152
+ Yields:
153
+
154
+ ``` js
155
+ {type: ' doctype' }
156
+ ```
121
157
122
158
### ` Element `
123
159
@@ -127,7 +163,7 @@ interface Element <: Parent {
127
163
tagName: string
128
164
properties: Properties?
129
165
content: Root?
130
- children: [Element | Comment | Text]
166
+ children: [Comment | Element | Text]
131
167
}
132
168
```
133
169
@@ -172,6 +208,50 @@ Yields:
172
208
}
173
209
```
174
210
211
+ ### ` Root `
212
+
213
+ ``` idl
214
+ interface Root <: Parent {
215
+ type: 'root'
216
+ }
217
+ ```
218
+
219
+ ** Root** (** [ Parent] [ dfn-parent ] ** ) represents a document.
220
+
221
+ ** Root** can be used as the * [ root] [ term-root ] * of a * [ tree] [ term-tree ] * , or as
222
+ a value of the ` content ` field on a ` 'template' ` ** [ Element] [ dfn-element ] ** ,
223
+ never as a * [ child] [ term-child ] * .
224
+
225
+ ### ` Text `
226
+
227
+ ``` idl
228
+ interface Text <: Literal {
229
+ type: 'text'
230
+ }
231
+ ```
232
+
233
+ ** Text** (** [ Literal] [ dfn-literal ] ** ) represents a [ Text] [ concept-text ]
234
+ ([ \[ DOM\] ] [ dom ] ).
235
+
236
+ For example, the following HTML:
237
+
238
+ ``` html
239
+ <span >Foxtrot</span >
240
+ ```
241
+
242
+ Yields:
243
+
244
+ ``` js
245
+ {
246
+ type: ' element' ,
247
+ tagName: ' span' ,
248
+ properties: {},
249
+ children: [{type: ' text' , value: ' Foxtrot' }]
250
+ }
251
+ ```
252
+
253
+ ### Types
254
+
175
255
#### ` Properties `
176
256
177
257
``` idl
@@ -294,80 +374,6 @@ For example, `<div class="alpha bravo"></div>` is represented as `['alpha',
294
374
295
375
> There’s no special format for the property value of the ` style ` property name.
296
376
297
- ### ` Doctype `
298
-
299
- ``` idl
300
- interface Doctype <: Node {
301
- type: 'doctype'
302
- }
303
- ```
304
-
305
- ** Doctype** (** [ Node] [ dfn-unist-node ] ** ) represents a
306
- [ DocumentType] [ concept-documenttype ] ([ \[ DOM\] ] [ dom ] ).
307
-
308
- For example, the following HTML:
309
-
310
- ``` html
311
- <!doctype html>
312
- ```
313
-
314
- Yields:
315
-
316
- ``` js
317
- {type: ' doctype' }
318
- ```
319
-
320
- ### ` Comment `
321
-
322
- ``` idl
323
- interface Comment <: Literal {
324
- type: 'comment'
325
- }
326
- ```
327
-
328
- ** Comment** (** [ Literal] [ dfn-literal ] ** ) represents a [ Comment] [ concept-comment ]
329
- ([ \[ DOM\] ] [ dom ] ).
330
-
331
- For example, the following HTML:
332
-
333
- ``` html
334
- <!-- Charlie-->
335
- ```
336
-
337
- Yields:
338
-
339
- ``` js
340
- {type: ' comment' , value: ' Charlie' }
341
- ```
342
-
343
- ### ` Text `
344
-
345
- ``` idl
346
- interface Text <: Literal {
347
- type: 'text'
348
- }
349
- ```
350
-
351
- ** Text** (** [ Literal] [ dfn-literal ] ** ) represents a [ Text] [ concept-text ]
352
- ([ \[ DOM\] ] [ dom ] ).
353
-
354
- For example, the following HTML:
355
-
356
- ``` html
357
- <span >Foxtrot</span >
358
- ```
359
-
360
- Yields:
361
-
362
- ``` js
363
- {
364
- type: ' element' ,
365
- tagName: ' span' ,
366
- properties: {},
367
- children: [{type: ' text' , value: ' Foxtrot' }]
368
- }
369
- ```
370
-
371
377
## Glossary
372
378
373
379
See the [ unist glossary] [ glossary ] .
0 commit comments