@@ -56,6 +56,28 @@ impl PreProcessor for Slim {
56
56
}
57
57
}
58
58
59
+ // Handle Ruby syntax with `%w[]` arrays embedded in Slim directly.
60
+ //
61
+ // E.g.:
62
+ //
63
+ // ```
64
+ // div [
65
+ // class=%w[bg-blue-500 w-10 h-10]
66
+ // ]
67
+ // ```
68
+ b'%' if matches ! ( cursor. next, b'w' | b'W' )
69
+ && matches ! ( cursor. input. get( cursor. pos + 2 ) , Some ( b'[' | b'(' | b'{' ) ) =>
70
+ {
71
+ result[ cursor. pos ] = b' ' ; // Replace `%`
72
+ cursor. advance ( ) ;
73
+ result[ cursor. pos ] = b' ' ; // Replace `w`
74
+ cursor. advance ( ) ;
75
+ result[ cursor. pos ] = b' ' ; // Replace `[` or `(` or `{`
76
+ bracket_stack. push ( cursor. curr ) ;
77
+ cursor. advance ( ) ; // Move past the bracket
78
+ continue ;
79
+ }
80
+
59
81
// Any `[` preceded by an alphanumeric value will not be part of a candidate.
60
82
//
61
83
// E.g.:
@@ -281,4 +303,29 @@ mod tests {
281
303
"# ;
282
304
Slim :: test_extract_contains ( input, vec ! [ "flex" , "items-center" ] ) ;
283
305
}
306
+
307
+ // https://github.com/tailwindlabs/tailwindcss/issues/17542
308
+ #[ test]
309
+ fn test_embedded_ruby_percent_w_extraction ( ) {
310
+ let input = r#"
311
+ div[
312
+ class=%w[bg-blue-500 w-10 h-10]
313
+ ]
314
+ div[
315
+ class=%w[w-10 bg-green-500 h-10]
316
+ ]
317
+ "# ;
318
+
319
+ let expected = r#"
320
+ div
321
+ class= bg-blue-500 w-10 h-10]
322
+ ]
323
+ div
324
+ class= w-10 bg-green-500 h-10]
325
+ ]
326
+ "# ;
327
+
328
+ Slim :: test ( input, expected) ;
329
+ Slim :: test_extract_contains ( input, vec ! [ "bg-blue-500" , "bg-green-500" , "w-10" , "h-10" ] ) ;
330
+ }
284
331
}
0 commit comments