Svelte for VS代码:如何避免格式化属性中的双引号?

发布于 2025-02-05 05:17:38 字数 539 浏览 3 评论 0原文

我正在使用 vs code for vs code 扩展。

当前格式化时,它删除了HTML属性中的双引号

示例:

export let altText;
<img src="test.jpg" alt="{altText}" />

格式化时,它将其变成类似的东西

export let altText;
<img src="test.jpg" alt={altText} />

,这是完全有效的。但是,我想将报价保留在属性中。有什么办法做到这一点吗?

I'm using Svelte for VS Code extension.

Currently when formatting it removes double quotes in HTML attributes

Example:

export let altText;
<img src="test.jpg" alt="{altText}" />

when formatted it turns it into something like this

export let altText;
<img src="test.jpg" alt={altText} />

Which is totally valid. However, I want to keep the quotes in the attributes. Is there any way to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

仙气飘飘 2025-02-12 05:17:39

扩展名使用 Prettier (这很烦人)。您可以通过添加.prettierrc并设置 quoteprops选项 “ preserve”

编辑:对此进行了测试,目前是 not 尊重的。


Svelte的插件具有设置a 严格模式 ,要么通过VS设置:

{
    "svelte.plugin.svelte.format.config.svelteStrictMode": true
}

或通过.prettierrc(如果存在文件,则忽略VS设置):

{
    "svelteStrictMode": true
}

将保留引号,但也会杀死速记,因此

<script lang="ts">
    export let alt: string;
</script>

<img src="test.jpg" {alt} />

<script lang="ts">
    export let alt: string;
</script>

<img src="test.jpg" alt="{alt}" />

The extension uses Prettier (which is annoying). You might be able to configure this by adding a .prettierrc and setting the quoteProps option to "preserve".

Edit: Tested this, and it is currently not respected.


The plugin for Svelte has an option for setting a strict mode, either via the VS settings:

{
    "svelte.plugin.svelte.format.config.svelteStrictMode": true
}

Or via the .prettierrc (the VS setting is ignored if the file exists):

{
    "svelteStrictMode": true
}

This will preserve the quotes but also kill shorthands, so e.g. from

<script lang="ts">
    export let alt: string;
</script>

<img src="test.jpg" {alt} />

To

<script lang="ts">
    export let alt: string;
</script>

<img src="test.jpg" alt="{alt}" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文