/[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 31 by dpavlin, Sun Feb 23 07:11:18 2003 UTC revision 638 by dpavlin, Wed Jan 19 22:29:54 2005 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\">";
16                  my @items = split(/#-#/,$line);                  my @items = split(/\s*#-#\s*/,$line);
17                    # convert spaces in left field to non-breaking spaces
18                    $items[0] =~ s#\s+#&nbsp;#g;
19                    # try to make link on right field
20                    sub mkurl($) {
21                            my $url = shift || die "mkurl needs url as argument";
22                            # chop URLS longer than 60 characters
23                            my $txturl = substr($1,0,60);
24                            $txturl .= "..." if (length($1) > 60);
25                            return "<a href=\"$url\">$txturl</a>";
26                    }
27                    $items[1] =~ s#(http://[\S]+)#mkurl($1)#gie;
28                  $out .= join("</td><td>",@items);                  $out .= join("</td><td>",@items);
29                  $out .= "</td></tr>\n";                  $out .= "</td></tr>\n";
30          }          }
31          $out =~ s/&lt;br\/*&gt;/<br\/>/g;          # put <br> back into html
32            $out =~ s,&lt;br/*&gt;,<br/>,gi;
33            # put <a href=xxx>yyyy</a> back into html
34            sub mkurl_param($$$$) {
35                    my ($a_href,$url,$text,$a_end) = @_;
36                    if ($url_params) {
37                            if ($url =~ m#\?#) {
38                                    $url .= "&".$url_params;
39                            } else {
40                                    $url .= "?".$url_params;
41                            }
42                    }
43                    return '<'.$a_href.'"'.$url.'">'.$text.'<'.$a_end.'>';
44            }
45            $out =~ s#&lt;(a\s+href=)['"]*(.+?)['"]*&gt;(.+?)&lt;(/a)&gt;#mkurl_param($1,$2,$3,$4)#gsie;
46          return $out;          return $out;
47  }  }
48    

Legend:
Removed from v.31  
changed lines
  Added in v.638

  ViewVC Help
Powered by ViewVC 1.1.26