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 OxideCore PreProcessors calls 3 called by 1

Entity Profile

Dependency Diagram

graph TD
  62d9fe3e_6a90_5721_5ba5_d748745756d4["process_maud_templates()"]
  a8609acc_55df_88cc_fa95_411762496663["process()"]
  a8609acc_55df_88cc_fa95_411762496663 -->|calls| 62d9fe3e_6a90_5721_5ba5_d748745756d4
  137d4a53_4b6e_09a1_8799_98b67760e503["is_empty()"]
  62d9fe3e_6a90_5721_5ba5_d748745756d4 -->|calls| 137d4a53_4b6e_09a1_8799_98b67760e503
  0d2f4bc0_2b1b_fd72_0ffc_954eed604d0a["push()"]
  62d9fe3e_6a90_5721_5ba5_d748745756d4 -->|calls| 0d2f4bc0_2b1b_fd72_0ffc_954eed604d0a
  6b9684e1_5d48_c752_bd3e_50b21816b836["pop()"]
  62d9fe3e_6a90_5721_5ba5_d748745756d4 -->|calls| 6b9684e1_5d48_c752_bd3e_50b21816b836
  style 62d9fe3e_6a90_5721_5ba5_d748745756d4 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