Skip to content

Commit c23000a

Browse files
authored
Merge pull request #570 from sodapopcan/improve-heex-highlighting
Improve embedded HEEx and Surface syntax highlighting
2 parents 71841da + 8377bd0 commit c23000a

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

Diff for: syntax/elixir.vim

+30-4
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,42 @@ syn region elixirSigil matchgroup=elixirSigilDelimiter start="\~\l\/"
109109
syn region elixirSigil matchgroup=elixirSigilDelimiter start=+\~\a\z("""\)+ end=+^\s*\z1+ skip=+\\"+ fold
110110
syn region elixirSigil matchgroup=elixirSigilDelimiter start=+\~\a\z('''\)+ end=+^\s*\z1+ skip=+\\'+ fold
111111

112-
113-
" LiveView Sigils surrounded with ~L"""
112+
" LiveView-specific sigils for embedded templates
114113
syntax include @HTML syntax/html.vim
115114
unlet b:current_syntax
116-
syntax region elixirLiveViewSigil matchgroup=elixirSigilDelimiter keepend start=+\~L\z("""\)+ end=+^\s*\z1+ skip=+\\"+ contains=@HTML fold
117-
syntax region elixirSurfaceSigil matchgroup=elixirSigilDelimiter keepend start=+\~H\z("""\)+ end=+^\s*\z1+ skip=+\\"+ contains=@HTML fold
115+
syntax region elixirHeexSigil matchgroup=elixirSigilDelimiter keepend start=+\~H\z("""\)+ end=+^\s*\z1+ skip=+\\"+ contains=@HTML fold
118116
syntax region elixirSurfaceSigil matchgroup=elixirSigilDelimiter keepend start=+\~F\z("""\)+ end=+^\s*\z1+ skip=+\\"+ contains=@HTML fold
117+
syntax region elixirLiveViewSigil matchgroup=elixirSigilDelimiter keepend start=+\~L\z("""\)+ end=+^\s*\z1+ skip=+\\"+ contains=@HTML fold
119118
syntax region elixirPhoenixESigil matchgroup=elixirSigilDelimiter keepend start=+\~E\z("""\)+ end=+^\s*\z1+ skip=+\\"+ contains=@HTML fold
120119
syntax region elixirPhoenixeSigil matchgroup=elixirSigilDelimiter keepend start=+\~e\z("""\)+ end=+^\s*\z1+ skip=+\\"+ contains=@HTML fold
121120

121+
syn cluster elixirTemplateSigils contains=elixirLiveViewSigil,elixirHeexSigil,elixirSurfaceSigil,elixirPhoenixESigil,elixirPhoenixeSigil
122+
123+
syn region heexComponent matchgroup=eelixirDelimiter start="<\.[a-z_]\+" end="%\@<!>" contains=ALLBUT,@elixirNotTop keepend
124+
syn region eelixirExpression matchgroup=eelixirDelimiter start="<%" end="%\@<!%>" contains=ALLBUT,@elixirNotTop containedin=@elixirTemplateSigils keepend
125+
syn region eelixirExpression matchgroup=eelixirDelimiter start="<%=" end="%\@<!%>" contains=ALLBUT,@elixirNotTop containedin=@elixirTemplateSigils keepend
126+
syn region eelixirQuote matchgroup=eelixirDelimiter start="<%%" end="%\@<!%>" contains=ALLBUT,@elixirNotTop containedin=@elixirTemplateSigils keepend
127+
syn region heexComment matchgroup=eelixirDelimiter start="<%!--" end="%\@<!--%>" contains=elixirTodo,eelixirComment,@Spell containedin=@elixirTemplateSigils keepend
128+
syn region heexExpression matchgroup=heexDelimiter start="=\zs{" end="}" contains=ALLBUT,@elixirNotTop containedin=htmlValue keepend
129+
syn region heexExpression matchgroup=heexDelimiter start="=\zs{" end="}" skip="#{[^}]*}" contains=ALLBUT,@elixirNotTop containedin=htmlValue keepend
130+
" missing `keepend` on next line is intentional
131+
syn region heexExpression matchgroup=heexDelimiter start="=\zs{" end="}" skip="%{[^}]*}" contains=ALLBUT,@elixirNotTop containedin=htmlValue
132+
133+
syn match phxArg "\<phx[-.0-9_a-z]*-[-.0-9_a-z]*\>" containedin=htmlTag
134+
syn match heexArg "\<[0-9_a-z]*\>\ze=" containedin=htmlTag
135+
syn match heexSpecialAttribute ":\%(if\|for\|let\)\ze=" containedin=htmlTag
136+
syn match heexComponentName "<\zs\.[A-Z_a-z][A-Z_a-z0-9]\+" containedin=htmlTag
137+
syn match heexEndComponent "<\zs\/\.[A-Z_a-z][A-Z_a-z0-9]\+" containedin=htmlEndTag
138+
139+
hi def link eelixirDelimiter PreProc
140+
hi def link heexDelimiter PreProc
141+
hi def link heexComment Comment
142+
hi def link phxArg htmlArg
143+
hi def link heexArg htmlArg
144+
hi def link heexSpecialAttribute htmlArg
145+
hi def link heexComponentName htmlTagName
146+
hi def link heexEndComponent htmlTagName
147+
122148
" Documentation
123149
if exists('g:elixir_use_markdown_for_docs') && g:elixir_use_markdown_for_docs
124150
syn include @markdown syntax/markdown.vim

0 commit comments

Comments
 (0)