From 3e7d1de0d9aa04a8d121ea777c91bbba8b4dfe1c Mon Sep 17 00:00:00 2001 From: Adam Katz <6454774+adamhotep@users.noreply.github.com> Date: Fri, 26 May 2023 17:59:23 -0400 Subject: [PATCH 01/21] overflow check fixes ap/vim-css-color#151 --- autoload/css_color.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/css_color.vim b/autoload/css_color.vim index ebfc705..86c563d 100644 --- a/autoload/css_color.vim +++ b/autoload/css_color.vim @@ -231,7 +231,7 @@ 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:_numval = s:_ws_ . '\([0-9]\{1,2}%\|100%\|1\?[0-9]\{1,2}\|2[0-4][0-9]\|25[0-5]\)' " 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_ . '[)]' From 7d597ee57519395d5c990bfce311a4b8dc730043 Mon Sep 17 00:00:00 2001 From: Adam Katz <6454774+adamhotep@users.noreply.github.com> Date: Fri, 26 May 2023 18:55:52 -0400 Subject: [PATCH 02/21] support for decimals and spaced color values --- autoload/css_color.vim | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/autoload/css_color.vim b/autoload/css_color.vim index 86c563d..6461ef0 100644 --- a/autoload/css_color.vim +++ b/autoload/css_color.vim @@ -230,11 +230,13 @@ 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:_funcprep = '\%(\s*\S\+\%(\%(\s\+\S\+\)\{2}\|\%(\s*,\s*\S\+\)\{2}\)\)\@=' " lookahead for 12,34,56 vs 12 34 56 to avoid 12 34,56 let s:_ws_ = '\s*' -let s:_numval = s:_ws_ . '\([0-9]\{1,2}%\|100%\|1\?[0-9]\{1,2}\|2[0-4][0-9]\|25[0-5]\)' " 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:_numval = '\(\d\{1,3}\%(\.\d*\)\?%\?\)' " submatch 3,4,5 (use this after implementing ceilings for the output of b:css_color_pat) +let s:_numval = '\(\d\{1,2}\%(\.\d*\)\?%\|100%\|255\|\%(1\?\d\{1,2}\|2[0-4]\d\|25[0-5]\)\%(\.\d*\)\?\)' " submatch 3,4,5 +let s:_listsep = s:_ws_ . '[,[:space:]]\+' +let s:_otherargs_ = s:_ws_ . '\%([,\/][^)]*\)\?' " ignore alpha +let s:_funcexpr = s:_funcname . '[(]' . s:_funcprep . s:_ws_ . s:_numval . s:_listsep . s:_numval . s:_listsep . s:_numval . s:_otherargs_ . '[)]' 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 From 583e8c27af91d00f27c801773739bf09f05bd64d Mon Sep 17 00:00:00 2001 From: Adam Katz <6454774+adamhotep@users.noreply.github.com> Date: Fri, 26 May 2023 21:53:18 -0400 Subject: [PATCH 03/21] awk is faster and more broadly installed than perl, support neovim and vim packages --- tests/bench | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/bench b/tests/bench index 21e6eea..a09dc0f 100755 --- a/tests/bench +++ b/tests/bench @@ -2,5 +2,5 @@ set -e s=startuptime.txt vim --startuptime $s -o -c qa "$@" -perl -lane'$sum += $F[1] if m!/\.vim/after/syntax/css\.vim$!; END {print $sum}' $s +awk '/\/after\/syntax\/css\.vim$/ {sum += $2} END {print sum}' $s rm $s From a696232412b059c15e407d0c9284dee56a20360b Mon Sep 17 00:00:00 2001 From: Adam Katz <6454774+adamhotep@users.noreply.github.com> Date: Sun, 28 May 2023 01:25:57 -0400 Subject: [PATCH 04/21] more comprehensive tests --- tests/suite.css | 102 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 tests/suite.css diff --git a/tests/suite.css b/tests/suite.css new file mode 100644 index 0000000..065bece --- /dev/null +++ b/tests/suite.css @@ -0,0 +1,102 @@ +/* see also https://developer.mozilla.org/en-US/docs/Web/CSS/color + * and https://www.w3schools.com/colors/colors_converter.asp */ + +i { background: #359 } +b { background: #335599 } +u { color: #12345678; background: rgba(144, 0, 0, .5) } +s { color: #1234; background: hsl(0, 100%, 50%) } +p { color:rebeccapurple; background-color:rgb(222 255 202 / 0.2) } + +/* These are all pretty much the same color (barring rounding and alpha) */ +a.rgb { color: rgb(0, 17, 136); } /* no alpha */ +a.rgb1 { color: rgb(0, 17, 136, 1); } /* alpha but fully opaque */ +a.rgba { color: rgba(0, 17, 136, 1); } /* explicit alpha but fully opaque */ +a.rgbp { color: rgb(0, 17, 136, 50%); } /* half transparent (via percent) */ +a.rgb0 { color: rgb(0, 17, 136, 0.1); } /* very transparent */ +a.rgbz { color: rgb(0, 17, 136, 0); } /* fully transparent */ +a.sp { color:rgb(0 , 17, 136, 0.3) } /* extra spaces */ +a.rgbd { color: rgb(0, 16.99, 136); } /* CSS supports decimals! */ +a.cc{color:rgb(0,17,136,.3)} /* compact with commas */ +a.cs{color:rgb(0 17 136/.3)} /* compact with spaces and slash */ +a.h3 { color: #018; } /* same color but in hex (3char) */ +a.h6 { color: #001188; } /* same color but in hex (6char) */ +a.h8 { color: #001188ff; } /* same color but in hex (8char) */ +a.hlcs { color:hsl(232.5 100% 27%); } /* same color but hsl with spaces */ +a.hslc { color:hsl(232.5, 100%, 27%) } /* same color but hsl, commas */ +a.hlca { color:hsl(232.5, 100%, 27%, 100%); } /* same color but hsla */ +a.hwb { color:hwb(232.5, 0%, 46.5%); } /* same color but hwb */ + +/* out of bounds but accepted by browsers */ +a.rgboob { color:rgb(0,17,256); } +a.rgbaoob1 { color:rgb(0,17,255, 1.1); } +a.rgbaoob2 { color:rgb(0,17,255, 2); } +a.hsloob101 { color:hsl(256, 200%, 27%); } + +/* are we rounding too much? these should be different */ +u.round1 { color: rgb(10.9% 123 122.5) } /* should be #1c7b7b */ +u.round2 { color: rgb(10.0% 123 123.4) } /* should be #1a7b7b */ +u.round3 { color: hsl(180 65% 29%) } /* should be #197a7a */ + +*::color1 { -x-: #359 } +*::color2 { -x-: #335599 } +*::color3 { -x-: rgba(144, 0, 0, .5) } +*::color4 { -x-: hsl(0, 100%, 50%) } + +/* + * #123, #456 + */ + +/* #123456 */ + +.do_color_me::after { color: rgb(123, 234, 0) } + +ul { color: white; } + +td { border: solid red 4px; } +td { border: solid #f00d 4px; } + +:root { --variable-test: rgb(1, 2, 3); } +button { color: yellow; background: var(--variable-test); } + +/* These are all the same color: */ +h1.hex { color: #7ab899; } +h1.num { color: hsl(150, 30%, 60%); } +h1.num { color: hsla(870, 30%, 60%, 1); } +h1.num { color: hsl(-210, 30%, 60%); } +h1.deg { color: hsl(150deg, 30%, 60%); } +h1.grad { color: hsl(166.7grad, 30%, 60%); } +h1.turn { color: hsl(0.41667turn, 30%, 60%); } +h1.tuac { color: hsl(0.41667turn, 30%, 60%, 1); } +h1.tuas { color: hsl(0.41667turn 30% 60% / 1); } + +/* hwb(), hue/whiteness/blackness + * https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/hwb + * These are all the same color: */ +a.a { color: hwb(90 10% 10%); } +a.b { color: hwb(90 10% 10% / 0.5); } +a.c { color: hwb(90deg 10% 10%); } +a.d { color: hwb(1.5708rad 10% 10%); } +a.e { color: hwb(0.25turn 10% 10% / 50%); } + +q { border-color: tan; } + +/* these should NOT be colored */ +.dont_color_me::after { content: "color: rgb(123, 234, 0)" } +#abcdef { border-color: unset; } +p.tan { color: inherit; width: calc(100px * tan(45deg)); } +a.cs1 { color: rgb(0, 17, 136 / 100%); } /* you can't mix commas and slash */ +a.cs2 { color: rgb(0 17 136, 100%); } /* you can't mix spaces and commas */ +a.cs3 { color: rgb(0 17 136 1); } /* alpha with spaces must use slash */ +a.cs4 { color: rgb(0 17 136 100%); } /* alpha with spaces must use slash */ +a.cs4 { color: rgb(0turn 17 136); } /* angular units aren't allowed in rgb */ +h1.nonpct1 { color: hsl(150%, 30%, 60%); } +h1.nonpct1 { color: hsl(150, 30, 60%); } +h1.nonpct2 { color: hsl(150, 30%, 60); } +h1.nonpct3 { color: hsl(150, 30, 60); } +a.a { color: hwb(90% 10% 10%); } +a.a { color: hwb(90 10 10%); } +a.a { color: hwb(90 10% 10); } +a.h5 { color: #00118; } +a.h7 { color: #001188f; } +a.h9 { color: #001188fff; } + From b54bcf5ef3823652f6e95f5efd8a90cd48580c1a Mon Sep 17 00:00:00 2001 From: Adam Katz <6454774+adamhotep@users.noreply.github.com> Date: Sun, 28 May 2023 01:28:13 -0400 Subject: [PATCH 05/21] support overflow/wraparound values, stricter adherence to formats, added support for different angle units, hwb(), and decimal values --- autoload/css_color.vim | 112 ++++++++++++++++++++++++++++++++++------- 1 file changed, 95 insertions(+), 17 deletions(-) diff --git a/autoload/css_color.vim b/autoload/css_color.vim index 6461ef0..2ca558d 100644 --- a/autoload/css_color.vim +++ b/autoload/css_color.vim @@ -11,17 +11,56 @@ if ! ( v:version >= 700 && has('syntax') && ( has('gui_running') || has('nvim') finish endif +let s:_invalid = -9999 " used after bounding/wrapping, so this is safe + +function! s:bound(n, min, max) + let n = a:n + if n < a:min | let n = a:min + elseif n > a:max | let n = a:max | endif + return str2nr( string(n + 0.5) ) +endfunction + +function! s:rgb2hex(r, g, b) + let [r,g,b] = map( [a:r,a:g,a:b], 's:bound(v:val, 0, 255)' ) + return printf( '%02x%02x%02x', r, g, b ) +endfunction + function! s:rgb2color(r,g,b) - " Convert 80% -> 204, 100% -> 255, etc. - let rgb = map( [a:r,a:g,a:b], 'v:val =~ "%$" ? ( 255 * v:val ) / 100 : v:val' ) - return printf( '%02x%02x%02x', rgb[0], rgb[1], rgb[2] ) + " Convert 35.6% -> 90.78, 80% -> 204, 100% -> 255, etc. + let [r,g,b] = map( [a:r,a:g,a:b], 'v:val =~ "%$" ? str2float(v:val) * 2.55 : str2float(v:val)' ) + return s:rgb2hex(r, g, b) endfunction -function! s:hsl2color(h,s,l) - " Convert 80% -> 0.8, 100% -> 1.0, etc. - let [s,l] = map( [a:s, a:l], 'v:val =~ "%$" ? v:val / 100.0 : v:val + 0.0' ) +" Vimscript modulo can't handle decimals. Fix that. +function! s:modulo(a, b) + let num = str2nr( string(a:a) ) + let extra = a:a - num + return str2nr(a:a - extra) % a:b + extra +endfunction + +function! s:angle2deg(angle, units) + let deg = str2float(a:angle) + " angles: https://developer.mozilla.org/en-US/docs/Web/CSS/angle + if a:units == "rad" + let deg = deg * 57.29577951308232 " deg = rad * 180 / pi, 360deg == 6.2832rad + elseif a:units == "grad" + let deg = deg * 0.9 " 360deg = 400grad + elseif a:units == "turn" + let deg = deg * 360.0 " 360deg = 1turn + elseif a:units != "" && a:units != "deg" + return s:_invalid " percent is invalid here + endif + let deg = s:modulo(deg, 360) + if deg < 0 | let deg = deg + 360 | endif + return deg +endfunction + +function! s:hsl2rgb(h,u,s,l) + let [s,l] = map( [a:s, a:l], 'str2nr(v:val) >= 1 ? 1.0 : str2float(v:val)' ) " algorithm transcoded to vim from http://www.w3.org/TR/css3-color/#hsl-color - let hh = ( a:h % 360 ) / 360.0 + let hh = s:angle2deg(a:h, a:u) + if hh == s:_invalid | return [hh,hh,hh] | endif + let hh = hh / 360.0 let m2 = l <= 0.5 ? l * ( s + 1 ) : l + s - l * s let m1 = l * 2 - m2 let rgb = [] @@ -32,12 +71,48 @@ function! s:hsl2color(h,s,l) \ h * 2 < 1 ? m2 : \ h * 3 < 2 ? m1 + ( m2 - m1 ) * ( 2/3.0 - h ) * 6 : \ m1 - if v > 1.0 | return '' | endif + if v > 1.0 | return [s:_invalid, s:_invalid, s:_invalid] | endif let rgb += [ float2nr( 255 * v ) ] endfor - return printf( '%02x%02x%02x', rgb[0], rgb[1], rgb[2] ) + return rgb endfunction +function! s:pctvet(h,s,l) + " hue cannot be a percent, the others must be percents. same with hwb + if a:h =~ "%$" || a:s !~ "%$" || a:l !~ "%$" + return [s:_invalid, s:_invalid, s:_invalid] + endif + let [s,l] = map( [a:s, a:l], 'v:val >= 100 ? 1.0 : v:val / 100.0' ) + return [a:h, s, l] +endfunction + +function! s:hsl2color(h,u,s,l) + let [h,s,l] = s:pctvet(a:h, a:s, a:l) " convert saturation & luminance % -> num + if h == s:_invalid | return '' | endif + let [r,g,b] = s:hsl2rgb(h, a:u, s, l) + if r == s:_invalid | return '' | endif + return s:rgb2hex(r, g, b) +endfunction + +function! s:hwb2color(h,u,w,b) + let [h,w,b] = s:pctvet(a:h, a:w, a:b) " convert whiteness & blackness % -> num + if h == s:_invalid | return '' | endif + " algorithm transcoded to vim from https://drafts.csswg.org/css-color/#hwb-to-rgb + if w + b >= 1 + let gray = w / (w + b) + let [r,g,b] = [gray,gray,gray] + else + let [r,g,b] = map( s:hsl2rgb(a:h, a:u, 1.0, 0.5), 'v:val * (1 - w - b) + w' ) + endif + return s:rgb2hex(r, g, b) +endfunction + +" TODO (probably not): new "device-independent colors": +" lch(), oklch(), lab(), oklab(), and color(). +" These look hard and I don't see reference algorithms to convert to sRGB. +" https://developer.mozilla.org/en-US/docs/Web/CSS/color_value +" https://drafts.csswg.org/css-color/#lab-colors + let s:_1_3 = 1.0/3 let s:_16_116 = 16.0/116.0 let s:cos16 = cos(16*(180/atan2(0,-1))) @@ -170,14 +245,17 @@ function! s:create_syn_match() let hex = submatch(1) let funcname = submatch(2) + if funcname =~ 'rgb' && submatch(4) != '' | return '' | endif " rgb() doesn't support units + let rgb_color - \ = funcname == 'rgb' ? s:rgb2color(submatch(3),submatch(4),submatch(5)) - \ : funcname == 'hsl' ? s:hsl2color(submatch(3),submatch(4),submatch(5)) + \ = funcname =~ '^rgb' ? s:rgb2color(submatch(3),submatch(5),submatch(6)) + \ : funcname =~ '^hsl' ? s:hsl2color(submatch(3),submatch(4),submatch(5),submatch(6)) + \ : funcname == 'hwb' ? s:hwb2color(submatch(3),submatch(4),submatch(5),submatch(6)) \ : 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 + if rgb_color == '' | return '' | endif let s:pattern_color[pattern] = rgb_color endif @@ -229,14 +307,14 @@ 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:_funcprep = '\%(\s*\S\+\%(\%(\s\+\S\+\)\{2}\|\%(\s*,\s*\S\+\)\{2}\)\)\@=' " lookahead for 12,34,56 vs 12 34 56 to avoid 12 34,56 +let s:_funcname = '\(rgb\a\?\|hsla\?\|hwb\)' " submatch 2 +let s:_consistent = '\%(\%(\s\+[0-9.%]\+\)\{2}\s*\%(\/\s*[-0-9.%]\+\)\?[)]\|\%(\s*,\s*[-0-9.%]\+\)\{2,3}[)]\)\@=' " lookahead: 1 2 3 or 1 2 3/4 or 1,2,3 or 1,2,3,4 after 1 let s:_ws_ = '\s*' -"let s:_numval = '\(\d\{1,3}\%(\.\d*\)\?%\?\)' " submatch 3,4,5 (use this after implementing ceilings for the output of b:css_color_pat) -let s:_numval = '\(\d\{1,2}\%(\.\d*\)\?%\|100%\|255\|\%(1\?\d\{1,2}\|2[0-4]\d\|25[0-5]\)\%(\.\d*\)\?\)' " submatch 3,4,5 +let s:_numval = '\(-\?\d\{1,3}\%(\.\d*\)\?%\?\)' " submatch 3,5,6 +let s:_units = '\(deg\|g\?rad\|turn\)\?' " submatch 4 let s:_listsep = s:_ws_ . '[,[:space:]]\+' let s:_otherargs_ = s:_ws_ . '\%([,\/][^)]*\)\?' " ignore alpha -let s:_funcexpr = s:_funcname . '[(]' . s:_funcprep . s:_ws_ . s:_numval . s:_listsep . s:_numval . s:_listsep . s:_numval . s:_otherargs_ . '[)]' +let s:_funcexpr = s:_funcname . '[(]' . s:_ws_ . s:_numval . s:_units . s:_consistent . s:_listsep . s:_numval . s:_listsep . s:_numval . s:_otherargs_ . '[)]' 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 From 993a0a562662b68a177958ed914c59435291381f Mon Sep 17 00:00:00 2001 From: Adam Katz <6454774+adamhotep@users.noreply.github.com> Date: Sun, 28 May 2023 13:46:36 -0400 Subject: [PATCH 06/21] bench script didn't work with -o, split it up per-file and added a "total" (which you'll notice is quite a bit higher than -o would have shown) --- tests/bench | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/bench b/tests/bench index a09dc0f..97f8d6b 100755 --- a/tests/bench +++ b/tests/bench @@ -1,6 +1,13 @@ #!/bin/sh set -e s=startuptime.txt -vim --startuptime $s -o -c qa "$@" -awk '/\/after\/syntax\/css\.vim$/ {sum += $2} END {print sum}' $s -rm $s +[ $# = 0 ] && set -- *.* # default to all files with a dot +[ $# -gt 1 ] && multi=1 || multi= +for sample in "$@"; do + vim --startuptime $s -c qa "$sample" + run=$(awk '/\/after\/syntax\/css\.vim$/ {sum += $2} END {print sum}' "$s") + rm $s + echo "$run${multi:+\t$sample}" + total=$(echo "${total:-0} + ${run:-0}" |bc -ql) +done +[ -n "$multi" ] && echo "$total\t(total)" From 928bee73b07303b3505e5918e522ab9ab4f82561 Mon Sep 17 00:00:00 2001 From: Adam Katz <6454774+adamhotep@users.noreply.github.com> Date: Sun, 28 May 2023 13:49:43 -0400 Subject: [PATCH 07/21] better comment for pctvet --- autoload/css_color.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/css_color.vim b/autoload/css_color.vim index 2ca558d..ff993d3 100644 --- a/autoload/css_color.vim +++ b/autoload/css_color.vim @@ -78,7 +78,7 @@ function! s:hsl2rgb(h,u,s,l) endfunction function! s:pctvet(h,s,l) - " hue cannot be a percent, the others must be percents. same with hwb + " for hsl & hwb, hue cannot be a percent, the others must be percents. if a:h =~ "%$" || a:s !~ "%$" || a:l !~ "%$" return [s:_invalid, s:_invalid, s:_invalid] endif From caaf911e2b19abae5cfe1d54c48ecb031e209ef7 Mon Sep 17 00:00:00 2001 From: Adam Katz <6454774+adamhotep@users.noreply.github.com> Date: Mon, 29 May 2023 17:10:02 -0400 Subject: [PATCH 08/21] removed hack to avoid `white-space` since it's already avoided by iskeyword including dashes (Also: it doesnt work; try a similar exclusion to avoid `width: calc(100px * tan(45deg))` and you'll find you cant.) --- syntax/colornames/basic.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/colornames/basic.vim b/syntax/colornames/basic.vim index 37730ce..688ba89 100644 --- a/syntax/colornames/basic.vim +++ b/syntax/colornames/basic.vim @@ -32,7 +32,7 @@ syn case ignore syn keyword BG000000 black contained containedin=@colorableGroup syn keyword BGc0c0c0 silver contained containedin=@colorableGroup syn keyword BG808080 gray contained containedin=@colorableGroup -syn match BGffffff "\c\" contained containedin=@colorableGroup +syn keyword BGffffff white contained containedin=@colorableGroup syn keyword BG800000 maroon contained containedin=@colorableGroup syn keyword BGff0000 red contained containedin=@colorableGroup syn keyword BG800080 purple contained containedin=@colorableGroup From 9ba1cc76056f54f61bd90ba15d50c6daf1ba9020 Mon Sep 17 00:00:00 2001 From: Adam Katz <6454774+adamhotep@users.noreply.github.com> Date: Mon, 29 May 2023 17:11:28 -0400 Subject: [PATCH 09/21] bench: run `bc` just once, exit cleanly unless the syntax was never run --- tests/bench | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/bench b/tests/bench index 97f8d6b..aaa4336 100755 --- a/tests/bench +++ b/tests/bench @@ -8,6 +8,7 @@ for sample in "$@"; do run=$(awk '/\/after\/syntax\/css\.vim$/ {sum += $2} END {print sum}' "$s") rm $s echo "$run${multi:+\t$sample}" - total=$(echo "${total:-0} + ${run:-0}" |bc -ql) + total="${total:-0} + ${run:-0}" done -[ -n "$multi" ] && echo "$total\t(total)" +# if multi, show the sum total. otherwise, return true only if we had a run. +[ -n "$multi" ] && echo "$(echo "$total" |bc -ql)\t(total)" || [ -n "$run" ] From 8bfd21e9c008111de35d7852127b0570dd4407a4 Mon Sep 17 00:00:00 2001 From: Adam Katz <6454774+adamhotep@users.noreply.github.com> Date: Mon, 29 May 2023 17:15:04 -0400 Subject: [PATCH 10/21] consistent test order for FP section --- tests/suite.css | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/suite.css b/tests/suite.css index 065bece..5b4cd26 100644 --- a/tests/suite.css +++ b/tests/suite.css @@ -48,10 +48,6 @@ u.round3 { color: hsl(180 65% 29%) } /* should be #197a7a */ /* #123456 */ -.do_color_me::after { color: rgb(123, 234, 0) } - -ul { color: white; } - td { border: solid red 4px; } td { border: solid #f00d 4px; } @@ -78,12 +74,16 @@ a.c { color: hwb(90deg 10% 10%); } a.d { color: hwb(1.5708rad 10% 10%); } a.e { color: hwb(0.25turn 10% 10% / 50%); } -q { border-color: tan; } +.do_color_me::after { color: rgb(123, 234, 0) } +q.tan { border-color: tan; } +q.white { border-color: white; } +q.abcdef { border-color: #abcdef; } /* these should NOT be colored */ .dont_color_me::after { content: "color: rgb(123, 234, 0)" } -#abcdef { border-color: unset; } p.tan { color: inherit; width: calc(100px * tan(45deg)); } +p.white { color: currentColor; white-space: inherit; } +#abcdef { border-color: unset; } a.cs1 { color: rgb(0, 17, 136 / 100%); } /* you can't mix commas and slash */ a.cs2 { color: rgb(0 17 136, 100%); } /* you can't mix spaces and commas */ a.cs3 { color: rgb(0 17 136 1); } /* alpha with spaces must use slash */ From 342554ca54716528ce4b5c780d099daa66ca4ddd Mon Sep 17 00:00:00 2001 From: Adam Katz <6454774+adamhotep@users.noreply.github.com> Date: Mon, 29 May 2023 17:16:50 -0400 Subject: [PATCH 11/21] HTML: fix broken CSS syntax within HTML attributes, add legacy HTML3 color attribute support --- after/syntax/html.vim | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/after/syntax/html.vim b/after/syntax/html.vim index 5452276..2d1f8a7 100644 --- a/after/syntax/html.vim +++ b/after/syntax/html.vim @@ -1,2 +1,35 @@ " default html syntax should already be including the css syntax -call css_color#init('none', 'none', 'htmlString,htmlCommentPart') +" but tag style attributes don't properly apply CSS syntax (as of vim 9.0.1378). +" Correct the bug by replacing htmlCssDefinition with a new htmlCssContent: {{{ +syn keyword htmlCssArg contained containedin=htmlTag nextgroup=htmlCssEq style +syn match htmlCssEq contained +=+ nextgroup=htmlCssQuote +syn match htmlCssQuote contained +["']+ nextgroup=htmlCssContent +syn region htmlCssContent contained start=+\%("\)\@<=.+ end=+"+ keepend contains=cssTagName,cssAttributeSelector,cssClassName,cssIdentifier,cssAtRule,cssAttrRegion,css.*Prop,cssComment,cssValue.*,cssColor,cssURL,cssImportant,cssCustomProp,cssError,cssStringQ,cssFunction,cssUnicodeEscape,cssVendor,cssHacks,cssNoise +syn region htmlCssContent contained start=+\%('\)\@<=.+ end=+'+ keepend contains=cssTagName,cssAttributeSelector,cssClassName,cssIdentifier,cssAtRule,cssAttrRegion,css.*Prop,cssComment,cssValue.*,cssColor,cssURL,cssImportant,cssCustomProp,cssError,cssStringQ,cssFunction,cssUnicodeEscape,cssVendor,cssHacks,cssNoise + +hi def link htmlCssArg htmlArg +hi def link htmlCssEq htmlTag +hi def link htmlCssQuote htmlString +" end bugfix }}} + +" Legacy HTML 3-style color declarations (depcecated) {{{ +" Search https://www.w3.org/TR/html4/index/attributes.html for `%Color;` +" Technically, these must be named or #RRGGBB, but both FF and Chrome simply +" map it to CSS, supporting #RGB, #RGBA, and #RRGGBBAA (though alpha is ignored) +syn region htmlTag start=+<\s*body\s+ end=+>+ fold contains=htmlTagN,htmlString,htmlArg,htmlValue,htmlTagError,htmlEvent,htmlCssDefinition,@htmlPreproc,@htmlArgCluster,htmlTagBodyColors +syn keyword htmlTagBodyColors contained nextgroup=htmlLegacyColor text bgcolor link alink vlink +syn region htmlTag start=+<\s*\%(table\|t[rdh]\)\s+ end=+>+ fold contains=htmlTagN,htmlString,htmlArg,htmlValue,htmlTagError,htmlEvent,htmlCssDefinition,@htmlPreproc,@htmlArgCluster,htmlBgColors +syn keyword htmlBgColors contained nextgroup=htmlLegacyColor bgcolor +syn region htmlTag start=+<\s*\%(base\)\?font\s+ end=+>+ fold contains=htmlTagN,htmlString,htmlArg,htmlValue,htmlTagError,htmlEvent,htmlCssDefinition,@htmlPreproc,@htmlArgCluster,htmlFgColors +syn keyword htmlFgColors contained nextgroup=htmlLegacyColor color +syn region htmlLegacyColor contained start=+="+ end=+"+ contains=cssColor +syn region htmlLegacyColor contained start=+='+ end=+'+ contains=cssColor + +hi def link htmlTagBody htmlTagName +hi def link htmlTagBodyColors htmlArg +hi def link htmlBgColors htmlArg +hi def link htmlFgColors htmlArg +" end legacy HTML-3 color attributes }}} + +" apply colors within HTML style attributes, legacy HTML-3 attributes, and comments +call css_color#init('none', 'none', 'htmlCssContent,htmlLegacyColor,htmlCommentPart') From 42f7c034ecf3f23f96fb804d9a6c83e6a6465b69 Mon Sep 17 00:00:00 2001 From: Adam Katz <6454774+adamhotep@users.noreply.github.com> Date: Mon, 29 May 2023 17:17:19 -0400 Subject: [PATCH 12/21] HTML: tests for legacy HTML3 colors, etc --- tests/example.html | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tests/example.html diff --git a/tests/example.html b/tests/example.html new file mode 100644 index 0000000..fcc3437 --- /dev/null +++ b/tests/example.html @@ -0,0 +1,22 @@ + + + + + +

