Skip to content
Merged
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: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Unreleased changes are available via `io.github.borkdude/html {:git/sha "..."}`

[html](https://github.com/borkdude/html): Produce HTML from hiccup in Clojure and ClojureScript

## Unreleased

- Fix shorthand classes being dropped when the attribute map has no `:class`: `[:div.card {:id "a"}]` rendered `<div id="a">`. The same path interpolated a symbol's _name_ when `:class` was bound to an expression, so `(let [x "big"] [:div.card {:class x}])` rendered `class="card x"`.

## 0.2.6

- Fix [#17](https://github.com/borkdude/html/issues/17): inline `style` map emitted a literal `\n` between declarations via `pr-str`, producing invalid CSS that dropped every declaration after the first ([@cycl1st](https://github.com/cycl1st))
Expand Down
21 changes: 11 additions & 10 deletions src/borkdude/html.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,16 @@
(.substring tag (unchecked-inc-int class-index)))]))

(defn merge-attrs [attrs short-attrs]
(let [attrs (if-let [c (:class attrs)]
(if-let [sc (:class short-attrs)]
(assoc attrs :class (str sc " " c))
attrs)
attrs)
(let [attrs (if-let [sc (:class short-attrs)]
(if-let [c (:class attrs)]
(assoc attrs :class (if (constant? c)
(str sc " " c)
`(str ~sc " " ~c)))
(assoc attrs :class sc))
attrs)
attrs (if-let [id (:id short-attrs (:id attrs))]
(assoc attrs :id id)
attrs)]
(assoc attrs :id id)
attrs)]
attrs))

(defn- ->html [opts form]
Expand Down Expand Up @@ -174,8 +176,7 @@
(html [:div [:<> "hello " "there"]])
(html [:div [[:<>script]]])
(html [:div [:$ [:<>script]]])
(macroexpand-all '(html [:div ]))
(macroexpand-all '(html [:div]))
(macroexpand-all '(html [:div "Hello"]))
(html [:br])
(xml [:br])
)
(xml [:br]))
13 changes: 13 additions & 0 deletions test/borkdude/html_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,19 @@
"<a class=\"bar baz quux\" id=\"foo\"></a>"
(html [:a#foo.bar.baz {:class "quux"}])

"<div id=\"a\" class=\"card\"></div>"
(html [:div.card {:id "a"}])

"<div class=\"card\"></div>"
(html [:div.card {}])

"<div class=\"card big\"></div>"
(let [x "big"]
(html [:div.card {:class x}]))

"<div class=\"card big\"></div>"
(html [:div.card {:class (str "bi" "g")}])

"<div style=\"color: blue;\"></div>"
(html [:div {:style {:color :blue}}])

Expand Down
Loading