zaininnari/html-minifier 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

zaininnari/html-minifier

最新稳定版本:0.4.2

Composer 安装命令:

composer require zaininnari/html-minifier

包简介

The Blink HTMLTokenizer ported to PHP.

README 文档

README

The Blink HTMLTokenizer ported to PHP and minify HTML.

Build Status Coverage Status

Requirements

  • Any flavor of PHP 5.3 should do
  • [optional] PHPUnit 3.5+ to execute the test suite (phpunit --version)

Use

Create composer.json. [composer.json]

{
    "require": {
        "zaininnari/html-minifier": "*"
    }
}

Download composer.phar and install.

curl -sS https://getcomposer.org/installer | php
php composer.phar install
<?php
require 'vendor/autoload.php';

use zz\Html\HTMLMinify;

$html = '<div>
    <p>
        text
    </p> 
</div>';

// shortcut. retrun minify html
$minify = HTMLMinify::minify($html);

// detail
$HTMLMinify = new HTMLMinify($html);
$minify = $HTMLMinify->process();

output html

<div>
<p>
text
</p> 
</div>

Option

optimizationLevel

OPTIMIZATION_SIMPLE(default)

Replace many whitespace to a single whitespace. This option leave a new line of one.

[input]

<section>
    <h1>Example of paragraphs</h1>
    This is the <em>first</em> paragraph in this example.
    <p>This is the second.</p>
    <!-- This is not a paragraph. -->
    <!--[if expression]> HTML <![endif]-->
    <![if expression]> HTML <![endif]>
</section>

[output]

<section>
<h1>Example of paragraphs</h1>
This is the <em>first</em> paragraph in this example.
<p>This is the second.</p>
<!--[if expression]> HTML <![endif]-->
<![if expression]> HTML <![endif]>
</section>

OPTIMIZATION_ADVANCED

Remove the whitespace of all as much as possible.

  • Remove whitespace
    • between block element and block element
    • between block element and inline element
    • run trim in style, script and downlevel-revealed conditional comment
    • [future] consider comments
  • Preserve whitespace
    • between inline element and inline element

[input]

<section>
    <h1>Example of paragraphs</h1>
    This is the <em>first</em> paragraph in this example.
    <p>This is the second.</p>
    <!-- This is not a paragraph. -->
    <!--[if expression]> HTML <![endif]-->
    <![if expression]> HTML <![endif]>
</section>

[output]

<section><h1>Example of paragraphs</h1>This is the<em>first</em>paragraph in this example.<p>This is the second.</p><!--[if expression]> HTML <![endif]--><![if expression]>HTML<![endif]></section>

Author

zaininnari
http://www.zay.jp/

Original source

http://www.chromium.org/blink

License

Licensed under the MIT License and other License - see the LICENSE file for details

统计信息

  • 总下载量: 389.32k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 62
  • 点击次数: 1
  • 依赖项目数: 9
  • 推荐数: 5

GitHub 信息

  • Stars: 61
  • Watchers: 5
  • Forks: 17
  • 开发语言: PHP

其他信息

  • 授权协议: The
  • 更新时间: 2013-07-14