diff options
author | Jonas Smedegaard <dr@jones.dk> | 2009-08-13 20:07:21 +0200 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2009-08-13 20:07:21 +0200 |
commit | 1d536eaeadcdfe74ec1a172d4ae17772fbc8dca4 (patch) | |
tree | b6c9248607b20e664fe1270a33f55c563222f199 /localmarkdown2sms | |
parent | c5e8ebb691777fb0ff591629c69d17ab21f9b854 (diff) |
Fix newline handling using tidymsg() subroutine.
Diffstat (limited to 'localmarkdown2sms')
-rwxr-xr-x | localmarkdown2sms | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/localmarkdown2sms b/localmarkdown2sms index 82547d3..0ca6abb 100755 --- a/localmarkdown2sms +++ b/localmarkdown2sms @@ -62,9 +62,10 @@ foreach my $file (read_dir( $path )) { my $content; # headline if ($line =~ /^(#+)\s*(.*?)\s*$/) { - # tidy latest reply (TODO: use sub) + # tidy latest reply if (defined($key) and defined($reply{$key}[$i])) { - $reply{$key}[$i] =~ s/^\s*(\w.*?)\s*$/$1/s || delete $reply{$key}[$i]; + $reply{$key}[$i] = &tidymsg($reply{$key}[$i]); + ($reply{$key}[$i]) || delete $reply{$key}[$i]; } my $level = length($1); $content = $2; @@ -121,13 +122,7 @@ foreach my $file (read_dir( $path )) { $directive_string =~ /^\s*\!(tag|taglink)\s*((\s*?\b\w+)+)/ and $file{$file}{'directive'}{'tag'} = [ split /\s+/, $2 ]; }; if ( defined( $key ) and not ($skipcontent)) { - $content = $reply{$key}[$i] . $content if (defined($reply{$key}[$i])); - $content =~ s/^\h*$//g; # clean virtually empty lines - $content =~ s/(\S)\h$/$1/g; # strip single trailing space - $content =~ s/\n\n+/\n\n/g; # strip excess newlines -# $content =~ s/(\S)\n([^\n])/$1 $2/g; # convert newline to space - $content =~ s/\h*$//g; # strip all trailing spaces - $reply{$key}[$i] = $content; + $reply{$key}[$i] .= $content; } elsif ($skipkey or $skipcontent) { # skipping - already warned about it... } else { @@ -136,12 +131,24 @@ foreach my $file (read_dir( $path )) { } } } - # tidy latest reply (TODO: use sub) + # tidy latest reply if (defined($key) and defined($reply{$key}[$i])) { - $reply{$key}[$i] =~ s/^\s*(\w.*?)\s*$/$1/s || delete $reply{$key}[$i]; + $reply{$key}[$i] = &tidymsg($reply{$key}[$i]); + ($reply{$key}[$i]) || delete $reply{$key}[$i]; } } +sub tidymsg { + my $msg = shift @_; + $msg =~ s/^\h*$//g; # clean virtually empty lines + $msg =~ s/(\S)\h$/$1/g; # strip single trailing space + $msg =~ s/\n\n+/\n\n/g; # strip excess newlines + $msg =~ s/(\S)\n([^\n])/$1 $2/g; # convert newline to space + $msg =~ s/\h*$//g; # strip all trailing spaces + $msg =~ s/^\s*(\w*?.*?)\s*$/$1/s; # strip surrounding space + return $msg; +} + sub sendmsg { my ($phone, $desc, $msg) = @_; |