robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Christian Clasonvim-patch:d3ff129ce8c67b8e582f1c

master
6.0 KiB190 linesraw
1" Vim syntax file.
2" Language:    Astro
3" Author:      Wuelner Martínez <wuelner.martinez@outlook.com>
4" Maintainer:  Wuelner Martínez <wuelner.martinez@outlook.com>
5" URL:         https://github.com/wuelnerdotexe/vim-astro
6" Last Change: 2022 Aug 22
7" Based On:    Evan Lecklider's vim-svelte
8" Changes:     See https://github.com/evanleck/vim-svelte
9" Credits:     See vim-svelte on github
10
11" Quit when a (custom) syntax file was already loaded.
12if !exists('main_syntax')
13  if exists('b:current_syntax')
14    finish
15  endif
16  let main_syntax = 'astro'
17elseif exists('b:current_syntax') && b:current_syntax == 'astro'
18  finish
19endif
20
21" Astro syntax variables are initialized.
22let g:astro_typescript = get(g:, 'astro_typescript', 'disable')
23let g:astro_stylus = get(g:, 'astro_stylus', 'disable')
24
25let s:cpoptions_save = &cpoptions
26set cpoptions&vim
27
28" Embedded HTML syntax.
29runtime! syntax/html.vim
30
31" htmlTagName: expand HTML tag names to include mixed case and periods.
32syntax match htmlTagName contained "\<[a-zA-Z\.]*\>"
33
34" astroDirectives: add Astro Directives to HTML arguments.
35syntax match astroDirectives contained '\<[a-z]\+:[a-z|]*\>' containedin=htmlTag
36
37unlet b:current_syntax
38
39if g:astro_typescript == 'enable'
40  " Embedded TypeScript syntax.
41  syntax include @astroJavaScript syntax/typescript.vim
42
43  " javaScriptExpression: a javascript expression is used as an arg value.
44  syntax clear javaScriptExpression
45  syntax region javaScriptExpression
46        \ contained start=+&{+
47        \ keepend end=+};+
48        \ contains=@astroJavaScript,@htmlPreproc
49
50  " javaScript: add TypeScript support to HTML script tag.
51  syntax clear javaScript
52  syntax region javaScript
53        \ start=+<script\_[^>]*>+
54        \ keepend
55        \ end=+</script\_[^>]*>+me=s-1
56        \ contains=htmlScriptTag,@astroJavaScript,@htmlPreproc,htmlCssStyleComment
57else
58  " Embedded JavaScript syntax.
59  syntax include @astroJavaScript syntax/javascript.vim
60endif
61
62" astroFence: detect the Astro fence.
63syntax match astroFence contained +^---$+
64
65" astrojavaScript: add TypeScript support to Astro code fence.
66syntax region astroJavaScript
67      \ start=+^---$+
68      \ keepend
69      \ end=+^---$+
70      \ contains=htmlTag,@astroJavaScript,@htmlPreproc,htmlCssStyleComment,htmlEndTag,astroFence
71      \ fold
72
73unlet b:current_syntax
74
75if g:astro_typescript == 'enable'
76  " Embedded TypeScript React (TSX) syntax.
77  syntax include @astroJavaScriptReact syntax/typescriptreact.vim
78else
79  " Embedded JavaScript React (JSX) syntax.
80  syntax include @astroJavaScriptReact syntax/javascriptreact.vim
81endif
82
83" astroJavaScriptExpression: add {JSX or TSX} support to Astro expresions.
84execute 'syntax region astroJavaScriptExpression start=+{+ keepend end=+}+ ' .
85      \ 'contains=@astroJavaScriptReact, @htmlPreproc containedin=' . join([
86      \   'htmlArg', 'htmlBold', 'htmlBoldItalic', 'htmlBoldItalicUnderline',
87      \   'htmlBoldUnderline', 'htmlBoldUnderlineItalic', 'htmlH1', 'htmlH2',
88      \   'htmlH3', 'htmlH4', 'htmlH5', 'htmlH6', 'htmlHead', 'htmlItalic',
89      \   'htmlItalicBold', 'htmlItalicBoldUnderline', 'htmlItalicUnderline',
90      \   'htmlItalicUnderlineBold', 'htmlLeadingSpace', 'htmlLink',
91      \   'htmlStrike', 'htmlString', 'htmlTag', 'htmlTitle', 'htmlUnderline',
92      \   'htmlUnderlineBold', 'htmlUnderlineBoldItalic',
93      \   'htmlUnderlineItalic', 'htmlUnderlineItalicBold', 'htmlValue'
94      \ ], ',')
95
96" cssStyle: add CSS style tags support in TypeScript React.
97syntax region cssStyle
98      \ start=+<style\_[^>]*>+
99      \ keepend
100      \ end=+</style\_[^>]*>+me=s-1
101      \ contains=htmlTag,@htmlCss,htmlCssStyleComment,@htmlPreproc,htmlEndTag
102      \ containedin=@astroJavaScriptReact
103
104unlet b:current_syntax
105
106" Embedded SCSS syntax.
107syntax include @astroScss syntax/scss.vim
108
109" cssStyle: add SCSS style tags support in Astro.
110syntax region scssStyle
111      \ start=/<style\>\_[^>]*\(lang\)=\("\|''\)[^\2]*scss[^\2]*\2\_[^>]*>/
112      \ keepend
113      \ end=+</style>+me=s-1
114      \ contains=@astroScss,astroSurroundingTag
115      \ fold
116
117unlet b:current_syntax
118
119" Embedded SASS syntax.
120syntax include @astroSass syntax/sass.vim
121
122" cssStyle: add SASS style tags support in Astro.
123syntax region sassStyle
124      \ start=/<style\>\_[^>]*\(lang\)=\("\|''\)[^\2]*sass[^\2]*\2\_[^>]*>/
125      \ keepend
126      \ end=+</style>+me=s-1
127      \ contains=@astroSass,astroSurroundingTag
128      \ fold
129
130unlet b:current_syntax
131
132" Embedded LESS syntax.
133syntax include @astroLess syntax/less.vim
134
135" cssStyle: add LESS style tags support in Astro.
136syntax region lessStyle
137      \ start=/<style\>\_[^>]*\(lang\)=\("\|''\)[^\2]*less[^\2]*\2\_[^>]*>/
138      \ keepend
139      \ end=+</style>+me=s-1
140      \ contains=@astroLess,astroSurroundingTag
141      \ fold
142
143unlet b:current_syntax
144
145" Embedded Stylus syntax.
146" NOTE: Vim does not provide stylus support by default, but you can install
147"       this plugin to support it: https://github.com/wavded/vim-stylus
148if g:astro_stylus == 'enable'
149  try
150    " Embedded Stylus syntax.
151    syntax include @astroStylus syntax/stylus.vim
152
153    " stylusStyle: add Stylus style tags support in Astro.
154    syntax region stylusStyle
155          \ start=/<style\>\_[^>]*\(lang\)=\("\|''\)[^\2]*stylus[^\2]*\2\_[^>]*>/
156          \ keepend
157          \ end=+</style>+me=s-1
158          \ contains=@astroStylus,astroSurroundingTag
159          \ fold
160
161    unlet b:current_syntax
162  catch
163    echomsg "you need install a external plugin for support stylus in .astro files"
164  endtry
165endif
166
167" astroSurroundingTag: add surround HTML tag to script and style.
168syntax region astroSurroundingTag
169      \ start=+<\(script\|style\)+
170      \ end=+>+
171      \ contains=htmlTagError,htmlTagN,htmlArg,htmlValue,htmlEvent,htmlString
172      \ contained
173      \ fold
174
175" Define the default highlighting.
176" Only used when an item doesn't have highlighting yet.
177highlight default link astroDirectives Special
178highlight default link astroFence Comment
179
180let b:current_syntax = 'astro'
181if main_syntax == 'astro'
182  unlet main_syntax
183endif
184
185" Sync from start because of the wacky nesting.
186syntax sync fromstart
187
188let &cpoptions = s:cpoptions_save
189unlet s:cpoptions_save
190" vim: ts=8