Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Fix `haml` pre-processing ([#17051](https://github.com/tailwindlabs/tailwindcss/pull/17051))
- Ensure classes between `>` and `<` are properly extracted ([#17094](https://github.com/tailwindlabs/tailwindcss/pull/17094))
- Treat starting single quote as verbatim text in Slim ([#17085](https://github.com/tailwindlabs/tailwindcss/pull/17085))

## [4.0.12] - 2025-03-07

Expand Down
43 changes: 43 additions & 0 deletions crates/oxide/src/extractor/pre_processors/slim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,26 @@ impl PreProcessor for Slim {
let mut result = content.to_vec();
let mut cursor = cursor::Cursor::new(content);
let mut bracket_stack = BracketStack::default();
let mut line_start_pos = 0x00;

while cursor.pos < len {
match cursor.curr {
b'\n' => {
line_start_pos = cursor.pos + 1;
}

// Line indicators:
//
// > Verbatim text with trailing white space '
// > See: https://github.com/slim-template/slim?tab=readme-ov-file#verbatim-text-with-trailing-white-space-
b'\''
if cursor.input[line_start_pos..cursor.pos]
.iter()
.all(|x| x.is_ascii_whitespace()) =>
{
// Do not treat the `'` as a string
}

// Consume strings as-is
b'\'' | b'"' => {
let len = cursor.input.len();
Expand Down Expand Up @@ -154,4 +171,30 @@ mod tests {
Slim::test(input, expected);
Slim::test_extract_contains(input, vec!["text-black", "bg-green-300", "bg-red-300"]);
}

// https://github.com/tailwindlabs/tailwindcss/issues/17081
// https://github.com/slim-template/slim?tab=readme-ov-file#verbatim-text-with-trailing-white-space-
#[test]
fn test_single_quotes_to_enforce_trailing_whitespace() {
let input = r#"
div
'A single quote enforces trailing white space
= 1234

.text-red-500.text-3xl
| This text should be red
"#;

let expected = r#"
div
'A single quote enforces trailing white space
= 1234

text-red-500 text-3xl
| This text should be red
"#;

Slim::test(input, expected);
Slim::test_extract_contains(input, vec!["text-red-500", "text-3xl"]);
}
}