0.3.5 • Published 7 years ago

to-mdxast v0.3.5

Weekly downloads
10
License
MIT
Repository
github
Last release
7 years ago

to-mdxast

Transforms MDAST to MDXAST.

Installation

npm i -S mdast-util-to-mdxast

Usage

const unified = require('unified')
const remark = require('remark-parse')
const inspect = require('unist-util-inspect')
const toMAST = require('to-mdast')
const { getImports } = require('to-mdast')

const MDX = `
import { Foo } from 'bar'

# Hello, world!

<Foo />
`

// Import scope must be passed to the remark
// parser for block parsing
const options = {
  blocks: getImports(MDX).blocks
}

const tree = unified()
  .use(remark, options)
  .use(toMDXAST, options)
  .parse(MDX)

const mdxast = toMDXAST(options)(tree)

console.log(inspect(mdxast))

Output

root[3] (1:1-7:1, 0-53)
├─ import: "import { Foo } from 'bar'" (2:1-2:26, 1-26)
├─ heading[1] (4:1-4:16, 28-43) [depth=1]
│  └─ text: "Hello, world!" (4:3-4:16, 30-43)
└─ jsx: "<Foo />" (6:1-6:8, 45-52)
0.3.5

7 years ago

0.3.3

7 years ago

0.3.2

7 years ago

0.3.0

7 years ago

0.1.0

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago