- What is Dindent used for in Laravel projects?
- Dindent is a regex-based HTML beautifier that adds indentation to markup produced by template engines such as Blade. It is intended for development and testing, especially when you need to read messy rendered output. It does not sanitize, rebuild, or otherwise alter the document.
- How do I install schleuse/dindent with Composer?
- Run composer require schleuse/dindent:^3.1 in your Laravel project. Pin ^3.1 rather than ^3.0 if the package may run more than once per process, because v3.1.0 fixes a state-leak defect. The package requires PHP 8.2 or newer.
- Does Dindent support Laravel 10 and PHP 8.2?
- Yes. Dindent v3.x requires PHP 8.2+, which aligns with Laravel 10 and newer. Projects on PHP 8.1 or older must upgrade PHP or use a fork, since this constraint was not relaxed in v3.1.0.
- How is Dindent different from DOMDocument or Tidy?
- Dindent uses regex-based indentation and only adds whitespace; it does not rebuild the document. DOMDocument and Tidy may add missing tags, close open tags, or remove invalid markup, which changes the output you are trying to debug. Dindent is for preserving the exact rendered markup while making it readable.
- Can Dindent be used for email templates and notifications?
- Yes, email templates and notifications are a strong fit, especially when mailables are rendered in bulk by queue workers. Dindent can normalize inconsistent indentation without changing the HTML structure. For compact emails or API responses, pair it with one-line mode.
- How do I enable one-line mode in Dindent?
- Pass the one_line option to the indent method, for example Dindent::indent($html, ['one_line' => true]). This produces compact HTML with minimal indentation. It is useful for API responses, notifications, and other places where readability matters less than size.
- Is Dindent safe to use in Octane or queue workers?
- Use v3.1.0 or later. Earlier v3.0.0 could leak temporary replacement placeholders between calls in the same process, silently corrupting later output when mixed content such as pre, textarea, and style tags was involved. Pin ^3.1 and verify the installed version with composer show schleuse/dindent.
- Does Dindent handle pre, textarea, and style tags?
- Yes. Dindent preserves formatting inside pre and textarea elements and supports style tags, which helps with email templates and legacy Blade views that contain inline CSS. The pre and textarea extraction path is the code most affected by the v3.1.0 state-leak fix, so test mixed content sequences after upgrading.
- Is Dindent suitable for production HTML rendering?
- No. Dindent is intended for development and testing, and adding indentation in a production-critical rendering pipeline is unnecessary overhead. It also does not sanitize output, so it should not be used as a security or standards-compliance tool. Use HTML Purifier, Tidy, or DOMDocument if you need sanitization or markup correction.
- Is schleuse/dindent actively maintained, and what are the alternatives?
- Maintenance velocity is low: v3.0.0 to v3.1.0 spanned roughly seven months with one bug fix and no feature work, suggesting a likely single-maintainer project. Pin your version and plan for slow support. If you need sanitization, standards compliance, or document rebuilding, consider HTML Purifier, Tidy, or DOMDocument::$formatOutput instead.