Commits

Scott Smerchek committed f325b1d

added support for jquery's :header selector

  • Participants
  • Parent commits ec5aa0b

Comments (0)

Files changed (2)

File pyquery/cssselectpatch.py

         xpath.add_condition("@type = 'reset' and name(.) = 'input'")
         return xpath
 
+    def _xpath_header(self, xpath):
+        """Matches all header elelements (h1, ..., h6)"""
+        # this seems kind of brute-force, is there a better way?
+        xpath.add_condition("(name(.) = 'h1' or name(.) = 'h2' or name (.) = 'h3') "
+        + "or (name(.) = 'h4' or name (.) = 'h5' or name(.) = 'h6')")
+        return xpath
+
 cssselect.Pseudo = JQueryPseudo
 
 class JQueryFunction(Function):

File pyquery/test.py

            </html>
            """
 
+    html5 = """
+           <html>
+            <body>
+              <h1>Heading 1</h1>
+              <h2>Heading 2</h2>
+              <h3>Heading 3</h3>
+              <h4>Heading 4</h4>
+              <h5>Heading 5</h5>
+              <h6>Heading 6</h6>
+            </body>
+           </html>
+           """
+
     def test_selector_from_doc(self):
         doc = etree.fromstring(self.html)
         assert len(self.klass(doc)) == 1
         assert len(e(':radio')) == 3
         assert len(e(':checkbox')) == 3
 
+        #test on other elements
+        e = self.klass(self.html5)
+        assert len(e(":header")) == 6
+
 class TestTraversal(unittest.TestCase):
     klass = pq
     html = """