Convert markdown file to react component using markdown-it
- import / export
- Write react component
- Use
{expression}
npm i @codpoe/react-markdown-loader -D
module.exports = {
module: {
rules: [
{
test: /\.md$/,
loader: [
'babel-loader',
'@codpoe/react-markdown-loader'
]
}
]
}
};
import Doc from './doc.md';
export default () => {
return (
<div>
<Doc />
</div>
);
}
import:
:::import
```js
import { add } from './add.js';
```
:::
export:
:::export
```js
export const meta = {
author: 'xxx',
time: '2018-06-23'
};
```
:::
:::demo
```js
render() {
return (
<div>{add(1, 2)}</div>
)
}
```
:::
Note: The
demo
container will show the source code and its result on the page. If you just want to create a react component, please usecode
container instead. By the way, you can write any code you want incode
container.
:::code
```js
const foo = () => { console.log('😘'); }
```
:::
Then you can call foo
, usually in demo components.
6 + 6 = {6 + 6}
-
className
string
. The class name of converted react component -
plugins
Array
. markdown-it plugins