3
3
[ ![ Build] [ build-badge ]] [ build ]
4
4
[ ![ Coverage] [ coverage-badge ]] [ coverage ]
5
5
[ ![ Downloads] [ downloads-badge ]] [ downloads ]
6
+ [ ![ Size] [ size-badge ]] [ size ]
7
+ [ ![ Sponsors] [ sponsors-badge ]] [ collective ]
8
+ [ ![ Backers] [ backers-badge ]] [ collective ]
6
9
[ ![ Chat] [ chat-badge ]] [ chat ]
7
10
8
- Find and replace text in a [ HAST ] [ ] tree.
11
+ [ ** hast ** ] [ hast ] utility to find and replace text in a [ * tree * ] [ tree ] .
9
12
10
- ## Installation
13
+ ## Install
11
14
12
15
[ npm] [ ] :
13
16
14
- ``` bash
17
+ ``` sh
15
18
npm install hast-util-find-and-replace
16
19
```
17
20
18
21
## Usage
19
22
20
- ``` javascript
23
+ ``` js
21
24
var h = require (' hastscript' )
22
25
var inspect = require (' unist-util-inspect' )
23
26
var findAndReplace = require (' hast-util-find-and-replace' )
@@ -68,9 +71,10 @@ element[9] [tagName="p"]
68
71
69
72
### ` findAndReplace(tree, find[, replace][, options]) `
70
73
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.
74
78
75
79
###### Signatures
76
80
@@ -80,33 +84,40 @@ are not supported.
80
84
###### Parameters
81
85
82
86
* ` tree ` ([ ` Node ` ] [ node ] )
83
- — HAST tree.
87
+ — [ ** hast ** ] [ hast ] [ * tree* ] [ tree ]
84
88
* ` 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 `
87
91
* ` 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
92
97
* ` 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'] `)
97
105
— Tag-names of elements * not* to search.
106
+ This list can be accessed at ` findAndReplace.ignore `
98
107
99
108
###### Returns
100
109
101
- The given, modified, tree.
110
+ The given, modified, ` tree ` .
102
111
103
112
## Contribute
104
113
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
106
115
started.
116
+ See [ ` support.md ` ] [ support ] for ways to get help.
107
117
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.
110
121
111
122
## License
112
123
@@ -126,20 +137,38 @@ repository, organisation, or community you agree to abide by its terms.
126
137
127
138
[ downloads ] : https://www.npmjs.com/package/hast-util-find-and-replace
128
139
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
+
129
150
[ chat-badge ] : https://img.shields.io/badge/join%20the%20community-on%20spectrum-7b16ff.svg
130
151
131
- [ chat ] : https://spectrum.chat/unified/rehype
152
+ [ chat ] : https://spectrum.chat/unified/syntax-tree
132
153
133
154
[ npm ] : https://docs.npmjs.com/cli/install
134
155
135
156
[ license ] : license
136
157
137
158
[ author ] : https://wooorm.com
138
159
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
+
139
166
[ hast ] : https://github.com/syntax-tree/hast
140
167
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
142
171
143
- [ contributing ] : https://github.com/syntax-tree/hast/blob/master/contributing.md
172
+ [ preorder ] : https://github.com/syntax-tree/unist#preorder
144
173
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