Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rehype-remove-comments

Package Overview
Dependencies
Maintainers
2
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rehype-remove-comments - npm Package Compare versions

Comparing version 5.0.0 to 6.0.0

lib/index.d.ts

28

index.d.ts

@@ -1,26 +0,2 @@

/**
* Remove comments (except conditional comments).
*
* When configured with `force: true` (default: `false`), conditional comments
* are also removed.
*
* @type {import('unified').Plugin<[Options?] | void[], Root>}
*/
export default function rehypeRemoveComments(
options?: void | Options | undefined
):
| void
| import('unified').Transformer<import('hast').Root, import('hast').Root>
export type Root = import('hast').Root
export type Node = import('unist').Node
export type HastNode = Root | Root['children'][number]
/**
* Configuration.
*/
export type Options = {
/**
* Conditional comments are also removed when configured with `force: true`
* The default is to leave them.
*/
removeConditional?: boolean | undefined
}
export { default } from "./lib/index.js";
export type Options = import('./lib/index.js').Options;
/**
* @fileoverview
* Remove comments (except conditional comments).
* rehype plugin to remove comments.
*
* When configured with `force: true` (default: `false`), conditional comments
* are also removed.
* ## What is this?
*
* This package is a plugin that removes comments.
* By default it keeps conditional comments, optionally it removes them too.
*
* ## When should I use this?
*
* You can use this plugin when you want to improve the transfer size of HTML
* documents.
*
* ## API
*
* ### `unified().use(rehypeRemoveComments[, options])`
*
* Remove comments.
*
* ###### Parameters
*
* * `options` (`Options`, optional)
* — configuration
*
* ###### Returns
*
* Transform ([`Transformer`](https://github.com/unifiedjs/unified#transformer)).
*
* ### `Options`
*
* Configuration (TypeScript type).
*
* ##### Fields
*
* * `removeConditional` (`boolean`, default: `false`)
* — remove conditional comments (default: `false`); the default is to
* leave them
*
* @example
* {}
* <!--Hello-->

@@ -13,50 +46,5 @@ * <!--[if IE 6]>OK<![endif]-->

/**
* @typedef {import('hast').Root} Root
* @typedef {import('unist').Node} Node
* @typedef {Root|Root['children'][number]} HastNode
*
* @typedef Options
* Configuration.
* @property {boolean} [removeConditional=false]
* Conditional comments are also removed when configured with `force: true`
* The default is to leave them.
* @typedef {import('./lib/index.js').Options} Options
*/
import {filter} from 'unist-util-filter'
import {isConditionalComment} from 'hast-util-is-conditional-comment'
/**
* Remove comments (except conditional comments).
*
* When configured with `force: true` (default: `false`), conditional comments
* are also removed.
*
* @type {import('unified').Plugin<[Options?] | void[], Root>}
*/
export default function rehypeRemoveComments(options = {}) {
const force = options.removeConditional
return (tree) =>
// `undefined` is never returned because we don’t remove nodes (but TS
// doesn’t know it.)
/* c8 ignore next */
filter(tree, {cascade: false}, force ? hard : soft) || undefined
}
/**
* @param {Node} node
* @returns {boolean}
*/
function soft(node) {
const x = /** @type {HastNode} */ (node)
return hard(x) || isConditionalComment(x)
}
/**
* @param {Node} node
* @returns {boolean}
*/
function hard(node) {
const x = /** @type {HastNode} */ (node)
return x.type !== 'comment'
}
export {default} from './lib/index.js'
{
"name": "rehype-remove-comments",
"version": "5.0.0",
"version": "6.0.0",
"description": "rehype plugin to remove comments (except conditional comments)",
"license": "MIT",
"keywords": [
"unified",
"comment",
"html",
"mangle",
"minify",
"plugin",
"rehype",
"rehype-plugin",
"plugin",
"html",
"minify",
"mangle",
"comment"
"unified"
],

@@ -28,25 +28,21 @@ "repository": "https://github.com/rehypejs/rehype-minify/tree/main/packages/rehype-remove-comments",

"type": "module",
"main": "index.js",
"types": "index.d.ts",
"exports": "./index.js",
"files": [
"index.d.ts",
"index.js"
"index.js",
"lib/"
],
"dependencies": {
"@types/hast": "^2.0.0",
"hast-util-is-conditional-comment": "^2.0.0",
"unified": "^10.0.0",
"unist-util-filter": "^4.0.0"
"@types/hast": "^3.0.0",
"hast-util-is-conditional-comment": "^3.0.0",
"unist-util-visit": "^5.0.0"
},
"scripts": {
"build": "rimraf \"*.d.ts\" && tsc && type-coverage",
"test": "node --conditions development test.js"
},
"xo": false,
"scripts": {},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true,
"ignoreCatch": true
}
"ignoreCatch": true,
"strict": true
},
"xo": false
}

@@ -1,2 +0,2 @@

<!--This file is generated by `build-packages.js`-->
<!--This file is generated-->

@@ -9,18 +9,41 @@ # rehype-remove-comments

