rehype-slug
Advanced tools
Comparing version 3.0.0 to 4.0.0
12
index.js
'use strict' | ||
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') | ||
var toString = require('hast-util-to-string') | ||
var is = require('hast-util-is-element') | ||
var has = require('hast-util-has-property') | ||
module.exports = slug | ||
var headings = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'] | ||
function slug() { | ||
@@ -20,4 +18,4 @@ return transformer | ||
visit(tree, 'element', function(node) { | ||
if (is(node, headings) && !has(node, 'id')) { | ||
visit(tree, 'element', function (node) { | ||
if (rank(node) && !has(node, 'id')) { | ||
node.properties.id = slugs.slug(toString(node)) | ||
@@ -24,0 +22,0 @@ } |
{ | ||
"name": "rehype-slug", | ||
"version": "3.0.0", | ||
"version": "4.0.0", | ||
"description": "rehype plugin to add `id` attributes to headings", | ||
@@ -27,3 +27,4 @@ "license": "MIT", | ||
"files": [ | ||
"index.js" | ||
"index.js", | ||
"types/index.d.ts" | ||
], | ||
@@ -33,3 +34,3 @@ "dependencies": { | ||
"hast-util-has-property": "^1.0.0", | ||
"hast-util-is-element": "^1.0.0", | ||
"hast-util-heading-rank": "^1.0.0", | ||
"hast-util-to-string": "^1.0.0", | ||
@@ -39,20 +40,23 @@ "unist-util-visit": "^2.0.0" | ||
"devDependencies": { | ||
"browserify": "^16.0.0", | ||
"browserify": "^17.0.0", | ||
"dtslint": "^4.0.0", | ||
"nyc": "^15.0.0", | ||
"prettier": "^1.0.0", | ||
"rehype": "^9.0.0", | ||
"remark-cli": "^7.0.0", | ||
"remark-preset-wooorm": "^6.0.0", | ||
"tape": "^4.0.0", | ||
"tinyify": "^2.0.0", | ||
"xo": "^0.28.0" | ||
"prettier": "^2.0.0", | ||
"rehype": "^11.0.0", | ||
"remark-cli": "^9.0.0", | ||
"remark-preset-wooorm": "^8.0.0", | ||
"tape": "^5.0.0", | ||
"tinyify": "^3.0.0", | ||
"unified": "^9.0.0", | ||
"xo": "^0.34.0" | ||
}, | ||
"scripts": { | ||
"format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix", | ||
"build-bundle": "browserify index.js -s rehypeSlug > rehype-slug.js", | ||
"build-mangle": "browserify index.js -s rehypeSlug -p tinyify > rehype-slug.min.js", | ||
"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": "npm run format && npm run build && npm run test-coverage" | ||
"test-types": "dtslint types", | ||
"test": "npm run format && npm run build && npm run test-coverage && npm run test-types" | ||
}, | ||
@@ -59,0 +63,0 @@ "nyc": { |
@@ -98,5 +98,5 @@ # rehype-slug | ||
[build-badge]: https://img.shields.io/travis/rehypejs/rehype-slug.svg | ||
[build-badge]: https://github.com/rehypejs/rehype-slug/workflows/main/badge.svg | ||
[build]: https://travis-ci.org/rehypejs/rehype-slug | ||
[build]: https://github.com/rehypejs/rehype-slug/actions | ||
@@ -121,5 +121,5 @@ [coverage-badge]: https://img.shields.io/codecov/c/github/rehypejs/rehype-slug.svg | ||
[chat-badge]: https://img.shields.io/badge/chat-spectrum-7b16ff.svg | ||
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg | ||
[chat]: https://spectrum.chat/unified/rehype | ||
[chat]: https://github.com/rehypejs/rehype/discussions | ||
@@ -130,7 +130,7 @@ [npm]: https://docs.npmjs.com/cli/install | ||
[contributing]: https://github.com/rehypejs/.github/blob/master/contributing.md | ||
[contributing]: https://github.com/rehypejs/.github/blob/HEAD/contributing.md | ||
[support]: https://github.com/rehypejs/.github/blob/master/support.md | ||
[support]: https://github.com/rehypejs/.github/blob/HEAD/support.md | ||
[coc]: https://github.com/rehypejs/.github/blob/master/code-of-conduct.md | ||
[coc]: https://github.com/rehypejs/.github/blob/HEAD/code-of-conduct.md | ||
@@ -137,0 +137,0 @@ [license]: license |
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
7580
5
25
11
+ Addedhast-util-heading-rank@1.0.1(transitive)
- Removedhast-util-is-element@^1.0.0
- Removedhast-util-is-element@1.1.0(transitive)