File tree Expand file tree Collapse file tree 1 file changed +26
-2
lines changed Expand file tree Collapse file tree 1 file changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -13,13 +13,37 @@ Select unist nodes using css-like selectors.
13
13
14
14
## Example
15
15
16
+ ` example.md ` :
17
+
18
+ ```
19
+ Get all TODO items from this list:
20
+
21
+ 1. Step 1.
22
+ 2. TODO Step 2.
23
+ 3. Step 3.
24
+ 1. TODO Step 3.1.
25
+ 2. Step 3.2.
26
+ 3. TODO Step 3.3.
27
+ ```
28
+
29
+ [ ` mdast ` ] [ mdast ] takes this Markdown as an input and returns unist syntax tree. After that, we use ` unist-util-select ` to extract the required parts:
30
+
16
31
``` js
17
32
var select = require (' unist-util-select' );
18
33
19
- select (ast, ' paragraph emphasis > text' )
20
- // => array of nodes
34
+ var markdown = fs .readFileSync (' example.md' , ' utf8' );
35
+ var ast = mdast .parse (markdown);
36
+
37
+ select (ast, ' list text[value*=TODO]' )
38
+ // => [ { type: 'text', value: 'TODO Step 2.' },
39
+ // { type: 'text', value: 'TODO Step 3.1.' },
40
+ // { type: 'text', value: 'TODO Step 3.3.' } ]
21
41
```
22
42
43
+ That's it!
44
+
45
+ [ mdast ] : https://github.com/wooorm/mdast
46
+
23
47
## Features
24
48
25
49
- [x] Type selectors: ` paragraph `
You can’t perform that action at this time.
0 commit comments