From 78165115c5b2b5561dcb67184cc8c0b5ed0da608 Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Wed, 1 Oct 2025 15:15:59 -0400 Subject: [PATCH 1/3] Add the opt_css() method --- great_tables/_options.py | 97 +++++++++++++++++++++++++++++++++++++++- great_tables/_scss.py | 10 +++-- great_tables/gt.py | 2 + 3 files changed, 104 insertions(+), 5 deletions(-) diff --git a/great_tables/_options.py b/great_tables/_options.py index f4ab0fc8a..cda1ed20d 100644 --- a/great_tables/_options.py +++ b/great_tables/_options.py @@ -22,7 +22,7 @@ def tab_options( table_margin_left: str | None = None, table_margin_right: str | None = None, table_background_color: str | None = None, - table_additional_css: list[str] | None = None, + table_additional_css: str | list[str] | None = None, table_font_names: str | list[str] | None = None, table_font_size: str | None = None, table_font_weight: str | int | float | None = None, @@ -553,6 +553,11 @@ def tab_options( if isinstance(modified_args["table_font_names"], str): modified_args["table_font_names"] = [modified_args["table_font_names"]] + # - `table_additional_css` should be a list but if given as a string, ensure it is list + if "table_additional_css" in modified_args: + if isinstance(modified_args["table_additional_css"], str): + modified_args["table_additional_css"] = [modified_args["table_additional_css"]] + new_options_info = { k: replace(getattr(self._options, k), value=v) for k, v in modified_args.items() } @@ -1427,6 +1432,96 @@ def dict_omit_keys(dict: dict[str, str], omit_keys: set[str]) -> dict[str, str]: return res +def opt_css( + self: GTSelf, + css: str, + add: bool = True, + allow_duplicates: bool = False, +) -> GTSelf: + """ + Option to add custom CSS for the table. + + `opt_css()` makes it possible to add extra CSS rules to a table. This CSS will be added after + the compiled CSS that Great Tables generates automatically when the object is transformed to an + HTML output table. + + Parameters + ---------- + css + The CSS to include as part of the rendered table's `