Skip to content

Commit 72f7b11

Browse files
committed
feat: add prettier
1 parent 5af8e42 commit 72f7b11

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@
4141
"@microsoft/api-extractor": "^7.19.2",
4242
"@types/codemirror": "^5.60.2",
4343
"@types/node": "^16.11.12",
44+
"@types/prettier": "^2.7.2",
4445
"@vitejs/plugin-vue": "^3.0.0",
4546
"codemirror": "^5.62.3",
4647
"emmet": "^2.4.4",
4748
"fflate": "^0.7.3",
4849
"hash-sum": "^2.0.0",
50+
"prettier": "^2.8.8",
4951
"rimraf": "^3.0.2",
5052
"sass": "^1.55.0",
5153
"sucrase": "^3.20.1",

pnpm-lock.yaml

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/codemirror/CodeMirror.vue

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
<script setup lang="ts">
66
import { ref, onMounted, watchEffect, inject } from 'vue'
7+
import prettier from 'prettier/standalone'
8+
import parserBabel from 'prettier/parser-babel'
9+
import parserHtml from 'prettier/parser-html'
710
import { debounce } from '../utils'
811
import CodeMirror from './codemirror'
912
@@ -59,6 +62,13 @@ onMounted(() => {
5962
emit('change', editor.getValue())
6063
})
6164
65+
editor.on('blur', () => {
66+
emit('change', prettier.format(
67+
editor.getValue(),
68+
{ parser: 'html', plugins: [parserBabel, parserHtml] }
69+
))
70+
})
71+
6272
watchEffect(() => {
6373
const cur = editor.getValue()
6474
if (props.value !== cur) {

0 commit comments

Comments
 (0)