Skip to content
This repository

Add feature that the ':only-child' pseudo class should work even though it's in ':not' pseudo class. #858

Merged
merged 1 commit into from about 1 year ago

2 participants

Yamagishi Kazutoshi Lee Jarvis
Yamagishi Kazutoshi
ykzts commented

cite: 6.6.7. The negation pseudo-class in specification

The negation pseudo-class, :not(X), is a functional notation taking a simple selector (excluding the negation pseudo-class itself) as an argument. It represents an element that is not represented by its argument.

Also contain a :only-child pseudo class.

Yamagishi Kazutoshi
ykzts commented

currently:

Nokogiri::CSS.xpath_for '*:not(:only-child)' # => ["//*[not(only-child(.))]"] 

merged this commit:

Nokogiri::CSS.xpath_for '*:not(:only-child)' # => ["//*[not(last() = 1)]"]
Lee Jarvis leejarvis merged commit d1b0afd into from
Lee Jarvis leejarvis closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Mar 12, 2013
Yamagishi Kazutoshi ykzts Add feature that the ':only-child' pseudo class should work even thou…
…gh it's in ':not' pseudo class.
4383dc6
This page is out of date. Refresh to see the latest.
1  lib/nokogiri/css/xpath_visitor.rb
@@ -109,6 +109,7 @@ def visit_pseudo_class node
109 109 when "last", "last-child" then "position() = last()"
110 110 when "first-of-type" then "position() = 1"
111 111 when "last-of-type" then "position() = last()"
  112 + when "only-child" then "last() = 1"
112 113 when "only-of-type" then "last() = 1"
113 114 when "empty" then "not(node())"
114 115 when "parent" then "node()"
5 test/css/test_xpath_visitor.rb
@@ -17,6 +17,11 @@ def test_not_last_child
17 17 @parser.parse('ol > *:not(:last-child)'))
18 18 end
19 19
  20 + def test_not_only_child
  21 + assert_xpath('//ol/*[not(last() = 1)]',
  22 + @parser.parse('ol > *:not(:only-child)'))
  23 + end
  24 +
20 25 def test_function_calls_allow_at_params
21 26 assert_xpath("//a[foo(., @href)]", @parser.parse('a:foo(@href)'))
22 27 assert_xpath("//a[foo(., @a, b)]", @parser.parse('a:foo(@a, b)'))

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.