Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Aug 2, 2021
1 parent cd590cb commit f684436
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

## Install

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][]:

```sh
Expand All @@ -33,19 +36,19 @@ Say we have the following file, `fragment.html`:
And our script, `example.js`, looks as follows:

```js
var fs = require('fs')
var rehype = require('rehype')
var slug = require('rehype-slug')
var link = require('rehype-autolink-headings')
import fs from 'node:fs'
import rehype from 'rehype'
import rehypeSlug from 'rehype-slug'
import rehypeAutolinkHeadings from 'rehype-autolink-headings'

var doc = fs.readFileSync('fragment.html')
const buf = fs.readFileSync('fragment.html')

rehype()
.data('settings', {fragment: true})
.use(slug)
.use(link)
.process(doc, function(err, file) {
if (err) throw err
.use(rehypeSlug)
.use(rehypeAutolinkHeadings)
.process(buf)
.then((file) => {
console.log(String(file))
})
```
Expand All @@ -62,7 +65,10 @@ Now, running `node example` yields:

## API

### `rehype().use(link[, options])`
This package exports no identifiers.
The default export is `rehypeAutolinkHeadings`.

### `unified().use(rehypeAutolinkHeadings[, options])`

Add links to headings (h1-h6) with an `id`.

Expand Down

0 comments on commit f684436

Please sign in to comment.