Skip to content

Commit ed76a34

Browse files
author
F-loat
committed
add highlight prop, update README.md
1 parent ea93bf9 commit ed76a34

File tree

3 files changed

+30
-21
lines changed

3 files changed

+30
-21
lines changed

README.md

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Vue-SimpleMDE
2-
> Markdown Editor component for Vue.js. Support both vue1.0 & vue2.0.
2+
> Markdown Editor component for Vue.js. Support only vue2.x.
33
44
[![NPM](https://nodei.co/npm/vue-simplemde.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/vue-simplemde/)
55

@@ -39,6 +39,15 @@ export default {
3939
}
4040
```
4141

42+
## Props
43+
| 属性 | 类型 | 默认值 | 描述 |
44+
| ----| ----- | ----- | ---- |
45+
| value | String || 初始值,可使用v-model绑定 |
46+
| previewClass | String || 自定义预览样式类 |
47+
| autoinit | Boolean | true | 是否自动初始化 |
48+
| highlight | Boolean | false | 是否开启高亮 |
49+
| configs | Object | {} | [SimpleMDE的配置项](#configuration) |
50+
4251
## Examples
4352

4453
> 不再支持Vue1.x,可自行修改使用
@@ -90,10 +99,7 @@ export default {
9099
content: '',
91100
configs: {
92101
status: false, // 禁用底部状态栏
93-
initialValue: 'hellow', // 设置初始值
94-
renderingConfig: {
95-
codeSyntaxHighlighting: true // 开启代码高亮
96-
}
102+
spellChecker: false // 禁用拼写检查
97103
}
98104
}
99105
},
@@ -131,7 +137,7 @@ export default {
131137
}
132138
}
133139
}
134-
<script>
140+
</script>
135141
```
136142

137143
## Markdown style
@@ -157,8 +163,11 @@ $ npm install --save github-markdown-css
157163
```
158164

159165
## Highlight
160-
> 代码高亮除需开启配置外,还要自行引入css文件
161166
``` vue
167+
<template>
168+
<markdown-editor :highlight="true"></markdown-editor>
169+
</template>
170+
162171
<style>
163172
@import '~simplemde/dist/simplemde.min.css';
164173
@import '~highlight.js/styles/atom-one-dark.css';
@@ -176,24 +185,21 @@ $ npm install --save simplemde-theme-base
176185

177186
### use
178187
``` vue
179-
<template>
180-
<markdown-editor :custom-theme="true"></markdown-editor>
181-
</template>
182-
183188
<style>
184189
@import '~simplemde-theme-base/dist/simplemde-theme-base.min.css';
185190
/* 无需引入simplemde.min.css */
186191
</style>
187192
```
188193

189194
## Configuration
195+
> SimpleMDE的配置
190196
191197
* [中文](doc/configuration_zh.md)
192198
* [English](doc/configuration_en.md)
193199

194200
## Dependencies
195201

196-
* [SimpleMDE](https://github.com/NextStepWebs/simplemde-markdown-editor)
202+
* [SimpleMDE](https://github.com/sparksuite/simplemde-markdown-editor)
197203
* [Highlight.js](https://github.com/isagalaev/highlight.js)
198204

199205
## Licence

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-simplemde",
3-
"version": "0.4.0",
3+
"version": "0.4.2",
44
"description": "SimpleMDE - Markdown Editor component for Vue.js",
55
"main": "index.js",
66
"scripts": {

src/markdown-editor.vue

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default {
1818
return true;
1919
},
2020
},
21-
customTheme: {
21+
highlight: {
2222
type: Boolean,
2323
default() {
2424
return false;
@@ -42,21 +42,24 @@ export default {
4242
},
4343
methods: {
4444
initialize() {
45-
const configs = {};
45+
const configs = {
46+
element: this.$el.firstElementChild,
47+
initialValue: this.value,
48+
renderingConfig: {},
49+
};
4650
Object.assign(configs, this.configs);
47-
configs.element = configs.element || this.$el.firstElementChild;
48-
configs.initialValue = configs.initialValue || this.value;
49-
50-
// 实例化编辑器
51-
this.simplemde = new SimpleMDE(configs);
5251
5352
// 判断是否开启代码高亮
54-
if (configs.renderingConfig && configs.renderingConfig.codeSyntaxHighlighting) {
53+
if (this.highlight) {
54+
configs.renderingConfig.codeSyntaxHighlighting = true;
5555
import('highlight.js').then((hljs) => {
5656
window.hljs = hljs;
5757
});
5858
}
5959
60+
// 实例化编辑器
61+
this.simplemde = new SimpleMDE(configs);
62+
6063
// 添加自定义 previewClass
6164
const className = this.previewClass || '';
6265
this.addPreviewClass(className);

0 commit comments

Comments
 (0)