diff options
author | John Ankarström <john@ankarstrom.se> | 2021-01-31 12:51:28 +0000 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2021-01-31 12:51:28 +0000 |
commit | 07f59f5eb8c296b7306882185cbe932a2f286174 (patch) | |
tree | d82ea0d882cc07a399a3c0257e85b3f94f626a65 /htindex | |
parent | dfb9b24814264abb429e4d289685654c469ff362 (diff) | |
download | em-07f59f5eb8c296b7306882185cbe932a2f286174.tar.gz |
Rename index to htindex (like htwrap)
Diffstat (limited to 'htindex')
-rwxr-xr-x | htindex | 74 |
1 files changed, 74 insertions, 0 deletions
@@ -0,0 +1,74 @@ +#!/bin/rc -e + +# index -- add ids to headings and print index to stderr + +flagfmt=s +args='[file ...]' + +if(! ifs=() eval `{aux/getflags $*}){ + aux/usage + exit usage +} + +fn source{ + if(! ~ $#* 0) + cat $* + if not + cat +} + +source $* | awk ' + /<h[0-9]>.*<\/h[0-9]/ { + heading($0) + next + } + /<h[0-9]>/ { + open = 1 + s = $0 + next + } + open && /<\/h[0-9]>/ { + open = 0 + s = s "\n" $0 + heading(s) + next + } + open { s = s " " $0; next } + { print } + + function heading(s) { + i = s + sub("^.*<h[0-9]>", "", i) + sub("</h[0-9]>.*$", "", i) + i = toascii(i) + sub("^<h[0-9]", "& id=\"" i "\"", s) + print s + if (!ENVIRON["flags"]) { # if not silent mode + sub("^<h", "", s) + sub(" id=\"", " ", s) + sub("\">", " ", s) + sub("<\/h[0-9]>$", "", s) + print s > "/dev/stderr" + } + } + + function toascii(s) { + s = tolower(s) + gsub("[ÀÁÂÃÄÅàáâãäå]", "a", s) + gsub("[Ææ]", "ae", s) + gsub("[Çç]", "c", s) + gsub("[Ðð]", "dh", s) + gsub("[ÈÉÊËèéêë]", "e", s) + gsub("[ÌÍÎÏìíîï]", "i", s) + gsub("[Ññ]", "n", s) + gsub("[ÒÓÔÕÖØòóôõöø]", "o", s) + gsub("[ß]", "ss", s) + gsub("[Þþ]", "th", s) + gsub("[ÙÚÛÜùúûü]", "u", s) + gsub("[×]", "x", s) + gsub("[Ýýÿ]", "y", s) + gsub("[^-a-z_ ]", "", s) + gsub("[ ]+", "-", s) + return s + } +' |