Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Wednesday November 13, 2002
02:14 PM

Reformatting journal entries

[ #8936 ]

I updated my template for my use.perl journal reader. Most things show up in a readable form thanks to Damian Conway's black magic in Text::AutoFormat. Most other things are special cases for the wierd things people do with HTML.

This code is the entire file that Text::Template uses to form each message.

{
use HTML::Entities;
use Text::Autoformat;
 
$entry{body} =~ s=</?(p|blockquote)/?>=\n\n=gi;
$entry{body} =~ s=</?tt>==gi;
$entry{body} =~ s|</?i>|__|gi;
$entry{body} =~ s|</?b>|*|gi;
 
decode_entities( $entry{body} );
 
my $text = autoformat( $entry{body}, { right => 73, all => 1 } );
 
$text =~ s|\n{3,}|\n\n|gi;
$text =~ s=^\n+|\n+$==gi;
 
"=========================================================== ===========
$entry{nickname}: $entry{subject}
$entry{date}, $entry{id}
-------------------------------------------------------------------- --
 
$text
"
}

I still want to add link parsing so the URLs show up at the end of the message, but I am not that concerned about it at the moment.