]> Sergey Matveev's repositories - zk.git/commitdiff
Various miscellaneous fixes
authorSergey Matveev <stargrave@stargrave.org>
Thu, 8 May 2025 11:22:27 +0000 (14:22 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Thu, 8 May 2025 14:56:01 +0000 (17:56 +0300)
zk

diff --git a/zk b/zk
index e4006617a7e46485e0ef956efa152d686233d1ba..8a4c90adf18a06d1f1b307ace17edcc2a8118d36 100755 (executable)
--- a/zk
+++ b/zk
@@ -96,6 +96,8 @@ to other pages. It also will include all backlinks in them. Each
 directory will also contain index page with links to all
 existing pages in current directory and to subdirectories.
 
+=head1 HISTORY
+
 Older version of that script, written on Z shell, can be found in Git history.
 
 =cut
@@ -209,9 +211,12 @@ sub genHTML {
         my $rel;
         foreach (@lnks) {
             $rel = File::Spec->abs2rel($_, $page);
-            $rel = substr $rel, 3;
-            if (-d $rel) {
-                $rel .= "/index";
+            $rel = (length $rel > 2) ? (substr $rel, 3) : "";
+            if (-d $_) {
+                if ($rel ne "") {
+                    $rel .= "/";
+                }
+                $rel .= "index";
             }
             push @rels, $rel;
         }
@@ -219,8 +224,7 @@ sub genHTML {
     startHead $out, $page;
     {
         my $fn = basename $page;
-        print $out "<link rel=\"alternate\" type=\"text/plain\" title=\"plain\"
-    href=\"$fn.txt\" />\n";
+        print $out "<link rel=\"alternate\" type=\"text/plain\" title=\"src\" href=\"$fn.txt\" />\n";
     }
     print $out "</head><body><pre>";
     open(my $fh, "<", $page) or die "$!";
@@ -228,14 +232,18 @@ sub genHTML {
         chop;
         if (/\r$/) {
             chop;
+            s/^(\s*)//g;
+            my $head = $1;
             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>";
+                $t =~ s/"/\&guot;/g;
+                $_ = "${head}=&gt; <a href=\"$cols[1]\">$t</a>";
             } elsif ($cols[0] eq "I") {
                 if ($#cols > 1) {
                     my $t = htmlescape join " ", @cols[2..$#cols];
+                    $t =~ s/"/\&guot;/g;
                     $_ = "<img src=\"$cols[1]\" alt=\"$t\" />";
                 } else {
                     $_ = "<img src=\"$cols[1]\" />";
@@ -247,7 +255,7 @@ sub genHTML {
             $_ = htmlescape $_;
             if (/\[.+\]/) {
                 while (my ($i, $l) = each @lnks) {
-                    s/\[$l\]/<a href="$rels[$i].html">[$l]<\/a>/g;
+                    s/\[\Q$l\E\]/<a href="$rels[$i].html">[$l]<\/a>/g;
                 }
             }
         }