@@ -18,16 +18,21 @@ The latest released version is [`1.0.0`][latest].
1818 * [ Where this specification fits] ( #where-this-specification-fits )
1919 * [ Scope] ( #scope )
2020* [ Types] ( #types )
21- * [ Nodes] ( #nodes )
22- * [ ` Parent ` ] ( #parent )
21+ * [ Nodes (abstract)] ( #nodes-abstract )
2322 * [ ` Literal ` ] ( #literal )
24- * [ ` Root ` ] ( #root )
25- * [ ` Element ` ] ( #element )
26- * [ ` Text ` ] ( #text )
23+ * [ ` Parent ` ] ( #parent )
24+ * [ Nodes ] ( #nodes )
25+ * [ ` Cdata ` ] ( #cdata )
2726 * [ ` Comment ` ] ( #comment )
2827 * [ ` Doctype ` ] ( #doctype )
28+ * [ ` Element ` ] ( #element )
2929 * [ ` 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 )
3136* [ Glossary] ( #glossary )
3237* [ List of utilities] ( #list-of-utilities )
3338* [ References] ( #references )
@@ -105,27 +110,14 @@ Internal document type declarations have no representation in xast:
105110
106111## Types
107112
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
109114with npm:
110115
111116``` sh
112117npm install @types/xast
113118```
114119
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)
129121
130122### ` Literal `
131123
@@ -138,128 +130,44 @@ interface Literal <: UnistLiteral {
138130** Literal** (** [ UnistLiteral] [ dfn-unist-literal ] ** ) represents a node in xast
139131containing a value.
140132
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 `
160134
161135``` 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]
202138}
203139```
204140
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 ] * ).
230143
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.
233145
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
237147
238- ### ` Text `
148+ ### ` Cdata `
239149
240150``` idl
241- interface Text <: Literal {
242- type: 'text '
151+ interface Cdata <: Literal {
152+ type: 'cdata '
243153}
244154```
245155
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 ] ).
248158
249159For example, the following XML:
250160
251161``` xml
252- <dc : language >en</ dc : language >
162+ <![CDATA[ <greeting>Hello, world!</greeting> ]] >
253163```
254164
255165Yields:
256166
257167``` js
258168{
259- type: ' element' ,
260- name: ' dc:language' ,
261- attributes: {},
262- children: [{type: ' text' , value: ' en' }]
169+ type: ' cdata' ,
170+ value: ' <greeting>Hello, world!</greeting>'
263171}
264172```
265173
@@ -327,6 +235,52 @@ Yields:
327235}
328236```
329237
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+
330284### ` Instruction `
331285
332286``` idl
@@ -357,32 +311,87 @@ Yields:
357311}
358312```
359313
360- ### ` Cdata `
314+ ### ` Root `
361315
362316``` idl
363- interface Cdata <: Literal {
364- type: 'cdata '
317+ interface Root <: Parent {
318+ type: 'root '
365319}
366320```
367321
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 ] ).
370342
371343For example, the following XML:
372344
373345``` xml
374- <![CDATA[ <greeting>Hello, world!</greeting> ]] >
346+ <dc : language >en</ dc : language >
375347```
376348
377349Yields:
378350
379351``` js
380352{
381- type: ' cdata' ,
382- value: ' <greeting>Hello, world!</greeting>'
353+ type: ' element' ,
354+ name: ' dc:language' ,
355+ attributes: {},
356+ children: [{type: ' text' , value: ' en' }]
383357}
384358```
385359
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+
386395## Glossary
387396
388397See the [ unist glossary] [ glossary ] .
0 commit comments