neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

astro.vim (6170B)


      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.
     12 if !exists('main_syntax')
     13  if exists('b:current_syntax')
     14    finish
     15  endif
     16  let main_syntax = 'astro'
     17 elseif exists('b:current_syntax') && b:current_syntax == 'astro'
     18  finish
     19 endif
     20 
     21 " Astro syntax variables are initialized.
     22 let g:astro_typescript = get(g:, 'astro_typescript', 'disable')
     23 let g:astro_stylus = get(g:, 'astro_stylus', 'disable')
     24 
     25 let s:cpoptions_save = &cpoptions
     26 set cpoptions&vim
     27 
     28 " Embedded HTML syntax.
     29 runtime! syntax/html.vim
     30 
     31 " htmlTagName: expand HTML tag names to include mixed case and periods.
     32 syntax match htmlTagName contained "\<[a-zA-Z\.]*\>"
     33 
     34 " astroDirectives: add Astro Directives to HTML arguments.
     35 syntax match astroDirectives contained '\<[a-z]\+:[a-z|]*\>' containedin=htmlTag
     36 
     37 unlet b:current_syntax
     38 
     39 if 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
     57 else
     58  " Embedded JavaScript syntax.
     59  syntax include @astroJavaScript syntax/javascript.vim
     60 endif
     61 
     62 " astroFence: detect the Astro fence.
     63 syntax match astroFence contained +^---$+
     64 
     65 " astrojavaScript: add TypeScript support to Astro code fence.
     66 syntax region astroJavaScript
     67      \ start=+^---$+
     68      \ keepend
     69      \ end=+^---$+
     70      \ contains=htmlTag,@astroJavaScript,@htmlPreproc,htmlCssStyleComment,htmlEndTag,astroFence
     71      \ fold
     72 
     73 unlet b:current_syntax
     74 
     75 if g:astro_typescript == 'enable'
     76  " Embedded TypeScript React (TSX) syntax.
     77  syntax include @astroJavaScriptReact syntax/typescriptreact.vim
     78 else
     79  " Embedded JavaScript React (JSX) syntax.
     80  syntax include @astroJavaScriptReact syntax/javascriptreact.vim
     81 endif
     82 
     83 " astroJavaScriptExpression: add {JSX or TSX} support to Astro expresions.
     84 execute '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.
     97 syntax region cssStyle
     98      \ start=+<style\_[^>]*>+
     99      \ keepend
    100      \ end=+</style\_[^>]*>+me=s-1
    101      \ contains=htmlTag,@htmlCss,htmlCssStyleComment,@htmlPreproc,htmlEndTag
    102      \ containedin=@astroJavaScriptReact
    103 
    104 unlet b:current_syntax
    105 
    106 " Embedded SCSS syntax.
    107 syntax include @astroScss syntax/scss.vim
    108 
    109 " cssStyle: add SCSS style tags support in Astro.
    110 syntax 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 
    117 unlet b:current_syntax
    118 
    119 " Embedded SASS syntax.
    120 syntax include @astroSass syntax/sass.vim
    121 
    122 " cssStyle: add SASS style tags support in Astro.
    123 syntax 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 
    130 unlet b:current_syntax
    131 
    132 " Embedded LESS syntax.
    133 syntax include @astroLess syntax/less.vim
    134 
    135 " cssStyle: add LESS style tags support in Astro.
    136 syntax 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 
    143 unlet 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
    148 if 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
    165 endif
    166 
    167 " astroSurroundingTag: add surround HTML tag to script and style.
    168 syntax 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.
    177 highlight default link astroDirectives Special
    178 highlight default link astroFence Comment
    179 
    180 let b:current_syntax = 'astro'
    181 if main_syntax == 'astro'
    182  unlet main_syntax
    183 endif
    184 
    185 " Sync from start because of the wacky nesting.
    186 syntax sync fromstart
    187 
    188 let &cpoptions = s:cpoptions_save
    189 unlet s:cpoptions_save
    190 " vim: ts=8