From 8532abca7eac6a650e55d4e7f743e9579b81ca4d Mon Sep 17 00:00:00 2001 From: Lectia Landau Date: Tue, 16 Jul 2024 22:25:54 +0300 Subject: [PATCH] Normalize spacing in style attr with multiple properties --- CHANGELOG.md | 3 +++ src/lambdaisland/hiccup.clj | 1 + test/lambdaisland/hiccup_test.clj | 6 +++--- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d627f3..02032f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ ## Fixed ## Changed +- Normalize spacing in style attr with multiple properties. + Where before the generated style attr might have "\n" or " ", + these are all now a simple " ", e.g. in-between multiple CSS properties. # 0.9.48 (2024-06-18 / e43362c) diff --git a/src/lambdaisland/hiccup.clj b/src/lambdaisland/hiccup.clj index 5c36408..4d4187d 100644 --- a/src/lambdaisland/hiccup.clj +++ b/src/lambdaisland/hiccup.clj @@ -120,6 +120,7 @@ (update-in [:attrs "style"] (fn [style] (-> (gc/compile-css [:& style]) (str/replace #"^\s*\{|\}\s*$" "") + (str/replace #"[ \n]+" " ") str/trim))) (sequential? (get-in node [:attrs "class"])) (update-in [:attrs "class"] #(str/join " " %)) diff --git a/test/lambdaisland/hiccup_test.clj b/test/lambdaisland/hiccup_test.clj index 2abbaf1..f7ad013 100644 --- a/test/lambdaisland/hiccup_test.clj +++ b/test/lambdaisland/hiccup_test.clj @@ -1,4 +1,3 @@ - (ns lambdaisland.hiccup-test (:require [clojure.test :refer [deftest testing is]] [lambdaisland.hiccup :as hiccup])) @@ -19,8 +18,9 @@ (is (= (hiccup/render [:div [:p]] {:doctype? false}) "

"))) (testing "styled tag" - (is (= (hiccup/render [:div {:style {:color "blue"}} [:p]] {:doctype? false}) - "

"))) + (let [style {:color "blue" :border "black"}] + (is (= (hiccup/render [:div {:style style} [:p]] {:doctype? false}) + "

")))) (testing "simple component" (is (= (hiccup/render [my-test-component "hello"] {:doctype? false}) "

hello

")))