Skip to content

Commit 63a0448

Browse files
committed
fix: set prettier parser from file extension
1 parent 5004917 commit 63a0448

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/codemirror/CodeMirror.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface Props {
1515
mode?: string
1616
value?: string
1717
readonly?: boolean
18+
extension?: string
1819
}
1920
2021
const props = withDefaults(defineProps<Props>(), {
@@ -68,7 +69,7 @@ onMounted(() => {
6869
: props.mode === 'htmlmixed' ? 'html'
6970
: props.mode === 'javascript' ? 'babel'
7071
: props.mode === 'css' ? 'postcss'
71-
: props.mode
72+
: props.extension || props.mode
7273
emit('change', prettier.format(
7374
editor.getValue(),
7475
{

src/editor/Editor.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ const activeMode = computed(() => {
1919
: filename.endsWith('.css') ? 'css'
2020
: 'javascript'
2121
})
22+
23+
const extension = computed(() => {
24+
const { filename } = store.state.activeFile
25+
return filename.split('.').pop()
26+
})
2227
</script>
2328

2429
<template>
@@ -28,6 +33,7 @@ const activeMode = computed(() => {
2833
@change="onChange"
2934
:value="store.state.activeFile.code"
3035
:mode="activeMode"
36+
:extension="extension"
3137
/>
3238
<Message :err="store.state.errors[0]" />
3339
</div>

0 commit comments

Comments
 (0)