Skip to content

Commit

Permalink
support RGBA hex notation in CSS
Browse files Browse the repository at this point in the history
  • Loading branch information
ap committed Aug 9, 2020
1 parent 727bc24 commit 96b3942
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions autoload/css_color.vim
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ function! s:create_syn_match()
let rgb_color
\ = funcname == 'rgb' ? s:rgb2color(submatch(3),submatch(4),submatch(5))
\ : funcname == 'hsl' ? s:hsl2color(submatch(3),submatch(4),submatch(5))
\ : strlen(hex) == 6 ? tolower(hex)
\ : strlen(hex) == 3 ? tolower(hex[0].hex[0].hex[1].hex[1].hex[2].hex[2])
\ : strlen(hex) >= 6 ? tolower(hex[0:5])
\ : strlen(hex) >= 3 ? tolower(hex[0].hex[0].hex[1].hex[1].hex[2].hex[2])
\ : ''

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

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

0 comments on commit 96b3942

Please sign in to comment.