Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jul 30, 2021
1 parent 2d9f521 commit a94fa25
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 36 deletions.
16 changes: 9 additions & 7 deletions doc/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,15 @@ npm install rehype
`index.js` contains:

```js
var rehype = require('rehype')
var report = require('vfile-reporter')

rehype().process('<title>Hi</title><h2>Hello world!', function(err, file) {
console.log(String(file))
console.log(report(err || file))
})
import {reporter} from 'vfile-reporter'
import {rehype} from 'rehype'

rehype()
.process('<title>Hi</title><h2>Hello world!')
.then((file) => {
console.log(String(file))
console.log(reporter(file))
})
```

`node index.js` yields:
Expand Down
33 changes: 21 additions & 12 deletions packages/rehype-parse/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ Support this effort and give back by sponsoring on [OpenCollective][collective]!

## 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 @@ -90,19 +93,22 @@ Say we have the following file, `example.html`, with a few errors:
…and our script, `example.js`, looks as follows:

```js
var vfile = require('to-vfile')
var report = require('vfile-reporter')
var unified = require('unified')
var parse = require('rehype-parse')
var rehype2remark = require('rehype-remark')
var stringify = require('remark-stringify')
import {readSync} from 'to-vfile'
import {reporter} from 'vfile-reporter'
import {unified} from 'unified'
import rehypeParse from 'rehype-parse'
import rehypeRemark from 'rehype-remark'
import remarkStringify from 'remark-stringify'

const file = readSync('example.html')

unified()
.use(parse, {emitParseErrors: true, duplicateAttribute: false})
.use(rehype2remark)
.use(stringify)
.process(vfile.readSync('example.html'), function(err, file) {
console.error(report(err || file))
.use(rehypeParse, {emitParseErrors: true, duplicateAttribute: false})
.use(rehypeRemark)
.use(remarkStringify)
.process(file)
.then((file) => {
console.error(reporter(file))
console.log(String(file))
})
```
Expand All @@ -123,7 +129,10 @@ example.html

## API

### `processor.use(parse[, options])`
This package exports no identifiers.
The default export is `rehypeParse`.

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

Configure `processor` to parse HTML and create a [**hast**][hast] syntax tree.

Expand Down
26 changes: 16 additions & 10 deletions packages/rehype-stringify/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ Support this effort and give back by sponsoring on [OpenCollective][collective]!

## 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 @@ -75,26 +78,29 @@ npm install rehype-stringify
## Use

```js
var unified = require('unified')
var createStream = require('unified-stream')
var parse = require('rehype-parse')
var stringify = require('rehype-stringify')

var processor = unified()
.use(parse)
.use(stringify, {
import {unified} from 'unified'
import {stream} from 'unified-stream'
import rehypeParse from 'rehype-parse'
import rehypeStringify from 'rehype-stringify'

const processor = unified()
.use(rehypeParse)
.use(rehypeStringify, {
quoteSmart: true,
closeSelfClosing: true,
omitOptionalTags: true,
entities: {useShortestReferences: true}
})

process.stdin.pipe(createStream(processor)).pipe(process.stdout)
process.stdin.pipe(stream(processor)).pipe(process.stdout)
```

## API

### `processor.use(stringify[, options])`
This package exports no identifiers.
The default export is `rehypeStringify`.

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

Configure `processor` to serialize [**hast**][hast] syntax trees to HTML.

Expand Down
19 changes: 12 additions & 7 deletions packages/rehype/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ Support this effort and give back by sponsoring on [OpenCollective][collective]!

## 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 @@ -83,13 +86,15 @@ npm install rehype
## Use

```js
var rehype = require('rehype')
var report = require('vfile-reporter')

rehype().process('<title>Hi</title><h2>Hello world!', function(err, file) {
console.log(report(err || file))
console.log(String(file))
})
import {reporter} from 'vfile-reporter'
import {rehype} from 'rehype'

rehype()
.process('<title>Hi</title><h2>Hello world!')
.then((file) => {
console.log(reporter(file))
console.log(String(file))
})
```

Yields:
Expand Down

0 comments on commit a94fa25

Please sign in to comment.