mirror of
https://github.com/mrclay/minify.git
synced 2025-08-06 14:16:28 +02:00
Minfy_HTML: all Unix newlines, replaces spaces with newlines in some tags to limit line lengths
Minify_CSS: fix Issue 49, uses newlines in common descendant selectors to limit line lengths All tests passing with shorter lines and no added bytes!
This commit is contained in:
@@ -113,9 +113,6 @@ class Minify_CSS {
|
||||
$css = preg_replace_callback('@\\s*/\\*([\\s\\S]*?)\\*/\\s*@'
|
||||
,array('Minify_CSS', '_commentCB'), $css);
|
||||
|
||||
// compress whitespace.
|
||||
$css = preg_replace('/\\s+/', ' ', $css);
|
||||
|
||||
// leave needed comments
|
||||
$css = str_replace('/*keep*/', '/**/', $css);
|
||||
|
||||
@@ -168,6 +165,14 @@ class Minify_CSS {
|
||||
// remove spaces between font families
|
||||
$css = preg_replace_callback('/font-family:([^;}]+)([;}])/'
|
||||
,array('Minify_CSS', '_fontFamilyCB'), $css);
|
||||
|
||||
$css = preg_replace('/@import\\s+url/', '@import url', $css);
|
||||
|
||||
// replace any ws involving newlines with a single newline
|
||||
$css = preg_replace('/[ \\t]*\\n+\\s*/', "\n", $css);
|
||||
|
||||
// separate common descendent selectors with newlines (to limit line lengths)
|
||||
$css = preg_replace('/([\\w#\\.]+)\\s+([\\w#\\.]+){/', "$1\n$2{", $css);
|
||||
|
||||
$rewrite = false;
|
||||
if (isset($options['prependRelativePath'])) {
|
||||
@@ -178,13 +183,26 @@ class Minify_CSS {
|
||||
$rewrite = true;
|
||||
}
|
||||
if ($rewrite) {
|
||||
$css = preg_replace_callback('/@import ([\'"])(.*?)[\'"]/'
|
||||
$css = preg_replace_callback('/@import\\s+([\'"])(.*?)[\'"]/'
|
||||
,array('Minify_CSS', '_urlCB'), $css);
|
||||
$css = preg_replace_callback('/url\\(([^\\)]+)\\)/'
|
||||
,array('Minify_CSS', '_urlCB'), $css);
|
||||
}
|
||||
self::$_tempPrepend = self::$_tempCurrentPath = '';
|
||||
return trim($css);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace what looks like a set of selectors
|
||||
*
|
||||
* @param array $m regex matches
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function _selectorsCB($m)
|
||||
{
|
||||
// remove ws around the combinators
|
||||
return preg_replace('/\\s*([,>+~])\\s*/', '$1', $m[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -251,19 +269,6 @@ class Minify_CSS {
|
||||
return ''; // remove all other comments
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace what looks like a set of selectors
|
||||
*
|
||||
* @param array $m regex matches
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function _selectorsCB($m)
|
||||
{
|
||||
// remove ws around the combinators
|
||||
return preg_replace('/\\s*([,>+~])\\s*/', '$1', $m[0]);
|
||||
}
|
||||
|
||||
protected static function _urlCB($m)
|
||||
{
|
||||
$isImport = (0 === strpos($m[0], '@import'));
|
||||
|
@@ -34,7 +34,7 @@ class Minify_HTML {
|
||||
self::$_jsMinifier = $options['jsMinifier'];
|
||||
}
|
||||
|
||||
$html = trim($html);
|
||||
$html = str_replace("\r\n", "\n", trim($html));
|
||||
|
||||
self::$_isXhtml = (false !== strpos($html, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML'));
|
||||
|
||||
@@ -77,6 +77,9 @@ class Minify_HTML {
|
||||
.'|ol|opt(?:group|ion)|p|param|t(?:able|body|head|d|h||r|foot|itle)'
|
||||
.'|ul)\\b[^>]*>)/i', '$1', $html);
|
||||
|
||||
// line break within some tags to limit line lengths
|
||||
$html = preg_replace('/(<(?:div|span|a|p|input)) ([^>]+>)/i', "$1\n$2", $html);
|
||||
|
||||
// remove ws outside of all elements
|
||||
$html = preg_replace_callback(
|
||||
'/>([^<]+)</'
|
||||
|
Reference in New Issue
Block a user