Customize
Custom pseudo classes and functions
Custom pseudo-class
Custom pseudo-classes extends the PseudoClass
and implements match(Node node)
. This method should return true
if a node is matched. You may also override the method getPseudoClassName()
if you don't want to generate a pseudo-class name from the class name. For example:
Then register your pseudo-class with:
From that moment you will be able to find all nodes with the attribute jodd-attr
using the :jodd
pseudo-class.
When a pseudo-class needs to perform an additional match in the range of matched nodes (e.g. first, last etc), then override matchInRange()
method, too.
Custom pseudo-function
Similar to pseudo-classes, custom pseudo-function implements the PseudoFunction
class. Additionally, you need to also implement a method that parses input expression. This expression is later passed to the matching method.
Let's make a function that matches all nodes with certain name length:
Register it with:
Start using it! E.g. :len-fn(3)
to match all nodes with short names:)
Last updated