Skip to content
Snippets Groups Projects
Commit fd7c2db0 authored by Andreas Gohr's avatar Andreas Gohr
Browse files

CSS compressor fix

darcs-hash:20060122124613-7ad00-41ed03a1d6668874a324db8bc98aee72ab90e277.gz
parent bf5e5a5b
No related branches found
No related tags found
No related merge requests found
......@@ -21,6 +21,25 @@ class css_css_compress_test extends UnitTestCase {
$this->assertEqual(css_compress($text), '#comment/* */{color:lime;}');
}
function test_slcom1(){
$text = '// this is a comment';
$this->assertEqual(css_compress($text), '');
}
function test_slcom2(){
$text = '#foo {
color: lime; // another comment
}';
$this->assertEqual(css_compress($text), '#foo{color:lime;}');
}
function test_slcom3(){
$text = '#foo {
background-image: url(http://foo.bar/baz.jpg);
}';
$this->assertEqual(css_compress($text), '#foo{background-image:url(http://foo.bar/baz.jpg);}');
}
function test_hack(){
$text = '/* Mac IE will not see this and continue with inline-block */
/* \\*/
......
......@@ -241,16 +241,16 @@ function css_pluginstyles($mode='screen'){
* @author Andreas Gohr <andi@splitbrain.org>
*/
function css_compress($css){
//strip comments through a callback
$css = preg_replace_callback('#(/\*)(.*?)(\*/)#s','css_comment_cb',$css);
//strip (incorrect but common) one line comments
$css = preg_replace('!//.*$!m','',$css);
$css = preg_replace('/(?<!:)\/\/.*$/m','',$css);
// strip whitespaces
$css = preg_replace('![\r\n\t ]+!',' ',$css);
$css = preg_replace('/ ?([:;,{}\/]) ?/','\\1',$css);
//strip comments through a callback
$css = preg_replace_callback('#(/\*)(.*?)(\*/)#s','css_comment_cb',$css);
// shorten colors
$css = preg_replace("/#([0-9a-fA-F]{1})\\1([0-9a-fA-F]{1})\\2([0-9a-fA-F]{1})\\3/", "#\\1\\2\\3",$css);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment