如何让 emmet 将具有值的属性添加到 div 标记中?

How do I get emmet to add an attribute with a value into a div tag?

我正在使用 emmet.vim 插件。

如何编写 emmet shorthand 来说明没有值的属性?

这是我写的:

div.contain-to-grid.sticky>nav.topbar[data-topbar]

这就是我想要发生的事情:

<div class="contain-to-grid sticky">
  <nav class="topbar" data-topbar></nav>
</div>

这是我得到的:

<div class="contain-to-grid sticky">
  <nav class="topbar" data-topbar=""></nav>
</div>

而不是创建没有值的属性:

data-topbar

它正在创建一个空值:

data-topbar=""

有解决办法吗?如果没有,那么我可以忍受它。很高兴知道它是否可以完成。谢谢

Emmet-vim 的行为已更改为与 documentation 的预期一致:

You don’t have to specify attribute values: td[colspan title] will produce <td colspan="" title=""> with tabstops inside each empty attribute (if your editor supports them).

所以没有。您可以在此处关注此请求:Attributes without values not being expanded.

可能的粗略解决方法是将 autoload/emmet/lang/html.vim 中的第 220 行从

更改为
let current.attr[atts] = ''

let current.attr[atts] = function('emmet#types#true')

我只是复制@Alexander Nied 的评论以使其更引人注目,上面写着

While the documentation does not seem to reflect it, this closed issue indicates that support for boolean attributes has been added to Emmet with the syntax of div[my-attribute.], which should expand to This worked for me in Sublime Text

这对我也有用,在 Intellij idea