Skip to content

Commit cc3e852

Browse files
authored
Treat starting single quote as verbatim text in Slim (#17085)
This PR fixes an issue in Slim templates where a single quote `'` at the start of the line (excluding white space) is considered a line indicator for verbatim text. It is not considered a string in this scenario. So something like this: ```slim div 'Foo' ``` Will compile to: ```html <div>Foo'</div> ``` Fixes: #17081
1 parent bc5a8c3 commit cc3e852

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121

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

2526
## [4.0.12] - 2025-03-07
2627

crates/oxide/src/extractor/pre_processors/slim.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,26 @@ impl PreProcessor for Slim {
1111
let mut result = content.to_vec();
1212
let mut cursor = cursor::Cursor::new(content);
1313
let mut bracket_stack = BracketStack::default();
14+
let mut line_start_pos = 0x00;
1415

1516
while cursor.pos < len {
1617
match cursor.curr {
18+
b'\n' => {
19+
line_start_pos = cursor.pos + 1;
20+
}
21+
22+
// Line indicators:
23+
//
24+
// > Verbatim text with trailing white space '
25+
// > See: https://github.com/slim-template/slim?tab=readme-ov-file#verbatim-text-with-trailing-white-space-
26+
b'\''
27+
if cursor.input[line_start_pos..cursor.pos]
28+
.iter()
29+
.all(|x| x.is_ascii_whitespace()) =>
30+
{
31+
// Do not treat the `'` as a string
32+
}
33+
1734
// Consume strings as-is
1835
b'\'' | b'"' => {
1936
let len = cursor.input.len();
@@ -154,4 +171,30 @@ mod tests {
154171
Slim::test(input, expected);
155172
Slim::test_extract_contains(input, vec!["text-black", "bg-green-300", "bg-red-300"]);
156173
}
174+
175+
// https://github.com/tailwindlabs/tailwindcss/issues/17081
176+
// https://github.com/slim-template/slim?tab=readme-ov-file#verbatim-text-with-trailing-white-space-
177+
#[test]
178+
fn test_single_quotes_to_enforce_trailing_whitespace() {
179+
let input = r#"
180+
div
181+
'A single quote enforces trailing white space
182+
= 1234
183+
184+
.text-red-500.text-3xl
185+
| This text should be red
186+
"#;
187+
188+
let expected = r#"
189+
div
190+
'A single quote enforces trailing white space
191+
= 1234
192+
193+
text-red-500 text-3xl
194+
| This text should be red
195+
"#;
196+
197+
Slim::test(input, expected);
198+
Slim::test_extract_contains(input, vec!["text-red-500", "text-3xl"]);
199+
}
157200
}

0 commit comments

Comments
 (0)