mirror of
https://github.com/sheerun/vim-polyglot.git
synced 2025-11-11 04:53:51 -05:00
Add svelte support, closes #410
This commit is contained in:
61
syntax/svelte.vim
Normal file
61
syntax/svelte.vim
Normal file
@@ -0,0 +1,61 @@
|
||||
if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'svelte') != -1
|
||||
finish
|
||||
endif
|
||||
|
||||
" Vim syntax file
|
||||
" Language: Svelte 3 (HTML/JavaScript)
|
||||
" Author: Evan Lecklider <evan@lecklider.com>
|
||||
" Maintainer: Evan Lecklide <evan@lecklider.com>
|
||||
" Depends: pangloss/vim-javascript
|
||||
" URL: https://github.com/evanleck/vim-svelte
|
||||
"
|
||||
" Like vim-jsx, this depends on the pangloss/vim-javascript syntax package (and
|
||||
" is tested against it exclusively). If you're using vim-polyglot (like I am),
|
||||
" then you're all set.
|
||||
|
||||
if exists("b:current_syntax")
|
||||
finish
|
||||
endif
|
||||
|
||||
" Read HTML to begin with.
|
||||
runtime! syntax/html.vim
|
||||
unlet! b:current_syntax
|
||||
|
||||
" Expand HTML tag names to include mixed case, periods, and colons.
|
||||
syntax match htmlTagName contained "\<[a-zA-Z:\.]*\>"
|
||||
|
||||
" Special attributes that include some kind of binding e.g. "on:click",
|
||||
" "bind:something", etc.
|
||||
syntax match svelteKeyword "\<[a-z]\+:[a-zA-Z|]\+=" contained containedin=htmlTag
|
||||
|
||||
" The "slot" attribute has special meaning.
|
||||
syntax keyword svelteKeyword slot contained containedin=htmlTag
|
||||
|
||||
" According to vim-jsx, you can let jsBlock take care of ending the region.
|
||||
" https://github.com/mxw/vim-jsx/blob/master/after/syntax/jsx.vim
|
||||
"
|
||||
" ALLBUT,htmlSpecialTagName keeps Vim from marking CSS regions as jsBlock.
|
||||
syntax region svelteExpression start="{" end="" contains=jsBlock,javascriptBlock containedin=htmlString,htmlTag,htmlArg,htmlValue,htmlH1,htmlH2,htmlH3,htmlH4,htmlH5,htmlH6,htmlHead,htmlTitle,htmlBoldItalicUnderline,htmlUnderlineBold,htmlUnderlineItalicBold,htmlUnderlineBoldItalic,htmlItalicUnderline,htmlItalicBold,htmlItalicBoldUnderline,htmlItalicUnderlineBold,htmlLink,htmlLeadingSpace,htmlBold,htmlBoldUnderline,htmlBoldItalic,htmlBoldUnderlineItalic,htmlUnderline,htmlUnderlineItalic,htmlItalic,htmlStrike,javaScript
|
||||
|
||||
" Block conditionals.
|
||||
syntax match svelteConditional "#if" contained containedin=jsBlock,javascriptBlock
|
||||
syntax match svelteConditional "/if" contained containedin=jsBlock,javascriptBlock
|
||||
syntax match svelteConditional ":else if" contained containedin=jsBlock,javascriptBlock
|
||||
syntax match svelteConditional ":else" contained containedin=jsBlock,javascriptBlock
|
||||
|
||||
" Block keywords.
|
||||
syntax match svelteKeyword "#await" contained containedin=jsBlock,javascriptBlock
|
||||
syntax match svelteKeyword "/await" contained containedin=jsBlock,javascriptBlock
|
||||
syntax match svelteKeyword ":catch" contained containedin=jsBlock,javascriptBlock
|
||||
syntax match svelteKeyword ":then" contained containedin=jsBlock,javascriptBlock
|
||||
syntax match svelteKeyword "@html" contained containedin=jsBlock,javascriptBlock
|
||||
|
||||
" Repeat functions.
|
||||
syntax match svelteRepeat "#each" contained containedin=jsBlock,javascriptBlock
|
||||
syntax match svelteRepeat "/each" contained containedin=jsBlock,javascriptBlock
|
||||
|
||||
highlight def link svelteConditional Conditional
|
||||
highlight def link svelteKeyword Keyword
|
||||
highlight def link svelteRepeat Repeat
|
||||
|
||||
let b:current_syntax = "svelte"
|
||||
Reference in New Issue
Block a user