Skip to content

Commit 7d1341b

Browse files
committed
Update docs
1 parent 2e5e5b1 commit 7d1341b

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

readme.md

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ Use version 3 for remark 13+.
2020

2121
## Install
2222

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

2528
```sh
@@ -38,29 +41,30 @@ title = "New Website"
3841
# Other markdown
3942
```
4043

41-
And our script, `example.js`, looks as follows:
44+
And our module, `example.js`, looks as follows:
4245

4346
```js
44-
var vfile = require('to-vfile')
45-
var report = require('vfile-reporter')
46-
var unified = require('unified')
47-
var parse = require('remark-parse')
48-
var stringify = require('remark-stringify')
49-
var frontmatter = require('remark-frontmatter')
47+
import {readSync} from 'to-vfile'
48+
import {reporter} from 'vfile-reporter'
49+
import {unified} from 'unified'
50+
import remarkParse from 'remark-parse'
51+
import remarkFrontmatter from 'remark-frontmatter'
52+
import remarkStringify from 'remark-stringify'
53+
54+
const file = readSync('example.md')
5055

5156
unified()
52-
.use(parse)
53-
.use(stringify)
54-
.use(frontmatter, ['yaml', 'toml'])
55-
.use(logger)
56-
.process(vfile.readSync('example.md'), function (err, file) {
57-
console.error(report(err || file))
57+
.use(remarkParse)
58+
.use(remarkStringify)
59+
.use(remarkFrontmatter, ['yaml', 'toml'])
60+
.use(() => (tree) => {
61+
console.dir(tree)
62+
})
63+
.process(file)
64+
.then((file) => {
65+
console.error(reporter(file))
5866
console.log(String(file))
5967
})
60-
61-
function logger() {
62-
return console.dir
63-
}
6468
```
6569

6670
Now, running `node example` yields:
@@ -90,7 +94,10 @@ title = "New Website"
9094

9195
## API
9296

93-
### `remark().use(frontmatter[, options])`
97+
This package exports no identifiers.
98+
The default export is `remarkFrontmatter`.
99+
100+
### `unified().use(remarkFrontmatter[, options])`
94101

95102
Configures remark so that it can parse and serialize frontmatter (YAML, TOML,
96103
and more).

0 commit comments

Comments
 (0)