/[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

Annotation of /trunk/back2html.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 782 - (hide annotations)
Mon Apr 6 14:19:15 2009 UTC (10 years, 8 months ago) by dpavlin
File size: 1460 byte(s)
merge fix from trunk to all branches

1 dpavlin 13 #
2     # reformat html inside xml back to html (basically, support for tables)
3     #
4     # filed #-# field ###
5     # ...
6    
7     sub back2html {
8     my $html = shift;
9 dpavlin 636 my $url_params = shift;
10 dpavlin 13
11 dpavlin 80 $html =~ s/</&lt;/g;
12     $html =~ s/>/&gt;/g;
13 dpavlin 13 my $out;
14 dpavlin 79 foreach $line (split(/\s*###\s*/,$html)) {
15 dpavlin 782 $out .= "<tr><td valign=\"top\" class=\"htmlLeft\">";
16 dpavlin 79 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 dpavlin 636 sub mkurl($) {
21 dpavlin 146 my $url = shift || die "mkurl needs url as argument";
22 dpavlin 782 # 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 dpavlin 66 }
31 dpavlin 146 $items[1] =~ s#(http://[\S]+)#mkurl($1)#gie;
32 dpavlin 13 $out .= join("</td><td>",@items);
33     $out .= "</td></tr>\n";
34     }
35 dpavlin 782 # put <br> and <b> back into html
36 dpavlin 151 $out =~ s,&lt;br/*&gt;,<br/>,gi;
37 dpavlin 782 $out =~ s,&lt;b&gt;,<b>,gi;
38     $out =~ s,&lt;/b&gt;,</b>,gi;
39 dpavlin 151 # put <a href=xxx>yyyy</a> back into html
40 dpavlin 782 sub mkurl_param($$$$$) {
41     my ($a_href,$url,$text,$a_end, $url_params) = @_;
42 dpavlin 638 if ($url_params) {
43     if ($url =~ m#\?#) {
44     $url .= "&".$url_params;
45     } else {
46     $url .= "?".$url_params;
47     }
48 dpavlin 636 }
49     return '<'.$a_href.'"'.$url.'">'.$text.'<'.$a_end.'>';
50     }
51 dpavlin 782 $out =~ s#&lt;(a\s+href=)['"]*(.+?)['"]*&gt;(.+?)&lt;(/a)&gt;#mkurl_param($1,$2,$3,$4,$url_params)#gsie;
52 dpavlin 13 return $out;
53     }
54    
55     1;

Properties

Name Value
cvs2svn:cvs-rev 1.11

  ViewVC Help
Powered by ViewVC 1.1.26