mirror of
https://github.com/NicklasVraa/Color-manager.git
synced 2026-01-18 17:27:20 +01:00
fix: expand rgb colors along with rgba colors
This commit is contained in:
@@ -156,12 +156,22 @@ def expand_css_rgba(match) -> str:
|
||||
int(match.group(3)), float(match.group(4))
|
||||
))
|
||||
|
||||
def expand_css_rgb(match) -> str:
|
||||
""" Used by the css_to_hex function. """
|
||||
return rgb_to_hex((
|
||||
int(match.group(1)), int(match.group(2)),
|
||||
int(match.group(3)))
|
||||
)
|
||||
|
||||
def css_to_hex(text:str) -> str:
|
||||
""" Returns the given string with css rgba functions and named colors substituted for their corresponding hexadecimal codes. """
|
||||
|
||||
text = re.sub(r"rgba\((\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*([\d.]+)\)",
|
||||
expand_css_rgba, text)
|
||||
|
||||
text = re.sub(r"rgb\((\d+)\s*,\s*(\d+)\s*,\s*(\d+)\)",
|
||||
expand_css_rgb, text)
|
||||
|
||||
for key in name_to_hex_dict:
|
||||
text = re.sub(key + r"\b", name_to_hex_dict[key], text)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user