From b2151362b07192a59da1be2d302df5c7410f9ce9 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Fri, 19 Jun 2020 18:17:33 +0100 Subject: [PATCH] README.md: wip TOC Signed-off-by: Ian Jackson --- README.md | 12 ++++-------- update-readme-toc => markdown-toc-filter | 13 +++++++------ 2 files changed, 11 insertions(+), 14 deletions(-) rename update-readme-toc => markdown-toc-filter (58%) diff --git a/README.md b/README.md index 2bd58a7..3fe20ab 100644 --- 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 ============================================== diff --git a/update-readme-toc b/markdown-toc-filter similarity index 58% rename from update-readme-toc rename to markdown-toc-filter index d5d5852..ec75972 100755 --- a/update-readme-toc +++ b/markdown-toc-filter @@ -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; } -- 2.30.2