#
# reformat html inside xml back to html (basically, support for tables)
#
# filed #-# field ###
# ...

sub back2html {
	my $html = shift;

	$html =~ s/</&lt;/g;
	$html =~ s/>/&gt;/g;
	my $out;
	foreach $line (split(/\s*###\s*/,$html)) {
		$out .= "<tr><td valign=\"top\">";
		my @items = split(/\s*#-#\s*/,$line);
		# convert spaces in left field to non-breaking spaces
		$items[0] =~ s#\s+#&nbsp;#g;
		# try to make link on right field
		sub mkurl {
			my $url = shift || die "mkurl needs url as argument";
			# chop URLS longer than 60 characters
			my $txturl = substr($1,0,60);
			$txturl .= "..." if (length($1) > 60);
			return "<a href=\"$url\">$txturl</a>";
		}
		$items[1] =~ s#(http://[\S]+)#mkurl($1)#gie;
		$out .= join("</td><td>",@items);
		$out .= "</td></tr>\n";
	}
	$out =~ s/&lt;br\/*&gt;/<br\/>/g;
	return $out;
}

1;
