schleuse/dindent
Dindent is a regex-based HTML indenter/beautifier for development and testing. It formats template-generated markup with readable indentation without sanitizing, fixing, or rebuilding the document like DOM/Tidy—useful for debugging messy HTML output.
Updated Use Case Alignment:
<style> tags and optimizes inline elements, making it more suitable for projects with embedded CSS or complex inline HTML (e.g., email templates, legacy Blade views with inline styles).New Considerations:
notifications or mailables with embedded CSS.PHP/Laravel Compatibility:
Dindent::indent($html, ['one_line' => true]);
<style>body { ... }</style>).<pre> or <textarea> blocks, critical for code snippets or markdown-like content.Example Integration Snippet (Updated):
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 for PHP version constraints.schleuse/dindent:v2) if migration is blocked.<style> and one-line mode add flexibility but may introduce edge cases (e.g., conflicting CSS rules in <style> tags).<div><span>...</span></div>)?<style> tag parsing in large HTML strings?<style> tag support for email templates or inline Blade CSS?DOMDocument-based solution suffice, or does this package’s new functionality justify the upgrade?php artisan html:indent --one-line --optimize-styles resources/views/email.blade.php
@indent to support config options:
Blade::directive('indent', function ($expression) {
return "<?php echo \\Schleuse\\Dindent\\Dindent::indent($expression, ".json_encode(['one_line' => true])."); ?>";
});
App\Mail\* classes or Notification templates for consistent styling:
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.0 and test:
Mailable classes or notification channels.--one-line for specific files).@media queries, nested rules) to avoid false formatting.<div><span>Test</span><br></div> <!-- Should remain compact -->
config/dindent.php) for default modes.| 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 |
| Install & basic test (v3.0) | High | Low | Backend Dev | Focus on one-line mode and styles |
| Artisan command update | Medium | Medium | Backend Dev | Add --one-line and --optimize-styles |
| Email template integration | High | Medium | Backend Dev | Test with inline CSS |
| Pre-commit hook update | Low | Medium | DevOps | Add conditional flags |
config([
'dindent.defaults' => [
'one_line' => env('DDINDENT_ONE_LINE', false),
'optimize_styles' => true,
],
]);
--debug flag to the Artisan command to show original vs. indented HTML.| Scenario | Impact | Mitigation |
|---|---|---|
| PHP 8.2 migration blocked | Integration failure | Fork or replace with DOMDocument |
Malformed CSS in <style> |
Crashes or broken output |
How can I help you explore Laravel packages today?