@@ -13,57 +13,57 @@ npm install --save unist-util-find
13
13
### Example
14
14
15
15
``` js
16
- import {remark } from ' remark'
17
- import {find } from ' unist-util-find'
18
-
19
- remark ()
20
- .use (function () {
21
- return function (tree ) {
22
- // string condition
23
- console .log (find (tree, ' value' ))
24
-
25
- // object condition
26
- console .log (find (tree, { value: ' emphasis' }))
27
-
28
- // function condition
29
- console .log (find (tree, function (node ) {
30
- return node .type === ' inlineCode'
31
- }))
32
- }
33
- })
34
- .processSync (' Some _emphasis_, **strongness**, and `code`.' )
16
+ import {fromMarkdown } from ' mdast-util-from-markdown'
17
+ import {find } from ' ./index.js'
18
+
19
+ const tree = fromMarkdown (' Some _emphasis_, **strongness**, and `code`.' )
20
+
21
+ // String condition
22
+ console .log (find (tree, ' value' ))
35
23
24
+ // Object condition
25
+ console .log (find (tree, {value: ' emphasis' }))
26
+
27
+ // Function condition
28
+ console .log (
29
+ find (tree, function (node ) {
30
+ return node .type === ' inlineCode'
31
+ })
32
+ )
36
33
```
37
34
38
35
Result:
39
36
40
37
```
41
38
// string condition: 'value'
42
- { type: 'text',
39
+ {
40
+ type: 'text',
43
41
value: 'Some ',
44
- position:
45
- Position {
46
- start : { line: 1, column: 1 , offset: 0 },
47
- end: { line: 1, column: 6, offset: 5 },
48
- indent: [] } }
42
+ position: {
43
+ start: { line: 1, column: 1, offset: 0 },
44
+ end : { line: 1, column: 6 , offset: 5 }
45
+ }
46
+ }
49
47
50
48
// object condition: { value: 'emphasis' }
51
- { type: 'text',
49
+ {
50
+ type: 'text',
52
51
value: 'emphasis',
53
- position:
54
- Position {
55
- start : { line: 1, column: 7 , offset: 6 },
56
- end: { line: 1, column: 15, offset: 14 },
57
- indent: [] } }
52
+ position: {
53
+ start: { line: 1, column: 7, offset: 6 },
54
+ end : { line: 1, column: 15 , offset: 14 }
55
+ }
56
+ }
58
57
59
58
// function condition: function (node) { return node.type === 'inlineCode' }
60
- { type: 'inlineCode',
59
+ {
60
+ type: 'inlineCode',
61
61
value: 'code',
62
- position:
63
- Position {
64
- start : { line: 1, column: 38 , offset: 37 },
65
- end: { line: 1, column: 44, offset: 43 },
66
- indent: [] } }
62
+ position: {
63
+ start: { line: 1, column: 38, offset: 37 },
64
+ end : { line: 1, column: 44 , offset: 43 }
65
+ }
66
+ }
67
67
```
68
68
69
69
### API
0 commit comments