Detect classes in markdown inline directives (#18967)

Fixes #18071
This commit is contained in:
Jordan Pittman 2025-09-18 16:53:44 -04:00 • committed by GitHub
parent d0f7f82787
commit 8d56381012
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 67 additions and 0 deletions

View file

@ -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

View file

@ -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<u8> {
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);
}
}
}

View file

@ -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::*;

View file

@ -486,6 +486,7 @@ pub fn pre_process_input(content: &[u8], extension: &str) -> Vec<u8> {
"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),