ben-eb / perfectionist

Beautify CSS files.
MIT License
229 stars 14 forks source link

Compact format breaks "content" rules with round braces #28

Closed catearcher closed 7 years ago

catearcher commented 8 years ago

Take the following LESS file:

.foo {
  color: white;

  &:before {
    content: "(";
  }

  &:after {
    content: ")";
  }
}

What this should compile to when using the "compact" format is:

.foo { color: #fff; }
.foo:before { content: "("; }
.foo:after { content: ")"; }

What is does compile to is this:

.foo { color: #fff; }
.foo:before { content: "( "; }
.foo:after { content: " )"; }

As you can see, extra spaces are added before the opening and before the closing brace.

This is due to this part of the code:

rule.value = rule.value.replace(/\(\s*/g, '( ');
rule.value = rule.value.replace(/\s*\)/g, ' )');

In the "expanded" and the "compressed" modes, the replacements don't contain spaces; in "compact" mode, however, they do.

Also: In the values of content rules, nothing should be replaced at all (that's also true for the other format modes), because the value is rendered by the browser as-is.