]> Sergey Matveev's repositories - zk.git/commitdiff
Ability to indent includes
authorSergey Matveev <stargrave@stargrave.org>
Sat, 10 May 2025 16:23:38 +0000 (19:23 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sat, 10 May 2025 16:27:37 +0000 (19:27 +0300)
FORMAT
zk

diff --git a/FORMAT b/FORMAT
index f0b5fa88a7709626e149b3bbb10d6ddf2a9b873e..e789d9f25ee4d6caa6bd2a0fab94010c569175a2 100644 (file)
--- a/FORMAT
+++ b/FORMAT
@@ -10,12 +10,12 @@ role only (currently) during HTML generation.
   Creates <a href="URL">{optional text|URL}</a> link in HTML.
 * img URL[ optional text]
   Creates <img src="URL" [alt="optional text"] /> in HTML.
-* raw ...
-  Just inserts ... line to HTML output as-is.
-* # ...
+* |...
+  Just inserts raw ... line to HTML output as-is.
+* #...
   Does nothing, commented line.
 * do-backs
   Forcefully creates a table with all backlinks to the page.
-* include [page]
-  Include contents of the specified page. Brackets here are
-  for making a link to page.
+* <<[indent][page]
+  Include contents of the specified page. Brackets around
+  [page] are for making a link to page. indent is optional.
diff --git a/zk b/zk
index 7acfab864a9f73fc630f8751e4852c810b5e7723..3edd2aa9bb03d5e4b5ba9bd7994fc5fb01103ee1 100755 (executable)
--- a/zk
+++ b/zk
@@ -104,7 +104,7 @@ for my $pth (keys %Mtimes) {
     my $lines = 0;
     my sub procline;
     sub procline {
-        if (/^include \[(.*)\]\r$/) {
+        if (/^<<.*\[(.*)\]\r$/) {
             $found{$1} = 1;
             open(my $fh, "<:encoding(UTF-8)", $1) or die "$!";
             while (<$fh>) { $lines++; procline $_ }
@@ -229,39 +229,43 @@ sub genHTML {
         }
         print $out "\n</head>\n<body>\n<pre>";
     }
+    my $indent = "";
     my sub procline;
     sub procline {
         $_ = $_[0];
         chop;
         if (/\r$/) {
             chop;
-            s/^(\s*)//g;
+            /^(\s*)(.*)$/;
             my $head = $1;
-            my @cols = split /\s+/;
+            my @cols = split /\s+/, $2;
             if ($cols[0] eq "=>") {
                 my $t = ($#cols > 1) ? (join " ", @cols[2..$#cols]) : $cols[1];
                 $t = htmlescape $t;
                 $t =~ s/"/\&guot;/g;
-                $_ = "${head}=&gt; <a href=\"$cols[1]\">$t</a>";
+                $_ = "$head=&gt; <a href=\"$cols[1]\">$t</a>";
             } elsif ($cols[0] eq "img") {
                 if ($#cols > 1) {
                     my $t = htmlescape join " ", @cols[2..$#cols];
                     $t =~ s/"/\&guot;/g;
-                    $_ = "<img src=\"$cols[1]\" alt=\"$t\" />";
+                    $_ = "$head<img src=\"$cols[1]\" alt=\"$t\" />";
                 } else {
-                    $_ = "<img src=\"$cols[1]\" />";
+                    $_ = "$head<img src=\"$cols[1]\" />";
                 }
             } elsif ($cols[0] eq "do-backs") {
                 $doBacks = 1;
                 return;
-            } elsif ($cols[0] eq "raw") {
-                $_ = join " ", @cols[1..$#cols];
-            } elsif ($cols[0] eq "#") {
+            } elsif (/^\s*#/) {
                 return;
-            } elsif ($cols[0] eq "include") {
-                open(my $fh, "<:encoding(UTF-8)", substr $cols[1], 1, -1) or die "$!";
+            } elsif (/^\s*\|/) {
+                $_ = $head . substr $_, 1 + (index $_, "|");
+            } elsif (/^\s*<<(.*)\[([^[]+)\]/) {
+                my $indentOrig = $indent;
+                $indent .= "${head}$1";
+                open(my $fh, "<:encoding(UTF-8)", $2) or die "$!";
                 while (<$fh>) { procline $_ }
                 close $fh;
+                $indent = $indentOrig;
                 return;
             } else {
                 die "unknown $cols[0] command: $page\n";
@@ -274,7 +278,7 @@ sub genHTML {
                 }
             }
         }
-        print $out "$_\n";
+        print $out "${indent}$_\n";
     }
     {
         my $fh;