enyancc / vscode-ext-color-highlight

Extension adds colored border around css/web colors in the editor
GNU General Public License v3.0
262 stars 83 forks source link

Match for R,G,B without the rgb()/rgba() format #120

Closed ferretwithaberet closed 3 years ago

ferretwithaberet commented 3 years ago

Description

Ability to detect RGB colors like "255,255,255" or "255, 255, 255" which do not explicitly have the rgb() or rgba() format. There should be a setting for these. (I know it might bork inside arrays with 3 or more numbers).

My ideea would be that it would always detect the color if it is inside of a string, so "255,255,255", '255, 255, 255'.

And the addition of another setting called color-highlight.matchInCodeLanguages which would be a list of languages like color-highlight.languages to let you select the languages you want it to try to match the colors in the actual code. If possible, you could ignore arrays that have less than or more than 3 elements.

Examples

If I would set color-highlight.matchInCodeLanguages to ['javascript']:

const color1 = [255, 255, 255]  // The `255, 255, 255` part will be colored

const color3 = [255, 255]  // Nothing will match
const color4 = [255, 255, 255, 255]  // Nothing will match

A great use case would be for KDE Plasma's .color files, used for color schemes, which look like:

[Colors:Button]
BackgroundAlternate=64,69,82
BackgroundNormal=28,33,36
DecorationFocus=246,126,125
DecorationHover=246,126,125
ForegroundActive=61,174,233
ForegroundInactive=118,119,122
ForegroundLink=41,128,185
ForegroundNegative=246,126,125
ForegroundNeutral=247,159,121
ForegroundNormal=208,209,212
ForegroundPositive=202,231,185
ForegroundVisited=82,148,226
ferretwithaberet commented 3 years ago

I forked this repo and added this feature, it is not tested extensively and might never be, the feature does not work exactly like I explained in this issue but it is good enough at the moment to fulfill my needs. You can see my changes in this commit.