|
34 | 34 | This package is a [unified][] ([rehype][]) plugin to format whitespace in HTML.
|
35 | 35 | In short, it works as follows:
|
36 | 36 |
|
37 |
| -* collapse all existing white space to either a line ending or a single space |
| 37 | +* collapse all existing whitespace to either a line ending or a single space |
38 | 38 | * remove those spaces and line endings if they do not contribute to the
|
39 | 39 | document
|
40 | 40 | * inject needed line endings
|
@@ -104,11 +104,13 @@ import rehypeStringify from 'rehype-stringify'
|
104 | 104 | import {read} from 'to-vfile'
|
105 | 105 | import {unified} from 'unified'
|
106 | 106 |
|
107 |
| -const file = await unified() |
| 107 | +const file = await read('index.html') |
| 108 | + |
| 109 | +await unified() |
108 | 110 | .use(rehypeParse)
|
109 | 111 | .use(rehypeFormat)
|
110 | 112 | .use(rehypeStringify)
|
111 |
| - .process(await read('index.html')) |
| 113 | + .process(file) |
112 | 114 |
|
113 | 115 | console.log(String(file))
|
114 | 116 | ```
|
@@ -221,7 +223,7 @@ import {unified} from 'unified'
|
221 | 223 |
|
222 | 224 | const file = await unified()
|
223 | 225 | .use(rehypeParse)
|
224 |
| - .use(rehypeFormat, {blanks: ['head', 'body'], indent: '\t'}) |
| 226 | + .use(rehypeFormat, {blanks: ['body', 'head'], indent: '\t'}) |
225 | 227 | .use(rehypeStringify)
|
226 | 228 | .process('<h1>Hi!</h1><p>Hello, Venus!</p>')
|
227 | 229 |
|
@@ -260,16 +262,16 @@ versions of Node.js.
|
260 | 262 |
|
261 | 263 | When we cut a new major release, we drop support for unmaintained versions of
|
262 | 264 | Node.
|
263 |
| -This means we try to keep the current release line, `rehype-format@^5`, |
| 265 | +This means we try to keep the current release line, `rehype-format@5`, |
264 | 266 | compatible with Node.js 16.
|
265 | 267 |
|
266 | 268 | This plugin works with `rehype-parse` version 3+, `rehype-stringify` version 3+,
|
267 | 269 | `rehype` version 5+, and `unified` version 6+.
|
268 | 270 |
|
269 | 271 | ## Security
|
270 | 272 |
|
271 |
| -Use of `rehype-format` changes white space in the tree. |
272 |
| -White space in `<script>`, `<style>`, `<pre>`, or `<textarea>` is not modified. |
| 273 | +Use of `rehype-format` changes whitespace in the tree. |
| 274 | +Whitespace in `<script>`, `<style>`, `<pre>`, or `<textarea>` is not modified. |
273 | 275 | If the tree is already safe, use of this plugin does not open you up for a
|
274 | 276 | [cross-site scripting (XSS)][xss] attack.
|
275 | 277 | When in doubt, use [`rehype-sanitize`][rehype-sanitize].
|
|
0 commit comments