another try on asciidoc.pawk, generating an explicit id
[nobug] / doc / asciidoc.pawk
index 22aa6a1..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])
     {
-        if (p[4]) 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
 }
 
@@ -57,13 +61,15 @@ match($0, com"(.*) HEAD([^ ]+) (.*); *(.*); *(.*)", p) {
 
     if (p[3])
     {
+        append(p[1],"",p[3])
+        append(p[1],"",gensub(/./, p[2], "g", p[3]))
+
         if (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"[]")
         }
-        append(p[1],"",p[3])
-        append(p[1],"",gensub(/./, p[2], "g", p[3]))
     }
     next
 }
@@ -72,8 +78,12 @@ match($0, com"(.*) HEAD([^ ]+) (.*); *(.*); *(.*)", p) {
 # Create an asciidoc index and anchor
 #             Sec        Title Index Explanation
 match($0, com"(.*) INDEX (.*); (.*); (.*)", p) {
-    append("index", tolower(p[3]), "xref:"p[3]"["p[2]"]:: "p[4])
-    append(p[1],"","[["p[3]"]]")
+    if (p[4])
+    {
+        id=tolower(gensub(/[^[:alnum:]]+/, "", "g", p[3]))
+        append("index", id, "xref:"id"["p[2]"]:: "p[4])
+    }
+    append(p[1],"","anchor:"id"[]")
     next
 }