-
Notifications
You must be signed in to change notification settings - Fork 151
Enlive selectors syntax
owenRiddy edited this page Jan 19, 2022
·
2 revisions
Enlive selectors syntax
- selector
- node-selector
-
{
node-selector node-selector}
; fragment selector {from to} - node-selector
-
[
selector-step (:>
? selector-step)*]
-
#{
node-selector*}
; grouping -
a-symbol
; must evaluate to a state-machine -
(some clojure code)
; must evaluate to a state-machine - selector-step
-
:a-keyword
; can be :* :.class :tag :#id or any combination eg :div#foo.bar.baz -
#{
selector-step*}
; union -
[
selector-step*]
; intersection -
a-symbol
; must evaluate to a state-machine — some are already defined -
(some clojure code)
; must evaluate to a state-machine — better built using some predefined functions, predicate builders or macros
root
,
first-child
,
last-child
,
first-of-type
,
last-of-type
,
only-child
,
only-of-type
,
void
(CSS's :empty
),
odd
and
even
.
-
attr?
CSS -
(attr?
attribute-keyword*)
(attr? :href) ; *[href] (attr? :href :title) ; *[href][title]
-
attr=
CSS -
(attr=
(attribute-keyword value)*)
(attr= :href "foo") ; *[href=foo] (attr= :href "foo" :title "bar") ; *[href=foo][title=bar]
-
attr-has
CSS -
(attr-has
(attribute-keyword value)*)
(attr-has :foo "bar" "baz") ; *[foo~=bar][foo~=baz]
-
attr-starts
CSS -
(attr-starts
(attribute-keyword value)*)
(attr-starts :href "foo" :title "bar"); *[href^=foo][title^=bar]
-
attr-ends
CSS -
(attr-ends
(attribute-keyword value)*)
(attr-ends :href "foo" :title "bar") ; *[href$=foo][title$=bar]
-
attr-contains
CSS -
(attr-contains
(attribute-keyword value)*)
(attr-contains :href "foo" :title "bar") ; *[href*=foo][title*=bar]
-
attr|=
CSS -
(attr|=
(attribute-keyword value)*)
(attr|= :lang "fr") ; *[lang|=fr]
-
nth-child
CSS -
(nth-child
stride? offset)
(nth-child 3) ; *:nth-child(3) (nth-child 4 2) ; *:nth-child(4n+2)
-
nth-last-child
CSS -
(nth-last-child
stride? offset)
(nth-last-child 3) ; *:nth-last-child(3) (nth-last-child 4 2) ; *:nth-last-child(4n+2)
-
nth-of-type
CSS -
(nth-of-type
stride? offset)
(nth-of-type 3) ; *:nth-of-type(3) (nth-of-type 4 2) ; *:nth-of-type(4n+2)
-
nth-last-of-type
CSS -
(nth-last-of-type
stride? offset)
(nth-last-of-type 3) ; *:nth-last-of-type(3) (nth-last-of-type 4 2) ; *:nth-last-of-type(4n+2)
-
but
CSS -
(but :a) ; :not(a)
has
-
(has [:a])
-
pred
-
(pred
predicate-on-elements)
(pred #(= (:tag %) tag-name))
-
text-pred
-
(text-pred
predicate-on-text-nodes)
(text-pred #(re-matches #"\d+" %))
-
zip-pred
-
(zip-pred
predicate-on-elements-locs)
-
sm/pred
(where sm aliases net.cgrand.enlive-html.state-machine) -
(sm/pred
predicate-on-locs)
selector
takes a selector and evaluates to a state-machine, selector-step
takes a selector-step and evaluates to a state-machine.They are backed by
compile-selector
and compile-step
.