diff --git a/CHANGELOG.md b/CHANGELOG.md index b34f6f3e1cb1..e81e71ae590d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/crates/oxide/src/extractor/pre_processors/slim.rs b/crates/oxide/src/extractor/pre_processors/slim.rs index 8cceb0536315..6352a6358be4 100644 --- a/crates/oxide/src/extractor/pre_processors/slim.rs +++ b/crates/oxide/src/extractor/pre_processors/slim.rs @@ -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(); @@ -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"]); + } }