Skip to content
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

Add support for the !important attribute #843

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

LaurenzV
Copy link
Contributor

@LaurenzV LaurenzV commented Nov 7, 2024

This solves the problem I had where I wanted to achieve that I can override all styles in the SVG via stylesheet injection. I tested it with rsvg-convert and it works in the same way, so it would be great to have this merged. :)

@RazrFalcon
Copy link
Collaborator

Are you sure !important shouldn't be handled on the simplecss side? I genuinely have no idea how it suppose to work.

@LaurenzV
Copy link
Contributor Author

LaurenzV commented Nov 8, 2024

Are you sure !important shouldn't be handled on the simplecss side? I genuinely have no idea how it suppose to work.

I think simplecss is low-level enough that it's enough if it provides the information whether an attribute has the important value or not, which is what it currently does. And since style deduplication is handled on the resvg side right now, we have to do it there anyway.

@RazrFalcon
Copy link
Collaborator

Looks good to me.

@RazrFalcon
Copy link
Collaborator

#252

@LaurenzV
Copy link
Contributor Author

Will try it.

@LaurenzV
Copy link
Contributor Author

Seems to work as intended. :)

Before:
test
sbahn2

After:
test
sbahn

@LaurenzV
Copy link
Contributor Author

I just noticed this, though:

When a declaration is important, the order of precedence is reversed. Declarations marked as important in the user-agent style sheets override all important declarations in the user style sheets. Similarly, all important declarations in the user style sheets override all important declarations in the author's style sheets. Finally, all important declarations take precedence over all animations.

So I think I need to adapt the swapping condition a bit. Will do so a bit later.

@LaurenzV
Copy link
Contributor Author

The condition should probably be:

  • Existing is not important, new is not important -> swap
  • Existing is important, new is not important -> don't swap
  • Existing is not important, new is important -> swap
  • Existing is important, new is important -> don't swap (since the order is reversed, so existing important attributes take precedence over new important attributes)

Will adapt it and extend the test cases.

@LaurenzV
Copy link
Contributor Author

Should be good now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants