another try on asciidoc.pawk, generating an explicit id
authorChristian Thaeter <ct@pipapo.org>
Tue, 17 Aug 2010 13:55:14 +0000 (15:55 +0200)
committerChristian Thaeter <ct@pipapo.org>
Tue, 17 Aug 2010 13:55:14 +0000 (15:55 +0200)
we may factor id generation into a function later, possibly
invent a encoding scheme which preserves sort order

doc/asciidoc.pawk

index d8de3df..9dc3244 100644 (file)
@@ -14,12 +14,12 @@ match($0, com"(.*) PARA (.*); *(.*); *(.*)", p) {
     append(p[1],"","."p[2])
     if(p[3])
     {
+        id=tolower(gensub(/[^[:alnum:]]+/, "", "g", p[3]))
         if (p[4])
         {
-            gsub(/[^[:alnum:]_]+/, "", p[3])
-            append("index", tolower(p[3]), "xref:"p[3]"["p[2]"]:: "p[4])
+            append("index", id, "xref:"id"["p[2]"]:: "p[4])
         }
-        append(p[1],"","[["p[3]"]]")
+        append(p[1],"","anchor:"id"[]")
     }
     next
 }
@@ -63,11 +63,12 @@ match($0, com"(.*) HEAD([^ ]+) (.*); *(.*); *(.*)", p) {
     {
         append(p[1],"",p[3])
         append(p[1],"",gensub(/./, p[2], "g", p[3]))
+
         if (p[4])
         {
-            gsub(/[^[:alnum:]_]+/, "", p[4])
-            if (p[5]) append("index", tolower(p[4]), "xref:"p[4]"["p[3]"]:: "p[5])
-            append(p[1],"","[["p[4]"]]")
+            id=tolower(gensub(/[^[:alnum:]]+/, "", "g", p[4]))
+            if (p[5]) append("index", id, "xref:"id"["p[3]"]:: "p[5])
+            append(p[1],"","anchor:"id"[]")
         }
     }
     next
@@ -79,10 +80,10 @@ match($0, com"(.*) HEAD([^ ]+) (.*); *(.*); *(.*)", p) {
 match($0, com"(.*) INDEX (.*); (.*); (.*)", p) {
     if (p[4])
     {
-        gsub(/[^[:alnum:]_]+/, "", p[3])
-        append("index", tolower(p[3]), "xref:"p[3]"["p[2]"]:: "p[4])
+        id=tolower(gensub(/[^[:alnum:]]+/, "", "g", p[3]))
+        append("index", id, "xref:"id"["p[2]"]:: "p[4])
     }
-    append(p[1],"","[["p[3]"]]")
+    append(p[1],"","anchor:"id"[]")
     next
 }