Skip to content

Commit

Permalink
fixed empty tag name case with id and class
Browse files Browse the repository at this point in the history
  • Loading branch information
onionpancakes committed Feb 12, 2024
1 parent ade537f commit 9d6fdc1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/dev/onionpancakes/chassis/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -715,11 +715,11 @@
head-name (.getName head)
pound-idx (.indexOf head-name 35 #_(int \#))
dot-idx (.indexOf head-name 46 #_(int \.))]
(if (pos? pound-idx)
(if (pos? dot-idx)
(if (>= pound-idx 0)
(if (>= dot-idx 0)
(if (< dot-idx pound-idx)
(let [dot-idx-after (.indexOf head-name 46 #_(int \.) pound-idx)]
(if (pos? dot-idx-after)
(if (>= dot-idx-after 0)
;; +head-id, +head-class-before, +head-class-after
(let [tag (->> (.substring head-name 0 dot-idx)
(clojure.lang.Keyword/intern head-ns))
Expand Down Expand Up @@ -751,7 +751,7 @@
(clojure.lang.Keyword/intern head-ns))
head-id (.substring head-name (inc pound-idx))]
(OpeningTag. metadata tag head-id nil attrs)))
(if (pos? dot-idx)
(if (>= dot-idx 0)
;; -head-id, +head-class
(let [tag (->> (.substring head-name 0 dot-idx)
(clojure.lang.Keyword/intern head-ns))
Expand Down
6 changes: 6 additions & 0 deletions test/dev/onionpancakes/chassis/tests/test_core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -117,27 +117,33 @@
(deftest test-html-tag-id-class
(are [node s] (= (c/html node) s)
;; id
[:#foo] "< id=\"foo\"></>"
[:div#foo] "<div id=\"foo\"></div>"

;; class
[:.a] "< class=\"a\"></>"
[:div.a] "<div class=\"a\"></div>"
[:div.a.b] "<div class=\"a b\"></div>"
[:div.a.b.c] "<div class=\"a b c\"></div>"

;; id, class
[:#foo.a] "< id=\"foo\" class=\"a\"></>"
[:div#foo.a] "<div id=\"foo\" class=\"a\"></div>"
[:div#foo.a.b] "<div id=\"foo\" class=\"a b\"></div>"
[:div#foo.a.b.c] "<div id=\"foo\" class=\"a b c\"></div>"

;; class, id
[:.a#foo] "< id=\"foo\" class=\"a\"></>"
[:div.a#foo] "<div id=\"foo\" class=\"a\"></div>"
[:div.a.b#foo] "<div id=\"foo\" class=\"a b\"></div>"
[:div.a.b.c#foo] "<div id=\"foo\" class=\"a b c\"></div>"

;; class, id, class
[:.a.b.c#foo.d.e.f] "< id=\"foo\" class=\"a b c d e f\"></>"
[:div.a.b.c#foo.d.e.f] "<div id=\"foo\" class=\"a b c d e f\"></div>"

;; class, id, class, pound
[:.a.b.c#foo.d.e.f#bar.baz] "< id=\"foo\" class=\"a b c d e f#bar baz\"></>"
[:div.a.b.c#foo.d.e.f#bar.baz] "<div id=\"foo\" class=\"a b c d e f#bar baz\"></div>"))

(deftest test-html-tag-id-class-attrs-merge
Expand Down

0 comments on commit 9d6fdc1

Please sign in to comment.