在 PHP 中整理 HTML5 输出缩进
我的 Web 应用程序将 HTML5 输出生成为可变数量视图的串联。最终结果是一团混乱的缩进:
</div>
</div>
<div id="content">
<div id="question-header">
<h1>
我想缩进代码以掩盖各个视图的起源并使输出更易于理解。
我已经研究了 Tidy PHP 扩展,但我所有的尝试都让它工作HTML5 产生了不正确的缩进。
My web application produces HTML5 output as a concatenation of a variable number of views. The end result is a mess of indentation:
</div>
</div>
<div id="content">
<div id="question-header">
<h1>
I want to indent the code to obscure the origin of individual views and to make the output easier to follow.
I have looked into the Tidy PHP extension but all my attempts to make it work with HTML5 have produced improper indenting.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您想掩盖各个视图的来源,我建议您缩小 HTML。这将具有减少文档大小的额外好处。
为了使 HTML 输出更易于理解,浏览器附带了调试实用程序,可以以缩进格式解析和渲染 DOM 树,例如 https://trac.webkit.org/wiki/WebInspector,http://getfirebug.com/< /a>.
If you want to obscure the origin of individual views, I suggest you to minify the HTML. This will have the added benefit of reducing the document size.
As for making the HTML output easier to follow, browsers come with debug utilities that parse and render out DOM tree in an indented format, e.g. https://trac.webkit.org/wiki/WebInspector, http://getfirebug.com/.
最接近您在 PHP 领域中寻找的内容的是 Dindent,https://github.com/gajus/dindent< /a>. Dindent 是一个 HTML 美化器,它使用正则表达式来缩进标记。这与 Tidy 不同,Tidy 充当 DOM 解析器。
从文档中:
Dindent 的唯一目的是缩进 HTML 标记。它允许配置哪些元素被视为内联以及哪些元素被视为块。
The closest to what you are looking for in the PHP land is Dindent, https://github.com/gajus/dindent. Dindent is a HTML beautifier that uses regular expressions to indent the markup. This is different from Tidy, that acts as a DOM parser.
From the documentation:
Dindent sole purpose is to indent the HTML markup. It allows to configure what elements to treat as inline and what elements to treat as block.