]> git.sesse.net Git - remoteglot/blob - clean-svg.pl
Handle streaming PGNs, like from Lichess (although this might break non-streaming...
[remoteglot] / clean-svg.pl
1 #! /usr/bin/perl
2 use strict;
3 use warnings;
4 use MIME::Base64;
5
6 undef $/;
7 my $x = <>;
8 $x = MIME::Base64::decode_base64($x);
9 $x =~ s/>\s*</></sg;  # Remove whitespace between tags.
10 $x =~ s/\s+/ /sg;  # Compress whitespace.
11 $x =~ s# />#/>#g;  # <foo /> -> <foo/>.
12 $x =~ s/;\s+/;/sg; # Remove whitespace in CSS.
13 $x =~ s/;"/"/g;   # Remove final semicolon in CSS.
14 $x =~ s/\s+$//;  # Remove tailing whitespace.
15 $x =~ s/><!DOCTYPE/>\n<!DOCTYPE/;  # Add back newline after XML header.
16 $x =~ s/<svg/\n<svg/;   # Add back newline after DOCTYPE.
17
18 print $x, "\n";
19 print MIME::Base64::encode_base64($x, ""), "\n";
20
21 my $z = $x;
22 $z =~ s/%/%25/g;
23 $z =~ s/\n/%0A/g;
24 $z =~ s/"/%22/g;
25 $z =~ s/#/%23/g;
26 print $z, "\n";