Download the PHP package mallardduck/html-formatter without Composer

On this page you can find all versions of the php package mallardduck/html-formatter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package html-formatter

HTML Formatter Latest Version

Unit tests Code analysis Coverage Status License: MIT

1. What Is It

HTML Formatter will beautify or minify your HTML string for development and testing. Dedicated for those who suffer from reading a template engine produced markup.

2. What Is It Not

HTML Formatter will not sanitize or otherwise manipulate your output beyond indentation and whitespace replacement. HTML Formatter will only add indentation, without otherwise affecting the markup.

If you are looking to remove malicious code or make sure that your document is standards compliant, consider the following alternatives:

If you need to format your code in the development environment, beware that earlier mentioned libraries will attempt to fix your markup.

3. Installation

This package can be installed through Composer.

4. Usage

5. Configuration

Formatter is using Simple config to adjust its configuration settings.

Name Type Description
tab string Character(s) used for indentation. Defaults to 4 spaces.
self-closing.tag array Here you can add more self-closing tags. see below
inline.tag array Here you can add more inline tags, or change any block tags and make them inline. see below
formatted.tag array Here you can add more tags to be exluded of formatting. see below
attributes.trim boolean Remove leading and trailing whitespace in the attribute values.
attribute.cleanup boolean Replace all whitespaces with a single space in the attribute values.
cdata.cleanup boolean Replace all whitespaces with a single space in CDATA.
cdata.trim boolean Remove leading and trailing whitespace in CDATA.

5.1. Inline and block elements

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:

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:

HTML Formatter identifies the following elements as "inline":

This is a subset of the inline elements defined in the MDN. All other elements are treated as block.

You can set additional inline elements by adding them to the inline.tag option.

5.2. Self-closing (empty) elements

An empty element is an element from HTML, SVG, or MathML that cannot have any child nodes (i.e., nested elements or text nodes).

HTML Formatter identifies the following elements as "inline":

This is a subset of the empty elements defined in the MDN. All other elements require closing tag.

You can set additional self-closing elements by adding them to the self-closing.tag option.

5.3. Preformatted elements

Specific element will be not touched by the formatter. The built in preformatted elements are

You can exclude additional elements by adding them to the formatted.tag option.

There settings for all the formatted tags are the following:

Setting Type Description
formatted.tag.cleanup-empty boolean Removes the inner content if it has only whitespace.
formatted.tag.opening-break boolean Inserts a line break after the opening tag.
formatted.tag.closing-break boolean Inserts a line break before the closing tag.
formatted.tag.trim boolean Removes the leading and trailing whitespace of the content.

You can also change the settings for a specific tag. For example, disabling the cleanup-empty setting for the script tag looks like this:

5.4. Attributes

Additional settings for formatted tags are the following:

Setting Type Description
cleanup-empty boolean Removes the inner content if it has only whitespace.
opening-break boolean Inserts a line break after the opening tag.
closing-break boolean Inserts a line break before the closing tag.
trim boolean Removes the leading and trailing whitespace of the content.

6. Methods

Name Attributes Description Example
constructor Config|array|null Creates a Formatter class instance $f = new Formatter($config);
getConfig - Configuration getter $config = $f->getConfig();
getConfigArray - Configuration getter $config = $f->getConfigArray();
setConfig Config|array|null Configuration setter $f->setConfig($config);
beautify string Beautifies the input string $output = $f->beautify($html);
minify string Minifies the input string $output = $f->minify($html);

7. Credits

Thanks to Gajus Kuizinas for originally creating gajus/dindent and all the other developers who are tirelessly working on it. HTML Formatter was inspired by Dindent.


All versions of html-formatter with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4 || ^8.0
ext-mbstring Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package mallardduck/html-formatter contains the following files

Loading the files please wait ....