Skip to content

Commit 98d7534

Browse files
committed
Refactor some more docs
1 parent ffee970 commit 98d7534

File tree

3 files changed

+33
-31
lines changed

3 files changed

+33
-31
lines changed

Diff for: lib/index.js

+8-11
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
* import {h} from 'hastscript'
3030
* import {defaultSchema, sanitize} from 'hast-util-sanitize'
3131
*
32+
* // This allows `className` on all elements.
3233
* const schema = deepmerge(defaultSchema, {attributes: {'*': ['className']}})
3334
*
3435
* const tree = sanitize(h('div', {className: ['foo']}), schema)
@@ -88,16 +89,14 @@
8889
*
8990
* ```js
9091
* attributes: {
91-
* a: ['href'],
92-
* // …
93-
* img: ['src', 'longDesc'],
92+
* 'ariaDescribedBy', 'ariaLabel', 'ariaLabelledBy', …, 'href'
9493
* // …
9594
* '*': [
9695
* 'abbr',
9796
* 'accept',
9897
* 'acceptCharset',
9998
* // …
100-
* 'vSpace',
99+
* 'vAlign',
101100
* 'value',
102101
* 'width'
103102
* ]
@@ -125,7 +124,7 @@
125124
* For example:
126125
*
127126
* ```js
128-
* clobber: ['id', 'name']
127+
* clobber: ['ariaDescribedBy', 'ariaLabelledBy', 'id', 'name']
129128
* ```
130129
* @property {string | null | undefined} [clobberPrefix]
131130
* Prefix to use before clobbering properties (default:
@@ -136,7 +135,7 @@
136135
* ```js
137136
* clobberPrefix: 'user-content-'
138137
* ```
139-
* @property {Record<string, Array<string>> | null | undefined} [protocols]
138+
* @property {Record<string, Array<string> | null | undefined> | null | undefined} [protocols]
140139
* Map of *property names* to allowed protocols (default:
141140
* `defaultSchema.protocols`).
142141
*
@@ -149,9 +148,9 @@
149148
*
150149
* ```js
151150
* protocols: {
152-
* href: ['http', 'https', 'irc', 'ircs', 'mailto', 'xmpp'],
151+
* cite: ['http', 'https'],
153152
* // …
154-
* longDesc: ['http', 'https']
153+
* src: ['http', 'https']
155154
* }
156155
* ```
157156
* @property {Record<string, Record<string, Properties[keyof Properties]>> | null | undefined} [required]
@@ -194,12 +193,10 @@
194193
* ```js
195194
* tagNames: [
196195
* 'a',
197-
* 'abbr',
198196
* 'b',
199197
* // …
200198
* 'ul',
201-
* 'var',
202-
* 'wbr'
199+
* 'var'
203200
* ]
204201
* ```
205202
*

Diff for: lib/schema.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,13 @@ export const defaultSchema = {
134134
'width'
135135
]
136136
},
137-
clobberPrefix: 'user-content-',
138137
clobber: ['ariaDescribedBy', 'ariaLabelledBy', 'id', 'name'],
138+
clobberPrefix: 'user-content-',
139139
protocols: {
140-
href: ['http', 'https', 'irc', 'ircs', 'mailto', 'xmpp'],
141140
cite: ['http', 'https'],
142-
src: ['http', 'https'],
143-
longDesc: ['http', 'https']
141+
href: ['http', 'https', 'irc', 'ircs', 'mailto', 'xmpp'],
142+
longDesc: ['http', 'https'],
143+
src: ['http', 'https']
144144
},
145145
required: {
146146
input: {disabled: true, type: 'checkbox'}

Diff for: readme.md

+21-16
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ import deepmerge from 'deepmerge'
159159
import {h} from 'hastscript'
160160
import {defaultSchema, sanitize} from 'hast-util-sanitize'
161161

162+
// This allows `className` on all elements.
162163
const schema = deepmerge(defaultSchema, {attributes: {'*': ['className']}})
163164

164165
const tree = sanitize(h('div', {className: ['foo']}), schema)
@@ -229,16 +230,16 @@ For example:
229230

230231
```js
231232
attributes: {
232-
a: ['href'],
233-
//
234-
img: ['src', 'longDesc'],
233+
a: [
234+
'ariaDescribedBy', 'ariaLabel', 'ariaLabelledBy', /**/, 'href'
235+
],
235236
//
236237
'*': [
237238
'abbr',
238239
'accept',
239240
'acceptCharset',
240241
//
241-
'vSpace',
242+
'vAlign',
242243
'value',
243244
'width'
244245
]
@@ -269,7 +270,7 @@ List of [*property names*][name] that clobber (`Array<string>`, default:
269270
For example:
270271

271272
```js
272-
clobber: ['id', 'name']
273+
clobber: ['ariaDescribedBy', 'ariaLabelledBy', 'id', 'name']
273274
```
274275

275276
###### `clobberPrefix`
@@ -297,9 +298,9 @@ For example:
297298

298299
```js
299300
protocols: {
300-
href: ['http', 'https', 'irc', 'ircs', 'mailto', 'xmpp'],
301+
cite: ['http', 'https'],
301302
//
302-
longDesc: ['http', 'https']
303+
src: ['http', 'https']
303304
}
304305
```
305306

@@ -349,12 +350,10 @@ For example:
349350
```js
350351
tagNames: [
351352
'a',
352-
'abbr',
353353
'b',
354354
//
355355
'ul',
356-
'var',
357-
'wbr'
356+
'var'
358357
]
359358
```
360359

@@ -365,15 +364,21 @@ It exports the additional type [`Schema`][api-schema].
365364

366365
## Compatibility
367366

368-
Projects maintained by the unified collective are compatible with all maintained
367+
Projects maintained by the unified collective are compatible with maintained
369368
versions of Node.js.
370-
As of now, that is Node.js 14.14+ and 16.0+.
371-
Our projects sometimes work with older versions, but this is not guaranteed.
369+
370+
When we cut a new major release, we drop support for unmaintained versions of
371+
Node.
372+
This means we try to keep the current release line, `hast-util-sanitize@^4`,
373+
compatible with Node.js 12.
372374

373375
## Security
374376

375377
By default, `hast-util-sanitize` will make everything safe to use.
376-
But when used incorrectly, deviating from the defaults can open you up to a
378+
Assuming you understand that certain attributes (including a limited set of
379+
classes) can be generated by users, and you write your CSS (and JS)
380+
accordingly.
381+
When used incorrectly, deviating from the defaults can open you up to a
377382
[cross-site scripting (XSS)][xss] attack.
378383

379384
Use `hast-util-sanitize` after the last unsafe thing: everything after it could
@@ -412,9 +417,9 @@ abide by its terms.
412417

413418
[downloads]: https://www.npmjs.com/package/hast-util-sanitize
414419

415-
[size-badge]: https://img.shields.io/bundlephobia/minzip/hast-util-sanitize.svg
420+
[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=hast-util-sanitize
416421

417-
[size]: https://bundlephobia.com/result?p=hast-util-sanitize
422+
[size]: https://bundlejs.com/?q=hast-util-sanitize
418423

419424
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
420425

0 commit comments

Comments
 (0)