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 4.0.1 to 5.0.0

index.d.ts

41

index.js

@@ -1,23 +0,28 @@

'use strict'
/**
* @typedef {import('hast').Root} Root
*/
var slugs = require('github-slugger')()
var has = require('hast-util-has-property')
var rank = require('hast-util-heading-rank')
var toString = require('hast-util-to-string')
var visit = require('unist-util-visit')
import Slugger from 'github-slugger'
import {hasProperty} from 'hast-util-has-property'
import {headingRank} from 'hast-util-heading-rank'
import {toString} from 'hast-util-to-string'
import {visit} from 'unist-util-visit'
module.exports = slug
const slugs = new Slugger()
function slug() {
return transformer
}
/**
* Plugin to add `id`s to headings.
*
* @type {import('unified').Plugin<[], Root>}
*/
export default function rehypeSlug() {
return (tree) => {
slugs.reset()
function transformer(tree) {
slugs.reset()
visit(tree, 'element', function (node) {
if (rank(node) && !has(node, 'id')) {
node.properties.id = slugs.slug(toString(node))
}
})
visit(tree, 'element', (node) => {
if (headingRank(node) && node.properties && !hasProperty(node, 'id')) {
node.properties.id = slugs.slug(toString(node))
}
})
}
}
{
"name": "rehype-slug",
"version": "4.0.1",
"version": "5.0.0",
"description": "rehype plugin to add `id` attributes to headings",

@@ -26,43 +26,40 @@ "license": "MIT",

],
"sideEffects": false,
"type": "module",
"types": "index.d.ts",
"main": "index.js",
"files": [
"index.js",
"types/index.d.ts"
"index.d.ts",
"index.js"
],
"types": "types/index.d.ts",
"dependencies": {
"@types/hast": "^2.0.0",
"github-slugger": "^1.1.1",
"hast-util-has-property": "^1.0.0",
"hast-util-heading-rank": "^1.0.0",
"hast-util-to-string": "^1.0.0",
"unist-util-visit": "^2.0.0"
"hast-util-has-property": "^2.0.0",
"hast-util-heading-rank": "^2.0.0",
"hast-util-to-string": "^2.0.0",
"unified": "^10.0.0",
"unist-util-visit": "^4.0.0"
},
"devDependencies": {
"browserify": "^17.0.0",
"dtslint": "^4.0.0",
"nyc": "^15.0.0",
"@types/github-slugger": "^1.3.0",
"@types/tape": "^4.0.0",
"c8": "^7.0.0",
"prettier": "^2.0.0",
"rehype": "^11.0.0",
"rehype": "^12.0.0",
"remark-cli": "^9.0.0",
"remark-preset-wooorm": "^8.0.0",
"rimraf": "^3.0.0",
"tape": "^5.0.0",
"tinyify": "^3.0.0",
"unified": "^9.0.0",
"xo": "^0.34.0"
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"xo": "^0.42.0"
},
"scripts": {
"build": "rimraf \"*.d.ts\" && tsc && type-coverage",
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"build-bundle": "browserify index.js -s rehypeSlug -o rehype-slug.js",
"build-mangle": "browserify index.js -s rehypeSlug -o rehype-slug.min.js -p tinyify",
"build": "npm run build-bundle && npm run build-mangle",
"test-api": "node test",
"test-coverage": "nyc --reporter lcov tape test.js",
"test-types": "dtslint types",
"test": "npm run format && npm run build && npm run test-coverage && npm run test-types"
"test-api": "node --conditions development test.js",
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov npm run test-api",
"test": "npm run build && npm run format && npm run test-coverage"
},
"nyc": {
"check-coverage": true,
"lines": 100,
"functions": 100,
"branches": 100
},
"prettier": {

@@ -77,7 +74,3 @@ "tabWidth": 2,

"xo": {
"prettier": true,
"esnext": false,
"ignores": [
"rehype-slug.js"
]
"prettier": true
},

@@ -88,3 +81,9 @@ "remarkConfig": {

]
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true,
"ignoreCatch": true
}
}

@@ -15,2 +15,5 @@ # rehype-slug

This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c):
Node 12+ is needed to use it and it must be `import`ed instead of `require`d.
[npm][]:

@@ -37,11 +40,13 @@

```js
var fs = require('fs')
var rehype = require('rehype')
var slug = require('rehype-slug')
import fs from 'node:fs'
import {rehype} from 'rehype'
import slug from 'rehype-slug'
const buf = fs.readFileSync('fragment.html')
rehype()
.data('settings', {fragment: true})
.use(slug)
.process(fs.readFileSync('fragment.html'), function(err, file) {
if (err) throw err
.process(buf)
.then((file) => {
console.log(String(file))

@@ -63,4 +68,7 @@ })

### `rehype().use(slug)`
This package exports no identifiers.
The default export is `rehypeSlug`.
### `unified().use(rehypeSlug)`
Add `id` properties to h1-h6 headings that don’t already have one.

@@ -67,0 +75,0 @@

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