File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,41 @@ npm install unist-util-index
13
13
14
14
## Usage
15
15
16
+ ``` javascript
17
+ var fs = require (' fs' )
18
+ var remark = require (' remark' )
19
+ var toString = require (' mdast-util-to-string' )
20
+ var Index = require (' unist-util-index' )
21
+
22
+ // Read this readme:
23
+ var tree = remark .parse (fs .readFileSync (' readme.md' ))
24
+
25
+ // Index on heading depth:
26
+ var index = new Index (tree, ' heading' , ' depth' )
27
+
28
+ console .log (index .get (1 ).map (toString))
29
+ console .log (index .get (2 ).map (toString))
30
+
31
+ index = new Index (tree, ' definition' , ' identifier' )
32
+
33
+ console .log (index .get (' unist' ).map (node => node .url ))
34
+ console .log (index .get (' travis' ).map (node => node .url ))
35
+ ```
36
+
37
+ Yields:
38
+
39
+ ``` js
40
+ [ ' unist-util-index Build Status Coverage Status' ]
41
+ [ ' Installation' ,
42
+ ' Usage' ,
43
+ ' API' ,
44
+ ' Related' ,
45
+ ' Contribute' ,
46
+ ' License' ]
47
+ [ ' https://github.com/syntax-tree/unist' ]
48
+ [ ' https://travis-ci.org/syntax-tree/unist-util-index' ]
49
+ ```
50
+
16
51
## API
17
52
18
53
### ` Index([tree[, filter]], prop|keyFn) `
You can’t perform that action at this time.
0 commit comments