From 1db6cbbea4fd318fc619d10e556f11cae7d90efe Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Sat, 10 May 2025 19:23:38 +0300 Subject: [PATCH] Ability to indent includes --- FORMAT | 12 ++++++------ zk | 28 ++++++++++++++++------------ 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/FORMAT b/FORMAT index f0b5fa8..e789d9f 100644 --- a/FORMAT +++ b/FORMAT @@ -10,12 +10,12 @@ role only (currently) during HTML generation. Creates {optional text|URL} link in HTML. * img URL[ optional text] Creates 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 7acfab8..3edd2aa 100755 --- a/zk +++ b/zk @@ -104,7 +104,7 @@ for my $pth (keys %Mtimes) { my $lines = 0; my sub procline; sub procline { - if (/^include \[(.*)\] $/) { + if (/^<<.*\[(.*)\] $/) { $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\n\n
";
     }
+    my $indent = "";
     my sub procline;
     sub procline {
         $_ = $_[0];
         chop;
         if (/
$/) {
             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}=> $t";
+                $_ = "$head=> $t";
             } elsif ($cols[0] eq "img") {
                 if ($#cols > 1) {
                     my $t = htmlescape join " ", @cols[2..$#cols];
                     $t =~ s/"/\&guot;/g;
-                    $_ = "\"$t\"";
+                    $_ = "$head\"$t\"";
                 } else {
-                    $_ = "";
+                    $_ = "$head";
                 }
             } 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;
-- 
2.48.1