publisher: Collect transition attributes as classes
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 23 Jul 2020 12:18:13 +0000 (14:18 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 23 Jul 2020 14:21:58 +0000 (16:21 +0200)
Fixes #7509

publisher/htmlElementsCollector.go
publisher/htmlElementsCollector_test.go

index 7bb2ebf15328f081d7e2d69dd01a02e8fa31becd..daaefe6cf17fe2821c2be2497494cd773551805d 100644 (file)
@@ -220,6 +220,7 @@ func isQuote(b byte) bool {
 var (
        htmlJsonFixer = strings.NewReplacer(", ", "\n")
        jsonAttrRe    = regexp.MustCompile(`'?(.*?)'?:.*`)
+       classAttrRe   = regexp.MustCompile(`(?i)^class$|transition`)
 )
 
 func parseHTMLElement(elStr string) (el htmlElement) {
@@ -242,7 +243,7 @@ func parseHTMLElement(elStr string) (el htmlElement) {
                                        // There should be only one, but one never knows...
                                        el.IDs = append(el.IDs, a.Val)
                                default:
-                                       if strings.EqualFold(a.Key, "class") {
+                                       if classAttrRe.MatchString(a.Key) {
                                                el.Classes = append(el.Classes, strings.Fields(a.Val)...)
                                        } else {
                                                key := strings.ToLower(a.Key)
index e255a735478b94a3c2035fb255b07a61ac5a806b..24bf87c2d66fe61fb889eff602ae877a978e779f 100644 (file)
@@ -85,6 +85,7 @@ func TestClassCollector(t *testing.T) {
       
                 }" class="block w-36 cursor-pointer pr-3 no-underline capitalize"></a>`, f("a", "block capitalize cursor-pointer no-underline pl-2 pl-3 pr-3 text-a text-b text-gray-600 w-36", "")},
 
+               {"Alpine transition 1", `<div x-transition:enter-start="opacity-0 transform mobile:-translate-x-8 sm:-translate-y-8">`, f("div", "mobile:-translate-x-8 opacity-0 sm:-translate-y-8 transform", "")},
                {"Vue bind", `<div v-bind:class="{ active: isActive }"></div>`, f("div", "active", "")},
        } {
                c.Run(test.name, func(c *qt.C) {