[![Size][size-badge]][size]
[![Sponsors][sponsors-badge]][collective]
[![Backers][backers-badge]][collective]
[![Sponsors][funding-sponsors-badge]][funding]
[![Backers][funding-backers-badge]][funding]
[![Chat][chat-badge]][chat]
Remove comments (except conditional comments).
**[rehype][]** plugin to remove comments.
When configured with `force: true` (default: `false`), conditional comments
are also removed.
## 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(rehypeRemoveComments[, options])`](#unifieduserehyperemovecomments-options)
* [`Options`](#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 removes comments.
By default it keeps conditional comments, optionally it removes them too.
## When should I use this?
You can use this plugin when you want to improve the transfer 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 16+), install with [npm][]:
[npm][]:
```sh

@@ -30,5 +53,16 @@ npm install rehype-remove-comments

This package exports no identifiers.
The default export is `rehypeRemoveComments`
In Deno with [`esm.sh`][esm-sh]:
```js
import rehypeRemoveComments from 'https://esm.sh/rehype-remove-comments@6'
```
In browsers with [`esm.sh`][esm-sh]:
```html
<script type="module">
import rehypeRemoveComments from 'https://esm.sh/rehype-remove-comments@6?bundle'
</script>
```
## Use

@@ -38,16 +72,16 @@

```diff
import {unified} from 'unified'
import rehypeParse from 'rehype-parse'
+import rehypeRemoveComments from 'rehype-remove-comments'
import rehypeStringify from 'rehype-stringify'
```js
import rehypeParse from 'rehype-parse'
import rehypeRemoveComments from 'rehype-remove-comments'
import rehypeStringify from 'rehype-stringify'
import {read} from 'to-vfile'
import {unified} from 'unified'
unified()
.use(rehypeParse)
+ .use(rehypeRemoveComments)
.use(rehypeStringify)
.process('<span>some html</span>', function (err, file) {
console.error(report(err || file))
console.log(String(file))
})
const file = await unified()
.use(rehypeParse)
.use(rehypeRemoveComments)
.use(rehypeStringify)
.process(await read('index.html'))
console.log(String(file))
```

@@ -58,8 +92,50 @@

```sh
rehype input.html --use remove-comments --output output.html
rehype input.html --use rehype-remove-comments --output output.html
```
On the CLI in a config file (here a `package.json`):
```diff
"rehype": {
"plugins": [
+ "rehype-remove-comments",
]
}
```
## API
This package exports no identifiers.
The default export is `rehypeRemoveComments`.
### `unified().use(rehypeRemoveComments[, options])`
Remove comments.
###### Parameters
* `options` (`Options`, optional)
— configuration
###### Returns
Transform ([`Transformer`](https://github.com/unifiedjs/unified#transformer)).
### `Options`
Configuration (TypeScript type).
##### Fields
* `removeConditional` (`boolean`, default: `false`)
— remove conditional comments (default: `false`); the default is to
leave them
## Example
##### In
###### In

@@ -71,3 +147,3 @@ ```html

##### Out
###### Out

@@ -78,2 +154,32 @@ ```html

## Syntax
HTML is parsed according to WHATWG HTML (the living standard), which is also
followed by all browsers.
## Syntax tree
The syntax tree used is [hast][].
## Types
This package is fully typed with [TypeScript][].
## Compatibility
Projects maintained by the unified collective are compatible with maintained
versions of Node.js.
When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line,
`rehype-remove-comments@^6`,
compatible with Node.js 16.
## 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

@@ -93,42 +199,54 @@

[build-badge]: https://github.com/rehypejs/rehype-minify/workflows/main/badge.svg
[author]: https://wooorm.com
[build]: https://github.com/rehypejs/rehype-minify/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/rehypejs/rehype-minify.svg
[build-badge]: https://github.com/rehypejs/rehype-minify/workflows/main/badge.svg
[chat]: https://github.com/rehypejs/rehype/discussions
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[coc]: https://github.com/rehypejs/.github/blob/main/code-of-conduct.md
[contributing]: https://github.com/rehypejs/.github/blob/main/contributing.md
[coverage]: https://codecov.io/github/rehypejs/rehype-minify
[downloads-badge]: https://img.shields.io/npm/dm/rehype-remove-comments.svg
[coverage-badge]: https://img.shields.io/codecov/c/github/rehypejs/rehype-minify.svg
[downloads]: https://www.npmjs.com/package/rehype-remove-comments
[size-badge]: https://img.shields.io/bundlephobia/minzip/rehype-remove-comments.svg
[downloads-badge]: https://img.shields.io/npm/dm/rehype-remove-comments.svg
[size]: https://bundlephobia.com/result?p=rehype-remove-comments
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[esm-sh]: https://esm.sh
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[funding]: https://opencollective.com/unified
[collective]: https://opencollective.com/unified
[funding-backers-badge]: https://opencollective.com/unified/backers/badge.svg
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[funding-sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[chat]: https://github.com/rehypejs/rehype/discussions
[hast]: https://github.com/syntax-tree/hast
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[health]: https://github.com/rehypejs/.github
[license]: https://github.com/rehypejs/rehype-minify/blob/main/license
[npm]: https://docs.npmjs.com/cli/install
[health]: https://github.com/rehypejs/.github
[rehype]: https://github.com/rehypejs/rehype
[contributing]: https://github.com/rehypejs/.github/blob/main/contributing.md
[rehype-sanitize]: https://github.com/rehypejs/rehype-sanitize
[size]: https://bundlejs.com/?q=rehype-remove-comments
[size-badge]: https://img.shields.io/bundlejs/size/rehype-remove-comments
[support]: https://github.com/rehypejs/.github/blob/main/support.md
[coc]: https://github.com/rehypejs/.github/blob/main/code-of-conduct.md
[typescript]: https://www.typescriptlang.org
[license]: https://github.com/rehypejs/rehype-minify/blob/main/license
[author]: https://wooorm.com
[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc