Using content management systems to build dynamic sites invariably results in ugly HTML. Indent levels are often wrong, white space litters the page, and a host of other tiny annoyances plague anyone attempting to read the source code for debugging or educational purposes.
Is there a way to automatically strip white space, autoindent, and otherwise beautify the output of a PHP or other dynamic script that spits out HTML?
I'm interested in any automated server-side solution that will improve the legibility of dynamically generated HTML, as well as solutions that strip all white space for compression purposes. If it matters, I normally run Apache or nginx.
It's safe to assume that I'm caching the output, so I won't be running whatever HTML beautification witchcraft you suggest on every page view (and taking the associated performance hit each time). As such, I'm more interested in ease of setup and reliable results than I am in performance.