X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?p=xscreensaver;a=blobdiff_plain;f=driver%2Fxscreensaver-text;fp=driver%2Fxscreensaver-text;h=e4c588c50cf41cd929f032ea11b34343c8cdae83;hp=f7d2a992d1858f7f1fa6f69beb18a8dd6f6dbf78;hb=ff35d056d723c9a5ffe728dbba5f1c25e141be04;hpb=b81f521c5ad7022ac12db18ca8fcdd9fb063831e diff --git a/driver/xscreensaver-text b/driver/xscreensaver-text index f7d2a992..e4c588c5 100755 --- a/driver/xscreensaver-text +++ b/driver/xscreensaver-text @@ -1,5 +1,5 @@ #!/usr/bin/perl -w -# Copyright © 2005-2012 Jamie Zawinski +# Copyright © 2005-2013 Jamie Zawinski # # Permission to use, copy, modify, distribute, and sell this software and its # documentation for any purpose is hereby granted without fee, provided that @@ -34,7 +34,7 @@ use Text::Wrap qw(wrap); use bytes; my $progname = $0; $progname =~ s@.*/@@g; -my $version = q{ $Revision: 1.27 $ }; $version =~ s/^[^0-9]+([0-9.]+).*$/$1/; +my $version = q{ $Revision: 1.29 $ }; $version =~ s/^[^0-9]+([0-9.]+).*$/$1/; my $verbose = 0; my $http_proxy = undef; @@ -495,6 +495,19 @@ sub reformat_html($$) { s@<[^<>]*>?@@gs; # lose all other HTML tags $_ = de_entify ($_); # convert HTML entities + # For Wikipedia: delete anything inside {{ }} and unwrap [[tags]] + # + if ($rss_p eq 'wiki') { + s@/\*.*?\*/@@si; # /* ... */ + 1 while (s/{{[^{}]*}}//gs); # {{ ... }} + s/\[\[([^:\[\]\|]+)\|([^\[\]]+)\]\]/$2/gs; # [[link|anchor]] + s/\[\[([^:\[\]\|]+)\]\]/$1/gs; # [[anchor]] + s/\[http:[^\[\]\s]+\s+([^\[\]]+)\]/$1/gs; # [url anchor] +# s@\s*.*?@*@gs; # url -> "*" + s/<[^<>]*>//gs; # -- omit. + } + + # elide any remaining non-Latin1 binary data... s/([\177-\377]+(\s*[\177-\377]+)[^a-z\d]*)/«...» /g; #s/([\177-\377]+(\s*[\177-\377]+)[^a-z\d]*)/«$1» /g; @@ -506,6 +519,7 @@ sub reformat_html($$) { if (!defined($wrap_columns) || $wrap_columns > 0) { $Text::Wrap::columns = ($wrap_columns || 72); + $Text::Wrap::break = '[\s/]'; # wrap on slashes for URLs $_ = wrap ("", " ", $_); # wrap the lines as a paragraph s/[ \t]+$//gm; # lose whitespace at end of line again } @@ -520,6 +534,8 @@ sub reformat_html($$) { sub reformat_rss($) { my ($body) = @_; + my $wiki_p = ($body =~ m@[^<>]*Wiki@si); + $body =~ s/(<(ITEM|ENTRY)\b)/\001\001$1/gsi; my @items = split (/\001\001/, $body); @@ -578,7 +594,7 @@ sub reformat_rss($) { $title = '' if ($body1 eq $title); # Identical in Twitter's atom feed. - reformat_html ("$title

$body1", 1); + reformat_html ("$title

$body1", $wiki_p ? 'wiki' : 'rss'); print "\n"; } } @@ -608,6 +624,7 @@ sub reformat_text($) { if ($wrap_columns && $wrap_columns > 0) { print STDERR "$progname: wrapping at $wrap_columns...\n" if ($verbose > 2); $Text::Wrap::columns = $wrap_columns; + $Text::Wrap::break = '[\s/]'; # wrap on slashes for URLs $body = wrap ("", "", $body); $body =~ s/[ \t]+$//gm; }