Add sections on possible values · syntax-tree/unist@691de9c (original) (raw)

`@@ -20,13 +20,26 @@ See [nlcst][nlcst] for more information on retext nodes,

`

20

20

`[mdast][mdast] for information on remark nodes, and

`

21

21

`` [hast#nodes][hast-nodes] for information on hast nodes.

``

22

22

``

``

23

`+

Subsets of Unist can define new properties on new nodes, and plug-ins

`

``

24

`` +

and utilities can define new data properties on nodes. But,

``

``

25

`` +

the values on those properties must be JSON values: string,

``

``

26

`` +

number, object, array, true, false, or null. This means

``

``

27

`+

that the syntax tree should be able to be converted to and from JSON

`

``

28

`+

and produce the same tree. For example, in JavaScript, a tree should

`

``

29

`` +

be able to be passed through JSON.parse(JSON.stringify(tree)) and

``

``

30

`+

result in the same values.

`

``

31

+

23

32

`` ### Node

``

24

33

``

25

34

`Node represents any unit in the Unist hierarchy. It is an abstract

`

26

35

`` class. Interfaces inheriting from Node must have a type property,

``

27

36

`` and may have data or location properties. types are defined by

``

28

37

`their namespace.

`

29

38

``

``

39

`+

Subsets of Unist are allowed to define properties on interfaces which

`

``

40

`+

subclass Unist’s abstract interfaces. For example, [mdast][] defines

`

``

41

`` +

a link node (subclassing Parent) with a url property.

``

``

42

+

30

43

```` ```idl


`31`

`44`

`interface Node {

`

`32`

`45`

` type: string;

`

`@@ -37,9 +50,10 @@ interface Node {

`

`37`

`50`

``

`38`

`51`

`` #### `Data`

``

`39`

`52`

``

`40`

``

`-

Data represents data associated with any node. Data is a scope for plug-ins

`

`41`

``

`-

to store any information. Its only limitation being that each property should

`

`42`

``

`` -

by `stringify`able: not throw when passed to `JSON.stringify()`.

``

``

`53`

`` +

Data represents data associated with any node. `Data` is a scope for

``

``

`54`

`` +

plug-ins to store any information. For example, [`remark-html`][remark-html]

``

``

`55`

`` +

uses `htmlAttributes` to let other plug-ins specify attributes added

``

``

`56`

`+

to the compiled HTML element.

`

`43`

`57`

``

`44`

`58`

```` ```idl

45

59

`interface Data { }

`

`@@ -175,3 +189,9 @@ A list of VFile-related utilities can be found at [vfile][vfile].

`

175

189

`[hast-nodes]: https://github.com/wooorm/hast#nodes

`

176

190

``

177

191

`[vfile]: https://github.com/wooorm/vfile

`

``

192

+

``

193

`+

`

``

194

+

``

195

`+

`

``

196

+

``

197

`+

`