summaryrefslogtreecommitdiff
path: root/localsvgtidy
blob: 507994f474b3376b6d872fcc132c9f3ef626125c (plain)
  1. #!/usr/bin/perl
  2. # Copyright © 2014 Jonas Smedegaard <dr@jones.dk>
  3. # Description: optimize internal structure of SVG files
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 3, or (at your option)
  8. # any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful, but
  11. # WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. # General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. #
  18. # Depends: libxml-twig-perl
  19. #
  20. # TODO: Apply (the equivalent of) python-scour
  21. use warnings;
  22. use strict;
  23. use XML::Twig;
  24. my $twig = XML::Twig->new(
  25. keep_encoding => 1,
  26. keep_atts_order => 1,
  27. pretty_print => 'indented',
  28. twig_handlers => {
  29. _all_ => sub { $_[0]->flush; },
  30. }
  31. );
  32. $twig->set_indent("\t");
  33. if ( my $file= $ARGV[0] ) {
  34. $twig->parsefile( $file);
  35. } else {
  36. $twig->parse( \*STDIN);
  37. }
  38. $twig->flush;
  39. 1;