File tree 1 file changed +38
-0
lines changed
1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * StagON Name: HTML Minifier
4
+ * StagON Text Domain: html-minifier
5
+ * StagON URI: https://stagphp.io
6
+ * StagON Description: This StagON minifies the HTML output
7
+ * Version: 1.0
8
+ * Author: StagPHP
9
+ * License: GPL3
10
+ * License URI: https://www.gnu.org/licenses/gpl-3.0.html
11
+ */
12
+
13
+
14
+ function sanitize_output ($ buffer ) {
15
+ $ search = array (
16
+ '/\>[^\S ]+/s ' , // strip white spaces after tags, except space
17
+ '/[^\S ]+\</s ' , // strip white spaces before tags, except space
18
+ '/(\s)+/s ' , // shorten multiple whitespace sequences
19
+ '/<!--(.|\s)*?-->/ ' // Remove HTML comments
20
+ );
21
+
22
+ $ replace = array (
23
+ '> ' ,
24
+ '< ' ,
25
+ '\\1 ' ,
26
+ ''
27
+ );
28
+
29
+ $ buffer = preg_replace ($ search , $ replace , $ buffer );
30
+
31
+ return $ buffer ;
32
+ }
33
+
34
+ function minified_output (){
35
+ echo sanitize_output (ob_get_clean ());
36
+ }
37
+
38
+ stag_add_action ('processed ' , 'minified_output ' , TRUE );
You can’t perform that action at this time.
0 commit comments