diff --git a/package-lock.json b/package-lock.json index 067b9fe..1d7ace2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,7 +6,7 @@ "packages": { "": { "name": "fachwerk", - "version": "0.0.9", + "version": "0.0.11", "license": "MIT", "dependencies": { "d3-shape": "^3.1.0", diff --git a/src/internal/Editor.vue b/src/internal/Editor.vue index 76a601b..38841a4 100644 --- a/src/internal/Editor.vue +++ b/src/internal/Editor.vue @@ -3,6 +3,10 @@ import { ref, computed, onMounted } from "vue"; import MarkdownIt from "markdown-it"; import IconOpen from "~icons/tabler/layers-subtract"; +import IconPrettier from "~icons/tabler/macro"; +import { format } from "prettier"; +import parserHtml from "prettier/esm/parser-html.mjs"; +import parserMarkdown from "prettier/esm/parser-markdown.mjs"; import Compiler from "./Compiler.vue"; import { atou, utoa } from "../internal/encoding"; @@ -26,10 +30,28 @@ const md = new MarkdownIt({ linkify: true, html: true, breaks: true }).use( editorPlugin ); +const prettierHtml = (str: string, printWidth = 20) => { + return format(str, { + parser: "html", + plugins: [parserHtml], + printWidth, + }); +}; + +const prettierMarkdown = (str: string, printWidth = 40) => { + return format(str, { + parser: "markdown", + plugins: [parserMarkdown], + printWidth, + }); +}; + const outputContent = computed(() => { - const r = md.render(content.value); - return r; + return prettierHtml(md.render(content.value)); }); + +const onPrettier = () => (content.value = prettierHtml(content.value)); + const editor = ref(null); onMounted(() => { @@ -64,13 +86,19 @@ const onError = (e: CompilerError[] | null) => (error.value = e); v-model="content" class="w-full whitespace-pre bg-gray-800 p-5 font-mono text-sm leading-6 text-gray-100 outline-none md:p-6 lg:p-8" /> - - - +
+ + + + +