From f5bf5190b96a6883f747a1b859be21f6143d11e9 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Thu, 18 Sep 2025 16:39:12 -0400 Subject: [PATCH 1/2] Detect classes in markdown inline directives --- .../src/extractor/pre_processors/markdown.rs | 63 +++++++++++++++++++ .../oxide/src/extractor/pre_processors/mod.rs | 2 + crates/oxide/src/scanner/mod.rs | 1 + 3 files changed, 66 insertions(+) create mode 100644 crates/oxide/src/extractor/pre_processors/markdown.rs diff --git a/crates/oxide/src/extractor/pre_processors/markdown.rs b/crates/oxide/src/extractor/pre_processors/markdown.rs new file mode 100644 index 000000000000..63dc37d1eb4b --- /dev/null +++ b/crates/oxide/src/extractor/pre_processors/markdown.rs @@ -0,0 +1,63 @@ +use crate::cursor; +use crate::extractor::pre_processors::pre_processor::PreProcessor; + +#[derive(Debug, Default)] +pub struct Markdown; + +impl PreProcessor for Markdown { + fn process(&self, content: &[u8]) -> Vec { + let len = content.len(); + let mut result = content.to_vec(); + let mut cursor = cursor::Cursor::new(content); + + let mut in_directive = false; + + while cursor.pos < len { + match (in_directive, cursor.curr) { + (false, b'{') => { + result[cursor.pos] = b' '; + in_directive = true; + } + (true, b'}') => { + result[cursor.pos] = b' '; + in_directive = false; + } + (true, b'.') => { + result[cursor.pos] = b' '; + } + _ => {} + } + + cursor.advance(); + } + + result + } +} + +#[cfg(test)] +mod tests { + use super::Markdown; + use crate::extractor::pre_processors::pre_processor::PreProcessor; + + #[test] + fn test_markdown_pre_processor() { + for (input, expected) in [ + // Convert dots to spaces inside markdown inline directives + ( + ":span[Some Text]{.text-gray-500}", + ":span[Some Text] text-gray-500 ", + ), + ( + ":span[Some Text]{.text-gray-500.bg-red-500}", + ":span[Some Text] text-gray-500 bg-red-500 ", + ), + ( + ":span[Some Text]{#myId .my-class key=val key2='val 2'}", + ":span[Some Text] #myId my-class key=val key2='val 2' ", + ), + ] { + Markdown::test(input, expected); + } + } +} diff --git a/crates/oxide/src/extractor/pre_processors/mod.rs b/crates/oxide/src/extractor/pre_processors/mod.rs index 7435c349c4d7..7f55b9d0307b 100644 --- a/crates/oxide/src/extractor/pre_processors/mod.rs +++ b/crates/oxide/src/extractor/pre_processors/mod.rs @@ -2,6 +2,7 @@ pub mod clojure; pub mod elixir; pub mod haml; pub mod json; +pub mod markdown; pub mod pre_processor; pub mod pug; pub mod razor; @@ -14,6 +15,7 @@ pub use clojure::*; pub use elixir::*; pub use haml::*; pub use json::*; +pub use markdown::*; pub use pre_processor::*; pub use pug::*; pub use razor::*; diff --git a/crates/oxide/src/scanner/mod.rs b/crates/oxide/src/scanner/mod.rs index 469c58146306..a5fe797a0b88 100644 --- a/crates/oxide/src/scanner/mod.rs +++ b/crates/oxide/src/scanner/mod.rs @@ -486,6 +486,7 @@ pub fn pre_process_input(content: &[u8], extension: &str) -> Vec { "cshtml" | "razor" => Razor.process(content), "haml" => Haml.process(content), "json" => Json.process(content), + "md" | "mdx" => Markdown.process(content), "pug" => Pug.process(content), "rb" | "erb" => Ruby.process(content), "slim" | "slang" => Slim.process(content), From 13f0daff4e3e15233d36600d2440ac1405ff1964 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Thu, 18 Sep 2025 16:47:35 -0400 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ea5ab40f5ca..79f3c2f30c65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Show Lightning CSS warnings (if any) when optimizing/minifying ([#18918](https://github.com/tailwindlabs/tailwindcss/pull/18918)) - Use `default` export condition for `@tailwindcss/vite` ([#18948](https://github.com/tailwindlabs/tailwindcss/pull/18948)) - Re-throw errors from PostCSS nodes ([#18373](https://github.com/tailwindlabs/tailwindcss/pull/18373)) +- Detect classes in markdown inline directives ([#18967](https://github.com/tailwindlabs/tailwindcss/pull/18967)) ## [4.1.13] - 2025-09-03