@@ -20,14 +20,16 @@ The latest released version is [`2.4.0`][latest].
2020 * [ Where this specification fits] ( #where-this-specification-fits )
2121 * [ Virtual DOM] ( #virtual-dom )
2222* [ Types] ( #types )
23- * [ Nodes] ( #nodes )
24- * [ ` Parent ` ] ( #parent )
23+ * [ Nodes (abstract)] ( #nodes-abstract )
2524 * [ ` Literal ` ] ( #literal )
26- * [ ` Root ` ] ( #root )
27- * [ ` Element ` ] ( #element )
28- * [ ` Doctype ` ] ( #doctype )
25+ * [ ` Parent ` ] ( #parent )
26+ * [ Nodes] ( #nodes )
2927 * [ ` Comment ` ] ( #comment )
28+ * [ ` Doctype ` ] ( #doctype )
29+ * [ ` Element ` ] ( #element )
30+ * [ ` Root ` ] ( #root )
3031 * [ ` Text ` ] ( #text )
32+ * [ Types] ( #types-1 )
3133* [ Glossary] ( #glossary )
3234* [ List of utilities] ( #list-of-utilities )
3335* [ Related HTML utilities] ( #related-html-utilities )
@@ -79,13 +81,24 @@ with npm:
7981npm install @types/hast
8082```
8183
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.
8396
8497### ` Parent `
8598
8699``` idl
87100interface Parent <: UnistParent {
88- children: [Element | Doctype | Comment | Text]
101+ children: [Comment | Doctype | Element | Text]
89102}
90103```
91104
@@ -94,30 +107,53 @@ containing other nodes (said to be *[children][term-child]*).
94107
95108Its content is limited to only other hast content.
96109
97- ### ` Literal `
110+ ## Nodes
111+
112+ ### ` Comment `
98113
99114``` idl
100- interface Literal <: UnistLiteral {
101- value: string
115+ interface Comment <: Literal {
116+ type: 'comment'
102117}
103118```
104119
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 ] ) .
107122
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 `
109136
110137``` idl
111- interface Root <: Parent {
112- type: 'root '
138+ interface Doctype <: Node {
139+ type: 'doctype '
113140}
114141```
115142
116- ** Root** (** [ Parent] [ dfn-parent ] ** ) represents a document.
143+ ** Doctype** (** [ Node] [ dfn-unist-node ] ** ) represents a
144+ [ DocumentType] [ concept-documenttype ] ([ \[ DOM\] ] [ dom ] ).
117145
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+ ```
121157
122158### ` Element `
123159
@@ -127,7 +163,7 @@ interface Element <: Parent {
127163 tagName: string
128164 properties: Properties?
129165 content: Root?
130- children: [Element | Comment | Text]
166+ children: [Comment | Element | Text]
131167}
132168```
133169
@@ -172,6 +208,50 @@ Yields:
172208}
173209```
174210
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+
175255#### ` Properties `
176256
177257``` idl
@@ -294,80 +374,6 @@ For example, `<div class="alpha bravo"></div>` is represented as `['alpha',
294374
295375> There’s no special format for the property value of the ` style ` property name.
296376
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-
371377## Glossary
372378
373379See the [ unist glossary] [ glossary ] .
0 commit comments