diff --git a/src/Property/Selector.php b/src/Property/Selector.php index b935b2a8..0f3965b9 100644 --- a/src/Property/Selector.php +++ b/src/Property/Selector.php @@ -93,6 +93,55 @@ public function getSpecificity(): int public function render(OutputFormat $outputFormat): string { - return $this->getSelector(); + $tidy = [ + '>', + '~', + '+', + ]; + + $selector = $this->getSelector(); + $attribute = false; + $output = ''; + + for ($i = 0; $i < \strlen($selector); ++$i) { + $current = $selector[$i]; + + if ($current === '[') { + $attribute = true; + $output .= $current; + $previous = $current; + continue; + } + + if ($attribute) { + if ($current === ']') { + $attribute = false; + } + + $output .= $current; + $previous = $current; + continue; + } + + if (\in_array($current, $tidy, true)) { + if ($previous !== ' ') { + $output .= ' '; + } + + $output .= $current; + + if ($selector[$i +1] !== ' ') { + $output .= ' '; + } + + $current = ' '; + } else { + $output .= $current; + } + + $previous = $current; + } + + return $output; } }