Skip to content

Commit 72b0c41

Browse files
committed
2.3.x
1 parent 736702a commit 72b0c41

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

pandas/io/formats/css.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@
1919
Iterator,
2020
)
2121

22+
def _lowercase_outside_quotes(value: str) -> str:
23+
parts = re.split(r'(".*?")', value)
24+
new_parts = []
25+
for part in parts:
26+
if part.startswith('"') and part.endswith('"'):
27+
new_parts.append(part) # preserve case
28+
else:
29+
new_parts.append(part.lower())
30+
return ''.join(new_parts)
31+
2232

2333
def _side_expander(prop_fmt: str) -> Callable:
2434
"""
@@ -391,7 +401,7 @@ def _error() -> str:
391401
def atomize(self, declarations: Iterable) -> Generator[tuple[str, str]]:
392402
for prop, value in declarations:
393403
prop = prop.lower()
394-
value = value.lower()
404+
value = _lowercase_outside_quotes(value)
395405
if prop in self.CSS_EXPANSIONS:
396406
expand = self.CSS_EXPANSIONS[prop]
397407
yield from expand(self, prop, value)
@@ -414,7 +424,8 @@ def parse(self, declarations_str: str) -> Iterator[tuple[str, str]]:
414424
prop, sep, val = decl.partition(":")
415425
prop = prop.strip().lower()
416426
# TODO: don't lowercase case sensitive parts of values (strings)
417-
val = val.strip().lower()
427+
raw_val = val.strip()
428+
val = _lowercase_outside_quotes(raw_val)
418429
if sep:
419430
yield prop, val
420431
else:

0 commit comments

Comments
 (0)