[pmwiki-users] Command line pretty-print PmWiki pages
Oliver Betz
list_ob at gmx.net
Fri Jul 31 05:22:02 CDT 2009
Eemeli Aro wrote:
(pretty-printing PmWiki pages)
thanks for your sed solution!
>above works for me. Anyone else have command line scripts that they
>use with PmWiki?
Based on your code, I made a Perl based filter doing the same as pmp
to use it in Windows environment because I thought Perl is more likely
installed on Windows machines than a unixoid shell and sed.
When I was ready, I found that there is a tiny native sed for windows
available from http://sourceforge.net/projects/unxutils/ and a bloated
but more recent version at http://sourceforge.net/projects/gnuwin32/.
To use it in a windows environment, it's IMO suitable to save your
script to a file and call sed -f pmp.sed Group.Name
Well, here is the Perl code, anyway:
- snip -
my $text;
if($ARGV[0] eq ''){
print STDERR "Script to pretty-print PmWiki page files\n";
print STDERR "Usage: $0 infile [outfile]\n";
exit;
}
if((-f($ARGV[0])) == 0){
print STDERR "couldn\'t open $ARGV[0]\n";
exit;
}
if($ARGV[1] ne ''){
open(OUTFILE, ">$ARGV[1]") or die "couldn\'t open $ARGV[1]";
}
else{
open(OUTFILE, ">-") or die "couldn\'t write to STDOUT";
};
open( FILE, $ARGV[0] ) or die "Can't open $ARGV[0]";
while(<FILE>) {
next if/^[^=]+:.*/; # skip history lines (no '=' before ':')
chomp;
if( /^text=(.*)/ ) {
$text = $1; # remember page text
}
else{
/^([^=]+)=(.*)/;
printf OUTFILE "%10s | %s\n", $1, $2;
}
} # while
close( FILE );
$text =~ s/%0a/\n/g;
$text =~ s/%3c/</g;
$text =~ s/%25/%/g;
print OUTFILE "$text\n";
close OUTFILE;
exit;
__END__
- snip -
With such a filter one can compare two page text files in a neat side
by side view using a "visual" diff tool *).
That's extremly useful for maintenance - consider checking local
modifications of PmWiki supplied pages when updating PmWiki. Or to
merge pages between wikis.
Works also very good by accessing the page files via sftp.
Oliver
*) Beyond Compare, EC Merge, UltraCompare Araxis Merge, KDiff3, Meld,
WinMerge und CSDiff...
More information about the pmwiki-users
mailing list