Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions pandas/io/formats/css.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@
)


def _lowercase_outside_quotes(value: str) -> str:
parts = re.split(r'(".*?")', value)
new_parts = []
for part in parts:
if part.startswith('"') and part.endswith('"'):
new_parts.append(part) # preserve case
else:
new_parts.append(part.lower())
return "".join(new_parts)


def _side_expander(prop_fmt: str) -> Callable:
"""
Wrapper to expand shorthand property into top, right, bottom, left properties
Expand Down Expand Up @@ -391,7 +402,7 @@ def _error() -> str:
def atomize(self, declarations: Iterable) -> Generator[tuple[str, str]]:
for prop, value in declarations:
prop = prop.lower()
value = value.lower()
value = _lowercase_outside_quotes(value)
if prop in self.CSS_EXPANSIONS:
expand = self.CSS_EXPANSIONS[prop]
yield from expand(self, prop, value)
Expand All @@ -414,7 +425,8 @@ def parse(self, declarations_str: str) -> Iterator[tuple[str, str]]:
prop, sep, val = decl.partition(":")
prop = prop.strip().lower()
# TODO: don't lowercase case sensitive parts of values (strings)
val = val.strip().lower()
raw_val = val.strip()
val = _lowercase_outside_quotes(raw_val)
if sep:
yield prop, val
else:
Expand Down
Loading