Welcome! » Log In » Create A New Profile

Mnify output

Posted by AJenbo 
Mnify output
May 22, 2013 06:43PM

It might be nice to minify the output. I have a rather simple implementation for minifying xHTML 1.0:

//Combine all white space
$html = preg_replace('/\s+/us', ' ', $html);
//Strip all white space surrounding block level elements
$html =  preg_replace(
    &#039;/\s*(<[\/]{0,1}(address|blockquote|center|dir|div|dl|fieldset|form|h1|h2|h3|h4|h5|h6|hr|isindex|menu|noframes|noscript|ol|p|pre|table|ul|dd|dt|frameset|li|tbody|td|tfoot|th|thead|tr|applet|button|del|iframe|insmap|object|script)(\s[^>]+?)*?>)\s*/us&#039;,
    &#039;$1&#039;,
    $html
);
//Strip all whitespace surounding line breaks
$html = preg_replace(&#039;/\s*<br \/>\s*/us&#039;, &#039;<br />&#039;, $html);

It's has a few backsides that i personally can live with

1: Does not respect literal (not written an an html entity) nbsp

2: Strips whitespace form "pre" content.

I think this should be rather fixable though

Edit: Line breaks, don't strip look-a-likes, less greedy regex

Re: Mnify output
May 22, 2013 06:47PM

Hmm, this wouldn't be too hard to add to the Generator.php class. I'm not going to implement it though.

Sorry, you do not have permission to post/reply in this forum.