π Populate code blocks from files
The plain remark version of gatsby-remark-import-code
.
yarn add -D remark-code-import
See Using plugins in the official documentation.
It can also be used in various of libraries using remark
: MDX, Gatsby gatsby-plugin-mdx
, Storybook docs, etc.
Just use the /gatsby
endpoint. It's possible through to-gatsby-remark-plugin
.
{
resolve: 'remark-code-import/gatsby',
options: {}
}
Transform:
```js file=./say-hi.js
```
into:
```js file=./say-hi.js
console.log('Hello remark-code-import!');
```
The file path is relative to the markdown file path.
You may also specify specific lines or ranges:
```js file=./say-hi.js#L3
```
```js file=./say-hi.js#L3-L6
```
```js file=./say-hi.js#L3-
```
```js file=./say-hi.js#-L6
```
async
: By default, this plugin usesreadFileSync
to read the contents of the files. Set this totrue
if you want to usereadFile
for non-blocking IO.
After installing dependencies with yarn
, the tests can be run with: yarn test
Kai Hao MIT