Skip to content

Commit

Permalink
Add better docs
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jun 18, 2021
1 parent e9fa43c commit 400bfe0
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ Extension for [`mdast-util-from-markdown`][from-markdown] and/or
When parsing (`from-markdown`), must be combined with
[`micromark-extension-frontmatter`][extension].

You probably shouldn’t use this package directly, but instead use
[`remark-frontmatter`][remark-frontmatter] with **[remark][]**.
## When to use this

Use this if you’re dealing with the AST manually.
It’s probably nicer to use [`remark-frontmatter`][remark-frontmatter] with
**[remark][]**, which includes this but provides a nicer interface and
makes it easier to combine with hundreds of plugins.

## Install

Expand All @@ -39,25 +43,25 @@ title = "New Website"
# Other markdown
```

And our script, `example.js`, looks as follows:
And our module, `example.js`, looks as follows:

```js
var fs = require('fs')
var fromMarkdown = require('mdast-util-from-markdown')
var toMarkdown = require('mdast-util-to-markdown')
var syntax = require('micromark-extension-frontmatter')
var frontmatter = require('mdast-util-frontmatter')
import fs from 'node:fs'
import {fromMarkdown} from 'mdast-util-from-markdown'
import {toMarkdown} from 'mdast-util-to-markdown'
import {frontmatter} from 'micromark-extension-frontmatter'
import {frontmatterFromMarkdown, frontmatterToMarkdown} from 'mdast-util-frontmatter'

var doc = fs.readFileSync('example.md')
const doc = fs.readFileSync('example.md')

var tree = fromMarkdown(doc, {
extensions: [syntax(['yaml', 'toml'])],
mdastExtensions: [frontmatter.fromMarkdown(['yaml', 'toml'])]
const tree = fromMarkdown(doc, {
extensions: [frontmatter(['yaml', 'toml'])],
mdastExtensions: [frontmatterFromMarkdown(['yaml', 'toml'])]
})

console.log(tree)

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

console.log(out)
```
Expand Down

0 comments on commit 400bfe0

Please sign in to comment.