@@ -13,8 +13,12 @@ Extension for [`mdast-util-from-markdown`][from-markdown] and/or
13
13
When parsing (` from-markdown ` ), must be combined with
14
14
[ ` micromark-extension-frontmatter ` ] [ extension ] .
15
15
16
- You probably shouldn’t use this package directly, but instead use
17
- [ ` remark-frontmatter ` ] [ remark-frontmatter ] with ** [ remark] [ ] ** .
16
+ ## When to use this
17
+
18
+ Use this if you’re dealing with the AST manually.
19
+ It’s probably nicer to use [ ` remark-frontmatter ` ] [ remark-frontmatter ] with
20
+ ** [ remark] [ ] ** , which includes this but provides a nicer interface and
21
+ makes it easier to combine with hundreds of plugins.
18
22
19
23
## Install
20
24
@@ -39,25 +43,25 @@ title = "New Website"
39
43
# Other markdown
40
44
```
41
45
42
- And our script , ` example.js ` , looks as follows:
46
+ And our module , ` example.js ` , looks as follows:
43
47
44
48
``` js
45
- var fs = require ( ' fs' )
46
- var fromMarkdown = require ( ' mdast-util-from-markdown' )
47
- var toMarkdown = require ( ' mdast-util-to-markdown' )
48
- var syntax = require ( ' micromark-extension-frontmatter' )
49
- var frontmatter = require ( ' mdast-util-frontmatter' )
49
+ import fs from ' node: fs'
50
+ import { fromMarkdown } from ' mdast-util-from-markdown'
51
+ import { toMarkdown } from ' mdast-util-to-markdown'
52
+ import { frontmatter } from ' micromark-extension-frontmatter'
53
+ import { frontmatterFromMarkdown , frontmatterToMarkdown } from ' mdast-util-frontmatter'
50
54
51
- var doc = fs .readFileSync (' example.md' )
55
+ const doc = fs .readFileSync (' example.md' )
52
56
53
- var tree = fromMarkdown (doc, {
54
- extensions: [syntax ([' yaml' , ' toml' ])],
55
- mdastExtensions: [frontmatter . fromMarkdown ([' yaml' , ' toml' ])]
57
+ const tree = fromMarkdown (doc, {
58
+ extensions: [frontmatter ([' yaml' , ' toml' ])],
59
+ mdastExtensions: [frontmatterFromMarkdown ([' yaml' , ' toml' ])]
56
60
})
57
61
58
62
console .log (tree)
59
63
60
- var out = toMarkdown (tree, {extensions: [frontmatter . toMarkdown ([' yaml' , ' toml' ])]})
64
+ const out = toMarkdown (tree, {extensions: [frontmatterToMarkdown ([' yaml' , ' toml' ])]})
61
65
62
66
console .log (out)
63
67
```
0 commit comments