#!/bin/sed -rf #-- a script to make a html table of contents from a plain text #-- 'book' file. This script requires gnused 4+ #-- #---------------------------- # start the table of contents 1 i
\n

Table of Contents

\n
#-- remove spaces on blank lines s/^[[:space:].]+$//g; #-- delete lines which are not section headings /^[[:upper:] .]+$/ !{ d; b; } #-- remove leading and trailing space s/^[[:space:]]+//g; s/[[:space:]]+$//g; #-- Convert section headings to a list of hyperlinks #-- Section headings are in all capitals /^[[:upper:] ]+$/ { s/[[:space:]]+$//g; s/^.*$/\L&/g; H; y/ /-/; s/.*//; x; s/[[:alnum:]]+/\u&/g; #-- make capital case (eg 'the title' -> 'The Title') x; G; s@.*@
  • &
  • @; s@\n@@g; /22/ { s/22//; s/^/<\/ul>\n/; } /11/ { s/11//; } x; s/.*//; s/^/11/; x; #-- put a flag in the hold space } #-- convert subsection headings (eg: TITLE ....) /^[[:upper:] .]+$/ { s/\.//g; #-- dots mark subsection headings s/[[:space:]]+$//g; s/^.*$/\L&/g; #-- lower case the whole line H; #-- add to the hold space y/ /-/; #-- s/.*//; x; s/[[:alnum:]]+/\u&/g; #-- make capital case (eg 'the title' -> 'The Title') x; G; s@.*@
  • &
  • @; s/\n//g; #-- remove newlines /11/ { s/11//; s/^/