百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
D

dindent

> 编程语言
开源

用于开发和测试的 HTML 缩进库。

179 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

用于开发和测试的 HTML 缩进库。

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

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
  • DOMDocument::$formatOutput
  • Tidy

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. 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 is not a direct replacement for Dindent.

Use

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

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


    

    

Dindent will convert it to:


    
    
        

        

        
    

Options

Indenter constructor accepts the following options that control indentation:

Name Description
indentation_character Character(s) used for indentation. Defaults to 4 whitespace characters.

Set element type

HTML elements are either "inline" elements or "block-level" elements.

An inline element occupies only the space bounded by the tags that define the inline element. The following example demonstrates the inline element's influence:


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:

Dindent identifies the following elements as "inline":

  • b, big, i, small, tt
  • abbr, acronym, cite, code, dfn, em, kbd, strong, samp, var
  • a, bdo, br, img, span, sub, sup

This is a subset of the inline elements defined in the MDN.

All other elements are treated as block.

You can set element type to either block or inline using setElementType method:

$indenter = new \Gajus\Dindent\Indenter();
/**
 * @param string $element_name Element name, e.g. "b".
 * @param ELEMENT_TYPE_BLOCK|ELEMENT_TYPE_INLINE $type
 * @return null
 */
$indenter->setElementType('foo', \Gajus\Dindent\Indenter::ELEMENT_TYPE_BLOCK);
$indenter->setElementType('bar', \Gajus\Dindent\Indenter::ELEMENT_TYPE_INLINE);

CLI

Dindent can be used via the CLI script ./bin/dindent.php.

…

Known issues

  • Does not treat comments nicely and IE conditional blocks.

Installation

The recommended way to use Dindent is through Composer.

{
    "require": {
        "gajus/dindent": "2.0.*"
    }
}

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHP

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言