feat(HTML Editor): option to minify output

Fix #1605
This commit is contained in:
ShareVB committed 2025-07-06 12:56:08 +02:00
1 parent a78201bffd
commit 5e3648e141
4 files changed
+35 -6

No files matched your search

+3
View File
@@ -303,6 +303,7 @@ declare module '@vue/runtime-core' {
'NanoMemo.content': typeof import('./src/tools/nano-memo/nano-memo.content.md')['default']
NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default']
NCode: typeof import('naive-ui')['NCode']
NColorPicker: typeof import('naive-ui')['NColorPicker']
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
NDivider: typeof import('naive-ui')['NDivider']
NEllipsis: typeof import('naive-ui')['NEllipsis']
@@ -318,6 +319,8 @@ declare module '@vue/runtime-core' {
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
NMenu: typeof import('naive-ui')['NMenu']
NScrollbar: typeof import('naive-ui')['NScrollbar']
NSpace: typeof import('naive-ui')['NSpace']
NSwitch: typeof import('naive-ui')['NSwitch']
NTable: typeof import('naive-ui')['NTable']
NumberInput: typeof import('./src/tools/pomodoro-timer/app/components/NumberInput.vue')['default']
NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default']
+1
View File
@@ -146,6 +146,7 @@
"heic-convert": "^2.1.0",
"hex-array": "^1.0.0",
"highlight.js": "^11.11.1",
"htmlfy": "^0.8.1",
"hyparquet": "^1.9.0",
"hyparquet-compressors": "^1.0.0",
"iarna-toml-esm": "^3.0.5",
+10 -3
View File
@@ -335,6 +335,9 @@ dependencies:
highlight.js:
specifier: ^11.11.1
version: 11.11.1
htmlfy:
specifier: ^0.8.1
version: 0.8.1
hyparquet:
specifier: ^1.9.0
version: 1.9.0
@@ -7026,7 +7029,7 @@ packages:
dependencies:
'@unhead/dom': 0.5.1
'@unhead/schema': 0.5.1
'@vueuse/shared': 13.3.0(vue@3.3.4)
'@vueuse/shared': 13.5.0(vue@3.3.4)
unhead: 0.5.1
vue: 3.3.4
dev: false
@@ -7698,8 +7701,8 @@ packages:
- vue
dev: false
/@vueuse/shared@13.3.0(vue@3.3.4):
resolution: {integrity: sha512-L1QKsF0Eg9tiZSFXTgodYnu0Rsa2P0En2LuLrIs/jgrkyiDuJSsPZK+tx+wU0mMsYHUYEjNsuE41uqqkuR8VhA==}
/@vueuse/shared@13.5.0(vue@3.3.4):
resolution: {integrity: sha512-K7GrQIxJ/ANtucxIXbQlUHdB0TPA8c+q5i+zbrjxuhJCnJ9GtBg75sBSnvmLSxHKPg2Yo8w62PWksl9kwH0Q8g==}
peerDependencies:
vue: ^3.5.0
dependencies:
@@ -11999,6 +12002,10 @@ packages:
resolution: {integrity: sha512-bEqo66MRXsUGxWHV5IP0PUiAWwoEjba4VCzg0LjFJBpchPaTfyfCKTG6bc5F8ucKec3q5y6qOdGyYTSBEvhCrg==}
dev: false
/htmlfy@0.8.1:
resolution: {integrity: sha512-xWROBw9+MEGwxpotll0h672KCaLrKKiCYzsyN8ZgL9cQbVumFnyvsk2JqiB9ELAV1GLj1GG/jxZUjV9OZZi/yQ==}
dev: false
/htmlparser2@8.0.2:
resolution: {integrity: sha512-GYdjWKDkbRLkZ5geuHs5NY1puJ+PXwP7+fHPRz06Eirsb9ugf6d8kkXav6ADhcODhFFPMIXyxkxSuMf3D6NCFA==}
dependencies:
@@ -1,16 +1,34 @@
<script setup lang="ts">
import { format } from 'prettier';
import htmlParser from 'prettier/plugins/html';
import { minify, prettify } from 'htmlfy';
import { useStorage } from '@vueuse/core';
import Editor from './editor/editor.vue';
import TextareaCopyable from '@/components/TextareaCopyable.vue';
import { useQueryParamOrStorage } from '@/composable/queryParams';
const html = useStorage('html-wysiwyg-editor--html', '<h1>Hey!</h1><p>Welcome to this html wysiwyg editor</p>');
const formattedHtml = asyncComputed(() => format(html.value, { parser: 'html', plugins: [htmlParser] }), '');
const minifyOutput = useQueryParamOrStorage({ name: 'minify', storageName: 'html-wysiwyg-editor--min', defaultValue: false });
const formattedHtml = computed(() => {
try {
if (minifyOutput.value) {
return minify(html.value);
}
return prettify(html.value);
}
catch {
return html.value;
}
});
</script>
<template>
<Editor v-model:html="html" />
<NSpace justify="center">
<n-form-item label="Minify:" label-placement="left" mt-2>
<NSwitch v-model:value="minifyOutput" />
</n-form-item>
</NSpace>
<TextareaCopyable :value="formattedHtml" language="html" />
</template>