Skip to content

Commit 8247413

Browse files
committed
Improve embedded HEEx and Surface syntax highlighting
* Properly highlight embedded HEEx (and Surface) * Re-name groups to favour HEEx naming * Add highlight group for `phx-` attributes * Add highlight group for heex attribute (eg, `some_attr="some value"`) * Add highlight group for heex special attribute (ie, `:if` and `:for`) * Add heexComponentName group * Add heexEndComponent group
1 parent 6dd03f8 commit 8247413

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

Diff for: syntax/elixir.vim

+30-6
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,39 @@ 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
119-
syntax region elixirPhoenixESigil matchgroup=elixirSigilDelimiter keepend start=+\~E\z("""\)+ end=+^\s*\z1+ skip=+\\"+ contains=@HTML fold
120-
syntax region elixirPhoenixeSigil matchgroup=elixirSigilDelimiter keepend start=+\~e\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
118+
119+
syn cluster elixirLiveSigils contains=elixirLiveViewSigil,elixirHeexSigil,elixirSurfaceSigil
120+
121+
syn region heexComponent matchgroup=eelixirDelimiter start="<\.[a-z_]\+" end="%\@<!>" contains=ALLBUT,@elixirNotTop keepend
122+
syn region heexExpression matchgroup=eelixirDelimiter start="<%" end="%\@<!%>" contains=ALLBUT,@elixirNotTop containedin=@elixirLiveSigils keepend
123+
syn region heexExpression matchgroup=eelixirDelimiter start="<%=" end="%\@<!%>" contains=ALLBUT,@elixirNotTop containedin=@elixirLiveSigils keepend
124+
syn region heexAttributeExpression matchgroup=heexDelimiter start="=\zs{" end="}" contains=ALLBUT,@elixirNotTop containedin=htmlValue keepend
125+
syn region heexAttributeExpression matchgroup=heexDelimiter start="=\zs{" end="}" skip="#{[^}]*}" contains=ALLBUT,@elixirNotTop containedin=htmlValue keepend
126+
" missing `keepend` on next line is intentional
127+
syn region heexAttributeExpression matchgroup=heexDelimiter start="=\zs{" end="}" skip="%{[^}]*}" contains=ALLBUT,@elixirNotTop containedin=htmlValue
128+
syn region eelixirQuote matchgroup=eelixirDelimiter start="<%%" end="%\@<!%>" contains=ALLBUT,@elixirNotTop containedin=@elixirLiveSigils keepend
129+
syn region heexComment matchgroup=eelixirDelimiter start="<%!--" end="%\@<!--%>" contains=elixirTodo,eelixirComment,@Spell containedin=@elixirLiveSigils keepend
130+
131+
syn match phxArg "\<phx[-.0-9_a-z]*-[-.0-9_a-z]*\>" containedin=htmlTag
132+
syn match heexArg "\<[0-9_a-z]*\>\ze=" containedin=htmlTag
133+
syn match heexSpecialAttribute ":\%(if\|for\|let\)\ze=" containedin=htmlTag
134+
syn match heexComponentName "<\zs\.[A-Z_a-z][A-Z_a-z0-9]\+" containedin=htmlTag
135+
syn match heexEndComponent "<\zs\/\.[A-Z_a-z][A-Z_a-z0-9]\+" containedin=htmlEndTag
136+
137+
hi def link eelixirDelimiter PreProc
138+
hi def link heexDelimiter PreProc
139+
hi def link heexComment Comment
140+
hi def link phxArg htmlArg
141+
hi def link heexArg htmlArg
142+
hi def link heexSpecialAttribute htmlArg
143+
hi def link heexComponentName htmlTagName
144+
hi def link heexEndComponent htmlTagName
121145

122146
" Documentation
123147
if exists('g:elixir_use_markdown_for_docs') && g:elixir_use_markdown_for_docs

0 commit comments

Comments
 (0)