g-plane / markup_fmt

Configurable HTML, Vue, Svelte, Astro, Angular, Jinja, Twig, Nunjucks and Vento formatter with dprint integration.
https://dprint.dev/plugins/markup_fmt/
MIT License
91 stars 4 forks source link

HTML escaping in Vue cannot be formatted. #20

Closed magic-akari closed 4 months ago

magic-akari commented 4 months ago

dprint.json

{
  "excludes": [
    "**/node_modules"
  ],
  "plugins": [
    "https://plugins.dprint.dev/typescript-0.90.4.wasm",
    "https://plugins.dprint.dev/g-plane/markup_fmt-v0.7.0.wasm"
  ]
}

App.vue

<script setup>
import { ref } from "vue";
const content = ref("");
</script>

<template>
  <button @click="content +=      &#x27;{&quot;hello&quot;: &quot;I\&#x27;m a button!&quot;}&#x27;">click {{ content }}</button>
</template>

Expected result

formatted without issue

Actual result

Error formatting /Users/akari/Developer/my-vue-app/src/App.vue. Message: [markup_fmt] failed to format code with external formatter: `<>{content +=      &#x27;{&quot;hello&quot;: &quot;I\&#x27;m a button!&quot;}&#x27;}</>`:
Expected ',', got '+=' at file:///expr.tsx:1:12

  <>{content +=      &#x27;{&quot;hello&quot;: &quot;I\&#x27;m a button!&quot;}&#x27;}</>
             ~~
Had 1 error formatting.

Replication Steps

Replication Steps

  1. Download this compressed package and extract it, then enter the directory.
  2. Run pnpm i and pnpm dev or pnpm build to ensure the code can run correctly.
  3. Run pnpm fmt to observe the formatting situation.
g-plane commented 4 months ago

Fun fact: Prettier can't format this. (playground)