Commits

Peggy Kuo  committed 9a89b22

Bumping jsoup version to 1.7.2. Adding few tests for newly supported pseudo selectors. README updated accordingly

  • Participants
  • Parent commits 09cecbc

Comments (0)

Files changed (5)

 ### Usage
 
 1. Include Botocss in your project, either by downloading the JAR or using the Maven dependency:
-    
+
         <dependency>
             <groupId>com.atlassian.botocss</groupId>
             <artifactId>botocss</artifactId>
             <version>2.0</version>
         </dependency>
-    
+
     This dependency is hosted in the [atlassian-contrib](https://maven.atlassian.com/content/repositories/atlassian-contrib/) Maven repository.
 
 2. Use the `Botocss.inject()` method to inject CSS into your markup.
-    
+
         // apply external stylesheet
         String markup = "<html><body><p>Hello, world!</p></body></html>";
         String styles = "p { margin: 10px; }";
         String output = Botocss.inject(markup, styles);
-    
+
         // Botocss also applies internal styles
         String markupWithStyles = "<html>" +
             "<head><style>p { margin: 10px; }</style></head>" +
-            "<body><p>Hello, world!</p></body>" + 
+            "<body><p>Hello, world!</p></body>" +
             "</html>";
         String output = Botocss.inject(markup);
 
 
 Styles are appended in order to the `@style` attribute on any matching elements. Botocss does not currently remove redundant styles, it relies on the user agent to disregard them.
 
-Most common CSS selectors are supported: descendent/child/sibling element selectors (`a b`, `a > b`, `a + b`), id, class and attribute selectors (`#id`, `.class`, `a[href]`), and so on. The jsoup documentation has a [complete list of supported selectors](http://jsoup.org/cookbook/extracting-data/selector-syntax).
+Most common CSS selectors are supported:
+
+* descendent, child, immediate sibling element selectors (`a b`, `a > b`, `a + b`)
+* id, class, attribute selectors (`#id`, `.class`, `a[href]`),
+* basic pseudo-selectors (`:first-child`, `:last-child`).
+
+Unsupported selectors are ignored during processing. Known unsupported selectors include:
 
-Unsupported selectors include `:first-child` and `:last-child` pseudo-selectors, and pseudo-selectors like `:hover` and `:active` which can't be applied via inline styles. Unsupported selectors are ignored during processing.
+* pseudo-selectors which can't be applied via inline styles (`:hover`, `:active`)
+* some pseudo-selectors (`:before`, `:after`, `:nth-child`)
+* advanced attribute element (`div[data=foobar]`, `a[href^=mailto]` etc)
+* non-immediate sibling selectors (`a ~ b`)
 
 You can enable INFO or DEBUG logging for detailed information about the processing. The log category name is 'com.atlassian.botocss'.
 

File dependencies.txt

 org.apache.commons:commons-io:1.3.2:jar:-:test||{sha1}b6dde38349ba9bb5e6ea6320531eae969985dae5
 org.hamcrest:hamcrest-core:1.2.1:jar:-:test|org.hamcrest:hamcrest-library:jar:1.2.1|{sha1}e89706d7a0641823a7d3f20c2b96272f622d155c
 org.hamcrest:hamcrest-library:1.2.1:jar:-:test||{sha1}b54856422a8b58f0fe61b3a762d024f5e6d0556d
-org.jsoup:jsoup:1.6.1:jar:-:compile||{sha1}70f0dfbe511d84ee7d0dda238a52746751787c47
+org.jsoup:jsoup:1.7.2:jar:-:compile||{sha1}d7e275ba05aa380ca254f72d0c0ffebaedc3adcf
 org.slf4j:slf4j-api:1.5.10:jar:-:compile||{sha1}cbe2371e467af56f350edfbdd87f5b75981fefe3
 org.slf4j:slf4j-log4j12:1.5.10:jar:-:runtime||{sha1}08274abbf7065ca15cf877d199a8bf75dba87f36
         <dependency>
             <groupId>org.jsoup</groupId>
             <artifactId>jsoup</artifactId>
-            <version>1.6.1</version>
+            <version>1.7.2</version>
         </dependency>
 
         <dependency>

File src/test/resources/com/atlassian/botocss/pseudo-output.html

             a:hover {
                 text-decoration: underline;
             }
+
+            ul li {
+                margin-top: 20px;
+                border-bottom: 1px solid #ccc;
+            }
+
+            ul li:first-child {
+                margin-top: 0;
+            }
+
+            ul li:last-child {
+                border-bottom: 0;
+            }
+
+            ul li:nth-child(3) {
+                color: #333
+            }
         </style>
     </head>
     <body>
         <a href="#" style="text-decoration: none">Hello, world!</a>
+        <ul>
+            <li style="margin-top: 20px; border-bottom: 1px solid #ccc; margin-top: 0">one</li>
+            <li style="margin-top: 20px; border-bottom: 1px solid #ccc">two</li>
+            <li style="margin-top: 20px; border-bottom: 1px solid #ccc">three</li>
+            <li style="margin-top: 20px; border-bottom: 1px solid #ccc">four</li>
+            <li style="margin-top: 20px; border-bottom: 1px solid #ccc; border-bottom: 0">five</li>
+        </ul>
     </body>
 </html>

File src/test/resources/com/atlassian/botocss/pseudo.html

             a:hover {
                 text-decoration: underline;
             }
+
+            ul li {
+                margin-top: 20px;
+                border-bottom: 1px solid #ccc;
+            }
+
+            ul li:first-child {
+                margin-top: 0;
+            }
+
+            ul li:last-child {
+                border-bottom: 0;
+            }
+
+            ul li:nth-child(3) {
+                color: #333
+            }
         </style>
     </head>
     <body>
         <a href="#">Hello, world!</a>
+        <ul>
+            <li>one</li>
+            <li>two</li>
+            <li>three</li>
+            <li>four</li>
+            <li>five</li>
+        </ul>
     </body>
 </html>