This is my first go at a Perl script to clean up CSS files.
@css = (
'-moz-binding',
'-moz-user-focus',
'display',
'visibility',
'clip',
'position',
'z-index',
'top',
'right',
'bottom',
'left',
'float',
'clear',
'margin',
'border',
'border-width',
'border-style',
'border-color',
'border-collapse',
'border-spacing',
'-moz-border-radius',
'outline',
'outline-width',
'outline-style',
'outline-color',
'padding',
'width',
'height',
'min-width',
'min-height',
'max-width',
'max-height',
'background',
'background-attachment',
'background-color',
'background-image',
'background-position',
'background-repeat',
'list-style',
'list-style-image',
'list-style-position',
'list-style-type',
'color',
'font',
'font-family',
'font-size',
'font-size-adjust',
'font-stretch',
'font-style',
'font-variant',
'font-weight',
'text-decoration',
'text-indent',
'text-shadow',
'text-transform',
'text-align',
'vertical-align',
'direction',
'unicode-bidi',
'letter-spacing',
'word-spacing',
'line-height',
'white-space',
'overflow',
'cursor',
'content',
'counter-increment',
'counter-reset',
'quotes',
'marker-offset');
foreach (0 .. $#css) {
$css{$css[$_]} = $_;
}
while (<>) {
if (/^\s*([-a-z]+)\s*:\s*(.*\s*)/ && defined($css{$1})) {
$_{$1} = substr(" $1 ", 0, 24) . ": " . $2;
} else {
foreach (@css) {
print $_{$_} if defined($_{$_});
}
%_ = ();
s/^\s+// if (/{|}/);
s/,\s+/,\n/g;
print;
}
}