diff --git a/CHANGELOG.md b/CHANGELOG.md
index 803b8d2..e97b8ee 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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 `
`. 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))
diff --git a/src/borkdude/html.cljc b/src/borkdude/html.cljc
index b0652ef..ae41c26 100644
--- a/src/borkdude/html.cljc
+++ b/src/borkdude/html.cljc
@@ -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]
@@ -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]))
diff --git a/test/borkdude/html_test.cljc b/test/borkdude/html_test.cljc
index 9db71d4..b93bdca 100644
--- a/test/borkdude/html_test.cljc
+++ b/test/borkdude/html_test.cljc
@@ -94,6 +94,19 @@
"
"
(html [:a#foo.bar.baz {:class "quux"}])
+ "
"
+ (html [:div.card {:id "a"}])
+
+ "
"
+ (html [:div.card {}])
+
+ "
"
+ (let [x "big"]
+ (html [:div.card {:class x}]))
+
+ "
"
+ (html [:div.card {:class (str "bi" "g")}])
+
"
"
(html [:div {:style {:color :blue}}])