-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure that ID value in compiled CSS is applied to all rules #92
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left a suggestion for condensing into a single regex, but feel free to merge if you'd rather keep as is!
great_tables/_scss.py
Outdated
@@ -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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this could be condensed into a single regex?
re.sub(r"^( p|p) \{", f" #{id} p {{", compiled_css, 0, re.MULTILINE)
The main difference is using ^( p|p)
to capture that the difference is whether people has a space or not.
Here's how I tested:
f = lambda x, id="ABC": re.sub(r"^( p|p) \{", f" #{id} p {{", x, 0, re.MULTILINE)
# substitutes
f(" p {abc")
f("p {abc")
# no substitute (good!)
f("group {abc")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that is totally good. I'll make the change!
I'm surprised this didn't fail / require regenerating any of the snapshot tests. (I guess maybe it's because the css one used condensed = False?). |
^^^ that's right. The snapshot test is only for that case. |
This fixes a
re.sub()
statement in thecompile_scss()
function so that the table ID is inserted before the rule for thep
element. This corrects a regression where the compiled CSS no longer worked with one of there.sub()
statements. With this fix, the rule for the table's<p>
element is specific to the table (and doesn't affect the page itself).