9 use Data::Validate::URI qw(is_uri);
12 ## get wiki formatted source text from PukiWiki Plus! page
13 # '-f' option to save file automatically
16 print "$0: [-f] url_to_pukiwikiplus_page\n";
21 if ($ARGV[0] eq '-f') {
26 die "$0: '$url' is not URI" unless is_uri($url);
28 if ($url !~ /cmd=source/ ) {
29 # set url to page of source plugin page (source.inc.php)
30 $url =~ s#\?(.+)#\?cmd=source&page=$1#;
32 $file = wikifile($1) . '.txt';
36 print STDERR "getting: '$url'\n";
38 my $source = scraper {
39 # scrape page with '<pre id="source">' tag
40 process "pre#source", "source" => "TEXT";
44 my $text = $source->scrape( URI->new($url) );
47 print STDERR "saving: '$file'\n";
48 open STDOUT, ">$file";
50 print encode('utf8', $text);
54 # get wiki text filename from pagename
55 my $pagename = shift @_;
57 $pagename =~ s/%([0-9A-Fa-f][0-9A-Fa-f])/pack('H2', $1)/eg;
58 return uc unpack("H*", $pagename);