PHPackages                             schleuse/dindent - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. schleuse/dindent

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

schleuse/dindent
================

Fork of gajus/dindent with various fixes from the community

3.0.0(2mo ago)364.1k↓22.3%11BSD-3-ClausePHPPHP ^8.2CI passing

Since Apr 16Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/Schleuse/dindent)[ Packagist](https://packagist.org/packages/schleuse/dindent)[ Docs](https://github.com/schleuse/dindent)[ RSS](/packages/schleuse-dindent/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (6)Versions (14)Used By (1)

Dindent
=======

[](#dindent)

[![Coverage Status](https://camo.githubusercontent.com/9e573755a967d600acf575c5100dd9bae58bb9d340490789728b54ddfebc4b77/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f5363686c657573652f64696e64656e742f62616467652e7376673f6272616e63683d6d61696e)](https://coveralls.io/github/Schleuse/dindent?branch=main)[![Latest Stable Version](https://camo.githubusercontent.com/e9acf660bb74c5ea74cac8c879c14fd3d24be181ccdd24b02c7534dcc928a4df/68747470733a2f2f706f7365722e707567782e6f72672f5363686c657573652f64696e64656e742f76657273696f6e2e706e67)](https://packagist.org/packages/Schleuse/dindent)[![License](https://camo.githubusercontent.com/acefd33f59151f8412725ed91aee3395c13d7cafccb29c1104a242cd5166d655/68747470733a2f2f706f7365722e707567782e6f72672f5363686c657573652f64696e64656e742f6c6963656e73652e706e67)](https://packagist.org/packages/Schleuse/dindent)

Dindent (aka., "HTML beautifier") will indent HTML for development and testing. Dedicated for those who suffer from reading a template engine produced markup.

Abuse Case
----------

[](#abuse-case)

Dindent will not sanitize or otherwise manipulate your output beyond indentation.

If you are looking to remove malicious code or make sure that your document is standards compliant, consider the following alternatives:

- [HTML Purifier](https://github.com/Exercise/HTMLPurifierBundle)
- [DOMDocument::$formatOutput](http://www.php.net/manual/en/class.domdocument.php)
- [Tidy](http://www.php.net/manual/en/book.tidy.php)

If you only want to indent your code, beware that earlier mentioned libraries will attempt to fix your markup (that's their primary purpose; indentation is a by-product).

Regex
-----

[](#regex)

There is a [good reason not to use regular expression to parse HTML](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454). However, DOM parser will rebuild the whole HTML document. It will add missing tags, close open block tags, or remove anything that's not a valid HTML. This is what Tidy does, DOM, etc. This behavior is undesirable when debugging HTML output. Regex based parser will not rebuild the document. Dindent will only add indentation, without otherwise affecting the markup.

The above is also the reason why [Chrome DevTools](https://developers.google.com/chrome-developer-tools/) is not a direct replacement for Dindent.

Installation
------------

[](#installation)

The recommended way to use Dindent is through [Composer](https://getcomposer.org).

```
composer req schleuse/dindent:^3.0
```

Use
---

[](#use)

```
$indenter = new \Gajus\Dindent\Indenter();
$indenter->indent('[..]');
```

In the above example, `\[..\]` is a placeholder for:```
>

console.log('te>
