schleuse/dindent
Dindent is a regex-based HTML beautifier for PHP that indents markup from template engines without rebuilding, sanitizing, or otherwise altering the document—unlike DOM or Tidy. Ideal for debugging messy output. Install via Composer: schleuse/dindent.
<style> tags and optimizes inline elements — suitable for projects with embedded CSS or complex inline HTML (e.g., email templates, legacy Blade views with inline styles).<pre>, <textarea>, <style>) could produce corrupted output on later calls. That makes the package materially more viable in long-running PHP processes (Horizon/queue workers, Octane/Swoole, looping Artisan commands) rather than only single-shot CLI/request contexts.Dindent::indent($html, ['one_line' => true]);
<style>body { ... }</style>).<pre>/<textarea> — and is the code path most affected by the v3.1.0 state-leak fix.^3.1 (not ^3.0) if the package is used anywhere other than a single CLI invocation per process. ^3.0 will resolve to 3.1.0 on a clean install but may leave already-installed environments on 3.0.0 — verify with composer show schleuse/dindent.use Schleuse\Dindent\Dindent;
// One-line mode for API responses
$compactHtml = Dindent::indent($html, ['one_line' => true]);
// Style tag optimization
$styledHtml = Dindent::indent($htmlWithStyles);
composer.json PHP constraints and, if migration is blocked, proposing a parallel fork (schleuse/dindent:v2).<style> and one-line mode add flexibility but may introduce edge cases (e.g., conflicting CSS rules in <style> tags).<pre>-heavy template followed by a plain template in the same worker)?<div><span>...</span></div>)?<style> tag parsing in large HTML strings?<style> support for email templates or inline Blade CSS?DOMDocument-based solution suffice, or does the new functionality justify the upgrade?php artisan html:indent --one-line --optimize-styles resources/views/email.blade.php
Blade::directive('indent', function ($expression) {
return "<?php echo \\Schleuse\\Dindent\\Dindent::indent($expression, ".json_encode(['one_line' => true])."); ?>";
});
public function build()
{
$html = $this->view('emails.welcome');
$indented = Dindent::indent($html, ['one_line' => false]);
return $this->markdown('emails.welcome')->with(['html' => $indented]);
}
DOMDocument-based alternative.schleuse/dindent:^3.1 (pin the minor, not ^3.0).<pre>, <textarea>, and <style>.--one-line for specific paths).@media, nested rules) to avoid false formatting.<div><span>Test</span><br></div> <!-- Should remain compact -->
config/dindent.php) are supported; otherwise standardize via wrapper.| Step | Priority | Effort | Owner | Notes |
|---|---|---|---|---|
| PHP 8.2/Laravel 10 audit | Critical | High | TPM/DevOps | Blocking for integration |
| Fork or fallback planning | Critical | Medium | TPM | If migration is blocked |
Pin ^3.1 + verify installed version |
High | Low | Backend Dev | composer show schleuse/dindent; confirm no environment lags on 3.0.0 |
| Repeated-call regression test | High | Low | Backend Dev | New in v3.1.0; guards the state-leak fix |
| Install & basic test (v3.1) | High | Low | Backend Dev | One-line mode + style tags |
| Artisan command update | Medium | Medium | Backend Dev | --one-line, --optimize-styles |
| Email template integration | High | Medium | Backend Dev | Test with inline CSS in a worker context |
| Pre-commit hook update | Low | Medium | DevOps | Conditional flags |
--debug flag to the Artisan command to show original vs. indented HTML.e130cb1.| Scenario | Impact | Mitigation |
|---|---|---|
| PHP 8.2 migration blocked | Integration failure | Fork or replace with DOMDocument |
Malformed CSS in <style> |
Crashes or broken output | Validate/log CSS pre-indent; wrap calls in try/catch |
| Cross-call state leakage (v3.0.0) | Silent output corruption in workers/Octane | Upgrade to v3.1.0; pin ^3.1; add render-twice regression test |
| Upstream abandonment / no patches | Security and PHP-version drift | Wrapper class + vendor-the-file fallback plan |
| One-line mode masks malformed markup | Harder debugging | Keep --debug diff output; restrict one-line mode to non-debug paths |
How can I help you explore Laravel packages today?