-
Notifications
You must be signed in to change notification settings - Fork 0
/
html-minifier.php
42 lines (36 loc) · 1.21 KB
/
html-minifier.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
/**
* StagON Name: HTML Minifier
* StagON Text Domain: html-minifier
* StagON Version: 1.0
* StagON Developer: STAGPHP COMMUNITY
* StagON URI: https://stagphp.io
* StagON Description: This StagON minifies the HTML output
* StagON Source: Open
* StagON Source URL: https://github.com/StagPHP/html-minifier
* StagON Package: https://github.com/StagPHP/html-minifier/raw/master/stagon-dist/html-minifier.zip
* StagON Docs: https://github.com/StagPHP/html-minifier
* Compitablilty: 1.0.6
* License: GPL3
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
*/
function sanitize_output($buffer) {
$search = array(
'/\>[^\S ]+/s', // strip white spaces after tags, except space
'/[^\S ]+\</s', // strip white spaces before tags, except space
'/(\s)+/s', // shorten multiple whitespace sequences
'/<!--(.|\s)*?-->/' // Remove HTML comments
);
$replace = array(
'>',
'<',
'\\1',
''
);
$buffer = preg_replace($search, $replace, $buffer);
return $buffer;
}
function minified_output(){
echo sanitize_output(ob_get_clean());
}
stag_add_action('processed', 'minified_output', TRUE);