https://github.com/chiaweilee/umi-plugin-md
๐ Markdown(*.md) component plugin for umi.
https://github.com/chiaweilee/umi-plugin-md
component markdown umi umi-plugin
Last synced: 8 months ago
JSON representation
๐ Markdown(*.md) component plugin for umi.
- Host: GitHub
- URL: https://github.com/chiaweilee/umi-plugin-md
- Owner: chiaweilee
- License: mit
- Created: 2019-06-30T06:55:24.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-09-10T15:15:33.000Z (about 4 years ago)
- Last Synced: 2023-03-21T11:48:20.484Z (over 2 years ago)
- Topics: component, markdown, umi, umi-plugin
- Language: TypeScript
- Homepage: https://chiaweilee.github.io/umi-plugin-md/
- Size: 752 KB
- Stars: 16
- Watchers: 3
- Forks: 2
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# [umi-plugin-md](#) ยท [](https://github.com/chiaweilee/umi-plugin-md/blob/master/LICENSE) [](https://www.npmjs.com/package/umi-plugin-md) [](https://npmcharts.com/compare/umi-plugin-md?minimal=true) [](#)
Markdown(\*.md) component plugin for umi.
*Create your website with umi and markdown only. Convenient and powerful for blog, documentation site and GitBook.*
* **Convert markdown into component:** loaded by `markdown-it` and translate into React component.
* **Auto routes create:** auto create markdown routes from dir.
* **Auto anchor:** auto create anchor for `h1`, `h2` and `h3`.
* **XSS protect:** by [xss](https://www.npmjs.com/package/xss).
* **Support:** umi@2.x only

## Installation
```
npm install umi-plugin-md
```
## Demo
https://chiaweilee.github.io/umi-plugin-md/
## Usage
```js
// .umirc.js
export default {
plugins: ['umi-plugin-md'],
};
```
## Options
option | intro | type | default
-|-|-|-
anchor | Auto Anchor `^0.2.0` | string[], falsy to disable | ['h1', 'h2', 'h3'] |
wrapper | HTMLElementTagName | string | section |
className | React className | string | |
style | React style | object | |
html | markdown-it option | boolean | true |
xhtmlOut | markdown-it option | boolean | true |
breaks | markdown-it option | boolean | true |
linkify | markdown-it option | boolean | true |
typographer | markdown-it option | boolean | true |
highlight | markdown-it option | function | highlight.js |
render | wrapper render | (rawHtml: string) => string; | see `src/render.ts` |
**tips**: `route of markdown will have higher priority, so route might be covered.`
e.g, `index.md` will cover `index.jsx`.
## Anchor

#### Get anchor id?
```js
import { slug } from 'umi-plugin-md';
var text = $('h2').text();
var id = slug(text);
```
Or copy `umi-plugin-md/lib/helpers/slug.js` to your repo.
#### Anchor Stylize
```css
// global.css
@import "~umi-plugin-md/anchor.css";
```
Or, write yourself.
tips: we do not support `scroll to anchor on 'componentDidMount'` this moment.
## Markdown Stylize
[github-markdown-css](https://www.npmjs.com/package/github-markdown-css)
```css
// global.css
@import "~github-markdown-css/github-markdown.css";
@import "~highlight.js/styles/github.css";
```
```js
// .umirc.js
export default {
plugins: [['umi-plugin-md', { className: 'markdown-body' }]],
};
```
## Priority
`index.md` have higher priority than `index.jsx`.