Skip to content

Commit 4621e05

Browse files
author
绯玉
committed
修改参数使支持table
0 parents  commit 4621e05

14 files changed

+5680
-0
lines changed

.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/react-markdown-it-loader.iml

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

+116
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+204
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
---
2+
imports:
3+
import {Loading} from 'react-gm';
4+
---
5+
# markdown-it-react-loader
6+
7+
用Markdown提供一份直观的React文档,有可运行的示例,有示例源代码,有示例的说明。
8+
9+
这样用户看起来直观,编写者写起来也直观,维护成本低。
10+
11+
经过几番尝试,结合 React 的特点。写了一套处理 Markdown 文件的 webpack loader,可以将 Markdown 转成 React 文件。
12+
13+
本md对应生成的文档是[readme.md](https://liyatang.github.io/markdown-it-react-loader/)
14+
15+
---
16+
17+
## Install
18+
19+
`npm install markdown-it-react-loader`
20+
21+
在 webpack 中加入 loader
22+
23+
```js
24+
{
25+
test: /\.md$/,
26+
loader: 'babel!markdown-it-react-loader'
27+
}
28+
```
29+
30+
随后把md文件当成一个react component去使用即可。比如本工程中的demo
31+
32+
```js
33+
import ReadMe from '../README.md';
34+
```
35+
36+
如需运行demo `npm install; npm start;` 打开 http://localhost:5000
37+
38+
### options
39+
40+
- `className` 默认'doc',页面容器的class
41+
42+
```js
43+
// webpack.config.js
44+
module.export = {
45+
//...省略
46+
markdownItReact: function () {
47+
return {
48+
className: 'doc' // 默认也是doc
49+
};
50+
}
51+
};
52+
```
53+
54+
具体见`webpack.config.js`
55+
56+
### 样式
57+
58+
提供样式文件`index.css`,可直接引入或自定义。
59+
60+
---
61+
62+
## 语法介绍
63+
64+
正常的Markdown语法不影响。有几个需要注意的地方:
65+
66+
### 使用示例
67+
68+
#### 纯渲染
69+
70+
::: demo 这是描述这是**描述**,点三角可展开代码。也可以不提供
71+
```jsx
72+
<button onClick={() => alert('dou la mi fa sou')}>click me</button>
73+
```
74+
:::
75+
76+
```
77+
::: demo 这是描述这是**描述**,点三角可展开代码
78+
```jsx
79+
<button>adfasdfa</button>
80+
```
81+
:::
82+
```
83+
84+
注意:渲染到页面的代码语言必须写`jsx`,因为loaders会把语言为`jsx`放入render的jsx内
85+
86+
#### 引入其他库
87+
88+
::: demo [react-gm](https://github.com/gmfe/react-gm)的Loading组件
89+
```jsx
90+
<Loading/>
91+
```
92+
:::
93+
94+
在md开头添加引入库
95+
96+
```js
97+
---
98+
imports:
99+
import {Loading} from 'react-gm';
100+
---
101+
```
102+
103+
然后
104+
```
105+
::: demo [react-gm](https://github.com/gmfe/react-gm)的日历组件
106+
```jsx
107+
<Loading/>
108+
```
109+
:::
110+
```
111+
112+
#### 更丰富的交互
113+
114+
比如需要 state,需要handleXXX
115+
116+
::: demo 更丰富的交互写在js内,这种场景更多
117+
```js
118+
class Test extends React.Component {
119+
constructor(props) {
120+
super(props);
121+
this.state = {
122+
value: 'hello'
123+
};
124+
}
125+
handleChange(e){
126+
this.setState({value: e.target.value});
127+
}
128+
render(){
129+
return (<input value={this.state.value} onChange={::this.handleChange} />)
130+
}
131+
}
132+
```
133+
```jsx
134+
<Test/>
135+
```
136+
:::
137+
138+
```
139+
::: demo 更丰富的交互写在js内,这种场景更多
140+
```js
141+
class Test extends React.Component {
142+
constructor(props) {
143+
super(props);
144+
this.state = {
145+
value: 'hello'
146+
};
147+
}
148+
handleChange(e){
149+
this.setState({value: e.target.value});
150+
}
151+
render(){
152+
return (<input value={this.state.value} onChange={::this.handleChange} />)
153+
}
154+
}
155+
```
156+
```jsx
157+
<Test/>
158+
```
159+
:::
160+
```
161+
162+
163+
### 花括号 (表达式)
164+
165+
有意思的是可以用花括号写表达式,比如我要显示
166+
167+
当前url是:`{location.href}`
168+
169+
userAgent是:`{navigator.userAgent}`
170+
171+
因而你要用花括号时`{'{}'}`需要写成`{'{\'{}\'}'}`
172+
173+
### 代码里面的花括号
174+
175+
`{'{ }'}`会自动转,无需关注
176+
177+
```jsx
178+
<div>{location.href}</div>
179+
```
180+
181+
---
182+
183+
## 参考
184+
185+
- [markdown-it](https://github.com/markdown-it/markdown-it)
186+
- [element](https://github.com/ElemeFE/element)
187+
- [react-markdown-loader](https://github.com/javiercf/react-markdown-loader)
188+
189+
## 其他
190+
191+
### anchor
192+
193+
github page是不支持browserHistory的,一般路由用hash处理。而锚点也是用hash,会冲突。
194+
所以只能自己处理。 监听锚的点击,阻止默认事件,然后用你自己的规则处理吧。
195+
196+
我是这样做的 https://github.com/gmfe/react-gm/blob/master/demo/index.js
197+
198+
### react模块
199+
200+
默认已经`import React from 'react';`
201+
202+
203+
204+

0 commit comments

Comments
 (0)