# Dindent [](https://travis-ci.org/gajus/dindent) [](https://coveralls.io/r/gajus/dindent?branch=master) [](https://packagist.org/packages/gajus/dindent) [](https://packagist.org/packages/gajus/dindent) Dindent (aka., "HTML beautifier") will indent HTML for development and testing. Dedicated for those who suffer from reading a template engine produced markup. Try it in the [sandbox](http://gajus.com/sandbox/dindent/sandbox/). ## 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 need to indent your code in the development environment, beware that earlier mentioned libraries will attempt to fix your markup (that's their primary purpose; indentation is a by-product). ## 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. ## Use ```php $indenter = new \Gajus\Dindent\Indenter(); $indenter->indent('[..]'); ``` In the above example, `[..]` is a placeholder for: ```html
| A cell test! |
| ||||||||
| Test Ce ll | |||||||||
| Cell | Cell | Cell | |||||||
| A cell test! |
|
||||||||
| Test Ce ll | |||||||||
| Cell | Cell | Cell | |||||||
This is an inline element within a block element.
``` A block-level element occupies the entire space of its parent element (container), thereby creating a "block." Browsers typically display the block-level element with a new line both before and after the element. The following example demonstrates the block-level element's influence: ```htmlThis is a block element within a block element.
elements as inline. ./dindent.php --input="./input.html" --block="span,em" Indent "input.html" file treating and elements as block. ``` ## Known issues * Does not treat comments nicely and IE conditional blocks. ## Installation The recommended way to use Dindent is through [Composer](https://getcomposer.org/). ```json { "require": { "gajus/dindent": "2.0.*" } } ```