File tree Expand file tree Collapse file tree 1 file changed +20
-14
lines changed Expand file tree Collapse file tree 1 file changed +20
-14
lines changed Original file line number Diff line number Diff line change @@ -65,21 +65,27 @@ onMounted(() => {
65
65
})
66
66
67
67
editor .on (' blur' , () => {
68
- const parser = props .mode === ' vue' ? ' html'
69
- : props .mode === ' htmlmixed' ? ' html'
70
- : props .mode === ' javascript' ? ' babel'
71
- : props .mode === ' css' ? ' postcss'
68
+ const parser = props .extension === ' vue' ? ' html'
69
+ : props .extension === ' html' ? ' html'
70
+ : props .extension === ' css' ? ' css'
71
+ : props .extension === ' js' ? ' babel'
72
+ : props .extension === ' ts' ? ' babel'
72
73
: props .extension || props .mode
73
- emit (' change' , prettier .format (
74
- editor .getValue (),
75
- {
76
- parser ,
77
- plugins: [parserBabel , parserHtml , parserPostcss ],
78
- semi: false ,
79
- singleQuote: true ,
80
- arrowParens: ' avoid' ,
81
- }
82
- ))
74
+
75
+ const options = {
76
+ parser ,
77
+ plugins: [parserBabel , parserHtml , parserPostcss ],
78
+ semi: false ,
79
+ singleQuote: true ,
80
+ arrowParens: ' avoid' as const ,
81
+ }
82
+
83
+ let code = editor .getValue ()
84
+ try {
85
+ code = prettier .format (code , options )
86
+ } catch (err ) {}
87
+
88
+ emit (' change' , code )
83
89
})
84
90
85
91
watchEffect (() => {
You can’t perform that action at this time.
0 commit comments