The best I can come up with is:
#!/usr/bin/env bash
filename=$1
cat "${filename}.css" | \
awk '{gsub(/{|;/,"&\n\t"); print}' | \
awk '{if(match($0,/[^\;]+}/)) {gsub(/}/,";\n&\n"); print}else{gsub(/}/,"\n&"); print}}' \
> "${filename}.unminified.css"
Is there a better way to parse code and insert whitespace for readability?
You can use JavaScript to do that. Let's say you have the css in a variable named
cssCode
then you can run the following code on it:If you try to check you will get the unminfied CSS now!