ZIm/extensions/vue/languages/vue/injections.scm
Marshall Bowers 6f24c1da79
vue: Support lang attribute for style tag injections (#19419)
This PR adds support for injecting languages into `<style>` tags using
`<style lang="...">` in Vue.

Extracted from https://github.com/zed-industries/zed/pull/18052.

Release Notes:

- N/A

Co-authored-by: Albert Marashi <albert@lumina.earth>
2024-10-18 11:36:30 -04:00

81 lines
1.7 KiB
Scheme

; <script>
((script_element
(start_tag) @_no_lang
(raw_text) @content)
(#not-match? @_no_lang "lang=")
(#set! "language" "javascript"))
; <script lang="js">
((script_element
(start_tag
(attribute
(attribute_name) @_lang
(quoted_attribute_value
(attribute_value) @_js)))
(raw_text) @content)
(#eq? @_lang "lang")
(#eq? @_js "js")
(#set! "language" "javascript"))
; <script lang="ts">
((script_element
(start_tag
(attribute
(attribute_name) @_lang
(quoted_attribute_value
(attribute_value) @_ts)))
(raw_text) @content)
(#eq? @_lang "lang")
(#eq? @_ts "ts")
(#set! "language" "typescript"))
; <script lang="tsx">
; <script lang="jsx">
; Zed built-in tsx, we mark it as tsx ^:)
(script_element
(start_tag
(attribute
(attribute_name) @_attr
(quoted_attribute_value
(attribute_value) @language)))
(#eq? @_attr "lang")
(#any-of? @language "tsx" "jsx")
(raw_text) @content)
; {{ }}
((interpolation
(raw_text) @content)
(#set! "language" "typescript"))
; v-
(directive_attribute
(quoted_attribute_value
(attribute_value) @content
(#set! "language" "typescript")))
; Vue <style lang="css"> injections
(style_element
(start_tag
(attribute
(attribute_name) @_attr_name
(#eq? @_attr_name "lang")
(quoted_attribute_value
(attribute_value) @language
)
)
)
(raw_text) @content
)
; Vue <style> css injections (no lang attribute)
(style_element
(start_tag
(attribute
(attribute_name) @_attr_name
)*
)
(raw_text) @content
(#not-any-of? @_attr_name "lang")
(#set! language "css")
)