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- Sanitize [ HAST ] [ ] .
11+ [ ** hast ** ] [ hast ] utility to sanitize a [ * tree * ] [ tree ] .
912
10- ## Installation
13+ ## Install
1114
1215[ npm] [ ] :
1316
14- ``` bash
17+ ``` sh
1518npm install hast-util-sanitize
1619```
1720
1821## Usage
1922
20- ``` javascript
23+ ``` js
2124var h = require (' hastscript' )
2225var u = require (' unist-builder' )
2326var sanitize = require (' hast-util-sanitize' )
24- var toHTML = require (' hast-util-to-html' )
27+ var toHtml = require (' hast-util-to-html' )
2528
2629var tree = h (' div' , {onmouseover: ' alert("alpha")' }, [
2730 h (
@@ -39,8 +42,8 @@ var tree = h('div', {onmouseover: 'alert("alpha")'}, [
3942 h (' math' , h (' mi' , {' xlink:href' : ' data:x,<script>alert("foxtrot")</script>' }))
4043])
4144
42- var unsanitized = toHTML (tree)
43- var sanitized = toHTML (sanitize (tree))
45+ var unsanitized = toHtml (tree)
46+ var sanitized = toHtml (sanitize (tree))
4447
4548console .log (unsanitized)
4649console .log (sanitized)
@@ -68,28 +71,28 @@ Sanitized:
6871
6972## API
7073
71- ### ` sanitize(node [, schema]) `
74+ ### ` sanitize(tree [, schema]) `
7275
73- Sanitize the given [ HAST ] [ ] tree.
76+ Sanitize a [ ** hast ** ] [ hast ] [ * tree* ] [ tree ] .
7477
7578###### Parameters
7679
77- * ` node ` ([ ` HASTNode ` ] [ hast ] ).
78- * ` schema ` ([ ` Schema ` ] [ schema ] , optional).
80+ * ` tree ` ([ ` Node ` ] [ node ] ) — [ * Tree * ] [ tree ] to sanitize
81+ * ` schema ` ([ ` Schema ` ] [ schema ] , optional) — Schema defining how to sanitize
7982
8083###### Returns
8184
82- [ ` HASTNode ` ] [ hast ] — A new node .
85+ [ ` Node ` ] [ node ] — A new, sanitized [ * tree * ] [ tree ] .
8386
8487### ` Schema `
8588
86- Configuration. If not given, defaults to [ GitHub] [ ] style sanitation.
89+ Configuration.
90+ If not given, defaults to [ GitHub] [ ] style sanitation.
8791If any top-level key isn’t given, it defaults to GH’s style too.
8892
89- For a thorough sample, see the packages [ ` github.json ` ] [ schema-github ] .
93+ For a thorough sample, see [ ` github.json ` ] [ schema-github ] .
9094
91- To extend the standard schema with a few changes, clone ` github.json `
92- like so:
95+ To extend the standard schema with a few changes, clone ` github.json ` like so:
9396
9497``` js
9598var h = require (' hastscript' )
@@ -107,12 +110,13 @@ console.log(tree)
107110
108111###### ` attributes `
109112
110- Map of tag-names to allowed attributes (` Object.<Array.<string>> ` ).
113+ Map of tag names to allowed [ * property names* ] [ name ]
114+ (` Object.<Array.<string>> ` ).
111115
112- The special ` '*' ` key sets attributes allowed on all elements.
116+ The special ` '*' ` key defines [ * property names* ] [ name ] allowed on all
117+ [ * elements* ] [ element ] .
113118
114- One special value, namely ` 'data*' ` , can be used to allow all ` data `
115- properties.
119+ One special value, namely ` 'data*' ` , can be used to allow all ` data ` properties.
116120
117121``` js
118122" attributes" : {
@@ -136,10 +140,10 @@ properties.
136140}
137141```
138142
139- Instead of a single string (such as ` type ` ), which allows any value of that
140- attribute , it’s also possible to provide an array (such as ` [ 'type',
141- ' checkbox'] `), where the first entry is the key, and the other entries are
142- allowed values of that property.
143+ Instead of a single string (such as ` type ` ), which allows any [ * property
144+ value * ] [ value ] of that [ * property name * ] [ name ] , it’s also possible to provide
145+ an array (such as ` ['type', ' checkbox']` ), where the first entry is the
146+ * propery name * , and the other entries are allowed * property values * .
143147
144148This is how the default GitHub schema allows only disabled checkbox inputs:
145149
@@ -156,13 +160,13 @@ This is how the default GitHub schema allows only disabled checkbox inputs:
156160
157161###### ` required `
158162
159- Map of tag- names to required attributes and their default values
160- (` Object.<Object.<*>> ` ).
161- If the properties in such a required attributes object do not exist on an
162- element , they are added and set to the specified value.
163+ Map of tag names to required [ * property names * ] [ name ] and their default
164+ [ * property value * ] [ value ] (` Object.<Object.<*>> ` ).
165+ If the defined keys do not exist in an [ * element * ] [ element ] ’s
166+ [ * properties * ] [ properties ] , they are added and set to the specified value.
163167
164168Note that properties are first checked based on the schema at ` attributes ` ,
165- so properties could be removed by that step and then added again through
169+ so * properties* could be removed by that step and then added again through
166170` required ` .
167171
168172``` js
@@ -176,7 +180,7 @@ so properties could be removed by that step and then added again through
176180
177181###### ` tagNames `
178182
179- List of allowed tag- names (` Array.<string> ` ).
183+ List of allowed tag names (` Array.<string> ` ).
180184
181185``` js
182186" tagNames" : [
@@ -192,7 +196,8 @@ List of allowed tag-names (`Array.<string>`).
192196
193197###### ` protocols `
194198
195- Map of protocols to support for attributes (` Object.<Array.<string>> ` ).
199+ Map of protocols to allow in [ * property values* ] [ value ]
200+ (` Object.<Array.<string>> ` ).
196201
197202``` js
198203" protocols" : {
@@ -211,7 +216,7 @@ Map of protocols to support for attributes (`Object.<Array.<string>>`).
211216
212217###### ` ancestors `
213218
214- Map of tag- names to their required ancestral elements
219+ Map of tag names to their required [ * ancestor * ] [ ancestor ] [ * elements* ] [ element ]
215220(` Object.<Array.<string>> ` ).
216221
217222``` js
@@ -229,7 +234,7 @@ Map of tag-names to their required ancestral elements
229234
230235###### ` clobber `
231236
232- List of allowed attribute- names which can clobber (` Array.<string> ` ).
237+ List of allowed [ * property names* ] [ name ] which can clobber (` Array.<string> ` ).
233238
234239``` js
235240" clobber" : [
@@ -240,18 +245,19 @@ List of allowed attribute-names which can clobber (`Array.<string>`).
240245
241246###### ` clobberPrefix `
242247
243- Prefix ( ` string ` ) to use before potentially clobbering properties .
248+ Prefix to use before potentially clobbering [ * property names * ] [ name ] ( ` string ` ) .
244249
245250``` js
246251" clobberPrefix" : " user-content-"
247252```
248253
249254###### ` strip `
250255
251- Tag-names to strip from the tree (` Array.<string> ` ).
256+ Names of [ * elements* ] [ element ] to strip from the [ * tree* ] [ tree ]
257+ (` Array.<string> ` ).
252258
253- By default, unsafe elements are replaced by their content. Some elements,
254- should however be entirely stripped from the tree.
259+ By default, unsafe * elements* are replaced by their [ * children * ] [ child ] .
260+ Some * elements * , should however be entirely stripped from the * tree* .
255261
256262``` js
257263" strip" : [
@@ -261,27 +267,29 @@ should however be entirely stripped from the tree.
261267
262268###### ` allowComments `
263269
264- Whether to allow comment nodes (` boolean ` , default: ` false ` ).
270+ Whether to allow [ * comments * ] [ comment ] (` boolean ` , default: ` false ` ).
265271
266272``` js
267273" allowComments" : true
268274```
269275
270276###### ` allowDoctypes `
271277
272- Whether to allow doctype nodes (` boolean ` , default: ` false ` ).
278+ Whether to allow [ * doctypes * ] [ doctype ] (` boolean ` , default: ` false ` ).
273279
274280``` js
275281" allowDoctypes" : true
276282```
277283
278284## Contribute
279285
280- See [ ` contributing.md ` in ` syntax-tree/hast ` ] [ contributing ] for ways to get
286+ See [ ` contributing.md ` in ` syntax-tree/.github ` ] [ contributing ] for ways to get
281287started.
288+ See [ ` support.md ` ] [ support ] for ways to get help.
282289
283- This organisation has a [ Code of Conduct] [ coc ] . By interacting with this
284- repository, organisation, or community you agree to abide by its terms.
290+ This project has a [ Code of Conduct] [ coc ] .
291+ By interacting with this repository, organisation, or community you agree to
292+ abide by its terms.
285293
286294## License
287295
@@ -301,24 +309,56 @@ repository, organisation, or community you agree to abide by its terms.
301309
302310[ downloads ] : https://www.npmjs.com/package/hast-util-sanitize
303311
312+ [ size-badge ] : https://img.shields.io/bundlephobia/minzip/hast-util-sanitize.svg
313+
314+ [ size ] : https://bundlephobia.com/result?p=hast-util-sanitize
315+
316+ [ sponsors-badge ] : https://opencollective.com/unified/sponsors/badge.svg
317+
318+ [ backers-badge ] : https://opencollective.com/unified/backers/badge.svg
319+
320+ [ collective ] : https://opencollective.com/unified
321+
304322[ chat-badge ] : https://img.shields.io/badge/join%20the%20community-on%20spectrum-7b16ff.svg
305323
306- [ chat ] : https://spectrum.chat/unified/rehype
324+ [ chat ] : https://spectrum.chat/unified/syntax-tree
307325
308326[ npm ] : https://docs.npmjs.com/cli/install
309327
310328[ license ] : license
311329
312330[ author ] : https://wooorm.com
313331
332+ [ contributing ] : https://github.com/syntax-tree/.github/blob/master/contributing.md
333+
334+ [ support ] : https://github.com/syntax-tree/.github/blob/master/support.md
335+
336+ [ coc ] : https://github.com/syntax-tree/.github/blob/master/code-of-conduct.md
337+
338+ [ tree ] : https://github.com/syntax-tree/unist#tree
339+
340+ [ child ] : https://github.com/syntax-tree/unist#child
341+
342+ [ ancestor ] : https://github.com/syntax-tree/unist#ancestor
343+
314344[ hast ] : https://github.com/syntax-tree/hast
315345
316- [ schema ] : #schema
346+ [ node ] : https://github.com/syntax-tree/hast#nodes
347+
348+ [ element ] : https://github.com/syntax-tree/hast#element
349+
350+ [ doctype ] : https://github.com/syntax-tree/hast#doctype
351+
352+ [ comment ] : https://github.com/syntax-tree/hast#comment
353+
354+ [ properties ] : https://github.com/syntax-tree/hast#properties
355+
356+ [ name ] : https://github.com/syntax-tree/hast#propertyname
357+
358+ [ value ] : https://github.com/syntax-tree/hast#propertyvalue
317359
318360[ github ] : https://github.com/jch/html-pipeline/blob/master/lib/html/pipeline/sanitization_filter.rb
319361
320362[ schema-github ] : lib/github.json
321363
322- [ contributing ] : https://github.com/syntax-tree/hast/blob/master/contributing.md
323-
324- [ coc ] : https://github.com/syntax-tree/hast/blob/master/code-of-conduct.md
364+ [ schema ] : #schema
0 commit comments