From dfb9b24814264abb429e4d289685654c469ff362 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Sun, 31 Jan 2021 12:49:22 +0000 Subject: Add index script Index automatically adds appropriate ids to HTML headings and prints an index of all headings on stderr (unless given the -s, silent, option). --- index | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ mkfile | 9 ++++++-- test.em | 2 ++ test.html | 7 +++++- 4 files changed, 89 insertions(+), 3 deletions(-) create mode 100755 index diff --git a/index b/index new file mode 100755 index 0000000..accd0be --- /dev/null +++ b/index @@ -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]/ { + heading($0) + next + } + // { + 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("^.*", "", i) + sub(".*$", "", i) + i = toascii(i) + 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 + } +' diff --git a/mkfile b/mkfile index f153627..84e93b3 100644 --- a/mkfile +++ b/mkfile @@ -1,8 +1,13 @@ test.html: - path=(. /bin) em test.em > test.html + path=(. /bin) + ramfs -p + em test.em > /tmp/1 + htwrap -t /tmp/1 > /tmp/2 + index -s /tmp/2 > test.html README.html: README - path=(. /bin) em README > README.html + path=(. /bin) + em README > README.html install: cp em emcollect emparse htwrap /rc/bin/ diff --git a/test.em b/test.em index 2965c09..95facea 100644 --- a/test.em +++ b/test.em @@ -8,6 +8,8 @@ Here is an asterisk at the end of a word*. Here is an *unfinished inline formatting tag. +== Meßerschmidts fiancé == + > Perhaps quotes could be regarded as lists. The paragraph goes on until a new "item" comes. > Here, a new paragraph is started. diff --git a/test.html b/test.html index 17f5566..5a76eaf 100644 --- a/test.html +++ b/test.html @@ -1,4 +1,7 @@ -

Em example

+ + +Em example +

Em example

This is an example of em.

@@ -11,6 +14,7 @@ Here is an asterisk at the end of a word*.

Here is an unfinished inline formatting tag.

+

Meßerschmidts fiancé

Perhaps quotes could be regarded as lists. The paragraph goes on until a new "item" comes. @@ -57,3 +61,4 @@ definition code block with two lines + -- cgit v1.2.3