Skip to content

Commit d5bf1ce

Browse files
author
Frederic Massart
committed
Parsing of filter rules specific to Microsoft
1 parent 850cbbc commit d5bf1ce

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

lib/Sabberworm/CSS/Parser.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Sabberworm\CSS\Value\Color;
2020
use Sabberworm\CSS\Value\URL;
2121
use Sabberworm\CSS\Value\CSSString;
22+
use Sabberworm\CSS\Value\Statement;
2223
use Sabberworm\CSS\Rule\Rule;
2324
use Sabberworm\CSS\Parsing\UnexpectedTokenException;
2425
use Sabberworm\CSS\Comment\Comment;
@@ -436,6 +437,8 @@ private function parsePrimitiveValue() {
436437
$oValue = $this->parseURLValue();
437438
} else if ($this->comes("'") || $this->comes('"')) {
438439
$oValue = $this->parseStringValue();
440+
} else if ($this->comes("progid:")) {
441+
$oValue = $this->parseMicrosoftFilter();
439442
} else {
440443
$oValue = $this->parseIdentifier(true, false);
441444
}
@@ -496,6 +499,11 @@ private function parseColorValue() {
496499
return new Color($aColor, $this->iLineNo);
497500
}
498501

502+
private function parseMicrosoftFilter() {
503+
$sStatement = $this->consumeUntil(')', true, true);
504+
return new Statement($sStatement, $this->iLineNo);
505+
}
506+
499507
private function parseURLValue() {
500508
$bUseUrl = $this->comes('url', true);
501509
if ($bUseUrl) {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Sabberworm\CSS\Value;
4+
5+
6+
class Statement extends PrimitiveValue {
7+
8+
private $sStatement;
9+
10+
public function __construct($sStatement = '', $iLineNo = 0) {
11+
parent::__construct($iLineNo);
12+
$this->sStatement = $sStatement;
13+
}
14+
15+
public function setStatement($sStatement) {
16+
$this->sStatement = $sStatement;
17+
}
18+
19+
public function getStatement() {
20+
return $this->sStatement;
21+
}
22+
23+
public function __toString() {
24+
return $this->render(new \Sabberworm\CSS\OutputFormat());
25+
}
26+
27+
public function render(\Sabberworm\CSS\OutputFormat $oOutputFormat) {
28+
return $this->sStatement;
29+
}
30+
31+
}

tests/Sabberworm/CSS/ParserTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,4 +582,10 @@ function testTopLevelCommentExtracting() {
582582
$this->assertCount(1, $comments);
583583
$this->assertEquals("Find Me!", $comments[0]->getComment());
584584
}
585+
586+
function testMicrosoftFilterParsing() {
587+
$oDoc = $this->parsedStructureForFile('ms-filter');
588+
$sExpected = ".test {filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#80000000', endColorstr='#00000000', GradientType=1);}";
589+
$this->assertSame($sExpected, $oDoc->render());
590+
}
585591
}

tests/files/ms-filter.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.test {filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#80000000', endColorstr='#00000000', GradientType=1);}

0 commit comments

Comments
 (0)