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

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

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

问题

I'm here to provide the translation you requested:

  1. 我正在尝试使用VS Code中的Emmet创建一些具有特定属性的元素。
  2. 以下Emmet正常工作,并产生良好的输出。
  3. ```css
  4. input[type="password"]

扩展为

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

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

  1. input[required]

扩展为

  1. <input required="required"></input>

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

  1. <input required></input>

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

  1. <details>
  2. <summary>英文:</summary>
  3. I&#39;m trying to create some elements using Emmet in VS Code, where those elements have specific properties.
  4. The following Emmet works correctly, and produces good output.
  5. ```css
  6. input[type=&quot;password&quot;]

Expands to

  1. &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.

  1. input[required]

Expands to

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

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

  1. &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文件

  1. "emmet.syntaxProfiles": {
  2. "html": {
  3. "compactBooleanAttributes": true
  4. }
  5. }

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

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

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

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:

  1. &quot;emmet.syntaxProfiles&quot;: {
  2. &quot;html&quot;: {
  3. &quot;compactBooleanAttributes&quot;: true
  4. }
  5. }

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:

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

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:

确定