Skip to content

Commit 400bfe0

Browse files
committed
Add better docs
1 parent e9fa43c commit 400bfe0

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

readme.md

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@ Extension for [`mdast-util-from-markdown`][from-markdown] and/or
1313
When parsing (`from-markdown`), must be combined with
1414
[`micromark-extension-frontmatter`][extension].
1515

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.
1822

1923
## Install
2024

@@ -39,25 +43,25 @@ title = "New Website"
3943
# Other markdown
4044
```
4145

42-
And our script, `example.js`, looks as follows:
46+
And our module, `example.js`, looks as follows:
4347

4448
```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'
5054

51-
var doc = fs.readFileSync('example.md')
55+
const doc = fs.readFileSync('example.md')
5256

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'])]
5660
})
5761

5862
console.log(tree)
5963

60-
var out = toMarkdown(tree, {extensions: [frontmatter.toMarkdown(['yaml', 'toml'])]})
64+
const out = toMarkdown(tree, {extensions: [frontmatterToMarkdown(['yaml', 'toml'])]})
6165

6266
console.log(out)
6367
```

0 commit comments

Comments
 (0)