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.
1313
1414## Example
1515
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+
1631``` js
1732var select = require (' unist-util-select' );
1833
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.' } ]
2141```
2242
43+ That's it!
44+
45+ [ mdast ] : https://github.com/wooorm/mdast
46+
2347## Features
2448
2549- [x] Type selectors: ` paragraph `
You can’t perform that action at this time.
0 commit comments