Unzip a stylesheet using sed

im compresses the stylesheet into 1 line using

cat stylesheet.css | gsed "s|/\*\(\\\\\)\?\*/|/~\1~/|g" -e "s|/\*[^*]*\*\+\([^/][^*]*\*\+\)*/||g" -e "s|\([^:/]\)//.*$|\1|" -e "s|^//.*$||" | tr '\n' ' ' | sed -e "s|/\*[^*]*\*\+\([^/][^*]*\*\+\)*/||g" -e "s|/\~\(\\\\\)\?\~/|/*\1*/|g" -e "s|\s\+| |g" -e "s| \([{;:,]\)|\1|g" -e "s|\([{;:,]\) |\1|g"

im trying to change the process.

cat stylesheet-compress.css | gsed 's/\([;{]\)\([^\n]\)/\1\n\t\2/g' | gsed 's/\([^}]\)}/\1;\n}\n\n/g' | gsed 's/{/ {/g' | gsed 's/[,]/& /g' | gsed '/}/ { n;n; s/}\n\([^\n]\)/}\n\n\1/ }'

works for the most part, but some css elements are indented and optional; s

+3
source share
1 answer

I think you are looking for a CSS formatter. There are a lot of them on the Internet. For instance. http://www.lonniebest.com/FormatCSS/ . If you need to do this from the sink, I would spawn to another program to make a heavy lift. http://cthedot.de/cssutils/ will do the trick.

+3
source

All Articles