Skip to content

Commit

Permalink
Fix regexp ws handling
Browse files Browse the repository at this point in the history
  • Loading branch information
PEZ committed Jun 3, 2024
1 parent 8ae95fd commit 0b01389
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/cljs-lib/src/calva/html2hiccup.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

(defn- mapify-style [style-str]
(try
(into {} (for [[_ k v] (re-seq #"(\S+):\s*([^;]+);?" style-str)]
(into {} (for [[_ k v] (re-seq #"(\S+?)\s*:\s*([^;]+);?" style-str)]
[(-> k string/lower-case keyword) (normalize-css-value v)]))
(catch :default e
(js/console.warn "Failed to mapify style: '" style-str "'." (.-message e))
Expand Down
5 changes: 4 additions & 1 deletion src/cljs-lib/test/calva/html2hiccup_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@
(sut/html->hiccup "<foo style='color:blue'></foo>" {:mapify-style? false}))))
(testing "style attributes do not need whitespace between entries with mapify-style? enabled"
(is (= [[:foo {:style {:color :blue}}]]
(sut/html->hiccup "<foo style='color:blue'></foo>" {:mapify-style? true})))))
(sut/html->hiccup "<foo style='color:blue'></foo>" {:mapify-style? true})))
(is (= [[:foo {:style {:color :blue
:stroke :red}}]]
(sut/html->hiccup "<foo style='color:blue;stroke:red;'></foo>" {:mapify-style? true})))))

(deftest html->hiccup-w-mapify-style?
(testing "style attribute is mapified with :mapify-style? enabled"
Expand Down

0 comments on commit 0b01389

Please sign in to comment.