Skip to content

Fix hiccup-like rendering of boolean attrs #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/net/cgrand/enlive_html.clj
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,9 @@
classes (keep (fn [^String seg]
(when (= \. (.charAt seg 0)) (subs seg 1)))
segments)
node {:tag (keyword tag-name) :attrs (if (attr-map? m) m {})
node {:tag (keyword tag-name) :attrs (if (attr-map? m)
(into {} (filter val m))
{})
:content (flatmap nodify (if (attr-map? m) ms more))}
node (if id (assoc-in node [:attrs :id] id) node)
node (if (seq classes)
Expand Down
10 changes: 10 additions & 0 deletions test/net/cgrand/enlive_html/test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,16 @@
(sniptest "<div>"
[:div] (content (html [:ul (for [s ["a" "b" "c"]] [:li s])])))))

(deftest hiccup-boolean-attrs
(is-same "<div><input type=checkbox></input></div>"
(sniptest "<div>"
[:div] (content (html [:input {:type "checkbox"
:checked false}]))))
(is-same "<div><input type=checkbox checked=checked></input></div>"
(sniptest "<div>"
[:div] (content (html [:input {:type "checkbox"
:checked "checked"}])))))

(deftest hiccup-mixed
(is-same "<div><p><i>big</i><b>world</b></p>"
(sniptest "<div>"
Expand Down