From: Sergey Matveev Date: Wed, 7 May 2025 18:45:59 +0000 (+0300) Subject: Much more simple URL/img format X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=042800fe83c369fd995b14ad53e6553d93181dd1;p=zk.git Much more simple URL/img format --- diff --git a/zk b/zk index 20a1fb3..4a7f63c 100755 --- a/zk +++ b/zk @@ -65,11 +65,14 @@ quickly open results in the editor. =item * -C<[img|src|alt]> can be used to create link to images in HTML output. +C URL[ optional text]ECRE> 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. +CCRE> on a separate line will add an image with +optional alternative text similarly as link is specified. =back @@ -186,19 +189,13 @@ sub startBody { "; } - -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; + return $_; +} use File::Spec; @@ -222,39 +219,33 @@ sub genHTML { print $out "
\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 = "$e";
-            } else {
-                if ($w =~ /^\[img\|(.*)\|(.+)\]$/) {
-                    $w = "\"$2\"";
-                } elsif ($w =~ /^\[raw\|(.*)\|(.+)\]$/) {
-                    $w = "$2";
-                } elsif ($w =~ /\[.+\]/) {
-                    $w =~ s/&/\&/g;
-                    $w =~ s//\>/g;
-                    while (my ($i, $l) = each @lnks) {
-                        $w =~ s/\[$l\]/[$l]<\/a>/g;
-                    }
+        if (/
$/) {
+            chop;
+            my @cols = split /\s+/;
+            if ($cols[0] eq ">") {
+                my $t = ($#cols > 1) ? (join " ", @cols[2..$#cols]) : $cols[1];
+                $t = htmlescape $t;
+                $_ = "$t";
+            } elsif ($cols[0] eq "I") {
+                if ($#cols > 1) {
+                    my $t = htmlescape join " ", @cols[2..$#cols];
+                    $_ = "\"$t\"";
                 } else {
-                    $w =~ s/&/\&/g;
-                    $w =~ s//\>/g;
+                    $_ = "";
+                }
+            } else {
+                print STDERR "unknown $cols[0]\n";
+            }
+        } else {
+            $_ = htmlescape $_;
+            if (/\[.+\]/) {
+                while (my ($i, $l) = each @lnks) {
+                    s/\[$l\]/[$l]<\/a>/g;
                 }
             }
-            push @ws, $w;
         }
-        my $w = join " ", @ws;
-        print $out "${w}${tail}\n";
+        print $out "$_\n";
     }
     close $fh;
     print $out "
\n";