@@ -20,13 +20,26 @@ See [**nlcst**][nlcst] for more information on **retext** nodes,
2020[ ** mdast** ] [ mdast ] for information on ** remark** nodes, and
2121[ ` hast#nodes ` ] [ hast-nodes ] for information on ** hast** nodes.
2222
23+ Subsets of Unist can define new properties on new nodes, and plug-ins
24+ and utilities can define new [ ` data ` ] [ 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+
2332### ` Node `
2433
2534Node represents any unit in the Unist hierarchy. It is an abstract
2635class. Interfaces inheriting from ** Node** must have a ` type ` property,
2736and may have ` data ` or ` location ` properties. ` type ` s are defined by
2837their namespace.
2938
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+
3043``` idl
3144interface Node {
3245 type: string;
@@ -37,9 +50,10 @@ interface Node {
3750
3851#### ` Data `
3952
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.
4357
4458``` idl
4559interface Data { }
@@ -175,3 +189,9 @@ A list of **VFile**-related utilities can be found at [**vfile**][vfile].
175189[ hast-nodes ] : https://github.com/wooorm/hast#nodes
176190
177191[ vfile ] : https://github.com/wooorm/vfile
192+
193+ [ remark-html ] : https://github.com/wooorm/remark-html
194+
195+ [ parent ] : #parent
196+
197+ [ data ] : #data
0 commit comments