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

Contents of /trunk/back2html.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 151 - (show annotations)
Sun Nov 16 22:39:36 2003 UTC (20 years, 4 months ago) by dpavlin
File size: 979 byte(s)
keep <a href>

1 #
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
10 $html =~ s/</&lt;/g;
11 $html =~ s/>/&gt;/g;
12 my $out;
13 foreach $line (split(/\s*###\s*/,$html)) {
14 $out .= "<tr><td valign=\"top\">";
15 my @items = split(/\s*#-#\s*/,$line);
16 # convert spaces in left field to non-breaking spaces
17 $items[0] =~ s#\s+#&nbsp;#g;
18 # try to make link on right field
19 sub mkurl {
20 my $url = shift || die "mkurl needs url as argument";
21 # chop URLS longer than 60 characters
22 my $txturl = substr($1,0,60);
23 $txturl .= "..." if (length($1) > 60);
24 return "<a href=\"$url\">$txturl</a>";
25 }
26 $items[1] =~ s#(http://[\S]+)#mkurl($1)#gie;
27 $out .= join("</td><td>",@items);
28 $out .= "</td></tr>\n";
29 }
30 # put <br> back into html
31 $out =~ s,&lt;br/*&gt;,<br/>,gi;
32 # put <a href=xxx>yyyy</a> back into html
33 $out =~ s,&lt;(a\s+href=)(.+?)&gt;(.+?)&lt;(/a)&gt;,<$1$2>$3<$4>,gsi;
34 return $out;
35 }
36
37 1;

Properties

Name Value
cvs2svn:cvs-rev 1.11

  ViewVC Help
Powered by ViewVC 1.1.26