Skip to content

Commit 224bfe7

Browse files
committed
small update
1 parent 0abb8d8 commit 224bfe7

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

html4docx/utils.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,20 @@ def parse_dict_string(string: str, separator: str = ";"):
9595

9696
def add_px(value):
9797
"""
98-
Append 'px' to numeric values (int, float, or numeric strings).
99-
Leaves values with units or non-numeric strings unchanged.
98+
Append 'px' only if the value is purely numeric (int, float, or numeric string).
99+
If there is any non-numeric character, return the original value unchanged.
100100
"""
101101
if isinstance(value, (int, float)):
102102
return f"{value}px"
103103

104104
if isinstance(value, str):
105105
stripped = value.strip()
106-
try:
107-
float(stripped)
106+
107+
# Check if it's a valid number (integer or float)
108+
if stripped.replace(".", "", 1).isdigit():
108109
return f"{stripped}px"
109-
except ValueError:
110-
return value
110+
111+
return value
111112

112113
return value
113114

0 commit comments

Comments
 (0)