kisscommunity

kisscommunity.bvnf.space site sources
git clone git://bvnf.space/home/kiss/kisscommunity.git
Log | Files | Refs | Submodules | README | LICENSE

commit 4bb93451a08413fbe6c83da9d5ed20def902e9c4
parent 5777321630f37d8d25a87edd6030b40bae92b662
Author: aabacchus <ben@bvnf.space>
Date:   Wed,  8 Feb 2023 01:07:07 +0000

add awk script to generate indices and heading links

Diffstat:
Aenumerate.awk | 33+++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+), 0 deletions(-)

diff --git a/enumerate.awk b/enumerate.awk @@ -0,0 +1,33 @@ +#!/usr/bin/awk -f +# For articles with only h2 and h3 as major and minor headings. +# If there is a ## Index already present, run with `awk -v major=-1`. +# You must manually move the index to the top. + +BEGIN { li = 0 } + +/^## / { + printf("## [%%[%d.0]] %s\n", ++major, substr($0, 4)) + minor = 0 + labels[li,0] = major "." minor + labels[li,1] = substr($0, 4) + labels[li++,2] = 1 + next +} +/^### / { + printf("### [%%[%d.%d]] %s\n", major, ++minor, substr($0, 5)) + labels[li,0] = major "." minor + labels[li++,1] = substr($0, 5) + next +} +{ + print +} + +END { + printf("\n## [%%[0.0]] Index\n\n") + for (i=0; i < li; i++) { + if (labels[i,2] != 1) + printf(" "); + printf("- [%s](#%s) %s\n", labels[i,0], labels[i,0], labels[i,1]); + } +}