如何使用Emmet缩写为元素添加一个无值的属性?

huangapple go评论69阅读模式
英文:

How can I use Emmet abbreviations to add a value-less property to an element?

问题

I'm here to provide the translation you requested:

我正在尝试使用VS Code中的Emmet创建一些具有特定属性的元素。

以下Emmet正常工作,并产生良好的输出。

```css
input[type="password"]

扩展为

<input type="password"></input>

然而,如果我尝试为元素提供一个没有值的属性,它会添加一个字符串,有时是不正确的。

input[required]

扩展为

<input required="required"></input>

如何让Emmet只生成没有值的属性,像这样?

<input required></input>

我已经查阅了缩写的文档,但这个特定情况似乎没有列出。有人有什么想法吗?



<details>
<summary>英文:</summary>

I&#39;m trying to create some elements using Emmet in VS Code, where those elements have specific properties.

The following Emmet works correctly, and produces good output.

```css
input[type=&quot;password&quot;]

Expands to

&lt;input type=&quot;password&quot;&gt;&lt;/input&gt;

However, if I try to give a value-less property to the element, it adds a string to it, which is sometimes incorrect.

input[required]

Expands to

&lt;input required=&quot;required&quot;&gt;&lt;/input&gt;

How can I make Emmet only produce the property with no value, like this?

&lt;input required&gt;&lt;/input&gt;

I've had a look through the documentation for abbreviations and this particular case doesn't seem to be listed there. Does anyone have any ideas?

答案1

得分: 1

从谷歌搜索“github vscode issues emmet attribute without value”,我找到了Emmet: compact boolean attributes won't work #32282,在那里我了解到了emmet.syntaxProfiles设置。

尝试将以下内容放入您的settings.json文件

"emmet.syntaxProfiles": {
    "html": {
        "compactBooleanAttributes": true
    }
}

另请参阅https://docs.emmet.io/customization/syntax-profiles/和https://docs.emmet.io/customization/preferences/。

出于某种原因,还有另一种方法可以做到:

"emmet.preferences": {
    "profile.allowCompactBoolean": true
},
英文:

From googling "github vscode issues emmet attribute without value", I found Emmet: compact boolean attributes won't work
#32282
, where I learned of the emmet.syntaxProfiles setting.

Try putting the following in your settings.json file:

&quot;emmet.syntaxProfiles&quot;: {
    &quot;html&quot;: {
        &quot;compactBooleanAttributes&quot;: true
    }
}

See also https://docs.emmet.io/customization/syntax-profiles/ and https://docs.emmet.io/customization/preferences/.

For some reason there's another way to do it as well:

&quot;emmet.preferences&quot;: {
    &quot;profile.allowCompactBoolean&quot;: true
},

huangapple
  • 本文由 发表于 2023年4月19日 18:28:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76053426.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定