Home > Back-end >  Formatting CSS into single or multiple lines based on property count
Formatting CSS into single or multiple lines based on property count

Time:01-05

Consider the following CSS:

.foo {
 color: red;
}

.bar {
 color: blue;
 font-size: 14px;
}

.baz { color: pink }

I am looking for a way to format that code as follows - All declarations with one property (.foo) should be on one line. Any declarations with more than one property (.bar) should remain on multiple lines. One declaration rules that already happen to be on one line (.baz) should remain as such.

.foo { color: red }

.bar {
 color: blue;
 font-size: 14px;
}

.baz { color: pink }

I don't care what tool I use, as it's generally a once only job on new files I receive. I have tried with Notepad as an obvious, and powerful choice, but the regex eludes me. It's something like "Find the content between brackets, count the line returns etc..." but I just can't get it.

CodePudding user response:

This would work, even for enter image description here

Screenshot (after):

enter image description here

  •  Tags:  
  • Related