radkovo / jStyleParser

jStyleParser is a CSS parser written in Java. It has its own application interface that is designed to allow an efficient CSS processing in Java and mapping the values to the Java data types. It parses CSS 2.1 style sheets into structures that can be efficiently assigned to DOM elements. It is intended be the primary CSS parser for the CSSBox library. While handling errors, it is user agent conforming according to the CSS specification.
http://cssbox.sourceforge.net/jstyleparser/
GNU Lesser General Public License v3.0
92 stars 49 forks source link

css3 :not not working #60

Closed ghost closed 8 years ago

ghost commented 8 years ago

css>>>

.a .b:not(:first-of-type):before{color:#FFF}a:hover{color:red}*{color:#000}

ParserDemo.java print>>>

#of rules parsed: 2
Selectors: [a:hover]
Declarations:
  Property: color
  Values: 
    #ff0000
Selectors: [\*]
Declarations:
  Property: color
  Values: 
    #000000

gradle: 'net.sf.cssbox:jstyleparser:1.23' code:

            StyleSheet style = CSSFactory.parseString(css, null);

            //obtain the number of rules
            System.out.println("#of rules parsed: " + style.size());
            //go through the rules
            for (RuleBlock<?> rule : style) {
                if (rule instanceof RuleSet) {
                    RuleSet set = (RuleSet) rule;
                    System.out.println("Selectors: " + Arrays.asList(set.getSelectors()));
                    System.out.println("Declarations:");
                    for (Declaration decl : set) {
                        System.out.println("  Property: " + decl.getProperty());
                        System.out.println("  Values: ");
                        for (Term<?> term : decl)
                            System.out.println("    " + term);
                    }
                } else if (rule instanceof RuleMedia) {
                    RuleMedia media = (RuleMedia) rule;
                    System.out.println("Media: " + media.getMediaQueries());
                    for (RuleSet set : media) {
                        //process similarly to the RuleSet processing above
                        System.out.println("  Rule: " + set);
                    }
                } else {
                    //other rules such as @page, @viewport etc.
                    System.out.println("Other rule " + rule);
                }
            }

Thanks for your job!

radkovo commented 8 years ago

:not() will be supported in jStyleParser 2.0 (see the jstyleparser2 branch).