/[webpac]/trunk/back2html.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/back2html.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 72 by dpavlin, Sat Jul 5 22:03:21 2003 UTC revision 782 by dpavlin, Mon Apr 6 14:19:15 2009 UTC
# Line 6  Line 6 
6    
7  sub back2html {  sub back2html {
8          my $html = shift;          my $html = shift;
9            my $url_params = shift;
10    
11            $html =~ s/</&lt;/g;
12            $html =~ s/>/&gt;/g;
13          my $out;          my $out;
14          foreach $line (split(/###/,$html)) {          foreach $line (split(/\s*###\s*/,$html)) {
15                  $out .= "<tr><td>";                  $out .= "<tr><td valign=\"top\" class=\"htmlLeft\">";
16                  my @items = split(/#-#/,$line);                  my @items = split(/\s*#-#\s*/,$line);
17                  if ($items[1] =~ m#(http://[\S]+)\s*.*?#i) {                  # convert spaces in left field to non-breaking spaces
18                          # chop URLS longer than 60 characters                  $items[0] =~ s#\s+#&nbsp;#g;
19                          my $url = substr($1,0,60);                  # try to make link on right field
20                          $url .= "..." if (length($1) > 60);                  sub mkurl($) {
21                          $items[1] =~ s#(.*)\b(http://[\S]+)(\b?.*)#$1<a href=\"$2\">$url</a>$3#g;                          my $url = shift || die "mkurl needs url as argument";
22                            # chop URLS longer than ... characters
23                            my $txturl = substr($1,0,40);
24                            my $title = '';
25                            if (length($1) > 40) {
26                                    $txturl .= "...";
27                                    $title = " title=\"$url\"";
28                            }
29                            return "<a href=\"$url\"$title>$txturl</a>";
30                  }                  }
31                    $items[1] =~ s#(http://[\S]+)#mkurl($1)#gie;
32                  $out .= join("</td><td>",@items);                  $out .= join("</td><td>",@items);
33                  $out .= "</td></tr>\n";                  $out .= "</td></tr>\n";
34          }          }
35          $out =~ s/&lt;br\/*&gt;/<br\/>/g;          # put <br> and <b> back into html
36            $out =~ s,&lt;br/*&gt;,<br/>,gi;
37            $out =~ s,&lt;b&gt;,<b>,gi;
38            $out =~ s,&lt;/b&gt;,</b>,gi;
39            # put <a href=xxx>yyyy</a> back into html
40            sub mkurl_param($$$$$) {
41                    my ($a_href,$url,$text,$a_end, $url_params) = @_;
42                    if ($url_params) {
43                            if ($url =~ m#\?#) {
44                                    $url .= "&".$url_params;
45                            } else {
46                                    $url .= "?".$url_params;
47                            }
48                    }
49                    return '<'.$a_href.'"'.$url.'">'.$text.'<'.$a_end.'>';
50            }
51            $out =~ s#&lt;(a\s+href=)['"]*(.+?)['"]*&gt;(.+?)&lt;(/a)&gt;#mkurl_param($1,$2,$3,$4,$url_params)#gsie;
52          return $out;          return $out;
53  }  }
54    

Legend:
Removed from v.72  
changed lines
  Added in v.782

  ViewVC Help
Powered by ViewVC 1.1.26