All Projects → wasinger → html-pretty-min

wasinger / html-pretty-min

Licence: MIT license
PHP library for minifying and indenting HTML documents that works on the DOM tree

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to html-pretty-min

RazorHtmlMinifier.Mvc5
↘️ Trivial compile-time Razor HTML Minifier for ASP.NET MVC 5.
Stars: ✭ 31 (+63.16%)
Mutual labels:  html-minification
Logger
✔️ Simple, pretty and powerful logger for android
Stars: ✭ 13,093 (+68810.53%)
Mutual labels:  pretty-printer
zprint-clj
Node.js wrapper for ZPrint Clojure source code formatter
Stars: ✭ 13 (-31.58%)
Mutual labels:  pretty-printer
php-ast-reverter
Reverts the php-ast AST back into (somewhat) PSR-compliant code
Stars: ✭ 49 (+157.89%)
Mutual labels:  pretty-printer
glitter
Display git status information in your shell prompt
Stars: ✭ 47 (+147.37%)
Mutual labels:  pretty-printer
StyLua
An opinionated Lua code formatter
Stars: ✭ 479 (+2421.05%)
Mutual labels:  pretty-printer
pretty print formatter
Pretty Print Formatter for Elixir Logger module -- Colorize Ecto's SQL ouput 🖌️
Stars: ✭ 22 (+15.79%)
Mutual labels:  pretty-printer
pretty.rs
Wadler-style pretty-printing combinators in Rust
Stars: ✭ 85 (+347.37%)
Mutual labels:  pretty-printer
Tabula
🈸 Pretty printer for maps/structs collections (Elixir)
Stars: ✭ 85 (+347.37%)
Mutual labels:  pretty-printer
tv
📺(tv) Tidy Viewer is a cross-platform CLI csv pretty printer that uses column styling to maximize viewer enjoyment.
Stars: ✭ 1,763 (+9178.95%)
Mutual labels:  pretty-printer
ex format
ExFormat formats Elixir source code according to a standard set of rules
Stars: ✭ 39 (+105.26%)
Mutual labels:  pretty-printer
kotlin-metadata-printer
Prints the Kotlin metadata attached to Java class files
Stars: ✭ 41 (+115.79%)
Mutual labels:  pretty-printer
sexp-grammar
Invertible parsing for S-expressions
Stars: ✭ 28 (+47.37%)
Mutual labels:  pretty-printer
language-rust
Parser and pretty-printer for the Rust language
Stars: ✭ 78 (+310.53%)
Mutual labels:  pretty-printer

HTML Pretty-Min

Build Status Latest Version

HTML Pretty-Min is a PHP library for minifying and prettyprinting (indenting) HTML documents that works directly on the DOM tree of an HTML document.

Currently it has the following features:

  • Prettyprint:

    • Indent Block-level elements, do not indent inline elements
  • Minify:

    • Remove whitespace and newlines
    • Compress embedded Javascript using mrclay/jsmin-php
    • Compress embedded CSS using tubalmartin/cssmin
    • Remove some attributes when their value is empty (by default "style" and "class" attributes)
    • Remove comments, except those matching some given regular expressions (by default, IE conditional comments are kept)

Installation

HTML Pretty-Min is listed on Packagist.

composer require wa72/html-pretty-min

Usage

<?php
use Wa72\HtmlPrettymin\PrettyMin;

$pm = new PrettyMin();

$output = $pm
    ->load($html)   // $html may be a \DOMDocument, a string containing an HTML code, 
                    // or an \SplFileInfo pointing to an HTML document
    ->minify()
    ->saveHtml();

For prettyprinting, call the indent() method instead of minify().

Attention: Because the formatting is done directly on the DOM tree, a DOMDocument object given to the load() method will be modified:

$dom_document = new \DOMDocument('1.0', 'UTF-8');
$dom_document->loadHTML('<html>...some html code...</html>');

$pm->load($dom_document)->minify();

echo $dom_document->saveHTML(); // Will output the minified, not the original, document
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].