@@ -572,12 +572,26 @@ function import(&$url, &$media) {
572
572
}
573
573
574
574
// a list of media types, very lenient
575
- function mediaTypes (&$ types ) {
575
+ function mediaTypes (&$ parts ) {
576
+ $ parts = array ();
577
+ while ($ this ->to ("( " , $ chunk , false , "[^{] " )) {
578
+ $ parts [] = array ('raw ' , $ chunk ."( " );
579
+ $ s = $ this ->seek ();
580
+ if ($ this ->keyword ($ name ) && $ this ->assign () &&
581
+ $ this ->propertyValue ($ value ))
582
+ {
583
+ $ parts [] = array ('assign ' , $ name , $ value );
584
+ } else {
585
+ $ this ->seek ($ s );
586
+ }
587
+ }
588
+
576
589
if ($ this ->to ('{ ' , $ rest , true , true )) {
577
- $ types = trim ( $ rest );
590
+ $ parts [] = array ( ' raw ' , $ rest );
578
591
return true ;
579
592
}
580
593
594
+ $ parts = null ;
581
595
return false ;
582
596
}
583
597
@@ -1018,7 +1032,7 @@ function compileBlock($block, $parent_tags = null) {
1018
1032
if ($ special_block ) {
1019
1033
$ this ->indentLevel --;
1020
1034
if (isset ($ block ->media )) {
1021
- echo " @media " . $ block -> media ;
1035
+ echo $ this -> compileMedia ( $ block ) ;
1022
1036
} elseif (isset ($ block ->keyframes )) {
1023
1037
echo $ block ->tags [0 ]." " .
1024
1038
$ this ->compileValue ($ this ->reduce ($ block ->keyframes ));
@@ -1374,6 +1388,21 @@ function compileValue($value) {
1374
1388
}
1375
1389
}
1376
1390
1391
+ function compileMedia ($ block ) {
1392
+ $ mediaParts = array ();
1393
+ foreach ($ block ->media as $ part ) {
1394
+ if ($ part [0 ] == "raw " ) {
1395
+ $ mediaParts [] = $ part [1 ];
1396
+ } elseif ($ part [0 ] == "assign " ) {
1397
+ list (, $ propName , $ propVal ) = $ part ;
1398
+ $ mediaParts [] = "$ propName: " .
1399
+ $ this ->compileValue ($ this ->reduce ($ propVal ));
1400
+ }
1401
+ }
1402
+
1403
+ return "@media " .trim (implode ($ mediaParts ));
1404
+ }
1405
+
1377
1406
function lib_isnumber ($ value ) {
1378
1407
return $ this ->toBool (is_numeric ($ value [1 ]));
1379
1408
}
@@ -2090,8 +2119,13 @@ function preg_quote($what) {
2090
2119
2091
2120
// advance counter to next occurrence of $what
2092
2121
// $until - don't include $what in advance
2122
+ // $allowNewline, if string, will be used as valid char set
2093
2123
function to ($ what , &$ out , $ until = false , $ allowNewline = false ) {
2094
- $ validChars = $ allowNewline ? ". " : "[^ \n] " ;
2124
+ if (is_string ($ allowNewline )) {
2125
+ $ validChars = $ allowNewline ;
2126
+ } else {
2127
+ $ validChars = $ allowNewline ? ". " : "[^ \n] " ;
2128
+ }
2095
2129
if (!$ this ->match ('( ' .$ validChars .'*?) ' .$ this ->preg_quote ($ what ), $ m , !$ until )) return false ;
2096
2130
if ($ until ) $ this ->count -= strlen ($ what ); // give back $what
2097
2131
$ out = $ m [1 ];
@@ -2111,7 +2145,7 @@ function match($regex, &$out, $eatWhitespace = true) {
2111
2145
// match something without consuming it
2112
2146
function peek ($ regex , &$ out = null ) {
2113
2147
$ r = '/ ' .$ regex .'/Ais ' ;
2114
- $ result = preg_match ($ r , $ this ->buffer , $ out , null , $ this ->count );
2148
+ $ result = preg_match ($ r , $ this ->buffer , $ out , null , $ this ->count );
2115
2149
2116
2150
return $ result ;
2117
2151
}
0 commit comments