#faa

+ +

#ff0000

+ + +

Text that is red.

+ +

+ Here's a visited link + and an unvisited link. +

+ + From 5dda71306b853588fd66aa7436df28222ff4dcfc Mon Sep 17 00:00:00 2001 From: Adam Katz <6454774+adamhotep@users.noreply.github.com> Date: Mon, 29 May 2023 17:20:25 -0400 Subject: [PATCH 13/21] commented "solution" to coloring the `tan()` function --- autoload/css_color.vim | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/autoload/css_color.vim b/autoload/css_color.vim index ff993d3..0fd9d96 100644 --- a/autoload/css_color.vim +++ b/autoload/css_color.vim @@ -13,6 +13,10 @@ endif let s:_invalid = -9999 " used after bounding/wrapping, so this is safe +" Add open-parens as a keyword char to avoid coloring function names like tan(). +" This is ... not advised; it's unclear what it might break +"syn iskeyword @,40,48-57,_,192-255,- + function! s:bound(n, min, max) let n = a:n if n < a:min | let n = a:min From 1db0b4dc78456349b9bbf4a71f225e24dba69865 Mon Sep 17 00:00:00 2001 From: Adam Katz <6454774+adamhotep@users.noreply.github.com> Date: Mon, 29 May 2023 17:41:52 -0400 Subject: [PATCH 14/21] address the concern in ap/vim-css-color#127 by canonicalizing the path also made the default run (all test files) work from any directory --- tests/bench | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/bench b/tests/bench index aaa4336..48a0384 100755 --- a/tests/bench +++ b/tests/bench @@ -1,11 +1,12 @@ #!/bin/sh -set -e s=startuptime.txt -[ $# = 0 ] && set -- *.* # default to all files with a dot +this=$(realpath "$0" 2>/dev/null || readlink -f "$0") +[ $# = 0 ] && cd "${this%/*}" && set -- *.* # default to all files with a dot +target="${this%/tests/*}/after/syntax/css.vim" [ $# -gt 1 ] && multi=1 || multi= for sample in "$@"; do vim --startuptime $s -c qa "$sample" - run=$(awk '/\/after\/syntax\/css\.vim$/ {sum += $2} END {print sum}' "$s") + run=$(awk -v t="$target" 'index($0, t) {sum += $2} END {print sum}' "$s") rm $s echo "$run${multi:+\t$sample}" total="${total:-0} + ${run:-0}" From a6846bfc45413bd098d92a49c2f42939a4392165 Mon Sep 17 00:00:00 2001 From: Adam Katz <6454774+adamhotep@users.noreply.github.com> Date: Mon, 29 May 2023 23:56:33 -0400 Subject: [PATCH 15/21] fix ap/vim-css-color#140 Support non-percent saturation/luminance & whiteness/blackness in SASS and SCSS but prevent them in standard CSS --- autoload/css_color.vim | 5 +++-- tests/example.sass | 2 +- tests/example.scss | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/autoload/css_color.vim b/autoload/css_color.vim index 0fd9d96..fa2aadc 100644 --- a/autoload/css_color.vim +++ b/autoload/css_color.vim @@ -81,9 +81,10 @@ function! s:hsl2rgb(h,u,s,l) return rgb endfunction +" vet hsl and hwb values function! s:pctvet(h,s,l) - " for hsl & hwb, hue cannot be a percent, the others must be percents. - if a:h =~ "%$" || a:s !~ "%$" || a:l !~ "%$" + " hue cannot be a percent, others must be percents (except for sass & scss) + if a:h =~ "%$" || b:current_syntax !~ "s[ac]ss$" && (a:s !~ "%$" || a:l !~ "%$") return [s:_invalid, s:_invalid, s:_invalid] endif let [s,l] = map( [a:s, a:l], 'v:val >= 100 ? 1.0 : v:val / 100.0' ) diff --git a/tests/example.sass b/tests/example.sass index e1c8cd0..71cb87c 100644 --- a/tests/example.sass +++ b/tests/example.sass @@ -10,7 +10,7 @@ s !color1 = #359 !color2 = #335599 !color3 = rgba(144, 0, 0, .5) -!color4 = hsl(0, 100%, 50%) +!color4 = hsl(0, 100, 50) /* * #123, #456 diff --git a/tests/example.scss b/tests/example.scss index a93f4da..91b47fc 100644 --- a/tests/example.scss +++ b/tests/example.scss @@ -6,7 +6,7 @@ s { background: hsl(0, 100%, 50%) } $color1: #359; $color2: #335599; $color3: rgba(144, 0, 0, .5); -$color4: hsl(0, 100%, 50%); +$color4: hsl(0, 100, 50); /* * #123, #456 From e31df59c7358954ef98f291dfdd21e122726f521 Mon Sep 17 00:00:00 2001 From: Adam Katz <6454774+adamhotep@users.noreply.github.com> Date: Wed, 31 May 2023 20:42:21 -0400 Subject: [PATCH 16/21] html3 colors don't support color functions. Just names and 3/6-digit hex --- after/syntax/html.vim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/after/syntax/html.vim b/after/syntax/html.vim index 2d1f8a7..c2d51c9 100644 --- a/after/syntax/html.vim +++ b/after/syntax/html.vim @@ -14,16 +14,16 @@ hi def link htmlCssQuote htmlString " Legacy HTML 3-style color declarations (depcecated) {{{ " Search https://www.w3.org/TR/html4/index/attributes.html for `%Color;` -" Technically, these must be named or #RRGGBB, but both FF and Chrome simply -" map it to CSS, supporting #RGB, #RGBA, and #RRGGBBAA (though alpha is ignored) syn region htmlTag start=+<\s*body\s+ end=+>+ fold contains=htmlTagN,htmlString,htmlArg,htmlValue,htmlTagError,htmlEvent,htmlCssDefinition,@htmlPreproc,@htmlArgCluster,htmlTagBodyColors syn keyword htmlTagBodyColors contained nextgroup=htmlLegacyColor text bgcolor link alink vlink syn region htmlTag start=+<\s*\%(table\|t[rdh]\)\s+ end=+>+ fold contains=htmlTagN,htmlString,htmlArg,htmlValue,htmlTagError,htmlEvent,htmlCssDefinition,@htmlPreproc,@htmlArgCluster,htmlBgColors syn keyword htmlBgColors contained nextgroup=htmlLegacyColor bgcolor syn region htmlTag start=+<\s*\%(base\)\?font\s+ end=+>+ fold contains=htmlTagN,htmlString,htmlArg,htmlValue,htmlTagError,htmlEvent,htmlCssDefinition,@htmlPreproc,@htmlArgCluster,htmlFgColors syn keyword htmlFgColors contained nextgroup=htmlLegacyColor color -syn region htmlLegacyColor contained start=+="+ end=+"+ contains=cssColor -syn region htmlLegacyColor contained start=+='+ end=+'+ contains=cssColor +" The spec only supports named colors & hash-prefixed RGB hex with 3 or 6 chars. +" (Both FF & Chrome use IE's crazy "flex hex" formula to convert anything else to hex: +" https://scrappy-do.blogspot.com/2004/08/little-rant-about-microsoft-internet.html -- we're NOT doing that.) +syn match htmlLegacyColor contained +=\(['"]\)\%(#\x\{3\}\%(\x\{3\}\)\?\|[A-Za-z]\+\)\1+ contains=cssColor hi def link htmlTagBody htmlTagName hi def link htmlTagBodyColors htmlArg From ebde02ef45ed21bd427bcf654f644d3487b7c244 Mon Sep 17 00:00:00 2001 From: Adam Katz <6454774+adamhotep@users.noreply.github.com> Date: Sun, 27 Aug 2023 11:30:08 -0400 Subject: [PATCH 17/21] svg in html --- after/syntax/svg.vim | 11 +++++++++++ tests/example.svg | 11 +++++++++++ 2 files changed, 22 insertions(+) create mode 100644 after/syntax/svg.vim create mode 100644 tests/example.svg diff --git a/after/syntax/svg.vim b/after/syntax/svg.vim new file mode 100644 index 0000000..5f7d29b --- /dev/null +++ b/after/syntax/svg.vim @@ -0,0 +1,11 @@ +syn region xmlTag start=+<\s*\%(circle\|ellipse\|line\|path\|poly\%(gon\|line\)\|rect\|text\%(path\)\?\|tref\|tspan\)\s+ end=+>+ fold contains=xmlTagName,xmlAttrib,xmlEqual,xmlString,@xmlStartTagHook,htmlString,htmlArg,htmlValue,htmlTagError,htmlEvent,htmlCssDefinition,@htmlPreproc,@htmlArgCluster,svgAttrib +syn keyword svgAttrib contained containedin=xmlTag nextgroup=svgColor fill color stroke sop-color flood-color lighting-color +syn match svgColor contained +="[^"]\+"+ +syn match svgColor contained +='[^']\+'+ + +" the first item here is redundant for html (which loads this) but necessary for svg +hi def link xmlTag xmlTag +hi def link svgAttrib Type +hi def link svgColor String + +call css_color#init('css', 'extended', 'svgColor') diff --git a/tests/example.svg b/tests/example.svg new file mode 100644 index 0000000..4ec50e3 --- /dev/null +++ b/tests/example.svg @@ -0,0 +1,11 @@ + + + + + + + SVG + + From dbb7b157876553b1d48a55de1ebad0597bb6e49f Mon Sep 17 00:00:00 2001 From: Adam Katz <6454774+adamhotep@users.noreply.github.com> Date: Sun, 27 Aug 2023 12:23:42 -0400 Subject: [PATCH 18/21] upstream merge (manual) --- after/syntax/conf.vim | 1 + after/syntax/haskell.vim | 1 + after/syntax/toml.vim | 1 + 3 files changed, 3 insertions(+) create mode 100644 after/syntax/conf.vim create mode 100644 after/syntax/haskell.vim create mode 100644 after/syntax/toml.vim diff --git a/after/syntax/conf.vim b/after/syntax/conf.vim new file mode 100644 index 0000000..16517af --- /dev/null +++ b/after/syntax/conf.vim @@ -0,0 +1 @@ +call css_color#init('hex', 'basic', 'confComment,confString') diff --git a/after/syntax/haskell.vim b/after/syntax/haskell.vim new file mode 100644 index 0000000..e3b4e13 --- /dev/null +++ b/after/syntax/haskell.vim @@ -0,0 +1 @@ +call css_color#init('hex', 'none', 'haskellLineComment,haskellBlockComment,haskellString') diff --git a/after/syntax/toml.vim b/after/syntax/toml.vim new file mode 100644 index 0000000..1b48f7d --- /dev/null +++ b/after/syntax/toml.vim @@ -0,0 +1 @@ +call css_color#init('hex', 'basic', 'tomlComment,tomlCommentPart,tomlString') From a24b250934e6458dcc625bacd5dd15c3c3605ea5 Mon Sep 17 00:00:00 2001 From: Adam Katz <6454774+adamhotep@users.noreply.github.com> Date: Sun, 27 Aug 2023 12:24:44 -0400 Subject: [PATCH 19/21] upstream merge (manual) --- after/syntax/csh.vim | 6 +++--- after/syntax/css.vim | 2 +- after/syntax/kitty.vim | 2 +- after/syntax/less.vim | 2 +- after/syntax/rasi.vim | 6 +++--- after/syntax/sass.vim | 2 +- after/syntax/scss.vim | 2 +- after/syntax/sh.vim | 10 +++++----- after/syntax/stylus.vim | 2 +- after/syntax/tcsh.vim | 6 +++--- after/syntax/tmux.vim | 2 +- after/syntax/typescript.vim | 7 +++---- after/syntax/vim.vim | 2 +- after/syntax/zsh.vim | 6 +++--- 14 files changed, 28 insertions(+), 29 deletions(-) diff --git a/after/syntax/csh.vim b/after/syntax/csh.vim index 2ce84d0..d7bc87e 100644 --- a/after/syntax/csh.vim +++ b/after/syntax/csh.vim @@ -1,4 +1,4 @@ syn match cshCommentColor contained '\(#[^#]*\)\@<=\zs#\x\{3}\%(\x\{3}\)\?\>' containedin=cshComment -call css_color#init( 'hex', 'none' - \, 'cshDblQuote,cshSnglQuote,cshHereDoc,' - \. 'cshCommentColor' ) +call css_color#init('hex', 'none', + \ 'cshCommentColor,' . + \ 'cshDblQuote,cshSnglQuote,cshHereDoc') diff --git a/after/syntax/css.vim b/after/syntax/css.vim index 1b45f23..2b154bb 100644 --- a/after/syntax/css.vim +++ b/after/syntax/css.vim @@ -1 +1 @@ -call css_color#init('css', 'extended', 'cssMediaBlock,cssFunction,cssDefinition,cssAttrRegion,cssComment') +call css_color#init('css', 'extended', 'cssComment,cssMediaBlock,cssFunction,cssDefinition,cssAttrRegion') diff --git a/after/syntax/kitty.vim b/after/syntax/kitty.vim index 94dd425..4d7e0f0 100644 --- a/after/syntax/kitty.vim +++ b/after/syntax/kitty.vim @@ -1 +1 @@ -call css_color#init('hex', 'none', 'kittyColor,kittyComment') +call css_color#init('hex', 'none', 'kittyComment,kittyColor') diff --git a/after/syntax/less.vim b/after/syntax/less.vim index 0f39b91..3e77739 100644 --- a/after/syntax/less.vim +++ b/after/syntax/less.vim @@ -5,4 +5,4 @@ " lessVariableValue | lessDefinition | cssComment | lessComment | https://github.com/groenewege/vim-less " lessVariableDefinition | cssDefinition | cssComment | lessComment | https://github.com/lunaru/vim-less -call css_color#init('css', 'extended', 'lessVariableValue,lessVariableDefinition,lessDefinition,lessCssAttribute,lessAttribute,cssDefinition,cssComment,lessCssComment,lessComment') +call css_color#init('css', 'extended', 'lessComment,lessCssComment,cssComment,lessVariableValue,lessVariableDefinition,lessDefinition,lessCssAttribute,lessAttribute,cssDefinition') diff --git a/after/syntax/rasi.vim b/after/syntax/rasi.vim index 103a9ea..de0c90c 100644 --- a/after/syntax/rasi.vim +++ b/after/syntax/rasi.vim @@ -1,4 +1,4 @@ " https://github.com/Fymyte/rasi.vim -call css_color#init('css', 'extended' - \, 'rasiHexColor,rasiRGBColor,rasiRGBAColor,rasiHSLColor,rasiHSLAColor,rasiNamedColor' - \. ',rasiPropertyVal,rasiComment,rasiCommentL,rasiEnvVar,rasiVarReference') +call css_color#init('css', 'extended', + \ 'rasiComment,rasiCommentL,rasiPropertyVal,rasiEnvVar,rasiVarReference,' . + \ 'rasiHexColor,rasiRGBColor,rasiRGBAColor,rasiHSLColor,rasiHSLAColor,rasiNamedColor') diff --git a/after/syntax/sass.vim b/after/syntax/sass.vim index 79f8bc0..9aa653a 100644 --- a/after/syntax/sass.vim +++ b/after/syntax/sass.vim @@ -1 +1 @@ -call css_color#init('css', 'extended', 'sassCssAttribute,sassComment,sassCssComment') +call css_color#init('css', 'extended', 'sassComment,sassCssComment,sassCssAttribute') diff --git a/after/syntax/scss.vim b/after/syntax/scss.vim index 57569b1..b34a17f 100644 --- a/after/syntax/scss.vim +++ b/after/syntax/scss.vim @@ -1 +1 @@ -call css_color#init('css', 'extended', 'scssAttribute,scssComment,scssVariableValue,scssMap,scssMapValue,sassCssAttribute,cssComment') +call css_color#init('css', 'extended', 'scssComment,cssComment,scssAttribute,scssVariableValue,scssMap,scssMapValue,sassCssAttribute') diff --git a/after/syntax/sh.vim b/after/syntax/sh.vim index 8d7d618..fefa3c3 100644 --- a/after/syntax/sh.vim +++ b/after/syntax/sh.vim @@ -1,6 +1,6 @@ syn match shCommentColor contained '\(#[^#]*\)\@<=\zs#\x\{3}\%(\x\{3}\)\?\>' containedin=shQuickComment,shBQComment,shComment -call css_color#init( 'hex', 'none' - \, 'shSingleQuote,shDoubleQuote,shHereDoc,' - \. 'shTestSingleQuote,shTestDoubleQuote,' - \. 'shEchoQuote,shEmbeddedEcho,shEcho,' - \. 'shCommentColor' ) +call css_color#init('hex', 'none', + \ 'shCommentColor,' . + \ 'shEchoQuote,shEmbeddedEcho,shEcho,' . + \ 'shTestSingleQuote,shTestDoubleQuote,' . + \ 'shSingleQuote,shDoubleQuote,shHereDoc') diff --git a/after/syntax/stylus.vim b/after/syntax/stylus.vim index 0aca85e..23e124f 100644 --- a/after/syntax/stylus.vim +++ b/after/syntax/stylus.vim @@ -1 +1 @@ -call css_color#init('css', 'extended', 'stylusCssAttribute,stylusComment,cssComment') +call css_color#init('css', 'extended', 'stylusComment,cssComment,stylusCssAttribute') diff --git a/after/syntax/tcsh.vim b/after/syntax/tcsh.vim index ce7db7d..cddcc74 100644 --- a/after/syntax/tcsh.vim +++ b/after/syntax/tcsh.vim @@ -1,4 +1,4 @@ syn match tcshCommentColor contained '\(#[^#]*\)\@<=\zs#\x\{3}\%(\x\{3}\)\?\>' containedin=tcshComment -call css_color#init( 'hex', 'none' - \, 'tcshSQuote,tcshDQuote,tcshHereDoc,' - \. 'tcshCommentColor' ) +call css_color#init('hex', 'none', + \ 'tcshCommentColor,' . + \ 'tcshSQuote,tcshDQuote,tcshHereDoc' ) diff --git a/after/syntax/tmux.vim b/after/syntax/tmux.vim index 666f16c..ecdf3e5 100644 --- a/after/syntax/tmux.vim +++ b/after/syntax/tmux.vim @@ -1 +1 @@ -call css_color#init('css', 'none', 'tmuxString,tmuxComment') +call css_color#init('css', 'none', 'tmuxComment,tmuxString') diff --git a/after/syntax/typescript.vim b/after/syntax/typescript.vim index 301425d..b08b4d3 100644 --- a/after/syntax/typescript.vim +++ b/after/syntax/typescript.vim @@ -1,6 +1,5 @@ " https://github.com/HerringtonDarkholme/yats.vim (stock Vim syntax) " https://github.com/leafgarland/typescript-vim -call css_color#init('css', 'extended' - \, 'typescriptString,typescriptStringProperty,typescriptStringS,typescriptStringD,typescriptStringB,' - \. 'typescriptComment,typescriptLineComment,typescriptCommentSkip,typescriptDocComment' - \) +call css_color#init('css', 'extended', + \ 'typescriptComment,typescriptLineComment,typescriptCommentSkip,typescriptDocComment,' . + \ 'typescriptString,typescriptStringProperty,typescriptStringS,typescriptStringD,typescriptStringB') diff --git a/after/syntax/vim.vim b/after/syntax/vim.vim index bcb1986..3f06e99 100644 --- a/after/syntax/vim.vim +++ b/after/syntax/vim.vim @@ -1 +1 @@ -call css_color#init('hex', 'none', 'vimHiGuiRgb,vimString,vimComment,vimLineComment') +call css_color#init('hex', 'none', 'vimComment,vimLineComment,vimString,vimHiGuiRgb') diff --git a/after/syntax/zsh.vim b/after/syntax/zsh.vim index 8f89ebb..9ff6678 100644 --- a/after/syntax/zsh.vim +++ b/after/syntax/zsh.vim @@ -1,4 +1,4 @@ syn match zshCommentColor contained '\(#[^#]*\)\@<=\zs#\x\{3}\%(\x\{3}\)\?\>' containedin=zshComment -call css_color#init( 'hex', 'none' - \, 'zshString,zshPOSIXString,zshHereDoc,' - \. 'zshCommentColor' ) +call css_color#init('hex', 'none', + \ 'zshCommentColor,' . + \ 'zshString,zshPOSIXString,zshHereDoc') From 474336626a858bbc8832bc80a1a27c04cfc4454e Mon Sep 17 00:00:00 2001 From: Adam Katz <6454774+adamhotep@users.noreply.github.com> Date: Sun, 27 Aug 2023 12:25:52 -0400 Subject: [PATCH 20/21] svg in html --- after/syntax/html.vim | 33 ++++++++++++++++++++------------- after/syntax/svg.vim | 2 -- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/after/syntax/html.vim b/after/syntax/html.vim index c2d51c9..ad92905 100644 --- a/after/syntax/html.vim +++ b/after/syntax/html.vim @@ -1,35 +1,42 @@ " default html syntax should already be including the css syntax " but tag style attributes don't properly apply CSS syntax (as of vim 9.0.1378). " Correct the bug by replacing htmlCssDefinition with a new htmlCssContent: {{{ -syn keyword htmlCssArg contained containedin=htmlTag nextgroup=htmlCssEq style -syn match htmlCssEq contained +=+ nextgroup=htmlCssQuote -syn match htmlCssQuote contained +["']+ nextgroup=htmlCssContent -syn region htmlCssContent contained start=+\%("\)\@<=.+ end=+"+ keepend contains=cssTagName,cssAttributeSelector,cssClassName,cssIdentifier,cssAtRule,cssAttrRegion,css.*Prop,cssComment,cssValue.*,cssColor,cssURL,cssImportant,cssCustomProp,cssError,cssStringQ,cssFunction,cssUnicodeEscape,cssVendor,cssHacks,cssNoise -syn region htmlCssContent contained start=+\%('\)\@<=.+ end=+'+ keepend contains=cssTagName,cssAttributeSelector,cssClassName,cssIdentifier,cssAtRule,cssAttrRegion,css.*Prop,cssComment,cssValue.*,cssColor,cssURL,cssImportant,cssCustomProp,cssError,cssStringQ,cssFunction,cssUnicodeEscape,cssVendor,cssHacks,cssNoise +syn keyword htmlCssArg contained containedin=htmlTag nextgroup=htmlCssEq style +syn match htmlCssEq contained +=+ nextgroup=htmlCssQuote +syn match htmlCssQuote contained +["']+ nextgroup=htmlCssContent +syn region htmlCssContent contained start=+\%("\)\@<=.+ end=+"+ keepend contains=cssTagName,cssAttributeSelector,cssClassName,cssIdentifier,cssAtRule,cssAttrRegion,css.*Prop,cssComment,cssValue.*,cssColor,cssURL,cssImportant,cssCustomProp,cssError,cssStringQ,cssFunction,cssUnicodeEscape,cssVendor,cssHacks,cssNoise +syn region htmlCssContent contained start=+\%('\)\@<=.+ end=+'+ keepend contains=cssTagName,cssAttributeSelector,cssClassName,cssIdentifier,cssAtRule,cssAttrRegion,css.*Prop,cssComment,cssValue.*,cssColor,cssURL,cssImportant,cssCustomProp,cssError,cssStringQ,cssFunction,cssUnicodeEscape,cssVendor,cssHacks,cssNoise hi def link htmlCssArg htmlArg hi def link htmlCssEq htmlTag hi def link htmlCssQuote htmlString " end bugfix }}} +call css_color#init('css', 'extended', 'htmlCssContent,htmlCommentPart') + +" SVG in HTML +"syn keyword htmlTagName contained svg text textPath tspan +syn include @htmlSvgColors after/syntax/svg.vim +syn region htmlSvg start=+<\s*svg\>+ end=+<\s*/svg\s*>+ keepend contains=@htmlXml,htmlTagName,@htmlSvgColors + " Legacy HTML 3-style color declarations (depcecated) {{{ " Search https://www.w3.org/TR/html4/index/attributes.html for `%Color;` -syn region htmlTag start=+<\s*body\s+ end=+>+ fold contains=htmlTagN,htmlString,htmlArg,htmlValue,htmlTagError,htmlEvent,htmlCssDefinition,@htmlPreproc,@htmlArgCluster,htmlTagBodyColors +syn region htmlTag start=+<\s*body\s+ end=+>+ fold contains=htmlTagN,htmlString,htmlArg,htmlValue,htmlTagError,htmlEvent,htmlCssDefinition,@htmlPreproc,@htmlArgCluster,htmlTagBodyColors syn keyword htmlTagBodyColors contained nextgroup=htmlLegacyColor text bgcolor link alink vlink -syn region htmlTag start=+<\s*\%(table\|t[rdh]\)\s+ end=+>+ fold contains=htmlTagN,htmlString,htmlArg,htmlValue,htmlTagError,htmlEvent,htmlCssDefinition,@htmlPreproc,@htmlArgCluster,htmlBgColors +syn region htmlTag start=+<\s*\%(table\|t[rdh]\)\s+ end=+>+ fold contains=htmlTagN,htmlString,htmlArg,htmlValue,htmlTagError,htmlEvent,htmlCssDefinition,@htmlPreproc,@htmlArgCluster,htmlBgColors syn keyword htmlBgColors contained nextgroup=htmlLegacyColor bgcolor -syn region htmlTag start=+<\s*\%(base\)\?font\s+ end=+>+ fold contains=htmlTagN,htmlString,htmlArg,htmlValue,htmlTagError,htmlEvent,htmlCssDefinition,@htmlPreproc,@htmlArgCluster,htmlFgColors -syn keyword htmlFgColors contained nextgroup=htmlLegacyColor color +syn region htmlTag start=+<\s*\%(base\)\?font\s+ end=+>+ fold contains=htmlTagN,htmlString,htmlArg,htmlValue,htmlTagError,htmlEvent,htmlCssDefinition,@htmlPreproc,@htmlArgCluster,htmlFgColors +syn keyword htmlFgColors contained nextgroup=htmlLegacyColor color " The spec only supports named colors & hash-prefixed RGB hex with 3 or 6 chars. " (Both FF & Chrome use IE's crazy "flex hex" formula to convert anything else to hex: " https://scrappy-do.blogspot.com/2004/08/little-rant-about-microsoft-internet.html -- we're NOT doing that.) +" BUG: I should have been able to specify this as +="[^"]\+"+ and +="[^"]\+"+ and set what +" matches with the args to css_color#init(), but that doesn't seem to work (overridden?) syn match htmlLegacyColor contained +=\(['"]\)\%(#\x\{3\}\%(\x\{3\}\)\?\|[A-Za-z]\+\)\1+ contains=cssColor -hi def link htmlTagBody htmlTagName hi def link htmlTagBodyColors htmlArg hi def link htmlBgColors htmlArg hi def link htmlFgColors htmlArg -" end legacy HTML-3 color attributes }}} -" apply colors within HTML style attributes, legacy HTML-3 attributes, and comments -call css_color#init('none', 'none', 'htmlCssContent,htmlLegacyColor,htmlCommentPart') +call css_color#init('hex', 'extended', 'htmlLegacyColor') +" end legacy HTML-3 color attributes }}} diff --git a/after/syntax/svg.vim b/after/syntax/svg.vim index 5f7d29b..ceeda61 100644 --- a/after/syntax/svg.vim +++ b/after/syntax/svg.vim @@ -3,8 +3,6 @@ syn keyword svgAttrib contained containedin=xmlTag nextgroup=svgColor fill color syn match svgColor contained +="[^"]\+"+ syn match svgColor contained +='[^']\+'+ -" the first item here is redundant for html (which loads this) but necessary for svg -hi def link xmlTag xmlTag hi def link svgAttrib Type hi def link svgColor String From dd893908259fa8f954afde0970918b0ea5cff374 Mon Sep 17 00:00:00 2001 From: Adam Katz <6454774+adamhotep@users.noreply.github.com> Date: Sun, 27 Aug 2023 14:09:58 -0400 Subject: [PATCH 21/21] svg comment tests --- tests/example.svg | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/example.svg b/tests/example.svg index 4ec50e3..bb19de4 100644 --- a/tests/example.svg +++ b/tests/example.svg @@ -7,5 +7,8 @@ SVG +