gajus/dindent
gajus/dindent is a PHP library that indents HTML using the DOM, producing clean, readable markup without regex hacks. Useful for formatting templates, tidying generated HTML, and adding consistent indentation in tooling, tests, or build pipelines.
Install via Composer: composer require gajus/dindent. The library is lightweight with a single public method: Dindent::render($html). Begin by wrapping your rendered Blade output or generated HTML string—e.g., in a test or debug route—to instantly get human-readable, indented markup. Start with unit tests where you assert against expected HTML snapshots; clean indentation makes mismatches visually obvious.
Dindent::render() into Pest/PHPUnit test helpers (after(fn () => dd(Dindent::render($response->getContent())))) to surface readable diffs on failure.app/Http/Middleware/DindentHtml.php) that processes text/html responses in local environments only, replacing the content with indented HTML for developer tooling (e.g., browser devtools or CLI curl calls).Dindent::render() before return $view->render() or file_put_contents().php artisan generate:email-report) to improve inspectability of long output.<div><span></div>) may misindent. Always normalize input (e.g., strip comments, enforce lowercase tags) before passing to render().if (app()->isLocal())).<br>, <img>, <input> may be misindented if not properly closed or space-padded (<br/> behaves better than <br>). Normalize HTML input (libxml_use_internal_errors(true) etc.) if possible.strtolower() or regex pre-filtering.NOASSERTION license, do not redistribute. Prefer embedding internally (e.g., as a service class) and audit the code before any deployment.How can I help you explore Laravel packages today?