2.0.0 • Published 3 years ago
remark-mdx-code-meta v2.0.0
remark-mdx-code-meta
A remark MDX plugin for using markdown code block metadata
Installation
npm install remark-mdx-code-metaUsage
This plugin interprets markdown code block metadata as JSX props.
For example, given a file named example.mdx with the following contents:
```js copy filename="awesome.js" onUsage={props.beAwesome} {...props}
console.log('Everything is awesome!');
```The following script:
import { readFileSync } from 'fs';
import { remarkMdxCodeMeta } from 'remark-mdx-code-meta';
import { compileSync } from 'xdm';
const { contents } = compileSync(readFileSync('example.mdx'), {
jsx: true,
remarkPlugins: [remarkMdxCodeMeta],
});
console.log(contents);Roughly yields:
export default function MDXContent(props) {
return (
<pre copy filename="awesome.js" onUsage={props.beAwesome} {...props}>
<code className="language-js">{"console.log('Everything is awesome!');\n"}</code>
</pre>
);
}Of course the <pre /> element doesn’t support those custom props. Use custom components to
give the props meaning.