@@ -18,16 +18,21 @@ The latest released version is [`1.0.0`][latest].
18
18
* [ Where this specification fits] ( #where-this-specification-fits )
19
19
* [ Scope] ( #scope )
20
20
* [ Types] ( #types )
21
- * [ Nodes] ( #nodes )
22
- * [ ` Parent ` ] ( #parent )
21
+ * [ Nodes (abstract)] ( #nodes-abstract )
23
22
* [ ` Literal ` ] ( #literal )
24
- * [ ` Root ` ] ( #root )
25
- * [ ` Element ` ] ( #element )
26
- * [ ` Text ` ] ( #text )
23
+ * [ ` Parent ` ] ( #parent )
24
+ * [ Nodes ] ( #nodes )
25
+ * [ ` Cdata ` ] ( #cdata )
27
26
* [ ` Comment ` ] ( #comment )
28
27
* [ ` Doctype ` ] ( #doctype )
28
+ * [ ` Element ` ] ( #element )
29
29
* [ ` Instruction ` ] ( #instruction )
30
- * [ ` Cdata ` ] ( #cdata )
30
+ * [ ` Root ` ] ( #root )
31
+ * [ ` Text ` ] ( #text )
32
+ * [ Other types] ( #other-types )
33
+ * [ ` Attributes ` ] ( #attributes )
34
+ * [ ` AttributeName ` ] ( #attributename )
35
+ * [ ` AttributeValue ` ] ( #attributevalue )
31
36
* [ Glossary] ( #glossary )
32
37
* [ List of utilities] ( #list-of-utilities )
33
38
* [ References] ( #references )
@@ -105,27 +110,14 @@ Internal document type declarations have no representation in xast:
105
110
106
111
## Types
107
112
108
- If you are using TypeScript, you can use the unist types by installing them
113
+ If you are using TypeScript, you can use the xast types by installing them
109
114
with npm:
110
115
111
116
``` sh
112
117
npm install @types/xast
113
118
```
114
119
115
- ## Nodes
116
-
117
- ### ` Parent `
118
-
119
- ``` idl
120
- interface Parent <: UnistParent {
121
- children: [Cdata | Comment | Doctype | Element | Instruction | Text]
122
- }
123
- ```
124
-
125
- ** Parent** (** [ UnistParent] [ dfn-unist-parent ] ** ) represents a node in xast
126
- containing other nodes (said to be * [ children] [ term-child ] * ).
127
-
128
- Its content is limited to only other xast content.
120
+ ## Nodes (abstract)
129
121
130
122
### ` Literal `
131
123
@@ -138,128 +130,44 @@ interface Literal <: UnistLiteral {
138
130
** Literal** (** [ UnistLiteral] [ dfn-unist-literal ] ** ) represents a node in xast
139
131
containing a value.
140
132
141
- ### ` Root `
142
-
143
- ``` idl
144
- interface Root <: Parent {
145
- type: 'root'
146
- }
147
- ```
148
-
149
- ** Root** (** [ Parent] [ dfn-parent ] ** ) represents a document fragment or a whole
150
- document.
151
-
152
- ** Root** should be used as the * [ root] [ term-root ] * of a * [ tree] [ term-tree ] * and
153
- must not be used as a * [ child] [ term-child ] * .
154
-
155
- XML specifies that documents should have exactly one ** [ element] [ dfn-element ] **
156
- child, therefore a root should have exactly one element child when representing
157
- a whole document.
158
-
159
- ### ` Element `
133
+ ### ` Parent `
160
134
161
135
``` idl
162
- interface Element <: Parent {
163
- type: 'element'
164
- name: string
165
- attributes: Attributes?
166
- children: [Cdata | Comment | Element | Instruction | Text]
167
- }
168
- ```
169
-
170
- ** Element** (** [ Parent] [ dfn-parent ] ** ) represents an
171
- * [ element] [ concept-element ] * ([ \[ XML\] ] [ xml ] ).
172
-
173
- The ` name ` field must be present.
174
- It represents the element’s * [ name] [ concept-name ] * ([ \[ XML\] ] [ xml ] ),
175
- specifically its * [ qualified name] [ concept-qualified-name ] *
176
- ([ \[ XML-NAMES\] ] [ xml-names ] ).
177
-
178
- The ` children ` field should be present.
179
-
180
- The ` attributes ` field should be present.
181
- It represents information associated with the element.
182
- The value of the ` attributes ` field implements the
183
- ** [ Attributes] [ dfn-attributes ] ** interface.
184
-
185
- For example, the following XML:
186
-
187
- ``` xml
188
- <package xmlns =" http://www.idpf.org/2007/opf" unique-identifier =" id" />
189
- ```
190
-
191
- Yields:
192
-
193
- ``` js
194
- {
195
- type: ' element' ,
196
- name: ' package' ,
197
- attributes: {
198
- xmlns: ' http://www.idpf.org/2007/opf' ,
199
- ' unique-identifier' : ' id'
200
- },
201
- children: []
136
+ interface Parent <: UnistParent {
137
+ children: [Cdata | Comment | Doctype | Element | Instruction | Text]
202
138
}
203
139
```
204
140
205
- #### ` Attributes `
206
-
207
- ``` idl
208
- interface Attributes {}
209
- ```
210
-
211
- ** Attributes** represents information associated with an element.
212
-
213
- Every field must be a ** [ AttributeName] [ dfn-attribute-name ] ** and every value an
214
- ** [ AttributeValue] [ dfn-attribute-value ] ** .
215
-
216
- #### ` AttributeName `
217
-
218
- ``` idl
219
- typedef string AttributeName
220
- ```
221
-
222
- Attribute names are keys on ** [ Attributes] [ dfn-attributes ] ** objects and must
223
- reflect XML attribute names exactly.
224
-
225
- #### ` AttributeValue `
226
-
227
- ``` idl
228
- typedef string AttributeValue
229
- ```
141
+ ** Parent** (** [ UnistParent] [ dfn-unist-parent ] ** ) represents a node in xast
142
+ containing other nodes (said to be * [ children] [ term-child ] * ).
230
143
231
- Attribute values are values on ** [ Attributes] [ dfn-attributes ] ** objects and must
232
- reflect XML attribute values exactly as a string.
144
+ Its content is limited to only other xast content.
233
145
234
- > In [ JSON] [ ] , the value ` null ` must be treated as if the attribute was not
235
- > included.
236
- > In [ JavaScript] [ ] , both ` null ` and ` undefined ` must be similarly ignored.
146
+ ## Nodes
237
147
238
- ### ` Text `
148
+ ### ` Cdata `
239
149
240
150
``` idl
241
- interface Text <: Literal {
242
- type: 'text '
151
+ interface Cdata <: Literal {
152
+ type: 'cdata '
243
153
}
244
154
```
245
155
246
- ** Text ** (** [ Literal] [ dfn-literal ] ** ) represents
247
- * [ character data ] [ concept-char ] * ([ \[ XML\] ] [ xml ] ).
156
+ ** Cdata ** (** [ Literal] [ dfn-literal ] ** ) represents a
157
+ * [ CDATA section ] [ concept-cdata ] * ([ \[ XML\] ] [ xml ] ).
248
158
249
159
For example, the following XML:
250
160
251
161
``` xml
252
- <dc : language >en</ dc : language >
162
+ <![CDATA[ <greeting>Hello, world!</greeting> ]] >
253
163
```
254
164
255
165
Yields:
256
166
257
167
``` js
258
168
{
259
- type: ' element' ,
260
- name: ' dc:language' ,
261
- attributes: {},
262
- children: [{type: ' text' , value: ' en' }]
169
+ type: ' cdata' ,
170
+ value: ' <greeting>Hello, world!</greeting>'
263
171
}
264
172
```
265
173
@@ -327,6 +235,52 @@ Yields:
327
235
}
328
236
```
329
237
238
+ ### ` Element `
239
+
240
+ ``` idl
241
+ interface Element <: Parent {
242
+ type: 'element'
243
+ name: string
244
+ attributes: Attributes?
245
+ children: [Cdata | Comment | Element | Instruction | Text]
246
+ }
247
+ ```
248
+
249
+ ** Element** (** [ Parent] [ dfn-parent ] ** ) represents an
250
+ * [ element] [ concept-element ] * ([ \[ XML\] ] [ xml ] ).
251
+
252
+ The ` name ` field must be present.
253
+ It represents the element’s * [ name] [ concept-name ] * ([ \[ XML\] ] [ xml ] ),
254
+ specifically its * [ qualified name] [ concept-qualified-name ] *
255
+ ([ \[ XML-NAMES\] ] [ xml-names ] ).
256
+
257
+ The ` children ` field should be present.
258
+
259
+ The ` attributes ` field should be present.
260
+ It represents information associated with the element.
261
+ The value of the ` attributes ` field implements the
262
+ ** [ Attributes] [ dfn-attributes ] ** interface.
263
+
264
+ For example, the following XML:
265
+
266
+ ``` xml
267
+ <package xmlns =" http://www.idpf.org/2007/opf" unique-identifier =" id" />
268
+ ```
269
+
270
+ Yields:
271
+
272
+ ``` js
273
+ {
274
+ type: ' element' ,
275
+ name: ' package' ,
276
+ attributes: {
277
+ xmlns: ' http://www.idpf.org/2007/opf' ,
278
+ ' unique-identifier' : ' id'
279
+ },
280
+ children: []
281
+ }
282
+ ```
283
+
330
284
### ` Instruction `
331
285
332
286
``` idl
@@ -357,32 +311,87 @@ Yields:
357
311
}
358
312
```
359
313
360
- ### ` Cdata `
314
+ ### ` Root `
361
315
362
316
``` idl
363
- interface Cdata <: Literal {
364
- type: 'cdata '
317
+ interface Root <: Parent {
318
+ type: 'root '
365
319
}
366
320
```
367
321
368
- ** Cdata** (** [ Literal] [ dfn-literal ] ** ) represents a
369
- * [ CDATA section] [ concept-cdata ] * ([ \[ XML\] ] [ xml ] ).
322
+ ** Root** (** [ Parent] [ dfn-parent ] ** ) represents a document fragment or a whole
323
+ document.
324
+
325
+ ** Root** should be used as the * [ root] [ term-root ] * of a * [ tree] [ term-tree ] * and
326
+ must not be used as a * [ child] [ term-child ] * .
327
+
328
+ XML specifies that documents should have exactly one ** [ element] [ dfn-element ] **
329
+ child, therefore a root should have exactly one element child when representing
330
+ a whole document.
331
+
332
+ ### ` Text `
333
+
334
+ ``` idl
335
+ interface Text <: Literal {
336
+ type: 'text'
337
+ }
338
+ ```
339
+
340
+ ** Text** (** [ Literal] [ dfn-literal ] ** ) represents
341
+ * [ character data] [ concept-char ] * ([ \[ XML\] ] [ xml ] ).
370
342
371
343
For example, the following XML:
372
344
373
345
``` xml
374
- <![CDATA[ <greeting>Hello, world!</greeting> ]] >
346
+ <dc : language >en</ dc : language >
375
347
```
376
348
377
349
Yields:
378
350
379
351
``` js
380
352
{
381
- type: ' cdata' ,
382
- value: ' <greeting>Hello, world!</greeting>'
353
+ type: ' element' ,
354
+ name: ' dc:language' ,
355
+ attributes: {},
356
+ children: [{type: ' text' , value: ' en' }]
383
357
}
384
358
```
385
359
360
+ ## Other types
361
+
362
+ ### ` Attributes `
363
+
364
+ ``` idl
365
+ interface Attributes {}
366
+ ```
367
+
368
+ ** Attributes** represents information associated with an element.
369
+
370
+ Every field must be a ** [ AttributeName] [ dfn-attribute-name ] ** and every value an
371
+ ** [ AttributeValue] [ dfn-attribute-value ] ** .
372
+
373
+ ### ` AttributeName `
374
+
375
+ ``` idl
376
+ typedef string AttributeName
377
+ ```
378
+
379
+ Attribute names are keys on ** [ Attributes] [ dfn-attributes ] ** objects and must
380
+ reflect XML attribute names exactly.
381
+
382
+ ### ` AttributeValue `
383
+
384
+ ``` idl
385
+ typedef string AttributeValue
386
+ ```
387
+
388
+ Attribute values are values on ** [ Attributes] [ dfn-attributes ] ** objects and must
389
+ reflect XML attribute values exactly as a string.
390
+
391
+ > In [ JSON] [ ] , the value ` null ` must be treated as if the attribute was not
392
+ > included.
393
+ > In [ JavaScript] [ ] , both ` null ` and ` undefined ` must be similarly ignored.
394
+
386
395
## Glossary
387
396
388
397
See the [ unist glossary] [ glossary ] .
0 commit comments