Skip to content

Commit d18fed1

Browse files
authored
Add razor/cshtml pre processing (#17027)
This PR fixes an issue in Razor template files where `@sm:flex` doesn't work and `@@sm:flex` is required. In Tailwind CSS v3, some people used a custom transform to replace `@@` with just `@`. But in Tailwind CSS v4 we don't have this. However, we can add a pre processor for `.cshtml` and `.razor` files. Fixes: #17022
1 parent bd1e540 commit d18fed1

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2222
- Ensure utilities are sorted based on their actual property order ([#16995](https://github.com/tailwindlabs/tailwindcss/pull/16995))
2323
- Ensure strings in Pug and Slim templates are handled correctly ([#17000](https://github.com/tailwindlabs/tailwindcss/pull/17000))
2424
- Ensure `}` and `{` are valid boundary characters when extracting candidates ([#17001](https://github.com/tailwindlabs/tailwindcss/pull/17001))
25+
- Add `razor`/`cshtml` pre processing ([#17027](https://github.com/tailwindlabs/tailwindcss/pull/17027))
2526

2627
## [4.0.11] - 2025-03-06
2728

Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
pub mod pre_processor;
22
pub mod pug;
3+
pub mod razor;
34
pub mod ruby;
45
pub mod slim;
56
pub mod svelte;
67

78
pub use pre_processor::*;
89
pub use pug::*;
10+
pub use razor::*;
911
pub use ruby::*;
1012
pub use slim::*;
1113
pub use svelte::*;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use crate::extractor::pre_processors::pre_processor::PreProcessor;
2+
use bstr::ByteSlice;
3+
4+
#[derive(Debug, Default)]
5+
pub struct Razor;
6+
7+
impl PreProcessor for Razor {
8+
fn process(&self, content: &[u8]) -> Vec<u8> {
9+
content.replace("@@", " @")
10+
}
11+
}
12+
13+
#[cfg(test)]
14+
mod tests {
15+
use super::Razor;
16+
use crate::extractor::pre_processors::pre_processor::PreProcessor;
17+
18+
#[test]
19+
fn test_razor_pre_processor() {
20+
let (input, expected) = (
21+
r#"<div class="@@sm:text-red-500">"#,
22+
r#"<div class=" @sm:text-red-500">"#,
23+
);
24+
Razor::test(input, expected);
25+
Razor::test_extract_contains(input, vec!["@sm:text-red-500"]);
26+
}
27+
}

crates/oxide/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ pub fn pre_process_input(content: &[u8], extension: &str) -> Vec<u8> {
468468
use crate::extractor::pre_processors::*;
469469

470470
match extension {
471+
"cshtml" | "razor" => Razor.process(content),
471472
"pug" => Pug.process(content),
472473
"rb" | "erb" => Ruby.process(content),
473474
"slim" => Slim.process(content),

0 commit comments

Comments
 (0)