package VJournal::Format;
use strict;
use vars qw(@EXPORT);
@EXPORT=qw(format_post format_tape format_comment);

our $imgprefix="/img";

our %sites=(
lj=>{uri=>'http://%s.livejournal.com',convertunderscore=>1,image=>'lj.gif'},
ljr=>{uri=>'http://lj.rossia.org/users/%s',convertunderscore=>0,image=>'ljr.gif'},
dw=>{uri=>'http://%s.dreamwidth.org',convertunderscore=>1,image=>'dw.gif'},
);

sub user_link {
	my ($site,$name,$title) = @_;
	$title ||=$name;
	return "" unless exists $sites{$site};
	my $s=$sites{$site};
	if ($s->{convertunderscore}) {
		$name=~tr/_/-/;
	}
	my $uri=sprintf($s->{uri},$name);
	return "<a href=\"$uri\"><img src=\"$imgprefix/".$s->{image}."\"><b>$title</b></a>";
}

sub find_user_links {
	local $_ = pop @_;
	my $expr="<(".join("|",keys %sites).')\s+user="?(\w+)"?(?:\s+title="([^\"]+)")?\s*/?>';
	s/$expr/user_link($1,$2,$3)/seg;
	return $_;
}
sub find_http_links {

}

