Skip to content

Commit 96b3942

Browse files
committed
support RGBA hex notation in CSS
1 parent 727bc24 commit 96b3942

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

autoload/css_color.vim

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ function! s:create_syn_match()
144144
let rgb_color
145145
\ = funcname == 'rgb' ? s:rgb2color(submatch(3),submatch(4),submatch(5))
146146
\ : funcname == 'hsl' ? s:hsl2color(submatch(3),submatch(4),submatch(5))
147-
\ : strlen(hex) == 6 ? tolower(hex)
148-
\ : strlen(hex) == 3 ? tolower(hex[0].hex[0].hex[1].hex[1].hex[2].hex[2])
147+
\ : strlen(hex) >= 6 ? tolower(hex[0:5])
148+
\ : strlen(hex) >= 3 ? tolower(hex[0].hex[0].hex[1].hex[1].hex[2].hex[2])
149149
\ : ''
150150

151151
if rgb_color == '' | throw 'css_color: create_syn_match invoked on bad match data' | endif
@@ -199,13 +199,14 @@ function! s:create_matches()
199199
endfunction
200200

201201
let s:_hexcolor = '#\(\x\{3}\%(\>\|\x\{3}\>\)\)' " submatch 1
202+
let s:_rgbacolor = '#\(\x\{3}\%(\>\|\x\%(\>\|\x\{2}\%(\>\|\x\{2}\>\)\)\)\)' " submatch 1
202203
let s:_funcname = '\(rgb\|hsl\)a\?' " submatch 2
203204
let s:_ws_ = '\s*'
204205
let s:_numval = s:_ws_ . '\(\d\{1,3}%\?\)' " submatch 3,4,5
205206
let s:_listsep = s:_ws_ . ','
206207
let s:_otherargs_ = '\%(,[^)]*\)\?'
207208
let s:_funcexpr = s:_funcname . '[(]' . s:_numval . s:_listsep . s:_numval . s:_listsep . s:_numval . s:_ws_ . s:_otherargs_ . '[)]'
208-
let s:_csscolor = s:_hexcolor . '\|' . s:_funcexpr
209+
let s:_csscolor = s:_rgbacolor . '\|' . s:_funcexpr
209210
" N.B. sloppy heuristic constants for performance reasons:
210211
" a) start somewhere left of screen in case of partially visible colorref
211212
" b) take some multiple of &columns to handle multibyte chars etc

0 commit comments

Comments
 (0)