File tree 2 files changed +49
-7
lines changed
2 files changed +49
-7
lines changed Original file line number Diff line number Diff line change 1
1
<template >
2
2
<div id =" root" >
3
- <textarea v-model =" text" />
4
- <p v-html =" compiledMarkdown" />
3
+ <textarea
4
+ :value =" text"
5
+ @input =" updateText"
6
+ />
7
+ <div v-html =" compiledMarkdown" />
5
8
</div >
6
9
</template >
7
10
@@ -17,20 +20,57 @@ export default {
17
20
},
18
21
computed: {
19
22
compiledMarkdown () {
20
- return marked (this .text , { sanitize: true });
23
+ return marked (this .text );
24
+ },
25
+ },
26
+ methods: {
27
+ updateText (e ) {
28
+ this .text = e .target .value ;
29
+ this .handleEnter (e);
30
+ },
31
+ handleEnter (e ) {
32
+ if (e .inputType !== ' insertLineBreak' ) return ;
33
+
34
+ const splitText = e .target .value .split (' \n ' );
35
+ const lenLine = splitText .length ;
36
+ const prevLine = splitText[lenLine - 2 ];
37
+ const isOrderedList = prevLine .match (/ ^ \d * \. \s. * / );
38
+ const isUnorderedList = prevLine .match (/ ^ [\* |-] \s. * / );
39
+
40
+ let prefix = ' ' ;
41
+
42
+ if (isOrderedList) {
43
+ const num = prevLine .match (/ ^ \d * / );
44
+ prefix = ` ${ parseInt (num) + 1 } .\v ` ;
45
+ } else if (isUnorderedList) {
46
+ prefix = prevLine .slice (0 , 2 );
47
+ }
48
+
49
+ this .text += prefix;
21
50
},
22
51
},
23
52
};
24
53
</script >
25
54
26
55
<style lang="scss" scoped>
27
56
#root {
28
- display : grid ;
29
- grid-template-rows : 100vh ;
30
- grid-template-columns : 1fr 1fr ;
57
+ width : 100% ;
58
+ height : 100vh ;
59
+ display : flex ;
60
+
61
+ textarea {
62
+ width : 50% ;
63
+ height : 100% ;
64
+ padding : 10px ;
65
+ font-size : 1.5rem ;
66
+ }
31
67
32
- p {
68
+ div {
69
+ width : 50% ;
70
+ height : 100% ;
33
71
padding : 10px ;
72
+ font-size : 1.5rem ;
73
+ overflow-y : scroll ;
34
74
}
35
75
}
36
76
</style >
Original file line number Diff line number Diff line change 1
1
* {
2
2
margin : 0 ;
3
+ box-sizing : border-box;
4
+ font-family : 'Nunito' , sans-serif;
3
5
color : # C9D2D9 ;
4
6
background-color : # 161C22 ;
5
7
}
You can’t perform that action at this time.
0 commit comments