Skip to content

Commit e0edd7e

Browse files
committed
fix: set prettier parser mode
1 parent d238aa2 commit e0edd7e

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/codemirror/CodeMirror.vue

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { ref, onMounted, watchEffect, inject } from 'vue'
77
import prettier from 'prettier/standalone'
88
import parserBabel from 'prettier/parser-babel'
99
import parserHtml from 'prettier/parser-html'
10+
import parserPostcss from 'prettier/parser-postcss'
1011
import { debounce } from '../utils'
1112
import CodeMirror from './codemirror'
1213
@@ -63,11 +64,16 @@ onMounted(() => {
6364
})
6465
6566
editor.on('blur', () => {
67+
const parser = props.mode === 'vue' ? 'html'
68+
: props.mode === 'htmlmixed' ? 'html'
69+
: props.mode === 'javascript' ? 'babel'
70+
: props.mode === 'css' ? 'postcss'
71+
: props.mode
6672
emit('change', prettier.format(
6773
editor.getValue(),
6874
{
69-
parser: 'html',
70-
plugins: [parserBabel, parserHtml],
75+
parser,
76+
plugins: [parserBabel, parserHtml, parserPostcss],
7177
semi: false,
7278
singleQuote: true,
7379
arrowParens: 'avoid',

0 commit comments

Comments
 (0)