Is there an application to automatically format CSS files?

I have a compressed CSS file (all spaces removed) that I want to check, but this is a huge pain checking it as it is. Is there any utility (preferably linux command line) with which I can run the file to format it?

+5
source share
9 answers

I have written some formatting for you in Ruby. Save it as some file .rband use it through the CLI, for example ruby format.rb input.css input-clean.css:

#Formats CSS

input, output = ARGV

#Input
if input == nil or output == nil
    puts "Syntax: #{$0} [input] [output]"
    exit
end

#Opens file
unless File.exist? input
    puts "File #{input} doesn't exist."
    exit
end

#Reads file
input = File.read input
#Creates output file
output = File.new output, "w+"

#Processes input
input = input.gsub("{", "\n{\n\t")
         .gsub(",", ", ")
         .gsub(";", ";\n\t")
         .gsub(/\t?}/, "}\n\n\n")
         .gsub(/\t([^:]+):/, "\t" + '\1: ')

#Writes output
output.write input

#Closes output
output.close
+2
source

The online service that Dave Newman mentioned was converted to a Node.js script, which you can run on the command line. If you have NPM installed, you can simply:

npm install -g cssunminifier

. :

cssunminifier style.min.css style.css
cssunminifier --width=8 style.min.css
curl http://cdn.sstatic.net/stackoverflow/all.css | cssunminifier - | less

css unminifier

+7

-.

Firebug.

+5

"". Google, .

+3

, -, CSS Tidy.

+2
+1
0

, Visual Studio . ( , )

0
source

take a look at the vkBeautify plugin

http://www.eslinstructor.net/vkbeautify/

It can decorate (pretty print) CSS, XML and JSON text,

written in simple javascript, small, simple and fast

0
source

All Articles