From 91c210e97adb4dece3be37905d3373d98409a215 Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Fri, 15 Dec 2023 12:09:31 -0500 Subject: [PATCH 1/3] Fix `re.sub()` stmt so match/replacement occurs --- great_tables/_scss.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/great_tables/_scss.py b/great_tables/_scss.py index d83f62358..a6e077c93 100644 --- a/great_tables/_scss.py +++ b/great_tables/_scss.py @@ -138,7 +138,7 @@ def compile_scss(data: GTData, id: Optional[str], compress: bool = True) -> str: if has_id: compiled_css = re.sub(r"\.gt_", f"#{id} .gt_", compiled_css, 0, re.MULTILINE) compiled_css = re.sub(r"thead", f"#{id} thead", compiled_css, 0, re.MULTILINE) - compiled_css = re.sub(r"^p \{", f"#{id} p " + "{", compiled_css, 0, re.MULTILINE) + compiled_css = re.sub(r"^ p \{", f" #{id} p " + "{", compiled_css, 0, re.MULTILINE) finalized_css = f"{gt_table_class_str}\n\n{compiled_css}" From 989a1d54e39846abf94ea527f8afc497bed4db54 Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Fri, 15 Dec 2023 12:18:58 -0500 Subject: [PATCH 2/3] Modify regex for both pathways --- great_tables/_scss.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/great_tables/_scss.py b/great_tables/_scss.py index a6e077c93..5499cf00e 100644 --- a/great_tables/_scss.py +++ b/great_tables/_scss.py @@ -138,7 +138,10 @@ def compile_scss(data: GTData, id: Optional[str], compress: bool = True) -> str: if has_id: compiled_css = re.sub(r"\.gt_", f"#{id} .gt_", compiled_css, 0, re.MULTILINE) compiled_css = re.sub(r"thead", f"#{id} thead", compiled_css, 0, re.MULTILINE) - compiled_css = re.sub(r"^ p \{", f" #{id} p " + "{", compiled_css, 0, re.MULTILINE) + if compress: + compiled_css = re.sub(r"^ p \{", f" #{id} p " + "{", compiled_css, 0, re.MULTILINE) + else: + compiled_css = re.sub(r"^p \{", f"#{id} p " + "{", compiled_css, 0, re.MULTILINE) finalized_css = f"{gt_table_class_str}\n\n{compiled_css}" From 07a546b569b894b35537d3b03a495e3ed6a3e8a7 Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Fri, 15 Dec 2023 16:01:32 -0500 Subject: [PATCH 3/3] Refactor regex replacement statements --- great_tables/_scss.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/great_tables/_scss.py b/great_tables/_scss.py index 5499cf00e..4f1d87730 100644 --- a/great_tables/_scss.py +++ b/great_tables/_scss.py @@ -138,10 +138,7 @@ def compile_scss(data: GTData, id: Optional[str], compress: bool = True) -> str: if has_id: compiled_css = re.sub(r"\.gt_", f"#{id} .gt_", compiled_css, 0, re.MULTILINE) compiled_css = re.sub(r"thead", f"#{id} thead", compiled_css, 0, re.MULTILINE) - if compress: - compiled_css = re.sub(r"^ p \{", f" #{id} p " + "{", compiled_css, 0, re.MULTILINE) - else: - compiled_css = re.sub(r"^p \{", f"#{id} p " + "{", compiled_css, 0, re.MULTILINE) + compiled_css = re.sub(r"^( p|p) \{", f"#{id} p {{", compiled_css, 0, re.MULTILINE) finalized_css = f"{gt_table_class_str}\n\n{compiled_css}"