Skip to content

Commit e1afb56

Browse files
committed
Vary Rule value handling based on type
A Rule can return a RuleValueList or a string depending on the CSS property being parsed. A format handler must be supplied when rendering the RuleValueList.
1 parent e72336f commit e1afb56

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/Svg/Style.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ public function fromStyleSheets(AbstractTag $tag, $attributes) {
109109
$class = isset($attributes["class"]) ? preg_split('/\s+/', trim($attributes["class"])) : null;
110110

111111
$stylesheets = $tag->getDocument()->getStyleSheets();
112+
$outputFormat = \Sabberworm\CSS\OutputFormat::createCompact();
112113

113114
$styles = array();
114115

@@ -127,7 +128,12 @@ public function fromStyleSheets(AbstractTag $tag, $attributes) {
127128
if ($_selector === ".$_class") {
128129
/** @var \Sabberworm\CSS\Rule\Rule $_rule */
129130
foreach ($_decl->getRules() as $_rule) {
130-
$styles[$_rule->getRule()] = $_rule->getValue()->render() . "";
131+
$value = $_rule->getValue();
132+
if ($value instanceof \Sabberworm\CSS\Value\Value) {
133+
$styles[$_rule->getRule()] = $value->render($outputFormat) . "";
134+
} else {
135+
$styles[$_rule->getRule()] = $value . "";
136+
}
131137
}
132138

133139
break 2;
@@ -139,7 +145,12 @@ public function fromStyleSheets(AbstractTag $tag, $attributes) {
139145
if ($_selector === $tag->tagName) {
140146
/** @var \Sabberworm\CSS\Rule\Rule $_rule */
141147
foreach ($_decl->getRules() as $_rule) {
142-
$styles[$_rule->getRule()] = $_rule->getValue()->render() . "";
148+
$value = $_rule->getValue();
149+
if ($value instanceof \Sabberworm\CSS\Value\Value) {
150+
$styles[$_rule->getRule()] = $value->render($outputFormat) . "";
151+
} else {
152+
$styles[$_rule->getRule()] = $value . "";
153+
}
143154
}
144155

145156
break;

0 commit comments

Comments
 (0)