-
Notifications
You must be signed in to change notification settings - Fork 148
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-hasCSS -
(attr-has(attribute-keyword value)*)(attr-has :foo "bar" "baz") ; *[foo~=bar][foo~=baz]
-
attr-startsCSS -
(attr-starts(attribute-keyword value)*)(attr-starts :href "foo" :title "bar"); *[href^=foo][title^=bar]
-
attr-endsCSS -
(attr-ends(attribute-keyword value)*)(attr-ends :href "foo" :title "bar") ; *[href$=foo][title$=bar]
-
attr-containsCSS -
(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-childCSS -
(nth-childstride? offset)(nth-child 3) ; *:nth-child(3) (nth-child 4 2) ; *:nth-child(4n+2)
-
nth-last-childCSS -
(nth-last-childstride? offset)(nth-last-child 3) ; *:nth-last-child(3) (nth-last-child 4 2) ; *:nth-last-child(4n+2)
-
nth-of-typeCSS -
(nth-of-typestride? offset)(nth-of-type 3) ; *:nth-of-type(3) (nth-of-type 4 2) ; *:nth-of-type(4n+2)
-
nth-last-of-typeCSS -
(nth-last-of-typestride? offset)(nth-last-of-type 3) ; *:nth-last-of-type(3) (nth-last-of-type 4 2) ; *:nth-last-of-type(4n+2)
-
butCSS -
(but :a) ; :not(a)
has-
(has [:a])
-
pred -
(predpredicate-on-elements)(pred #(= (:tag %) tag-name))
-
text-pred -
(text-predpredicate-on-text-nodes)(text-pred #(re-matches #"\d+" %))
-
zip-pred -
(zip-predpredicate-on-elements-locs) -
sm/pred(where sm aliases net.cgrand.enlive-html.state-machine) -
(sm/predpredicate-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.