#!/bin/awk -f ## (c) Sphynkx 2023 GPL3++ ## Script parses input stream, modifyes headings (add 'id"-s and tags). Also collect them ## to separate div as list. List places on page according css options. To hide this list for some separate ## page put tag "" in any place in source of page. BEGIN { n = 0; notoc = 0 } function mk_toc_item(tag, id, i, n) { margin = "" while(i--) margin = margin " " return "
  • " margin "" tag "
  • " } { if($0 ~ //) notoc++ tag = $0 split("123456", arr, "") for (i in arr) { _ = "" if($0 ~ _) { gsub("", "", tag) gsub("", "", tag) id = tag gsub(" ", "_", id) toc_item[n] = mk_toc_item(tag, id, i, n) tag = "" tag "" n++ } } print tag } END { if(notoc > 0) n=0 if(n == 0) hide_div=" style=\"display: none\"" print "
      " for(i = 0; i < length(toc_item); i++) print toc_item[i] print "
    " }