aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xindex74
-rw-r--r--mkfile9
-rw-r--r--test.em2
-rw-r--r--test.html7
4 files changed, 89 insertions, 3 deletions
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]>.*<\/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
+ }
+'
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 @@
-<h1>Em example</h1>
+<!DOCTYPE html>
+<html>
+<title>Em example</title>
+<h1 id="em-example">Em example</h1>
<p>
This is an example of <i>em</i>.
</p>
@@ -11,6 +14,7 @@ Here is an asterisk at the end of a word*.
<p>
Here is an <i>unfinished inline formatting tag.
</i></p>
+<h2 id="messerschmidts-fiance">Meßerschmidts fiancé</h2>
<blockquote>
<p>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
</pre>
+</html>