Skip to content

Commit 55c05f2

Browse files
committed
fix: support multiple number split
1 parent cf10bb6 commit 55c05f2

2 files changed

Lines changed: 53 additions & 22 deletions

File tree

cmd/class.go

Lines changed: 52 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -53,40 +53,71 @@ func (c *Command) makeProperty(str string) string {
5353
str = prefixRegex.ReplaceAllString(str, "")
5454

5555
strict := false
56-
last := strings.LastIndex(str, "-")
56+
separator := "-"
5757
if strings.Contains(str, "~") {
5858
strict = true
59-
last = strings.LastIndex(str, "~")
59+
separator = "~"
6060
}
6161

62-
if last == -1 {
63-
return str
62+
// First check for color patterns like "color-red-400"
63+
colorStr, isColor := c.makeColor(str)
64+
if isColor {
65+
return colorStr
6466
}
6567

66-
value := str[last+1:]
68+
// Split the string by the separator
69+
parts := strings.Split(str, separator)
70+
if len(parts) <= 1 {
71+
return str
72+
}
6773

68-
intValue, err := strconv.Atoi(value)
74+
// Find the first part that contains a number
75+
propertyEndIdx := -1
76+
for i, part := range parts {
77+
// Check if this part contains a number
78+
if regexp.MustCompile(`\d`).MatchString(part) {
79+
propertyEndIdx = i
80+
break
81+
}
82+
}
6983

70-
if err == nil {
71-
// it ends in a number it may be a color, e.g.: color-red-400
72-
str, ok := c.makeColor(str)
73-
if ok {
84+
// If no number found, use traditional approach with last part as value
85+
if propertyEndIdx == -1 {
86+
last := strings.LastIndex(str, separator)
87+
if last == -1 {
7488
return str
7589
}
76-
val := float32(intValue)
77-
if !strict {
78-
val = float32(intValue) / float32(c.Config.Divider)
79-
}
80-
81-
property := str[:last] + ":" + fmt.Sprintf("%v", val)
90+
return str[:last] + ":" + str[last+1:]
91+
}
8292

83-
if strict {
84-
return property
93+
// Join parts before the property end to form the property name
94+
property := strings.Join(parts[:propertyEndIdx], "-")
95+
96+
// For strict values, just join remaining parts with spaces
97+
if strict {
98+
valueStr := strings.Join(parts[propertyEndIdx:], " ")
99+
return property + ":" + valueStr
100+
}
101+
102+
// Process each value part individually
103+
valueParts := parts[propertyEndIdx:]
104+
processedValues := make([]string, len(valueParts))
105+
106+
for i, part := range valueParts {
107+
// Try to convert to number
108+
numValue, err := strconv.Atoi(part)
109+
if err == nil {
110+
// It's a number, apply divider and unit
111+
val := float32(numValue) / float32(c.Config.Divider)
112+
processedValues[i] = fmt.Sprintf("%v%s", val, c.Config.Unit)
113+
} else {
114+
// Not a number, keep as is
115+
processedValues[i] = part
85116
}
86-
return property + c.Config.Unit
87117
}
88-
89-
return str[:last] + ":" + value
118+
119+
// Join the processed values with spaces
120+
return property + ":" + strings.Join(processedValues, " ")
90121
}
91122

92123
func (c *Command) makeColor(str string) (string, bool) {

test/test.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ui <- fluidPage(
55
div(
66
class = "display-flex padding-2 margin-bottom-2 width-40",
77
div(
8-
class = "flex-grow~1",
8+
class = "flex-grow~1 box-shadow-1-1-1~2-grey",
99
h1("Hello, world!", class = "color-red-400 hover:color-cyan-500")
1010
),
1111
div(

0 commit comments

Comments
 (0)