chiark / gitweb /
README.md: wip TOC
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 19 Jun 2020 17:17:33 +0000 (18:17 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 19 Jun 2020 17:17:33 +0000 (18:17 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
README.md
markdown-toc-filter [moved from update-readme-toc with 58% similarity]

index 2bd58a74bbf5b19b9be1bb03300ed3d02be9282d..3fe20abb5b6828be65233df5a8e7d52c812008b2 100644 (file)
--- a/README.md
+++ b/README.md
@@ -22,14 +22,6 @@ alongside the top-level git repositories you are working with, and
 invoke nailing-cargo from the git directory containing the Rust
 package you want to build.
 
-Table of Contents
-=================
-
-
-
-Getting started
-===============
-
 Installing
 ----------
 
@@ -57,6 +49,10 @@ $ nailing-cargo generate-lockfile
 $ nailing-cargo build
 ```
 
+Documentation table of contents
+-------------------------------
+
+
 Using local crates, or locally modified crates
 ==============================================
 
similarity index 58%
rename from update-readme-toc
rename to markdown-toc-filter
index d5d5852a878268b4eb1ecd5c1f2136874e33b563..ec759724a64a72ac71e781ea2b0e53e7de5cd969 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/perl -wni~
+#!/usr/bin/perl -wn
 
 use strict;
 use autodie;
@@ -6,26 +6,27 @@ use autodie;
 our (@doc, @toc);
 our $last;
 
-if (1..m/^Table of Contents/) {
+if (1..(m/^[A-Z]/ && m/table of contents/i)) {
   # before TOC
   print;
 } elsif (m/^\w/..0) {
   push @doc, $_;
   # after TOC
   if (m/^-+$/ || m/^=+$/) {
-    my $lev = $& =~ m/^-/ ? '  ' : '    ';
+    my $lev = $& =~ m/^=/ ? '  ' : '    ';
     my $href = $last;
-    $href =~ y/ A-Z-/-a-z/d;
+    $href =~ y/ A-Z/-a-z/;
+    $href =~ y/-._a-z//cd;
     push @toc, "${lev}* [$last](#$href)\n";
   }
   $last = $_;
   chomp $last;
 } else {
   # in TOC
-  print if m/^===/;
+  print if m/^===|^---/;
 }
 
 END {
-  print @toc;
+  print "\n", @toc, "\n";
   print @doc;
 }