微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

查询选择没有给定属性的 html 标签

如何解决查询选择没有给定属性的 html 标签

给定以下树:

style_element [0,0] - [1,8]
  start_tag [0,0] - [0,19]
    tag_name [0,1] - [0,6]
    attribute [0,7] - [0,18]
      attribute_name [0,11]
      quoted_attribute_value [0,12] - [0,18]
        attribute_value [0,13] - [0,17]
  raw_text [1,0]
  end_tag [1,8]
    ERROR [1,2] - [1,7]
    tag_name [1,7]
style_element [3,0] - [4,8]
  start_tag [3,0] - [3,19]
    tag_name [3,1] - [3,6]
    attribute [3,7] - [3,13]
      attribute_name [3,13]
    attribute [3,14] - [3,18]
      attribute_name [3,18]
  raw_text [4,0]
  end_tag [4,8]
    tag_name [4,2] - [4,7]
style_element [6,0] - [7,8]
  start_tag [6,0] - [6,12]
    tag_name [6,1] - [6,6]
    attribute [6,7] - [6,11]
      attribute_name [6,11]
  raw_text [7,0]
  end_tag [7,8]
    tag_name [7,2] - [7,7]
style_element [9,0] - [10,8]
  start_tag [9,0] - [9,7]
    tag_name [9,1] - [9,6]
  raw_text [10,0]
  end_tag [10,8]
    tag_name [10,2] - [10,7]
style_element [12,0] - [13,8]
  start_tag [12,0] - [12,14]
    tag_name [12,1] - [12,6]
    attribute [12,7] - [12,13]
      attribute_name [12,13]
  raw_text [13,0]
  end_tag [13,8]
    tag_name [13,2] - [13,7]
style_element [15,0] - [16,8]
  start_tag [15,0] - [15,14]
    tag_name [15,1] - [15,6]
    attribute [15,7] - [15,13]
      attribute_name [15,13]
  raw_text [16,0]
  end_tag [16,8]
    tag_name [16,2] - [16,7]

这是通过解析这段代码产生的:

<style lang="scss" scoped>
</style>

<style scoped lang>
</style>

<style lang>
</style>

<style>
</style>

<style scoped>
</style>

<style module>
</style>

当样式标签缺少属性 lang 时,我想将其突出显示为 css。以上包含一些需要考虑的情况。只有最后三个应该突出显示为 css

到目前为止,我想出了这个查询

((style_element (start_tag (attribute (attribute_name) @_attr (#not-eq? @_attr "lang"))) (raw_text) @css))

但不幸的是,这也突出显示<style lang="scss" scoped>,因为它包含与 lang 不匹配的属性。此标签包含 lang 属性,因此不应匹配。

如何修改上述查询,使其仅匹配没有 lang 属性的样式标签

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。