@@ -20,6 +20,9 @@ Use version 3 for remark 13+.
20
20
21
21
## Install
22
22
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
+
23
26
[ npm] [ ] :
24
27
25
28
``` sh
@@ -38,29 +41,30 @@ title = "New Website"
38
41
# Other markdown
39
42
```
40
43
41
- And our script , ` example.js ` , looks as follows:
44
+ And our module , ` example.js ` , looks as follows:
42
45
43
46
``` 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' )
50
55
51
56
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))
58
66
console .log (String (file))
59
67
})
60
-
61
- function logger () {
62
- return console .dir
63
- }
64
68
```
65
69
66
70
Now, running ` node example ` yields:
@@ -90,7 +94,10 @@ title = "New Website"
90
94
91
95
## API
92
96
93
- ### ` remark().use(frontmatter[, options]) `
97
+ This package exports no identifiers.
98
+ The default export is ` remarkFrontmatter ` .
99
+
100
+ ### ` unified().use(remarkFrontmatter[, options]) `
94
101
95
102
Configures remark so that it can parse and serialize frontmatter (YAML, TOML,
96
103
and more).
0 commit comments