File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ export default {
12
12
name: ' markdown-editor' ,
13
13
props: {
14
14
value: String ,
15
+ previewClass: String ,
15
16
configs: {
16
17
type: Object
17
18
}
@@ -25,14 +26,44 @@ export default {
25
26
configs .element = configs .element || this .$el .firstChild
26
27
configs .initialValue = configs .initialValue || this .value
27
28
29
+ // 开启代码高亮
30
+ if (configs .renderingConfig .codeSyntaxHighlighting ) {
31
+ require .ensure ([], () => {
32
+ var theme = configs .renderingConfig .highlightingTheme || ' default'
33
+ window .hljs = require (' highlight.js' )
34
+ require (' highlight.js/styles/' + theme + ' .css' )
35
+ }, ' highlight' )
36
+ }
37
+
28
38
// 实例化编辑器
29
39
this .simplemde = new SimpleMDE (configs)
30
40
41
+ // 添加自定义 previewClass
42
+ this .addPreviewClass ()
43
+
31
44
// 绑定输入事件
32
45
this .simplemde .codemirror .on (' change' , () => {
33
46
this .$emit (' input' , this .simplemde .value ())
34
47
})
48
+ },
49
+ addPreviewClass () {
50
+ var _class = this .configs .renderingConfig .codeSyntaxHighlighting ? this .previewClass + ' hljs' : this .previewClass
51
+ var wrapper = this .simplemde .codemirror .getWrapperElement ()
52
+ var preview = document .createElement (' div' )
53
+ this .$el .lastChild .className += ' ' + _class
54
+ preview .className = ' editor-preview ' + _class
55
+ wrapper .appendChild (preview)
35
56
}
36
57
}
37
58
}
38
59
</script >
60
+
61
+ <style >
62
+ .markdown-editor .hljs {
63
+ display : none
64
+ }
65
+
66
+ .markdown-editor .editor-preview-active , .markdown-editor .editor-preview-active-side {
67
+ display : block ;
68
+ }
69
+ </style >
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " vue-simplemde" ,
3
- "version" : " 0.2.0 " ,
3
+ "version" : " 0.2.4 " ,
4
4
"description" : " SimpleMDE - Markdown Editor component for Vue.js" ,
5
5
"main" : " index.js" ,
6
6
"scripts" : {
17
17
},
18
18
"license" : " MIT" ,
19
19
"dependencies" : {
20
+ "highlight.js" : " ^9.9.0" ,
20
21
"simplemde" : " ^1.11.2"
21
22
},
22
23
"repository" : {
You can’t perform that action at this time.
0 commit comments