diff --git a/lib/Minify/HTML.php b/lib/Minify/HTML.php index 89cbaf0..f2c25fa 100644 --- a/lib/Minify/HTML.php +++ b/lib/Minify/HTML.php @@ -71,16 +71,17 @@ class Minify_HTML { $html = preg_replace('/^\\s+|\\s+$/m', '', $html); // remove ws around block/undisplayed elements - $html = preg_replace('/\\s*(<\\/?(?:area|base(?:font)?|blockquote|body' + $html = preg_replace('/\\s+(<\\/?(?:area|base(?:font)?|blockquote|body' .'|caption|center|cite|col(?:group)?|dd|dir|div|dl|dt|fieldset|form' .'|frame(?:set)?|h[1-6]|head|hr|html|legend|li|link|map|menu|meta' .'|ol|opt(?:group|ion)|p|param|t(?:able|body|head|d|h||r|foot|itle)' .'|ul)\\b[^>]*>)/i', '$1', $html); - // remove ws between and inside elements. - $html = preg_replace('/>\\s+(\\S[\\s\\S]*?)? $1<", $html); - $html = preg_replace('/>(\\S[\\s\\S]*?)?\\s+$1 <", $html); - $html = preg_replace('/>\\s+ <", $html); + // remove ws outside of all elements + $html = preg_replace_callback( + '/>([^<]+)' . preg_replace('/^\\s+|\\s+$/', ' ', $m[1]) . '<'; + } + protected static function _removePreCB($m) { self::$_pres[] = $m[1]; diff --git a/web/test/test_HTML.php b/web/test/test_HTML.php index 1551c9f..da68e08 100644 --- a/web/test/test_HTML.php +++ b/web/test/test_HTML.php @@ -12,17 +12,19 @@ function test_HTML() $src = file_get_contents($thisDir . '/_test_files/html/before.html'); $minExpected = file_get_contents($thisDir . '/_test_files/html/before.min.html'); + $time = microtime(true); $minOutput = Minify_HTML::minify($src, array( 'cssMinifier' => array('Minify_CSS', 'minify') ,'jsMinifier' => array('Minify_Javascript', 'minify') )); + $time = microtime(true) - $time; $passed = assertTrue($minExpected === $minOutput, 'Minify_HTML'); if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) { - echo "\n---Output: " .strlen($minOutput). " bytes\n\n{$minOutput}\n\n"; - echo "---Expected: " .strlen($minExpected). " bytes\n\n{$minExpected}\n\n"; - echo "---Source: " .strlen($src). " bytes\n\n{$src}\n\n\n"; + echo "\n---Output: ", strlen($minOutput), " bytes (", round($time * 1000), " ms)\n\n{$minOutput}\n\n" + , "---Expected: ", strlen($minExpected), " bytes\n\n{$minExpected}\n\n" + , "---Source: ", strlen($src), " bytes\n\n{$src}\n\n\n"; } }