From 00e00da233ab4d643de90bafca00f60ee0bbe785 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Thu, 23 Jul 2020 14:18:13 +0200 Subject: [PATCH] publisher: Collect transition attributes as classes Fixes #7509 --- publisher/htmlElementsCollector.go | 3 ++- publisher/htmlElementsCollector_test.go | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/publisher/htmlElementsCollector.go b/publisher/htmlElementsCollector.go index 7bb2ebf15..daaefe6cf 100644 --- a/publisher/htmlElementsCollector.go +++ b/publisher/htmlElementsCollector.go @@ -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) diff --git a/publisher/htmlElementsCollector_test.go b/publisher/htmlElementsCollector_test.go index e255a7354..24bf87c2d 100644 --- a/publisher/htmlElementsCollector_test.go +++ b/publisher/htmlElementsCollector_test.go @@ -85,6 +85,7 @@ func TestClassCollector(t *testing.T) { }" class="block w-36 cursor-pointer pr-3 no-underline capitalize">`, 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", `
`, f("div", "mobile:-translate-x-8 opacity-0 sm:-translate-y-8 transform", "")}, {"Vue bind", `
`, f("div", "active", "")}, } { c.Run(test.name, func(c *qt.C) {