@@ -83,16 +83,26 @@ There is no default export.
83
83
84
84
### ` matches(selector, node[, space]) `
85
85
86
- Check that the given ` node ` ([ ` Node ` ] [ node ] , should be [ element] [ ] ) matches the
87
- CSS selector ` selector ` (` string ` , stuff like ` a, b ` is also supported).
88
- Also accepts a ` space ` (enum, ` 'svg' ` or ` 'html' ` , default: ` 'html' ` )
89
- Returns whether the node matches or not (` boolean ` ).
86
+ Check that the given ` node ` matches ` selector ` .
90
87
91
88
This only checks the element itself, not the surrounding tree.
92
89
Thus, nesting in selectors is not supported (` p b ` , ` p > b ` ), neither are
93
90
selectors like ` :first-child ` , etc.
94
91
This only checks that the given element matches the selector.
95
92
93
+ ###### Parameters
94
+
95
+ * ` selector ` (` string ` )
96
+ — CSS selector, such as (` h1 ` , ` a, b ` )
97
+ * ` node ` ([ ` Node ` ] [ node ] , optional)
98
+ — node that might match ` selector ` , should be an element
99
+ * ` space ` (` 'svg' ` or ` 'html' ` , default: ` 'html' ` )
100
+ — name of namespace
101
+
102
+ ###### Returns
103
+
104
+ Whether ` node ` matches ` selector ` (` boolean ` ).
105
+
96
106
###### Example
97
107
98
108
``` js
@@ -106,15 +116,27 @@ matches('.classy', h('a', {className: ['classy']})) // => true
106
116
matches (' #id' , h (' a' , {id: ' id' })) // => true
107
117
matches (' [lang|=en]' , h (' a' , {lang: ' en' })) // => true
108
118
matches (' [lang|=en]' , h (' a' , {lang: ' en-GB' })) // => true
109
- // ...
119
+ // …
110
120
```
111
121
112
122
### ` select(selector, tree[, space]) `
113
123
114
- Select the first [ element] [ ] (or ` null ` ) matching the CSS selector ` selector ` in
115
- the given ` tree ` ([ ` Node ` ] [ node ] ), which could be the tree itself.
116
- Searches the [ tree] [ ] in * [ preorder] [ ] * .
117
- Also accepts a ` space ` (enum, ` 'svg' ` or ` 'html' ` , default: ` 'html' ` )
124
+ Select the first element that matches ` selector ` in the given ` tree ` .
125
+ Searches the tree in * [ preorder] [ ] * .
126
+
127
+ ###### Parameters
128
+
129
+ * ` selector ` (` string ` )
130
+ — CSS selector, such as (` h1 ` , ` a, b ` )
131
+ * ` tree ` ([ ` Node ` ] [ node ] , optional)
132
+ — tree to search
133
+ * ` space ` (` 'svg' ` or ` 'html' ` , default: ` 'html' ` )
134
+ — name of namespace
135
+
136
+ ###### Returns
137
+
138
+ First element in ` tree ` that matches ` selector ` or ` null ` if nothing is found.
139
+ This could be ` tree ` itself.
118
140
119
141
###### Example
120
142
@@ -147,10 +169,22 @@ Yields:
147
169
148
170
### ` selectAll(selector, tree[, space]) `
149
171
150
- Select all [ element] [ ] s (` Array<Element> ` ) matching the CSS selector ` selector `
151
- in the given ` tree ` ([ ` Node ` ] [ node ] ), which could include the tree itself.
152
- Searches the [ tree] [ ] in * [ preorder] [ ] * .
153
- Also accepts a ` space ` (enum, ` 'svg' ` or ` 'html' ` , default: ` 'html' ` )
172
+ Select all elements that match ` selector ` in the given ` tree ` .
173
+ Searches the tree in * preorder* .
174
+
175
+ ###### Parameters
176
+
177
+ * ` selector ` (` string ` )
178
+ — CSS selector, such as (` h1 ` , ` a, b ` )
179
+ * ` tree ` ([ ` Node ` ] [ node ] , optional)
180
+ — tree to search
181
+ * ` space ` (` 'svg' ` or ` 'html' ` , default: ` 'html' ` )
182
+ — name of namespace
183
+
184
+ ###### Returns
185
+
186
+ Elements in ` tree ` that match ` selector ` .
187
+ This could include ` tree ` itself.
154
188
155
189
###### Example
156
190
@@ -385,16 +419,12 @@ abide by its terms.
385
419
386
420
[ coc ] : https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
387
421
388
- [ tree ] : https://github.com/syntax-tree/unist#tree
389
-
390
422
[ preorder ] : https://github.com/syntax-tree/unist#preorder
391
423
392
424
[ hast ] : https://github.com/syntax-tree/hast
393
425
394
426
[ node ] : https://github.com/syntax-tree/hast#nodes
395
427
396
- [ element ] : https://github.com/syntax-tree/hast#element
397
-
398
428
[ xss ] : https://en.wikipedia.org/wiki/Cross-site_scripting
399
429
400
430
[ unist-util-visit ] : https://github.com/syntax-tree/unist-util-visit
0 commit comments