NAME

CSS::Tidy - reformat CSS

SYNOPSIS

    use CSS::Tidy 'tidy_css';
    my $output = tidy_css ($input);

VERSION

This documents version 0.00_03 of CSS-Tidy corresponding to git commit 1668f31eff84bdf5c79ba4e22b0cdd2117c45935 released on Thu Jan 28 14:17:55 2021 +0900.

DESCRIPTION

This reformats CSS.

The idea is to have a formatting script which can be used to consistently format CSS.

FUNCTIONS

tidy_css

    my $output = tidy_css ($input);

Given CSS in $input, reformat it into a consistent format and return the value.

TRANSFORMATIONS APPLIED

Indentation

Indentation is changed to multiples of four spaces.

Trailing whitespace

Trailing whitespace (blanks after the end of the line) is removed.

Property/value pairs

The spacing between property/value pairs such as

    font-size:21em;

is altered to put a single space after the colon:

    font-size: 21em;
Declaration blocks

A blank line is inserted between declaration blocks.

Single-line braces are expanded out
    .something { something:something; }

is expanded to

    .something {
        something: something;
    }
Comments have a blank line before and after

If the comment is on a line by itself, it will be given one blank line before and after itself.

SCRIPT

The script csstidy runs "tidy_css" on STDIN and prints the result to STDOUT. There is also css-tidy.el in the distribution which enables one to run csstidy on the current buffer.

SEE ALSO

About CSS

CSS Specification

CSS Syntax Module Level 3 at the W3 Consortium.

Other CPAN modules

Parsers

CSS

[Author: IAMCAL; Date: 2011-03-22; Version: 1.09]

CSS::Croco

[Author: GUGU; Date: 2009-12-26; Version: 0.09]

CSS::DOM

[⭐ Author: SPROUT; Date: 2018-01-29; Version: 0.17]

CSS::Object

[⭐ Author: JDEGUEST; Date: 2020-08-12; Version: v0.1.3]

CSS::SAC

[Author: BJOERN; Date: 2008-07-05; Version: 0.08]

👎 This seems to be unusable, it fails on the CSS stylesheets we've tried it on.

CSS::Simple

[Author: KAMELKEV; Date: 2017-11-16; Version: 3224]

CSS::Struct

[Author: SKIM; Date: 2020-08-11; Version: 0.03]

It doesn't have very much documentation. See https://github.com/michal-josef-spacek/CSS-Struct/issues/2.

CSS::Tiny

[⭐ Author: CHORNY; Date: 2016-03-10; Version: 1.20]

Preprocessors

CSS::LESS

[Author: MUGIFLY; Date: 2013-09-20; Version: v0.0.3]

CSS::Sass

[⭐ Author: OCBNET; Date: 2020-05-04; Version: v3.6.3]

Minifiers

CSS::Compressor

[⭐ Author: JANUS; Date: 2018-12-03; Version: 0.05]

CSS::Minifier

[⭐ Author: PMICHAUX; Date: 2007-08-03; Version: 0.01]

CSS::Minifier::XS

[⭐ Author: GTERMARS; Date: 2020-12-31; Version: 0.11]

CSS::Packer

[⭐ Author: LEEJO; Date: 2018-11-06; Version: 2.07]

CSS::Squish

[Author: TSIBLEY; Date: 2010-11-05; Version: 0.10]

Other

CSS::Coverage

[⭐ Author: SARTAK; Date: 2013-08-08; Version: 0.04]

👎 Test whether your styles are actually in use or not. Unfortunately it depends on "CSS::SAC" which seems to be unusable.

CSS::Inliner

[⭐ Author: KAMELKEV; Date: 2020-01-01; Version: 4014]

Test::CSS

[Author: MANWAR; Date: 2017-09-09; Version: 0.08]

Test CSS files or strings using regular expressions and a list of properties. The properties list is somewhat out of date, for example it doesn't have the touch-action property. See https://github.com/manwar/Test-CSS/issues/2.

AUTHOR

Ben Bullock, <bkb@cpan.org>

COPYRIGHT & LICENCE

This package and associated files are copyright (C) 2021 Ben Bullock.

You can use, copy, modify and redistribute this package and associated files under the Perl Artistic Licence or the GNU General Public Licence.