Home / Function/ process_maud_templates() — tailwindcss Function Reference

process_maud_templates() — tailwindcss Function Reference

Architecture documentation for the process_maud_templates() function in rust.rs from the tailwindcss codebase.

Function rust RustCore PreProcessors calls 3 called by 1

Entity Profile

Dependency Diagram

graph TD
  27acbaf9_c0fa_6604_691a_4e61de20fd6b["process_maud_templates()"]
  d401993d_c01b_6151_61d4_86356cbb108e["process()"]
  d401993d_c01b_6151_61d4_86356cbb108e -->|calls| 27acbaf9_c0fa_6604_691a_4e61de20fd6b
  a6cec50b_244a_1320_58e6_036228829a18["is_empty()"]
  27acbaf9_c0fa_6604_691a_4e61de20fd6b -->|calls| a6cec50b_244a_1320_58e6_036228829a18
  2c3dea25_8534_307e_ed29_9da5e42908c7["push()"]
  27acbaf9_c0fa_6604_691a_4e61de20fd6b -->|calls| 2c3dea25_8534_307e_ed29_9da5e42908c7
  97d3f6aa_a90c_02b6_d13e_9bea2e7ae659["pop()"]
  27acbaf9_c0fa_6604_691a_4e61de20fd6b -->|calls| 97d3f6aa_a90c_02b6_d13e_9bea2e7ae659
  style 27acbaf9_c0fa_6604_691a_4e61de20fd6b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

crates/oxide/src/extractor/pre_processors/rust.rs lines 29–121

    fn process_maud_templates(&self, replaced_content: &[u8]) -> Vec<u8> {
        let len = replaced_content.len();
        let mut result = replaced_content.to_vec();
        let mut cursor = cursor::Cursor::new(replaced_content);
        let mut bracket_stack = bracket_stack::BracketStack::default();

        while cursor.pos < len {
            match cursor.curr {
                // Escaped character, skip ahead to the next character
                b'\\' => {
                    cursor.advance_twice();
                    continue;
                }

                // Consume strings as-is
                b'"' => {
                    result[cursor.pos] = b' ';
                    cursor.advance();

                    while cursor.pos < len {
                        match cursor.curr {
                            // Escaped character, skip ahead to the next character
                            b'\\' => cursor.advance_twice(),

                            // End of the string
                            b'"' => {
                                result[cursor.pos] = b' ';
                                break;
                            }

                            // Everything else is valid
                            _ => cursor.advance(),
                        };
                    }
                }

                // Only replace `.` with a space if it's not surrounded by numbers. E.g.:
                //
                // ```diff
                // - .flex.items-center
                // +  flex items-center
                // ```
                //
                // But with numbers, it's allowed:
                //
                // ```diff
                // - px-2.5
                // + px-2.5
                // ```
                b'.' => {
                    // Don't replace dots with spaces when inside of any type of brackets, because
                    // this could be part of arbitrary values. E.g.: `bg-[url(https://example.com)]`
                    //                                                                       ^
                    if !bracket_stack.is_empty() {
                        cursor.advance();
                        continue;
                    }

                    // If the dot is surrounded by digits, we want to keep it. E.g.: `px-2.5`
                    // EXCEPT if it's followed by a valid variant that happens to start with a
                    // digit.
                    // E.g.: `bg-red-500.2xl:flex`
                    //                 ^^^
                    if cursor.prev.is_ascii_digit() && cursor.next.is_ascii_digit() {
                        let mut next_cursor = cursor.clone();
                        next_cursor.advance();

                        let mut variant_machine = VariantMachine::default();
                        if let MachineState::Done(_) = variant_machine.next(&mut next_cursor) {
                            result[cursor.pos] = b' ';
                        }
                    } else {
                        result[cursor.pos] = b' ';
                    }
                }

                b'[' => {
                    bracket_stack.push(cursor.curr);
                }

                b']' if !bracket_stack.is_empty() => {
                    bracket_stack.pop(cursor.curr);
                }

                // Consume everything else
                _ => {}
            };

            cursor.advance();
        }

        result
    }

Domain

Subdomains

Called By

Frequently Asked Questions

What does process_maud_templates() do?
process_maud_templates() is a function in the tailwindcss codebase.
What does process_maud_templates() call?
process_maud_templates() calls 3 function(s): is_empty, pop, push.
What calls process_maud_templates()?
process_maud_templates() is called by 1 function(s): process.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free