diff options
author | Thor (atiredmachine) <thor@bandwidthbeta.com> | 2012-01-25 05:44:51 +0100 |
---|---|---|
committer | Thor (atiredmachine) <thor@bandwidthbeta.com> | 2012-01-25 05:44:51 +0100 |
commit | 79db4cdba1a1a80634cd76ab8fc69fce7b1a7ea6 (patch) | |
tree | dbcddf0376bedf61e061625cbf66db9df9a03d44 /system | |
parent | 63678a27864fdd6bb0ed89e6940a1d331121072a (diff) |
Improved minifier to restore <pre> contents, remove even more spaces, and process CSS with its own rules.
Diffstat (limited to 'system')
-rwxr-xr-x | system/core/Output.php | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/system/core/Output.php b/system/core/Output.php index 55a505c34..bb39a7f31 100755 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -582,12 +582,45 @@ class CI_Output { switch ($type) { case 'html': + + // Keep track of <pre> tags as they were before processing. + // We'll want to return them to this state later. + preg_match_all('{<pre.+</pre>}msU',$output,$pres_clean); + + // Keep track of <pre> tags as they were before processing. + // We'll want to return them to this state later. + preg_match_all('{<style.+</style>}msU',$output,$style_clean); + // Run <style> content through CSS minifier + foreach ($style_clean[0] as $s) + { + $output = str_replace($s, $this->minify($s,'css'), $output); + } + // Replaces multiple spaces with a single space. - $output = preg_replace('!\s{2,}!',' ',$output); + $output = preg_replace('!\s{2,}!',"\n",$output); + + $output = preg_replace('{\s*(</?(html|head|title|meta|script|link|style|body|h[1-6]|div|p|br).*>)\s*}', '$1', $output); + + // Get the mangled <pre> tags... + preg_match_all('{<pre.+</pre>}msU',$output,$pres_messed); + + // Replace mangled <pre> tags with unprocessed <pre>s + $output = str_replace($pres_messed[0],$pres_clean[0],$output); // ... break; + + + case 'css': + + // Remove spaces around curly brackets + $output = preg_replace('!\s*(:|;|}|{)\s*!','$1',$output); + + // Replace spaces with line breaks to limit line lengths + $output = preg_replace('!\s+!',"\n",$output); + + break; } return $output; |