better documentation, allmost useful :-)
[webpac] / back2html.pm
index 7676fd8..d61922f 100644 (file)
@@ -7,13 +7,25 @@
 sub back2html {
        my $html = shift;
 
+       $html =~ s/</&lt;/g;
+       $html =~ s/>/&gt;/g;
        my $out;
-       foreach $line (split(/###/,$html)) {
-               $out .= "<tr><td>";
-               my @items = split(/#-#/,$line);
+       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
+               if ($items[1] =~ m#(http://[\S]+)\s*.*?#i) {
+                       # chop URLS longer than 60 characters
+                       my $url = substr($1,0,60);
+                       $url .= "..." if (length($1) > 60);
+                       $items[1] =~ s#(.*)\b(http://[\S]+)(\b?.*)#$1<a href=\"$2\">$url</a>$3#g;
+               }
                $out .= join("</td><td>",@items);
                $out .= "</td></tr>\n";
        }
+       $out =~ s/&lt;br\/*&gt;/<br\/>/g;
        return $out;
 }