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.

Author:
Your Email:

Subject:

HTML input is enabled. Make sure you escape all HTML and angled brackets with &lt; and &gt;.

Auto-paragraphing is enabled. Double newlines will be converted to paragraphs; for single newlines, use the pre tag.

Allowed tags: a, abbr, acronym, b, blockquote, caption, cite, code, dd, del, dfn, div, dl, dt, em, i, ins, kbd, li, ol, p, pre, s, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, var.

For inputting literal code such as HTML and PHP for display, use CDATA tags to auto-escape your angled brackets, and pre to preserve newlines:

<pre><![CDATA[
Place code here
]]></pre>

Power users, you can hide this notice with:

.htmlpurifier-help {display:none;}

Message: