Well, I worked for a bit tonight and I finally came up with a (admitantly
pathetic) basic RTF to HTML converter.
It's not that great, I don't claim it's efficient, just that it works.
Currently, it supports new lines, bold, italics and underline.
I'm working on converting < and > correctly, as well as a HTML 2 RTF sub (or
is there already one?)
sub rtf2html{
my $re = $main->reDesc; #Just set this to the RichEdit object
my $i = 0;
my $b = 0;
my $u = 0;
my $text = '';
my $oldtext = $re->Text();
foreach my $x (0..(length($oldtext)+1)){
$re->Select($x,$x+1);
my %att = $re->GetCharFormat();
#Note: The odd if statements are to avoid
# annoying warning messages
if(($i && !exists($att{-italic})) || (!$i && exists($att{-italic}))){
$i = $att{-italic};
$text .= ($i ? '<I>' : '</I>');
}
if(($b && !exists($att{-bold})) || (!$b && exists($att{-bold}))){
$b = $att{-bold};
$text .= ($b ? '<B>' : '</B>');
}
if(($u && !exists($att{-underline})) || (!$u &&
exists($att{-underline}))){
$u = $att{-underline};
$text .= ($u ? '<U>' : '</U>');
}
$text .= substr($oldtext,$x,1);
}
$text =~ s/\r//g;
$text =~ s/\n/<BR>/gio;
return $text;
}
Comments, questions, suggestions? I know the output leaves something to be
desired, but most browsers can translate it well enough... Feel free to
take this and run with it, I just ask that ya post any improvements :)
_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com