1
1
# hast-util-select
2
2
3
- [ ![ Build] [ build-badge ]] [ build ]
4
- [ ![ Coverage] [ coverage-badge ]] [ coverage ]
5
- [ ![ Downloads] [ downloads-badge ]] [ downloads ]
6
- [ ![ Size] [ size-badge ]] [ size ]
7
- [ ![ Sponsors] [ sponsors-badge ]] [ collective ]
8
- [ ![ Backers] [ backers-badge ]] [ collective ]
9
- [ ![ Chat] [ chat-badge ]] [ chat ]
3
+ [ ![ Build] [ badge-build-image ]] [ badge-build-url ]
4
+ [ ![ Coverage] [ badge-coverage-image ]] [ badge-coverage-url ]
5
+ [ ![ Downloads] [ badge-downloads-image ]] [ badge-downloads-url ]
6
+ [ ![ Size] [ badge-size-image ]] [ badge-size-url ]
10
7
11
- [ hast] [ ] utility with equivalents for ` matches ` , ` querySelector ` ,
12
- and ` querySelectorAll ` .
8
+ [ hast] [ github-hast ] utility with equivalents for
9
+ ` matches ` , ` querySelector ` , and ` querySelectorAll ` .
13
10
14
11
## Contents
15
12
@@ -46,17 +43,19 @@ This information is not stored in hast, so selectors like that don’t work.
46
43
This is a small utility that is quite useful, but is rather slow if you use it a
47
44
lot.
48
45
For each call, it has to walk the entire tree.
49
- In some cases, walking the tree once with [ ` unist-util-visit ` ] [ unist-util-visit ]
46
+ In some cases,
47
+ walking the tree once with [ ` unist-util-visit ` ] [ github-unist-util-visit ]
50
48
is smarter, such as when you want to change certain nodes.
51
49
On the other hand, this is quite powerful and fast enough for many other cases.
52
50
53
- This utility is similar to [ ` unist-util-select ` ] [ unist-util-select ] , which can
54
- find and match any unist node.
51
+ This utility is similar to
52
+ [ ` unist-util-select ` ] [ github-unist-util-select ] ,
53
+ which can find and match any unist node.
55
54
56
55
## Install
57
56
58
- This package is [ ESM only] [ esm ] .
59
- In Node.js (version 16+), install with [ npm] [ ] :
57
+ This package is [ ESM only] [ github-gist- esm] .
58
+ In Node.js (version 16+), install with [ npm] [ npmjs-install ] :
60
59
61
60
``` sh
62
61
npm install hast-util-select
@@ -120,7 +119,7 @@ This only checks that the given element matches the selector.
120
119
121
120
* ` selector ` (` string ` )
122
121
— CSS selector, such as (` h1 ` , ` a, b ` )
123
- * ` node ` ([ ` Node ` ] [ node ] , optional)
122
+ * ` node ` ([ ` Node ` ] [ github-hast-nodes ] , optional)
124
123
— node that might match ` selector ` , should be an element
125
124
* ` space ` ([ ` Space ` ] [ api-space ] , default: ` 'html' ` )
126
125
— name of namespace
@@ -147,13 +146,13 @@ matches('[lang|=en]', h('a', {lang: 'en-GB'})) // => true
147
146
### ` select(selector, tree[, space]) `
148
147
149
148
Select the first element that matches ` selector ` in the given ` tree ` .
150
- Searches the tree in * [ preorder] [ ] * .
149
+ Searches the tree in * [ preorder] [ github-unist-preorder ] * .
151
150
152
151
###### Parameters
153
152
154
153
* ` selector ` (` string ` )
155
154
— CSS selector, such as (` h1 ` , ` a, b ` )
156
- * ` tree ` ([ ` Node ` ] [ node ] , optional)
155
+ * ` tree ` ([ ` Node ` ] [ github-hast-nodes ] , optional)
157
156
— tree to search
158
157
* ` space ` ([ ` Space ` ] [ api-space ] , default: ` 'html' ` )
159
158
— name of namespace
@@ -196,13 +195,13 @@ Yields:
196
195
### ` selectAll(selector, tree[, space]) `
197
196
198
197
Select all elements that match ` selector ` in the given ` tree ` .
199
- Searches the tree in * [ preorder] [ ] * .
198
+ Searches the tree in * [ preorder] [ github-unist-preorder ] * .
200
199
201
200
###### Parameters
202
201
203
202
* ` selector ` (` string ` )
204
203
— CSS selector, such as (` h1 ` , ` a, b ` )
205
- * ` tree ` ([ ` Node ` ] [ node ] , optional)
204
+ * ` tree ` ([ ` Node ` ] [ github-hast-nodes ] , optional)
206
205
— tree to search
207
206
* ` space ` ([ ` Space ` ] [ api-space ] , default: ` 'html' ` )
208
207
— name of namespace
@@ -388,11 +387,11 @@ compatible with Node.js 16.
388
387
## Security
389
388
390
389
This package does not change the syntax tree so there are no openings for
391
- [cross-site scripting (XSS)][xss] attacks.
390
+ [cross-site scripting (XSS)][wikipedia- xss] attacks.
392
391
393
392
## Related
394
393
395
- * [ ` unist -util -select ` ](https:// github.com/syntax-tree/ unist-util-select)
394
+ * [ ` unist -util -select ` ][ github- unist-util-select]
396
395
— select unist nodes with CSS-like selectors
397
396
* [ ` hast -util -find -and -replace ` ](https://github.com/syntax-tree/hast-util-find-and-replace)
398
397
— find and replace text in a hast tree
@@ -403,82 +402,74 @@ This package does not change the syntax tree so there are no openings for
403
402
404
403
## Contribute
405
404
406
- See [ ` contributing .md ` ][contributing] in [ ` syntax -tree /.github ` ][health] for
407
- ways to get started.
408
- See [ ` support .md ` ][help] for ways to get help.
405
+ See [ ` contributing .md ` ][health-contributing]
406
+ in
407
+ [ ` syntax -tree /.github ` ][health]
408
+ for ways to get started.
409
+ See [ ` support .md ` ][health-support] for ways to get help.
409
410
410
- This project has a [code of conduct][coc].
411
+ This project has a [code of conduct][health- coc].
411
412
By interacting with this repository, organization, or community you agree to
412
413
abide by its terms.
413
414
414
415
## License
415
416
416
- [MIT][license] © [Titus Wormer][author ]
417
+ [MIT][file- license] © [Titus Wormer][wooorm ]
417
418
418
419
<!-- Definitions -->
419
420
420
- [build-badge]: https://github.com/syntax-tree/hast-util-select/workflows/main/badge.svg
421
-
422
- [build]: https://github.com/syntax-tree/hast-util-select/actions
423
-
424
- [coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/hast-util-select.svg
425
-
426
- [coverage]: https://codecov.io/github/syntax-tree/hast-util-select
421
+ [api-matches]: #matchesselector-node-space
427
422
428
- [downloads-badge ]: https://img.shields.io/npm/dm/hast-util-select.svg
423
+ [api-select ]: #selectselector-tree-space
429
424
430
- [downloads ]: https://www.npmjs.com/package/hast-util-select
425
+ [api-select-all ]: #selectallselector-tree-space
431
426
432
- [size-badge ]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=hast-util-select
427
+ [api-space ]: #space
433
428
434
- [size ]: https://bundlejs .com/?q= hast-util-select
429
+ [badge-build-image ]: https://github .com/syntax-tree/ hast-util-select/workflows/main/badge.svg
435
430
436
- [sponsors- badge]: https://opencollective .com/unified/sponsors/badge.svg
431
+ [badge-build-url ]: https://github .com/syntax-tree/hast-util-select/actions
437
432
438
- [backers- badge]: https://opencollective.com/unified/backers/badge .svg
433
+ [badge-coverage-image ]: https://img.shields.io/codecov/c/github/syntax-tree/hast-util-select .svg
439
434
440
- [collective ]: https://opencollective.com/unified
435
+ [badge-coverage-url ]: https://codecov.io/github/syntax-tree/hast-util-select
441
436
442
- [chat- badge]: https://img.shields.io/badge/chat-discussions-success .svg
437
+ [badge-downloads-image ]: https://img.shields.io/npm/dm/hast-util-select .svg
443
438
444
- [chat ]: https://github. com/syntax-tree/unist/discussions
439
+ [badge-downloads-url ]: https://www.npmjs. com/package/hast-util-select
445
440
446
- [npm ]: https://docs.npmjs.com/cli/install
441
+ [badge-size-image ]: https://img.shields.io/bundlejs/size/hast-util-select
447
442
448
- [esm ]: https://gist.github. com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
443
+ [badge-size-url ]: https://bundlejs. com/?q=hast-util-select
449
444
450
445
[esmsh]: https://esm.sh
451
446
452
- [typescript ]: https://www.typescriptlang.org
447
+ [file-license ]: license
453
448
454
- [license ]: license
449
+ [github-gist-esm ]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
455
450
456
- [author ]: https://wooorm .com
451
+ [github-hast ]: https://github .com/syntax-tree/hast
457
452
458
- [health ]: https://github.com/syntax-tree/.github
453
+ [github-hast-nodes ]: https://github.com/syntax-tree/hast#nodes
459
454
460
- [contributing ]: https://github.com/syntax-tree/.github/blob/main/contributing.md
455
+ [github-unist-preorder ]: https://github.com/syntax-tree/unist#preorder
461
456
462
- [help ]: https://github.com/syntax-tree/.github/blob/main/support.md
457
+ [github-unist-util-select ]: https://github.com/syntax-tree/unist-util-select
463
458
464
- [coc ]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
459
+ [github-unist-util-visit ]: https://github.com/syntax-tree/unist-util-visit
465
460
466
- [preorder]: https://github.com/syntax-tree/unist#preorder
467
-
468
- [hast]: https://github.com/syntax-tree/hast
469
-
470
- [node]: https://github.com/syntax-tree/hast#nodes
461
+ [health]: https://github.com/syntax-tree/.github
471
462
472
- [xss ]: https://en.wikipedia.org/wiki/Cross-site_scripting
463
+ [health-coc ]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
473
464
474
- [unist-util-visit ]: https://github.com/syntax-tree/unist-util-visit
465
+ [health-contributing ]: https://github.com/syntax-tree/.github/blob/main/contributing.md
475
466
476
- [unist-util-select ]: https://github.com/syntax-tree/unist-util-select
467
+ [health-support ]: https://github.com/syntax-tree/.github/blob/main/support.md
477
468
478
- [api-matches ]: #matchesselector-node-space
469
+ [npmjs-install ]: https://docs.npmjs.com/cli/install
479
470
480
- [api-select ]: #selectselector-tree-space
471
+ [typescript ]: https://www.typescriptlang.org
481
472
482
- [api-select-all ]: #selectallselector-tree-space
473
+ [wikipedia-xss ]: https://en.wikipedia.org/wiki/Cross-site_scripting
483
474
484
- [api-space ]: #space
475
+ [wooorm ]: https://wooorm.com
0 commit comments