codekingpro/portable-devtools
115k
1" Vim syntax file.2" Language: Astro3" Author: Wuelner Martínez <wuelner.martinez@outlook.com>4" Maintainer: Wuelner Martínez <wuelner.martinez@outlook.com>5" URL: https://github.com/wuelnerdotexe/vim-astro6" Last Change: 2022 Aug 227" Based On: Evan Lecklider's vim-svelte8" Changes: See https://github.com/evanleck/vim-svelte9" Credits: See vim-svelte on github10 11" Quit when a (custom) syntax file was already loaded.12if !exists('main_syntax')13 if exists('b:current_syntax')14 finish15 endif16 let main_syntax = 'astro'17elseif exists('b:current_syntax') && b:current_syntax == 'astro'18 finish19endif20 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 = &cpoptions26set cpoptions&vim27 28" Embedded HTML syntax.29runtime! syntax/html.vim30 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=htmlTag36 37unlet b:current_syntax38 39if g:astro_typescript == 'enable'40 " Embedded TypeScript syntax.41 syntax include @astroJavaScript syntax/typescript.vim42 43 " javaScriptExpression: a javascript expression is used as an arg value.44 syntax clear javaScriptExpression45 syntax region javaScriptExpression46 \ contained start=+&{+47 \ keepend end=+};+48 \ contains=@astroJavaScript,@htmlPreproc49 50 " javaScript: add TypeScript support to HTML script tag.51 syntax clear javaScript52 syntax region javaScript53 \ start=+<script\_[^>]*>+54 \ keepend55 \ end=+</script\_[^>]*>+me=s-156 \ contains=htmlScriptTag,@astroJavaScript,@htmlPreproc,htmlCssStyleComment57else58 " Embedded JavaScript syntax.59 syntax include @astroJavaScript syntax/javascript.vim60endif61 62" astroFence: detect the Astro fence.63syntax match astroFence contained +^---$+64 65" astrojavaScript: add TypeScript support to Astro code fence.66syntax region astroJavaScript67 \ start=+^---$+68 \ keepend69 \ end=+^---$+70 \ contains=htmlTag,@astroJavaScript,@htmlPreproc,htmlCssStyleComment,htmlEndTag,astroFence71 \ fold72 73unlet b:current_syntax74 75if g:astro_typescript == 'enable'76 " Embedded TypeScript React (TSX) syntax.77 syntax include @astroJavaScriptReact syntax/typescriptreact.vim78else79 " Embedded JavaScript React (JSX) syntax.80 syntax include @astroJavaScriptReact syntax/javascriptreact.vim81endif82 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 cssStyle98 \ start=+<style\_[^>]*>+99 \ keepend100 \ end=+</style\_[^>]*>+me=s-1101 \ contains=htmlTag,@htmlCss,htmlCssStyleComment,@htmlPreproc,htmlEndTag102 \ containedin=@astroJavaScriptReact103 104unlet b:current_syntax105 106" Embedded SCSS syntax.107syntax include @astroScss syntax/scss.vim108 109" cssStyle: add SCSS style tags support in Astro.110syntax region scssStyle111 \ start=/<style\>\_[^>]*\(lang\)=\("\|''\)[^\2]*scss[^\2]*\2\_[^>]*>/112 \ keepend113 \ end=+</style>+me=s-1114 \ contains=@astroScss,astroSurroundingTag115 \ fold116 117unlet b:current_syntax118 119" Embedded SASS syntax.120syntax include @astroSass syntax/sass.vim121 122" cssStyle: add SASS style tags support in Astro.123syntax region sassStyle124 \ start=/<style\>\_[^>]*\(lang\)=\("\|''\)[^\2]*sass[^\2]*\2\_[^>]*>/125 \ keepend126 \ end=+</style>+me=s-1127 \ contains=@astroSass,astroSurroundingTag128 \ fold129 130unlet b:current_syntax131 132" Embedded LESS syntax.133syntax include @astroLess syntax/less.vim134 135" cssStyle: add LESS style tags support in Astro.136syntax region lessStyle137 \ start=/<style\>\_[^>]*\(lang\)=\("\|''\)[^\2]*less[^\2]*\2\_[^>]*>/138 \ keepend139 \ end=+</style>+me=s-1140 \ contains=@astroLess,astroSurroundingTag141 \ fold142 143unlet b:current_syntax144 145" Embedded Stylus syntax.146" NOTE: Vim does not provide stylus support by default, but you can install147" this plugin to support it: https://github.com/wavded/vim-stylus148if g:astro_stylus == 'enable'149 try150 " Embedded Stylus syntax.151 syntax include @astroStylus syntax/stylus.vim152 153 " stylusStyle: add Stylus style tags support in Astro.154 syntax region stylusStyle155 \ start=/<style\>\_[^>]*\(lang\)=\("\|''\)[^\2]*stylus[^\2]*\2\_[^>]*>/156 \ keepend157 \ end=+</style>+me=s-1158 \ contains=@astroStylus,astroSurroundingTag159 \ fold160 161 unlet b:current_syntax162 catch163 echomsg "you need install a external plugin for support stylus in .astro files"164 endtry165endif166 167" astroSurroundingTag: add surround HTML tag to script and style.168syntax region astroSurroundingTag169 \ start=+<\(script\|style\)+170 \ end=+>+171 \ contains=htmlTagError,htmlTagN,htmlArg,htmlValue,htmlEvent,htmlString172 \ contained173 \ fold174 175" Define the default highlighting.176" Only used when an item doesn't have highlighting yet.177highlight default link astroDirectives Special178highlight default link astroFence Comment179 180let b:current_syntax = 'astro'181if main_syntax == 'astro'182 unlet main_syntax183endif184 185" Sync from start because of the wacky nesting.186syntax sync fromstart187 188let &cpoptions = s:cpoptions_save189unlet s:cpoptions_save190" vim: ts=8191 