Skip to content

Commit ce3cb54

Browse files
committed
Fix emoji generator path in mkdocs.yml and add hex color validation in color_utils.py
1 parent 9f31e77 commit ce3cb54

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ markdown_extensions:
4747
- attr_list
4848
- pymdownx.emoji:
4949
emoji_index: !!python/name:material.extensions.emoji.twemoji
50-
emoji_generator: !!python/name:materialx.emoji.to_svg
50+
emoji_generator: !!python/name:material.extensions.emoji.to_svg
5151

5252
copyright: |
5353
&copy; 2023 <a href="https://github.com/MatteoFasulo" target="_blank" rel="noopener">Matteo Fasulo</a>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,32 @@
1+
import re
2+
3+
4+
def validate_hex_color(color: str) -> bool:
5+
"""Validate if the input string is a valid hex color."""
6+
pattern = r"^#?([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$"
7+
return bool(re.match(pattern, color))
8+
9+
110
def rgb_to_bgr(rgb: str) -> str:
211
"""Convert RGB hex to BGR hex."""
12+
# Validate input length
13+
if len(rgb) != 6 and len(rgb) != 7:
14+
raise ValueError("RGB hex must be 6 or 7 characters long (including #).")
15+
16+
# Validate hex characters
17+
match = validate_hex_color(rgb)
18+
19+
if not match:
20+
raise ValueError("Invalid RGB hex format.")
21+
322
if rgb.startswith("#"):
423
rgb = rgb[1:]
524
r, g, b = rgb[0:2], rgb[2:4], rgb[4:6]
625
return b + g + r
26+
27+
28+
if __name__ == "__main__":
29+
# Example usage
30+
rgb_color = "#1A2B3C"
31+
bgr_color = rgb_to_bgr(rgb_color)
32+
print(f"RGB: {rgb_color} -> BGR: #{bgr_color}")

0 commit comments

Comments
 (0)