rehype-autolink-headings
Advanced tools
Comparing version 6.0.0 to 6.1.0
@@ -16,2 +16,3 @@ /** | ||
export type Properties = import('hast').Properties | ||
export type Test = import('hast-util-is-element').Test | ||
export type Behavior = 'prepend' | 'append' | 'wrap' | 'before' | 'after' | ||
@@ -41,6 +42,4 @@ export type Build = (node: Element) => ElementChild | ElementChild[] | ||
content?: | ||
| import('hast').Element | ||
| import('hast').Comment | ||
| import('hast').Text | ||
| (import('hast').Element | import('hast').Comment | import('hast').Text)[] | ||
| import('hast').ElementContent | ||
| import('hast').ElementContent[] | ||
| Build | ||
@@ -54,8 +53,13 @@ | undefined | ||
group?: | ||
| import('hast').Element | ||
| import('hast').Comment | ||
| import('hast').Text | ||
| (import('hast').Element | import('hast').Comment | import('hast').Text)[] | ||
| import('hast').ElementContent | ||
| import('hast').ElementContent[] | ||
| Build | ||
| undefined | ||
/** | ||
* Test to define which heading elements are linked. | ||
* Any test that can be given to `hast-util-is-element` is supported. | ||
* The default (no test) is to link all headings. | ||
* Can be used to link only h1-h3, or for example all except h1. | ||
*/ | ||
test?: Test | ||
} |
14
index.js
@@ -7,2 +7,3 @@ /** | ||
* @typedef {import('hast').Properties} Properties | ||
* @typedef {import('hast-util-is-element').Test} Test | ||
* | ||
@@ -31,2 +32,7 @@ * @typedef {'prepend'|'append'|'wrap'|'before'|'after'} Behavior | ||
* There is no default. | ||
* @property {Test} [test] | ||
* Test to define which heading elements are linked. | ||
* Any test that can be given to `hast-util-is-element` is supported. | ||
* The default (no test) is to link all headings. | ||
* Can be used to link only h1-h3, or for example all except h1. | ||
*/ | ||
@@ -37,2 +43,3 @@ | ||
import {headingRank} from 'hast-util-heading-rank' | ||
import {convertElement} from 'hast-util-is-element' | ||
import {visit, SKIP} from 'unist-util-visit' | ||
@@ -58,2 +65,3 @@ | ||
const group = options.group | ||
const is = convertElement(options.test) | ||
@@ -77,3 +85,7 @@ /** @type {import('unist-util-visit').Visitor<Element>} */ | ||
visit(tree, 'element', (node, index, parent) => { | ||
if (headingRank(node) && hasProperty(node, 'id')) { | ||
if ( | ||
headingRank(node) && | ||
hasProperty(node, 'id') && | ||
is(node, index, parent) | ||
) { | ||
return method(node, index, parent) | ||
@@ -80,0 +92,0 @@ } |
{ | ||
"name": "rehype-autolink-headings", | ||
"version": "6.0.0", | ||
"version": "6.1.0", | ||
"description": "rehype plugin to add links to headings", | ||
@@ -38,2 +38,3 @@ "license": "MIT", | ||
"hast-util-heading-rank": "^2.0.0", | ||
"hast-util-is-element": "^2.0.0", | ||
"unified": "^10.0.0", | ||
@@ -50,4 +51,4 @@ "unist-util-visit": "^4.0.0" | ||
"rehype": "^12.0.0", | ||
"remark-cli": "^9.0.0", | ||
"remark-preset-wooorm": "^8.0.0", | ||
"remark-cli": "^10.0.0", | ||
"remark-preset-wooorm": "^9.0.0", | ||
"rimraf": "^3.0.0", | ||
@@ -58,3 +59,3 @@ "tape": "^5.0.0", | ||
"typescript": "^4.0.0", | ||
"xo": "^0.42.0" | ||
"xo": "^0.44.0" | ||
}, | ||
@@ -61,0 +62,0 @@ "scripts": { |
@@ -11,3 +11,4 @@ # rehype-autolink-headings | ||
[**rehype**][rehype] plugin to automatically add links to headings (h1-h6). | ||
[**rehype**][rehype] plugin to automatically add links to headings (h1-h6) that | ||
already have an ID. | ||
@@ -76,4 +77,4 @@ ## Install | ||
> **Note**: this plugin expects `id`s to already exist on headings. | ||
> One way to add those automatically, is [`rehype-slug`][slug] (see example). | ||
**Note**: this plugin expects `id`s to already exist on headings. | ||
One way to add those automatically is [`rehype-slug`][slug] (see example). | ||
@@ -121,4 +122,4 @@ ##### `options` | ||
```js | ||
var toString = require('hast-util-to-string') | ||
var h = require('hastscript') | ||
import {toString} from 'hast-util-to-string' | ||
import {h} from 'hastscript' | ||
@@ -147,3 +148,3 @@ // … | ||
```js | ||
var h = require('hastscript') | ||
import {h} from 'hastscript' | ||
@@ -157,2 +158,13 @@ // … | ||
###### `options.test` | ||
Test to define which heading elements are linked. | ||
Any test that can be given to [`hast-util-is-element`][is] is supported. | ||
The default (no test) is to link all headings. | ||
Can be used to link only `<h1>` through `<h3>` (with `['h1', 'h2', 'h3']`), or | ||
for example all except `<h1>` (with `['h2', 'h3', 'h4', 'h5', 'h6']`). | ||
Functions can also be given to do more complex things! | ||
## Security | ||
@@ -240,1 +252,3 @@ | ||
[slug]: https://github.com/rehypejs/rehype-slug | ||
[is]: https://github.com/syntax-tree/hast-util-is-element |
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
17256
214
249
0
7
+ Addedhast-util-is-element@^2.0.0
+ Addedhast-util-is-element@2.1.3(transitive)