Skip to content

Commit db55001

Browse files
committed
(readme) Elaborate on example
1 parent 33476e5 commit db55001

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

README.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff 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
1732
var 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`

0 commit comments

Comments
 (0)