another try on asciidoc.pawk, generating an explicit id
[nobug] / doc / asciidoc.pawk
index 0029d64..9dc3244 100644 (file)
@@ -11,12 +11,16 @@ match($0, com "([[:alpha:]][[:alnum:]_]*)(([.]([^[:space:]]*)))?", p) {
 # Create an asciidoc paragraph and index entry
 #             Sec       Name  Index Explanation
 match($0, com"(.*) PARA (.*); *(.*); *(.*)", p) {
+    append(p[1],"","."p[2])
     if(p[3])
     {
-        append("index", tolower(p[3]), "xref:"p[3]"["p[2]"]:: "p[4])
-        append(p[1],"","[["p[3]"]]")
+        id=tolower(gensub(/[^[:alnum:]]+/, "", "g", p[3]))
+        if (p[4])
+        {
+            append("index", id, "xref:"id"["p[2]"]:: "p[4])
+        }
+        append(p[1],"","anchor:"id"[]")
     }
-    append(p[1],"","."p[2])
     next
 }
 
@@ -45,14 +49,41 @@ match($0, com"(.*) HEAD([^ ]+) (.*); *(.*); *(.*)", p) {
         if (asciidoc_level > 1) --asciidoc_level
         p[2] = asciidoc_header[asciidoc_level]
     }
+    else
+    {
+        for (n_HEAD = 0; n_HEAD <=4; ++n_HEAD) {
+            if (p[2] == asciidoc_header[n_HEAD]) {
+                asciidoc_level = n_HEAD
+                break
+            }
+        }
+    }
+
+    if (p[3])
+    {
+        append(p[1],"",p[3])
+        append(p[1],"",gensub(/./, p[2], "g", p[3]))
+
+        if (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
+}
+
 
+# Create an asciidoc index and anchor
+#             Sec        Title Index Explanation
+match($0, com"(.*) INDEX (.*); (.*); (.*)", p) {
     if (p[4])
     {
-        append("index", tolower(p[4]), "xref:"p[4]"["p[3]"]:: "p[5])
-        append(p[1],"","[["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],"",gensub(/./, p[2], "g", p[3]))
+    append(p[1],"","anchor:"id"[]")
     next
 }