# md-react-loader

> Webpack loader for markdown loader in React.js

Latest version **0.1.6** (published 2020-02-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install md-react-loader
pnpm add md-react-loader
yarn add md-react-loader
bun add md-react-loader
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.6 |
| Published | 2020-02-19 |
| First published | 2020-01-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 12.1 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 3 |
| Author | zhengyuanbing |
| Maintainers | zhengyuanbing |
| Keywords | markdown, react, webpack, loader |

## Links

- npm: https://www.npmjs.com/package/md-react-loader
- Repository: https://github.com/cappuccino6/md-react-loader
- Homepage: https://github.com/cappuccino6/md-react-loader#readme
- Issues: https://github.com/cappuccino6/md-react-loader/issues
- npm.io page: https://npm.io/package/md-react-loader

## Dependencies (5)

- [ava](https://npm.io/package/ava.md) ^2.4.0
- [braces](https://npm.io/package/braces.md) ^2.3.1
- [standard](https://npm.io/package/standard.md) ^14.3.1
- [cross-env](https://npm.io/package/cross-env.md) ^6.0.3
- [commonmark](https://npm.io/package/commonmark.md) ^0.29.1

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.1.6 (latest) — 2020-02-19
- 0.1.5 — 2020-02-19
- 0.1.4 — 2020-02-14
- 0.1.3 — 2020-01-20
- 0.1.2 — 2020-01-20
- 0.1.1 — 2020-01-20
- 0.1.0 — 2020-01-20
- 0.0.37 — 2020-01-19
- 0.0.36 — 2020-01-19
- 0.0.35 — 2020-01-19
- 0.0.34 — 2020-01-19
- 0.0.33 — 2020-01-19
- 0.0.32 — 2020-01-19
- 0.0.31 — 2020-01-19
- 0.0.30 — 2020-01-19
- … 28 more at https://npm.io/package/md-react-loader/versions

## README

![license](https://img.shields.io/npm/l/md-react-loader)
![version](https://img.shields.io/npm/v/md-react-loader)
![downloads](https://img.shields.io/npm/dt/md-react-loader)

## This is a markdown file loader

### Why this?

This loader will help you directly import a markdown file as a common react component, is that amazing?

Previously when we want to load a markdown file, we may need to do some extra work to load the file, or babel will throw some error while you do these jobs.


### How to use?

While using this loader, you need to download it first

```
npm i md-react-loader
```

Secondly, write the config of your webpack module rule for md file

```js
{
  test: /\.(md)$/,
  use: [
    {
      loader: require.resolve('babel-loader'),
      options: {
        presets:[
          "@babel/preset-env",
          "@babel/preset-react"
        ]
      }
    },
    {
      loader: require.resolve('md-react-loader')
    }
  ]
}
```

if there if a warning: Unknown DOM property class. Did you mean className?

Im sorry for that, you need this lib:

```js
npm install --save-dev babel-plugin-react-html-attrs
```

and rewrite your babel loader options:

```js
{
  presets:[
    "@babel/preset-env",
    "@babel/preset-react"
  ],
  plugins: [
    "react-html-attrs"
  ]
}
```

At the end, you just need to import the file directly, then you will get a object like this

```js
{
  html: 'your html',
  Component: a react component
}
```

so you can whatever use the Component directly, or render html in your own way, and meantime you can add your own props to this component

```js
import Md from './MyTest.md'
const MyComponent = () => <Md.Component className="my_own_class" />
export default MyComponent

or

import Md from './MyTest.md'
const MyComponent = () => (
  <div
    dangerouslySetInnerHTML={{ __html: Md.html }}
  />
)
export default MyComponent
```

Besides, if your markdown file contains some code and you are going to highlight them, you just need to download prismjs on npm and import css file in this library

```js
import Md from './MyTest.md'
import 'prismjs'
import 'md-react-loader/lib/index.css'

const MyComponent = () => <Md.Component className="my_own_class" />
export default MyComponent
```

now you just did a good job!

---
_Source: https://npm.io/package/md-react-loader · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
