Skip to content

Handle template toolkit %]…[% syntax#20269

Merged
RobinMalfait merged 5 commits into
mainfrom
fix/issue-20233
Jun 22, 2026
Merged

Handle template toolkit %]…[% syntax#20269
RobinMalfait merged 5 commits into
mainfrom
fix/issue-20233

Conversation

@RobinMalfait

Copy link
Copy Markdown
Member

This PR handles template toolkit syntax as a pre-processor step such that %] and [% are seen as valid boundary characters.

This is handled for the .tt, .tt2 and .tx file extensions. It's not handled if this syntax is used in .html files because then everybody pays a pre processor cost even if you don't need this syntax in most cases.

This now ensures that a template.tx like this:

<div class="[% IF $is_open %]bg-white/40[% ELSE %]bg-white/10[% END %]"></div>
<!--                         ^^^^^^^^^^^          ^^^^^^^^^^^              -->

Extracts the classes in between those conditions correctly.

This also fixes a small issue related to Maud, a template engine for Rust where conditionals like p.text-black[condition] caused the text-black class not to be extracted. This is fixed as part of this PR because it was commented on the linked issue.

Fixes: #20233

Test plan

  1. Added a new extractor
  2. Added regression tests
  3. All existing tests pass

@RobinMalfait RobinMalfait requested a review from a team as a code owner June 22, 2026 13:22
@greptile-apps

greptile-apps Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

Safe to merge — changes are well-scoped pre-processor additions with no effect on existing file extensions.

Both changes are additive and narrowly scoped: the Template Toolkit pre-processor only activates for .tt/.tt2/.tx files, and the Maud [ guard only fires inside html! blocks when the preceding character is not -. All boundary accesses are safe, and the new behavior is covered by unit tests plus regression tests.

No files require special attention.

Reviews (2): Last reviewed commit: "update changelog" | Re-trigger Greptile

@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: ad76187b-c655-4617-a224-f2fb8337ce48

📥 Commits

Reviewing files that changed from the base of the PR and between 0fee7b5 and ffa94a4.

📒 Files selected for processing (6)
  • CHANGELOG.md
  • crates/oxide/src/extractor/mod.rs
  • crates/oxide/src/extractor/pre_processors/mod.rs
  • crates/oxide/src/extractor/pre_processors/rust.rs
  • crates/oxide/src/extractor/pre_processors/template_toolkit.rs
  • crates/oxide/src/scanner/mod.rs

Walkthrough

Two pre-processor fixes are added to the Tailwind CSS oxide extractor. A new TemplateToolkit struct is introduced in a new file, implementing PreProcessor by replacing [% and %] byte sequences with spaces; the scanner's pre_process_input function now routes .tt, .tt2, and .tx files through this processor. The existing Rust/Maud pre-processor's process_maud_templates function gains a check that replaces [ with whitespace only when not preceded by -, correctly handling bracket-conditional class syntax without breaking arbitrary-value patterns. Unit and integration tests are added for both changes, and the CHANGELOG.md is updated.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title directly describes the main change: handling Template Toolkit %] and [% syntax in the codebase.
Description check ✅ Passed The description clearly explains the purpose of the PR, implementation approach, files affected, and includes test information related to the changeset.
Linked Issues check ✅ Passed The PR fully addresses issue #20233 by implementing Template Toolkit preprocessor support for .tt, .tt2, and .tx files, and fixing Maud conditional extraction as mentioned in the issue.
Out of Scope Changes check ✅ Passed All changes are scoped to implementing Template Toolkit preprocessing and the related Maud fix mentioned in the linked issue; no unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@RobinMalfait RobinMalfait merged commit d5ca0ae into main Jun 22, 2026
9 checks passed
@RobinMalfait RobinMalfait deleted the fix/issue-20233 branch June 22, 2026 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Class names adjacent to [ and ] delimiters not extracted

1 participant