


=encoding UTF-8

=head1 NAME

CSS::Tidy - reformat CSS

=head1 SYNOPSIS

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

=head1 VERSION

This documents version 0.04 of CSS-Tidy
corresponding to L<git commit d237baf76e9f413725f83c33b825d7ed347e86d4|https://github.com/benkasminbullock/css-tidy/commit/d237baf76e9f413725f83c33b825d7ed347e86d4> released on Sat Jul 30 19:54:16 2022 +0900.

=head1 DESCRIPTION

This reformats CSS.

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

=head1 FUNCTIONS

=head2 copy_css

    copy_css (in => $infile, out => $outfile);

Copy CSS from a file specified by L</in> to a file specified by
L</out>.

=over

=item in

Input file. The file is read in via the function C<read_text> in
L</File::Slurper> so it must be in the UTF-8 encoding.

=item out

Output file. The file is written using C<write_text> from
L</File::Slurper> so it must be in the UTF-8 encoding.

=item decomment

Remove comments from the output file.

=back

=head2 tidy_css

    my $output = tidy_css ($input, %options);

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

Options are as follows:

=over

=item decomment

Set to a true value to remove comments from the output

=back

=head1 TRANSFORMATIONS APPLIED

=over

=item Indentation

Indentation is changed to multiples of four spaces.

=item Trailing whitespace

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

=item 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;

=item Declaration blocks

A blank line is inserted between declaration blocks.

=item Single-line braces are expanded out

    .something { something:something; }

is expanded to

    .something {
        something: something;
    }

=item 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.

=back

=head1 SCRIPT

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

=head1 DEPENDENCIES

=over 

=item L<C::Tokenize>

This is used for comment regex.

=item L<File::Slurper>

This is used to read and write files

=back

=head1 SEE ALSO

 



=head2 About CSS

=over

=item CSS Specification

L<CSS Syntax Module Level 3|https://www.w3.org/TR/css-syntax-3/> at
the W3 Consortium.

=back

=head2 Other CPAN modules

=head3 Parsers

=over


=item L<CSS>


[Author: L<IAMCAL|https://metacpan.org/author/IAMCAL>; Date: C<2011-03-22>; Version: C<1.09>]




=item L<CSS::Croco>


[Author: L<GUGU|https://metacpan.org/author/GUGU>; Date: C<2009-12-26>; Version: C<0.09>]




=item L<CSS::DOM>


[⭐ Author: L<SPROUT|https://metacpan.org/author/SPROUT>; Date: C<2018-01-29>; Version: C<0.17>]




=item L<CSS::Object>


[⭐ Author: L<JDEGUEST|https://metacpan.org/author/JDEGUEST>; Date: C<2020-08-12>; Version: C<v0.1.3>]




=item L<CSS::SAC>


[Author: L<BJOERN|https://metacpan.org/author/BJOERN>; Date: C<2008-07-05>; Version: C<0.08>]



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


=item L<CSS::Simple>


[Author: L<KAMELKEV|https://metacpan.org/author/KAMELKEV>; Date: C<2017-11-16>; Version: C<3224>]




=item L<CSS::Struct>


[Author: L<SKIM|https://metacpan.org/author/SKIM>; Date: C<2021-01-28>; Version: C<0.04>]




=item L<CSS::Tiny>


[⭐ Author: L<CHORNY|https://metacpan.org/author/CHORNY>; Date: C<2016-03-10>; Version: C<1.20>]



Claims to reduce memory usage compared to the L<CSS> module.

=back

=head3 Preprocessors

=over


=item L<Crayon>


[⭐ Author: L<LNATION|https://metacpan.org/author/LNATION>; Date: C<2021-04-15>; Version: C<0.07>]



"dedupe, minify and extend CSS". We haven't tried it, but from the
documentation it seems to be a CSS preprocessor.


=item L<CSS::LESS>


[Author: L<MUGIFLY|https://metacpan.org/author/MUGIFLY>; Date: C<2013-09-20>; Version: C<v0.0.3>]




=item L<CSS::Prepare>


[Author: L<MNF|https://metacpan.org/author/MNF>; Date: C<2011-06-20>; Version: C<v0.9.2.4>]




=item L<CSS::Sass>


[⭐ Author: L<OCBNET|https://metacpan.org/author/OCBNET>; Date: C<2020-05-04>; Version: C<v3.6.3>]



Unfortunately this is built on top of a deprecated library which is
being replaced with Dart Sass.


=item L<CSS::Scopifier>


[⭐ Author: L<VANSTYN|https://metacpan.org/author/VANSTYN>; Date: C<2015-08-27>; Version: C<0.04>]



=back

=head3 Minifiers

=over


=item L<CSS::Compressor>


[⭐ Author: L<JANUS|https://metacpan.org/author/JANUS>; Date: C<2018-12-03>; Version: C<0.05>]




=item L<CSS::Minifier>


[⭐ Author: L<PMICHAUX|https://metacpan.org/author/PMICHAUX>; Date: C<2007-08-03>; Version: C<0.01>]




=item L<CSS::Minifier::XS>


[⭐ Author: L<GTERMARS|https://metacpan.org/author/GTERMARS>; Date: C<2021-02-07>; Version: C<0.13>]




=item L<CSS::Packer>


[⭐ Author: L<LEEJO|https://metacpan.org/author/LEEJO>; Date: C<2021-03-02>; Version: C<2.08>]




=item L<CSS::Squish>


[Author: L<TSIBLEY|https://metacpan.org/author/TSIBLEY>; Date: C<2010-11-05>; Version: C<0.10>]



=back

=head3 Other

=over


=item L<CSS::Coverage>


[⭐ Author: L<SARTAK|https://metacpan.org/author/SARTAK>; Date: C<2013-08-08>; Version: C<0.04>]



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


=item L<CSS::Inliner>


[⭐ Author: L<KAMELKEV|https://metacpan.org/author/KAMELKEV>; Date: C<2020-01-01>; Version: C<4014>]




=item L<CSS::Selector::Parser>


[Author: L<HDP|https://metacpan.org/author/HDP>; Date: C<2011-11-06>; Version: C<0.003>]




=item L<CSS::Selector::Grammar>


[Author: L<DFH|https://metacpan.org/author/DFH>; Date: C<2014-07-04>; Version: C<0.002>]




=item L<Graphics::ColorNames::CSS>


[⭐ Author: L<CFAERBER|https://metacpan.org/author/CFAERBER>; Date: C<2019-05-01>; Version: C<1.14>]



This provides a map from the names of colours valid in CSS to their
RGB values.


=item L<Test::CSS>


[Author: L<MANWAR|https://metacpan.org/author/MANWAR>; Date: C<2017-09-09>; Version: C<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 C<touch-action> property. See
L<https://github.com/manwar/Test-CSS/issues/2>.

=back



=head1 AUTHOR

Ben Bullock, <bkb@cpan.org>

=head1 COPYRIGHT & LICENCE

This package and associated files are copyright (C) 
2021-2022
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.



