Skip to content

Commit 589fe50

Browse files
committed
retain CSSList and Rule comments when parsing
1 parent 0309c90 commit 589fe50

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

src/CSSList/CSSList.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ public static function parseList(ParserState $oParserState, CSSList $oList)
8989
$oListItem->setComments($comments);
9090
$oList->append($oListItem);
9191
}
92-
$oParserState->consumeWhiteSpace();
9392
}
9493
if (!$bIsRoot && !$bLenientParsing) {
9594
throw new SourceException("Unexpected end of document", $oParserState->currentLine());
@@ -412,6 +411,15 @@ public function render(OutputFormat $oOutputFormat)
412411
}
413412
foreach ($this->aContents as $oContent) {
414413
$sRendered = $oOutputFormat->safely(function () use ($oNextLevel, $oContent) {
414+
$sResult = '';
415+
$aComments = $oContent->getComments();
416+
417+
foreach ($aComments as $oComment)
418+
{
419+
$sResult .= $oComment->render($oNextLevel);
420+
$sResult .= $oNextLevel->spaceAfterBlocks();
421+
}
422+
return $sResult . $oContent->render($oNextLevel);
415423
return $oContent->render($oNextLevel);
416424
});
417425
if ($sRendered === null) {

src/Rule/Rule.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ public static function parse(ParserState $oParserState)
106106
while ($oParserState->comes(';')) {
107107
$oParserState->consume(';');
108108
}
109-
$oParserState->consumeWhiteSpace();
110109

111110
return $oRule;
112111
}

src/RuleSet/RuleSet.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,15 @@ public function render(OutputFormat $oOutputFormat)
273273
foreach ($this->aRules as $aRules) {
274274
foreach ($aRules as $oRule) {
275275
$sRendered = $oOutputFormat->safely(function () use ($oRule, $oOutputFormat) {
276-
return $oRule->render($oOutputFormat->nextLevel());
276+
$sResult = '';
277+
$aComments = $oRule->getComments();
278+
279+
foreach ($aComments as $oComment)
280+
{
281+
$sResult .= $oComment->render($oOutputFormat);
282+
$sResult .= $oOutputFormat->nextLevel()->spaceBeforeRules();
283+
}
284+
return $sResult . $oRule->render($oOutputFormat->nextLevel());
277285
});
278286
if ($sRendered === null) {
279287
continue;

0 commit comments

Comments
 (0)