1
0
mirror of https://github.com/tateisu/SubwayTooter synced 2024-12-31 19:27:21 +01:00

update full_description.pl, just add comments.

This commit is contained in:
tateisu 2022-12-04 10:29:55 +09:00
parent 81f762541b
commit 15a037150e

View File

@ -4,21 +4,23 @@ use warnings;
use utf8; use utf8;
use feature qw(say); use feature qw(say);
my $file = $0; # read from __DATA__ section in this file.
$file =~ s/\.pl$/\.txt/;
local $/ = undef; local $/ = undef;
my $text = <DATA>; my $text = <DATA>;
# change multiple spaces and line feeds to single space ############################################
# it required for F-droid android client. # change spaces and line feeds to single space,
$text =~ s/[\x00-\x20]+/ /g; # it's required for F-droid android client.
# also remove head/tail spaces in whole text.
# remove head/tail space $text =~ s/[\x00-\x20]+/ /g;
$text =~ s/\A //; $text =~ s/\A //;
$text =~ s/ \z//; $text =~ s/ \z//;
# HTML block elements and "br". ############################################
# trim spaces before/after open/close block tags. also <br>,<br/>,</br>
# HTML block elements and "br". joined with '|'
my $blockElements = join "|", qw( my $blockElements = join "|", qw(
address article aside blockquote canvas dd div dl dt address article aside blockquote canvas dd div dl dt
fieldset figcaption figure footer form fieldset figcaption figure footer form
@ -27,19 +29,23 @@ my $blockElements = join "|", qw(
br br
); );
# block tag it may have attributes, and spaces before/after tag. # RegEx for block tag that may have attributes, and spaces before/after tag.
my $trimElementsRe = qr!\s*(</?(?:$blockElements)\b(?:[^>/"]+|"[^"]*")*/?>)\s*!i; my $trimElementRe = qr!\s*(</?(?:$blockElements)\b(?:[^>/"]+|"[^"]*")*/?>)\s*!i;
## verbose debugging. ## verbose debugging.
#say $trimElementsRe; #say $trimElementsRe;
#while( $text =~ /$trimElementsRe/g){ #while( $text =~ /$trimElementRe/g){
# next if $& eq $1; # next if $& eq $1;
# say "[$&] => [$1]"; # say "[$&] => [$1]";
#} #}
# trim spaces before/after block tags. also <br>,<br/>,</br> $text =~ s/$trimElementRe/$1/g;
$text =~ s/$trimElementsRe/$1/g;
############################################
# write to .txt file. $0 means path of the this script file.
my $file = $0;
$file =~ s/\.pl$/\.txt/ or die "can't make output filename. $0";
open(my $fh,">:utf8",$file) or die "$file $!"; open(my $fh,">:utf8",$file) or die "$file $!";
say $fh $text; say $fh $text;
close($fh) or die "$file $!"; close($fh) or die "$file $!";