MCPcopy Create free account
hub / github.com/streamlit/streamlit / validate_material_icon

Function validate_material_icon

lib/streamlit/string_util.py:93–132  ·  view source on GitHub ↗

Validate a Material icon shortcode and return the icon in normalized format if valid.

(maybe_material_icon: str | None)

Source from the content-addressed store, hash-verified

91
92
93def validate_material_icon(maybe_material_icon: str | None) -> str:
94 """Validate a Material icon shortcode and return the icon in
95 normalized format if valid.
96 """
97
98 supported_icon_packs = [
99 "material",
100 ]
101
102 if maybe_material_icon is None:
103 return ""
104
105 icon_regex = r"^\s*:(.+)\/(.+):\s*$"
106 icon_match = re.match(icon_regex, maybe_material_icon)
107 # Since our markdown processing needs to change the `/` to `_` in order to
108 # correctly render the icon, we need to add a zero-width space before the
109 # `/` to avoid this transformation here.
110 invisible_white_space = "\u200b"
111
112 if not icon_match:
113 raise StreamlitAPIException(
114 f'The value `"{maybe_material_icon.replace("/", invisible_white_space + "/")}"` is '
115 "not a valid Material icon. Please use a Material icon shortcode like "
116 f"**`:material{invisible_white_space}/thumb_up:`**"
117 )
118
119 pack_name, icon_name = icon_match.groups()
120
121 if (
122 pack_name not in supported_icon_packs
123 or not icon_name
124 or not is_material_icon(icon_name)
125 ):
126 raise StreamlitAPIException(
127 f'The value `"{maybe_material_icon.replace("/", invisible_white_space + "/")}"` is not a '
128 "valid Material icon. Please use a Material icon shortcode like "
129 f"**`:material{invisible_white_space}/thumb_up:`**."
130 )
131
132 return f":{pack_name}/{icon_name}:"
133
134
135def extract_leading_emoji(text: str) -> tuple[str, str]:

Callers 6

_get_favicon_stringFunction · 0.90
_process_logo_imageFunction · 0.90
LinkColumnFunction · 0.90
_process_avatar_inputFunction · 0.90
validate_icon_or_emojiFunction · 0.85
extract_leading_iconFunction · 0.85

Calls 2

is_material_iconFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…