0.0.2 • Published 5 years ago

remark-import-code v0.0.2

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

remark-import-code

Install

$ npm install remark-import-code

Use

The idea is to transform md/mdx like this:

```js file=./hello-world.js
```

Into:

```js
function helloWorld() {
  return "hello world";
}
```

But this plugin gets you half way there. You need to use the remark-import-code/loader somewhere (maybe in webpack). I use it like this with gatsby:

import { MDXRenderer } from "gatsby-plugin-mdx";
import replaceCode from "remark-import-code/loader";

// ...
<MDXRenderer>{replaceCode(post.body)}</MDXRenderer>;
// ...

This shouldn't be necessary, but I don't know how to get the file path when the plugin runs. Ideally it should work like remark-embed-images.