Skip to content

Commit 316bdec

Browse files
authored
handle arbitrary properties (#64)
* handle arbitrary properties * .
1 parent 3a1f6aa commit 316bdec

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

lib/tailwind_formatter.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ defmodule TailwindFormatter do
9494

9595
defp sort_variant_chains(classes) do
9696
classes
97-
|> String.split()
97+
|> String.split(~r/\s+(?![^\[]*\])/i, trim: true)
9898
|> Enum.map(fn class ->
9999
class
100100
|> String.split(":")
@@ -125,7 +125,7 @@ defmodule TailwindFormatter do
125125
end
126126

127127
defp placeholder?(class), do: String.contains?(class, @placeholder)
128-
defp variant?(class), do: String.contains?(class, ":")
128+
defp variant?(class), do: String.contains?(class, ":") and not String.starts_with?(class, "[")
129129
defp prose?(class), do: String.contains?(class, "prose")
130130

131131
defp class_position(class),

test/tailwind_formatter_test.exs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,4 +523,41 @@ defmodule TailwindFormatterTest do
523523

524524
assert_formatter_output(input, expected)
525525
end
526+
527+
# https://tailwindcss.com/docs/adding-custom-styles#arbitrary-properties
528+
test "handles arbitrary properties" do
529+
input = """
530+
<html lang="en" class="sm:[scrollbar-gutter: stable] potato">
531+
"""
532+
533+
expected = """
534+
<html lang="en" class="potato sm:[scrollbar-gutter: stable]">
535+
"""
536+
537+
assert_formatter_output(input, expected)
538+
end
539+
540+
test "issue #63" do
541+
input = """
542+
<html lang="en" class="[scrollbar-gutter: stable]">
543+
"""
544+
545+
expected = """
546+
<html lang="en" class="[scrollbar-gutter: stable]">
547+
"""
548+
549+
assert_formatter_output(input, expected)
550+
end
551+
552+
test "splits variants with arbitrary values" do
553+
input = """
554+
<div class="sm:lowercase sm:px-[1px] potato text-sm uppercase"></div>
555+
"""
556+
557+
expected = """
558+
<div class="potato text-sm uppercase sm:px-[1px] sm:lowercase"></div>
559+
"""
560+
561+
assert_formatter_output(input, expected)
562+
end
526563
end

0 commit comments

Comments
 (0)