From 8e57cb6df374a0f366373247602ec935bd7e02e9 Mon Sep 17 00:00:00 2001
From: dheerusri324 <121012dheeraj@gmail.com>
Date: Sat, 28 Feb 2026 15:09:59 +0530
Subject: [PATCH 1/3] Enhance color validation in Icon class
Added validation for hex color codes in Icon class.
---
folium/map.py | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/folium/map.py b/folium/map.py
index 90fb205c23..ac15bd0c42 100644
--- a/folium/map.py
+++ b/folium/map.py
@@ -353,9 +353,13 @@ def __init__(
):
super().__init__()
self._name = "Icon"
- if color not in self.color_options:
+
+ # Check if the color is a valid hex code
+ is_hex_color = color.startswith("#") and len(color) in (4, 7)
+
+ if color not in self.color_options and not is_hex_color:
warnings.warn(
- f"color argument of Icon should be one of: {self.color_options}.",
+ f"color argument of Icon should be one of: {self.color_options} or a valid hex color (e.g., '#FF0000').",
stacklevel=2,
)
self.options = remove_empty(
From 6bc163f9a7020af24dcdf1d5b6164d48cbdb526e Mon Sep 17 00:00:00 2001
From: dheerusri324 <121012dheeraj@gmail.com>
Date: Sat, 28 Feb 2026 15:20:42 +0530
Subject: [PATCH 2/3] Enhance Icon class with hex color support
Added dynamic CSS for hex color markers and improved color validation.
---
folium/map.py | 44 +++++++++++++++++++++++++++++++++++++++-----
1 file changed, 39 insertions(+), 5 deletions(-)
diff --git a/folium/map.py b/folium/map.py
index ac15bd0c42..04ce6b36f9 100644
--- a/folium/map.py
+++ b/folium/map.py
@@ -319,6 +319,33 @@ class Icon(MacroElement):
{{ this.options|tojavascript }}
);
{% endmacro %}
+
+ {% macro header(this, kwargs) %}
+ {% if this.is_hex %}
+
+ {% endif %}
+ {% endmacro %}
""")
color_options = {
"red",
@@ -354,16 +381,23 @@ def __init__(
super().__init__()
self._name = "Icon"
- # Check if the color is a valid hex code
- is_hex_color = color.startswith("#") and len(color) in (4, 7)
+ # 1. Determine if the input is a hex color
+ self.is_hex = color.startswith("#") and len(color) in (4, 7)
+ self.color = color
- if color not in self.color_options and not is_hex_color:
+ # 2. Strip the '#' for the CSS class name generation
+ self.color_name = color[1:] if self.is_hex else color
+
+ # 3. Allow hex codes to pass the warning check
+ if color not in self.color_options and not self.is_hex:
warnings.warn(
- f"color argument of Icon should be one of: {self.color_options} or a valid hex color (e.g., '#FF0000').",
+ f"color argument of Icon should be one of: {self.color_options} or a valid hex code.",
stacklevel=2,
)
+
+ # 4. Pass the stripped color_name to the JavaScript options
self.options = remove_empty(
- marker_color=color,
+ marker_color=self.color_name,
icon_color=icon_color,
icon=icon,
prefix=prefix,
From 45db09bfea9ef6476a8597cdef240dc52788dcfa Mon Sep 17 00:00:00 2001
From: "pre-commit-ci[bot]"
<66853113+pre-commit-ci[bot]@users.noreply.github.com>
Date: Thu, 23 Apr 2026 19:48:39 +0000
Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
---
folium/map.py | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/folium/map.py b/folium/map.py
index 04ce6b36f9..011025b6a4 100644
--- a/folium/map.py
+++ b/folium/map.py
@@ -319,7 +319,7 @@ class Icon(MacroElement):
{{ this.options|tojavascript }}
);
{% endmacro %}
-
+
{% macro header(this, kwargs) %}
{% if this.is_hex %}