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

rehype-slug

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-slug - npm Package Compare versions

Comparing version 5.0.1 to 5.1.0

15

index.d.ts
/**
* Plugin to add `id`s to headings.
*
* @type {import('unified').Plugin<Array<void>, Root>}
* @type {import('unified').Plugin<[Options?]|Array<void>, Root>}
*/
export default function rehypeSlug():
export default function rehypeSlug(
options?: void | Options | undefined
):
| void
| import('unified').Transformer<import('hast').Root, import('hast').Root>
export type Root = import('hast').Root
/**
* Configuration (optional).
*/
export type Options = {
/**
* Prefix to add in front of `id`s.
*/
prefix?: string | undefined
}

15

index.js

@@ -5,2 +5,9 @@ /**

/**
* @typedef Options
* Configuration (optional).
* @property {string} [prefix='']
* Prefix to add in front of `id`s.
*/
import Slugger from 'github-slugger'

@@ -17,5 +24,7 @@ import {hasProperty} from 'hast-util-has-property'

*
* @type {import('unified').Plugin<Array<void>, Root>}
* @type {import('unified').Plugin<[Options?]|Array<void>, Root>}
*/
export default function rehypeSlug() {
export default function rehypeSlug(options = {}) {
const prefix = options.prefix || ''
return (tree) => {

@@ -26,3 +35,3 @@ slugs.reset()

if (headingRank(node) && node.properties && !hasProperty(node, 'id')) {
node.properties.id = slugs.slug(toString(node))
node.properties.id = prefix + slugs.slug(toString(node))
}

@@ -29,0 +38,0 @@ })

{
"name": "rehype-slug",
"version": "5.0.1",
"version": "5.1.0",
"description": "rehype plugin to add `id` attributes to headings",

@@ -36,3 +36,3 @@ "license": "MIT",

"@types/hast": "^2.0.0",
"github-slugger": "^1.1.1",
"github-slugger": "^2.0.0",
"hast-util-has-property": "^2.0.0",

@@ -45,3 +45,2 @@ "hast-util-heading-rank": "^2.0.0",

"devDependencies": {
"@types/github-slugger": "^1.0.0",
"@types/tape": "^4.0.0",

@@ -51,3 +50,3 @@ "c8": "^7.0.0",

"rehype": "^12.0.0",
"remark-cli": "^10.0.0",
"remark-cli": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",

@@ -58,3 +57,3 @@ "rimraf": "^3.0.0",

"typescript": "^4.0.0",
"xo": "^0.47.0"
"xo": "^0.52.0"
},

@@ -61,0 +60,0 @@ "scripts": {

@@ -20,3 +20,3 @@ # rehype-slug

* [API](#api)
* [`unified().use(rehypeSlug)`](#unifieduserehypeslug)
* [`unified().use(rehypeSlug[, options])`](#unifieduserehypeslug-options)
* [Types](#types)

@@ -61,13 +61,13 @@ * [Compatibility](#compatibility)

In Deno with [Skypack][]:
In Deno with [`esm.sh`][esmsh]:
```js
import rehypeSlug from 'https://cdn.skypack.dev/rehype-slug@5?dts'
import rehypeSlug from 'https://esm.sh/rehype-slug@5'
```
In browsers with [Skypack][]:
In browsers with [`esm.sh`][esmsh]:
```html
<script type="module">
import rehypeSlug from 'https://cdn.skypack.dev/rehype-slug@5?min'
import rehypeSlug from 'https://esm.sh/rehype-slug@5?bundle'
</script>

@@ -95,12 +95,8 @@ ```

main()
const file = await rehype()
.data('settings', {fragment: true})
.use(rehypeSlug)
.process(await read('example.html'))
async function main() {
const file = await rehype()
.data('settings', {fragment: true})
.use(rehypeSlug)
.process(await read('example.html'))
console.log(String(file))
}
console.log(String(file))
```

@@ -123,11 +119,18 @@

### `unified().use(rehypeSlug)`
### `unified().use(rehypeSlug[, options])`
Add `id`s to headings.
There are no options.
##### `options`
Configuration (optional).
###### `options.prefix`
Prefix to add in front of `id`s (`string`, default: `''`).
## Types
This package is fully typed with [TypeScript][].
There are no extra exported types.
It exports the additional type `Options`.

@@ -202,3 +205,3 @@ ## Compatibility

[skypack]: https://www.skypack.dev
[esmsh]: https://esm.sh

@@ -205,0 +208,0 @@ [health]: https://github.com/rehypejs/.github

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