Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Dindent Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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.

Implementation Patterns

  • Test Harness Enhancement: Inject Dindent::render() into Pest/PHPUnit test helpers (after(fn () => dd(Dindent::render($response->getContent())))) to surface readable diffs on failure.
  • Local Debug Middleware: Create a lightweight middleware (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).
  • Template Snippet Debugging: When building Blade partials via string concatenation (e.g., in emails or email templates), prepend output with Dindent::render() before return $view->render() or file_put_contents().
  • CLI Utilities: Integrate into artisan commands that generate static HTML (e.g., php artisan generate:email-report) to improve inspectability of long output.

Gotchas and Tips

  • Non-strict Parsing: Uses heuristic regex, not an HTML parser—malformed or missing closing tags (<div><span></div>) may misindent. Always normalize input (e.g., strip comments, enforce lowercase tags) before passing to render().
  • Performance Overhead: Avoid in production or high-throughput flows; even small pages (~10KB) can see measurable latency if called repeatedly (e.g., in per-request response middleware). Use conditionally (if (app()->isLocal())).
  • Self-Closing Tag Edge Cases: Tags like <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.
  • Case Sensitivity: Only lowercase tag names are handled reliably. If generating HTML from JSON or external APIs, downcase via strtolower() or regex pre-filtering.
  • Extend with Caution: Its simplicity makes it easy to fork or wrap—but given the ambiguous NOASSERTION license, do not redistribute. Prefer embedding internally (e.g., as a service class) and audit the code before any deployment.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport