-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrsimplemde.vue
executable file
·74 lines (69 loc) · 1.43 KB
/
rsimplemde.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<template>
<div class="markdown-editor">
<textarea></textarea>
</div>
</template>
<script>
var SimpleMDE = require("./simplemde.js")
export default {
name:"markdown-editor",
data(){
return {
}
},
props:{
value:String,
previewClass:String,
configs:{
type:Object,
default(){
return {}
}
}
},
mounted(){
this.initialize();
},
methods:{
initialize() {
const configs = {
element: this.$el.firstElementChild,
initialValue: this.value,
renderingConfig: {},
};
Object.assign(configs, this.configs);
// 判断是否开启代码高亮
if (this.highlight) {
configs.renderingConfig.codeSyntaxHighlighting = true;
}
// 设置是否渲染输入的html
//marked.setOptions({ sanitize: this.sanitize });
// 实例化编辑器
this.simplemde = new SimpleMDE(configs);
// 添加自定义 previewClass
const className = this.previewClass || '';
// 绑定事件
this.bindingEvents();
},
bindingEvents() {
this.simplemde.codemirror.on('change', () => {
this.$emit('input', this.simplemde.value());
});
},
},
destroyed() {
this.simplemde = null;
},
watch: {
value(val) {
if (val === this.simplemde.value()) return;
this.simplemde.value(val);
},
},
}
</script>
<style>
.markdown-editor {
font-size:16px;
}
</style>