rehype-minify-whitespace
Advanced tools
Comparing version 5.0.0 to 5.0.1
/** | ||
* Collapse whitespace. | ||
* Minify whitespace. | ||
* | ||
* Normally, collapses to a single space. | ||
* If `newlines: true`, collapses whitespace containing newlines to `'\n'` | ||
* instead of `' '`. | ||
* | ||
* @type {import('unified').Plugin<[Options?] | void[], Root>} | ||
* @type {import('unified').Plugin<[Options?]|Array<void>, Root>} | ||
*/ | ||
@@ -10,0 +6,0 @@ export default function rehypeMinifyWhitespace( |
47
index.js
/** | ||
* @fileoverview | ||
* Collapse whitespace. | ||
* rehype plugin to minify whitespace between elements. | ||
* | ||
* Normally, collapses to a single space. | ||
* If `newlines: true`, collapses whitespace containing newlines to `'\n'` | ||
* instead of `' '`. | ||
* ## What is this? | ||
* | ||
* This package is a plugin that can minify the whitespace between elements. | ||
* | ||
* ## When should I use this? | ||
* | ||
* You can use this plugin when you want to improve the size of HTML documents. | ||
* | ||
* ## API | ||
* | ||
* ### `unified().use(rehypeMinifyWhitespace[, options])` | ||
* | ||
* Minify whitespace. | ||
* | ||
* ##### `options` | ||
* | ||
* Configuration (optional). | ||
* | ||
* ##### `options.newlines` | ||
* | ||
* Whether to collapse runs of whitespace that include line endings to one | ||
* line ending (`boolean`, default: `false`). | ||
* The default is to collapse everything to one space. | ||
* | ||
* @example | ||
@@ -50,9 +70,5 @@ * <h1>Heading</h1> | ||
/** | ||
* Collapse whitespace. | ||
* Minify whitespace. | ||
* | ||
* Normally, collapses to a single space. | ||
* If `newlines: true`, collapses whitespace containing newlines to `'\n'` | ||
* instead of `' '`. | ||
* | ||
* @type {import('unified').Plugin<[Options?] | void[], Root>} | ||
* @type {import('unified').Plugin<[Options?]|Array<void>, Root>} | ||
*/ | ||
@@ -177,3 +193,3 @@ export default function rehypeMinifyWhitespace(options = {}) { | ||
/** | ||
* @param {Node[]} nodes | ||
* @param {Array<Node>} nodes | ||
* @param {number} index | ||
@@ -307,3 +323,4 @@ * @param {boolean|undefined} [after] | ||
/** | ||
* We don’t support void elements here (so `nobr wbr` -> `normal` is ignored). | ||
* We don’t need to support void elements here (so `nobr wbr` -> `normal` is | ||
* ignored). | ||
* | ||
@@ -317,4 +334,8 @@ * @param {Root|Element} node | ||
switch (node.tagName) { | ||
// Whitespace in script/style, while not displayed by CSS as significant, | ||
// could have some meaning in JS/CSS, so we can’t touch them. | ||
case 'listing': | ||
case 'plaintext': | ||
case 'script': | ||
case 'style': | ||
case 'xmp': | ||
@@ -321,0 +342,0 @@ return 'pre' |
{ | ||
"name": "rehype-minify-whitespace", | ||
"version": "5.0.0", | ||
"version": "5.0.1", | ||
"description": "rehype plugin to collapse whitespace", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
159
readme.md
@@ -1,2 +0,2 @@ | ||
<!--This file is generated by `build-packages.js`--> | ||
<!--This file is generated--> | ||
@@ -13,15 +13,34 @@ # rehype-minify-whitespace | ||
Collapse whitespace. | ||
**[rehype][]** plugin to minify whitespace between elements. | ||
Normally, collapses to a single space. | ||
If `newlines: true`, collapses whitespace containing newlines to `'\n'` | ||
instead of `' '`. | ||
## Contents | ||
* [What is this?](#what-is-this) | ||
* [When should I use this?](#when-should-i-use-this) | ||
* [Install](#install) | ||
* [Use](#use) | ||
* [API](#api) | ||
* [`unified().use(rehypeMinifyWhitespace[, options])`](#unifieduserehypeminifywhitespace-options) | ||
* [Example](#example) | ||
* [Syntax](#syntax) | ||
* [Syntax tree](#syntax-tree) | ||
* [Types](#types) | ||
* [Compatibility](#compatibility) | ||
* [Security](#security) | ||
* [Contribute](#contribute) | ||
* [License](#license) | ||
## What is this? | ||
This package is a plugin that can minify the whitespace between elements. | ||
## When should I use this? | ||
You can use this plugin when you want to improve the size of HTML documents. | ||
## Install | ||
This package is [ESM only][esm]: | ||
Node 12+ is needed to use it and it must be `imported`ed instead of `required`d. | ||
This package is [ESM only][esm]. | ||
In Node.js (version 12.20+, 14.14+, or 16.0+), install with [npm][]: | ||
[npm][]: | ||
```sh | ||
@@ -31,5 +50,16 @@ npm install rehype-minify-whitespace | ||
This package exports no identifiers. | ||
The default export is `rehypeMinifyWhitespace` | ||
In Deno with [Skypack][]: | ||
```js | ||
import rehypeMinifyWhitespace from 'https://cdn.skypack.dev/rehype-minify-whitespace@5?dts' | ||
``` | ||
In browsers with [Skypack][]: | ||
```html | ||
<script type="module"> | ||
import rehypeMinifyWhitespace from 'https://cdn.skypack.dev/rehype-minify-whitespace@5?min' | ||
</script> | ||
``` | ||
## Use | ||
@@ -39,16 +69,20 @@ | ||
```diff | ||
import {unified} from 'unified' | ||
import rehypeParse from 'rehype-parse' | ||
+import rehypeMinifyWhitespace from 'rehype-minify-whitespace' | ||
import rehypeStringify from 'rehype-stringify' | ||
```js | ||
import {read} from 'to-vfile' | ||
import {unified} from 'unified' | ||
import rehypeParse from 'rehype-parse' | ||
import rehypeStringify from 'rehype-stringify' | ||
import rehypeMinifyWhitespace from 'rehype-minify-whitespace' | ||
unified() | ||
.use(rehypeParse) | ||
+ .use(rehypeMinifyWhitespace) | ||
.use(rehypeStringify) | ||
.process('<span>some html</span>', function (err, file) { | ||
console.error(report(err || file)) | ||
console.log(String(file)) | ||
}) | ||
main() | ||
async function main() { | ||
const file = await unified() | ||
.use(rehypeParse) | ||
.use(rehypeMinifyWhitespace) | ||
.use(rehypeStringify) | ||
.process(await read('index.html')) | ||
console.log(String(file)) | ||
} | ||
``` | ||
@@ -59,8 +93,41 @@ | ||
```sh | ||
rehype input.html --use minify-whitespace --output output.html | ||
rehype input.html --use rehype-minify-whitespace --output output.html | ||
``` | ||
On the CLI in a config file (here a `package.json`): | ||
```diff | ||
… | ||
"rehype": { | ||
"plugins": [ | ||
… | ||
+ "rehype-minify-whitespace", | ||
… | ||
] | ||
} | ||
… | ||
``` | ||
## API | ||
This package exports no identifiers. | ||
The default export is `rehypeMinifyWhitespace`. | ||
### `unified().use(rehypeMinifyWhitespace[, options])` | ||
Minify whitespace. | ||
##### `options` | ||
Configuration (optional). | ||
##### `options.newlines` | ||
Whether to collapse runs of whitespace that include line endings to one | ||
line ending (`boolean`, default: `false`). | ||
The default is to collapse everything to one space. | ||
## Example | ||
##### In | ||
###### In | ||
@@ -72,3 +139,3 @@ ```html | ||
##### Out | ||
###### Out | ||
@@ -79,2 +146,28 @@ ```html | ||
## Syntax | ||
HTML is handled according to WHATWG HTML (the living standard), which is also | ||
followed by browsers such as Chrome and Firefox. | ||
## Syntax tree | ||
The syntax tree format used is [`hast`][hast]. | ||
## Types | ||
This package is fully typed with [TypeScript][]. | ||
## Compatibility | ||
Projects maintained by the unified collective are compatible with all maintained | ||
versions of Node.js. | ||
As of now, that is Node.js 12.20+, 14.14+, and 16.0+. | ||
Our projects sometimes work with older versions, but this is not guaranteed. | ||
## Security | ||
As **rehype** works on HTML, and improper use of HTML can open you up to a | ||
[cross-site scripting (XSS)][xss] attack, use of rehype can also be unsafe. | ||
Use [`rehype-sanitize`][rehype-sanitize] to make the tree safe. | ||
## Contribute | ||
@@ -124,2 +217,10 @@ | ||
[skypack]: https://www.skypack.dev | ||
[typescript]: https://www.typescriptlang.org | ||
[rehype-sanitize]: https://github.com/rehypejs/rehype-sanitize | ||
[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting | ||
[health]: https://github.com/rehypejs/.github | ||
@@ -136,1 +237,5 @@ | ||
[author]: https://wooorm.com | ||
[hast]: https://github.com/syntax-tree/hast | ||
[rehype]: https://github.com/rehypejs/rehype |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
18506
445
234
0