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

Question - easier way to get all rules of multiple types? #49

Closed
jamesaspence opened this issue Apr 11, 2018 · 3 comments
Closed

Question - easier way to get all rules of multiple types? #49

jamesaspence opened this issue Apr 11, 2018 · 3 comments
Assignees
Labels

Comments

@jamesaspence
Copy link

jamesaspence commented Apr 11, 2018

Hello. I'm digging into this library for the first time and am trying to parse a stylesheet, in order to pull all font-family/ font-face declarations out of it. I've found that to be rather difficult - when working with a stylesheet instance, I have to call getAllStyleRules, getAllMediaRules, etc. etc., and iterate my way through many layers.

Is there any way to do this easier, without requiring so many manual calls? I would use getAllRules but that returns a very generic rule instance (ICSSTopLevelRule), and I'm trying to avoid having a large if statement chain within my code to check for relevant class instances, just to retrieve child declarations.

@phax phax self-assigned this Apr 11, 2018
@phax phax added the question label Apr 11, 2018
@phax
Copy link
Owner

phax commented Apr 11, 2018

You may want to have a look at class CSSVisitor.
Call visitCSS using the parsed CascadingStyleSheet and as visitor use a class derived from DefaultCSSVisitor.
Overload onDeclaration and check for font-family or whatever you need.
hth

@phax
Copy link
Owner

phax commented Apr 17, 2018

Does that help you? Can the issue be closed?

@jamesaspence
Copy link
Author

@phax haven't gotten the chance to revisit, so yes, let's close for now - I can always reopen if this doesn't work. Thank you!

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

No branches or pull requests

2 participants