=item *
-C<[img|src|alt]> can be used to create link to images in HTML output.
+C<E<gt> URL[ optional text]E<lt>CRE<gt>> on a separate line will add a
+link to the specified URL (with optional text). Pay attention that line
+contains carriage-return character at the end.
=item *
-C<[raw|url|text]> can be used to create arbitrary link in HTML output.
+C<I URL[ alt]E<lt>CRE<gt>> on a separate line will add an image with
+optional alternative text similarly as link is specified.
=back
</head><body>";
}
-
-my %schemes = (
- "finger" => 1,
- "ftp" => 1,
- "gemini" => 1,
- "gopher" => 1,
- "http" => 1,
- "https" => 1,
- "irc" => 1,
- "ircs" => 1,
- "news" => 1,
- "telnet" => 1,
-);
+sub htmlescape {
+ $_ = shift;
+ s/&/\&/g;
+ s/</\</g;
+ s/>/\>/g;
+ return $_;
+}
use File::Spec;
print $out "<pre>\n";
open(my $fh, "<", $page) or die "$!";
while (<$fh>) {
- my @ws;
chop;
- /( *)$/;
- my $tail = $1;
- foreach my $w (split / /) {
- my ($scheme, $authority, $path, $query, $fragment) = $w =~
- m|(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?|;
- if (defined $scheme and exists $schemes{$scheme}) {
- my $e = $w;
- $e =~ s/&/\&/g;
- $w = "<a href=\"$w\">$e</a>";
- } else {
- if ($w =~ /^\[img\|(.*)\|(.+)\]$/) {
- $w = "<img src=\"$1\" alt=\"$2\" />";
- } elsif ($w =~ /^\[raw\|(.*)\|(.+)\]$/) {
- $w = "<a href=\"$1\">$2</a>";
- } elsif ($w =~ /\[.+\]/) {
- $w =~ s/&/\&/g;
- $w =~ s/</\</g;
- $w =~ s/>/\>/g;
- while (my ($i, $l) = each @lnks) {
- $w =~ s/\[$l\]/<a href="$rels[$i].html">[$l]<\/a>/g;
- }
+ if (/\r$/) {
+ chop;
+ my @cols = split /\s+/;
+ if ($cols[0] eq ">") {
+ my $t = ($#cols > 1) ? (join " ", @cols[2..$#cols]) : $cols[1];
+ $t = htmlescape $t;
+ $_ = "<a href=\"$cols[1]\">$t</a>";
+ } elsif ($cols[0] eq "I") {
+ if ($#cols > 1) {
+ my $t = htmlescape join " ", @cols[2..$#cols];
+ $_ = "<img src=\"$cols[1]\" alt=\"$t\" />";
} else {
- $w =~ s/&/\&/g;
- $w =~ s/</\</g;
- $w =~ s/>/\>/g;
+ $_ = "<img src=\"$cols[1]\" />";
+ }
+ } else {
+ print STDERR "unknown $cols[0]\n";
+ }
+ } else {
+ $_ = htmlescape $_;
+ if (/\[.+\]/) {
+ while (my ($i, $l) = each @lnks) {
+ s/\[$l\]/<a href="$rels[$i].html">[$l]<\/a>/g;
}
}
- push @ws, $w;
}
- my $w = join " ", @ws;
- print $out "${w}${tail}\n";
+ print $out "$_\n";
}
close $fh;
print $out "</pre>\n";