These are called "fragment selectors" in enlive parlance and unfortunatly for your purposes they don't support content
directly, though if you wrap them in a clone-for
you can get the same effect.
user> (require '[net.cgrand.enlive-html :as html])
nil
user> (html/sniptest "<div>
<p class='before'>before</p>
<p class='start'>Hi</p>
<p class='end'>There</p>
<p class='after'>after</p>
<p class='end'>last</p>
</div>"
{[:.start] [:.end]} (html/clone-for [m ["Hello"]]
[:p] (html/content m)))
"<div>
<p class=\"before\">before</p>
<p class=\"start\">Hello</p>
<p class=\"end\">Hello</p>
<p class=\"after\">after</p>
<p class=\"end\">last</p>
</div>"
This allows you to do more interesting things based on the position in the fragment
user> (html/sniptest "<div>
<p class='before'>before</p>
<p class='start'>Hi</p>
<p class='end'>There</p>
<p class='after'>after</p>
<p class='end'>last</p>
</div>"
{[:.start] [:.end]} (html/clone-for [m [["Hello" "Sir"]]]
[:p.start] (html/content (first m))
[:p.end] (html/content (last m))))
"<div>
<p class=\"before\">before</p>
<p class=\"start\">Hello</p>
<p class=\"end\">Sir</p>
<p class=\"after\">after</p>
<p class=\"end\">last</p>
</div>"
You can also use do->
instead of clone-for
:
user> (html/sniptest "<div>
<p class='before'>before</p>
<p class='start'>Hi</p>
<p class='end'>There</p>
<p class='after'>after</p>
<p class='end'>last</p>
</div>"
{[:.start] [:.end]} (html/do-> (html/content "Hello")))
"<div>
<p class=\"before\">before</p>
<p class=\"start\">Hello</p>
<p class=\"end\">Hello</p>
<p class=\"after\">after</p>
<p class=\"end\">last</p>
</div>"