Pretty-print HTML via PHP without validation?

倖福魔咒の 提交于 2019-12-04 03:39:53

The behaviour that you've observed when using Tidy is a result of the underlying use of DOM API. Instead of manipulating the provided source code, DOM API will reconstruct the whole source, thus making fixes along the way.

I've written Dindent, which is a library that uses Regex. It does not do anything beyond adding the indentation and removing whitespaces. However, I advise against using this implementation beyond development purposes.

I've never used Tidy but it seems pretty customizable.

Here's the quick reference of configuration options: http://tidy.sourceforge.net/docs/quickref.html

But really, with tools like Firebug, I've never seen the need to Tidy HTML output.

Since you do not want to have it validate for whatever reason, I will not suggest htmlpurifier ; ). Why not just use an IDE to get everything indented nicely, like Alt-Shift-F in Netbeans.

Facing the same problem i currently use a combination of two commands:

 cat template-home.php | js-beautify --type html | prettier --parser php

js-beautify formats the html bits and prettier formats the php code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!