[CssSelector] Support *:only-of-type pseudo class selector
This commit is contained in:
parent
2044ba8e97
commit
eae2ebc0d7
@ -1,6 +1,11 @@
|
|||||||
CHANGELOG
|
CHANGELOG
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
4.4.0
|
||||||
|
-----
|
||||||
|
|
||||||
|
* Added support for `*:only-of-type`
|
||||||
|
|
||||||
2.8.0
|
2.8.0
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
@ -308,6 +308,8 @@ HTML
|
|||||||
['li div:only-child', ['li-div']],
|
['li div:only-child', ['li-div']],
|
||||||
['div *:only-child', ['li-div', 'foobar-span']],
|
['div *:only-child', ['li-div', 'foobar-span']],
|
||||||
['p:only-of-type', ['paragraph']],
|
['p:only-of-type', ['paragraph']],
|
||||||
|
[':only-of-type', ['html', 'li-div', 'foobar-span', 'paragraph']],
|
||||||
|
['div#foobar-div :only-of-type', ['foobar-span']],
|
||||||
['a:empty', ['name-anchor']],
|
['a:empty', ['name-anchor']],
|
||||||
['a:EMpty', ['name-anchor']],
|
['a:EMpty', ['name-anchor']],
|
||||||
['li:empty', ['third-li', 'fourth-li', 'fifth-li', 'sixth-li']],
|
['li:empty', ['third-li', 'fourth-li', 'fifth-li', 'sixth-li']],
|
||||||
|
@ -100,17 +100,10 @@ class PseudoClassExtension extends AbstractExtension
|
|||||||
->addCondition('last() = 1');
|
->addCondition('last() = 1');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws ExpressionErrorException
|
|
||||||
*/
|
|
||||||
public function translateOnlyOfType(XPathExpr $xpath): XPathExpr
|
public function translateOnlyOfType(XPathExpr $xpath): XPathExpr
|
||||||
{
|
{
|
||||||
$element = $xpath->getElement();
|
$element = $xpath->getElement();
|
||||||
|
|
||||||
if ('*' === $element) {
|
|
||||||
throw new ExpressionErrorException('"*:only-of-type" is not implemented.');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $xpath->addCondition(sprintf('count(preceding-sibling::%s)=0 and count(following-sibling::%s)=0', $element, $element));
|
return $xpath->addCondition(sprintf('count(preceding-sibling::%s)=0 and count(following-sibling::%s)=0', $element, $element));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user