33[ ![ Build] [ build-badge ]] [ build ]
44[ ![ Coverage] [ coverage-badge ]] [ coverage ]
55[ ![ Downloads] [ downloads-badge ]] [ downloads ]
6+ [ ![ Size] [ size-badge ]] [ size ]
7+ [ ![ Sponsors] [ sponsors-badge ]] [ collective ]
8+ [ ![ Backers] [ backers-badge ]] [ collective ]
69[ ![ Chat] [ chat-badge ]] [ chat ]
710
8- Find and replace text in a [ HAST ] [ ] tree.
11+ [ ** hast ** ] [ hast ] utility to find and replace text in a [ * tree * ] [ tree ] .
912
10- ## Installation
13+ ## Install
1114
1215[ npm] [ ] :
1316
14- ``` bash
17+ ``` sh
1518npm install hast-util-find-and-replace
1619```
1720
1821## Usage
1922
20- ``` javascript
23+ ``` js
2124var h = require (' hastscript' )
2225var inspect = require (' unist-util-inspect' )
2326var findAndReplace = require (' hast-util-find-and-replace' )
@@ -68,9 +71,10 @@ element[9] [tagName="p"]
6871
6972### ` findAndReplace(tree, find[, replace][, options]) `
7073
71- Find and replace text in a [ HAST] [ ] tree.
72- The algorithm searches for complete values in text nodes. Partial matches
73- are not supported.
74+ Find and replace text in a [ ** hast** ] [ hast ] [ * tree* ] [ tree ] .
75+ The algorithm searches the tree in [ * preorder* ] [ preorder ] for complete values
76+ in [ ` Text ` ] [ text ] nodes.
77+ Partial matches are not supported.
7478
7579###### Signatures
7680
@@ -80,33 +84,40 @@ are not supported.
8084###### Parameters
8185
8286* ` tree ` ([ ` Node ` ] [ node ] )
83- — HAST tree.
87+ — [ ** hast ** ] [ hast ] [ * tree* ] [ tree ]
8488* ` find ` (` string ` or ` RegExp ` )
85- — Value to find and remove. When ` string ` , escaped and made into a global
86- ` RegExp ` .
89+ — Value to find and remove.
90+ When ` string ` , escaped and made into a global ` RegExp `
8791* ` replace ` (` string ` or ` Function ` )
88- — Value to insert. When ` string ` , turned into a text node. When
89- ` Function ` , invoked with the results of calling ` RegExp.exec ` as arguments,
90- in which case it can return a [ ` Node ` ] [ node ] or a ` string ` , in which case
91- it’s wrapped in a text node.
92+ — Value to insert.
93+ When ` string ` , turned into a [ ` Text ` ] [ text ] node.
94+ When ` Function ` , invoked with the results of calling ` RegExp.exec ` as
95+ arguments, in which case it can return a [ ` Node ` ] [ node ] or a ` string ` , which
96+ is in the latter case wrapped in a [ ` Text ` ] [ text ] node
9297* ` search ` (` Object ` or ` Array ` )
93- — Perform multiple find-and-replace’s. When ` Array ` , each entry is a tuple
94- (array) of a ` find ` and ` replace ` . When ` Object ` , each key is a ` find `
95- (in string form) and each value is ` replace ` .
96- * ` options.ignore ` (` Array ` , default: ` ['title', 'script', 'style', 'svg', 'math'] ` )
98+ — Perform multiple find-and-replace’s.
99+ When ` Array ` , each entry is a tuple (` Array ` ) of a ` find ` (at ` 0 ` ) and
100+ ` replace ` (at ` 1 ` ).
101+ When ` Object ` , each key is a ` find ` (in string form) and each value is a
102+ ` replace `
103+ * ` options.ignore ` (` Array ` , default: `[ 'title', 'script', 'style', 'svg',
104+ 'math'] `)
97105 — Tag-names of elements * not* to search.
106+ This list can be accessed at ` findAndReplace.ignore `
98107
99108###### Returns
100109
101- The given, modified, tree.
110+ The given, modified, ` tree ` .
102111
103112## Contribute
104113
105- See [ ` contributing.md ` in ` syntax-tree/hast ` ] [ contributing ] for ways to get
114+ See [ ` contributing.md ` in ` syntax-tree/.github ` ] [ contributing ] for ways to get
106115started.
116+ See [ ` support.md ` ] [ support ] for ways to get help.
107117
108- This organisation has a [ Code of Conduct] [ coc ] . By interacting with this
109- repository, organisation, or community you agree to abide by its terms.
118+ This project has a [ Code of Conduct] [ coc ] .
119+ By interacting with this repository, organisation, or community you agree to
120+ abide by its terms.
110121
111122## License
112123
@@ -126,20 +137,38 @@ repository, organisation, or community you agree to abide by its terms.
126137
127138[ downloads ] : https://www.npmjs.com/package/hast-util-find-and-replace
128139
140+ [ size-badge ] : https://img.shields.io/bundlephobia/minzip/hast-util-find-and-replace.svg
141+
142+ [ size ] : https://bundlephobia.com/result?p=hast-util-find-and-replace
143+
144+ [ sponsors-badge ] : https://opencollective.com/unified/sponsors/badge.svg
145+
146+ [ backers-badge ] : https://opencollective.com/unified/backers/badge.svg
147+
148+ [ collective ] : https://opencollective.com/unified
149+
129150[ chat-badge ] : https://img.shields.io/badge/join%20the%20community-on%20spectrum-7b16ff.svg
130151
131- [ chat ] : https://spectrum.chat/unified/rehype
152+ [ chat ] : https://spectrum.chat/unified/syntax-tree
132153
133154[ npm ] : https://docs.npmjs.com/cli/install
134155
135156[ license ] : license
136157
137158[ author ] : https://wooorm.com
138159
160+ [ contributing ] : https://github.com/syntax-tree/.github/blob/master/contributing.md
161+
162+ [ support ] : https://github.com/syntax-tree/.github/blob/master/support.md
163+
164+ [ coc ] : https://github.com/syntax-tree/.github/blob/master/code-of-conduct.md
165+
139166[ hast ] : https://github.com/syntax-tree/hast
140167
141- [ node ] : https://github.com/syntax-tree/hast#ast
168+ [ node ] : https://github.com/syntax-tree/hast#ndoes
169+
170+ [ tree ] : https://github.com/syntax-tree/unist#tree
142171
143- [ contributing ] : https://github.com/syntax-tree/hast/blob/master/contributing.md
172+ [ preorder ] : https://github.com/syntax-tree/unist#preorder
144173
145- [ coc ] : https://github.com/syntax-tree/hast/blob/master/code-of-conduct.md
174+ [ text ] : https://github.com/syntax-tree/hast#text
0 commit comments